笔记本电脑上的OpenGL,着色器和奇怪的闪电

时间:2014-01-17 13:00:27

标签: opengl graphics shader glew light

我必须编写一个简单的OpenGL游戏。当我在我的电脑上运行时,一切都很好。不幸的是,当我在笔记本电脑上运行时,它有一些问题。

PC: http://imagizer.imageshack.us/v2/800x600q90/11/i48o.png

笔记本: http://imagizer.imageshack.us/v2/800x600q90/543/zdpf.png

这是片段着色器的代码:

varying vec3 normal, lightDir[3], eyeVec;
uniform sampler2D myTexture;

const float cos_outer_cone_angle = 0.73;

void main (void)
{
    vec4 final_color = (gl_FrontLightModelProduct.sceneColor * gl_FrontMaterial.ambient) + 1.2*((gl_LightSource[0].ambient) * gl_FrontMaterial.ambient);

    for(int j=1;j<2;j++){
        final_color+=(gl_FrontLightModelProduct.sceneColor * gl_FrontMaterial.ambient) + ((gl_LightSource[j].ambient) * gl_FrontMaterial.ambient);
    }

    vec3 L[5];
    vec3 D[5];
    vec3 E = normalize(eyeVec);
    vec3 R[5];
    float specular[5];
    float cos_cur_angle[5];
    float cos_inner_cone_angle[5]; 
    float cos_inner_minus_outer_angle[5]; 
    float spot[5];
    vec3 N = normalize(normal);
    float lambertTerm[5];

    for(int i=0;i<3;i++){
        L[i]=normalize(lightDir[i]);

        D[i]=normalize(gl_LightSource[i].spotDirection);

        cos_cur_angle[i]=dot(-L[i], D[i]);

        cos_inner_cone_angle[i] = gl_LightSource[i].spotCosCutoff;

        cos_inner_minus_outer_angle[i] = cos_inner_cone_angle[i] - cos_outer_cone_angle;

        spot[i] = clamp((cos_cur_angle[i] - cos_outer_cone_angle) / cos_inner_minus_outer_angle[i], 0.0,1.0);

        lambertTerm[i] = max( dot(N,L[i]), 0.0);

        R[i] = reflect(-L[i], N);

        specular[i] = pow( max(dot(R[i], E), 0.0), gl_FrontMaterial.shininess );

        if(lambertTerm[i] >0.0){
            final_color += gl_LightSource[i].diffuse * gl_FrontMaterial.diffuse * lambertTerm[i] *1.5* spot[i];

            final_color += gl_LightSource[i].specular * gl_FrontMaterial.specular * specular[i] *3.0* spot[i];
        }
    }

    gl_FragColor = final_color *  texture2D(myTexture, vec2(gl_TexCoord[0]));           
}

这适用于Vertex Shader:

varying vec3 normal, lightDir[3], eyeVec;

void main()
{   
    normal = gl_NormalMatrix * gl_Normal;

    vec3 vVertex = vec3(gl_ModelViewMatrix * gl_Vertex);

    for(int i=0;i<3;i++){
        lightDir[i] = vec3(gl_LightSource[i].position.xyz - vVertex);
    }
    eyeVec = -vVertex;
    gl_TexCoord[0] = gl_MultiTexCoord0;

    gl_Position = ftransform();     
}    

PC显卡是Radeon HD6770,笔记本GPU是Geforce GT325M。

我不知道问题出在哪里。是着色器还是地形加载或什么。

0 个答案:

没有答案