Multipass rendering per Camera Topic is solved

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


User avatar
bishopnator
Goblin
Posts: 299
Joined: Thu Apr 26, 2007 11:43 am
Location: Slovakia / Switzerland
x 11

Multipass rendering per Camera

Post by bishopnator »

Hi, I am trying to figure out how to "simply" setup the rendering in ogre-next to get the proper output for my meshes. Current rendering using another library which is closer to ogre 1.x than ogre-next supports the multipass rendering and a single material can contain multiple configurations (each with its own setup of mutlipass rendering if needed). Let's consider a single box with material like:

  1. configuration A renders mesh with a single pass (VS + PS)
  2. configuration B renders mesh with 2 passes:
    • render triangles with shaded output (e.g. like HlmsPbs)
      • render mesh using GS to convert triangles to lines
  3. etc - for the sake of example it is enough 2 configurations :-)

Let's have camera 1 which renders box with configuration A and camera 2 with the configuration B. According to viewtopic.php?t=96902 it is necessary to create 2 instances of Ogre::Item to support 2-pass rendering as required by the material. So by the first camera it is necessary to hide one of the instances and keep only second instance.

Is it really the proper way? It just sounds too complex compared to Ogre 1.x. Through the Hlms::preparePassHash it is possible to select desired shaders according to the camera/compositor for each instance of Ogre::Item/SubItem, but then it is necessary to handle also visibility of the objects. Let's consider that I would like to have a class "rendering style / render mode" which I can set to the window - this defines how the objects are rendered in the window (it can be like "shaded" output (let's say same as HlmsPbs), "shaded" with edges (HlmsPbs + my own Hlms to output edges from the mesh), shaded with "thick" edges (HlmsPbs + 2 passes (thin edges + thick edges), hidden lines, etc.) - if I insert new object to the scene, I have to check the maximum number of passes needed by any possible rendering and insert the Ogre::Item so many times as number of rendering passes are required. Then per camera and its render mode setup the visibility flags of the Ogre::Item instances, etc.

What will be more suitable in my case, is to have still single Ogre::Item (and its Ogre::SubItem instances) in the SceneManager and somewhere during populating RenderQueue allow to insert multiple instance (multipass) of the same Datablock but with different properties active to create shaders through Hlms. I didn't check deeper the implementation of SceneManager/RenderQueue whether such "dynamic" multipass rendering is feasible, but only thinking loud the ideas..

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: Multipass rendering per Camera

Post by dark_sylinc »

Is it really the proper way? It just sounds too complex compared to Ogre 1.x

The question (and solution) to the link you posted was about the same Item being rendered twice in the same pass (that IS multi-pass).

Ogre 1.x supports such functionality but OgreNext doesn't, as it was very rarely used and complicated things at engine level in many ways. If you want to render the object twice, one after another, with different materials in a single render_scene pass then a clone will be necessary.

However it seems you're asking a slightly different question: How to render the same object to 3 different cameras in 3 different ways. You can of course use 3 Item clones each with a different material.

But you can also do what you suggested:

Through the Hlms::preparePassHash it is possible to select desired shaders according to the camera/compositor for each instance of Ogre::Item/SubItem, but then it is necessary to handle also visibility of the objects.

Yes. With preparePassHash you can trigger a custom shader that renders the object in any way you want.

Regarding visibility, may I suggest to use visibility masks? They are meant for exactly these sort of scenarios:

Let's say:

Code: Select all

enum RenderingModes
{
    Normal = 1u << 0u,
    ShadedWithEdges = 1u << 1u,
    ShadedWithThickEdges = 1u << 2u,
};

item0->setVisibilityFlags( Normal | ShadedWithEdges );
item1->setVisibilityFlags( Normal );
item2->setVisibilityFlags( Normal | ShadedWithEdges | ShadedWithThickEdges );

Then your pass_scene passes set the visibility masks to 0x00000001, 0x00000002 and 0x00000004 accordingly (and the corresponding Hlms flag for each pass).

If you know in advance that an object rendering mode is exclusive (i.e. it can only have one flag from RenderingModes set), you could also use RenderQueue IDs (filtering by render queue ID is faster than filtering by visibility flags; but switching render queue IDs is slower than toggling visibility flags).

User avatar
bishopnator
Goblin
Posts: 299
Joined: Thu Apr 26, 2007 11:43 am
Location: Slovakia / Switzerland
x 11

Re: Multipass rendering per Camera

Post by bishopnator »

I think the Render Queue ID is the way to go for me. It sounds feasible for the setup which I need to achieve.