Unity Version 2022.3
Hi, Martin here.
For my first real post, I have an update to my Fog render
feature I have been working on forever.
The reason - I am still getting used to HLSL and ShaderGraph, as I think
this will help me produce the look and feel I want for my game. Although I have learned a lot I still I’m
nowhere near where I need to be. This
learning process is so I don’t have to use Unity’s out-of-the-box tools, such
as depth fog, part of the fun for me is learning how to create such things and
being able to fix things if they go wrong.
Fog:
The easiest way I found to get fog into my scene was to use
a ShaderGraph material added to a custom render feature. I found ShaderGraph a great tool to visualise
the maths/interaction of the pixel and fragment shaders “parts”; It’s helped me
understand things like Lerp, Depth, clamping etc.
I was able to get a first pass to work with some controls
for; colour, start and end points and fog thickness. It looks good.
I then switched to HLSL; this is an old code sample. I eventually got it to work in HLSL, please
don’t run a check on my Fragment shader, I’m still learning:
Both ShaderGraph and HLSL versions make use of the depth
texture, this has exposed a problem.
When the camera angle changes, the fogs near and far planes change with
it. At this stage I’m not experienced
enough to fix this, if it even is fixable - the only thing I could think of is
locking the y camera camera plain?
Searching around I was advised to use distance fog, but it didn’t help
with close-ups due to the curve effect from the camera position. As the use case is for small rooms or close-ups
etc I come up with a temporary alternative using the VFX Graph.
So here is my depth Fog using the VFX Graph.
A better term would be “World space Linear Layered Fog”,
Allow me to explain: Imagine the back of
a room, with 30 sheets of huge tracing paper over it, that is the effect
here. I think it works well and it’s
much more resilient to camera angle changes.
The number of layers can also be adjusted, improving the effect. On the plus side, the framerate is around 100fps. I’m not sure why as I thought the GPU was
doing the heavy lifting here but my laptop fans go full power.
#indiegamesdaily #indiegames #madewithunity #videogame #gamedev #indiedev #indiegame #steam #indiegames #gamedevelopment #gameart #indiegamestudio #indiegamedev #indiedevelopment
No comments:
Post a Comment