java - GLSL shaders, gl_ModelViewMatrix not correct? -
so trying make shader changed color of crystal little bit on time, , went fine until noticed didn't darker further away went light source ( default opengl lights now! ). tried tone down color values distance away light didn't work. later on discovered ( setting color red if x position of vertex in world coordinates greater value ), vertex.x value around 0. though should 87.0.
void main() { vec3 vertexposition = vec3(gl_modelviewmatrix * vertexpos); vec3 surfacenormal = (gl_normalmatrix * normals).xyz; vec3 lightdirection = normalize(gl_lightsource[0].position.xyz - vertexposition); float diffuseli = max(0.0, dot(surfacenormal, lightdirection)); vec4 texture = texture2d(texturesample, gl_texcoord[0]); if(vertexposition.x > 0)gl_fragcolor.rgba = vec4(1, 0, 0, 1); /*and on....*/ }
as far know gl_modelviewmatrix * gl_vertex should give world coordinates of vertex. stupid or what? ( tried same if statement light position correct! )
Comments
Post a Comment