Screen space decals mask

Discussion area about developing with Ogre2 branches (2.1, 2.2 and beyond)
Post Reply
User avatar
TaaTT4
OGRE Contributor
OGRE Contributor
Posts: 165
Joined: Wed Apr 23, 2014 3:49 pm
x 16

Screen space decals mask

Post by TaaTT4 » Mon Oct 08, 2018 10:05 am

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.
0 x
Senior game programmer at Vae Victis
Working on Racecraft

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

Re: Screen space decals mask

Post by al2950 » Mon Oct 08, 2018 12:46 pm

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.
0 x

User avatar
TaaTT4
OGRE Contributor
OGRE Contributor
Posts: 165
Joined: Wed Apr 23, 2014 3:49 pm
x 16

Re: Screen space decals mask

Post by TaaTT4 » Mon Oct 08, 2018 1:10 pm

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.
0 x
Senior game programmer at Vae Victis
Working on Racecraft

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

Re: Screen space decals mask

Post by al2950 » Mon Oct 08, 2018 1:19 pm

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.
0 x

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

Re: Screen space decals mask

Post by dark_sylinc » Mon Oct 08, 2018 7:06 pm

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.
0 x

Post Reply