Hey all, I’ve been banging my head against this one for a bit but I’m having trouble finding a clear answer. I’m working on modifying a shader I found that implements decals using HLSL: How do i implement decals into a shader in hlsl
It works very nicely for default Unity primitives, but breaks on other objects. For example, here are 4 objects. The left 2 are a Unity cube and sphere, and the right 2 are a 3D modeled cube from Blender and a Bus model I found:
With the Decal shader, you can see the left 2 objects fade nicely while the right cube is completely solid and the bus doesn’t appear at all:
Debugging it, the issue seems to arise when converting the vertex from world to local space. Here’s a modified version of the shader that visualizes the localPos variable:
For reference, this is created by sampling the scene depth at the vertex position, then converting it to local space using unity_WorldToObject. My hunch is that scale has something to do with it, and I had some success multiplying the localPos by the object’s scale using code from here: Can I get the scale in the transform of the object I attach a shader to? If so, how?
However, this changes the values (which I don’t want) and still doesn’t seem to work for the bus in the bottom right.
Can anyone explain how unity_WorldToObject works, or have any guesses what I’m doing wrong?



