Page 1 of 1

Screen space decals mask

Posted: Mon Oct 08, 2018 10:05 am
by TaaTT4
Is there a way to avoid that some items would be affected by decals?

See the following image for a use case scenario:
Image

At the moment, the skid marks are rendered using a transparent plane coplanar with the road mesh. This solution works quite well, but has obvious z-fighting issues. Infact, the skid marks aren't rendered onto the orange kerb because it has some thickness. A workaround is to apply some depth bias to the skid marks plane, but this could lead to other problems and/or it's hard to tune due to the procedural nature of the tracks in my game.
Now that OGRE supports it, the idea is to trasform the skid marks in a decal. But doing so, the skid marks would be splatted even over the car which is, of course, something I have to avoid.

Re: Screen space decals mask

Posted: Mon Oct 08, 2018 12:46 pm
by al2950
Why would the decals be 'splattered' on the car? A decal has an x,y size as well as a depth, which determines the volume in which decals will be applied. If you set the depth to something like 5cm, then the skid marks won't appear on the car.

Re: Screen space decals mask

Posted: Mon Oct 08, 2018 1:10 pm
by TaaTT4
Hmm... maybe I didn't understand well how screen space decals works. I know that decals affect just what is inside their "bounding box", but as far as I squeeze the depth (even to 1 cm) car tyres will always be inside (at least partially) the decals bounding box.
And reality are even worse. In my previous post I talked about coplanar meshes and planes just to let things simple. The road mesh is never planar, in fact it can go up and down from the "sea level" (y = 0.0) by some meters. In that case reducing the depth isn't a feasible approach.

Re: Screen space decals mask

Posted: Mon Oct 08, 2018 1:19 pm
by al2950
TaaTT4 wrote: Mon Oct 08, 2018 1:10 pm The road mesh is never planar, in fact it can go up and down from the "sea level" (y = 0.0) by some meters. In that case reducing the depth isn't a feasible approach.
I was afraid you might say that! In which case yes it gets harder. I have not delved into the implementation yet, but is suspect its probably quite hard to do what you want in a single pass, but perhaps could be dealt with using multiple render queues and multiple passes.

Re: Screen space decals mask

Posted: Mon Oct 08, 2018 7:06 pm
by dark_sylinc
Hi!

I see three solutions:

1. Play with thin decal thickness. Doesn't seem too promising given what you said (the roads aren't planar, but rather bumpy)

2. Compile with OGRE_CONFIG_ENABLE_FINE_LIGHT_MASK_GRANULARITY enabled.
I'd swear I included light masks with Decals. I think I'm getting confused with LTC lights.
Ok the code is not there but it shouldn't be too hard if roughness & metalness params are turned into half floats instead of floats, or the texture indices are turned to 8-bit instead of 16 (to make room for a 32-bit mask).
This is the easiest and most flexible solution.

3. Two render_pass scenes. Decals live in render queues (separate/independent from Items' render queues). Right now Forward Clustered collects decals in [MinDecalRq; MaxDecalRq].
With additional code, the first pass would render the car with a Decal RQ range that does not include those tire stuff, the second pass scene would render the terrain with full Decal RQ range.
Again there is not yet code for specifying the Decal RQ range but it could be done (notice that this affects ForwardPlusBase::getCachedGridFor because now the cache must track the RQ ranges).
It will get the job done but I think it is a little convoluted and complex, and it is not very flexible.

Re: Screen space decals mask

Posted: Wed Feb 17, 2021 2:39 pm
by al2950
Since the original post, are there any better/easier ways to apply 'masks' to decals/items?

Also as I read it option 3 above requires changes to Ogre?

Re: Screen space decals mask

Posted: Sat Feb 11, 2023 5:40 pm
by Nickak2003

Have masks been added to decals yet? Are the listed options still the only ones?