Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion

Tags in this Discussion

Shadow Mapping on OpenGL 3 with FBO GeForce GTX 550 Ti
  • I recently had some free time at work and the intel graphics card in my machine supports opengl 3 so I decided to see if my engine would run... it does. So I thought, the only thing it's really missing right now is to convert my shadow mapping. I do it and it works with flying colors. It only took me about 3 hours to add it to the renderer.

    So I thought, that was too easy, especailly for an intel card. So I brought the code home and put it in my svn and compiled on my home computer with a geforce 550 from nvidia themselves. It supports opengl 4.2. Suddenly, I realized the shadows do not work at all, in fact the whole screen is black...

    Has anyone else ran into this? I've been faithful to NVidia and it has to work on nvidia and ati, and this is very strange. Normally I'm fighting with Intel cards.

    Anyway, just was hoping for some quick advice, maybe a couple things to check out... here's some screen shots

    Here is a screenshot from work of the shadows working on the intel gma card:


    Here is the shadow map as generated on my NVidia card (It is exactly the same as the one as the Intel card!):


    But alas, like I said, the screen is black...

    I looked at gDeBugger and there seems to be no errors, especially no OpenGL Errors.

    Once again, any thoughts would be greatly appreciated!
  • 4 Comments sorted by
  • Without code this is tougher to solve. Does the GTX550 Ti support shadow mapping extension, grep shadow from the glxinfo in your debug tool?
  • Turns out it was me not following the opengl spec properly from nvidia...

    I needed to add the correct TexParameters...

    My code went from:

    graphics->SetActiveTexture(2);
    shaders->SetInt("shadow_mapping_enabled", 1);
    shaders->SetMatrix4("shadow_mapping_bias", shadow_mapping_bias * light->GetProjectionMatrix() * light->GetViewMatrix());
    graphics->BindTexture(light->GetShadowBuffer()->GetDepthTextureId(), 2);


    To:

    graphics->SetActiveTexture(2);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE_ARB, GL_COMPARE_R_TO_TEXTURE_ARB);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_FUNC_ARB, GL_LEQUAL);
    shaders->SetInt("shadow_mapping_enabled", 1);
    shaders->SetMatrix4("shadow_mapping_bias", shadow_mapping_bias * light->GetProjectionMatrix() * light->GetViewMatrix());
    graphics->BindTexture(light->GetShadowBuffer()->GetDepthTextureId(), 2);


    The problem is, the first light is not generating a shadow, but I'm sure that's just a lingering affect of not setting the parameters back.
  • Vote Up0Vote Down PaloDeQueso
    Posts: 4 Accepted Answer
    I don't believe I'm using that. I'm using an FBO with a depth attachment, which is the second pic, and all glsl.
  • Vote Up0Vote Down PaloDeQueso
    Posts: 4 Accepted Answer

    #version 140

    smooth in vec2 texcoord;

    uniform mat4 shadow_mapping_bias;
    uniform int shadow_mapping_enabled;
    uniform sampler2DShadow shadow_map;
    uniform vec2 shadow_map_size;

    uniform sampler2D position_map;
    uniform sampler2D normal_map;
    uniform vec3 camera_position;
    uniform vec3 light_position;
    uniform vec3 light_color;
    uniform vec3 light_attenuation;
    uniform float light_radius;

    out vec4 fragment_output;

    void main(){
    vec4 position_specular = texture(position_map, texcoord);
    vec3 position = position_specular.xyz;
    vec3 light_vector = position - light_position;
    float shadow_influence = 1.0;
    float light_distance = abs(length(light_vector));
    if (light_distance > light_radius){
    discard;
    }

    float specular_factor = position_specular.w;
    vec4 color = vec4(0.0, 0.0, 0.0, 0.0);

    vec4 normal_height = texture(normal_map, texcoord);
    vec3 normal_vector = normalize(normal_height.xyz);
    float height_value = normal_height.w;

    vec3 view_vector = normalize(camera_position - position);
    light_vector = normalize(light_vector);
    vec3 reflect_vector = normalize(reflect(light_vector, normal_vector));

    float diffuse = max(dot(normal_vector, light_vector), 0.0);
    if (diffuse > 0.0){
    float attenuation_factor = 1.0 / (light_attenuation.x + (light_attenuation.y * light_distance) + (light_attenuation.z * light_distance * light_distance));
    attenuation_factor *= (1.0 - pow((light_distance / light_radius), 2.0));

    float specular = pow(max(dot(reflect_vector, view_vector), 0.0), 16.0) * specular_factor;

    vec3 diffuse_color = (diffuse * attenuation_factor) * light_color;
    vec3 specular_color = (specular * attenuation_factor) * light_color;
    color = vec4(diffuse_color + specular_color, 1.0);
    }

    if (shadow_mapping_enabled == 1){
    vec4 projected_coordinate = shadow_mapping_bias * vec4(position, 1.0);
    shadow_influence = textureProj(shadow_map, projected_coordinate);
    }

    fragment_output = vec4(color.rgb * shadow_influence, 1.0);
    }


    That's my lighting fragment shader for my deferred renderer... Like I said, this exact same code works great on the Intel card. I should also note that I have now checked to make sure that the shadow depth buffer is getting properly passed in and debugged it all the way through. I am at a loss considering all of the data is there and computed the same way as the intel card.