Realistic nightvision shader

Forum rules
The Projects forums are only for projects. If you are asking questions about a project, either find that project's thread, or start a thread in the General section instead.

Got a cool project idea but nothing else? Put it in the project ideas thread instead!

Projects for any Doom-based engine (especially 3DGE) are perfectly acceptable here too.

Please read the full rules for more details.
Post Reply
User avatar
Caligari87
Admin
Posts: 6174
Joined: Thu Feb 26, 2004 3:02 pm
Preferred Pronouns: He/Him
Contact:

Realistic nightvision shader

Post 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]

Features
  • Customizable resolution downscaling / pixelization
  • Optional horizontal and / or vertical scanlines
  • Customizable color filtering with two color modes and white clip levels
Usage
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.
Limitations
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.

8-)
3336655445
Posts: 34
Joined: Wed Jul 24, 2019 6:54 pm
Graphics Processor: Not Listed
Location: Odessa

Re: Realistic nightvision shader

Post by 3336655445 »

what the weapons mod?
User avatar
Caligari87
Admin
Posts: 6174
Joined: Thu Feb 26, 2004 3:02 pm
Preferred Pronouns: He/Him
Contact:

Re: Realistic nightvision shader

Post by Caligari87 »

so19
Posts: 3
Joined: Thu Jul 18, 2019 10:41 pm

Re: Realistic nightvision shader

Post 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 https://www.moddb.com/mods/call-of-doom ... eapons-mod
User avatar
Caligari87
Admin
Posts: 6174
Joined: Thu Feb 26, 2004 3:02 pm
Preferred Pronouns: He/Him
Contact:

Re: Realistic nightvision shader

Post 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.

8-)
Post Reply

Return to “Shaders”