[2.1] Ocean

Design / architecture / roadmap discussions related to future of Ogre3D (version 2.0 and above)
xrgo
OGRE Expert User
OGRE Expert User
Posts: 989
Joined: Sat Jul 06, 2013 10:59 pm
Location: Chile
x 60

Re: [2.1] Ocean

Post by xrgo » Fri Oct 13, 2017 11:50 am

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!
0 x

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

Re: [2.1] Ocean

Post by xrgo » Tue Oct 24, 2017 6:58 pm

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.
0 x

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

Re: [2.1] Ocean

Post by dark_sylinc » Tue Oct 24, 2017 7:10 pm

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.
0 x

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

Re: [2.1] Ocean

Post by xrgo » Tue Oct 24, 2017 7:56 pm

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
0 x

123iamking
Gremlin
Posts: 152
Joined: Sat Aug 12, 2017 4:16 pm
x 3

Re: [2.1] Ocean

Post by 123iamking » Fri Nov 03, 2017 10:34 am

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 :(
0 x

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

Re: [2.1] Ocean

Post by xrgo » Sat Nov 04, 2017 6:58 pm

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
0 x

123iamking
Gremlin
Posts: 152
Joined: Sat Aug 12, 2017 4:16 pm
x 3

Re: [2.1] Ocean

Post by 123iamking » Mon Nov 06, 2017 4:10 am

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:
0 x

Lax
Gnome
Posts: 322
Joined: Mon Aug 06, 2007 12:53 pm
Location: Saarland, Germany
x 7

Re: [2.1] Ocean

Post by Lax » Wed Apr 11, 2018 10:23 pm

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
0 x

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

Re: [2.1] Ocean

Post by xrgo » Wed Apr 11, 2018 11:30 pm

ohh I am really sorry, please wait until tomorrow and I will look in to it =) I am just leaving the office
0 x

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

Re: [2.1] Ocean

Post by xrgo » Thu Apr 12, 2018 3:28 pm

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
0 x

Lax
Gnome
Posts: 322
Joined: Mon Aug 06, 2007 12:53 pm
Location: Saarland, Germany
x 7

Re: [2.1] Ocean

Post by Lax » Thu Apr 12, 2018 9:15 pm

Hi,

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

Regards
Lax
0 x

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

Re: [2.1] Ocean

Post by dark_sylinc » Thu Apr 12, 2018 9:37 pm

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)
0 x

Hrenli
Halfling
Posts: 62
Joined: Tue Jun 14, 2016 12:26 pm
x 8

Re: [2.1] Ocean

Post by Hrenli » Tue Nov 13, 2018 4:57 pm

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.
0 x

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

Re: [2.1] Ocean

Post by xrgo » Wed Nov 14, 2018 12:12 am

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!!!!
1 x

Hrenli
Halfling
Posts: 62
Joined: Tue Jun 14, 2016 12:26 pm
x 8

Re: [2.1] Ocean

Post by Hrenli » Wed Nov 14, 2018 11:55 am

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?
0 x

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

Re: [2.1] Ocean

Post by xrgo » Wed Nov 14, 2018 1:26 pm

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
0 x

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

Re: [2.1] Ocean

Post by xrgo » 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
0 x

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

Re: [2.1] Ocean

Post by dark_sylinc » Mon Dec 17, 2018 6:12 pm

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.
1 x

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

Re: [2.1] Ocean

Post by xrgo » Sun Feb 17, 2019 11:17 pm

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
1 x

Post Reply