Adding Decal To Box Geometry Is Not Working Correctly

when i add decal on a sphere geo , it shows correctly. but with same code , when i add a decal on a box geo , it shows wrong. Why?

decalcube decalsphere

What you see is a current limitation of the approach which is used to compute the vertex data for the decal. Texture coordinates are derived from XY values only. Hence, if vertices just have different z values, the respective uv data are all equal.

Is there a solution to this or should I look for alternative ways?

I’m not aware of an approach that avoids this glitch. You see it even in commercial games. I also don’t know alternatives.

1 Like

There are solution to this, but they require deferred shading pipeline. This here is not inevitable either, you just have to rotate your clipping cube.

1 Like