Screen space decals mask

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


Post Reply
User avatar
TaaTT4
OGRE Contributor
OGRE Contributor
Posts: 267
Joined: Wed Apr 23, 2014 3:49 pm
Location: Bologna, Italy
x 75
Contact:

Screen space decals mask

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

Senior programmer at 505 Games; former senior engine programmer at Sandbox Games
Worked on: Racecraft EsportRacecraft Coin-Op, Victory: The Age of Racing

al2950
OGRE Expert User
OGRE Expert User
Posts: 1227
Joined: Thu Dec 11, 2008 7:56 pm
Location: Bristol, UK
x 157

Re: Screen space decals mask

Post 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.
User avatar
TaaTT4
OGRE Contributor
OGRE Contributor
Posts: 267
Joined: Wed Apr 23, 2014 3:49 pm
Location: Bologna, Italy
x 75
Contact:

Re: Screen space decals mask

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

Senior programmer at 505 Games; former senior engine programmer at Sandbox Games
Worked on: Racecraft EsportRacecraft Coin-Op, Victory: The Age of Racing

al2950
OGRE Expert User
OGRE Expert User
Posts: 1227
Joined: Thu Dec 11, 2008 7:56 pm
Location: Bristol, UK
x 157

Re: Screen space decals mask

Post 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.
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: Screen space decals mask

Post 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.
al2950
OGRE Expert User
OGRE Expert User
Posts: 1227
Joined: Thu Dec 11, 2008 7:56 pm
Location: Bristol, UK
x 157

Re: Screen space decals mask

Post 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?
Nickak2003
Goblin
Posts: 272
Joined: Thu Jun 10, 2004 4:19 am
x 26

Re: Screen space decals mask

Post by Nickak2003 »

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

Post Reply