• 9
• 10
• 11
• 13
• 9

# Deferred lighting

This topic is 2208 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

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.

##### 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.

##### 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")

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

##### Share on other sites
Also final color equation should be something like:
 finalColor = ambientLightAmount + diffuseLightAmount + specularLightAmount; 

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.

##### Share on other sites
hmm maybe that was my problem, I had something like

saturate(ambietlight + diffuselight)

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

##### Share on other sites

hmm maybe that was my problem, I had something like

saturate(ambietlight + diffuselight)

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

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.

##### 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.

##### 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.

Can you show us the shader you are using for this lighting equation, or try using the built in function "lit", only works in HLSL 2.0.
But usually the pixel shader looks something like this:
 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 ); 

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.

##### Share on other sites
well in my case its absolutely basic stuff

 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; } 

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.