Paralax problem

I’m trying to implement some parallax shaders from ShaderDesigner but somehow I keep getting something like this

Do you guys have any ideea what might be the problem?
My lights are indeed set up correcly :slight_smile:

Looks sorta like affine texmapping… like there’s linear texcoord interpolation or something going on.

I’m sorry but I don’t really understand this. Could someone point me to some stuff to read about this? googeling “opengl linear texcoord” or “affine texmapping” won’t lead me anywhere good.
It’s not a urgent thing as in the meenwhile I can start implementing physics.
I’m trying to make a 3d engine but I’m quite new to shaders.
Also is this correct for setting up lights?
float pos[] = {EntityX(true),EntityY(true),-EntityZ(true),1};
glLightfv(gl_light[light_no],GL_POSITION,pos);
I set up the light just after I set up my camera. I have a pointlight shader and it seems to work fine and also the normal opengl lights seem to be working well. I ask this because trying to apply different shaders (from ShaderDesigner) won’t provide the same result.
I’ve read about the difference between higher than ogl 1.3 and lower. Does this mean that if my card supports more (nvidia 8600GM and 9400 GT) I won’t be able to use lower commands? or is it just not recommended?
Thank you.

Maybe you missing additional vertex attributes (tangent and binormal)?

This looks like something you’d get if you specify invalid tangent / binormal vectors. Make sure these are correct!

Yes indeed I played a bit with the the tangent and binormal vectors and it does modify the way it looks.
Now the thing is that in shader designer it looks good so then I guess it’s something from my code. Since the light won’t affect it at all it doesn’t matter how that is set up (and plus with a per pixel lighting shader it looks great).
So then I guess the way I set up my camera is important right?
Here is my code. Can anyone spot something wrong with this?
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glFrustum(left+dx,right+dx,bottom+dy,top+dy,zNear,zFar);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glTranslatef(-eyedx,-eyedy,0);

Please help me with this guys. I’ll be forever gratefull and when I learn this stuff more I’ll also help others.

Well I think I got an ideea of what’s wrong. First of all I didn’t know attributes had to set from the app.
Now since I use draw elements I guess it would be normal to use array pointers. So I set them up like this:

GLint binormal = glGetAttribLocation(material->Shader->Program,“binormal”);
GLint tangent = glGetAttribLocation(material->Shader->Program,“tangent”);
glEnableVertexAttribArray(binormal);
glVertexAttribPointer(binormal, 3, GL_FLOAT, 0, 0, this->face_binormal);
glEnableVertexAttribArray(tangent);
glVertexAttribPointer(tangent, 3, GL_FLOAT, 0, 0, this->face_tangent);

So I basically have tri_count 33 arrays of floats for each the tanget and binormal since I have to supply one for each vertex of a triangle.

I calculate the binormal and the tangent like this:



CVector2 tex21 = tex2 - tex1;
CVector2 tex31 = tex3 - tex1;

CVector3 vec21 = vec2-vec1;
CVector3 vec31 = vec3-vec1;

CVector3 tangent = vec21*tex31.y-vec31*tex21.y;
tangent.normalize();

CVector3 binormal = vec31*tex21.x-vec21*tex31.x;
binormal.normalize();

Is this right? I’m quite hopeless here since I don’t know exactly what I’m doing. I have to supply the same binormals and tangents for each vertex of a face right?

(in the variable names 31 comes from 3-1 just os you get what I’m doing)

Have a gander at this

http://http.developer.nvidia.com/GPUGems3/gpugems3_ch18.html

The reference section alone has the goods on background material.

For the tangent/binormal stuff you might search “tangent basis generation/calculation”.

http://www.terathon.com/code/tangent.html

Good read on affine (linear) and projective (rational-linear/hyperbolic) texture mapping

http://www.cs.cmu.edu/~ph/texfund/texfund.pdf

Look at page 12 for an image that resembles yours a bit.

Thank you very much. I’ve read those documents and while they are helpful I think I lack the necessary math skills to understand everything.
Anyway I did understand how to calculate them. Basically it’s just some cross products :).
The thing is it still doesn’t work so I did a little workaround to exclude this problem. I modified the vert shader as follows to make sure everything else is set up right. It works exactly the same in ShaderDesigner without attributes and still I get a distorted image in my program. I’d like to know what from the app influences the way textures are calculated. Maybe some view matrix and stuff like that.
I’m going to document myself more now but please if you have any ideea do tell.
Thank you again Brolingstanz


//attribute vec3 tangent;
//attribute vec3 binormal;
varying vec3 eyeVec;

void main() 
{ 
	vec3 tangent; 
	vec3 binormal; 
	
	vec3 c1 = cross(gl_Normal, vec3(0.0, 0.0, 1.0)); 
	vec3 c2 = cross(gl_Normal, vec3(0.0, 1.0, 0.0)); 
	
	if(length(c1)>length(c2))
	{
		tangent = c1;	
	}
	else
	{
		tangent = c2;	
	}
	
	tangent =- normalize(tangent);
	binormal = cross(gl_Normal, tangent); 
	binormal = normalize(binormal);
	
     gl_TexCoord[0] = gl_MultiTexCoord0; 
 
     mat3 TBN_Matrix;// = mat3(tangent, binormal, gl_Normal);  
     TBN_Matrix[0] =  gl_NormalMatrix * tangent; 
     TBN_Matrix[1] =  gl_NormalMatrix * binormal; 
     TBN_Matrix[2] =  gl_NormalMatrix * gl_Normal; 
     vec4 Vertex_ModelView = gl_ModelViewMatrix * gl_Vertex; 
     eyeVec = vec3(-Vertex_ModelView) * TBN_Matrix ;      
     // Vertex transformation 
     gl_Position = ftransform(); 
}

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.