I’m trying to create a post-processing material that will overlay hazard lines on top of certain ‘dangerous’ actors. See the (simplified) shader graph below:
The masking of the material and the creation of the lines in the shader are working just fine. The problem that I have is that the lines change thickness as the camera moves closer or further away. I believe it has to do with the UV’s and the WorldPostitionOffset or CameraOffset, but I’m uncertain how to implement it.
Hi, thanks for the reply! You’re totally right, in the editor it’s kinda hard to see this.
Is there any workaround to this? Since I have the Line Thickness (sine period) as a parameter, could one use the movement of the camera to somehow change the size of the lines so they ‘appear’ to stay the same thickness relative to the objects?
Is a PPM the best method to achieve the effect I’m looking for?
Just a quick update, I tried to use the CustomDepth Scene Texture, with some division to reduce the output value. I added a Clamp with the Min Value set to the Line Thickness parameter. The greyscale output of this gives a useful scalar to work with.
This works quite well when moving up close, as the lines don’t get thinner once the Min threshold is met. The problem with CustomDepth is that it hits its max value of 1,0 quite quickly as the camera moves away. The main issue is that I can’t clamp the upper bound, as the Line Thickness needs to decrease as the camera moves further away.
Hi @ClockworkOcean, thanks, this is really cool and will definitely have its uses. I gave it a try, but I’m not sure if it’s what I’m looking for.
I ultimately want to be able to highlight hazards or enemies through walls/when obscured. A post-processing material allows me to use the scene depth to mask items and see when they are obscured. I also want the line material to be aligned to the camera (i.e. have the same angle regardless of camera position). Using a custom depth or stencil, I can choose which items use the effect. It will probably combine it with an outline PPM as well.
I’m not sure that a decal will allow for this type of masking, or be able to align with the camera direction.
I might also add that I see this more of a HUD/UI element than a hazard line that I want to apply as a texture (or decal) to meshes. I want it to render over certain other actors.
I had a quick look at this, as I forgot about the Distance node. I had to divide it somewhat to bring it into usable values, but it causes an almost moiré effect, which I suspect is because of how the lines further from the camera ‘bend’.
Using only the CameraPositionWS node and also dividing it by a factor, and then subtracting that from the Line Thickness parameter, do I get the lines more stable. This also maintains the straight edges on the lines.
Increasing the factor that the Camera Position is divided by and then clamping the result of the subtraction creates a far more stable result. I’m thinking of making the effect simply fade out at a certain distance to the CustomDepth, that way the effect should be less noticeable anyway.
It seems to create a weird flicker. Clamping it removes the flicker, but the lines don’t change. Wouldn’t the Object Position only work on an in-engine object line, a static mesh. I’m guessing the PostProcessVolume doesn’t count as such an object.
I think this highlight part of the problem, that you don’t have a fixed (and known) point in space to reference from in a PPM?
I also just realised that this has no effect in fact. Seems it was merely placebo. I’ll keep messing around with this, as it’s proven to be a fascinating problem.