Simplest way to "decal" in GLSL

651 Views Asked by At

This is all done in C++ with GLSL...

I have mesh A. I project another (flat) mesh onto mesh A, and it takes the shape of the part of Mesh A it collides with. This is how I'm putting decals onto a model.

Now, I used a seperate shader to render the decal's pixels. Without going too deep into it, I prevent z-fighting and put the decal on top by simply multiplying the final vertex position's "w" by 1.0005f. This seems to work with everything I throw at it.

The only downside is, when very, very, very zoomed in, you can see that the decal is hovering above mesh A (because it is). Is there some better way for me to do this decal deal? Rendering it multitexture is not an option because of the application involved-- it has to be a seperate mesh. Is there some better method of adjusting w than a multiply like this?

1

There are 1 best solutions below

0
Tomas On

Use glPolygonOffset (official documentation). This applies an offset to the depth only and not the actual position of the vertex.