I think you might find you actually want screen-space UVs instead of world space, or maybe offset the UVs by the players position so it centers there.
Aaanyway, your UVs should be equal to “mul(_Object2World, vertex).xy”. This will put your vertex in world-space and will not skew it with the camera’s perspective. This will be a little more complicated if you have to rotate your camera, and I’m also assuming your camera.forward is looking down the Z axis.
Since I have very limited shader knowledge, I still don’t know how to do it.
Just to show you that I’m trying
EDIT: I changed the code many times because nothing worked. So this might be even more useless then I what I had in the beginning
Since I’m not using the uv coordinates, I assume I don’t have to do anything with them when I build the mesh?
The problem with this code is that the mesh is screwed up and seems to extend infinitely in x and y.
So with this shader the screen is just black.
The problem now is that my shader doesn’t support alpha transparency. So with my light texture I can only fade into a specific color. Is there a way I can use a white to transparent gradient texture, so it works with every background color?
One note, doing lighting this way is a little wrong as a second pass on the already rendered background. The background already has some kind of coloring applied means the additive pass won’t have the same result as using an actual light.
That works great thanks. And it totally makes sense
You just missed a uniform float _LightRange, in case someone else uses the code.
I’m not sure if I understand right what you mean. Can I do something about it?
And could you give me an advise on how I would achieve that the boxes that aren’t lit aren’t rendered?