Multipass Lighting/Shading

Get answers to all your basic programming questions. No Ogre questions, please!
Post Reply
xTiming
Gnoblar
Posts: 17
Joined: Mon Feb 06, 2012 9:22 pm

Multipass Lighting/Shading

Post by xTiming »

Hey there,

I'm working on implementing multipass shading in a project I'm working on and I came across this thread from several years back which helped me out quite a bit in understanding what would be necessary for creating a multipass solution:

http://www.ogre3d.org/forums/viewtopic.php?f=10&t=32936

I wanted to ask a question about multipass shading however, more specifically something in the thread posted by Praetor:
Unlimited lights is just a nice flexible system. Obviously you just have to make sure you don't go crazy with it. I implemented this with a 2d engine recently, and Sinbad put in some nice facilities to support a similar technique in Ogre. Here's the strategy:

1. Do an ambient pass
2. Group lights together somehow (you're lucky, Ogre does this for you)
3. Run one pass per group of lights (I usually do 4 lights per pass, you can also use the diffuse texture here to properly light it)
4. *MAYBE* if you didn't feed the diffuse texture into the passes you need to modulate it onto the object here. Not as accurate, but does the trick.
The underlined part is what my question is about... I haven't been able to find much information on where the material's texture should be applied, e.g. which pass, before x, after y, etc. I was able to find an article here:
http://digital-lighting.150m.com/ch11lev1sec3.html
which outlined different types of passes and what should be included in them but it seems to be geared more towards passes in software like Maya or Blender. Is there even a difference between the passes used by these software solutions and the passes you would use in a material in Ogre?

Anyways back to the original question: where should the material's texture be applied if I have for example a texture being applied called "rock.png" (clarification that I'm not talking about a diffuse/specular texture or similar.) Should it be included in the ambient pass as the article above suggests, should it be saved for the end after everything else is done or is there another place it should be applied other than the two I mentioned?

If somebody could help me out it would be much appreciated since I haven't been able to find all that much information about it.
bstone
OGRE Expert User
OGRE Expert User
Posts: 1920
Joined: Sun Feb 19, 2012 9:24 pm
Location: Russia
x 201

Re: Multipass Lighting/Shading

Post by bstone »

Well, the render passes in Ogre sort of resemble what you read in that article. In general passes let you divide the render process for a material into multiple steps that build the result up with each pass. In addition to that Ogre can apply a special semantics to the passes: ambient, per-light, decal. These separate the rendering into three related illumination stages. That only happens if you enable additive shadows since that is required for accurate lighting with shadows.

The post you mentioned talks exactly about those different illumination stages. Even if you don't need shadows you can enable an additive shadow technique and then turn shadow casting off for your lights. The benefit is that Ogre will manage the lighting passes for you as was described by that underlined text.
xTiming
Gnoblar
Posts: 17
Joined: Mon Feb 06, 2012 9:22 pm

Re: Multipass Lighting/Shading

Post by xTiming »

Thanks for the reply!

So I'm assuming I would want any ambient lighting to occur in the ambient pass and then the per-light would have my light dependent lighting/shadow shaders, which would of course change depending on the type of light it is? If this is right, would that leave the decal pass to handle any textures my object may have such as the "rock.png" I mentioned earlier?

Also when I use setLightCountPerIteration does this just mean you're using a per-light pass (assuming of course setIteratePerLight( true ) was called,) but putting more than one light into each pass, or is there some different stage which would be used in that situation?

Thanks again, much appreciated.
bstone
OGRE Expert User
OGRE Expert User
Posts: 1920
Joined: Sun Feb 19, 2012 9:24 pm
Location: Russia
x 201

Re: Multipass Lighting/Shading

Post by bstone »

Yeah, in its simplest form the multipass rendering would be: accumulate ambient light in the ambient pass, accumulate per-light lighting in the per-light pass, multiply the total light by the diffuse texture in the decal pass. That's the simplest and the cheapest option but not very accurate as long as you're concerned with the specular component.

In order to factor in the specular lighting properly you have to get your diffuse textures into the per-light pass so that you can calculate the diffuse and specular lighting component independently and then superimpose them. You don't need the decal pass in this case unless you have some effects that could go there.

setLightCountPerIteration() controls how much lights your shader can handle at once. The more the value the less passes will be rendered in the end.
xTiming
Gnoblar
Posts: 17
Joined: Mon Feb 06, 2012 9:22 pm

Re: Multipass Lighting/Shading

Post by xTiming »

Ok, I understand a little better now. I guess I have one more question for the moment - the diffuse texture you referred to.. Is that a texture for determining which parts of an object should be lit with diffuse lighting only? Or is "diffuse texture" the term you're using to refer to the texture that gives the material it's skin, like "rock.png" that I keep mentioning as an example?
bstone
OGRE Expert User
OGRE Expert User
Posts: 1920
Joined: Sun Feb 19, 2012 9:24 pm
Location: Russia
x 201

Re: Multipass Lighting/Shading

Post by bstone »

The latter.
xTiming
Gnoblar
Posts: 17
Joined: Mon Feb 06, 2012 9:22 pm

Re: Multipass Lighting/Shading

Post by xTiming »

Alright, thanks a lot for the help. The information is very useful.
Post Reply