Page 1 of 1

Realistic nightvision shader

Posted: Sun Dec 15, 2019 10:38 am
by Caligari87
Originally created to replace the stock nightvision goggles shader in Hideous Destructor, but should work for anything else as well, provided you write a script and GLDEFs to activate it.

Note: Click through for full resolution, the scanlines look odd downscaled. Screenshot shows the dark edges from Hideous Destructor's goggle overlay, which is not included with this shader.

nitevis.fp [Github Gist]

  • Customizable resolution downscaling / pixelization
  • Optional horizontal and / or vertical scanlines
  • Customizable color filtering with two color modes and white clip levels

Your script must pass a custom exposure uniform to the shader, or else nothing will happen. The expected exposure value is an integer between -100 to 100, but should theoretically work with floats and higher numbers if desired. Positive values activate the primary color filter, negative values activate the secondary color filter. A value of zero disables color filtering and light amplification, but retains scanlines and pixelization.

The user-customizable values at the top of the shader should be self-explanatory, but are listed here for convenience. These are hardcoded by default, but if you're familiar with shaders it shouldn't take much to make them dynamic.
  • resfactor: Divides the native screen resolution by this amount. For example, if your game is running at 1920x1080, a resfactor of 4 will produce a virtual resolution of 480x270.
  • hscan/vscan: Enables horizontal and/or vertical scanlines. These are 1 real (not virtual) pixel thick, rendered black.
  • posfilter/negfilter: Color filters for positive and negative exposure values respectively. These are relative RGB channel strengths in the range of 0-1, but will be normalized by the shader, so (5, 2, 1) becomes (1.0, 0.4, 0.2).
  • whiteclip: Adjusts the "white value" of the brightest screen areas, with 1.0 being pure white, and 0.0 being the dominant filter color. Values above 1.0 are valid, as are negative values. Both can provide unique and interesting effects.

Please note the exposure curve on this shader is exponentially strong and meant to simulate realistic nightvision capabilities. Even at even moderate exposure values, typical Doom levels may become blindingly white.

The shader may not be able to amplify pure (0,0,0) black values. A minimum sector light level of 1 is recommended (My other project, DarkDoomZ, can be used to help enforce this if your project does not use custom maps). Some other method like attaching a very very dim dynamic light to the player when the shader is active can work as well.

There are no grain/static/noise effects, but these could be added if you wish to pass a timer uniform to the shader. Vignettes like the one seen in the screenshot are also left as an exercise for the user.

So far as I'm aware this code is my own, and is under the very permissive zlib license. You may use or modify this shader freely, provided the license and copyright notice remains intact.


Re: Realistic nightvision shader

Posted: Fri Dec 27, 2019 7:14 am
by 3336655445
what the weapons mod?

Re: Realistic nightvision shader

Posted: Fri Dec 27, 2019 3:43 pm
by Caligari87

Re: Realistic nightvision shader

Posted: Tue Jan 26, 2021 10:54 pm
by so19
Could someone compile this as a pk3 that could be readily used? I'm new to Gzdoom and can't figure out the coding. What I'd love is to use this shader to replace the current NVG effect in an existing modern warfare mod

Re: Realistic nightvision shader

Posted: Wed Jan 27, 2021 3:58 pm
by Caligari87
I released it this way because there is no way to make it universally compatible or "readily usable". Specifically, the existing NVG effect from the modern warfare mod would need to be modified to activate this one instead, or disabled to make this one to activate independently with some kind of hook. Either way, code needs to be written which will be specific to whatever mod you want this to work with.