• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0

Shadow Map Bias issue

5 posts in this topic

Recently I managed to get shadow mapping working within my application, however, a lot of the occluders are getting occluded, that is a LOT of self-shadowing


Now in my hlsl code I DO have a bias however it is simply NOT working. What I mean is no matter how much I increase or decrease the bias, the shadows stay static.


It seems like a bias value of 1 or 0 seem to only make a difference


    float2 projectTexCoord = float2(0.0f, 0.0f);
    float  bias            = 0.006f;
    float4 textureMap      = colorMap[0].Sample(colorSampler, texel.tex);
    float  lightIntensity  = 0.0f;
    float  depthValue      = 0.0f;
    float  lightDepthValue = 0.0f;
    float4 color           = float4(0.0f, 0.0f, 0.0f, 0.0f);
    float4 lightObject     = light[5].ambient;
    float4 specular        = float4(0.0f, 0.0f, 0.0f, 0.0f);
    bool   lightHit        = false;

    //Normal Mapping
    float4 bumpMap    = colorMap[1].Sample(colorSampler, texel.tex);
    bumpMap           = (bumpMap * 2.0f) - 1.0f;
    float bumpNormal = texel.norm + bumpMap.x * texel.tang + bumpMap.y * texel.binorm;
    float lightItensity2 = saturate(dot(bumpNormal, -1.5f));

    //Specular Mapping
    float3 reflection = normalize(2 * lightItensity2 * bumpNormal - light[5].dir);
    specular   = pow(saturate(dot(reflection, texel.viewDir)), 2.5f);
    specular += float4(0.02f, 0.02f, 0.06f, 0.0f);
    float4 specTex = colorMap[3].Sample(colorSampler, texel.tex);
    specular *= specTex;

    //Grab the lightPosition at the vertex
    texel.lightPos = light[5].dir.xyz - texel.wPos.xyz;
    texel.lightPos = normalize(texel.lightPos);

    // input.lpos.xyz /= input.lpos.w;

     //Create The texture coordinates for the projecting of the shadowMap
    projectTexCoord.x =  texel.lightViewP.x / texel.lightViewP.w  /  2.0f + 0.5f;
    projectTexCoord.y =  texel.lightViewP.y / texel.lightViewP.w / -2.0f + 0.5f;

    // Determine if the projected coordinates are in the 0 to 1 range.  If so then this pixel is in the view of the light
    if((saturate(projectTexCoord.x) == projectTexCoord.x) && (saturate(projectTexCoord.y) == projectTexCoord.y))

        // Sample the shadow map depth value from the depth texture using the sampler at the projected texture coordinate location.
        depthValue = colorMap[2].Sample(sampleTypeClamp, projectTexCoord).r;

        // Calculate the depth of the light.
        lightDepthValue = texel.lightViewP.z / texel.lightViewP.w;

        // Subtract the bias from the lightDepthValue.
        lightDepthValue = (lightDepthValue - bias);

        // Compare the depth of the shadow map value and the depth of the light to determine whether to shadow or to light this pixel.
        // If the light is in front of the object then light the pixel, if not then shadow this pixel since an object (occluder) is casting a shadow on it.
        if(lightDepthValue > depthValue)

             lightIntensity = saturate(dot(texel.norm, texel.lightPos));

            // Calculate the amount of light on this pixel.
            if(lightIntensity > 0.0f)

                lightObject = light[5].diffuse;
                color += float4(0.0f, 2.4f, 0.0f, 0.0f);

                lightHit    = true;

    float4 color2 = lightItensity2 * lightObject;
    color = saturate(color2 + lightObject) * textureMap;
    color = saturate(color + specular);

    //color += float4(0.5f, 0.0f, 0.0f, 1.0f);
    return color;


I just can't seem to figure this out. I tried working with the sampler, I tried to see if my depth shader was correct (it is). But I constantly get the same results of the self shadowing.


If someone could just point me in the direction UI should be looking to solve this problem I would be so grateful. Im just so lost right now.


And if anybody needs any code not shown here let me know


Any response will be appreciated


-Marcus Hansen



Share this post

Link to post
Share on other sites

Can you show an image of the issue?  If your depth bias isn't working, then it sounds like your transformation to light space is somehow not correct.  Is the shadowing working properly everywhere else?


Share this post

Link to post
Share on other sites

Thanks for the quick reply!




As you can see Im rendering the depthBuffer on a texture. If you notice I am not parsing the ground through the depth shader. The reason for that is the same as with the rest of the issues. Self-Shadowing. If i parse the ground through the shader (all the individual tiles with a mag of 2) it all gets self-shadowed like the brick hedges surrounding the level.


"Is the shadowing working properly everywhere else?"


Somewhat, the shadows do look nice, and do look like their doing their offset correctly.


I also checked the tile offset for my level generation, but it seemed to check out.


If you want I can post my light code.


Thanks for the quick reply! I needed some input before I went insane!


Marcus Hansen


Share this post

Link to post
Share on other sites

Any ideas?


Here is my code for setting up of the view and projection matrices for the light


light.pos     = XMFLOAT3(-90.0f, 60.0f, -25.0f);
light.diffuse = XMFLOAT4(0.18f, 0.18f, 0.50f, 0.4f);
light.ambient = XMFLOAT4(0.10f, 0.10f, 0.40f, 0.3f);
//View Matrix
XMFLOAT3 o = XMFLOAT3(90,10,-25.0f), up = XMFLOAT3(0,1,0);
XMVECTOR e = XMLoadFloat3(&light[5].pos), fp = XMLoadFloat3(&o), u = XMLoadFloat3(&up);
lView.lightView = XMMatrixLookAtLH( e, fp, u );
//Projection Matrix
fieldOfView = (float)3.14 / 4.0f;
screenAspect = 1024 / 768;

 // Create the projection matrix for the light.
lProj.lightProj = XMMatrixPerspectiveFovLH(fieldOfView, screenAspect, 0.1f, 1000.0f);
lView.lightView = XMMatrixTranspose(lView.lightView);
lProj.lightProj = XMMatrixTranspose(lProj.lightProj);


It seems to me like i'm missing one important step.


I setup a clamp sampler for the depthBuffer Texture


Marcus Hansen


Share this post

Link to post
Share on other sites

I realized that a less then operator was facing the wrong direction in  a condition (My Shader) and I switched it around. Now this is how my shadows look




Is this a problem with my depthTexture!?


Should I review my Creation of the DepthStencilView and Texture? Does the depthTexture look correct? (Im not rendering the ground until I reprimand the issue with the brick hedges)


I'm not looking for any solution to be handed to me, I just want input, I'm lost :p


Marcus Hansen


Share this post

Link to post
Share on other sites

I got it to work.


I had to tear apart the shader. Also I thought about it. I was creating a renderTargetView. I don't know why, maybe because rastertek did it. So I removed the RenderTargetView since I only needed depth.


And, before I had a pixelShader that only did a return. So I removed the PS and just set it as null in the pipeline.


I wonder which one of the above things was causing it to perform the severe amount of shadow ance. My guess is the shaders. Or having a renderTargetView for a pass where I only render depth.


Marcus Hansen


Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  
Followers 0