- Home /
Unity projector projecting on other side of object [math required]
I've been going over some shader code for projector here and also in the shader code for projector in Unity standard assets and they both have a flaw that they project also on the other side of object like this:
this could be solved if I would check for
dot(normal, vector_to_projector) > 0
however I don't know of any Unity shader var that would give me projector position. There is unity_Projector matrix but that's for object->projector space transformation. Now I suspect there might a way to extract the projector world basis vector from that because we also know object->world matrix but my math is not that strong so I could do that.
Any math guru out there or is there more elegant way to check for not-projector-facing fragments?
Answer by elenzil · Mar 13, 2019 at 06:15 PM
do you not have the normal in object space ?
i'd consider going a step beyond and multiplying the color by the dot of the normal with the direction vector to the projector clamped to [0, 1]. that way you'll get the projection fading out as the surface it's projecting on becomes tangent to the direction of projection.
i'm unfamiliar w/ the matrices involved, but it seems like if you have the normal in object space and a matrix from object space to projector space, you're good ?
That's it! Once I converted the normal to projector space I checked for normal.z > 0 (originally though it's < 0, but hey, whatever works :D) and it does the trick!
Ok now to more complicated topic and that's to make it so the objects are actually occludable and not like on the picture where the projected texture is projected to everything.
right on! glad that helped.
occlusion, yah, idk. raymarch everything! ;)