[2.1] Stencil buffer over compositor nodes

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


Frankincense
Kobold
Posts: 33
Joined: Mon May 05, 2014 5:36 pm
x 3

[2.1] Stencil buffer over compositor nodes

Post by Frankincense »

Hi all,

I am looking to write to the stencil buffer in my main render compositor node and then use it again in following compositor nodes using 'pass stencil'. It looks like the stencil buffer is not shared between the compositor nodes though, or at least it seems to be empty when reading it in the second compositor node I am using - is the stencil buffer not accessible from following compositor nodes?

I am not performing any explicit 'pass clear's apart from at the very start of the render chain.
I have seen in examples that the depth/stencil buffer can be written to directly using the depth_pool ID, but I don't believe that will help me when I want to read from it using a 'pass stencil'
Frankincense
Kobold
Posts: 33
Joined: Mon May 05, 2014 5:36 pm
x 3

Re: [2.1] Stencil buffer over compositor nodes

Post by Frankincense »

I had a go with RenderDoc to see if I could see when the stencil buffer was cleared, but I believe as I don't explicitly use it as a texture I can't view the stencil buffer as its being written to
User avatar
lingfors
Hobgoblin
Posts: 525
Joined: Mon Apr 02, 2007 12:18 am
Location: Sweden
x 79

Re: [2.1] Stencil buffer over compositor nodes

Post by lingfors »

Could you share some code of your compositor setup?

Also, just to make sure. I believe "pass stencil" is just a place to set up the stencil settings, it doesn't actually render anything. So I assume you have a "pass render_scene" or similar after your "pass stencil"
Frankincense
Kobold
Posts: 33
Joined: Mon May 05, 2014 5:36 pm
x 3

Re: [2.1] Stencil buffer over compositor nodes

Post by Frankincense »

lingfors wrote: Tue Oct 13, 2020 11:09 am Could you share some code of your compositor setup?

Also, just to make sure. I believe "pass stencil" is just a place to set up the stencil settings, it doesn't actually render anything. So I assume you have a "pass render_scene" or similar after your "pass stencil"
Sure, here is the main render compositor_node:

Code: Select all

compositor_node TestRender
{
	in 0 rt_renderwindow

	texture rtt 				target_width target_height PF_R8G8B8A8 PF_FLOAT32_RGBA PF_FLOAT32_RGBA depth_format PF_D32_FLOAT_X24_S8_UINT depth_texture depth_pool 1
	texture rtt_depthbuffer	target_width target_height PF_D32_FLOAT_X24_S8_UINT depth_pool 1

	target rtt
	{
		pass clear
		{
			colour_value 0 0 0 1
			depth_value 1.0
			stencil_value 0

			buffers colour depth stencil
		}

		pass stencil
		{
			check true

			ref_value	1
			mask			0xFFFFFFFF
			read_mask	0xFFFFFFFF

			both
			{
				comp_func		always_pass
				pass_op			replace
				depth_fail_op	replace
				fail_op			replace
			}
		}

		pass render_scene
		{
			overlays	off
			shadows	ShadowMapFromCodeShadowNode

			rq_first	0
			rq_last	21
		}


		pass stencil
		{
			check true

			ref_value	1
			mask			0xFFFFFFFF
			read_mask	0xFFFFFFFF

			both
			{
				comp_func		equal
				pass_op			keep
				depth_fail_op	keep
				fail_op			keep
			}
		}

		pass render_scene
		{
			overlays	off
			shadows	ShadowMapFromCodeShadowNode

			rq_first	50
			rq_last	61
		}


		pass stencil
		{
			check false
		}

		pass render_scene
		{
			overlays	on
			shadows	ShadowMapFromCodeShadowNode

			rq_first	70
			rq_last	255
		}
	}

	target rt_renderwindow
	{
		pass render_quad
		{
			material Ogre/Copy/4xFP32
			input 0 rtt 0
		}
	}

	out 0 rtt
	out 1 rtt_depthbuffer
}
And the second compositor_node that I would like to also read from the stencil buffer:

Code: Select all

compositor_node TestWrite
{
	in 0 rtt
	in 1 rtt_depthbuffer
	in 2 rt_renderwindow

	target rt_renderwindow
	{
		pass stencil
		{
			check true

			ref_value	1
			mask			0xFFFFFFFF
			read_mask	0xFFFFFFFF

			both
			{
				comp_func		equal
				pass_op			keep
				depth_fail_op	keep
				fail_op			keep
			}
		}

		pass render_quad
		{
			material Fog
			input 0 rtt 1
		}
	}
}
So for the quad rendered by TestWrite, the stencil buffer appears to always be cleared
User avatar
dark_sylinc
OGRE Team Member
OGRE Team Member
Posts: 5446
Joined: Sat Jul 21, 2007 4:55 pm
Location: Buenos Aires, Argentina
x 1348

Re: [2.1] Stencil buffer over compositor nodes

Post by dark_sylinc »

The render window has its own special depth buffer which cannot be shared with regular depth buffers.

Thus the last pass in TestWrite will be reading from a different render window.
I'm afraid to workaround this issue you'll have to render your fog pass to an internal RTT and then copy the final result to the window.
Frankincense
Kobold
Posts: 33
Joined: Mon May 05, 2014 5:36 pm
x 3

Re: [2.1] Stencil buffer over compositor nodes

Post by Frankincense »

dark_sylinc wrote: Tue Oct 13, 2020 5:09 pm The render window has its own special depth buffer which cannot be shared with regular depth buffers.

Thus the last pass in TestWrite will be reading from a different render window.
I'm afraid to workaround this issue you'll have to render your fog pass to an internal RTT and then copy the final result to the window.
Ah OK, that makes sense - is there a way of rendering to a single channel of an MRT? It sounds like something that wouldn't be possible, but if it is that would simplify having to use another separate texture
User avatar
dark_sylinc
OGRE Team Member
OGRE Team Member
Posts: 5446
Joined: Sat Jul 21, 2007 4:55 pm
Location: Buenos Aires, Argentina
x 1348

Re: [2.1] Stencil buffer over compositor nodes

Post by dark_sylinc »

In Ogre 2.2 it is possible to separate an MRT target (or even put the same rtt into different MRT sets)

However that is not possible in 2.1 (this is one of the reasons of the texture refactor in 2.2, no API ever imposed this restriction yet Ogre 2.1 and older treated MRT targets as special)

The render window still cannot share its depth buffer or be part of an MRT set in 2.2 though (some APIs have this restriction)