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

<p>Some of my shadows come as expected, however some are very strange.</p>

<p>For example in this image:</p>

<p><a href="https://i.sstatic.net/xGcQD.jpg" rel="nofollow noreferrer"><img src="https://i.sstatic.net/xGcQD.jpg" alt="enter image description here"></a></p>

<p>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.</p>

<p>I am not sure why or how these hard shadows are being created.</p>

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

<p>In other words, this is the shader:</p>

<pre><code>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) &amp;&amp; (l&lt;=length(start-light)) &amp;&amp; acc&lt;1)
    {
        l=length(start-r);
        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;
}
</code></pre>

CC BY-SA 4.0
2018-07-31T02:30:27.470Z
There's quite a few "magic" numbers in your code, can you explain what the constants are used for ?
PaulHK
CC BY-SA 4.0
2018-07-31T21:56:38.453Z
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
Makogan
<opengl><rendering><global-illumination><voxelization>
Hard edges appearing in voxel cone tracing (how to remove them?)
Makogan
# Hard edges appearing in voxel cone tracing (how to remove them?)

(Asked by: username_0 on 2018-07-29)

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](https://i.sstatic.net/xGcQD.jpg)](https://i.sstatic.net/xGcQD.jpg)

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)
    {
        l=length(start-r);
        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;
}

```

**Tags:** opengl, rendering, global-illumination, voxelization

> **Comments:**
> **username_1**: There's quite a few "magic" numbers in your code, can you explain what the constants are used for ?  
> **username_0**: 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  

---

## 0 answers

