Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

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: poorly textured donut

His Program Output: poorly rendered donut

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);
    }
}
share|improve this question
    
Is your system the only computer this works on? It may help to know the differences in hardware. Also, based on what you've said, it appears that the loading is not the issue. If you've matched up the vertices being loaded as exactly the same then it's the display that's the issue, so you may want to rephrase your title. –  Byte56 May 29 '13 at 23:27
2  
yeah, it seems like it could be a harware dependent problem –  Brendan Webster May 29 '13 at 23:28
4  
Your shaders might be buggy. Different drivers will do different things with non-conforming shader code. –  Sean Middleditch May 29 '13 at 23:29
2  
Could it be lack of support for GL_UNSIGNED_INT index data? Although you don't have so many vertices that it would be a problem. Just an idea. –  DaleyPaley May 30 '13 at 0:09
1  
@BrendanWebster: You should post that in an answer (perfectly fine to answer yourself, if you've found the solution), so others will be able to find this in case they encounter something similar. –  Mario May 30 '13 at 8:53

1 Answer 1

up vote 3 down vote accepted

Alright, so as stated in the comments the problem is the equation for the Normal. Nvidia accepts poor shader programming, so if you have Nvidia just make sure you check with the standards of the shader version. Also don't use keywords such as "Normal" or other words that would cause a name collision.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.