[2.1] Custom pass questions (Cubemaps & custom fields)

Discussion area about developing with Ogre2 branches (2.1, 2.2 and beyond)
Post Reply
al2950
OGRE Expert User
OGRE Expert User
Posts: 1214
Joined: Thu Dec 11, 2008 7:56 pm
Location: Bristol, UK
x 149

[2.1] Custom pass questions (Cubemaps & custom fields)

Post by al2950 »

Hi

I have recently ported a couple of custom passes from the old 1.x way of doing things to the new 2.x custom pass way, and its sooooo nice to use :D. However I have a couple of queries.

I need to use the custom pass while rendering a cubemap, however unlike render_scene there is no cubemap_reorient property. So I dont know if I should rotate the camera or not. There are a couple of ways to solve this and I would like your opinion
1) I could try a detect if the current render target is a cubemap, not 100% sure how to do this
2) Allow a custom pass access to the script properties

Now I have another issue where I would like to pass in a input texture to the custom pass, this could be done via code, however it would be nice to have the flexibility in the compositor script to do this. So option 2 becomes preferable. I thought we could add another parameter CompositorPassProvider::addPassDef that could contain script properties in the defined custom_pass

Any thoughts?

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

Re: [2.1] Custom pass questions (Cubemaps & custom fields)

Post by dark_sylinc »

Rotating the camera is the easy part:

Code: Select all

const Quaternion CubemapRotations[6] =
{
	Quaternion( Degree(-90 ), Vector3::UNIT_Y ),        //+X
	Quaternion( Degree( 90 ), Vector3::UNIT_Y ),        //-X
	Quaternion( Degree( 90 ), Vector3::UNIT_X ),        //+Y
	Quaternion( Degree(-90 ), Vector3::UNIT_X ),        //-Y
	Quaternion::IDENTITY,                               //+Z
	Quaternion( Degree(180 ), Vector3::UNIT_Y )         //-Z
};

const Quaternion oldCameraOrientation( mCamera->getOrientation() );
if( mDefinition->mCameraCubemapReorient )
{
	uint32 sliceIdx = std::min<uint32>( mDefinition->getRtIndex(), 5 );
	mCamera->setOrientation( oldCameraOrientation * CubemapRotations[sliceIdx] );
}

if( mDefinition->mCameraCubemapReorient )
{
	//Restore orientation
	mCamera->setOrientation( oldCameraOrientation );
}
Detecting whether it's a cubemap would be done when creating the instance. Grab the const CompositorChannel &target parameter, and look for target.textures[0]->getTextureType. Note that target.textures may be an empty vector even though target.target is not a null pointer.

The other solution (script properties) sounds nice. I think in fact the Scripting system does allow inserting your own parsing definitions (via registerCustomWordId; there might be listeners already in place too). However that system is a huge behemoth I do not dare to touch. It's only for the brave and courageous!.

al2950
OGRE Expert User
OGRE Expert User
Posts: 1214
Joined: Thu Dec 11, 2008 7:56 pm
Location: Bristol, UK
x 149

Re: [2.1] Custom pass questions (Cubemaps & custom fields)

Post by al2950 »

Damn it, I was close, but for some reason could not connect all the dots!

As for parsing the script nodes to custom pass def, I think it could be very useful, but yes that script code is not fun! Maybe ill take a look at it when I am feeling brave!

Thanks for the help

al2950
OGRE Expert User
OGRE Expert User
Posts: 1214
Joined: Thu Dec 11, 2008 7:56 pm
Location: Bristol, UK
x 149

Re: [2.1] Custom pass questions (Cubemaps & custom fields)

Post by al2950 »

dark_sylinc wrote: Detecting whether it's a cubemap would be done when creating the instance. Grab the const CompositorChannel &target parameter, and look for target.textures[0]->getTextureType. Note that target.textures may be an empty vector even though target.target is not a null pointer.
I thought this might come back to sting me. As the texture I am rendering to in this case is the 'RenderWindow' texture target.textures is an empty vector and I can not get the texture type from the target.target.

Any thoughts of how to solve?

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

Re: [2.1] Custom pass questions (Cubemaps & custom fields)

Post by dark_sylinc »

There is no way.

However it is a safe bet that if target.textures is empty we're dealing with a RenderWindow thus it's a 2D texture.

If target.textures is empty and the RenderTarget was a Cubemap/3D volume/whatever, then the right way to fix it is to use the CompositorManager2::addWorkspace overload that accepts a CompositorChannel instead of the overload that takes a RenderTarget when creating the workspace.

eg.

Code: Select all

CompositorChannel channel;
channel.target = myRenderTarget;
channel.textures.push_back( textureThatOwnsMyRenderTarget );
compoMgr->addWorkspace( sceneManager, finalRenderTarget, camera, "My Workspace", true );

al2950
OGRE Expert User
OGRE Expert User
Posts: 1214
Joined: Thu Dec 11, 2008 7:56 pm
Location: Bristol, UK
x 149

Re: [2.1] Custom pass questions (Cubemaps & custom fields)

Post by al2950 »

Ah, I see. Should have noticed that as that is how the cube mapping sample does it :oops:

Thanks again

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

Re: [2.1] Custom pass questions (Cubemaps & custom fields)

Post by dark_sylinc »

I can't blame you. The RenderTarget <-> texture model is from DX9 and it doesn't really map too well to modern APIs. Right now it's getting in the way for nice Vulkan/DX12 support, better UAVs, and MSAA + MRT support.

It may probably refactored for sure in Ogre 2.2 (that's a loooong time ahead)

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

Re: [2.1] Custom pass questions (Cubemaps & custom fields)

Post by dark_sylinc »

The UAV branch has been merged with the main one.

While it may not have been 100% ready, it was stable and thus unnecessary to keep them as separate branches. There are also two new samples showing the UAV. There may be a 3rd, more advanced UAV sample coming.

Also read about this update:
http://ogre3d.org/forums/viewtopic.php? ... 01#p520201

Post Reply