I am generating shadows using a voxel pyramid (commonly called voxel cone, although I hate that term).

Some of my shadows come as expected, however some are very strange.

For example in this image:

enter image description here

If you look at the back column at the right, we have a neat soft shadow. However the shadows over the shield are hard, As are the shadows on the other columns.

I am not sure why or how these hard shadows are being created.

The way I am making my shadows is the standard shadow pyramid that increases as the ray advances, sampling at different LOD's

In other words, this is the shader:

void main()
    fragment_color = blinn_phong();

    float v_size = cube_dim/voxel_resolution;
    vec3 r = f_pos + f_norm*v_size*6;
    vec3 dir = normalize(light-r);
    vec3 start = r;
    float l=0;
    float acc=0;
    vec4 val1, val2;
    while(incube(r, cube_dim) && (l<=length(start-light)) && acc<1)
        r += dir*v_size*0.2;
        float coeff = 0.001;
        l = min(l, 7*1.f/(coeff));
        val1 = textureLod(normal_map, (r)*0.5/cube_dim+vec3(0.5), l*coeff);
        acc += val1.a;

    acc = min(acc, 1);
    fragment_color *= (1-acc)*0.8 + 0.2;
  • $\begingroup$ There's quite a few "magic" numbers in your code, can you explain what the constants are used for ? $\endgroup$ – PaulHK Jul 31 '18 at 2:30
  • $\begingroup$ The coefficient of 6 when calculating the ray origin r. Is simply to prevent voxel self intersection. The coefficient of 0.2 when moving the ray inside the inner loop is the step size of teh ray. Simply a value that gave good results in a decent amount of time. the coefficient called "coeff" is the aperture of teh voxel cone/pyrammid FInally multiplying by 0.8 and then adding 0.2 restricts the possible values of shadows to the interval (0.2, 1) which essentially prevents black shadows $\endgroup$ – Makogan Jul 31 '18 at 21:56
  • $\begingroup$ The word "pyramid" has only one "m". $\endgroup$ – Rahul Aug 1 '18 at 19:34

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.