Creating SSAO compositor node from code

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


Lax
Gnoll
Posts: 644
Joined: Mon Aug 06, 2007 12:53 pm
Location: Saarland, Germany
x 59

Creating SSAO compositor node from code

Post by Lax »

Hi dark_sylinc,

I'm trying to create the SSAO compositor node from C++ code and have some questions.

First:

Code: Select all

texture ssaoTexture target_width_scaled 0.5 target_height_scaled 0.5 PFG_R16_FLOAT depth_pool 0
  • How can I set, that the texure definition width/height is scaled 0.5 by targets width/height? Because I'm leaving it to 0, to get automatically the targets width/height.
  • How can I set the depth_pool to 0?
  • How can I set the msaa_auto flag in code?

Code: Select all

rtv rt0
{
	colour		rt0 gBufferNormals
	depth_stencil	depthTexture
}
  • How can I create 'rtv' rt0 via code?
  • How can I set the depth_stencil texture? Is this correct?

Code: Select all

rtv->depthAttachment.textureName = depthTexture;

Thanks in advance!

Best Regards
Lax

http://www.lukas-kalinowski.com/Homepage/?page_id=1631
Please support Second Earth Technic Base built of Lego bricks for Lego ideas: https://ideas.lego.com/projects/81b9bd1 ... b97b79be62

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: Creating SSAO compositor node from code

Post by dark_sylinc »

I'm not a fan of compositor nodes created from C++ if it can be avoided (it's much easier to modify one created in scripts from C++; than to create one from scratch).

But to answer your question, see PostprocessingGameState::createExtraEffectsFromCode in Samples/2.0/Showcase/Postprocessing/PostprocessingGameState.cpp.

All the questions you are asking are answred by setting texDef variables (e.g. widthFactor, depthBufferId set it to Ogre::DepthBuffer::POOL_NO_DEPTH which is 0.

Lax
Gnoll
Posts: 644
Joined: Mon Aug 06, 2007 12:53 pm
Location: Saarland, Germany
x 59

Re: Creating SSAO compositor node from code

Post by Lax »

I'm not a fan of compositor nodes created from C++ if it can be avoided (it's much easier to modify one created in scripts from C++; than to create one from scratch).

I'm neither, but unfortunately I need to activate/deactivate parts of compositor code at runtime. E.g. setting useHdr to false or activating planar reflections at runtime etc. I have lots of permutations, which I'm not able to stand only in compositor files.

But thanks, I will take a look there.

Best Regards
Lax

http://www.lukas-kalinowski.com/Homepage/?page_id=1631
Please support Second Earth Technic Base built of Lego bricks for Lego ideas: https://ideas.lego.com/projects/81b9bd1 ... b97b79be62

Lax
Gnoll
Posts: 644
Joined: Mon Aug 06, 2007 12:53 pm
Location: Saarland, Germany
x 59

Re: Creating SSAO compositor node from code

Post by Lax »

Hi,

I got some things working. But this one is hard:

Code: Select all

rtv rt0
{
	colour		rt0 gBufferNormals
	depth_stencil	depthTexture
}

Because I still have no idea how to create that. The SSAO_HS.compositor file has besides other things the following content:

Code: Select all

...
texture depthTextureCopy	target_width_scaled 0.5	target_height_scaled 0.5	PFG_D32_FLOAT
...

rtv rt0
	{
		colour			rt0 gBufferNormals
		depth_stencil	depthTexture
	}

target rt0
{
	pass render_scene
	{
		load
		{
			all				clear
			clear_colour	0	0.2 0.4 0.6 1
			clear_colour	1	0.5 0.5 1.0 1
		}
		lod_update_list	off
		overlays	off

		gen_normals_gbuffer true
	}
}

So I tried to create a render target view for rt0 and set rt0, gBufferNormals als colour attachment. I set depthTexture as depthStencil attachment. But then when I create a second time the render target view for rt0 in order to set the render_scene pass. I get an error, because the render target pass rt0 does already exist. Is this wrong in the compositor script?

I get also an error with the depthTextureCopy, because its no depth texture. I have no idea, how to make the texture to satisfy the isDepth flags.

Best Regards
Lax

http://www.lukas-kalinowski.com/Homepage/?page_id=1631
Please support Second Earth Technic Base built of Lego bricks for Lego ideas: https://ideas.lego.com/projects/81b9bd1 ... b97b79be62

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: Creating SSAO compositor node from code

Post by dark_sylinc »

Lax wrote: Tue Jan 10, 2023 11:22 am

I'm not a fan of compositor nodes created from C++ if it can be avoided (it's much easier to modify one created in scripts from C++; than to create one from scratch).

I'm neither, but unfortunately I need to activate/deactivate parts of compositor code at runtime. E.g. setting useHdr to false or activating planar reflections at runtime etc. I have lots of permutations, which I'm not able to stand only in compositor files.

Note that SSAO is something you can activate and deactivate without having to create its node programmatically!
Please see & analyze Postprocessing sample. It enables and disables various postprocessing effects on demand, without having to recreate it (the only thing it deals with are connections in the workspace definition).

I got some things working. But this one is hard:

To answer your question:

Code: Select all

// If addRenderTextureView fails, try ssaoDef->->getRenderTargetViewDefNonConstNoThrow( "rt0" );
RenderTargetViewDef *rtv = ssaoDef->addRenderTextureView( "rt0" );
RenderTargetViewEntry attachment;
attachment.textureName = "rt0";
rtv->colourAttachments.push_back( attachment );
attachment.textureName = "gBufferNormals";
rtv->colourAttachments.push_back( attachment );
rtv->depthAttachment.textureName = "depthTexture";

I get also an error with the depthTextureCopy, because its no depth texture.

What error do you get?

Cheers

Lax
Gnoll
Posts: 644
Joined: Mon Aug 06, 2007 12:53 pm
Location: Saarland, Germany
x 59

Re: Creating SSAO compositor node from code

Post by Lax »

Hi,

Note that SSAO is something you can activate and deactivate without having to create its node programmatically!
Please see & analyze Postprocessing sample.

Thats great! I orientated on the glass compositor effect. But failed setting the input and output properly.
See your SSAO compositor code:

Code: Select all

compositor_node SSAO_RenderNode
{
	in 0 rt_renderwindow

texture RT0				target_width target_height PFG_RGBA8_UNORM_SRGB		msaa_auto
texture gBufferNormals	target_width target_height PFG_R10G10B10A2_UNORM	msaa_auto explicit_resolve

texture depthTexture		target_width			target_height				PFG_D32_FLOAT msaa_auto
texture depthTextureCopy	target_width_scaled 0.5	target_height_scaled 0.5	PFG_D32_FLOAT

texture ssaoTexture target_width_scaled 0.5 target_height_scaled 0.5 PFG_R16_FLOAT depth_pool 0

texture blurTextureHorizontal	target_width target_height PFG_R16_FLOAT depth_pool 0
texture blurTextureVertical		target_width target_height PFG_R16_FLOAT depth_pool 0

rtv RT0
{
	colour			RT0 gBufferNormals
	depth_stencil	depthTexture
}

target RT0
{
	pass render_scene
	{
		load
		{
			all				clear
			clear_colour	0	0.2 0.4 0.6 1
			clear_colour	1	0.5 0.5 1.0 1
		}
		lod_update_list	off
		overlays	off

		gen_normals_gbuffer true
	}
}

target depthTextureCopy
{
	pass render_quad
	{
		load { all dont_care }
		material Ogre/Depth/DownscaleMax
    	input 0 depthTexture
	}
}

target ssaoTexture
{
	pass render_quad
	{
		load
		{
			all				clear
			clear_colour	1 1 1 1
		}
		material SSAO/HS
    	input 0 depthTextureCopy
		input 1 gBufferNormals

		quad_normals	camera_far_corners_view_space
	}
}

target blurTextureHorizontal
{
	pass render_quad
	{
		load { all dont_care }
		material SSAO/BlurH
		input 0 ssaoTexture
		input 1 depthTextureCopy
	}
}

target blurTextureVertical
{
	pass render_quad
	{
		load { all dont_care }
		material SSAO/BlurV
		input 0 blurTextureHorizontal
		input 1 depthTextureCopy
	}
}

target rt_renderwindow
{
	pass render_quad
	{
		load { all dont_care }
		material SSAO/Apply
		input 0 blurTextureVertical
		input 1 RT0
	}
	
	pass render_scene
	{
		lod_update_list	off

		//Render Overlays
		overlays	on
		rq_first	254
		rq_last		255
	}
}
}

And here the glass compositor:

Code: Select all

compositor_node Glass
{
	in 0 rt_input
	in 1 rt_output

custom_id Ogre/Postprocess

target rt_output
{
	pass render_quad
	{
		load { all dont_care }
		material Postprocess/Glass
		input 0 rt_input
	}
}

out 0 rt_output
out 1 rt_input
}

How can I change SSAO compositor, so that render scene is removed, because I use the render scene in a different compositor and just matter about the render_quad. How can I set the rt_input, rt_output for SSAO properly?

Could you help me out here?
Maybe you could adapt the SSAO compositor so that it also uses the rt_input and rt_output properly?

That would be great!

Best Regards
Lax

http://www.lukas-kalinowski.com/Homepage/?page_id=1631
Please support Second Earth Technic Base built of Lego bricks for Lego ideas: https://ideas.lego.com/projects/81b9bd1 ... b97b79be62

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: Creating SSAO compositor node from code

Post by dark_sylinc »

Sorry I forgot to reply!

I'm not sure what you want to do because there's a billion ways to approach this, and some approaches will make your life easier, others harder.

One way would be to split the nodes lin 2 ike this:

Code: Select all

compositor_node SSAO_RenderNode
{
	in 0 rt_renderwindow

texture RT0				target_width target_height PFG_RGBA8_UNORM_SRGB		msaa_auto
texture gBufferNormals	target_width target_height PFG_R10G10B10A2_UNORM	msaa_auto explicit_resolve

texture depthTexture		target_width			target_height				PFG_D32_FLOAT msaa_auto

rtv RT0
{
	colour			RT0 gBufferNormals
	depth_stencil	depthTexture
}

target RT0
{
	pass render_scene
	{
		load
		{
			all				clear
			clear_colour	0	0.2 0.4 0.6 1
			clear_colour	1	0.5 0.5 1.0 1
		}
		lod_update_list	off
		overlays	off

		gen_normals_gbuffer true
	}
}

out 0 RT0
out 1 gBufferNormals
out 2 depthTexture
}
	
compositor_node SSAO_RenderNodePART2
{
	in 0 RT0
	in 1 gBufferNormals
	in 2 depthTexture
	in 3 rt_renderwindow
	
target depthTextureCopy
{
	pass render_quad
	{
		load { all dont_care }
		material Ogre/Depth/DownscaleMax
    	input 0 depthTexture
	}
}

target ssaoTexture
{
	pass render_quad
	{
		load
		{
			all				clear
			clear_colour	1 1 1 1
		}
		material SSAO/HS
    	input 0 depthTextureCopy
		input 1 gBufferNormals

		quad_normals	camera_far_corners_view_space
	}
}

target blurTextureHorizontal
{
	pass render_quad
	{
		load { all dont_care }
		material SSAO/BlurH
		input 0 ssaoTexture
		input 1 depthTextureCopy
	}
}

target blurTextureVertical
{
	pass render_quad
	{
		load { all dont_care }
		material SSAO/BlurV
		input 0 blurTextureHorizontal
		input 1 depthTextureCopy
	}
}

target rt_renderwindow
{
	pass render_quad
	{
		load { all dont_care }
		material SSAO/Apply
		input 0 blurTextureVertical
		input 1 RT0
	}
	
	pass render_scene
	{
		lod_update_list	off

		//Render Overlays
		overlays	on
		rq_first	254
		rq_last		255
	}
}
}

workspace SSAOWorkspace
{
	connect SSAO_RenderNode SSAO_RenderNodePART2
	connect_output SSAO_RenderNodePART2 3
}

Now if you want to do something in the middle, the "best" way is something that needs some thought to see the simplest way.

Btw are you familiar with Blender's compositor nodes?
Even though we don't have such nice UI to interact them, they way our connections work is the same.

I suggest you try to follow one of the many tutorials available online to get the hang of it, just for the fun of it.

Once how it works "clicks" in your mind, you'll find a much easier time figuring out the best way to deal with compositor nodes in OgreNext.

Lax
Gnoll
Posts: 644
Joined: Mon Aug 06, 2007 12:53 pm
Location: Saarland, Germany
x 59

Re: Creating SSAO compositor node from code

Post by Lax »

Hi,

thanks for the information.
I know blender's compositor nodes. That is not the issue.
The issue is, that I try to manage all yet for me interesting Ogre sample effects. I already managed e.g. the following combinations

  • Backgroundscroll with several backgrounds + Hdr + MSAA + Reflection + Distoration + Glass ...

But SSAO is really hard to manage and combine with all other things. No matter what I do, I get just gray background. I think I will give it up for now.

Thanks anyway!
Best Regards
Lax

http://www.lukas-kalinowski.com/Homepage/?page_id=1631
Please support Second Earth Technic Base built of Lego bricks for Lego ideas: https://ideas.lego.com/projects/81b9bd1 ... b97b79be62

User avatar
Crystal Hammer
Gnome
Posts: 388
Joined: Sat Jun 23, 2007 5:16 pm
x 99

Re: Creating SSAO compositor node from code

Post by Crystal Hammer »

Hi Lax, check out my comment here: viewtopic.php?p=556758#p556758
I think I had the same issue.
I found out that this is bad for depth buffer (or depthTexture):
texDef->depthBufferFormat = Ogre::PFG_D32_FLOAT;
I needed this, to fix crash:
texDef->format = Ogre::PFG_D32_FLOAT;