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

Stenciled Shadow volumes - after the shadows are rendered

2 posts in this topic

I have been following [url="http://ogldev.atspace.co.uk/www/tutorial40/tutorial40.html"]this tutorial [/url]carefully. Usually these tutorials are very clear but this one has me confused.

The main steps are handled in the RenderSceneCB() function. After setting up a few uniform variables for the shaders, it calls the 3 functions in sequence:

[code]

RenderSceneIntoDepth();
glEnable(GL_STENCIL_TEST);
RenderShadowVolIntoStencil();
RenderShadowedScene();

[/code]

You can find the definitions of each function in the tutorial-they're not that long.

First the entire scene is rendered (a box and a floor quad) depth-only.

Then the shadow-volumes are rendered which populates the stencil buffer based on when the depth-test fails for front and back faces. Cool. Makes sense.

The last bit confuses me. Take a look at the RenderedShadowScene() function:

[code]

void RenderShadowedScene()
{
glDrawBuffer(GL_BACK);
glDepthMask(GL_FALSE);
glStencilFunc(GL_EQUAL, 0x0, 0xFF);
m_LightingTech.Enable();
m_pointLight.AmbientIntensity = 0.0f;
m_pointLight.DiffuseIntensity = 0.8f;
m_LightingTech.SetPointLights(1, &m_pointLight);
m_pGroundTex->Bind(GL_TEXTURE0);
Pipeline p;
p.SetPerspectiveProj(m_persProjInfo);
p.SetCamera(m_pGameCamera->GetPos(), m_pGameCamera->GetTarget(), m_pGameCamera->GetUp());
p.WorldPos(m_boxPos);
p.Rotate(0, m_scale, 0);
m_LightingTech.SetWVP(p.GetWVPTrans());
m_LightingTech.SetWorldMatrix(p.GetWorldTrans());
m_box.Render();
p.Scale(10.0f, 10.0f, 10.0f);
p.WorldPos(0.0f, 0.0f, 0.0f);
p.Rotate(90.0f, 0.0f, 0.0f);
m_LightingTech.SetWVP(p.GetWVPTrans());
m_LightingTech.SetWorldMatrix(p.GetWorldTrans());
m_quad.Render();
}
[/code]

Mostly the real meat and potatoes happens in the first two calls I think. glDrawBuffer(GL_BACK) and glDepthMask(GL_FALSE). From my understanding. I have never scene the glDrawBuffer(GL_BACK) call before and the tutorial doesn't explain it. As for glDepthMask, my understanding here is that this means the depth test is still active, but writing new values does not occur.

Apart from not knowing what the point of glDrawBuffer(GL_BACK) is, I don't understand how the depth-test can work here. If the depth test is enabled, we should get Z-fighting, since "RenderSceneIntoDepth();" already filled the depth buffer. On the other hand, if we disable the depth buffer, than the pixels might be rendered out of order.

So confused... Edited by mv348
0

Share this post


Link to post
Share on other sites
Is [font=courier new,courier,monospace]glDrawBuffer(GL_NONE)[/font] used at some point to disable colour-writes? If so, then [font=courier new,courier,monospace]glDrawBuffer(GL_BACK)[/font] would re-enable colour-writes.
Yes, [font=courier new,courier,monospace]glDepthMask(GL_FALSE)[/font] disables depth-writes.
What is the depth comparison function at the time that [font=courier new,courier,monospace]RenderShadowedScene[/font] is called? If it's EQUAL or LEQUAL, then the scene will draw fine -- the depth values in this pass should be [i]exactly the same[/i] as the depth values written in the first pass, so there'll be no z-fighting.
1

Share this post


Link to post
Share on other sites
Thanks for that very prompt and clear response, Hodgeman! I saw your response earlier but didn't have time to respond until now.

I just have one more question on a slightly different area of this topic. The primitives that form the shadow volume in the above tutorial are created using the geometry shader, Each triangle given to the Geometry Shader comes paired with 3 neighboring vertices, and these are used to determine which of its edges are silhouette edges. These edges are projected (as a quad) an infinite distance behind the occluder and they form the 'sides' of the volume. The triangle (if front facing) is rendered at its present location and it forms part of the front cap of the volume, and another triangle (projected backwards) forms the back cap.

Makes sense. What I'm confused about is a small tweak used to avoid floating point inaccuracies. Here is the code from the Geometry Shader that creates the front cap:
[code]
// front cap
vec3 LightDir = (normalize(GSin[0].WorldPos - gLightPos)) * EPSILON;
gl_Position = gVP * vec4((GSin[0].WorldPos + LightDir), 1.0);
EmitVertex();
LightDir = (normalize(GSin[2].WorldPos - gLightPos)) * EPSILON;
gl_Position = gVP * vec4((GSin[2].WorldPos + LightDir), 1.0);
EmitVertex();
LightDir = (normalize(GSin[4].WorldPos - gLightPos)) * EPSILON;
gl_Position = gVP * vec4((GSin[4].WorldPos + LightDir), 1.0);
EmitVertex();
EndPrimitive();
[/code]

As you can see, the vertex is shifted slightly by a distance of EPSILON, in the direction of the light. I don't quite understand the need for this. The tutorial explains this tweak by stating:
[quote]The reason is that due to floating point errors we might encounter bizarre corruptions where the volume hides the front cap. Moving the cap away from the volume by just a bit works around this problem[/quote]

I don't really understand how the sides of the volume could hide the cap but even so, that would probably occur if the sides of the volume somehow got in front of the cap. But what this does is move the vertex along the vector from the light to the occluder, placing the cap deeper inside the volume, and so I would think this would only make matters worse.

Why exactly is that tweak needed and why does it work?
. Edited by mv348
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