• 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
newObjekt

Shadows Mapping - Triangle Casting Shadows On Self

10 posts in this topic

I've been researching and working on implementing shadow mapping into my engine. I've been following this tutorial pretty closely but I've run into an issue.

 

Here are some pictures to show exactly what is wrong:

Picture 1 - You can see the cat walks are casting shadows on the floor, but they are also casting shadows on the tops of themselves.

Picture 2 - Same as picture 1 with the depth FBO texture rendered in the corner.

Picture 3 - Rendering the game from the exact position that the light source is in.

 

I'm guessing I need to somehow compare the fragment depth of the shadow map with the fragment depth of the normal render and if the fragment depth of the render is <= the fragment depth of the shadow then I don't apply the shadow.

 

That's just my guess, I really don't know if I'm even on the right track. Advice would be greatly appreciated. smile.png

 

I can post the code related to the shadow mapping but its' basically identical to the linked tutorials code aside from the differences in Java and C++.

0

Share this post


Link to post
Share on other sites

I'm guessing I need to somehow compare the fragment depth of the shadow map with the fragment depth of the normal render and if the fragment depth of the render is <= the fragment depth of the shadow then I don't apply the shadow.

If you already use the shadow sampler (e.g. sampler2DShadow) , then the sampler already do comparision. The problem you encounters is quite common (self shadowing/shadow acne), besides other shadowmapping approaches, the most common trick is to use a bias. Your tutorial already handles these effects, therefor try to play around with given bias values.

Edited by Ashaman73
0

Share this post


Link to post
Share on other sites

I'm guessing I need to somehow compare the fragment depth of the shadow map with the fragment depth of the normal render and if the fragment depth of the render is <= the fragment depth of the shadow then I don't apply the shadow.

If you already use the shadow sampler (e.g. sampler2DShadow) , then the sampler already do comparision. The problem you encounters is quite common (self shadowing/shadow acne), besides other shadowmapping approaches, the most common trick is to use a bias. Your tutorial already handles these effects, therefor try to play around with given bias values.

 

 

        double bias[] = {    
            0.5, 0.0, 0.0, 0.0,
            0.0, 0.5, 0.0, 0.0,
            0.0, 0.0, 0.5, 0.0,
        0.5, 0.5, 0.5, 1.0};

 

Is this what you are talking about? How should I "play around them".

 

Or is the problem something to do with this?

		vec4 shadowCoordinateWdivide = ShadowCoord / ShadowCoord.w ;
	
		// Used to lower moiré pattern and self-shadowing
		shadowCoordinateWdivide.z += 0.0005;
	
	
		float distanceFromLight = texture2D(ShadowMap,shadowCoordinateWdivide.st).z * 2;
	
	
 		float shadow = 1.0;
 			if (ShadowCoord.w > 0.0)
 				shadow = distanceFromLight < shadowCoordinateWdivide.z ? 0.5 : 1.0;
	
  		gl_FragColor = shadow * texture2D(diffuseTexture, gl_TexCoord[0].st);
0

Share this post


Link to post
Share on other sites

Hello

// Used to lower moiré pattern and self-shadowing
shadowCoordinateWdivide.z += 0.0005;

The bias is the small value you add to the vertex's depth in order to (I quote you) lower moiré pattern and self-shadowing wink.png

Here it is 0.0005.

 

What was suggested was probably to try greater values

 

 

EDIT : answer to your ... next post tongue.png  : OK, sorry it cannot be so easy to fix !

Edited by Tournicoti
0

Share this post


Link to post
Share on other sites

Hello

// Used to lower moiré pattern and self-shadowing
shadowCoordinateWdivide.z += 0.0005;

The bias is the small value you add to the vertex's depth in order to (I quote you) lower moiré pattern and self-shadowing wink.png

Here it is 0.0005.

 

What was suggested was probably to try greater values

 

Yeah I tried playing with that value before I posted. I don't know if this issue is actually "self shadowing" though. The problem is that if a triangle casts a shadow, it also has the shadow cast on it. From what I read self shadowing is when you have back facing polygons being shadowed on the same model.

 

Just another note, the model that is casting the shadow is having the shadows cast on it. The map itself is one large OBJ of Hangemhigh I imported. I'm using old halo maps for testing :P

Edited by newObjekt
0

Share this post


Link to post
Share on other sites

Okay so I'm on the right track. I set the game to render from the same position as the light and I put in an if statement that compares the depth of the pixel in the ShadowMap with the depth of the pixel that's being rendered. If the Shadow depth is < the fragDepth then it doesn't apply the Shadow.

 

Heres the code and result:

http://inferno.codebrainshideout.net/Images/shadows%20d.png

		vec4 shadowCoordinateWdivide = ShadowCoord / ShadowCoord.w ;
	
		// Used to lower moiré pattern and self-shadowing
		shadowCoordinateWdivide.z += 0.0005;
	
		float shadowDepth = texture2D(ShadowMap,shadowCoordinateWdivide.st).z / texture2D(ShadowMap,shadowCoordinateWdivide.st).w;
		float fragDepth = (gl_FragCoord.z / gl_FragCoord.w)/2048;
		
		float distanceFromLight = texture2D(ShadowMap,shadowCoordinateWdivide.st).z * 2;
	
	
 		float shadow = 1.0;
 		 if (ShadowCoord.w > 0.0)
 			if (shadowDepth+0.0005 < fragDepth) //THIS IS THE NEW CHECK TO STOP SELF SHADOWING
 					shadow = distanceFromLight < shadowCoordinateWdivide.z ? 0.5 : 1.0;
	
  		gl_FragColor = shadow * texture2D(diffuseTexture, gl_TexCoord[0].st);

 

You can see the self shadowing is gone and from what I can tell the shadows are still being cast on the things they should.  The big problem is that I can't move the camera otherwise the gl_FragCoord is not going to be the same as the ShadowMap coord.

 

So I need to know how to transform the gl_FragCoord to face the light source in GLSL so I can compare the depths before applying a shadow.

Edited by newObjekt
0

Share this post


Link to post
Share on other sites

I think my current algorithm is to cull all away facing triangles so that ones facing the light render (just like normal rendering). I use a tiny glPolyGonOffset. This will make aliasing around  the triangles facing away from the light but thats ok because the dot-product between the light vector and the triangles normal will fill it in. Self shadowing won't happen.

0

Share this post


Link to post
Share on other sites

I think my current algorithm is to cull all away facing triangles so that ones facing the light render (just like normal rendering). I use a tiny glPolyGonOffset. This will make aliasing around  the triangles facing away from the light but thats ok because the dot-product between the light vector and the triangles normal will fill it in. Self shadowing won't happen.

 

I already have calls to glCullFace(GL_FRONT); and glCullFace(GL_BACK); in place.

I already have a working solution I just need a way to measure the distance from the fragment to the light source. *see my previous post*

 

Is there a way to transform the fragment to face the light or a way to transform the fragment to normal world space and then just do a normal distance test? Halp :(

0

Share this post


Link to post
Share on other sites

So after a couple more hours of bashing my head on the keyboard, grasping desperately for a solution I think I finally have it.

 

http://inferno.codebrainshideout.net/Images/shadows%20e.png

 

Now I need to find a way to smooth the shadows edges (possibly by blurring the edges of the shadow map)?

 

I ended up forcing shadows on fragments who's normal was facing away from the light. I had issues with shadow artifacts on triangles facing away from the light.

Edited by newObjekt
0

Share this post


Link to post
Share on other sites

I ended up forcing shadows on fragments who's normal was facing away from the light.


That is actually what I was saying.  Now do the other thing I said which is render into the shadow map with culling GL_BACK, so taht front facing triangles render into the shadow map, just like how normal rendering from the eye works. Then you wont have those awful bleeding spots around the areas touching the floor.
1

Share this post


Link to post
Share on other sites

I ended up forcing shadows on fragments who's normal was facing away from the light.


That is actually what I was saying.  Now do the other thing I said which is render into the shadow map with culling GL_BACK, so taht front facing triangles render into the shadow map, just like how normal rendering from the eye works. Then you wont have those awful bleeding spots around the areas touching the floor.

 Ah I see what you mean now. I"m culling GL_FRONT on the shadow FBO right now. I'll try that tomorrow morning first thing.

 

I rendered out a video with some different shadowing techniques that I tried. I'm getting closer to the results I want. Almost there.

http://www.youtube.com/watch?v=kTSFco8nKUU&feature=youtu.be

Edited by newObjekt
0

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