Lighting Shader Transformations Problem

Started by
0 comments, last by Enalis 13 years, 1 month ago
[font=arial, verdana, tahoma, sans-serif][size=2]The issue is that my objects are getting transformed correctly however the lighting is not. EG... I have a sphere rolling on some terrain, as it rolls the triangles/textures transform correctly, however the lighting does not, and the lit side of the sphere rolls with the sphere. I am posting my vert shader which is pretty straight forward...

As you can see, the modelview_matrix is used for the gl_Position variable and is working quite nicely...
The normal_matrix uniform is just

- Take the top left 3x3 of the modelview matrix
- Then calculate the Inverse Transpose of that.

That's it.

I've also tried sending just the modelview_matrix in for lighting as well, even though the normal scaling problem would exist, at least it might rotate properly?
Anyway, this is the last little issue with this new lighting model in which I've replaced opengls matrices.

I'm hoping it's quickly solvable, thanks in advance!
CODE BAM!


varying vec3 normal, tangent, bitangent;
varying vec3 light, view;
varying float light_distance;

uniform vec3 light_position;

uniform mat4 projection_matrix;
uniform mat4 modelview_matrix;
uniform mat3 normal_matrix;

void main(){
normal = normalize(normal_matrix * gl_Normal);
tangent = normalize(normal_matrix * gl_MultiTexCoord1.xyz);
bitangent = normalize(normal_matrix * gl_MultiTexCoord2.xyz);

vec4 eye_position = modelview_matrix * gl_Vertex;
view = normalize(-eye_position.xyz);
vec3 transformed_light_position = vec3(modelview_matrix * vec4(light_position, 1.0));
vec3 temp = vec3(transformed_light_position - eye_position.xyz);
light = normalize(temp);
light_distance = length(temp);

gl_Position = projection_matrix * modelview_matrix * gl_Vertex;
gl_TexCoord[0].st = gl_MultiTexCoord0.st;
gl_FrontColor = gl_Color;
}
[/font]
Douglas Eugene Reisinger II
Projects/Profile Site
Advertisement
[font=arial, verdana, tahoma, sans-serif][size=2]sorry for posting so much, I should have just kept hammering on the code... once I really broke down and did a bunch of math I figured out what I needed to do...

here's the code for reference if anyone's interested:[/font]



varying vec3 normal, tangent, bitangent;
varying vec3 light, view;
varying float light_distance;

uniform vec3 light_position;
uniform vec3 camera_position;

uniform mat4 projection_matrix;
uniform mat4 view_matrix;
uniform mat4 model_matrix;
uniform mat4 normal_matrix;

void main(){
normal = normalize(normal_matrix * vec4(gl_Normal, 0.0)).xyz;
tangent = normalize(normal_matrix * vec4(gl_MultiTexCoord1.xyz, 0.0)).xyz;
bitangent = normalize(normal_matrix * vec4(gl_MultiTexCoord2.xyz, 0.0)).xyz;

vec3 vertex_position = (model_matrix * gl_Vertex).xyz;
vec3 light_vector = vertex_position - light_position;

view = normalize(camera_position - vertex_position);

light_distance = length(light_vector);
light = -normalize(light_vector);

gl_Position = projection_matrix * view_matrix * model_matrix * gl_Vertex;
gl_TexCoord[0].st = gl_MultiTexCoord0.st;
gl_FrontColor = gl_Color;
}
Douglas Eugene Reisinger II
Projects/Profile Site

This topic is closed to new replies.

Advertisement