Skip to content

Shadow contact issue in sample shadow-sapp.c #114

Description

@lazalong

Hi

There is a shadow contact issue in the sample shadow-sapp.c.
You see it when the cube is near the floor.
Compiled with gcc & VSCode

To show the issue just added a float variable cy to the state struct and the following lines at 218:

    state.cy += 0.01 * t;
    float fff = sin(state.cy) * 2 + 0.95;
    const hmm_mat4 translate = HMM_Translate(HMM_Vec3(0,fff,0));

c-shadows-sapp

Activity

  1. lazalong commented on Dec 12, 2022

    @lazalong
    Author

    In fact it can be 'fixed' by adding 0.001 to the depth at line 154 of shadow-sapp.glsl

    float depth = lightPos.z+0.001;

    But that is purely by trying instead of understanding what I am doing ahaha

  2. jknightdoeswork commented on Feb 15, 2025

    @jknightdoeswork
    Contributor

    I found this as well & had the same feeling of 'lol idk what im doing'.
    Then I studied it for like a week.

    I fixed it by using CULLMODE_FRONT on the shadow pass and adding a bias in the shader to get rid of self-shadowing

            float bias = max(0.008 * (1.0 - n_dot_l), 0.0005);
            sm_pos.z = sm_pos.z - bias;
    
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions