varying ambient light Topic is solved

Discussion area about developing with Ogre-Next (2.1, 2.2 and beyond)


jwwalker
Goblin
Posts: 247
Joined: Thu Aug 12, 2021 10:06 pm
Location: San Diego, CA, USA
x 18

varying ambient light

Post by jwwalker »

I'm aware that regular lights can be restricted to certain renderables using light masks, but is there any way to have different amounts of ambient light for different renderables?
User avatar
sercero
Bronze Sponsor
Bronze Sponsor
Posts: 479
Joined: Sun Jan 18, 2015 4:20 pm
Location: Buenos Aires, Argentina
x 167

Re: varying ambient light

Post by sercero »

As far as I know, you would probably have to solve it by using your own shaders.
User avatar
dark_sylinc
OGRE Team Member
OGRE Team Member
Posts: 5433
Joined: Sat Jul 21, 2007 4:55 pm
Location: Buenos Aires, Argentina
x 1341

Re: varying ambient light

Post by dark_sylinc »

No, there is not out of the box.

You could workaround the issue by using Render Queues (or scene visibility flags, but this is less efficient) and multiple pass scene passes.
And in between the passes, you change the ambient light.

Or else, customize the shaders.
jwwalker
Goblin
Posts: 247
Joined: Thu Aug 12, 2021 10:06 pm
Location: San Diego, CA, USA
x 18

Re: varying ambient light

Post by jwwalker »

Can you give me any hints on how to set up multiple scene passes, or where to find sample code illustrating that?
User avatar
dark_sylinc
OGRE Team Member
OGRE Team Member
Posts: 5433
Joined: Sat Jul 21, 2007 4:55 pm
Location: Buenos Aires, Argentina
x 1341

Re: varying ambient light

Post by dark_sylinc »

It's just two "pass render_scene" passes:

Code: Select all

	pass render_scene
	{
		load
		{
			all		clear
			colour	dont_care
		}
		store
		{
			all		dont_care
			colour	store_or_resolve
		}
		
		// kArbitraryId0
		identifier 101
		
		rq_first	0
		rq_last		5

		shadows		MyShadowNode
	}

	pass render_scene
	{
		skip_load_store_semantics true
		
		// kArbitraryId1
		identifier 102
		
		rq_first	5
		rq_last		199

		shadows		MyShadowNode reuse
	}
skip_load_store_semantics optimizes performance (Ogre 2.3+) by telling Ogre to keep rendering without flushing anything. The identifier is an arbitrary number you use to identify this pass in CompositorWorkspaceListener (so you know what to turn on and off)

rq_first and rq_last is how you tell Ogre what RQs to render

shadows "reuse" forces Ogre to reuse an already populated shadow node (Ogre should notice this automatically, but using reuse makes it explicit)
jwwalker
Goblin
Posts: 247
Joined: Thu Aug 12, 2021 10:06 pm
Location: San Diego, CA, USA
x 18

Re: varying ambient light

Post by jwwalker »

OK, so that quoted code is not C++, it's... what? What do I do with it? Sorry about my cluelessness. Normally when I'm trying to figure out how to do something, I look through the API docs, but this is going in a very different direction.
User avatar
dark_sylinc
OGRE Team Member
OGRE Team Member
Posts: 5433
Joined: Sat Jul 21, 2007 4:55 pm
Location: Buenos Aires, Argentina
x 1341

Re: varying ambient light

Post by dark_sylinc »

It's script code to setup in ".compositor".

You'll find lots of them in "Samples/Media/2.0/scripts/Compositors" and a few of them in "Samples/Media/2.0/scripts/materials".

Compositors tell Ogre how you want to render code. You create a compositor definition, and then instantiate it via CompositorManager::addWorkspace()

You can do it via C++ but it can be hard to setup (it's easier to set them up in script, then modify them in C++; rather than constructing them from scratch). If you truly want to construct them from scratch we have a few examples in Samples/2.0/Showcase/Postprocessing/Postprocessing.cpp (see PostprocessingGameState::createExtraEffectsFromCode)

Ignition is also constructing them in pure C++ in Ogre2RenderTarget::BuildCompositor
jwwalker
Goblin
Posts: 247
Joined: Thu Aug 12, 2021 10:06 pm
Location: San Diego, CA, USA
x 18

Re: varying ambient light

Post by jwwalker »

I decided to do it by shader customization. At the end of the DoAmbientLighting piece in AmbientLighting_piece_ps.any, I added a line:

Code: Select all

finalColour += material.userValue[2].xyz * pixelData.diffuse.xyz;
So I can modify an HlmsPbsDatablock to add "extra ambient light" for that material.