سؤال

I developed an OpenGL game in C++ on my desktop machine, where no errors occurred. Now compiling and running it on my tablet, the lighting is messed up. This is my lighting buffer.

the lighting calculation is incorrect

I use deferred rendering, so I have positions and normals as textures. As pointed out in an answer below, the reason for the lighting issue is that instead of the normal texture, the position texture is used for the calculation.

Some facts about the environments. Both machines run Windows 8 Pro 64bit. The video cards are a Nvidia Geforce 560 on the desktop and a Intel HD Graphics 4000 on the tablet. The G-buffer textures, normals and positions in this case, are intact on the tablet and are not mixed up. There are no OpenGL errors.

This is my lighting shader.

#version 330

in vec2 coord;
out vec3 image;

uniform int type = 1;

uniform sampler2D positions;
uniform sampler2D normals;
uniform vec3 light;
uniform vec3 color;
uniform float radius;
uniform float intensity = 1.0;

void main()
{
    if(type == 0) // directional light
    {
        vec3 normal = texture2D(normals, coord).xyz;
        float fraction = max(dot(normalize(light), normal) / 2.0 + 0.5, 0);
        image = intensity * color * fraction;
    }
    else if(type == 1) // point light
    {
        // ...
    }
    else if(type == 2) // spot light
    {
        // ...
    }
}

This is the code I use to bind the sampler uniforms. Pass->Samplers is an unordered_map<string, GLuint> which maps texture target ids to shader locations. Pass->Program holds the shader program id.

glUseProgram(Pass->Program);

int n = 0; for(auto i : Pass->Samplers)
{
    glActiveTexture(GL_TEXTURE0 + n);
    glBindTexture(GL_TEXTURE_2D, i.second);
    glUniform1i(glGetUniformLocation(Pass->Program, i.first.c_str()), n);
    n++;
}

Why are the samplers for positions and normals mixed up on the tablet machine? What am I doing wrong?

Update: After updating my operating system to Windows 8.1, I noticed that the problem disappeared.

هل كانت مفيدة؟

المحلول

It looks to me like is is using the position data instead of the normal data for lighting. Might the textures have been mixed up (you might find the sampler uniforms are at different locations between your desktop at tablet)?

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top