Same node, different shadow node? Topic is solved

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


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

Same node, different shadow node?

Post by jwwalker »

I have multiple compositor workspaces, which often have the same first compositor node, but want to have different shadow nodes, depending on things like the number of shadow-casting lights and whether I want shadows at all. But I can't figure out a safe way to do that, since CompositorNodeDef and related classes don't have clone methods or copy constructors. And there's a documentation remark that "Modifying a NodeDef while it's being used by CompositorNode instances is undefined". Suggestions?

User avatar
dark_sylinc
OGRE Team Member
OGRE Team Member
Posts: 5476
Joined: Sat Jul 21, 2007 4:55 pm
Location: Buenos Aires, Argentina
x 1358

Re: Same node, different shadow node?

Post by dark_sylinc »

You would have to create one duplicate for each node with its own shadow node.

One solution is to keep the node as simple as possible (e.g. one render_scene pass) so that you can easily construct it from scratch in C++ and then use connections to plug it into other workspaces (one CompositorWorkspaceDef per shadow configuration, but those are easier to make).

e.g.

Code: Select all


// Constructed from scratch in C++
compositor_node SimpleNode01
{
	in 0 rt
	
target rt
{
	pass render_scene
	{
		shadows what_you_need
	} 
}

out 0 rt
}

// Pre-made in script.
compositor_node ComplexNodeBefore
{
...
}
compositor_node ComplexNodeAfter
{
...
}


// Constructed from scratch in C++
workspace Workspace01
{
	connect_output ComplexNodeBefore 0
	connect ComplexNodeBefore SimpleNode01
	connect SimpleNode01 ComplexNodeAfter
}

Another solution is to not do that at all, and in workspacePreUpdate you medde with CompositorShadowNode::setLightFixedToShadowMap to set all lights you want to cast shadow by hand (technically you can only set a few slots and let OgreNext figure out the rest, but you may run into some bugs or limitations, it's best if you just set them all).

You will have to set a shadow node large enough to support a maximum number of lights, and with that you have full control.

If you try to go with one shadow node definition per "need", you will run into many troubles. A shadow node that is large enough to flexibly handle all cases should be enough (or you can group your needs into categories, so that you have e.g. 2 or 3 shadow nodes for each need).

Is there a reason you want to go with personalized shadow nodes for each "need"?

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

Re: Same node, different shadow node?

Post by jwwalker »

dark_sylinc wrote: Sat Jun 17, 2023 3:34 pm

If you try to go with one shadow node definition per "need", you will run into many troubles. A shadow node that is large enough to flexibly handle all cases should be enough (or you can group your needs into categories, so that you have e.g. 2 or 3 shadow nodes for each need).

Is there a reason you want to go with personalized shadow nodes for each "need"?

One reason is that I don't know the maximum number of lights. Lights come and go depending on user actions. And at the same time there may be some windows in which I am not rendering any shadows, though maybe I could make a different simplified compositor for that case.

User avatar
dark_sylinc
OGRE Team Member
OGRE Team Member
Posts: 5476
Joined: Sat Jul 21, 2007 4:55 pm
Location: Buenos Aires, Argentina
x 1358

Re: Same node, different shadow node?

Post by dark_sylinc »

I'll rephrase: Why do you need multiple compositor workspaces with so many different shadow nodes at the same time?

Usually light setup is global (or per scene) and the usual approach is to take down all CompositorWorkspaces (not their definitions), edit the CompositorShadowNodeDef to support the new configuration and recreate the CompositorWorkspaces.

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

Re: Same node, different shadow node?

Post by jwwalker »

You say the light setup could be "per scene". Can I have two different scenes existing at the same time, using the same compositor setup except for different shadow nodes?

I'd also like to be able to have shadows completely disabled in some windows and not others, otherwise rendering the same stuff.

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

Re: Same node, different shadow node?

Post by jwwalker »

jwwalker wrote: Mon Jun 19, 2023 6:47 pm

I'd also like to be able to have shadows completely disabled in some windows and not others, otherwise rendering the same stuff.

What I came up with was to delve into the compositor workspace, find the CompositorShadowNode, and then call setEnabled on that. Seems to work.