0
$\begingroup$

I have a scene rendered using texelFetch() and I am trying to modify the shader to use textureLod() instead.

This is the image generated with texelFetch:

enter image description here

When I try to change the shader to use textureLod instead I get:

enter image description here

So as you can see, areas that should not be darkend are now darkened. This seems like the downscaling to the 0-1 coordinate system was not done properly.

This is how I generated the first image:

fragment_color = blinn_phong();

float v_size = cube_dim/voxel_resolution;
vec3 r = f_pos + f_norm*v_size*2;
vec3 dir = normalize(light-r);
vec3 start = r;
ivec3 first = ivec3(((r)*0.5/(cube_dim)+vec3(0.5))*(voxel_resolution-1));
float hit = 1.f;
while(incube(r, cube_dim) && (length(start-r)<=length(start-light)))
{
    r += dir*v_size*0.5;
    ivec3 hpos = ivec3(((r)*0.5/cube_dim+vec3(0.5))*(voxel_resolution-1));
    vec4 val = texelFetch(normal_map, hpos, 0);
    if(val.w > 0 && (first != hpos))
    {
        hit=atan(length(start-r)/200.f)/(PI/2.f)*0.9 + 0.1;
        break;
    }
}
fragment_color *=hit;

And this is how I generated the second:

fragment_color = blinn_phong();

float v_size = cube_dim/voxel_resolution;
vec3 r = f_pos + f_norm*v_size*2;
vec3 dir = normalize(light-r);
vec3 start = r;
ivec3 first = ivec3(((r)*0.5/(cube_dim)+vec3(0.5)));
float hit = 1.f;
while(incube(r, cube_dim) && (length(start-r)<=length(start-light)))
{
    r += dir*v_size*0.5;
    vec3 hpos = vec3(((r)*0.5/cube_dim+vec3(0.5)));
    vec4 val = textureLod(normal_map, hpos, 0);
    if(val.w > 0 && (first != hpos))
    {
        hit=atan(length(start-r)/200.f)/(PI/2.f)*0.9 + 0.1;
        break;
    }
}
fragment_color *=hit;

In other words, the changes consist only on not scaling by the voxel resolution, which should result in a 0 to 1 coordinate system, instead of the 0 to texture dimensions coordinate system.

Alas, it would seem that I am downscaling thins wrongly.

$\endgroup$
  • $\begingroup$ Did you run a graphics debugger and inspect your variables? $\endgroup$ – Varaquilex Aug 3 '18 at 6:42
  • $\begingroup$ I ran renderdoc $\endgroup$ – Makogan Aug 3 '18 at 19:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.