So, I've been working on this game engine for a while now, and just the other day my friend tried running the program and his output doesn't match my output...
My Program Output:
His Program Output:
both are supposed to be donuts, but his donut is very much misformed. I made sure that all the vertices and indices were loaded on his machine correctly so it has to be something going wrong in the shaders
Vertex Shader:
#version 150
in vec3 in_Position;
in vec3 in_Normal;
in vec2 in_TexCoord;
out vec2 ex_TexCoord;
out vec3 Normal;
uniform mat4 model_matrix;
uniform mat4 view_matrix;
uniform mat4 projection_matrix;
void main(void){
ex_TexCoord = in_TexCoord;
Normal = vec3(transpose(inverse(model_matrix * view_matrix)) * vec4(in_Normal, 1.0));
gl_Position = projection_matrix * view_matrix * model_matrix * vec4(in_Position,1.0);
}
Fragment Shader:
#version 150
in vec2 ex_TexCoord;
in vec3 Normal;
out vec4 frag_color;
uniform vec3 lambient;
uniform vec3 ldifuse;
uniform vec3 lspecular;
uniform vec3 light_pos;
uniform vec3 position;
uniform vec3 lstrength;
uniform sampler2D color_texture;
float dcont;
vec3 light_dir;
float intensity;
vec3 normal;
vec3 light;
void main(void){
float dist = length(position-light_pos);
float att = (1/(1.0+(0.01*dist)+(0.001*dist*dist)));
light_dir=normalize(light_pos-position);
normal = normalize(Normal);
intensity = dot(light_dir,normal);
light = normalize(light_pos-position);
dcont = max(0.0,dot(normal,light));
vec3 ambient = lambient;
vec3 difuse = dcont * ldifuse;
vec3 specular = lspecular;
if(intensity > 0.95){
frag_color= vec4((difuse + ambient) * vec3(texture2D(color_texture,ex_TexCoord))*(att),1.0);
}
else if(intensity > 0.5){
frag_color = vec4((difuse + ambient) * vec3(texture2D(color_texture,ex_TexCoord))*0.9*(att),1.0);
}
else if(intensity > 0.25){
frag_color = vec4((difuse + ambient) * vec3(texture2D(color_texture,ex_TexCoord))*0.7*(att),1.0);
}
else{
frag_color = vec4((difuse + ambient) * vec3(texture2D(color_texture,ex_TexCoord))*0.4*(att),1.0);
}
}