[2.1] Ocean

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


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 HulkRomain,

thanks! I would like to try out your code. Unfortunately the link seems to be broken. Could you re-upload?

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

User avatar
Crystal Hammer
Gnome
Posts: 317
Joined: Sat Jun 23, 2007 5:16 pm
x 77
Contact:

Re: [2.1] Ocean

Post by Crystal Hammer »

Well since there previous download from HulkRomain doesn't work,
I tried adding the code from this post viewtopic.php?p=539654#p539654.
to my terrain demo on branch ocean (disabled on main).
I made some fixes, since stuff changed in Ogre. I got it to build, but now on start there is a crash compiling vertex shader.

Code: Select all

GLSL compile log: 600000000VertexShader_vs
0:64(1): error: syntax error, unexpected NEW_IDENTIFIER, expecting end of file
WARNING: GraphicsSystem::deinitialize() not called!!!
An exception has occured: OGRE EXCEPTION(3:RenderingAPIException): Vertex Program 600000000VertexShader_vs failed to compile. See compile log above for details. in GLSLShader::compile at ../../RenderSystems/GL3Plus/src/GLSL/OgreGLSLShader.cpp (line 313)

IDK, got no idea, seems like very beginning.
Tried debugging and it fails in this assert:

Code: Select all

        assert( (size_t)(passBufferPtr - startupPtr) * 4u == mapSize );

So yeah it's the same issue as back then in 2017 :cry: :x .
BTW I marked all changes I have doubts with:

Code: Select all

// fixme

or just check my commits for changes.
Pity Ocean didn't go into Ogre officially back then. IDK if this is fixable but now seems like advanced trouble for sure.
Anyway since it's now building with Ogre-next 3.0 master and using GL, maybe someone will try fixing it?

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 »

Looking at the generated 600000000VertexShader_vs may help a lot to see what happened, specially in diagnosing what went wrong (make sure to call setDebugOutputPath() and enable it; the lines with the error provided in the Ogre.log are without the outputProperties dumped on the beginning, which can be disabled in setDebugOutputPath call or stripped by hand from the file).

tritonas00
Halfling
Posts: 87
Joined: Sun Apr 08, 2018 2:21 pm
x 36

Re: [2.1] Ocean

Post by tritonas00 »

It would be great if we can see this ocean in action. And the syntax error doesn't seem that difficult to resolve. On the other hand, i don't know anything about shaders lol. But man, terra + global illumination + HLMS + atmosphere component + this ocean -> heaven :D

User avatar
Crystal Hammer
Gnome
Posts: 317
Joined: Sat Jun 23, 2007 5:16 pm
x 77
Contact:

Re: [2.1] Ocean

Post by Crystal Hammer »

Hi dark_sylinc. (Or anyone interested in testing and fixing this)
I've updated my repo with more info on how to build.
Since you offered help building SR3 from sources, I think it'd be even greater to start with this as it should be simpler to build.

BTW there is still 1 lib missing under https://github.com/OGRECave/ogre-next#d ... cies-linux
for Debian-based, in apt-get that is: libxcb-randr0-dev
I couldn't build without it.

So to test Ocean, just try to follow the commands on my repo: https://github.com/cryham/ogre3ter-demo ... om-sources
But checkout branch ocean. It has what I've got so far, and has the above mentioned assert (in Debug):

Code: Select all

        // fixme crash in debug ..
        assert( (size_t)(passBufferPtr - startupPtr) * 4u == mapSize );

In code just search for // fixme, I marked so few places that I wasn't sure about. Most notably:

Code: Select all

        virtual void uploadToConstBuffer( char *dstPtr, uint8 dirtyFlags )  //new
        {   }   // fixme

which I'd assume can't be empty right? And possibly is the reason for assert?
IDK this code and stuff, feels for me like visiting Asia for 1st time :?
I suspect this issue isn't simple here.

But definitely worth fixing as many people are interested.

Did ocean not use PlanarReflections, only cubemap/env probe? Is is easy and possible to use that insted? I remeber we had flat water in SR and it did work great also with refractions.

I added shader output in my demo code and the line that has this error (in RelWithDebInfo):

Code: Select all

GLSL compile log: 600000000VertexShader_vs
0:64(1): error: syntax error, unexpected NEW_IDENTIFIER, expecting end of file
WARNING: GraphicsSystem::deinitialize() not called!!!
An exception has occured: OGRE EXCEPTION(3:RenderingAPIException): Vertex Program 600000000VertexShader_vs failed to compile. See compile log above for details. in GLSLShader::compile at ../../RenderSystems/GL3Plus/src/GLSL/OgreGLSLShader.cpp (line 313)

is the first line here:

Code: Select all

layout_constbuffer(binding = 2) uniform InstanceBuffer
{
	CellData cellData[256];
} instance;

IDK, seems okay syntax, saw it elsewhere. Maybe my #version 450 is bad here, just guessing.
Here are both shaders:

600000000VertexShader_vs.glsl
(4.41 KiB) Downloaded 35 times
600000000PixelShader_ps.glsl
(4.4 KiB) Downloaded 32 times
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 »

The assert crash was an easy fix. The Ocean sample added a timer variable and wrote to it, but it didn't add the extra bytes to the requested mapping size in mapSize. The fix is simply:

Code: Select all

diff --git a/src/Ocean/Hlms/OgreHlmsOcean.cpp b/src/Ocean/Hlms/OgreHlmsOcean.cpp
index 3b0052c..3644813 100644
--- a/src/Ocean/Hlms/OgreHlmsOcean.cpp
+++ b/src/Ocean/Hlms/OgreHlmsOcean.cpp
@@ -451,6 +451,9 @@ namespace Ogre
             mapSize += ( 3 * 4 * 4 ) * numDirectionalLights;
         }
 
+		// vec4 timer
+		mapSize += 4u * 4u;
+
         mapSize += mListener->getPassBufferSize( shadowNode, casterPass, dualParaboloid,
                                                  sceneManager );
 

Did ocean not use PlanarReflections, only cubemap/env probe? Is is easy and possible to use that insted? I remeber we had flat water in SR and it did work great also with refractions.

Ocean sample was forked before we added PlanarReflections to Terra, so it doesn't seem like it has any mention of planar reflections.

Likely it would be easier to modify the current Terra to reapply the Ocean changes (since they're not actually that many) than to try to add PlanarReflections to the Ocean code.

Edit: Ah, I forgot to checkout the "ocean" branch. I can repro the compiler generation bug.

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 »

Ok I'm trying to get the Ocean compiling but I see it's very out of date compared to OgreNext 3.0

Ironically it's all glue code that changed, they're not big or difficult, but rather it's a lot of small things:

  • The reason you get the current crash (and you had to add #version 450) is because the piece SetCrossPlatformSettings is never defined. To do that, you need to add Hlms/Common/GLSL and Hlms/Common/Any paths to the libraries passed to HlmsOcean

  • After I do that, new problems arise: It now complains in the vertex shader that passBuf is undeclared.

    • This happens because the piece PassDecl (used in Media/Hlms/Ocean/GLSL/VertexShader_vs.glsl) is no longer defined

    • In latest OgreNext 3.0, this piece is defined in Pbs (because Terra used to clone all the code from Pbs, but after a refactor it reuses a lot of code from Pbs)

    • This can be fixed by adding Hlms/Pbs/Any/Main and Hlms/Pbs/Any paths like Terra does

  • However after I add the Pbs shader pieces, it starts complaining that the piece VertexTransform is defined twice (and that error cascades into a lot of other errors).

    • Terra, which used to clone Pbs, used piece VertexTransform

    • But after it was refactored to share code with Pbs, Terra's version was renamed to VertexTerraTransform (see Hlms/Terra/Any/800.VertexShader_piece_vs.any)

And that is as far as I went. There's likely more similar issues once I fix VertexTransform -> VertexTerraTransform. These are all minor issues, but it is time consuming to fix one by one.

This is the patch as far as I had so far:

Code: Select all

diff --git a/Media/Hlms/Ocean/GLSL/PixelShader_ps.glsl b/Media/Hlms/Ocean/GLSL/PixelShader_ps.glsl
index 4320496..ddf83ab 100644
--- a/Media/Hlms/Ocean/GLSL/PixelShader_ps.glsl
+++ b/Media/Hlms/Ocean/GLSL/PixelShader_ps.glsl
@@ -1,5 +1,3 @@
-	#version 450
-
 @property( false )
 @insertpiece( SetCrossPlatformSettings )
 @insertpiece( SetCompatibilityLayer )
diff --git a/Media/Hlms/Ocean/GLSL/Structs_piece_vs_piece_ps.glsl b/Media/Hlms/Ocean/GLSL/Structs_piece_vs_piece_ps.glsl
index d11d337..3b90793 100644
--- a/Media/Hlms/Ocean/GLSL/Structs_piece_vs_piece_ps.glsl
+++ b/Media/Hlms/Ocean/GLSL/Structs_piece_vs_piece_ps.glsl
@@ -1,5 +1,3 @@
-	#version 450
-
 @piece( TerraMaterialDecl )
 layout_constbuffer(binding = 1) uniform MaterialBuf
 {
diff --git a/Media/Hlms/Ocean/GLSL/Textures_piece_ps.glsl b/Media/Hlms/Ocean/GLSL/Textures_piece_ps.glsl
index e1f6183..96232da 100644
--- a/Media/Hlms/Ocean/GLSL/Textures_piece_ps.glsl
+++ b/Media/Hlms/Ocean/GLSL/Textures_piece_ps.glsl
@@ -1,5 +1,3 @@
-	#version 450
-
 @undefpiece( kD )
 @piece( kD )diffuseCol@end
 
diff --git a/Media/Hlms/Ocean/GLSL/VertexShader_vs.glsl b/Media/Hlms/Ocean/GLSL/VertexShader_vs.glsl
index 0446778..88e9a73 100644
--- a/Media/Hlms/Ocean/GLSL/VertexShader_vs.glsl
+++ b/Media/Hlms/Ocean/GLSL/VertexShader_vs.glsl
@@ -1,5 +1,3 @@
-	#version 450
-
 @insertpiece( SetCrossPlatformSettings )
 @insertpiece( SetCompatibilityLayer )
 
diff --git a/include/Ocean/Hlms/OgreHlmsOcean.h b/include/Ocean/Hlms/OgreHlmsOcean.h
index dd2b4a5..45b41fa 100644
--- a/include/Ocean/Hlms/OgreHlmsOcean.h
+++ b/include/Ocean/Hlms/OgreHlmsOcean.h
@@ -185,6 +185,8 @@ namespace Ogre
         AmbientLightMode getAmbientLightMode(void) const    { return mAmbientLightMode; }
 
     void setEnvProbe( Ogre::TextureGpu* probe );
+
+        static void getDefaultPaths( String &outDataFolderPath, StringVector &outLibraryFoldersPaths );
     };
 
     struct OceanProperty
diff --git a/src/Ocean/Hlms/OgreHlmsOcean.cpp b/src/Ocean/Hlms/OgreHlmsOcean.cpp
index 3b0052c..24db5d0 100644
--- a/src/Ocean/Hlms/OgreHlmsOcean.cpp
+++ b/src/Ocean/Hlms/OgreHlmsOcean.cpp
@@ -451,6 +451,9 @@ namespace Ogre
             mapSize += ( 3 * 4 * 4 ) * numDirectionalLights;
         }
 
+        // vec4 timer
+        mapSize += 4u * 4u;
+
         mapSize += mListener->getPassBufferSize( shadowNode, casterPass, dualParaboloid,
                                                  sceneManager );
 
@@ -992,6 +995,32 @@ namespace Ogre
         mProbe = probe;
     }
     //-----------------------------------------------------------------------------------
+    void HlmsOcean::getDefaultPaths( String &outDataFolderPath, StringVector &outLibraryFoldersPaths )
+    {
+        //We need to know what RenderSystem is currently in use, as the
+        //name of the compatible shading language is part of the path
+        Ogre::RenderSystem *renderSystem = Ogre::Root::getSingleton().getRenderSystem();
+        Ogre::String shaderSyntax = "GLSL";
+        if (renderSystem->getName() == "Direct3D11 Rendering Subsystem")
+            shaderSyntax = "HLSL";
+        else if (renderSystem->getName() == "Metal Rendering Subsystem")
+            shaderSyntax = "Metal";
+
+        //Fill the library folder paths with the relevant folders
+        outLibraryFoldersPaths.clear();
+        outLibraryFoldersPaths.push_back( "Hlms/Common/" + shaderSyntax );
+        outLibraryFoldersPaths.push_back( "Hlms/Common/Any" );
+        //outLibraryFoldersPaths.push_back( "Hlms/Pbs/Any" );
+#ifdef OGRE_BUILD_COMPONENT_ATMOSPHERE
+        outLibraryFoldersPaths.push_back( "Hlms/Pbs/Any/Atmosphere" );
+#endif
+        outLibraryFoldersPaths.push_back( "Hlms/Pbs/Any/Main" );
+        outLibraryFoldersPaths.push_back( "Hlms/Ocean/" + shaderSyntax + "/Custom" );
+
+        //Fill the data folder path
+        outDataFolderPath = "Hlms/Ocean/" + shaderSyntax;
+    }
+    //-----------------------------------------------------------------------------------
     HlmsDatablock* HlmsOcean::createDatablockImpl( IdString datablockName,
                                                        const HlmsMacroblock *macroblock,
                                                        const HlmsBlendblock *blendblock,
diff --git a/src/Terrain.cpp b/src/Terrain.cpp
index ed65ecb..96dc9f3 100644
--- a/src/Terrain.cpp
+++ b/src/Terrain.cpp
@@ -201,22 +201,29 @@ namespace Demo
                                       getMediaReadArchiveType(), true ) );
             hlmsPbs->reloadFrom( archivePbs, &libraryPbs );
 
+            {
+                // Create & Register Ocean Hlms
+                // Get the path to all the subdirectories used by HlmsOcean
+                Ogre::HlmsOcean::getDefaultPaths( mainFolderPath, libraryFoldersPaths );
+                Ogre::Archive *archiveOcean = archiveManager.load( rootHlmsFolder + mainFolderPath,
+                                                                   getMediaReadArchiveType(), true );
+                Ogre::ArchiveVec archiveOceanLibraryFolders;
+                libraryFolderPathIt = libraryFoldersPaths.begin();
+                libraryFolderPathEn = libraryFoldersPaths.end();
+                while( libraryFolderPathIt != libraryFolderPathEn )
+                {
+                    Ogre::Archive *archiveLibrary = archiveManager.load(
+                        rootHlmsFolder + *libraryFolderPathIt, getMediaReadArchiveType(), true );
+                    archiveOceanLibraryFolders.push_back( archiveLibrary );
+                    ++libraryFolderPathIt;
+                }
 
-            //  Ocean Hlms
-            Ogre::String dataFolder = rootHlmsFolder;
-            Ogre::ArchiveVec library;
-
-            Ogre::Archive *archiveOcean = Ogre::ArchiveManager::getSingletonPtr()->load(
-                dataFolder + "Hlms/Ocean/GLSL", "FileSystem", true);
-
-            Ogre::Archive *archiveLibraryCustom = Ogre::ArchiveManager::getSingletonPtr()->load(
-                dataFolder + "Hlms/Ocean/GLSL/Custom", "FileSystem", true);
-            library.push_back(archiveLibraryCustom);
-
-            Ogre::HlmsOcean *mHlmsOcean = OGRE_NEW Ogre::HlmsOcean(archiveOcean, &library, mRoot);
-            hlmsManager->registerHlms(mHlmsOcean);
-            mHlmsOcean->setDebugOutputPath(true, false, "shaders/");
-            // todo: delete?
+                // Create and register the terra Hlms
+                Ogre::HlmsOcean *mHlmsOcean =
+                    OGRE_NEW Ogre::HlmsOcean( archiveOcean, &archiveOceanLibraryFolders, mRoot );
+                hlmsManager->registerHlms( mHlmsOcean );
+                mHlmsOcean->setDebugOutputPath( true, false, "shaders/" );
+            }
         }
 
     public:

But like I said in the previous post; I think it would probably be FAR easier to take HlmsTerra.cpp (and all related cpp & shader files) from OgreNext 2.1; compare it with the HlmsOcean sample w/ a visual diff tool; and then re-apply those changes into HlmsTerra.cpp (and all related files) from OgreNext 3.0

User avatar
Crystal Hammer
Gnome
Posts: 317
Joined: Sat Jun 23, 2007 5:16 pm
x 77
Contact:

Re: [2.1] Ocean

Post by Crystal Hammer »

Okay thank you for the effort.
I understand, sounds better to reimplement it on 3.0, given how much has changed in Ogre since 2.1.

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 think the ocean functionality belongs like terra to the Ogre-Next tutorials, as it is a really nice feature!
Imagine the combination of terra and ocean working together :shock:

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

Post Reply