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

Light pre-pass problem

5 posts in this topic

[color=#4A4A4A]Okay, so I've set up a light pre-pass render system once before, except my new one is slightly different.[/color][color=#4A4A4A]
I'm trying to implement it without using a normal buffer. In theory this would work well for the toon-shaded game I'm making, except I've run into a problem.[/color]
[color=#4A4A4A]
When I render a pointlight (as a sphere) in the lighting pass, I'm sampling from the depth-map and comparing the sphere's depth.[/color][color=#4A4A4A]
Clipping any pixels from drawing where the scene is closer to the camera then the light. This sadly only works for one side of the point-light[/color]

[left][font="'Segoe UI"][size="2"][color="#4a4a4a"]BTW: I'm using XNA, but that's irrelevant to this problem... [/color][/size][/font][/left]
[color=#4A4A4A]
[CODE]
VertexShaderOutput VertexShaderFunction(VertexShaderInput input)
{
VertexShaderOutput output;

float4 worldPosition = mul(input.Position, World);
float4 viewPosition = mul(worldPosition, View);
output.Position = mul(viewPosition, Projection);

output.Depth = 1 - (viewPosition.z / viewPosition.w);

return output;
}

float4 PixelShaderFunction(VertexShaderOutput input, float2 screenSpace : VPOS ) : COLOR0
{
screenSpace /= float2(1280, 720);

float depth = tex2D(Depth, screenSpace);

clip(depth < input.Depth ? -1:1);

return LightColor;
}
[/CODE][/color]
[color=#4A4A4A]

When I render with this code, the clip function works as expected, but I don't know how to clip the sphere from lighting parts of the scene that are behind it, beyond it's reach.

Here's a pic showing that the depth behind the sphere isn't being taken into account:
The farthest cube shouldn't be receiving any light, and the plane shouldn't be shaded that mush in the rear.

[IMG]http://i443.photobucket.com/albums/qq151/link125552/Error1.png[/IMG]

Here's another picture showing the problem a bit more visibly. Top is the final image, bottom is the light buffer:

[IMG]http://i443.photobucket.com/albums/qq151/link125552/Error4.png[/IMG]


I think I'm just missing the last step for determining the influence the light has, but I just can't figure it out!
Any help would be greatly appreciated. :)[/color]
0

Share this post


Link to post
Share on other sites
Your problem is that your depth test is only one way: you're rendering the front faces of your sphere, and testing if those faces are closer than the depth in your depth buffer. To get the results you want, you would need to also do the reverse depth test on the back faces on the sphere. However you won't know the depth of the back faces when rendering the front faces, or vice versa.

Two solutions come to mind:[list=1]
[*]Use the depth value to reconstruct position, and then determine the distance from that position to the sphere's center. You can then clip out any pixels that have a distance > the sphere radius, or even fade out the light contribution as surfaces get further from the light center (which is how real light attenuation works).
[*]Render the backfaces first with color writes off and stencil writes on, and clip out any pixels where the depth buffer value is greater than the pixel depth. Then turn color writes on, stencil writes off, and stencil testing on, and render front faces the way you do right now. This will give you the results you were expecting.
[/list]
0

Share this post


Link to post
Share on other sites
I think I'll try solution 1, but despite my efforts I've yet to find an example of calculating world position that works with my depth buffer...

[color=#000000]output[/color][color=#666600].[/color][color=#660066]Depth[/color][color=#000000] [/color][color=#666600]=[/color][color=#000000] [/color][color=#006666]1[/color][color=#000000] [/color][color=#666600]-[/color][color=#000000] [/color][color=#666600]([/color][color=#000000]viewPosition[/color][color=#666600].[/color][color=#000000]z [/color][color=#666600]/[/color][color=#000000] viewPosition[/color][color=#666600].[/color][color=#000000]w[/color][color=#666600]);[/color]

I like the way I'm calculating Depth right now, as it returns a linear value from the camera, is there any way I can calculate the world position using this type of depth?
0

Share this post


Link to post
Share on other sites
z/w is actually very non-linear, but you can use it to reconstruct depth. Something like this should work:
[code]
float x = screenSpace.x * 2 - 1;
float y = (1 - screenSpace.y) * 2 - 1;
float z = 1.0f - depth;
float4 projectedPos = float4(x, y, z, 1.0f);
float4 worldPosition = mul(projectedPos, InvViewProjection);
worldPosition.xyz /= worldPosition.w;
[/code]

Where "InvViewProjection" is the inverse of View * Projection.
0

Share this post


Link to post
Share on other sites
Thanks, I got it!

Here's the code if anyone else runs into this problem:

Depth is now : Output.Position.z / Output.Position.w

[CODE]
screenSpace /= float2(1279.5, 719.5);
float lightDepth = input.Depth.x / input.Depth.y;
float sceneDepth = tex2D(Depth, screenSpace).r;
clip(sceneDepth > lightDepth || sceneDepth == 0 ? -1:1);
float4 H = float4(screenSpace.x * 2 - 1, (1 - screenSpace.y) * 2 - 1, sceneDepth, 1);
float4 D = mul(H, iViewProjection);
float4 worldPos = D / D.w;
clip( length(LightPosition - worldPos) > LightRadius ? -1:1);
return LightColor;
[/CODE]

Pic:

[IMG]http://i443.photobucket.com/albums/qq151/link125552/Fixed2.png[/IMG]
0

Share this post


Link to post
Share on other sites
I'm glad that you got it working! It actually looks better now that you're using position, since the light volumes look perfectly spherical rather than having polygonal edges.
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