Few serious questions for Ogre-Next, moving Stunt Rally

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


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

Re: Few serious questions for Ogre-Next, moving Stunt Rally

Post by dark_sylinc »

OK I managed to compile and run it! (In full Debug!).

NOW WHAT? :lol: (what problems do I look for?)

I can see there are crashes on shutdown in sr-editor3, but I suspect you have more pressing matters.

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

Re: Few serious questions for Ogre-Next, moving Stunt Rally

Post by dark_sylinc »

Crystal Hammer wrote: Sun Apr 09, 2023 4:42 pm

Ok, great, I didn't see such issue before with conan.

So new way builds, but doesn't seem to skip faces.
Where do I setExecutionMask then? Not in workspace?

Actually faceIdx is 1 after that code, not 6.
My SR3.compositor has this for cube reflect node:

Code: Select all

compositor_node CubemapNode
{
	in 0 cubemap

	texture tmpCubemap target_width target_height target_format cubemap mipmaps 0

	target tmpCubemap +X : cubemap_target { execution_mask 1 }
	target tmpCubemap -X : cubemap_target { execution_mask 2 }
	target tmpCubemap +Y : cubemap_target { execution_mask 4 }
	target tmpCubemap -Y : cubemap_target { execution_mask 8 }
	target tmpCubemap +Z : cubemap_target { execution_mask 16 }
	target tmpCubemap -Z : cubemap_target { execution_mask 32
		pass ibl_specular
		{
			input tmpCubemap
			output cubemap
	}	}
}

I'm guessing 1 pass does 6 faces at once?

First, get rid of the execution_mask in target as it is causing script syntax errors:

Code: Select all

compositor_node CubemapNode
{
	in 0 cubemap

texture tmpCubemap target_width target_height target_format cubemap mipmaps 0

target tmpCubemap +X : cubemap_target {  }
target tmpCubemap -X : cubemap_target { }
target tmpCubemap +Y : cubemap_target {  }
target tmpCubemap -Y : cubemap_target {  }
target tmpCubemap +Z : cubemap_target {  }
target tmpCubemap -Z : cubemap_target {
	pass ibl_specular
	{
		input tmpCubemap
		output cubemap
}	}
}

Second, I edited my reply because it was wrong. Check my reply again with the updated code.

User avatar
Crystal Hammer
Gnome
Posts: 388
Joined: Sat Jun 23, 2007 5:16 pm
x 99

Re: Few serious questions for Ogre-Next, moving Stunt Rally

Post by Crystal Hammer »

dark_sylinc wrote: Sun Apr 09, 2023 4:59 pm

OK I managed to compile and run it! (In full Debug!).

NOW WHAT? :lol: (what problems do I look for?)

I can see there are crashes on shutdown in sr-editor3, but I suspect you have more pressing matters.

Wow, awesome :D
Yes I do have like 3 serious strange issues, but first I'd like to fix whatever is missing with Planar Reflections to get started with water, I think SR is suffocating without it :) And leave Ocean for later since it is much more complicated to port now.

So the issue is that I only see mirror with Unlit material (right), and the mirror with Pbs (left) is not reflecting, it has some white texture but no reflection. I think that mip map generation is working at least it doesn't log any errors. This is shown on that post screen Image.

To check this out, you can follow these steps:

  1. Edit the file /home/username/.config/stuntrally3/editor.cfg
    and change track to this (top under [ game ]):
    track = Test13-Hills

  2. Uncomment this line (277) in src/editor/SceneInit.cpp
    // createReflectiveSurfaces(); // todo: water ...
    This will now create those 2 mirror planes like in Ogre sample.

  3. Build and start sr3-editor project.

  4. Move somewhere to the middle, or follow the arrow on minimap from screenshot.
    With WS,AD,QE etc or Ctrl-F1 for quick help on editor, 2nd tab View.

I'm kind of lost on what I could mess up or forget, that this is not working.

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

Re: Few serious questions for Ogre-Next, moving Stunt Rally

Post by dark_sylinc »

Overview

  • PBS Planar Reflections not working was an Ogre bug. Fixed. Thanks! (and sorry! I'm sure you went crazy and you did nothing wrong)

  • GlassRoughness.png is missing (the error shows up in Ogre.log). It's included in our samples.

  • You correctly call workspace->addListener( mWorkspaceListener ); so that PlanarReflectionsWorkspaceListener is updated. However this also needs to be done to every workspace that can see the reflection (e.g. the cubemap workspaces). Otherwise the reflections will be wrong in the Cubemap, and additionally Vulkan is going to crash.

Vulkan Support

Why Vulkan? It has better support for debugging tools. And it complains more, which is good for finding errors but also worse when you just want to get something quickly on screen to see if you're in the right track.

I managed to get Vulkan working with the following patch BUT I had to disable MyGUI (more on this below):

Code: Select all

diff --git a/CMake/Dependencies/OGRE.cmake b/CMake/Dependencies/OGRE.cmake
index a5024a6..d05ee20 100644
--- a/CMake/Dependencies/OGRE.cmake
+++ b/CMake/Dependencies/OGRE.cmake
@@ -110,7 +110,7 @@ macro( setupPluginFileFromTemplate BUILD_TYPE OGRE_USE_SCENE_FORMAT OGRE_USE_PLA
 		findPluginAndSetPath( ${BUILD_TYPE} OGRE_PLUGIN_RS_D3D11	RenderSystem_Direct3D11 )
 		findPluginAndSetPath( ${BUILD_TYPE} OGRE_PLUGIN_RS_GL3PLUS	RenderSystem_GL3Plus )
 		findPluginAndSetPath( ${BUILD_TYPE} OGRE_PLUGIN_RS_PARTICLE	Plugin_ParticleFX )
-		### findPluginAndSetPath( ${BUILD_TYPE} OGRE_PLUGIN_RS_VULKAN	RenderSystem_Vulkan )
+		findPluginAndSetPath( ${BUILD_TYPE} OGRE_PLUGIN_RS_VULKAN	RenderSystem_Vulkan )
 
if( ${BUILD_TYPE} STREQUAL "Debug" )
	configure_file( ${CMAKE_SOURCE_DIR}/CMake/Templates/Plugins.cfg.in
@@ -175,7 +175,7 @@ macro( setupPluginFileFromTemplate BUILD_TYPE OGRE_USE_SCENE_FORMAT OGRE_USE_PLA
 		unset( OGRE_PLUGIN_RS_D3D11 )
 		unset( OGRE_PLUGIN_RS_GL3PLUS )
 		unset( OGRE_PLUGIN_RS_PARTICLE )
-		### unset( OGRE_PLUGIN_RS_VULKAN )
+		unset( OGRE_PLUGIN_RS_VULKAN )
 	endif()
 
 	unset( OGRE_BUILD_TYPE_MATCHES )
diff --git a/bin/Debug/plugins_d.cfg b/bin/Debug/plugins_d.cfg
index bbfe16d..bfee6db 100644
--- a/bin/Debug/plugins_d.cfg
+++ b/bin/Debug/plugins_d.cfg
@@ -6,5 +6,5 @@ PluginFolder=Plugins
 # Define plugins
 
 PluginOptional=RenderSystem_GL3Plus_d
-
+PluginOptional=RenderSystem_Vulkan_d
 PluginOptional=Plugin_ParticleFX_d
diff --git a/src/Terra/Terra2.cpp b/src/Terra/Terra2.cpp
index 5716ef8..244388a 100644
--- a/src/Terra/Terra2.cpp
+++ b/src/Terra/Terra2.cpp
@@ -189,6 +189,14 @@ namespace Ogre
 		//	pTerra->mManager->destroyCamera( camera );
 		#endif
 
+		RenderSystem *renderSystem = pTerra->mManager->getDestinationRenderSystem();
+		renderSystem->endCopyEncoder();
+		BarrierSolver &barrierSolver = renderSystem->getBarrierSolver();
+		ResourceTransitionArray resourceTransitions;
+		barrierSolver.resolveTransition( resourceTransitions, texture, ResourceLayout::Texture,
+										 ResourceAccess::Read, 1u << GPT_FRAGMENT_PROGRAM );
+		renderSystem->executeResourceTransition( resourceTransitions );
+
 		//^^ todo:  for GetTerMtrIds  tire ter surf ..
 		// texture->writeContentsToFile("blendmapRTT.png", 0, 1);  //** ter test blendmap
 	}
diff --git a/src/common/AppGui_UtilMem.cpp b/src/common/AppGui_UtilMem.cpp
index c2b5901..8ab6e70 100644
--- a/src/common/AppGui_UtilMem.cpp
+++ b/src/common/AppGui_UtilMem.cpp
@@ -167,7 +167,14 @@ void AppGui::MinimizeMemory()
 	Root *root = mGraphicsSystem->getRoot();
 	RenderSystem *renderSystem = root->getRenderSystem();
 	VaoManager *vaoManager = renderSystem->getVaoManager();
-	vaoManager->cleanupEmptyPools();
+	try
+	{
+		vaoManager->cleanupEmptyPools();
+	}
+	catch( UnimplementedException & )
+	{
+		// Ignore. Vulkan doesn't implement this (yet?).
+	}
 }
 
 #if 0
diff --git a/src/editor/Render2tex.cpp b/src/editor/Render2tex.cpp
index 732fb7c..9a314dd 100644
--- a/src/editor/Render2tex.cpp
+++ b/src/editor/Render2tex.cpp
@@ -159,7 +159,16 @@ void App::CreateRnd2Tex()
 			MaterialPtr brush_mt = getByName("BrushPrvMtr");
 			r.mini->setMaterial(i == RT_Brush ? brush_mt : mt);
 			r.mini->setVisibilityFlags(i == RT_Last ? RV_MaskPrvCam : RV_Hud);*/
-		}	}
+		}
+
+		RenderSystem *renderSystem = mSceneMgr->getDestinationRenderSystem();
+		renderSystem->endCopyEncoder();
+		BarrierSolver &barrierSolver = renderSystem->getBarrierSolver();
+		ResourceTransitionArray resourceTransitions;
+		barrierSolver.resolveTransition( resourceTransitions, r.tex, ResourceLayout::Texture,
+										 ResourceAccess::Read, 1u << GPT_FRAGMENT_PROGRAM );
+		renderSystem->executeResourceTransition( resourceTransitions );
+		}
 	}
 
 	//  backgr cover prv cam meh-
diff --git a/src/editor/SceneInit.cpp b/src/editor/SceneInit.cpp
index 85ab54c..330be09 100644
--- a/src/editor/SceneInit.cpp
+++ b/src/editor/SceneInit.cpp
@@ -274,7 +274,7 @@ void App::LoadTrackEv()
 	
 	CreateRnd2Tex();  // 🖼️
 
-	// createReflectiveSurfaces();
+	createReflectiveSurfaces();
 	
 	//UpdVisGui();
 	UpdStartPos();

I had to hack OgreHlmsPbs.cpp to get Vulkan running with reflections because of the error I mentioned (the cubemap workspaces must add the listeners but right now they are not doing that).

I didn't check if there are Vulkan validation errors.

Your app compiles a lot of PSOs and shaders (1000 shaders! and roughly 500 PSOs!) and thus shader compilation in Vulkan feels slow; specially app initialization and when new objects (with new shaders) appear on screen. This problem is also shared with GL3+, but it's probably more notorious in Vulkan.

It will heavily benefit from OgreNext 4.0 (currently living in warm_up branch) which introduces multithreaded shader compilation, multithreaded PSO generation and SPIR-V cache for Vulkan. The difference is night and day.

I can't recommend it yet though, because the API may change in the future.

MyGUI and Vulkan

There is a crash while trying to render MyGUI. I had to apply this patch:

Code: Select all

diff --git a/Platforms/Ogre2/Ogre2Platform/src/MyGUI_Ogre2RenderManager.cpp b/Platforms/Ogre2/Ogre2Platform/src/MyGUI_Ogre2RenderManager.cpp
index 5944add4d..c378d63dc 100644
--- a/Platforms/Ogre2/Ogre2Platform/src/MyGUI_Ogre2RenderManager.cpp
+++ b/Platforms/Ogre2/Ogre2Platform/src/MyGUI_Ogre2RenderManager.cpp
@@ -249,7 +249,7 @@ namespace MyGUI
                onRenderToTarget(this, mUpdate);
 
            mRenderSystem->executeRenderPassDescriptorDelayedActions();
-               mSceneManager->getRenderQueue()->render(mRenderSystem, RENDER_QUEUE_OVERLAY, RENDER_QUEUE_OVERLAY+1, false, false);
+               mSceneManager->getRenderQueue()->render(mRenderSystem, RENDER_QUEUE_OVERLAY+1, RENDER_QUEUE_OVERLAY+1, false, false);
                // mSceneManager->getRenderQueue()->render(mSceneManager->getDestinationRenderSystem(), RENDER_QUEUE_OVERLAY, RENDER_QUEUE_OVERLAY+1, false, false);
 
        // сбрасываем флаг

Which essentially disables GUI rendering on Vulkan.

I want to revisit this when I get some time because the error was quite weird: it shouldn't happen. Which means that either:

  1. MyGUI is doing something wrong or something OgreNext doesn't expect.
  2. The Vulkan backend has a bug or doesn't consider an edge case.

Pictures

This was taken using the Vulkan backend:

Rebuild everything

I fixed the PBS planar reflection, but you will need to pull the latest OgreNext + rebuild it + rebuild MyGUI + rebuild sr3 + Run CMake again to copy all *.so libs.

If you don't do all that you may end up with an ABI error that is hard to find (at best it crashes, at worst it causes erratic bad behavior).

User avatar
Crystal Hammer
Gnome
Posts: 388
Joined: Sat Jun 23, 2007 5:16 pm
x 99

Re: Few serious questions for Ogre-Next, moving Stunt Rally

Post by Crystal Hammer »

Holy cow, I didn't even suspect a bug in Ogre with this yet. Well great that you've fixed it already. :shock:
Yeah I forgot I had GlassRoughness.png here but didn't push it since it was just for test.
I think I'll support Vulkan too in SR3. Probably will need some effort but sounds useful.

Your app compiles a lot of PSOs and shaders (1000 shaders! and roughly 500 PSOs!)

Do you think I'm doing something wrong, or is this just because of so many materials?
I just searched for "hlms " in *.material* files and it got 879 results, so that many materials are in SR3 right now. But only a small subset (I'm guessing 20-40 or so) will be present on one track/map.

User avatar
Crystal Hammer
Gnome
Posts: 388
Joined: Sat Jun 23, 2007 5:16 pm
x 99

Re: Few serious questions for Ogre-Next, moving Stunt Rally

Post by Crystal Hammer »

Okay. I will probably rebuild all deps and SR3 tomorrow, since it's late already and it'll take a while.
BTW, reflection cube faces skip is working now.

One of the other issues and how to test it, if you have the time:
This is the one with weird stuff happening to my road mesh (like offset was bad or every 2nd vertex went nuts):
Image

To test this issue:

  • Change the track either in /home/username/.config/stuntrally3/editor.cfg
    to this (from the screenshot): track = TestC8-Align
    or pick from list and load in Track tab, there is a find box left too.
  • In file src/road/Road_Mesh.cpp comment out line 34, like so:
    //#define V1tangents
  • Build and start sr3-editor.

Road will be now creating V2 meshes with tangents. Just search for V1tangents in that file, this is just a try. It sets tangents wrong, but I thought I'd try this before using any real tangents and binormals computing code.
I mean I have to create a V2 mesh with those in vertex declarations right? But now when I do, I get messed positions, which doesn't seem to be right.
I'm lost with what's causing this, I think I've checked a few things already like different VET_ types and line below has also comented out binormal if needed, but I just get funny looking random road mess every try. And I'd expect my road, just badly lit, due to wrong tangents or so.

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

Re: Few serious questions for Ogre-Next, moving Stunt Rally

Post by dark_sylinc »

Crystal Hammer wrote: Sun Apr 09, 2023 9:32 pm

Do you think I'm doing something wrong, or is this just because of so many materials?
I just searched for "hlms " in *.material* files and it got 879 results, so that many materials are in SR3 right now. But only a small subset (I'm guessing 20-40 or so) will be present on one track/map.

It's normal to have 1000 if you have lots of materials (Unreal Engine 4/5 can easily have 100.000...).
It's quite possible (once everything is working) this can be optimized by placing breakpoints when a new PSO is being created and dump what material it is and why a new PSO is needed; and manually see if this can be avoided.

Less amount of PSO means lower loading times and potentially less stutter/stalls and higher performance. But if it can't be avoided, it can't be avoided.

If you have 10k PSOs, then I'd be wondering why (just because UE4 or other games can easily go into 100k territory doesn't mean it's ok) and it's a sign you're doing it wrong.

One of the other issues and how to test it, if you have the time:
This is the one with weird stuff happening to my road mesh (like offset was bad or every 2nd vertex went nuts):

I found the problem. You'll bang your head against the wall when you realize what's wrong. TBH I'm not fan of the coding style you have here, because it's hiding the problem.

After I changed to my style it became obvious.

You have 3 paths and 2 of them need to account for v1 tangents:

Code: Select all

if( trail )
{
	// Can't have v1 tangents
}
else if( hasClr )
{
	// YOU FORGOT TO ADD V1 TANGENTS HERE!
}
else
{
	// You only added V1 tangents here
}

When I changed it to:

Code: Select all

	if( trail )
	{
		for( uint i = 0; i < vertCnt; ++i )
		{
			v[a++] = pos[i].x; v[a++] = pos[i].y; v[a++] = pos[i].z;
			aabox.merge( pos[i] );
			v[a++] = clr[i].x; v[a++] = clr[i].y; v[a++] = clr[i].z; v[a++] = clr[i].w;
		}
	}
	else if( hasClr )
	{
		for( uint i = 0; i < vertCnt; ++i )
		{
			v[a++] = pos[i].x; v[a++] = pos[i].y; v[a++] = pos[i].z;
			aabox.merge( pos[i] );
			v[a++] = norm[i].x; v[a++] = norm[i].y; v[a++] = norm[i].z;
#ifndef V1tangents
			v[a++] = norm[i].x; v[a++] = norm[i].z; v[a++] = norm[i].y;  // tangent-
			// v[a++] = norm[i].z;  v[a++] = norm[i].y;  v[a++] = norm[i].x;  // binormal-
#endif
			v[a++] = tcs[i].x; v[a++] = tcs[i].y;
			v[a++] = clr[i].x; v[a++] = clr[i].y; v[a++] = clr[i].z; v[a++] = clr[i].w;
		}
	}
	else
	{
		for( uint i = 0; i < vertCnt; ++i )
		{
			v[a++] = pos[i].x; v[a++] = pos[i].y; v[a++] = pos[i].z;
			aabox.merge( pos[i] );
			v[a++] = norm[i].x; v[a++] = norm[i].y; v[a++] = norm[i].z;
#ifndef V1tangents
			v[a++] = norm[i].x; v[a++] = norm[i].z; v[a++] = norm[i].y;  // tangent-
			// v[a++] = norm[i].z;  v[a++] = norm[i].y;  v[a++] = norm[i].x;  // binormal-
#endif
			v[a++] = tcs[i].x; v[a++] = tcs[i].y;
			// v[a++] = tcs[i].x;   v[a++] = tcs[i].y;  //2nd uv-
		}
	}

The problem went away :lol: .

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

Re: Few serious questions for Ogre-Next, moving Stunt Rally

Post by dark_sylinc »

Oh btw disable the use of USE_UMA_SHARED_BUFFERS. That is incredibly advanced and there's 99.99% chance you'll get it wrong.

It shouldn't be doing anything on any RenderSystem other than Metal on iOS (or M1), but just to be sure disable it.

User avatar
Crystal Hammer
Gnome
Posts: 388
Joined: Sat Jun 23, 2007 5:16 pm
x 99

Re: Few serious questions for Ogre-Next, moving Stunt Rally

Post by Crystal Hammer »

Aah. So I was going the the hasClr way and didn't realize for so long.
Thanks for finding out. I feel stupid :roll:
Yeah SR road code feels like another galaxy. And I'll have to rework it again soon to have grid based segments merging not by road length.

User avatar
Crystal Hammer
Gnome
Posts: 388
Joined: Sat Jun 23, 2007 5:16 pm
x 99

Re: Few serious questions for Ogre-Next, moving Stunt Rally

Post by Crystal Hammer »

All right PBS planar reflection is working fine now after rebuilding all 8) .

There is a tiny bug in this line for clear coat, in Media/Hlms/Pbs/Any/Main/200.BRDFs_piece_ps.any:

Code: Select all

		Rs += pixelData.clearCoatEnvColourS * pixelData.specular.xyz * ( _h ( 0.04 ) * clearCoatEnvBRDF.x + clearCoatEnvBRDF.y ) * pixelData.clearCoat;

Was crashing for me in GL3+. It's that space after _h, should be w/o it: _h( :mrgreen:

BTW is there a way to have brighter clear coat, not dark when material color is dark too? Or is that not natural / PBR correct? I think I saw black cars with mirror like reflection or would want to see them.
Ok I think I'm close to it, after removing * pixelData.specular.xyz.

User avatar
Crystal Hammer
Gnome
Posts: 388
Joined: Sat Jun 23, 2007 5:16 pm
x 99

Re: Few serious questions for Ogre-Next, moving Stunt Rally

Post by Crystal Hammer »

I got a few questions:

  • I got a problem with planar reflections, when it is XZ plane flat, for water, I sometimes see skirt in reflection where only sky should be.
    Can I somehow disable Terra skirt when rendering planar reflections (e.g. by passing shader uniform value)? That'd be great.
    I remember having this problem in old SR too, and IIRC our only fix there was to make skirt very small.
  • On this screen with PBS reflection plane on left:
    Image
    Why is reflection brighter or even more saturated colors? Is there some magic in shader to get it back to normal look? Just like the unlit reflection on right.
  • For our split screen (with 2 to 4 players at once) I should update Terra for each player camera, how to do it in code? Do I need a workspace listener and update Terra there? Which of its method do I override and use for this?
  • I have a problem when I have 2 Terras (or more). When I deform on last terrain I get correct normalmap update and my blendmap too. But when I deform on first terrain, I get no normalmap, seems empty, blendmap too, only gets same noise.
    It all works when I just create terrains, they get proper normalmap and blendmap. Strangely problem is only when I update.
    Do you think this is something I forgot or did wrong in my code? Or is there maybe a reason this wouldn't work anyway?
  • I added a HlmsPbs2 and I'm using it just as Pbs. It is cool, I just check if material name has e.g. grass.
    But there already was a HlmsListener in Terra: HlmsPbsTerraShadows. Can I have only 1 HlmsListener?
    I added globalTime there, in preparePassBuffer, *passBufferPtr++ = globalTime; seems working, but not for Terra.
  • If I set this item->getSubItem(0)->setCustomParameter(1234, Vector4(selected ? 1 : 0, 0,0,0));
    Do I need to call anything after? I did this to update items to have a custom shader piece for selected items glow.

OFC If needed I can make a video for these problems or describe how to test them in SR3. I just wanted to ask first, maybe you'd know what's wrong already.

User avatar
Crystal Hammer
Gnome
Posts: 388
Joined: Sat Jun 23, 2007 5:16 pm
x 99

Re: Few serious questions for Ogre-Next, moving Stunt Rally

Post by Crystal Hammer »

I did change the brightness and color of reflection with specular in the pbs material. And found a topic that answered that I can only have 1 HlmsListener. But that's all.
Any chance for some hints or answers for the remaining?

I can't really use this as it is for water or anything.
I made a video of the issues I still have with plane reflection and Terra.
I guess my setup is bad or something, but I already tried changing every value there is. It looks like it needs adjusting clip height (plane distance) for rendering reflection, because it is rendering too far. Or something like that. But nothing I did, changes this. Is this maybe a bug?

  • Is it possible to disable Terra skirt (set its shader property) just for the pass that renders this reflection?
  • Will I be able to use it for water? I'd only need to apply some uv offset for that reflection texture or so, we had a good shader and very nice looking water/mud this way, also with refraction. But I see that normal map makes it just very blurry here, I guess I'd need to modify some shader code.
  • There is also this odd twitching (probably low float precision?) when camera is close to reflection.

Anyways, if you wanted to test this:

  • pull latest version
  • uncomment line 282 in src/editor/SceneInit.cpp:
    scn->refl.CreateReflect(); // todo: water ...
  • build and start sr-editor
  • set track = For4-OSquare in editor.cfg or load via Gui
  • code is now in FluidReflect::CreateReflect() in src/common/Reflect.cpp
User avatar
dark_sylinc
OGRE Team Member
OGRE Team Member
Posts: 5433
Joined: Sat Jul 21, 2007 4:55 pm
Location: Buenos Aires, Argentina
x 1341

Re: Few serious questions for Ogre-Next, moving Stunt Rally

Post by dark_sylinc »

I'll be brief: I'll have to pay attention at what's going on with Reflection + Terra.

It is likely that there needs "something" to be done for it to be rendered properly; it is very likely there's some missing support from the Ogre side.

User avatar
Crystal Hammer
Gnome
Posts: 388
Joined: Sat Jun 23, 2007 5:16 pm
x 99

Re: Few serious questions for Ogre-Next, moving Stunt Rally

Post by Crystal Hammer »

Sounds good. Any idea when you'll be able to continue with it?

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

Re: Few serious questions for Ogre-Next, moving Stunt Rally

Post by dark_sylinc »

Sorry, I forgot. I fixed the problem.

I don't know if that fixes every reflection problem you had with Terra, but I can't find anything wrong with the terrain's reflections fow now.

User avatar
Crystal Hammer
Gnome
Posts: 388
Joined: Sat Jun 23, 2007 5:16 pm
x 99

Re: Few serious questions for Ogre-Next, moving Stunt Rally

Post by Crystal Hammer »

Amazing. And that was only 3 lines of code. After your previous post I was afraid this would need something bigger.
Yeah, I have to admit, you do forget my issues in Ogre-Next quite often.

Okay it fixed the main problem with clipping distance. Terrain reflects okay now.
I fixed that twitching by using more segments in plane mesh, had 1 before and triangles were huge.
Now I got like 3 issues:

  • Suddenly all my items (vegetation, road, objects) are completely shadowed everywhere with that reflection plane present. If I don't create that plane, it's normal. I do have item->setCastShadows(false), doesn't matter.
  • How do I offset, per pixel the reflection uv in shader, any hint where? Using normalmap doesn't change it, reflection is always flat.
  • I see normalmap is working but it doesn't even give any specular highlights on water plane, seems a bit broken as it gets black with less flat normal values.
User avatar
dark_sylinc
OGRE Team Member
OGRE Team Member
Posts: 5433
Joined: Sat Jul 21, 2007 4:55 pm
Location: Buenos Aires, Argentina
x 1341

Re: Few serious questions for Ogre-Next, moving Stunt Rally

Post by dark_sylinc »

Crystal Hammer wrote: Sat May 06, 2023 8:01 pm
  • Suddenly all my items (vegetation, road, objects) are completely shadowed everywhere with that reflection plane present. If I don't create that plane, it's normal. I do have item->setCastShadows(false), doesn't matter.

Does by any chance look like this?
https://github.com/OGRECave/ogre-next/issues/369

A user reported that bug that I haven't looked at.

Crystal Hammer wrote: Sat May 06, 2023 8:01 pm
  • How do I offset, per pixel the reflection uv in shader, any hint where? Using normalmap doesn't change it, reflection is always flat.

Planar reflections are limited in flexibility so that will depend on how much distortion you want to apply. But I just looked up and we're using pixelData.normal
The code you're looking for is in Samples/Media/Hlms/Pbs/Any/PlanarReflections_piece_ps.any

Look for planarReflUVs. The normal is living in pixelData.normal.

Note: You may see that we do this in code:

Code: Select all

float distanceToPlanarReflPlane = dot( planarReflection.xyz, inPs.pos.xyz ) + planarReflection.w;
float3 pointInPlane = inPs.pos.xyz - pixelData.normal * distanceToPlanarReflPlane;

Don't be confused: That code isn't for applying normal mapping into the planar reflection, it's just a trick for when the surface isn't a perfect plane.

A user wanted to use the planar reflections on furniture. And this trick allows it to put the reflection on more complex surfaces. Of course, the less the furniture looks like a plane in the exact position where the reflection plane is, the more distorted the reflection becomes.

We later apply planarWeight to fade out cases where it distorts too much.

Tip: Try doing the same but in the opposite direction, because what want is to purposely distort the reflection:

Code: Select all

float arbitraryDistortion = 5.0f;
float3 pointInPlane = inPs.pos.xyz - pixelData.normal * distanceToPlanarReflPlane + pixelData.normal * arbitraryDistortion;

If that achieves your goal, we can look into integrating that into mainline.

User avatar
Crystal Hammer
Gnome
Posts: 388
Joined: Sat Jun 23, 2007 5:16 pm
x 99

Re: Few serious questions for Ogre-Next, moving Stunt Rally

Post by Crystal Hammer »

Ok thanks, it's what I needed.
Can't use y for water, so for now I got this working:

Code: Select all

float3 pointInPlane = inPs.pos.xyz - pixelData.normal * distanceToPlanarReflPlane
	+ pixelData.normal * float3(5.0, 0.0, 5.0);

No, it seems a different bug, or something I have wrong. Not sure if I had it before, possibly. It isn't the fix in shader that makes all objects shadowed. Basically if I have reflection plane (doesn't matter if small, or where) all objects are fully shadowed. No idea.

  • How can I set plane reflection camera's Lod bias or view distance and such?
    I've tried adding in void ReflectListener::passEarlyPreExecute( e.g. camera->setLodBias(0.1f); but if only does degrade Lod for my regular camera.
User avatar
dark_sylinc
OGRE Team Member
OGRE Team Member
Posts: 5433
Joined: Sat Jul 21, 2007 4:55 pm
Location: Buenos Aires, Argentina
x 1341

Re: Few serious questions for Ogre-Next, moving Stunt Rally

Post by dark_sylinc »

Crystal Hammer wrote: Sun May 07, 2023 6:12 pm

It isn't the fix in shader that makes all objects shadowed. Basically if I have reflection plane (doesn't matter if small, or where) all objects are fully shadowed. No idea.

Can you post a picture?

I can check that out on your following your last instructions?

Crystal Hammer wrote: Sun May 07, 2023 6:12 pm
  • How can I set plane reflection camera's Lod bias or view distance and such?
    I've tried adding in void ReflectListener::passEarlyPreExecute( e.g. camera->setLodBias(0.1f); but if only does degrade Lod for my regular camera.

Mmm, I'm noticing you can't do that without changing Ogre's code.

You need to get access to the ActiveActorData::workspace and add the listener, or provide the listener to setMaxActiveActors() so that when Ogre calls addWorkspace it automatically adds your specified listener.

User avatar
Crystal Hammer
Gnome
Posts: 388
Joined: Sat Jun 23, 2007 5:16 pm
x 99

Re: Few serious questions for Ogre-Next, moving Stunt Rally

Post by Crystal Hammer »

Sure, here is a screen, track is named Sway.
I chose it because it is clearly visible: rocks, road, even grass are dark, shadowed. And in reflection they are not.
Yes you can test the way I wrote before (just track = Can4-Sway is better, but it happens on any).
Hmm maybe this is bad terrain shadowmap? But I disabled it, I had that issue with my unnormalized any float values being bad below 0 height. Will have to fix it someday. I don't really want to normalize my terrain height, especially when it is crashing now :roll:

You do not have the required permissions to view the files attached to this post.
User avatar
Crystal Hammer
Gnome
Posts: 388
Joined: Sat Jun 23, 2007 5:16 pm
x 99

Re: Few serious questions for Ogre-Next, moving Stunt Rally

Post by Crystal Hammer »

Any update on this?
I think it could be not related to planar reflections even, but with workspaces setup in general, either shadows or terrain shadowmap etc.
I got a possibly similar issue in sr-editor if I switch to manual RTT update like so:
lines 127-8 in src/editor/Render2tex.cpp

Code: Select all

			// r.ws = mgr->addWorkspace( mSceneMgr, chan, r.cam, name, true );  //! slower
			r.ws = mgr->addWorkspace( mSceneMgr, chan, r.cam, name, false );  // todo: manual update

and uncomment lines 204-6:

Code: Select all

		r.ws->_beginUpdate(true);
		r.ws->_update();  // todo: upd when needed only, skip
		r.ws->_endUpdate(true);

I get shadowed RTTs. Most notably camera preview (toggle with F7), and terrain top view (alt-F2,F3 cycles them all) in minimap corner.
Plus I don't have reflection plane but some dark solid color (on both).
And I really don't want to update those RTTs every frame.

Here is a screen, also BTW:

  • why is my shadow suddenly so square after 1st shadowmap? This was track = Des4-SBridge
  • how do I disable fog (Atmosphere) for RTTs?
13_13-12-09`.jpg
You do not have the required permissions to view the files attached to this post.
User avatar
dark_sylinc
OGRE Team Member
OGRE Team Member
Posts: 5433
Joined: Sat Jul 21, 2007 4:55 pm
Location: Buenos Aires, Argentina
x 1341

Re: Few serious questions for Ogre-Next, moving Stunt Rally

Post by dark_sylinc »

Crystal Hammer wrote: Sat May 13, 2023 12:08 pm

Any update on this?

I can only work on this on weekends, and only partially.

Good news, I fixed the problem. I missed it last time because Vulkan was masking it with "no terrain shadows", but GL3+ was going full "terrain shadows".

Note that OgreHlmsPbsTerraShadows.cpp is a file that you have to copy to your own repo, so you need to update sr3/src/Terra/Hlms/PbsListener/OgreHlmsPbsTerraShadows.cpp accordingly.

I also found a few other problems that came from your Ogre.log:

Code: Select all

Compiler error: invalid parameters in GpuBlendlMapper.compositor(4): RTV rt_outputcannot be overriden because it comes from an input. Create a duplicate instead
Compiler error: invalid parameters in GpuBlendlMapper.compositor(26): RTV rt_outputcannot be overriden because it comes from an input. Create a duplicate instead
Compiler error: invalid parameters in GpuBlendlMapper.compositor(48): RTV rt_outputcannot be overriden because it comes from an input. Create a duplicate instead
Compiler error: invalid parameters in GpuBlendlMapper.compositor(70): RTV rt_outputcannot be overriden because it comes from an input. Create a duplicate instead

That happens because you have this:

Code: Select all

compositor_node Terra/GpuBlendMapper
{
	in 0 rt_output
	rtv rt_output
	{	slice 1  }  // draw to slice 1

target rt_output
{
	pass render_quad
	{
		material Terra/GpuBlendMapper
	}
	pass generate_mipmaps
	{	}
}
}

This would be valid if rt_output was a local texture, but it's an input. And unfortunately we don't support modifying autogenerated RTVs from an input.

I believe it should be this (note that slices start from 0, slice 1 means to write to the 2nd slice):

Code: Select all

compositor_node Terra/GpuBlendMapper
{
	in 0 rt_output
	
rtv myRtv
{
	colour		rt_output
	depth_stencil	rt_output  
	slice 1 // draw to slice 1
}

target myRtv
{
	pass render_quad
	{
		material Terra/GpuBlendMapper
	}
	pass generate_mipmaps
	{	}
}
}

Next error: You have:

Code: Select all

hlms roadMudWet pbs : road
{
	diffuse_map  roadMud.jpg
	roadAsphalt_spec2.jpg
	diffuse  0.7 0.7 0.7
	specular 0.3 0.3 0.2
}

I believe the correct material definition is:

Code: Select all

hlms roadMudWet pbs : road
{
	diffuse_map  roadMud.jpg
	specular_map roadAsphalt_spec2.jpg
	diffuse  0.7 0.7 0.7
	specular 0.3 0.3 0.2
}

Next error: Please run in Debug mode. When launching stuntrally3 (not the editor) I get this assert:

Code: Select all

stuntrally3: ../../OgreMain/include/OgreNode.h:681: const Ogre::Matrix4& Ogre::Node::_getFullTransform() const: Assertion `!mCachedTransformOutOfDate' failed.

Hooking a debugger I see that the object in question triggering the error is "skymesh".

You shouldn't modify SceneNodes (or AABBs) in listeners because SceneManager::updateAllTransforms has already been called.
But if you do (which can happen if you need to move a Camera or the Sky) after you're done with your modifications you can call node->_getFullTransformUpdated(). See documentation.

Next issue: Please apply this patch for Vulkan support.

Code: Select all

diff --git a/src/Terra/Terra2.cpp b/src/Terra/Terra2.cpp
index 0501df3..3e7f132 100644
--- a/src/Terra/Terra2.cpp
+++ b/src/Terra/Terra2.cpp
@@ -198,6 +198,14 @@ namespace Ogre
 		//	sceneMgr->destroyCamera( camera );
 		#endif
 
+		RenderSystem *renderSystem = pTerra->mManager->getDestinationRenderSystem();
+		renderSystem->endCopyEncoder();
+		BarrierSolver &barrierSolver = renderSystem->getBarrierSolver();
+		ResourceTransitionArray resourceTransitions;
+		barrierSolver.resolveTransition( resourceTransitions, texture, ResourceLayout::Texture,
+										 ResourceAccess::Read, 1u << GPT_FRAGMENT_PROGRAM );
+		renderSystem->executeResourceTransition( resourceTransitions );
+
 		//^^ todo:  for GetTerMtrIds  tire ter surf ..
 		// texture->writeContentsToFile("blendmapRTT.png", 0, 1);  //** ter test blendmap
 	}
diff --git a/src/common/AppGui_UtilMem.cpp b/src/common/AppGui_UtilMem.cpp
index c2b5901..8ab6e70 100644
--- a/src/common/AppGui_UtilMem.cpp
+++ b/src/common/AppGui_UtilMem.cpp
@@ -167,7 +167,14 @@ void AppGui::MinimizeMemory()
 	Root *root = mGraphicsSystem->getRoot();
 	RenderSystem *renderSystem = root->getRenderSystem();
 	VaoManager *vaoManager = renderSystem->getVaoManager();
-	vaoManager->cleanupEmptyPools();
+	try
+	{
+		vaoManager->cleanupEmptyPools();
+	}
+	catch( UnimplementedException & )
+	{
+		// Ignore. Vulkan doesn't implement this (yet?).
+	}
 }
 
 #if 0
diff --git a/src/editor/Render2tex.cpp b/src/editor/Render2tex.cpp
index cb3b7dd..5ff90d6 100644
--- a/src/editor/Render2tex.cpp
+++ b/src/editor/Render2tex.cpp
@@ -150,7 +150,16 @@ void App::CreateRnd2Tex()
 			r.nd = mSceneMgr->getRootSceneNode()->createChildSceneNode();
 			r.nd->attachObject(r.hr);
 			r.nd->setVisible(false);//pSet->trackmap);
-		}	}
+		}
+
+		RenderSystem *renderSystem = mSceneMgr->getDestinationRenderSystem();
+		renderSystem->endCopyEncoder();
+		BarrierSolver &barrierSolver = renderSystem->getBarrierSolver();
+		ResourceTransitionArray resourceTransitions;
+		barrierSolver.resolveTransition( resourceTransitions, r.tex, ResourceLayout::Texture,
+										 ResourceAccess::Read, 1u << GPT_FRAGMENT_PROGRAM );
+		renderSystem->executeResourceTransition( resourceTransitions );
+		}
 	}
 
 	//  backgr cover prv cam meh-

Next error: Building on Debug is broken for me on Ubuntu. I fixed it with this patch:

Code: Select all

diff --git a/src/common/AppGui_Util.cpp b/src/common/AppGui_Util.cpp
index cbdd74d..d128a3b 100644
--- a/src/common/AppGui_Util.cpp
+++ b/src/common/AppGui_Util.cpp
@@ -104,7 +104,7 @@ void AppGui::UpdSelectGlow(Ogre::Renderable *rend, bool selected)
 	Hlms *hlms = datablock->getCreator();
 	if( hlms->getType() == HLMS_PBS )
 	{
-		assert( dynamic_cast<MyHlmsPbs*>( hlms ) );
+		assert( dynamic_cast<HlmsPbs2*>( hlms ) );
 		HlmsPbs2 *myHlmsPbs = static_cast<HlmsPbs2*>( hlms );
 		uint32 hash, casterHash;
 		myHlmsPbs->CalculateHashFor( rend, hash, casterHash );
diff --git a/src/common/HlmsPbs2.h b/src/common/HlmsPbs2.h
index afd894d..6f8f23b 100644
--- a/src/common/HlmsPbs2.h
+++ b/src/common/HlmsPbs2.h
@@ -36,7 +36,7 @@ public:
 	HlmsPbs2( Ogre::Archive *dataFolder, Ogre::ArchiveVec *libraryFolders );
 	~HlmsPbs2() override;
 	
-	const static size_t selected_glow = 123;
+	constexpr static size_t selected_glow = 123;
 
 	void CalculateHashFor( Ogre::Renderable *renderable, Ogre::uint32 &outHash, Ogre::uint32 &outCasterHash )
 	{

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

Re: Few serious questions for Ogre-Next, moving Stunt Rally

Post by dark_sylinc »

Crystal Hammer wrote: Sat May 13, 2023 12:08 pm

why is my shadow suddenly so square after 1st shadowmap? This was track = Des4-SBridge

You need to tweak your PSSM settings.
You can tweak the pssmLambda and/or increase the resolution of the last slice(s).

With your current settings now you're getting incredibly shadow map resolution for objects close to the camera but horrible for objects slightly further away.

how do I disable fog (Atmosphere) for RTTs?

Good question?

Try calling AtmosphereNpr::setSky( sceneManager, bEnabled ); between RTTs.

User avatar
Crystal Hammer
Gnome
Posts: 388
Joined: Sat Jun 23, 2007 5:16 pm
x 99

Re: Few serious questions for Ogre-Next, moving Stunt Rally

Post by Crystal Hammer »

Great, thank you for fixes. It works nice now.
I applied them all and pushed. I just removed that rtv rt_output I don't think it did anything.
Yeah I got that sky dome mesh which I set to camera center everytime it changes. I guess having sky as postprocess could be better but I'd have to learn that first.
Aah, so I need to add a listener to every workspace created, to change something before it renders. Okay great, I disabled fog in RTT now and also fixed no reflection in RTT view, but it does have wrong reflection in RTT, like camera direction was wrong or so, IDK.
Didn't fix shadowed RTT, no idea.

Anyways, is there a guide for extending HLMS? I've read the docs here but it still doesn't tell me how to do such things:

  • How to add a global float time and pass it to Terra? I did this for Pbs shaders here. I think after reading topic [2.1] Easier way to communicate with hlms shader? and of Adding Wind to Grass
  • How to get e.g. camera dir or light direction or anything that I don't see in passBuf or inPS?
  • [2.1]Adding HLMS customisations per datablock, would all this be needed if I want to add few custom parameters for vehicle paints only? Based on Pbs with clear coat.
  • How could I add reading a new texture to all Pbs shaders? Found this: [2.1] Adding custom texture to PBS HLMS
  • At which point is it better to split off Pbs and create a new HLMS with some changes and how much work is it? I think water shader would be good example to do it, but given how much code is in Pbs shaders, I think I'd rather add stuff to it, than to copy all that.
  • Some example of creating own basic shader in .any with some basic code, e.g. for 2D Hud elements
  • How to render depth only RTT and read depth in Pbs shader?

Some official samples, with code for each would be great. Is this possible or is getting info from forum topics the way it has to be? I think at some point I just couldn't find stuff in samples, and started asking questions.
There are few good topics on forum (above links), also this Struggling with HLMS.
But they are spread, contain more than a guide or sample would have, and some from 2016-17 making me wonder how much has changed, and would it work still, and do I really need to do all that to get something working.
I think this was all easier for me in old Ogre with shiny, or maybe I got used to it. But this feels really low level in Ogre-Next, I mean one has to write code to pass parameters, count their size, count and pass textures?, this is also error prone when I do it wrong.

Last edited by Crystal Hammer on Sat May 27, 2023 12:35 am, edited 2 times in total.
User avatar
Crystal Hammer
Gnome
Posts: 388
Joined: Sat Jun 23, 2007 5:16 pm
x 99

Re: Few serious questions for Ogre-Next, moving Stunt Rally

Post by Crystal Hammer »

More questions:

  • Does Pbs not even use and pass vertex colors to shader? If not is it much to do to add? Or maybe would it be easier to use another UV set per vertex and new code in shader to use it to any purpose.
  • If I'm gonna need few extra parameters for car paint in my own datablock, and some other parameters for other use case, then should I create different datablocks and cpp code, or even other Hlms and register that? Or can I just use one own Pbs datablock and put all my parameters in it, regardless of use. Is this very wasteful?

Yeah, it's gonna take ages here, even if we can solve 1 issue per week. I got like 10 issues I don't know how to fix, and 10 things I don't know how to code and progress further :? .

So my current one is that I have fully shadowed RTTs in editor when I switch then to manual update. I'm not sure how many things are still buggy in code right now, but I don't know what's causing this.
If you had time to test:

  • uncomment that line 120 in src/editor/Render2tex.cpp

    Code: Select all

    //#define MANUAL_RTT_UPD  // todo: terrain shadowed..?
  • build, start sr-editor
  • now the terrain preview minimap is dark, and without that define it is normal bright
    in editor menu: Options - Settings - Minimap, check minimap and set type to Terrain Preview