Page 1 of 1

[SHADER] Sonic The Fighters-style model lighting (v2)

Posted: Sat Apr 25, 2020 4:32 am
Can't download? Try this link instead: ... 8#p1148678

Here's a Sonic The Fighters/Superhot style model lighting shader for Zandronum 3.0 (Which might work with map geometry, haven't tested). Thanks to Kevin over at for his great help, without it I wouldn't have done this at all.
For usage, set up a brightmapped model as you normally would in GLDEFS and MODELDEFS, but set "map" to "shader/null.png" (included in the pk3 file)
NOTE: If your brightmaps have any alpha translucency, that section of the brightmap will be interpreted as "needs flat shading" (This also completely discards RGB info the brightmap set in that pixel!). Use only black and white brightmaps if you need normal Zandronum/GZDoom behavior.

I recommend keeping the shader itself as a separate addon, for compatibility with future Zandronum versions. Since this overrides func_brightmap.fp, and GZDoom itself has already completely switched to using a different method for brightmaps (They are internally treated as materials, and old shaders replacing it won't work correctly) it's to be expected Zandronum will too, so please avoid making this an absolute requirement so people will be able to run your mod with newer Zandronum versions.
Spoiler: Features (Open)
-Gives your models in Zandronum a lot more contrast and a e s t h e t i c !

-Allows you to choose exactly which models/surfaces get affected by the lighting, and which ones don't!

-Does not sacrifice brightmap functionality!
Spoiler: Customization (Open)
You can also customize light direction by modifying the following line in shaders/glsl/func_brightmap.fp:

Code: Select all

vec3 lightDir = vec3(x, y, z);
Where X is left/right (left is negative, right is positive)
Y is up/down (negative up, positive down)
and Z is depth (positive closer, negative further).
Keep in mind that this doesn't work like a point light, but like a directional light.
Spoiler: Known bugs (Open)
-Zandronum will spit a shader compilation error with "pixelpos" and "xyz", these are false errors and can't be avoided, as far as I'm aware. The shader will still work fine.

-GPUs with Shader Model older than 4.0 may experience issues with light orientation (The lighting will appear to be "painted" into the model, and will rotate with it).
Screenshot of how it looks (might look nicer with higher poly models, or some with better triangle distribution):

Re: [SHADER] Sonic The Fighters-style model lighting (v2)

Posted: Sat Apr 25, 2020 6:22 am
by Ivan
Does Zandronum even support shaders?

Re: [SHADER] Sonic The Fighters-style model lighting (v2)

Posted: Sat Apr 25, 2020 7:10 am
Ivan wrote:
Sat Apr 25, 2020 6:22 am
Does Zandronum even support shaders?
Sort of. You can override the built-in shaders, but most of the time this still isn't enough to do anything decent since GZD 1.8.6's renderer (and by extension Zandro's) does not expose anything but the bare essentials for GLSL (and even then, gl_Normal is not among those).

This one works by replacing the brightmap shader, and checking if the processed brightmap texel has any alpha translucency in it (if it doesn't the brightmap is processd as Zandro would normally do), and if it does then it recalculates the currently processed polygon normal, and does other light-related stuff. This way, brightmap functionality is left intact, and a new feature is added without requiring any source code modifications.

Well, almost completely intact, because if a brightmap uses alpha translucency instead of a darker color to indicate less-bright areas (which is not the intended way AFAIK), then the shader assumes it just means "just ignore what the brightmap set for this texel and apply flat shading", so for safety reasons only black and white brightmaps should be used except for a few special cases.