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

Volumetric Light Scattering (help)

8 posts in this topic

I'm trying to implement the following screen-space based technique into my renderer but am having trouble getting it to work.

[url="http://http.developer.nvidia.com/GPUGems3/gpugems3_ch13.html"]http://http.develope...gems3_ch13.html[/url]

Unfortunately I don't have access to the book's demo code but afaik there's nothing more "special" going on than what is written there.

The shader is rather simple and short though it seems I'm still doing something wrong here:
[code]
// 2D Vector
extern float2 GBufferTextureSize;
// 3D Vector
const float3 LightPos = float3(0.0f, -1.0f, 1.0f);

// Matrices
float4x4 WVP;
// Sample our Composite Scene
sampler2D SceneSampler : register(s0);

// Constants
const int NUM_SAMPLES = 16;
float Density = 0.8f;
float Weight = 0.9f;
float Decay = 0.5f;
float Exposure = 0.5f;

struct VSI_VolLightScattering
{
float4 Position : POSITION0;
float2 UV : TEXCOORD0;
};

struct PSI_VolLightScattering
{
float4 Position : SV_POSITION;
float2 UV : TEXCOORD0;
float4 ScreenLightPos : TEXCOORD1;
};





PSI_VolLightScattering VolumetricLightScattering_VS(VSI_VolLightScattering input)
{
PSI_VolLightScattering output = (PSI_VolLightScattering)0;
output.Position = float4(input.Position.xy, 1, 1);
output.UV = input.UV + GBufferTextureSize;
output.ScreenLightPos = mul(LightPos, WVP);
return output;
}





float4 VolumetricLightScattering_PS(PSI_VolLightScattering input) : COLOR0
{
half2 ssPos = input.ScreenLightPos.xy / input.ScreenLightPos.w * float2(0.5, -0.5) + 0.5;
half2 deltaTexCoord = (input.UV - ssPos);
deltaTexCoord *= 1.0f / NUM_SAMPLES * Density;
half3 color = tex2D(SceneSampler, input.UV);
half illuminationDecay = 1.0f;
for(int i = 0; i < NUM_SAMPLES; i++)
{
input.UV -= deltaTexCoord;
half3 Sample = tex2D(SceneSampler, input.UV);
Sample *= illuminationDecay * Weight;
color += Sample;
illuminationDecay *= Decay;
}

return float4(color.rgb * Exposure, 1);
}


[/code]

In engine it looks like this:
[url="http://cl.ly/3J0r241G2e0J200P1i3b"]http://cl.ly/3J0r241G2e0J200P1i3b[/url]

It's just blurring the whole screen.


Did anyone implement this technique or can help me in any way ?

Also, I'm using a pow approach on my skydome to fake a sun, how would that translate to the Light's Position in my shader here (directional light)?
0

Share this post


Link to post
Share on other sites
Well, asides the shader it actually does one more important step, rendering a darkened scene. Everything not black will result in blur streaks, into a specific direction (usually towards or away from the sun or another dominent lightsource). So if you apply the shader on a normal colored scene, everything will blur. Just render the scene black, a darkish color for the skybox eventually, and a bright (flare)sprite for the sun. Also reduce your "density" factor to shorten the blurstreaks.Now it seems as if the loop takes quite big steps when adding "deltaTexCoord" to the sample UV. If it keeps going wrong, triple check the lightPos and vectors. I remember that went wrong in my case :D
1

Share this post


Link to post
Share on other sites
I just use the scene texture (being the final rendered scene) and read that in my scattering shader and output it to a fullscreen quad. How would I draw this "black" scene first ?
Do I just make the input black ? I'm a little confused on how to do this technique using a deferred renderer.

Rendering to a fullscreen quad I also would not have access to the light's world matrix.
0

Share this post


Link to post
Share on other sites
There are several ways. One straight forward way is to render the scene again in a background pass, on a texture target. But very simple only:
- Clear the screen with the color that represents the skybox light (black, or a dark color as well)
- Render the scene geometry, but just output black pixels (no textures, no lighting, no nothing)
- Render the lightsource sprite/flare(s) <- btw, you may want to render the sprite bigger as usual to make sure you got some pixels to blur

Another way is to store a bit extra data in the alpha channel while doing your main render. IF you have that channel available that is. In the RGB you store colors as always, then in the alpha you store the blur intensity. Black means nothing, white means maximum blur. So typically the skybox outputs a low or 0 value to the alpha, the geometry 0, and the flare(s) a relative high value. Then your post-blur shader, simply multiply the input texture color like this:


[color=#000000]half4 [/color][color=#660066]Sample[/color][color=#000000] [/color][color=#666600]=[/color][color=#000000] tex2D[/color][color=#666600]([/color][color=#660066]SceneSampler[/color][color=#666600],[/color][color=#000000] input[/color][color=#666600].[/color][color=#000000]UV[/color][color=#666600]).rgba;
[/color] sample.rgb *= sample.a;
[color=#000000] [/color][color=#660066]Sample[/color][color=#000000] [/color][color=#666600]*=[/color][color=#000000] illuminationDecay [/color][color=#666600]*[/color][color=#000000] [/color][color=#660066]Weight[/color][color=#666600];[/color]
1

Share this post


Link to post
Share on other sites
[quote]

[b] 13.5.1 The Occlusion Pre-Pass Method[/b]

[color=#000000][font=Verdana, Geneva, Arial, Helvetica,]If we render the occluding objects black and untextured into the source frame buffer, image processing to generate light rays is performed on this image. Then the occluding scene objects are rendered with regular shading, and the post-processing result is additively blended into the scene. This approach goes hand in hand with the common technique of rendering an unshaded depth pre-pass to limit the depth complexity of fully shaded pixels. [/font][/color][url="http://http.developer.nvidia.com/GPUGems3/gpugems3_ch13.html"]Figure 13-3[/url][color=#000000][font=Verdana, Geneva, Arial, Helvetica,] shows the steps involved.[/font][/color]
[/quote]

You can also use your deferred render's depth texture instead of re-rendering everything.

I don't think you need to render the light source either. You know your light source's screen space position, so you can take that into account along with the depth buffer occlusion.
0

Share this post


Link to post
Share on other sites
So do I understand that right, I draw my whole scene just black + something bright which I then input to the shader above. And this shader blurs the picture (which would be just the light source), stretches that blurred image somehow to the light position and adds that to my "normal" scene?

And that black geometry is drawn to a seperate RT (let's call it BlackTarget), which then gets the shader applied and outputs the finished image ? ("normal" scene + Light shafts?)

Btw using the deferred lighting (Light pre pass) way I already have to render my geometry a second time. So I'm currently using a second renderTarget output in there to just output everything black in there. That should work right ?

[b]update: video deleted* (forgive the music ^^)[/b]
0

Share this post


Link to post
Share on other sites
[b]>> So do I understand that right, I draw my whole scene just black + something bright which I then input to the shader above. And this shader blurs the picture (which would be just the light source), stretches that blurred image somehow to the light position and adds that to my "normal" scene[/b]
That's pretty much it indeed. The GPU Gems example also slightly lits the environment with the same lightsource, but just try it with a black scene first for ease. The blur streaks towards (or from) the lightsource screen position is an important element. And it seems that goes wrong in your case. Wrong coordinates probably. I remember my first attempt calculated the screen positions all wrong.

As a first test, I would test the inputUV and density setting. If deltaTexCoord keeps 0, you should get an unblurred copy of the original input, If not, the input.uv value is wrong. It seems the blur goes into exactly the wrong direction, with too big steps. What happens if you inverse the deltaTexCoord and make it 10 times smaller? If it keeps weird, double check ssPos.


[b]>> And that black geometry is drawn to a seperate RT (let's call it BlackTarget), which then gets the shader applied and outputs the finished image ? ("normal" scene + Light shafts?[/b]
That's an option. The finished imagine can be added to the other results with an additive blend. Though render it to a separate target requires to render the entire environment twice. You said you are using a deferred pipeline. I would try to reserve a value into of those textures indeed and use that texture as input for the lightscatter shader.
0

Share this post


Link to post
Share on other sites
You mean setting deltaTexCoord to 0 ? If I do that I get an unblurred standard scene image.
Also negating and scaling it doesn't make it look much better.

I'm not quite sure how to get the position of my sun, which is just done in a seperate shader like this:
[code] // Calculate Sun
float3 Normal = normalize(input.PositionOS);
float3 Sun = normalize(vSunPos);
float sunDot = dot(Sun, Normal);
float4 sunVector = 1000.0f * pow(max(0, sunDot), 350.0f);
[/code]

This is being applied to my skydome geometry.
0

Share this post


Link to post
Share on other sites
Setting the delta to 0 means an unblurred result indeed, but did you test that? To make sure original UV coordinates are ok. Try to elimate all possible errors. Most likely one or more coordinates aren't properly converted to screen space.

The way how the sun position and vector are calculated seem odd to me, but I'm not a matrix-math hero. But what you really want to know are the 2D screen coordinates of the sun, and the 2D direction vectors between the rendered pixels and that sun. First make sure you have that sun position correct before going to blur. In case you render your screen quad that does the post effect with corner coordinates in the range of -1..+1, the sunPosition should be somewhere in that range too. Here's an article (also doing blur as post effect) that explains some code that also converts world-positions to screen points:
[url="http://http.developer.nvidia.com/GPUGems3/gpugems3_ch27.html"]http://http.developer.nvidia.com/GPUGems3/gpugems3_ch27.html[/url]
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