[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

[2.1] Ocean

Post by xrgo »

Hello, I've made an ocean (this might fit showcase forum?, but since there's code, and 2.1.. well... please move it if you think it belongs to showcase)


(those black highlights are because the cubemap was taken too high and could see the black bg, also I had the sun commented out in my skydome)

Its basically a very mutilated version of Terra with a nice baked textures (from blender's ocean modifier)

Edit: updated code and added usage

here is the code!
https://github.com/yoyTeam/OgreOcean

To use:

register the hlmsOcean

Code: Select all

    Ogre::Archive *archiveOcean = Ogre::ArchiveManager::getSingletonPtr()->load( "../../yoyEngine/media/Hlms/Ocean/GLSL", "FileSystem", true );

    Ogre::Archive *archiveLibraryCommon = Ogre::ArchiveManager::getSingletonPtr()->load("../../yoyEngine/media/Hlms/Common/GLSL", "FileSystem", true );
    Ogre::Archive *archiveLibraryCommonAny = Ogre::ArchiveManager::getSingletonPtr()->load("../../yoyEngine/media/Hlms/Common/Any", "FileSystem", true );
    Ogre::Archive *archivePbsLibrary = Ogre::ArchiveManager::getSingletonPtr()->load("../../yoyEngine/media/Hlms/Pbs/GLSL", "FileSystem", true );
    Ogre::Archive *archivePbsLibraryAny = Ogre::ArchiveManager::getSingletonPtr()->load("../../yoyEngine/media/Hlms/Pbs/Any", "FileSystem", true );
    library.push_back( archiveLibraryCommon );
    library.push_back( archiveLibraryCommonAny );
    library.push_back( archivePbsLibrary );
    library.push_back( archivePbsLibraryAny );

    Ogre::Archive *archiveLibraryCustom = Ogre::ArchiveManager::getSingletonPtr()->load( "../../yoyEngine/media/Hlms/Ocean/GLSL/Custom", "FileSystem", true );
    library.push_back( archiveLibraryCustom );

    mHlmsOcean = OGRE_NEW Ogre::HlmsOcean( archiveOcean, &library );
    mHlmsManager->registerHlms( mHlmsOcean );
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 );
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 );
update it somewhere

Code: Select all

bool yOceanManager::frameRenderingQueued(const Ogre::FrameEvent &evt){

    mOcean->update();

    return true;
}
the only thing missing from the video is that the timer that's communicated to the shader in the file OgreHlmsOcean.cpp, line ~738 should be scaled by the wind intensity (so the waves move quicker) I use my weather manager for that but I removed it

cheers!
Last edited by xrgo on Thu Oct 12, 2017 1:26 pm, edited 3 times 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 »

Holy Moly!

Talk about looking good! Looks great! Thanks for sharing!

Also: It uses Terra's code as groundwork, wonderful!
123iamking
Gremlin
Posts: 152
Joined: Sat Aug 12, 2017 4:16 pm
x 4

Re: [2.1] Ocean

Post by 123iamking »

This is fantastic! :shock: thanks for posting it here :D
cloud
Gremlin
Posts: 196
Joined: Tue Aug 08, 2006 6:45 pm
x 14

Re: [2.1] Ocean

Post by cloud »

beautiful, well done!
123iamking
Gremlin
Posts: 152
Joined: Sat Aug 12, 2017 4:16 pm
x 4

Re: [2.1] Ocean

Post by 123iamking »

It would be awesome if it could be merged into the Sample_Tutorial_Terrain officially :D Just saying :)
123iamking
Gremlin
Posts: 152
Joined: Sat Aug 12, 2017 4:16 pm
x 4

Re: [2.1] Ocean

Post by 123iamking »

I have a question :)
In the file \Ocean\Hlms\OgreHlmsOcean.cpp has

Code: Select all

#include "Graphics/yGraphicsServices.h"
#include "Terra/yTerraManager.h"
#include "Probes/yProbeManager.h"
I can't find these file anywhere?
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:I have a question :)
In the file \Ocean\Hlms\OgreHlmsOcean.cpp has

Code: Select all

#include "Graphics/yGraphicsServices.h"
#include "Terra/yTerraManager.h"
#include "Probes/yProbeManager.h"
I can't find these file anywhere?
Yes I am sorry, that's what I meant with this
the reflection probe and the terra shadow(this one is not working yet) its been taken from a manager in my engine, just replace that with whatever you want (or comment out). Also it needs a timer that you have to pass through passBufferPtr as you like.
But please wait! I'll make some time today to make it really straight forward to use
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 »

Now should work!! download again and see the usage code.. I've should have done that from the beginning, but I was in a hurry, sorry for wasting your time =)
User avatar
devxkh
Halfling
Posts: 84
Joined: Tue Aug 02, 2016 6:07 pm
Location: Germany
x 12

Re: [2.1] Ocean

Post by devxkh »

wow! realy an expert! love it! thanks for sharing!

Maybe you need SSS as next! :P
My little OGRE engine -> FrankE WIP
mrmclovin
Gnome
Posts: 324
Joined: Sun May 11, 2008 9:27 pm
x 20

Re: [2.1] Ocean

Post by mrmclovin »

Wow! absolutely beautiful!
User avatar
BohdanKornienko
Halfling
Posts: 43
Joined: Sat Nov 01, 2014 10:26 pm

Re: [2.1] Ocean

Post by BohdanKornienko »

Incredible work! Looks so real!
Arkiruthis
Gremlin
Posts: 178
Joined: Fri Dec 24, 2010 7:55 pm
x 10

Re: [2.1] Ocean

Post by Arkiruthis »

That is astonishingly lovely!
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] Ocean

Post by AshMcConnell »

Beautiful, great work!
frostbyte
Orc Shaman
Posts: 737
Joined: Fri May 31, 2013 2:28 am
x 65

Re: [2.1] Ocean

Post by frostbyte »

wow, thanks, best ocean waves i've seen...+3 :wink:
funny but i think i've mentioned in past post the idea of using terra to render waves- i even named it "terra waves"
other idea was modifying terra to render rivers and roads... "terra" seems to be a really good base for lots of stuff.
i remember wondering on the post on "how would it look?"...now i know, it looks amazing... :P

not sure, but maybe its better to put this on github?
anyways, thanks a bunch, much appreciated... :D
the woods are lovely dark and deep
but i have promises to keep
and miles to code before i sleep
and miles to code before i sleep..

coolest videos link( two minutes paper )...
https://www.youtube.com/user/keeroyz/videos
User avatar
Zonder
Ogre Magi
Posts: 1168
Joined: Mon Aug 04, 2008 7:51 pm
Location: Manchester - England
x 73

Re: [2.1] Ocean

Post by Zonder »

nice work :D
There are 10 types of people in the world: Those who understand binary, and those who don't...
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 »

frostbyte wrote:funny but i think i've mentioned in past post the idea of using terra to render waves- i even named it "terra waves"
I stealed your idea on purpose :twisted: ...jk :D
frostbyte wrote:not sure, but maybe its better to put this on github
yes indeed!
https://github.com/yoyTeam/OgreOcean
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] Ocean

Post by al2950 »

Awesome work :)

As we are getting more and more questions about custom HLMS, would this be a good repo to point them to?
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] Ocean

Post by al2950 »

I now want to see what the other sliders on you UI do :D
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:I now want to see what the other sliders on you UI do :D
"Visibilidad" it's just fog, actually the inverse of fog, visibility and its just a simple linear fog
"Nubosidad" cloudiness, just shows less/more clouds in the sky
"Lluvia" rain!
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] Ocean

Post by al2950 »

Oooooo..... damn it that rain shader is better than mine, I want it :lol:
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 can share it... but I don't consider it to be finished, since... it rains indoors xD, I need to mask with a shadow texture or something but its kind of hard to achieve it as I want, so I just give up for now
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:I can share it... but I don't consider it to be finished, since... it rains indoors xD, I need to mask with a shadow texture or something but its kind of hard to achieve it as I want, so I just give up for now
You can use clip distances for that!
Set the number of clip distance you'll be using in the property HlmsBaseProp::GlobalClipDistances.

Then shader-wise, a clip distance is an output from the vertex shader. If any of the clip distances is negative, the vertex won't be drawn. If drawing a line made of two vertices and one vertex has clip distance = 1 and the ther clip distance = -1; then half of the line will be visible: the part where the interpolation is in range [0; 1] and the other half won't be visible which is the part where the interpolation puts the value in range [-1; 0).
Same happens with triangles.

The shaders generated by PlanarReflection use clip distances so you can take a look to see how Ogre uses it (tip: the Unlit shader supports it too, and is easier to analyze).
PlanarReflection culls against a plane; and does so by using the mathematical formula:

Code: Select all

gl_ClipDistance[0] = dot( cull_plane.xyzw, float4( vertex_pos.xyz, 1.0 ) );
For culling against a sphere you would do something like (i.e. everything inside the sphere isn't visible):

Code: Select all

gl_ClipDistance[0] = dot( sphere_center.xyz, vertex_pos.xyz ) - sphere_radius * sphere_radius;
For culling against a cube you would do something like (i.e. everything inside the cube isn't visible):

Code: Select all

float3 dist = abs( cube_center.xyz - vertex_pos.xyz );
dist = dist.xyz - cube_half_size.xyz;
gl_ClipDistance[0] = max( dist.x, dist.y, dist.z );
Clip distances isn't a feature that is often used, but it is very powerful and extremely useful for masking geometry (avoid rain being visible in certain areas; slicing meshes, creating holes, etc) when it is too inconvinient or expensive to do it with a CPU-based algorithm.
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:You can use clip distances for that!
mmm really interesting! but it seems that I'll need to place boxes/spheres everywhere I want no rain... I was thinking something more automatic.

What I did(tried) is:
cast a static shadow from a very far spotlight ( the correct way is to use a directional light so it can be ortho, but they move with the camera, also tried rendering a depthmap with an ortho camera but I din't knew how to use that texture as a shadow lol ) and use that shadow to mask the wetness of the surface, but it looked really bad in certain areas, for example: if I have a tiny cube 30 meters above ground it will still cast shadow, and it shouldn't, but a big cube 30 meters above the ground it should cast shadow, and a tiny cube 5cm above ground it will also have to cast shadow....
So the solution I came up for this is to wiggle/rotate the light an X amount of degrees in order to "paint" the shadowmap with "white" (during a few frames and then make it static again) this way the small cube high above its shadow should move a lot and eventually disappear, the big cube high above its shadow should "erode" a bit, and the tiny cube close to the ground should cast full shadow... just like rain! that doesnt fall strictly vertical. Anyways it dint work in my first try so I move to other stuffs, I'll be back to that later.. but makes sense?? it should work??

The clip distance solves the rain inside cabin's cars/trucks that moves all the time, 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] Ocean

Post by dark_sylinc »

xrgo wrote:
dark_sylinc wrote:You can use clip distances for that!
mmm really interesting! but it seems that I'll need to place boxes/spheres everywhere I want no rain... I was thinking something more automatic.
Yeah, it certainly doesn't scale to lots of places (e.g. comparing every vertex against 30 cubes could be expensive)
xrgo wrote: What I did(tried) is:
cast a static shadow from a very far spotlight ( the correct way is to use a directional light so it can be ortho, but they move with the camera, also tried rendering a depthmap with an ortho camera but I din't knew how to use that texture as a shadow lol ) and use that shadow to mask the wetness of the surface, but it looked really bad in certain areas, for example: if I have a tiny cube 30 meters above ground it will still cast shadow, and it shouldn't, but a big cube 30 meters above the ground it should cast shadow, and a tiny cube 5cm above ground it will also have to cast shadow....
So the solution I came up for this is to wiggle/rotate the light an X amount of degrees in order to "paint" the shadowmap with "white" (during a few frames and then make it static again) this way the small cube high above its shadow should move a lot and eventually disappear, the big cube high above its shadow should "erode" a bit, and the tiny cube close to the ground should cast full shadow... just like rain! that doesnt fall strictly vertical. Anyways it dint work in my first try so I move to other stuffs, I'll be back to that later.. but makes sense?? it should work??
That sounds interesting...
You should manually handle an orthogonal camera and define its size. Think of it as handling a plane with normal = setDirection; and the plane bounds are controlled via setOrthoWindow (which is in world units). If the rain covers a square of 100x100 meters in downwards rain, then you call setOrthoWindow( 100, 100 ) and setDirection( -UNIT_Y );
If it's diagonal, you set a different direction and use pythagoras to displace and enlarge the square a little.

Then using depth you can discover whether something is covered from rain or not; just like shadow maps cover light.
However you're gonna have the same problems: resolution and aliasing. If the area covered by rain is too big, you'll need a bigger resolution depth map. Or (similar to PSSM) cover the most interesting areas with higher res, and somehow cover further away areas or uninteresting ones with lower res.

Then set the clip distance to negative for drops of rain behind the depth map.
xrgo wrote:The clip distance solves the rain inside cabin's cars/trucks that moves all the time, thanks!
You're welcome!
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] Ocean

Post by al2950 »

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.
Post Reply