Search Unity

Question Help understanding how decals work

Discussion in 'General Graphics' started by MMeyers23, Jun 27, 2020.

  1. MMeyers23

    MMeyers23

    Joined:
    Dec 29, 2019
    Posts:
    101
    I am working on a post processing effect that will (hopefully) map a texture onto ground surface like a projector or a decal would. So far it only works in one plane (xz) and stretching in other directions.

    https://giphy.com/gifs/KZjqJVHSs5i2dSfFbV

    I retrieve world space coordinate of pixels via depth texture. I have basically worked out how to get world normals of a scene as well (it is acting a little odd, I think due to how I am feeding my matrix into my shader) : https://giphy.com/gifs/KHJTZBjlfAMAwz68re

    I assume decal shaders combine world position and world normals somehow, if this is the case could someone help me understand how exactly to combine the two to make my texture project correctly across surfaces like a decal shader would? Ideally, I would also like to be able to change the projection angle to mimic the main directional light.

    I am using post processing stack v2 in URP, so I have to use hlsl includes, not cginc. Thanks for any insight!