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 »

Video here. Any idea why this happens? Is this something wrong with my compostor setup in editor or a bug in planar reflections?

It looks like the PlanarReflection camera is using the wrong parameters (could be aspect ratio, near/far plane, viewport size).

This is handled by PlanarReflections::update and PlanarReflections::cameraMatches:

Code: Select all

void PlanarReflections::update( Camera *camera, Real aspectRatio )
{
...
actorData->workspace->setEnabled( true );
actorData->reflectionCamera->setPosition( camPos );
actorData->reflectionCamera->setOrientation( camRot );
actorData->reflectionCamera->setNearClipDistance( nearPlane );
actorData->reflectionCamera->setFarClipDistance( farPlane );
actorData->reflectionCamera->setAspectRatio( aspectRatio );
actorData->reflectionCamera->setFocalLength( focalLength );
actorData->reflectionCamera->setFOVy( fov );
actorData->reflectionCamera->enableReflection( actor->mPlane );
}

bool PlanarReflections::cameraMatches( const Camera *camera )
{
  return !camera->isReflected() && mLastAspectRatio == camera->getAspectRatio() &&
         mLastCameraPos == camera->getDerivedPosition() &&
         mLastCameraRot == camera->getDerivedOrientation();
}

I just noticed viewport size is not part of the data that is being copied (so far OgreNext's PlanarReflections implementation always assumed you're rendering to the whole screen) and thus that may explain the problem.
I'm not sure if the viewport size is available at that stage.

Another simple reason is that the parameters are correctly copied in PlanarReflections::update; but later on the Camera you passed to it gets its aspect ratio changed (e.g. because of Camera::setAutoAspectRatio which is true by default).

I'm moving to material.json now and editing it in my Material Editor window on Gui. It's better.
But, if I save some I have this then present in json:

And if I start editor again with this it will crash early on parsing, because DynamicCubemap is created from code much later.
How to deal with this? Instead of removing this manually and adding that in code, based on a parameter stored somewhere.

Mmmm... I see multiple possible solutions:

  1. Create the texture "DynamicCubemap" early on as a cubemap; but don't even schedule it to Resident. I'm not sure if that will work because at some point HlmsPbsDatablock::loadAllTextures() will be called and it will try to load your cubemap.
  2. Upon saving implement use HlmsJsonListener::savingChangeTextureName to change the texture name to something else (i.e. a dummy name to a 1x1 cubemap)

That's off the top of my head.

it is really nice and very easy to have those:
ALBEDO, NORMAL, METALLIC, ROUGHNESS, SPECULAR, ALPHA etc output variables for PBS to set up with your own stuff.
Can you list all variables from our 800.PixelShader_piece_ps.any that would do the same thing?

Most of them should be in PixelData pixelData.

Naturally by piece @insertpiece( custom_ps_posExecution ) you can be certain all of these variables have been fully populated. If you use earlier pieces, you may find yourself that some of these variables haven't been populated yet.

Can you tell how much work or in how many places do I need to change TerraShadowMapper for my terrain with unlimited floats (any values, in meters). I can't handle this 10bit and other assumptions. Generally it works now, but only for terrain above 0, below it's all shadowed.

Look for PFG_R10G10B10A2_UNORM in TerraShadowMapper.cpp.
Note that you may need to modify TerraShadowGenerator.glsl which performs:

Code: Select all

float currHeight = float( texelFetch( heightMap, xyPos << int( resolutionShift ), 0 ).x );
...
imageStore( shadowMap, xyPos, vec4( shadowValue, roundedHeight.y, invHeightLength, 1.0 ) );

If I recall, currHeight is already in range [0; 1] in out of the box Terra (because we use R16_UNORM to store the height).

I suspect what's really troubling you is none of that, but rather this in PbsTerraShadows_piece_vs_piece_ps.glsl:

Code: Select all

vec3 terraShadowData = textureLod( vkSampler2D( terrainShadows, terrainShadowSampler ),
								   terraWorldPos.xz * passBuf.invTerraBounds.xz +
								   passBuf.terraOrigin.xz, 0 ).xyz;
float terraHeightWeight = terraWorldPos.y * passBuf.invTerraBounds.y + passBuf.terraOrigin.y;
terraHeightWeight = (terraHeightWeight - terraShadowData.y) * terraShadowData.z * 1023.0;
outVs.terrainShadow = mix( midf_c( terraShadowData.x ), _h( 1.0 ), midf_c( saturate( terraHeightWeight ) ) );

Of extreme particular importance is passBuf.invTerraBounds.y + passBuf.terraOrigin.y which takes care of squashing the Y position to the range [0; 1]

You could add:

Code: Select all

if( terraHeightWeight < 0.0 )
    outVs.terrainShadow = mix( midf_c( terraShadowData.x ), _h( 1.0 ), midf_c( saturate( terraHeightWeight ) ) );
else
    outVs.terrainShadow = _h( 1.0 );

Or maybe passBuf.terraOrigin.y is not the correct value.

I'm not sure how you can be "below the terrain" and be something you want to render.

What freaks me out still, is those white flashes when a new texture appears (on Gui mostly now).

Gee, you sound like another client of mine.

Every frame you can call TextureGpuManager::waitForStreamingCompletion() to avoid that (but you gain stall or stutter because the engine must wait for textures to be loaded).

Lastly why is Ogre-Next still not using auto keyword, this shortens code so much. Do you still need old C++ standard supported?

We adopted C++11 for OgreNext 3.0 but I'll be deep in the cold cold ground before I allow auto in the codebase :lol:
With a few exceptions where it's reasonable (e.g. deep templates, example documentation), auto brings more problems than benefits.

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 »

Thank you for help. Any chance with the rest of questions I asked?

I have another issue with planar reflections, seems like a fountain issue with it, but yeah I'm using it for water etc not for mirrors.
If I set my fluids to use "cull_mode" : "none", I get back that odd looking issue with weird stuff on surface (like flipped terrain was in reflection or its shadowmap per vertex or so).
All is fine if I have "cull_mode" : "clockwise".
Is this easy fixable? Or was planar reflections meant to be one-sided. And would I need to make 2 for each side (I need underwater too).

I'm building with clang these days on Debian 12, and I had to change this in CMakeLists.txt line 151:

Code: Select all

        -Winconsistent-missing-destructor-override -Wcomma -Wsign-conversion -Wconversion" )

to just

Code: Select all

        -Wsign-conversion -Wconversion" )

Because the other two cause errors:

Code: Select all

-- Build files have been written to: /home/ch/_sr/Ogre/ogre-next/build/Debug
[1/815] Building CXX object OgreMain/CMakeFiles/OgreMain.dir/src/OgreAlignedAllocator.cpp.o
FAILED: OgreMain/CMakeFiles/OgreMain.dir/src/OgreAlignedAllocator.cpp.o 
/usr/bin/c++ -DFREEIMAGE_LIB -DOGRE_NONCLIENT_BUILD -DOgreMain_EXPORTS -D_MT -D_USRDLL -I/home/ch/_sr/Ogre/ogre-next/OgreMain/include -I/home/ch/_sr/Ogre/ogre-next/build/Debug/include -I/home/ch/_sr/Ogre/ogre-next/Dependencies/include -I/home/ch/_sr/Ogre/ogre-next -I/home/ch/_sr/Ogre/ogre-next/OgreMain/include/Threading -I/home/ch/_sr/Ogre/ogre-next/OgreMain/include/GLX -Wall -Winit-self -Wcast-qual -Wwrite-strings -Wextra -Wno-unused-parameter -Wshadow -Wimplicit-fallthrough         -Winconsistent-missing-destructor-override -Wcomma -Wsign-conversion -Wconversion  -msse -msse2 -g -DDEBUG=1 -fPIC   -fPIC -fvisibility=hidden -fvisibility-inlines-hidden -MD -MT OgreMain/CMakeFiles/OgreMain.dir/src/OgreAlignedAllocator.cpp.o -MF OgreMain/CMakeFiles/OgreMain.dir/src/OgreAlignedAllocator.cpp.o.d -o OgreMain/CMakeFiles/OgreMain.dir/src/OgreAlignedAllocator.cpp.o -c /home/ch/_sr/Ogre/ogre-next/OgreMain/src/OgreAlignedAllocator.cpp
c++: error: unrecognized command-line option ‘-Winconsistent-missing-destructor-override’
c++: error: unrecognized command-line option ‘-Wcomma’; did you mean ‘-Wcomment’?

Well from old issues there is still that notorious mystery of assert( !mCachedTransformOutOfDate ); from Node::_getFullTransform().
Which I now commented out again. I gave it another try and no idea still. It now happens not each frame but after track (re)load, from void AppGui::UpdCubeRefl() in wsCubeRefl->_update(); - so when updating my dynamic cube map reflection workspace. IIRC I had it before too in cullPhase01 which I managed to hack/fix by skipping first 4 updates.
All this makes me think if I should have just _update or all 3 here

Code: Select all

wsCubeRefl->_beginUpdate( true );
wsCubeRefl->_update();
wsCubeRefl->_endUpdate( true );

and should I have true or false. But anyway I tried other options here and it happens still, so it may be someting else. Is one PITA with this. But as long as Release works without artifacts, I'm not that worried.

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: Thu Oct 05, 2023 11:01 pm

Look for PFG_R10G10B10A2_UNORM in TerraShadowMapper.cpp.
Note that you may need to modify TerraShadowGenerator.glsl which performs:

Code: Select all

float currHeight = float( texelFetch( heightMap, xyPos << int( resolutionShift ), 0 ).x );
...
imageStore( shadowMap, xyPos, vec4( shadowValue, roundedHeight.y, invHeightLength, 1.0 ) );

Aah, so does this part mean that this 10 bit 0..1 was actually a result of PFG_R10G10B10A2_UNORM and that TerraShadowGenerator needs to store 3 values each time? So if I wanted just FLOATs here is PFG_RGBA32_FLOAT the right choice (is it 4x 32 bit floats)? Then I'd need to drop all those 1023 and other 10bit conversions to use unlimited floats. Do I get this right?

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: Mon Oct 09, 2023 6:58 pm

Aah, so does this part mean that this 10 bit 0..1 was actually a result of PFG_R10G10B10A2_UNORM and that TerraShadowGenerator needs to store 3 values each time? So if I wanted just FLOATs here is PFG_RGBA32_FLOAT the right choice (is it 4x 32 bit floats)? Then I'd need to drop all those 1023 and other 10bit conversions to use unlimited floats. Do I get this right?

Yes and no...

The value in:

  • shadowMap.x stores a value in range [0; 1] where 0 is completely shadowed, 1 no shadow.

  • shadowMap.y is a height value.

  • shadowMap.z is expressed as a function of height values: 1 / (prevHeight.x - prevHeight.y + 1)

The idea is that the terrain is multiplied against shadowMap.x.

The idea is that for regular objects; if they're below range prevHeight.y then they're fully shadowed. And if they're between prevHeight.y & prevHeight.x then they're blended.

These 2 pictures explain it much better:

Basically it wants to achieve a penumbra and umbra effect.

As for whether it will work, whether you work with floats or normalized coordinates, it always depends on whether all your calculations are made in the same relative space (that's always the hardest part).

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 »

Ah. Great explanation, thank you. So I'll use that PFG_RGBA32_FLOAT for this, (even if it's like 4 times the size 128bit info here) if I get it right, I still need it.

Anyway let me point out something that is now bothering me much more. I can't get v1::RibbonTrail to look okay with texture and vertex colors. The best I could get is solid color

obviously I can't use v1 materials:

Code: Select all

19:53:28: OGRE EXCEPTION(3:RenderingAPIException): Fixed Function pipeline is no longer allowed nor supported. The material Examples/LightRibbonTrail must use shaders in HlmsLowLevel::calculateHashFor at /home/ch/_sr/Ogre/ogre-next/OgreMain/src/OgreHlmsLowLevel.cpp (line 155)
19:53:28: Couldn't apply datablock '[Hash 0x4624f081]' to this renderable. Using default one. Check previous log messages to see if there's more information.

So I'm using unlit as it naturally has vertex colors and should work

Code: Select all

	"unlit" :
	{

		"TireTrail" :
		{
			"macroblock" : "Macroblock_0",
			"blendblock" : "Blendblock_1",
			"shadow_const_bias" : 0.01,
			"workflow" : "specular_ogre",
			"diffuse" :
			{
				"value" : [0.8, 0.8, 0.8],
				"background" : [1, 1, 1, 1],
				"sampler" : "Sampler_10",
				"texture" : "flare1.png"
			}
		}
	},

and in code created like so:

Code: Select all

std::vector<Ogre::v1::RibbonTrail*> whTrail;
..
	if (!whTrail[w])
	{	NameValuePairList params;
		params["numberOfChains"] = "1";
		params["maxElements"] = toStr(320 * pSet->trails_len);
		params["useVertexColours"] = "true";
		params["useTextureCoords"] = "true";

		whTrail[w] = (v1::RibbonTrail*)mSceneMgr->createMovableObject(
			"RibbonTrail", &mSceneMgr->_getEntityMemoryManager(SCENE_DYNAMIC), &params);
		whTrail[w]->setUseVertexColours(true);
		whTrail[w]->setUseTextureCoords(true);
		whTrail[w]->setInitialColour(0, 0.1,0.1,0.1, 0);
		whTrail[w]->setFaceCamera(false,Vector3::UNIT_Y);
		whTrail[w]->setRenderQueueGroup(RQG_CarTrails);
		whTrail[w]->setDatablockOrMaterialName("TireTrail", "General");  //
		whTrail[w]->setCastShadows(false);
		whTrail[w]->addNode(ndWhE[w]);
		ndRoot->attachObject(whTrail[w]);
	}
	whTrail[w]->setTrailLength(90 * pSet->trails_len);  //30
	whTrail[w]->setInitialColour(0, 0.1f,0.1f,0.1f, 0);
	whTrail[w]->setColourChange(0, 0.0,0.0,0.0, /*fade*/0.08f * 1.f / pSet->trails_len);
	whTrail[w]->setInitialWidth(0, 0.f);

But best I got so far is single color changing with fading, no texture.
Also BTW is much work to have 2D textured RibbonTrails? Honestly it's in every game, even normalmaps are there I think. I'd like this in Ogre-Next too.

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: Tue Oct 10, 2023 7:16 pm

But best I got so far is single color changing with fading, no texture.
Also BTW is much work to have 2D textured RibbonTrails? Honestly it's in every game, even normalmaps are there I think. I'd like this in Ogre-Next too.

Maybe it's working but the problem is that RibbonTrails only support 1D UVs? (it has U, but not V).
I totally agree, I never understood why it was 1D instead of 2D.

The code never attempts to do any math to calculate 2D UVs.

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 »

Right. Could you maybe fix it? I still have a few other things I'd like to restore or fix.

How do I apply my fog to transparent meshes?
I add fog in PBS pixelshader here.
Whole fog code is there], it just simply lerps a bunch of times (maybe too many) finalColour.xyz into various fog types.

This is what I get with transparency_mode transparent, it's bad, like it was additive not blending, only for pipes, rest is okay.

19_19-49-30.jpg

And this is okay for fog with transparency_mode fade but with bad specular light not like before on pipes.

19_19-49-50 fade.jpg

Should I lerp/blend fog into finalColour.xyz scaled by pixelData.diffuse.w or F0.w or something else is wrong?

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 »

Well another question.
So compositor_node has pass render_scene and I got e.g. visibility_mask 0x000011FF for 1st player.
Can I change this in C++ for other players? I read in docs that changing it in CompositorPassSceneDef is bad and won't work as *Defs are shared.
So how do I change it for created CompositorWorkspace, is it possible?
I tried different camera->setVisibilityFlags for workspaces but that didn't work, like it's ignored.
Am I then left with just creating 4 times a full copy in .compositor file (or can I clone *Def in C++?) duplicating it hidiously with just visibility_mask different?

Update: Okay I managed to do it by inheriting:
And then I had to assign shadow node to each one of SR3_RenderX, since doing it once for SR3_RenderAbs didn't work.

Code: Select all

abstract compositor_node SR3_RenderAbs
{
...
}
compositor_node SR3_Render0 : SR3_RenderAbs
{	target rt_renderwindow
	{	pass clear			{	}
		pass render_scene	{	visibility_mask  0x000011FF  }
}	}
compositor_node SR3_Render1 : SR3_RenderAbs
{	target rt_renderwindow
	{	pass clear			{	}
		pass render_scene	{	visibility_mask  0x000101FF  }
}	}
...
workspace SR3_Workspace0
{
	connect_external 0 SR3_Render0 0  // Render Window  on channel #0
	connect_external 1 SR3_Render0 1  // Cubemap  on channel #1
}
workspace SR3_Workspace1
{
	connect_external 0 SR3_Render1 0
	connect_external 1 SR3_Render1 1
}

Man I miss some help here again, for the previous issues, like transparency fog.

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 »

Hi!

Late reply but: Indeed you shouldn't modify mVisibilityMask because there is no guarantee it won't be broken in future versions.
However you can do it anyway. The chance of this breaking in the future is very low (and if it does, I'd have to offer some alternative so the following solution works).
The chance is much higher with values that are directly involved in API commands (like the clear colour, which gets embedded into the RenderPassDescriptor, so changing the CompositorPassDef after it was instanciated won't do anything).

You can do it in CompositorPass::passEarlyPreExecute: Either const_cast the ptr, or walk your way down using getNodeDefinitionNonConst.

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, cool.
I'm currently facing a serious, strange issue with Terrain going half black with (any) triplanar enabled, only happening on NVidia card on Windows (so far) using GL3+. I don't have this issue (also using GL3+) on Windows 10 with integrated Intel GPU, neither on Debian 12 with AMD GPU.
So rubberduck has some weird black patterns on terrain here
while I don't, it's always normal color, nothing black for me here.
Since you have experiece with shaders and various issues on different GPU types, do you have any hints what I should look and check for in shaders (I'm guessing it's their fault)? IDK divisions by zero, normalizations etc? What's worst there aren't any issues in ogre.log from shaders.

Last edited by Crystal Hammer on Fri Nov 03, 2023 1:33 am, edited 1 time 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 »

Okay it appears to be this code:
in /home/ch/sr/sr3/Media/Hlms/Terra/Any/800.PixelShader_piece_ps.any

Code: Select all

		midf3 triplanarBlend = pow3( pixelData.worldSpaceNormal, _h( 4.0 ) );
		triplanarBlend /= dot( triplanarBlend, midf3_c( 1.0, 1.0, 1.0 ) );

Is pow not working on NVidia for negative values? It seems to work on AMD and Intel. (Only 1 of each GPU tested).
I also tried fixing pow3 to use this instead

Code: Select all

	return midf3_c(
		(v.x >= _h( 0.0 )) ? pow( v.x, e ) : -pow( -v.x, e ),
		(v.y >= _h( 0.0 )) ? pow( v.y, e ) : -pow( -v.y, e ),
		(v.z >= _h( 0.0 )) ? pow( v.z, e ) : -pow( -v.z, e ));

but this didn't fix it, and had bad looking areas, close to 0.

So, I replaced that code with our old code from SR 2.7 that worked fine, just a bit different blending:

Code: Select all

        float3 absNormal = abs( pixelData.worldSpaceNormal );
        float3 triplanarBlend = absNormal;
        //  Tighten up the blending zone:  
//triplanarBlend = (triplanarBlend - 0.2) * 7; // in other paper triplanarBlend = (triplanarBlend - 0.5); triplanarBlend = max(triplanarBlend, 0.0001); // Force weights to sum to 1.0 triplanarBlend /= triplanarBlend.x + triplanarBlend.y + triplanarBlend.z;

I've also found a way to fix (not ideal) that fog on transparency (glass glowing).
I had to multiply each fog color that I'm blending into, by factor = pixelData.diffuse.w * 1.05.
Strange but works (almost).

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 have some more general questions.
What is the proper way of destroying all, and loading again on map / track change? I mean when should I do this, what should I call? Is it okay in update() (it's the only place for me)? Or should everybody use LogicSystem, GameEntityManager and such new things. I don't really see the point, unless it's necessary for some reason.
If see this right (I may be wrong) no sample destroys anything. I'd really like a sample that does load different scenes / maps after user pressed a key, just to know that properly.
Should I use any of the unloadAll.. methods, or is it okay to do this myself, destroying all things that I created?
I'm using that (strange, long, complex) code based on MinimizeMemory after destroying track, before loading next.

But I still have that freaking texture wrap issue, since a year now, which makes some datablocks/samplers loose texture wrap
I see that MinimizeMemory doesn't destroy all (at least unused) datablocks and has weird logic for textures I don't want to delete.
How do I get all samplerblocks (count at least)? Maybe they increase or get corrupted or so.
I made a new video for it. It's pretty obvious. I load 1st track, all is good, then I load next and suddenly (only new) pipe materials freak out, blink, loose wrap etc. I quit and start again, 1st track is good, then loading next has same issues. This only happens to road meshes like glass pipes and columns. No idea yet why. I'm using my ulitity methods like SetTexWrap from here.
I remember you wrote already a procedure for this, but how can I fix it easier? E.g. get datablocks, samplers counts, check if they're gone bad? Will you maybe have time someday to investigate it, or are you still very busy? I remember when you did test SR3 code directly, all bugs went way faster.

Should I destroyAllDatablocks or all samplers (before new track load I mean)?
Or how do I keep samplers the way they should. E.g. I'd like 1 sampler for all objects, roads, etc, always wrapping textures (why is this not by default) and change it's anisotropy to what user chose in options. After loading materials from .json I guess. Probably should move all there.

Next, when should I set positions and orientations of cameras and scenenodes that moved, in update() ?
When/how should I destroy workspaces and cameras, and recreate (e.g. after I change players count, or some rendering options)?

Since I got my new PC, rather high end, I see no point of shader cache. It even does the opposite, at some point, it gets to 1GB and starting editor or game slows down like 1 sec more. If I delete it then it's back to normal. Maybe slightly slower without it. Probably useful for old HW. Also I tried 7zip and packed shader cache file of 775 MB to a 3.6 MB file, so what on Earth is then that 200x space waste for? I guess uncompressing would be slower still.

And I still have that issue from March with triplanar normals darkening. viewtopic.php?p=554304#p554304
I'm glad though I fixed the ones in previous post. Didn't anyone check triplanar on a new Nvidia GPU on Windows and GL3+?

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 moved now all PBS materials from .material to .material.json (1 freaking big file with amost 50000 lines).
I'm also not using few code methods, and finally that issue from video is gone :D . (Hmm it had like 2 views, while this post had few thousands recently? bots are attacking I suppose).

So, basically all use just this sampler:

Code: Select all

	"samplers" :
	{
		"Sampler_10" :
		{
			"min" : "anisotropic",
			"mag" : "anisotropic",
			"mip" : "anisotropic",
			"u" : "wrap",
			"v" : "wrap",
			"w" : "wrap",
			"miplodbias" : 0,
			"max_anisotropic" : 16,
			"compare_function" : "disabled",
			"border" :[1, 1, 1, 1],
			"min_lod" : -3.4028235e+38,
			"max_lod" : 3.4028235e+38
		}
	},

Now how do I set max_anisotropic from code? There is like always in graphics options an Anisotropy value, What is the code that will apply it?
I just want to get that sampler block and set new anisotropy value. I see that's just impossible.
I wrote this, maybe could work,

Code: Select all


void AppGui::SetAnisotropy()
{
	HlmsSamplerblock s;
	InitTexFilt(&s);

	Hlms *hlms = mRoot->getHlmsManager()->getHlms( HLMS_PBS );

	const auto& dbs = hlms->getDatablockMap();
	for (auto it = dbs.begin(); it != dbs.end(); ++it)
	{
		auto* db = static_cast< HlmsPbsDatablock *>(it->second.datablock);
		if (db)
		for (int n=0; n < NUM_PBSM_SOURCES; ++n)  // all
		{
			// const HlmsSamplerblock* sb = db->getSamplerblock(n);  // copy?
			db->setSamplerblock( n, s );
		}
	}
}

void AppGui::InitTexFilt(HlmsSamplerblock* sb)
{
	FilterOptions mia, mip;
	switch (pSet->g.tex_filt)
	{
	case 3:  mia = FO_ANISOTROPIC;  mip = FO_ANISOTROPIC;  break;  // full anisotropic
	case 2:  mia = FO_ANISOTROPIC;  mip = FO_LINEAR;  break;  // anisotropic
	case 1:  mia = FO_LINEAR;  mip = FO_LINEAR;  break;  // trilinear
	case 0:  mia = FO_LINEAR;  mip = FO_POINT;  break;  // bilinear
	}
	sb->mMinFilter = mia;  sb->mMagFilter = mia;
	sb->mMipFilter = mip;

	sb->mMaxAnisotropy = pSet->g.anisotropy;
}

but does this assert

Code: Select all

Creating PSO with 100000225VertexShader_vs 100000225PixelShader_ps
sr-editor3: /home/ch/_sr/Ogre/ogre-next/RenderSystems/GL3Plus/src/OgreGL3PlusRenderSystem.cpp:1231: virtual void Ogre::GL3PlusRenderSystem::_setSamplers(Ogre::uint32, const Ogre::DescriptorSetSampler*): Assertion `( !samplerblock || samplerblock->mRsData ) && "The block must have been created via HlmsManager::getSamplerblock!"' failed.

I can't even :? .
Okay but doing this there also crashes.

Code: Select all

            HlmsSamplerblock sb( *db->getSamplerblock( n ) );
	    InitTexFilt(&sb);
            db->setSamplerblock( n, sb );
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 also tried doing this in json but blocks are const:
void HlmsPbs2::_loadJson( const rapidjson::Value &jsonValue, const HlmsJson::NamedBlocks &blocks,

And tried doing this in Pbs here:

Code: Select all

class HlmsPbs2 : public Ogre::HlmsPbs
{
	void _collectSamplerblocks( set<const HlmsSamplerblock *>::type &outSamplerblocks,
								const HlmsDatablock *datablock ) const override;

But that thing has const HlmsSamplerblock *. It's like everywhere with const.

I would be delighted if I knew: what's the way to just set anisotropy, everywhere.
Without any issues, and even from Gui in update().
Just like back in the good old years:

Code: Select all

Ogre::MaterialManager::getSingleton().setDefaultTextureFiltering(Ogre::TFO_ANISOTROPIC);
Ogre::MaterialManager::getSingleton().setDefaultAnisotropy(16);

It seems that my old way here of just calling SetTexWrap or SetAnisotropy, every time after each Item* it = mSceneMgr->createItem( wasn't that bad, and kind of works, or is even the right way?

The only thing not const is this I think:
void setSamplerblock( uint8 texType, const HlmsSamplerblock &params );


So here is the code now:

Code: Select all

void AppGui::SetAnisotropy(Item* it)
{
	assert( dynamic_cast< HlmsPbsDatablock *>( it->getSubItem(0)->getDatablock() ) );
	HlmsPbsDatablock *db = static_cast< HlmsPbsDatablock *>( it->getSubItem(0)->getDatablock() );
	
	for (int n=0; n < NUM_PBSM_SOURCES; ++n)  // all
	{
		const HlmsSamplerblock *s = db->getSamplerblock( n );
		if (s)
		{
			HlmsSamplerblock sb( *s );
			InitTexFilt(&sb);   // posted before, does set mMaxAnisotropy and 3x *Filter
			db->setSamplerblock( n, sb );
		}
	}
}

I do call SetAnisotropy, after each createItem( and this seems to work, well at start. If I save all materials to json I see those used have new samplers set, all unused have still old samplers. If I restart it works. Changing from Gui in editor and loading does change terrain, but doesn't change road anisotropy. Weird.. What does it mean? Why can't it apply new sampler or doesn't change it?

I've got also this method:

Code: Select all

void AppGui::SetAnisotropy()
{
	Hlms *hlms = mRoot->getHlmsManager()->getHlms( HLMS_PBS );
	const auto& dbs = hlms->getDatablockMap();
	for (auto it = dbs.begin(); it != dbs.end(); ++it)
	{
		auto* db = static_cast< HlmsPbsDatablock *>(it->second.datablock);
		for (int n=0; n < NUM_PBSM_SOURCES; ++n)  // all
		{
			const HlmsSamplerblock *s = db->getSamplerblock( n );
			if (s)
			{
				HlmsSamplerblock sb( *s );
				InitTexFilt(&sb);
				db->setSamplerblock( n, sb );
			}
		}
	}
}

Which I call after changing anisotropy or filtering from Gui. It changes terrain and objects but completely destroys road texture wrap, it gets set to clamp very ugly. And for all road materials it seems. Why? I don't touch it so it seems like a corruption?

Obviously the best way to change anisotropy is still editing all.material.json and replacing all values for "max_anisotropic" : 8. But I can't just tell users to do that. Why isn't there a simple way of doing this?
I also can't use saving all materials from our Gui to this .json directly. Like half of samplers are different always. And I can't name them nicely like Sampler_Sky, it'll be all numbers. Have to merge but since that file is almost 50000 lines long it's tedious, rather a PITA.

So any chance for help here? Seems like you're extremely busy and just ignoring this topic now (since like 11 Oct).

BTW I still got those dreaded mCachedTransformOutOfDate asserts on various occasions. But since you didn't reply to these questions then I don't know what to change or try in my code. And obviously I don't want to spend a day cursing or puking while debugging this and getting no further. At least works well and stable in Release, doesn't seem to break anything.

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 »

So can I just ask what's the current status?
Both for help in this topic and Ogre-Next (release, dev etc). Not much happened in last months (as I see it).

I shouldn't post here if there is no chance of any help. Seems only dark_sylinc can help me. Any idea when and if possible? There are few issues that are unsolved or unanswered (in previous posts) and surely few other things that I'd have more issues with if I started (so I won't).

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 really need to fix that Planar Reflections flipped bug, happens for any workspaces other than default.
Currently trying it in my Terrain demo for refractions which has split rendering in 2 parts (I mentioned it in other topic). And now Reflections already get flipped just like the same bug from this topic, where it happens in my Track Editor's preview camera.

I tried your post suggestions from top.
I didn't fix it and I think it may be close but not where the bug is.
I made a new video, talking how to test and what I've tried.
Could you fix this bug? because I can't even. :(

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 »

That video sounds like it makes it easy for me to repro.

I will give it a shot tomorrow.

I assume that code was from this repo, main branch?

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 »

Yes.

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 »

Unrelated to that bug the first thing I notice is that it triggers an exception:

An exception has occured: OGRE EXCEPTION(1:InvalidStateException): Mapping the buffer twice within the same frame detected! This is not allowed. in BufferPacked::map at /home/matias/CRYHAM/dev/Ogre/ogre-next/OgreMain/src/Vao/OgreBufferPacked.cpp (line 180)

Walking up the stack reveals the reason:

Code: Select all

1   __cxa_throw                                                                               0x7ffff6336650 
2   Ogre::ExceptionFactory::throwException                   OgreException.h             295  0x7ffff6cf3290 
3   Ogre::BufferPacked::map                                  OgreBufferPacked.cpp        180  0x7ffff72f67cd 
4   Ogre::ShadowMapper::updateShadowMap                      TerraShadowMapper.cpp       277  0x4d14c4       
5 Ogre::Terra::update Terra.cpp 542 0x4c844a
6 Ogre::Terra::update Terra.cpp 533 0x4c8322
7 Ogre::PlanarReflections::update OgrePlanarReflections.cpp 875 0x4adc4d
8 Demo::PlanarReflectWsListener::passEarlyPreExecute TerrainScene_Water.cpp 90 0x4e5616
9 Ogre::CompositorPass::notifyPassEarlyPreExecuteListeners OgreCompositorPass.cpp 536 0x7ffff72cb7cd 10 Ogre::CompositorPassScene::execute OgreCompositorPassScene.cpp 184 0x7ffff72df9da 11 Ogre::CompositorNode::_update OgreCompositorNode.cpp 833 0x7ffff729517b 12 Ogre::CompositorWorkspace::_update OgreCompositorWorkspace.cpp 836 0x7ffff72b4255 13 Ogre::CompositorManager2::_updateImplementation OgreCompositorManager2.cpp 790 0x7ffff72829d7 14 Ogre::RenderSystem::updateCompositorManager OgreRenderSystem.cpp 1311 0x7ffff702ecb0 15 Ogre::CompositorManager2::_update OgreCompositorManager2.cpp 712 0x7ffff7282615 16 Ogre::Root::_updateAllRenderTargets OgreRoot.cpp 1568 0x7ffff7092c98 17 Ogre::Root::renderOneFrame OgreRoot.cpp 1102 0x7ffff709052d 18 Demo::GraphicsSystem::update GraphicsSystem.cpp 436 0x47b0e8
19 Demo::MainEntryPoints::mainAppSingleThreaded MainLoopSingleThreaded.cpp 139 0x489a21
20 mainApp Terrain.cpp 251 0x4d469b
... <More>

You're calling:

Code: Select all

void Terra::update()
    {
        update(m_prevLightDir, 0.0f);
    }

But unfortunately m_prevLightDir is always 0 (an invalid value for light) thus 0.dotProduct( 0 ) is always 0 instead of 1 (1 means the vectors are equal as they have the same angle) and the code thinks it must update the shadow map again.

Besides triggering the exception in debug mode, this is costing you unnecessary performance, as you're recalculating the Terrain's sun shadows multiple times per frame.

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 »

Done!

Thanks for the easy repro!

I noticed you already merged the PR!

Btw I noticed the water was shinning / flickering; upon inspection on RenderDoc the code was assigning terrain shadows and reflections to the same slot (ugh, this bug again... it's like the 3rd time we encounter it)

So I fixed it (hopefully this time for good). Please note you'll have to copy some of those changes to your project.

Be on the lookout if this "fix" causes any regression.

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 »

Awesome. Thank you very much.
I was still testing this. I've rebuilt, checked OgreNext source to be sure.
What is strange is that indeed reflection flipped bug is fixed in Vulkan. But I still have it in GL on Debian.
Any idea why?
Ah I didn't rebuild OgreNext, I still need to test that.

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 good. I've rebuilt OgreNext, from that 3.0 branch and applied fixes
https://github.com/OGRECave/ogre-next/compare/v3-0
to Terrain Demo also.
The bug is gone, there is no blinking on water.
But I see no terrain shadow, it's like terrain shadowmap is gone now. And I saw it recently, before all changes today.

Also BTW I had to again change it here in CMake:

Code: Select all

    set( OGRE_WARNING_FLAGS "${OGRE_WARNING_FLAGS} \
        -Wsign-conversion -Wconversion" )
        #**  -Winconsistent-missing-destructor-override -Wcomma
        #-Winconsistent-missing-destructor-override -Wcomma -Wsign-conversion -Wconversion" )

because I'm having these:

Code: Select all

c++: error: unrecognized command-line option ‘-Winconsistent-missing-destructor-override’
c++: error: unrecognized command-line option ‘-Wcomma’; did you mean ‘-Wcomment’?

I see this when building OgreNext:
-- Detected g++ 12

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 Mar 10, 2024 10:46 pm

But I see no terrain shadow, it's like terrain shadowmap is gone now. And I saw it recently, before all changes today.

You mean in the demo? On the terrain? (i.e. because there's shadows on the terrain from the terrain, and shadows on normal objects from the terrain).
Because at least on the demo, since you always call Terra::update() with m_prevLightDir = 0, you should have never seen shadows.

If I hack your demo so that m_prevLightDir is valid, e.g. in Terra::createHeightmap I change

Code: Select all

//m_prevLightDir = Vector3::ZERO;
m_prevLightDir = Vector3(-1, -1, -1).normalisedCopy();

Then I see terrain shadows.

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 »

Ah thanks, I understood now what was happening and fixed it by passing light dir to terra update.

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 »

Is there really no way to setRefractionStrength in .material.json?
I don't see that call in void HlmsJsonPbs::loadMaterial( :shock: