Sign in to follow this  
Eitsch

TexCoord generation in shader

Recommended Posts

i am trying to implement the texture coordinate generation like GL_EYE_LINEAR. the vertex shader:
void main()
{
	vec4 xEyePlane = vec4(1.0,0.0,0.0,0.0) * gl_ModelViewMatrixInverse;
	vec4 yEyePlane = vec4(0.0,1.0,0.0,0.0) * gl_ModelViewMatrixInverse;
	vec4 zEyePlane = vec4(0.0,0.0,1.0,0.0) * gl_ModelViewMatrixInverse;
	vec4 wEyePlane = vec4(0.0,0.0,0.0,1.0) * gl_ModelViewMatrixInverse;

	vec4 eyeVertex = gl_Vertex * gl_ModelViewMatrix;


	
	gl_TexCoord[0].s = xEyePlane.x * eyeVertex.x + xEyePlane.y * eyeVertex.y + xEyePlane.z * eyeVertex.z + xEyePlane.w * eyeVertex.w;
	gl_TexCoord[0].t = yEyePlane.x * eyeVertex.x + yEyePlane.y * eyeVertex.y + yEyePlane.z * eyeVertex.z + yEyePlane.w * eyeVertex.w;
	gl_TexCoord[0].r = zEyePlane.x * eyeVertex.x + zEyePlane.y * eyeVertex.y + zEyePlane.z * eyeVertex.z + zEyePlane.w * eyeVertex.w;
	gl_TexCoord[0].q = wEyePlane.x * eyeVertex.x + wEyePlane.y * eyeVertex.y + wEyePlane.z * eyeVertex.z + wEyePlane.w * eyeVertex.w;


	gl_Position = ftransform();
}
i don't get the correct results....please help /EDIT: i changed vec4 xEyePlane = vec4(1.0,0.0,0.0,0.0) * gl_ModelViewMatrixInverse; and so on with vec4 xEyePlane = gl_ModelViewMatrixInverse * vec4(1.0,0.0,0.0,0.0); [Edited by - Eitsch on March 12, 2006 7:11:50 AM]

Share this post


Link to post
Share on other sites
sorry i dont know how eye_linear works (itll be discussed in the red book no doubt)
btw this looks unneseccary
vec4 xEyePlane = vec4(1.0,0.0,0.0,0.0) * gl_ModelViewMatrixInverse;

also u can use gl_FragCoord.xy + the frag shader to do what eye_linear does (i believe)
eg
vec2 texcoord = gl_FragCoord.xy / 100.0;

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this