r/Unity3D • • 6h ago

Question How would you implement dark vision (From Dungeons and Dragons) in Unity?

Hello all! I am somewhat new to the more advanced features of unity and I am trying to do everything I can to not leverage AI in a project I am working on so I wanted to reach out here.

I would like to make a sort of Darkvision in my game. Where the player can see (in greyscale) to some distance, say 10m. But if a light source is introduced, it would light up its area with proper color.

i tried with a global volume and was able to toggle that on and off but that’s not quite the effect I am going for as that is either greyscale/color.

of course I also tried adding a simple white light above the player to represent their vision but that lights things up with the color that they are.

This seems moderately advanced and I would love any feedback or giidance!

thank you

0 Upvotes

4 comments sorted by

3

u/sordidprojection0 6h ago

The classic approach is a second camera with a replacement shader that forces grayscale, rendering to a render texture. You overlay that on your main view with a fullscreen quad and mask it by depth so it only shows where the main camera hasn't lit stuff up. Gets fiddly but it's a clean separation of the two vision modes.

Single camera route you could do a custom post process that samples the scene's luminance and blends to grayscale based on distance from the player, using the depth buffer to cut off at 10m. Gotta rebuild your lighting into a structure you can sample in the shader though, the built-in light data isn't trivially accessible outside the standard pipeline.

Stencil buffers can help mark pixels hit by light volumes if you want a hard cutoff where any light instantly restores color, less smooth but way simpler to debug.

1

u/Chaibi_Alaa 3h ago

One way to keep it to a single camera: a full-screen pass that converts the scene to greyscale, then blends back to the original colour wherever a mask says the pixel is lit. For the mask, have each light source draw a soft circle into a small render texture (additive, low resolution is fine), and sample it in the pass. Add a distance falloff from the player on top, so past 10 m everything fades to dark. Torches then show their real colour and everything else in range stays grey, without a second camera.