Open dougmpham opened 2 years ago
So to expand the max distance, you increased the camera far clipping plane, adjusted the script [Range] property so you can increase the values and expanded the size property (Width / Heigth) of the decal projector, right?
Looking once more at your screenshot I think I kind of get the problem. So if the margin is too big, everything is highlighted, even back sides of buildings. And if it is too small, you get stripes. Right?
I think the limitation here is the depth texture. You could use more than one depth texture to get more information to the shader but this is a quite complicated process. The format is already set to float so I doubt that there is any room to improve precision.
I made this a while ago so I'll look into it to try to understand where those stripes come from and why I fixed it with a margin. Maybe this can be resolved, idk.
Ok, stripes come from the resolution of the depth map. I am comparing the game camera depth with enemy camera depth. Depth becomes increasingly more unprecise with further distance. Stripes happen because the pixel on the enemy depth texture at this point has a lower value than the world position of the point (as visible to the game camera, projected with a matrix to enemy cam viewport).
I just tested: providing a higher resolution depth texture allows for a smaller margin without getting stripes. The best way to solve this would be to somehow round the calculated depth to the depth texture scaling. Maybe applying some logarithmic scaling to the projected world positions in the shader. But I am not an shader expert, idk how I would do that.
I increased the size of the depth texture by just adding " * 2 " to the pixel size of the camera like so:
_depthTexture = new RenderTexture(_enemyCam.pixelWidth * 2, _enemyCam.pixelHeight * 2, 24, RenderTextureFormat.Depth);
So in order to resolve the stripes in a clean way, we need the logarithmic rounding just after the "Project Point to Camera Space" comment in the shader, only for the "B" channel, after the split. (I guess)
Then we would have the same resolution in your compare-source as in our depth texture (which we use for comparison).
Thank you for your responses. I did try to increase the depth texture size and didn’t get a better result. I’m not a shader expert either and trying to understand what the shader is doing with the margin and projections. Thanks for the pointers.
Hi, First, thank you for your code. Just what I need for my project. I'm testing your view cone a city block. After adjusting the distance (larger), I ran into an issue of coverage and Margin adjustment. I had to change margin in material to 0 or near 0 to get near correct obstructed view from behind (see pic 1). However, this caused the decal projector to have line effects (larger gaps from further away, see pic 2). Hope you can give me some pointers of how to fix this. Thank you, Doug