[2.1] How to HMLS PBS dunamic cubemap reflection ?

Problems building or running the engine, queries about how to use features etc.
User avatar
Kohedlo
Orc
Posts: 435
Joined: Fri Nov 27, 2009 3:34 pm
Location: Ukraine, Sumy
x 32
Contact:

[2.1] How to HMLS PBS dunamic cubemap reflection ?

Post by Kohedlo »

How to dynamic cubemap reflection with OgreHMLSPbsDatablock??
c++ game developer.
current project: Imperial Game Engine 2.5
Image
xrgo
OGRE Expert User
OGRE Expert User
Posts: 1148
Joined: Sat Jul 06, 2013 10:59 pm
Location: Chile
x 168

Re: [2.1] How to HMLS PBS dunamic cubemap reflection ?

Post by xrgo »

first create a camera for the cubemap, then a cube texture, and a workspace:

Code: Select all

        envCam = sceneManager->createCamera( "envCubeMapCamera",true,true );
        Ogre::Camera* envCam->setFOVy(Ogre::Degree(90));
        envCam->setAspectRatio(1);
        envCam->setFixedYawAxis(false);
        envCam->setNearClipDistance(0.01);
        envCam->setFarClipDistance(1000);

        Ogre::TexturePtr envCubeMap = Ogre::TextureManager::getSingletonPtr()->createManual(
                    "envCubeMap",
                    Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME,
                    Ogre::TEX_TYPE_CUBE_MAP,
                    512,
                    512,
                    Ogre::MIP_UNLIMITED,  //if you want mipmaps
                    Ogre::PF_R8G8B8,
                    Ogre::TU_AUTOMIPMAP | Ogre::TU_RENDERTARGET | Ogre::TU_AUTOMIPMAP_AUTO,  //if you want mipmaps
                    0,
                    true
                    );

        Ogre::CompositorChannel channel;
        channel.target = envCubeMap->getBuffer(0)->getRenderTarget(); //Any of the render targets will do
        channel.textures.push_back( envCubeMap );
        Ogre::CompositorWorkspace* envCubeMapWorkspace = root->getCompositorManager2()->addWorkspace(sceneManager, channel, envCam, "WorkspaceCubeMap", false); //notice it start disabled
"WorkspaceCubeMap" should be defined somewhere, my definition looks like this:

Code: Select all

//CUBEMAP WORKSPACE for enviroment map
//+X'. '-X', '+Y', '-Y', '+Z', and '-Z
abstract target cubemap_target
{
	pass clear
	{
		colour_value 0 0 0 1
	}

	pass render_scene
	{
		//lod_update_list off
		overlays         off
		camera_cubemap_reorient true
	}
	
   pass generate_mipmaps {}  //if you want mipmaps
}

compositor_node cubeMapRenderNode
{
   in 0 cubemap

   target cubemap +X : cubemap_target { }
   target cubemap -X : cubemap_target { }
   target cubemap +Y : cubemap_target { }
   target cubemap -Y : cubemap_target { }
   target cubemap +Z : cubemap_target { }
   target cubemap -Z : cubemap_target { }
}

//CubeMap Workspace
workspace WorkspaceCubeMap
{
	connect_output cubeMapRenderNode 0
}
Then you can use that "envCubeMap" as reflection texture on your hlmsPbsDatablock
Be aware that this is very expensive, so one thing you can do is to update "envCubeMapWorkspace" not every frame, maybe every other frame or less (that's why I set it as disabled) or you can just set it as enabled and let it run :P
al2950
OGRE Expert User
OGRE Expert User
Posts: 1227
Joined: Thu Dec 11, 2008 7:56 pm
Location: Bristol, UK
x 157

Re: [2.1] How to HMLS PBS dunamic cubemap reflection ?

Post by al2950 »

I saw this post on my phone, and completely forgot to reply to it when I got home... sorry :oops:

However it did give me an idea....
Allow the scripts to define when a compositor is updated, it could be everyFrame, timeInterval, frameInterval or onRequest.

Any thoughts? Cant really think of any other use cases except dynamic env maps...
xrgo
OGRE Expert User
OGRE Expert User
Posts: 1148
Joined: Sat Jul 06, 2013 10:59 pm
Location: Chile
x 168

Re: [2.1] How to HMLS PBS dunamic cubemap reflection ?

Post by xrgo »

al2950 wrote:Allow the scripts to define when a compositor is updated, it could be everyFrame, timeInterval, frameInterval or onRequest.
I would love that
al2950 wrote:Cant really think of any other use cases except dynamic env maps...
I usually do this (but manually) for mirrors and TVs/Screens
User avatar
Kohedlo
Orc
Posts: 435
Joined: Fri Nov 27, 2009 3:34 pm
Location: Ukraine, Sumy
x 32
Contact:

Re: [2.1] How to HMLS PBS dunamic cubemap reflection ?

Post by Kohedlo »

ok/ thanks/ i fiirst think its new only dataclock
c++ game developer.
current project: Imperial Game Engine 2.5
Image
User avatar
Kohedlo
Orc
Posts: 435
Joined: Fri Nov 27, 2009 3:34 pm
Location: Ukraine, Sumy
x 32
Contact:

Re: [2.1] How to HMLS PBS dunamic cubemap reflection ?

Post by Kohedlo »

there i integrate according to task cubemap camera. but in resultat is no camera show.

Image
Original

on picture:

camera- cubemap camera.
cube- manual object 2 that have applied cubemap material. last have added sampler of diffuse map.
c++ game developer.
current project: Imperial Game Engine 2.5
Image
User avatar
Kohedlo
Orc
Posts: 435
Joined: Fri Nov 27, 2009 3:34 pm
Location: Ukraine, Sumy
x 32
Contact:

Re: [2.1] How to HMLS PBS dunamic cubemap reflection ?

Post by Kohedlo »

ok. all works.

Image
Large
c++ game developer.
current project: Imperial Game Engine 2.5
Image
al2950
OGRE Expert User
OGRE Expert User
Posts: 1227
Joined: Thu Dec 11, 2008 7:56 pm
Location: Bristol, UK
x 157

Re: [2.1] How to HMLS PBS dunamic cubemap reflection ?

Post by al2950 »

Did you do anything special to get the reflections to be correct? Currently they are incorrect out of the box with Ogre when using dynamic cubemaps.
User avatar
AshMcConnell
Silver Sponsor
Silver Sponsor
Posts: 605
Joined: Fri Dec 14, 2007 11:44 am
Location: Northern Ireland
x 16
Contact:

Re: [2.1] How to HMLS PBS dunamic cubemap reflection ?

Post by AshMcConnell »

al2950 wrote: Allow the scripts to define when a compositor is updated, it could be everyFrame, timeInterval, frameInterval or onRequest.
Any thoughts? Cant really think of any other use cases except dynamic env maps...
This would be awesome! In my Ogre 1.10 I update the dynamic env maps and mirrors every x frames, would be good to stick that into a script indeed!

I am about to try to implement Dynamic Env Maps and Mirrors in Ogre 2.1. Is this still the best way to do it? How do you manually update it every x frames using this method?

Thanks for your help!
Ash
User avatar
dark_sylinc
OGRE Team Member
OGRE Team Member
Posts: 5296
Joined: Sat Jul 21, 2007 4:55 pm
Location: Buenos Aires, Argentina
x 1278
Contact:

Re: [2.1] How to HMLS PBS dunamic cubemap reflection ?

Post by dark_sylinc »

I'll be pushing a dynamic cubemap demo this weekend, if anyone's interested and wants to wait one or two days. :)
User avatar
AshMcConnell
Silver Sponsor
Silver Sponsor
Posts: 605
Joined: Fri Dec 14, 2007 11:44 am
Location: Northern Ireland
x 16
Contact:

Re: [2.1] How to HMLS PBS dunamic cubemap reflection ?

Post by AshMcConnell »

dark_sylinc wrote:I'll be pushing a dynamic cubemap demo this weekend, if anyone's interested and wants to wait one or two days. :)
Ah, great, I'll wait for that - thanks!
User avatar
dark_sylinc
OGRE Team Member
OGRE Team Member
Posts: 5296
Joined: Sat Jul 21, 2007 4:55 pm
Location: Buenos Aires, Argentina
x 1278
Contact:

Re: [2.1] How to HMLS PBS dunamic cubemap reflection ?

Post by dark_sylinc »

Demo implemented. The sample is in 2.1-pso branch, but it can be easily backported to 2.1 (in fact it's easier because there is no need to expose the cubemap to the pass; you can just ignore that)
User avatar
AshMcConnell
Silver Sponsor
Silver Sponsor
Posts: 605
Joined: Fri Dec 14, 2007 11:44 am
Location: Northern Ireland
x 16
Contact:

Re: [2.1] How to HMLS PBS dunamic cubemap reflection ?

Post by AshMcConnell »

dark_sylinc wrote:Demo implemented. The sample is in 2.1-pso branch, but it can be easily backported to 2.1 (in fact it's easier because there is no need to expose the cubemap to the pass; you can just ignore that)

Code: Select all

pass render_scene
	{
		//Filter stuff that shouldn't be reflected (vampires?)
		visibility_mask		0x00000005
		overlays			off
		camera_cubemap_reorient true
	}
}
I'm glad you had provision for vampire rendering in there :D

Thanks! :)
User avatar
AshMcConnell
Silver Sponsor
Silver Sponsor
Posts: 605
Joined: Fri Dec 14, 2007 11:44 am
Location: Northern Ireland
x 16
Contact:

Re: [2.1] How to HMLS PBS dunamic cubemap reflection ?

Post by AshMcConnell »

I've managed to get the envmap rendering, but for some reason the orientation and texture co-ords seem to be off. I thought the PBS shader would be able to receive the cubemap rendered in this way. I have no doubt have misunderstood somewhere. Here is a video of the problem: -

[youtube]Evk9N5EdqOI[/youtube]

Here is the Material in question: -

Code: Select all

"fs_carbody": {
            "macroblock": "Macroblock_0",
            "blendblock": "Blendblock_0",
            "shadow_const_bias": 0.01,
            "workflow": "specular_ogre",
            "diffuse": {
                "value": [
                    0.784314,
                    0.784314,
                    0.784314
                ],
                "texture": "FS01_carbody.dds",
                "sampler": "Sampler_1"
            },
            "specular": {
                "value": [
                    0.784314,
                    0.784314,
                    0.784314
                ]
            },
            "fresnel": {
                "value": 0.1,
                "mode": "coeff"
            },
            "roughness": {
                "value": 0.000005
            },
            "reflection" :
            {
                "texture" : "envCubeMap"
            }
        }

I am using xrgo's code above to create the texture / camera / workspace and updating the envCam's position each frame.

Any pointers would be appreciated :)

Thanks!
Ash
xrgo
OGRE Expert User
OGRE Expert User
Posts: 1148
Joined: Sat Jul 06, 2013 10:59 pm
Location: Chile
x 168

Re: [2.1] How to HMLS PBS dunamic cubemap reflection ?

Post by xrgo »

can you try it in a sphere so its easier to see whats happening
Also! you should try the new sample Tutorial_DynamicCubemap
User avatar
AshMcConnell
Silver Sponsor
Silver Sponsor
Posts: 605
Joined: Fri Dec 14, 2007 11:44 am
Location: Northern Ireland
x 16
Contact:

Re: [2.1] How to HMLS PBS dunamic cubemap reflection ?

Post by AshMcConnell »

xrgo wrote:can you try it in a sphere so its easier to see whats happening
Also! you should try the new sample Tutorial_DynamicCubemap
Thanks, I'll try again tonight. I was trying to make the car a mirror, I thought that roughness = 0 would make that happen, but it didn't work. Do you have a datablock that is a proper mirror?

Thanks!
Ash
User avatar
GlowingPotato
Goblin
Posts: 211
Joined: Wed May 08, 2013 2:58 pm
x 10

Re: [2.1] How to HMLS PBS dunamic cubemap reflection ?

Post by GlowingPotato »

to make a mirror using specular workflow,

Code: Select all

"mirror_material": {
      "macroblock": "default_macro",
      "blendblock": "default_blend",
      "alpha_test": [
        "disabled",
        0.5
      ],
      "shadow_const_bias": 0.01,
      "workflow": "specular",
      "diffuse": {
      "value": [
          0.0,
          0.0,
          0.0
        ]
      },
      "specular": {
        "value": [
          1.0,
          1.0,
          1.0
        ]
      },
      "roughness": {
        "value": 0.01
      },
      "reflection": {
        "texture": "cubeMap.dds",
        "sampler": "default_sampler"
      }
    },
For metallic worflow, have booth diffuse color and specular color set to pure white,
Metallic set to 1.0 and roughness to 0.01

If you set roughness to 0, you will receive a warning saying the roughness value is too low and can cause issues.
User avatar
AshMcConnell
Silver Sponsor
Silver Sponsor
Posts: 605
Joined: Fri Dec 14, 2007 11:44 am
Location: Northern Ireland
x 16
Contact:

Re: [2.1] How to HMLS PBS dunamic cubemap reflection ?

Post by AshMcConnell »

Thanks Mr. Potato, much appreciated. I am but a mere coder :)

Here is the shiny ball: -

Image

It looks like it's upside down (and I haven't cleared the "sky" properly). What can I tweek to make this work?

Thanks guys!
Ash
User avatar
dark_sylinc
OGRE Team Member
OGRE Team Member
Posts: 5296
Joined: Sat Jul 21, 2007 4:55 pm
Location: Buenos Aires, Argentina
x 1278
Contact:

Re: [2.1] How to HMLS PBS dunamic cubemap reflection ?

Post by dark_sylinc »

Clearly... it's upside down <captain obvious flies away>

Are you rendering to a RenderTexture instead of directly to the RenderWindow? I suspect it could be an Ogre bug.
Is this D3D11 or GL?

Edit: I just realized the PassScene applies camera reorientation relative to its current orientation. That means the camera you're telling Ogre to use for rendering could be upside down. Try ensuring it has an identity quaternion as orientation. If that doesn't work... I guess you could roll the camera so it counters the upside down?
User avatar
AshMcConnell
Silver Sponsor
Silver Sponsor
Posts: 605
Joined: Fri Dec 14, 2007 11:44 am
Location: Northern Ireland
x 16
Contact:

Re: [2.1] How to HMLS PBS dunamic cubemap reflection ?

Post by AshMcConnell »

I set the _envCam's orientation to Identity on creation. I assume that the compositor takes care of the orientation after that?
User avatar
dark_sylinc
OGRE Team Member
OGRE Team Member
Posts: 5296
Joined: Sat Jul 21, 2007 4:55 pm
Location: Buenos Aires, Argentina
x 1278
Contact:

Re: [2.1] How to HMLS PBS dunamic cubemap reflection ?

Post by dark_sylinc »

@Ash You will see your post has been edited and a lot of what you wrote was lost. I accidentally hit "Edit" instead of "Quote" and didn't realize. I hate it when it happens!!! :oops: :oops:
Sorry. :oops: :oops:
AshMcConnell wrote:I set the _envCam's orientation to Identity on creation. I assume that the compositor takes care of the orientation after that?
Do you mean the main camera that I am rendering the "real" scene with (rather than the camera for env mapping)? It is connected relatively to the car. If it is showing everything correctly, I'm not sure how it could be upside down - maybe I'm being silly :)

I set the _envCam's orientation to Identity on creation. I assume that the compositor takes care of the orientation after that?
I meant the _envCam's orientation.

First check it truly is identity (maybe it's being overridden somewhere). or else try rolling it the envCam's 180°.
Btw. look for "mCamera->setOrientation( oldCameraOrientation * CubemapRotations[sliceIdx] );" in OgreMain's code. Place a breakpoint, and see that oldCameraOrientation is identity.
User avatar
AshMcConnell
Silver Sponsor
Silver Sponsor
Posts: 605
Joined: Fri Dec 14, 2007 11:44 am
Location: Northern Ireland
x 16
Contact:

Re: [2.1] How to HMLS PBS dunamic cubemap reflection ?

Post by AshMcConnell »

My post, my beautiful post! :P :D

Image

Yep, seems to be Identity ok

Also, If I change the _envMap orientation it does affect the result (although I guessed the wrong axis :P)

Image

It would be nice to understand what I've done wrong though
User avatar
dark_sylinc
OGRE Team Member
OGRE Team Member
Posts: 5296
Joined: Sat Jul 21, 2007 4:55 pm
Location: Buenos Aires, Argentina
x 1278
Contact:

Re: [2.1] How to HMLS PBS dunamic cubemap reflection ?

Post by dark_sylinc »

Maybe you've done nothing wrong. I just realized the demo works on 2.1-pso branch... this may be a 2.1-specific bug. Mmmm....
User avatar
AshMcConnell
Silver Sponsor
Silver Sponsor
Posts: 605
Joined: Fri Dec 14, 2007 11:44 am
Location: Northern Ireland
x 16
Contact:

Re: [2.1] How to HMLS PBS dunamic cubemap reflection ?

Post by AshMcConnell »

dark_sylinc wrote:Maybe you've done nothing wrong. I just realized the demo works on 2.1-pso branch... this may be a 2.1-specific bug. Mmmm....
I think other guys have got it working without a tactical piece of code*





*Dirty hack
User avatar
AshMcConnell
Silver Sponsor
Silver Sponsor
Posts: 605
Joined: Fri Dec 14, 2007 11:44 am
Location: Northern Ireland
x 16
Contact:

Re: [2.1] How to HMLS PBS dunamic cubemap reflection ?

Post by AshMcConnell »

Just taking another look at the reflections, it seems that the reflection is not actually mirrored (notice the garage door numbers). Is that something I need to deal with or is it part of the PBS implementation?

Image
Post Reply