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

Deferred lighting

28 posts in this topic

So every time I read deferred lighting/shadowing/techniques/what ever, the example always end up like a flashlight or a light bulb, and looks great if you are going to make a nice dungeon full of lights.

On with the questions.

when a directional deferred light is on, can it be like the sun, or its always like a flash light, and If I want it to behave like the sun, I need to put it a million miles away from target?

If I have a single deferred light as sun, how does it do global illumination?

How can I make that cool effect of a sun shining... (not the lens one, just like a glow in the sky)

tx.
0

Share this post


Link to post
Share on other sites
A directional light would typically be a light which just has a direction vector. Thus all rays emitted from the light source are considered to be parallel. The sun would be a typical example of a directional light.

A flashlight is typically a spotlight, which can be represented as a cone, or a set of nested cones for things like the penumbra.

Light bulbs tend to be point light sources, that is they are a source with a position that emit lights in all directions. However, you can treat many common "point" light sources as spotlights as well (inset lamps typically have a reflector on the backside to direct light that hits the back of the socket outwards). You can often represent point lights as spheres, with the radius of the sphere indicating the area that the light illuminates.

More importantly, in deferred rendering all lights can be seen as a form of geometry (with the exception of directional lights and global illumination/ambient). Thus any form of geometry you want can represent the light emitted by a source.

As for getting the bright blob in the sky... that's typically done through HDR.
1

Share this post


Link to post
Share on other sites
wow lots of info... ok, so the sun can be represented with a directional deferred light... now I have (yet) another question, if I have a cube, and I use normals for my sides, and I have a light pointing straight from up to down.

-my top side is bright and nice
-the sides seem kinda shaded, looks cool
-bottom is black.. not shaded, just plain old black.

Now I have what is supposed to be ambient light, shouldn't that ambient light give some color to the bottom of the cube?

example, it does not matters what I put as ambient light, it always turns out black (see bottom of "tree")

[attachment=7914:shaded test.png]
0

Share this post


Link to post
Share on other sites
You want to take the average of the face normals for smooth shading.
0

Share this post


Link to post
Share on other sites
Also final color equation should be something like:
[code]
finalColor = ambientLightAmount + diffuseLightAmount + specularLightAmount;
[/code]

This offcourse can change depending on textures and which lighting model you use but generally speaking thats the ammount of light for each pixel on the screen.
1

Share this post


Link to post
Share on other sites
hmm maybe that was my problem, I had something like

[CODE]saturate(ambietlight + diffuselight)[/CODE]

I'll give it a try, since saturate seems to normalize my values.
0

Share this post


Link to post
Share on other sites
[quote name='winsrp' timestamp='1332860457' post='4925680']
hmm maybe that was my problem, I had something like

[CODE]saturate(ambietlight + diffuselight)[/CODE]

I'll give it a try, since saturate seems to normalize my values.
[/quote]
No that equation is fine, the saturate just clamps the values between 0..1. Specular isn't always necessary and just adds a highlight anyway. You might want to check that your ambient light amount isn't zero or that your "normal dot lightVec" is positive. As soon as the light amounts go to negative this will show up as black in the color scene, especially when you saturate the values.
0

Share this post


Link to post
Share on other sites
seems tricky all this light stuff, in order to get a desent lighted scene, i had to do something like

saturate((diffuse/2)+ ambient) + ambient

really weird, all the other equations I tried end up with the bottom pitch black.

I'm also thinking that it might be best if I add like an if to the HLSL code to exclude the lighting when the normals are pointing down.
0

Share this post


Link to post
Share on other sites
[quote name='winsrp' timestamp='1333034165' post='4926364']
seems tricky all this light stuff, in order to get a desent lighted scene, i had to do something like

saturate((diffuse/2)+ ambient) + ambient

really weird, all the other equations I tried end up with the bottom pitch black.

I'm also thinking that it might be best if I add like an if to the HLSL code to exclude the lighting when the normals are pointing down.
[/quote]
Can you show us the shader you are using for this lighting equation, or try using the built in function "[url="http://msdn.microsoft.com/en-us/library/windows/desktop/bb509619(v=vs.85).aspx"]lit[/url]", only works in HLSL 2.0.
But usually the pixel shader looks something like this:
[code]
float3 normal = normalize(input.normal);
float3 lightVector = normalize(input.lightVector);
float ndotl = saturate( dot(normal, lightVector) ); //Saturate here is necessary to avoid the case where ndotl < 0 or when ndotl > 0
float4 diffuseLight = diffuseColor * ndotl;
float4 ambientLight = ambientLightColor * ambientLightStrength;
float4 color = saturate( ambientLight + diffuseLight );
[/code]

If in the above code ndotl = 0 then the resulting output light color is shaded by the ambient color unless it's strength factor is 0, only if both are 0 will black show up.
1

Share this post


Link to post
Share on other sites
well in my case its absolutely basic stuff

[CODE]

PixelToFrame Diffused_PixelShader( VertexShaderOutput input ) : COLOR0
{

float3 normal = normalize(cross(ddy(input.PosDummy), ddx(input.PosDummy)));

float4 diffuse1 = dot( DiffuseLightDirection, normal ) * DiffuseIntensity * DiffuseColor;

float4 ambient = AmbientIntensity * AmbientColor;

PixelToFrame Output = (PixelToFrame)0;
Output.Color = input.Color;
Output.Color.rgb *= saturate((diffuse1/2)+ambient) * ambient ;

return Output;
}
[/CODE]

I don't really understand much of what each line is doing (besides multiplying vectors), I really only know what my first line really does, as that was explained to me in another post.
0

Share this post


Link to post
Share on other sites
[quote name='winsrp' timestamp='1333083836' post='4926569']
well in my case its absolutely basic stuff

[CODE]

PixelToFrame Diffused_PixelShader( VertexShaderOutput input ) : COLOR0
{

float3 normal = normalize(cross(ddy(input.PosDummy), ddx(input.PosDummy)));

float4 diffuse1 = dot( DiffuseLightDirection, normal ) * DiffuseIntensity * DiffuseColor;

float4 ambient = AmbientIntensity * AmbientColor;

PixelToFrame Output = (PixelToFrame)0;
Output.Color = input.Color;
Output.Color.rgb *= saturate((diffuse1/2)+ambient) * ambient ;

return Output;
}
[/CODE]

I don't really understand much of what each line is doing (besides multiplying vectors), I really only know what my first line really does, as that was explained to me in another post.
[/quote]

You need to saturate your dot product to eliminate having areas go completely black with normals that point in the same direction as the light, this is way the bottoms of your trees go black. You do realise that for deffered shading you should create a G-buffer, which contains normal, albedo and other stuff you need when rendering the light?

This [url="http://xna-uk.net/blogs/randomchaos/archive/2008/11/11/basic-hlsl-lighting-techniques-episode-1-ambient-and-diffuse.aspx"]article[/url] will show you the basic directional light example in XNA, this is forward shading though, but the equations stay the same.
0

Share this post


Link to post
Share on other sites
well I made some changes to the code, following both your example and the example of the web page you referred, but it looks exactly the same.


[CODE]
float4 diffuse1 = DiffuseColor * dot(normal , normalize(DiffuseLightDirection * DiffuseIntensity) ) ;
float4 ambient = AmbientColor * AmbientIntensity ;
PixelToFrame Output = (PixelToFrame)0;
Output.Color = input.Color;
Output.Color.rgb *= saturate( ambient + diffuse1);[/CODE]

[attachment=7959:shaded test2.png]
0

Share this post


Link to post
Share on other sites
Ok, from your comments, it seems you're not sure what the math is doing.

You should probably pick up a good math book that explains vectors and matrices (I recommend "3D Math Primer for Graphics and Game Development", by Fletcher Dunn and Ian Parberry. I have Version 1, which is excellent. I can't comment on Version 2.

Start here, after you've got that book: [url="http://content.gpwiki.org/index.php/D3DBook:Table_of_Contents#Lighting"]Link[/url]
2

Share this post


Link to post
Share on other sites
[quote name='winsrp' timestamp='1333165232' post='4926861']
well I made some changes to the code, following both your example and the example of the web page you referred, but it looks exactly the same.


[CODE]
float4 diffuse1 = DiffuseColor * dot(normal , normalize(DiffuseLightDirection * DiffuseIntensity) ) ;
float4 ambient = AmbientColor * AmbientIntensity ;
PixelToFrame Output = (PixelToFrame)0;
Output.Color = input.Color;
Output.Color.rgb *= saturate( ambient + diffuse1);[/CODE]

[attachment=7959:shaded test2.png]
[/quote]
You are still forgetting to saturate the result of the dot operation. The dot product of a normal vector that's in the same direction as the light direction will end up being in between 0 .. -1. For light calculations you want to ignore the minus dot product values and just make them 0 so they don't contribute any diffuse light. if you then have one of these black pixels and add your ambient light value to it, you should end up with a darker looking patch that is not black. If there is no ambient light then the pixel should be black if diffuse light doesn't hit it.

The book narf recommended is really good to get to grips with what is going on in these calculations.
1

Share this post


Link to post
Share on other sites
night creature, that solution worked great, so light should be from 0 to 1... and saturate clams values from 0 to 1... and if a number tend to go way below 0 is hard to get them up to do something ... got it now.

the other question I have is, how come some areas are hard to be differentiated, I know I still need shadows but seems like something is still missing here.

look at center of the following image, you can hardly tell there are cubes here.

[attachment=7992:shaded test3.png]
0

Share this post


Link to post
Share on other sites
[quote name='winsrp' timestamp='1333383177' post='4927534']
night creature, that solution worked great, so light should be from 0 to 1... and saturate clams values from 0 to 1... and if a number tend to go way below 0 is hard to get them up to do something ... got it now.

the other question I have is, how come some areas are hard to be differentiated, I know I still need shadows but seems like something is still missing here.

look at center of the following image, you can hardly tell there are cubes here.

[attachment=7992:shaded test3.png]
[/quote]
Ok, so you are reading that book.Yaay. :)

I'd suggest attenuation, but directional lights don't have that, being just a direction and not a position. It's useful to know, though, so I'll go ahead and explain it.

Attenuation, in this context, is the reduction in light levels from being farther from the light. It is calculated as:
[code]
Attenuation = 1.0 / ( ( Constant ) + ( Linear * Distance ) + ( Quadratic * Distance * Distance ) )
[/code]
You then multiply this by your light colour. If you don't saturate attenuation, but do saturate the final light colour, near areas saturate to white. You may or may not want this automatic effect.

Now, to explain it, including the probably-obvious stuff, just to be thorough:
Constant provides a flat reduction (or increase, for less than 1.0) in light.
Linear divides your light by some multiple of distance. It provides a steady and quite useful reduction in light.
Quadratic is physically realistic; it mirrors the formula for energy "loss" over distance. It reduces your light by the square of the distance, multiplied by some value.
Distance is the distance to a vertex (for vertex lighting; much less accurate, but much faster) or a pixel (for pixel lighting; much more accurate, but much slower).

Put them all together and you have a complete equation for attenuation.

Now, what you're missing right now is probably fog. Simple fog works like this:
Position := CameraPosition
Attenuation := Attenuation formula
Colour := A float4 Colour.
Range := Anything beyond this doesn't need to be drawn.
On := a true/false switch.

Position is the center of your fog fading; this should be your camera position for most instances.

You then use that as follows:
Distance := Pixel/Vertex position - Fog.Position
Interpolation := Attenuation (we're going to use this to fade from easily visible to fogged).
Output.Colour := Saturate( (Colour you calculated * Interpolation ) + ( Fog.Colour * ( 1.0 - Interpolation ) ) )

This is an alpha interpolation for fog; as distance increases, attenuation will also (provided you set either Linear or Quadratic to a positive number) decrease.
Since interpolation is equal to attenuation, as distance increases, the final colour will be closer to your fog colour.
0

Share this post


Link to post
Share on other sites
the attenuation stuff seems great, but as you pointed out, I don't have distance, so I think I will be using this for when I do my point lights in the world.

Now on that fog topic, this will be making my colors blend to the fog color, and when the object are beyond my range, they will turn into the fog color, right? as distance increases the attenuation value should decrease making my color fade out
0

Share this post


Link to post
Share on other sites
[quote name='winsrp' timestamp='1333408215' post='4927686']
the attenuation stuff seems great, but as you pointed out, I don't have distance, so I think I will be using this for when I do my point lights in the world.

Now on that fog topic, this will be making my colors blend to the fog color, and when the object are beyond my range, they will turn into the fog color, right? as distance increases the attenuation value should decrease making my color fade out
[/quote]
Yep. It's not the most complex or detailed fog in the world, but it does the job and is used, even today.
0

Share this post


Link to post
Share on other sites
[quote name='winsrp' timestamp='1333383177' post='4927534']
night creature, that solution worked great, so light should be from 0 to 1... and saturate clams values from 0 to 1... and if a number tend to go way below 0 is hard to get them up to do something ... got it now.

the other question I have is, how come some areas are hard to be differentiated, I know I still need shadows but seems like something is still missing here.

look at center of the following image, you can hardly tell there are cubes here.

[attachment=7992:shaded test3.png]
[/quote]

I'd work through that book first to be honest, for light equations and a solid understanding of the math involved is necessary. Especially when spotlights, projected lights and shadows come along.
Having a solid understanding of 3D math will help as well when more advanced effects and shaders are presented to you.
0

Share this post


Link to post
Share on other sites
[quote name='NightCreature83' timestamp='1333410577' post='4927699']
[quote name='winsrp' timestamp='1333383177' post='4927534']
night creature, that solution worked great, so light should be from 0 to 1... and saturate clams values from 0 to 1... and if a number tend to go way below 0 is hard to get them up to do something ... got it now.

the other question I have is, how come some areas are hard to be differentiated, I know I still need shadows but seems like something is still missing here.

look at center of the following image, you can hardly tell there are cubes here.

[attachment=7992:shaded test3.png]
[/quote]

I'd work through that book first to be honest, for light equations and a solid understanding of the math involved is necessary. Especially when spotlights, projected lights and shadows come along.
Having a solid understanding of 3D math will help as well when more advanced effects and shaders are presented to you.
[/quote]
Thing is, if he practices what's in the book while reading it, it may stick better. Depends on how you learn.
0

Share this post


Link to post
Share on other sites
the problem with the book is that is applied to DX10, and I'm using DX9 since its XNA, so, somethings are useful and somethings are not.
0

Share this post


Link to post
Share on other sites
[quote name='winsrp' timestamp='1333412178' post='4927712']
funny that fog thing...

[attachment=8001:fog test1.png]
[/quote]
Looks like it's working. :)
[quote name='winsrp' timestamp='1333419055' post='4927737']
the problem with the book is that is applied to DX10, and I'm using DX9 since its XNA, so, somethings are useful and somethings are not.
[/quote]
Hmm...I didn't notice anything really specific to DirectX in it; do you have the second edition?
0

Share this post


Link to post
Share on other sites
not really I just clicked the link, and the first chapter is, what was Dx9 like, and what they killed in Dx10, and from that point on, its all dx10.1
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