[2.1] Ocean

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


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

Re: [2.1] Ocean

Post by xrgo »

al2950 wrote:Dont know if you have ever seen this;
https://seblagarde.wordpress.com/2012/1 ... s-effects/

but it is a great series on how to render rain and its effects, might be of help if you do want to take it further.
Yes! I actually took the ripple effect and other details from there. Thanks!
xrgo
OGRE Expert User
OGRE Expert User
Posts: 1148
Joined: Sat Jul 06, 2013 10:59 pm
Location: Chile
x 168

Re: [2.1] Ocean

Post by xrgo »

Hello!! I am integrating planar reflections into my ocean, it was working great in mono, but in stereo VR I noticed a few problems:

first they look all wrong, the problem was that I was using setFrustumExtents for my eye cameras, so I added this:

Code: Select all

    Ogre::Vector4 frustumExtents;
    camera->getFrustumExtents( frustumExtents.x, frustumExtents.y, frustumExtents.z, frustumExtents.w );
    actorData->reflectionCamera->setFrustumExtents( frustumExtents.x, frustumExtents.y, frustumExtents.z, frustumExtents.w, Ogre::FET_PROJ_PLANE_POS);
to the line ~690 of OgrePlanarReflections.cpp, and that fixed it! but I guess I have to wrap it around some if but not sure how.

And the second problem is that I need to omit rendering the ocean in the reflection pass or I get some visual glitches... so I set setVisibilityFlags( 0x00000001 ); on the ocean, and using visibility_mask 0xfffffffe on the PlanarReflectionsReflectiveRenderingNode it solves that problem.

BUT! for some reason when rendering in stereo, the ocean in the right eye is invisible!
If I remove setVisibilityFlags( 0x00000001 ); on the ocean, it shows, the reflecion looks good, but I get the visual glitch;
If I remove passSceneDefRight->mIdentifier = 25001; (and maintain the setVisibilityFlags ) for my right eye, it shows, I get no visual glitch but I get the same reflection from the left eye, which looks very very bad.

So the question is why the ocean is not visible in my right scene render pass?
Last edited by xrgo on Mon Mar 05, 2018 3:22 pm, edited 1 time in total.
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] Ocean

Post by dark_sylinc »

Planar Reflections has a few requirements:
  • You can't render the object that uses the reflection (think infinite reflections problem) inside the reflection. Doing so can cause rendering artifacts. I think for PBS reflective surfaces we automatically handled that, but not for the rest (look at the sample carefully).
  • A clipping plane prevents objects behind the plane to be rendered in the reflection pass (otherwise objects behind a mirror would appear in the reflection as well)
Could be that whatever VR voodoo is going on is not being accounted for the clipping plane, and thus the clipping plane is cutting off geometry at a random location.
xrgo
OGRE Expert User
OGRE Expert User
Posts: 1148
Joined: Sat Jul 06, 2013 10:59 pm
Location: Chile
x 168

Re: [2.1] Ocean

Post by xrgo »

thanks, I am doing it like unlit, just passing the texture.
Is there another way I can omit the ocean object from the reflection pass? I can't just simply "move the actor a bit up" since the ocean can have large waves, its not just a plane.

and what about the first problem? I think the if I need should use mFrustumExtentsManuallySet, but its protected. Can you fix it for cameras with setFrustumExtents? please =D
123iamking
Gremlin
Posts: 152
Joined: Sat Aug 12, 2017 4:16 pm
x 4

Re: [2.1] Ocean

Post by 123iamking »

Sorry but I have difficulty in setting up this ocean.
  • I try to figure what is reflection probe in Terrain project, but I haven't figured out yet
    xrgo wrote: when you have a reflection probe, set it

    Code: Select all

            Ogre::HlmsOcean* hlmsOcean = static_cast<Ogre::HlmsOcean*>( Ogre::Root::getSingletonPtr()->getHlmsManager()->getHlms( Ogre::HLMS_USER2 ) );
            hlmsOcean->setEnvProbe( probeTexture );
    
  • I try to find object similar to mHlmsOcean but I haven't found it yet. Also there is oceanData.mOcean, I just replace this with mOcean and hope it work :oops:
    xrgo wrote: create the ocean object

    Code: Select all

            mOcean = new Ogre::Ocean( Ogre::Id::generateNewId<Ogre::MovableObject>(),
                                      &mSceneManager->_getEntityMemoryManager( Ogre::SCENE_STATIC ),
                                      mSceneManager, 0, mRoot->getCompositorManager2(),
                                      mCamera );
            mOcean->setCastShadows( false );
    
            mOcean->create( center, size );
    
            Ogre::SceneNode *oceanNode = mSceneManager->getRootSceneNode( Ogre::SCENE_STATIC );
            oceanNode->attachObject( oceanData.mOcean );
    
            Ogre::String datablockName = "testOcean";
            mDatablock = static_cast<Ogre::HlmsOceanDatablock*>( mHlmsOcean->createDatablock( datablockName, datablockName, Ogre::HlmsMacroblock(), Ogre::HlmsBlendblock(), Ogre::HlmsParamVec() ) );
    
            mOcean->setDatablock( mDatablock );
    
I have separated Terrain project from OGRE solution with hope to learn how to control terrain.
Here is my attempt so far trying to add the Ocean. Please help :(
xrgo
OGRE Expert User
OGRE Expert User
Posts: 1148
Joined: Sat Jul 06, 2013 10:59 pm
Location: Chile
x 168

Re: [2.1] Ocean

Post by xrgo »

123iamking wrote: Fri Nov 03, 2017 10:34 am I try to figure what is reflection probe in Terrain project, but I haven't figured out yet
probeTexture is jut a cubemap Ogre::TexturePtr you can load a file o capture it from scene
123iamking wrote: Fri Nov 03, 2017 10:34 am I try to find object similar to mHlmsOcean but I haven't found it yet
mHlmsOcean is:

Code: Select all

    mHlmsOcean = OGRE_NEW Ogre::HlmsOcean( archiveOcean, &library );
see the fisrt post, or you can later obtain it like this:

Code: Select all

Ogre::HlmsOcean* mHlmsOcean = static_cast<Ogre::HlmsOcean*>( Ogre::Root::getSingletonPtr()->getHlmsManager()->getHlms( Ogre::HLMS_USER2 ) );
123iamking wrote: Fri Nov 03, 2017 10:34 am Also there is oceanData.mOcean, I just replace this with mOcean and hope it work
yes sorry, it should work
123iamking
Gremlin
Posts: 152
Joined: Sat Aug 12, 2017 4:16 pm
x 4

Re: [2.1] Ocean

Post by 123iamking »

Thank xrgo, I don't have compile error anymore :D
Here is my update code:

Code: Select all

		//Create ocean
		mOcean = new Ogre::Ocean(Ogre::Id::generateNewId<Ogre::MovableObject>(),
			&sceneManager->_getEntityMemoryManager(Ogre::SCENE_STATIC),
			sceneManager, 0, root->getCompositorManager2(),
			mGraphicsSystem->getCamera());
		mOcean->setCastShadows(false);

		Ogre::Vector3 center;
		center = 0;
		Ogre::Vector2 size;
		size = 2;

		mOcean->create(center, size);

		Ogre::SceneNode *oceanNode = sceneManager->getRootSceneNode(Ogre::SCENE_STATIC);

		oceanNode->attachObject(mOcean);

		Ogre::TexturePtr probeTexture = Ogre::TextureManager::getSingletonPtr()->getByName("oceanData.dds");
		if (probeTexture.isNull()) {
			probeTexture = Ogre::TextureManager::getSingleton().load("oceanData.dds", Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, Ogre::TEX_TYPE_3D);
		}

		Ogre::HlmsOcean* hlmsOcean = static_cast<Ogre::HlmsOcean*>(
			Ogre::Root::getSingletonPtr()->getHlmsManager()->getHlms(Ogre::HLMS_USER2)
			);
		hlmsOcean->setEnvProbe(probeTexture);

		Ogre::String datablockName = "testOcean";
		Ogre::HlmsDatablock *datablockOcean = static_cast<Ogre::HlmsOceanDatablock*>(hlmsOcean->createDatablock(datablockName, datablockName, Ogre::HlmsMacroblock(), Ogre::HlmsBlendblock(), Ogre::HlmsParamVec()));

		mOcean->setDatablock(datablockOcean);
But now I got run-time error :oops:
Assertion failed!

Program: ...\bin\Debug\TestOcean.exe
File: ...\src\Ocean\Hlms\OgreHlmsOcean.cpp
Line: 747

Expression: (size_t)(passBufferPtr - startupPtr) * 4u == mapSize
And I update the code into this project

it is so diddly doodly hard :evil:
Lax
Hobgoblin
Posts: 583
Joined: Mon Aug 06, 2007 12:53 pm
Location: Saarland, Germany
x 50

Re: [2.1] Ocean

Post by Lax »

Hi,

I would also like to try out the wonderful ocean feature. But I get the same assert. When I deactivate the assert I get further errors:

Code: Select all

23:21:30: GLSL compile log: 3221226112VertexShader_vs
0(144) : error C1008: undefined variable "passBuf"
...
Is It because Ocean is no more up to date with ogre?

Or has somebody an example how to use it properly?

Thanks in advance
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

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

Re: [2.1] Ocean

Post by xrgo »

ohh I am really sorry, please wait until tomorrow and I will look in to it =) I am just leaving the office
xrgo
OGRE Expert User
OGRE Expert User
Posts: 1148
Joined: Sat Jul 06, 2013 10:59 pm
Location: Chile
x 168

Re: [2.1] Ocean

Post by xrgo »

I just tried and its working fine with me, before looking deeply in to your specific problem, I am going to try to integrate/pullrequest the Ocean as an official sample =), please hold on a little bit

btw:

Code: Select all

Ogre::TexturePtr probeTexture = Ogre::TextureManager::getSingletonPtr()->getByName("oceanData.dds");
		if (probeTexture.isNull()) {
			probeTexture = Ogre::TextureManager::getSingleton().load("oceanData.dds", Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, Ogre::TEX_TYPE_3D);
		}
you're not suppose to use the "oceanData.dds" as the probe, the idea is to use a reflection cubemap, either captured by you in engine or a file
Lax
Hobgoblin
Posts: 583
Joined: Mon Aug 06, 2007 12:53 pm
Location: Saarland, Germany
x 50

Re: [2.1] Ocean

Post by Lax »

Hi,

thanks for the response and the hint. I will take a breath and wait :D .

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: 5296
Joined: Sat Jul 21, 2007 4:55 pm
Location: Buenos Aires, Argentina
x 1278
Contact:

Re: [2.1] Ocean

Post by dark_sylinc »

A few tips: Based on experience with other Hlms extensions, it looks like the problem lies in how the Hlms Library (the pieces) was initialized. Which would explain why passBuf is an undeclared identifier (there's likely an insertpiece but the piece is never defined due to incorrect initialization)
Hrenli
Halfling
Posts: 73
Joined: Tue Jun 14, 2016 12:26 pm
x 19

Re: [2.1] Ocean

Post by Hrenli »

I have a question to xrgo about how he came up with the .dds and as it might be interesting to others I thought I'd ask here.

So, blender ocean modifier can bake its output into a set of images (displacement, normals and foam separately). The only thing which is more or less clear to me straight away is foam. The displacement and normals - not so much. :( Green channel in the displacement seems to be answering for the height, but the rest of the data doesn't add up in my head, especially normals (why the image is so one-channeled?)...

So, the question - did you find a description of what on Earth the colors mean there (I've tried to google but failed so far) or manage to guess it yourself? :)

Update: after staring onto those hdr exrs produced by ocean modifer for half a day I came to conclusion that you most probably baked displacement map from the animation in blender. Still not 100% sure so will leave the question as it was.
xrgo
OGRE Expert User
OGRE Expert User
Posts: 1148
Joined: Sat Jul 06, 2013 10:59 pm
Location: Chile
x 168

Re: [2.1] Ocean

Post by xrgo »

Hello! At first I tried to use the displacement generated by blender's ocean modifier, it was textures like this one:
Image
this includes a displacement in all axis, XYZ as RGB, the vertical axis is obvious (basically a heightmap) but the other two axis are for the choppiness, which is something really importan for the looks. But I failed at using this because there was something that wasn't working... I don't remember very well, but I think it was something to do about problems at tiling the texture. So I decided to use just the vertical axis, but as I mentioned before, choppiness is really important so it looked really bad xD.
I ended up just rendering a heightmap that includes the choppiness, this also have the benefit that I now use just one channel, so it actually doesn't move the vertex horizontally, the choppiness is just a visual effect of the good hightmap.
Using the heightmap I could render a normal map directly in blender using compositor nodes.
And the foam was baked the ocean modifier as you mentioned.
Lastly I composited everything in after effects, to put every map in the corresponding channel (rg normal, b height, a foam), and exported all the frames and converted to volume dds in GIMP ( or photoshop? don't remember)

As you can see is not magic, just a lot of guessing, testing and tweeking.

here is the blend file if you want to check it:
https://www.dropbox.com/s/cl2a95tpztm4v ... blend?dl=0
if you press F12 you will render a frame of the height map, the height map is just an ocean object, with a white shadeless material, and a black mist/fog applied to the scene (the most simple way of making a depth map)
In the compositor node editor in blender... if you connect the Gamma node output in to the Image input of the Composite node you will see the normal map.
The ocean is tiled both on UV coords and time, for tiling the time I used two ocean modifiers and animated the time and scale so they blend nicely
If you want to scroll thought the time I recommend you to decrease the Preview value on the Multires modifier applied to the ocean object.

Cheers!!!!
Hrenli
Halfling
Posts: 73
Joined: Tue Jun 14, 2016 12:26 pm
x 19

Re: [2.1] Ocean

Post by Hrenli »

Thanks for the details! For me the main problem with displacement maps from the ocean modifier was their awkward scale (16 bit floats with way too much black in low areas and in general wave form was different from what I see in blender if I just apply that map as a displacement). Seems like instead of linear function they use squares or whatnot...

So, yeah, I guessed already that if you see the wave in blender you can just get all the info from there (was a good push for me to finally figure out how to bake displacement maps).

Another question if you don't mind - how you transformed normals to two channels? Just ignored the blue (it's mostly at 1.0 for everything but the choppiest wave tips anyway) or found a way to rescale it properly? I know texconv can create a two channel .dds out of three-colored tangent space image, but maybe there are more convenient tools?
xrgo
OGRE Expert User
OGRE Expert User
Posts: 1148
Joined: Sat Jul 06, 2013 10:59 pm
Location: Chile
x 168

Re: [2.1] Ocean

Post by xrgo »

tangent space normals are usually just two channels, and if you need information in the third channel you can calculate it out of the other 2. The normals texture I generated in blender was a 3 channel png, in after effects when I composited everything I just used 2 channels
xrgo
OGRE Expert User
OGRE Expert User
Posts: 1148
Joined: Sat Jul 06, 2013 10:59 pm
Location: Chile
x 168

Re: [2.1] Ocean

Post by xrgo »

xrgo wrote: Tue Oct 24, 2017 6:58 pm first they look all wrong, the problem was that I was using setFrustumExtents for my eye cameras, so I added this:

Code: Select all

    Ogre::Vector4 frustumExtents;
    camera->getFrustumExtents( frustumExtents.x, frustumExtents.y, frustumExtents.z, frustumExtents.w );
    actorData->reflectionCamera->setFrustumExtents( frustumExtents.x, frustumExtents.y, frustumExtents.z, frustumExtents.w, Ogre::FET_PROJ_PLANE_POS);
to the line ~690 of OgrePlanarReflections.cpp, and that fixed it! but I guess I have to wrap it around some if but not sure how.
Hello, can this fix be integrated in ogre? in my experience doesn't break anything in mono, so no if needed
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] Ocean

Post by dark_sylinc »

xrgo wrote: Mon Dec 17, 2018 4:03 pm
xrgo wrote: Tue Oct 24, 2017 6:58 pm first they look all wrong, the problem was that I was using setFrustumExtents for my eye cameras, so I added this:

Code: Select all

    Ogre::Vector4 frustumExtents;
    camera->getFrustumExtents( frustumExtents.x, frustumExtents.y, frustumExtents.z, frustumExtents.w );
    actorData->reflectionCamera->setFrustumExtents( frustumExtents.x, frustumExtents.y, frustumExtents.z, frustumExtents.w, Ogre::FET_PROJ_PLANE_POS);
to the line ~690 of OgrePlanarReflections.cpp, and that fixed it! but I guess I have to wrap it around some if but not sure how.
Hello, can this fix be integrated in ogre? in my experience doesn't break anything in mono, so no if needed
PR or it didn't happen :lol:
I'm lacking a lot of context. I don't know where to add that.
xrgo
OGRE Expert User
OGRE Expert User
Posts: 1148
Joined: Sat Jul 06, 2013 10:59 pm
Location: Chile
x 168

Re: [2.1] Ocean

Post by xrgo »

dark_sylinc wrote: Mon Dec 17, 2018 6:12 pm PR or it didn't happen :lol:
I'm lacking a lot of context. I don't know where to add that.
included in this PR https://bitbucket.org/sinbad/ogre/pull- ... hadow/diff
Lax
Hobgoblin
Posts: 583
Joined: Mon Aug 06, 2007 12:53 pm
Location: Saarland, Germany
x 50

Re: [2.1] Ocean

Post by Lax »

Hi,

I just wanted to ask if there is any progress with Ocean?
It would be nice, if it could be integrated to Ogre samples.

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

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

Re: [2.1] Ocean

Post by xrgo »

Hi! not more progress besides porting it to Ogre 2.2 and hlsl, I am going to try to update the repo with that in the next few days, I have to make sure it works without the context of my engine
Lax
Hobgoblin
Posts: 583
Joined: Mon Aug 06, 2007 12:53 pm
Location: Saarland, Germany
x 50

Re: [2.1] Ocean

Post by Lax »

Hi xrgo,

I just wanted to ping you, if you have any progress porting Ocean to Ogre 2.2?

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
Hobgoblin
Posts: 583
Joined: Mon Aug 06, 2007 12:53 pm
Location: Saarland, Germany
x 50

Re: [2.1] Ocean

Post by Lax »

Hi all,

is there any updated Ocean implemtation? Also Form directX shading?

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
Hobgoblin
Posts: 583
Joined: Mon Aug 06, 2007 12:53 pm
Location: Saarland, Germany
x 50

Re: [2.1] Ocean

Post by Lax »

Hi dark_sylinc,

are there any plans to integrate ocean to Ogre and samples?
That would form a great combination with the atmosphere component!

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

HulkRomain
Gnoblar
Posts: 1
Joined: Sat Aug 13, 2022 4:01 am
x 1

Re: [2.1] Ocean

Post by HulkRomain »

Hello !

I'm a programmer of the sunday but with some effort, i succeeded to port the code for Ogre 2.3. It works also with the 3.0.0unstable.
This is less beautiful than dark_sylinc did but it works.
You can see a picture here.
Image

The code can be downloaded here : https://file.io/wVtGhGSYlvcB

I hope someone who has better experience than me with HLMS and shaders will do better than me, but i wanted to share with you this because it's better than nothing !

Have a good day !

HulkRomain.

Post Reply