🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

Lighting works! Screenshot included

posted in IfThen Software
Published May 20, 2011
Advertisement
Lighting works! Per-pixel lighting was easier than I thought; it is literally just moving the lighting calculation from the vertex shader into the pixel shader.

If you want to learn how to do lighting, I recommend Real-Time Rendering, specifically chapter 5. From what I have seen, the book goes into great detail on the subject of lighting in later chapters as well.

I currently have experience with two types of lights: directional and omni. A directional light is basically a light which shines everywhere in one direction. Directional lights are commonly used for the sun, and other far-off light sources. An omni light is a type of point-light; it shines from a specific point in all directions. These would be used for things like torches, fireballs, sci-fi weapon projectiles, lamps without a shade, etc. There is another type of point-light called a "spotlight", which only shines within a specific set of directions (a cone).

Lighting requires two properties from a material: specular and diffuse. Currently, the specular property is constant over the entire model. Textures supply the diffuse property on a pixel-by-pixel basis, allowing the artist to finely tune how the model will look. A texture is pretty much a diffuse map.

Today I learned about a couple things you want to watch out for when setting shader constant registers. The first is that if you are passing in an array all in one call to Set*ShaderConstant*(), each array element must be packed to align with a 4-float/int boundary. I tried passing in an array where each element was a float3 and I was initially rather confused as to why it wouldn't work.

The second thing I would like to point out is that there is apparently a separate set of registers for integers. If you need to pass an integer to your shader, make sure you are using Set*ShaderConstantI() and not Set*ShaderConstantF(). This one took me a while to figure out, which was a little embarrassing.

grpg_screenshot2_sm.png

I am now researching shadows. Unfortunately, it appears as though creating shadows from omni lights is a bit of a black art... It involves creating 6 shadow maps and cube mapping with them or something. I should have more details tomorrow.

[size="1"]Reposted from http://invisiblegdev.blogspot.com/
Previous Entry Multiple animations
0 likes 2 comments

Comments

LordCovenant
You can do omni lights with 6 shadowmaps and cubemapping, but that's expensive... You might want to look into dual-paraboloid shadow maps (for example [url="http://graphicsrunner.blogspot.com/2008/07/dual-paraboloid-variance-shadow-mapping.html"]http://graphicsrunner.blogspot.com/2008/07/dual-paraboloid-variance-shadow-mapping.html[/url]). I've implemented this successfully in a couple of days...
The advantage of this is that you only have to render 2 shadowmaps (instead of 6)... And if you think about lighting in a game context and use a kind of hemisphere light (same as a omni, but with just one direction, like half a sphere), you can cut that down to only 1 shadowmap...

My implementation's results ends up being something like [url="http://www.youtube.com/watch?v=OhzO2pnDNnQ"]http://www.youtube.com/watch?v=OhzO2pnDNnQ[/url] . In that scene you have 100 lights, with dynamic updates (with a LOD algorithm), and with "soft shadowing" for the closer lights...
May 23, 2011 09:59 AM
Ashaman73
Congratulation on you progress :)

Shadows are really quite expensive, omni shadows even more, so you should consider this in your planing of adding shadows. If you plan to have lot of light sources, adding shadows to all light sources would be overkill. You need shadow to ground objects, that is the human brain need shadow information to know where a object is located in relation to other objects (i.e. a ball on the ground, without shadow it could appear to float above the ground).

But, you don't need to have physical correct shadows or shadows from every light source, a simple believable shadow from one virtual light source could be enough to ground your objects.

If shadow is a major gameplay aspect, try to concentrate on this (i.e. a torch hold by the player).

An other tip: to get rid of the over-saturation of your torch you should consider to add HDR+tonemapping and take a look at gamma correction.
May 24, 2011 11:23 AM
You must log in to join the conversation.
Don't have a GameDev.net account? Sign up!
Advertisement