SimSun Shader - Simulated directional light for models

SimSun Shader - Simulated directional light for models

Postby Cherno » Sun Feb 02, 2020 4:44 am

This shader shades a model as if there was a lightsource coming from above, like the sun, sky, or moon outside and a ceiling light inside. The effect is subtle but noticeable. The flat lighting on models bothers me since most Doom maps don't have any, or not enough, dynamic light sources to properly light a model, resulting in a very flat look. You can combine this shader with GZDoom's ambient occlusion to further enhance it.
The shader works per-texture. If you are not familiar with using shaders, just check GLDEFS and add your own model textures.

Image

Image

Image
(thanks to Kizoky)

Download:
simsun1.0.pk3

Code: Select allExpand view
const float pi = 3.14159265359;
vec4 Process(vec4 color)
{
   vec3 lightDir = vec3(0.75,-1.0,0.5);

   vec2 texCoord = gl_TexCoord[0].st;
   vec3 l = lightDir;
   vec3 n = normalize(vWorldNormal.xyz);
   float angle = acos
   (
      (l.x*n.x + l.y*n.y + l.z * n.z)
      /
      (
         (   
            sqrt
            (
               (l.x*l.x)+(l.y*l.y)+(l.z*l.z)
            )
            *
            sqrt
            (
               (n.x*n.x) + (n.y*n.y) + (n.z*n.z)
            )
         )
      )
   );
   float lightLevel = angle;
   lightLevel /= pi;
   return getTexel(texCoord) * color * vec4(lightLevel,lightLevel,lightLevel,1.0);
}
Last edited by Cherno on Sun Feb 02, 2020 9:55 am, edited 3 times in total.
User avatar
Cherno
 
Joined: 06 Dec 2016

Re: SimSun Shader - Simulated directional light for models

Postby Kizoky » Sun Feb 02, 2020 7:30 am

Looks great! I gave this shader on a hand texture, you can see it here: https://gph.is/g/aQOOJwR

I always hated how all the models looked static unless they were under a dynamic light source
User avatar
Kizoky
I smell like gravity
 
Joined: 14 Nov 2011
Location: Around weirdos, I'm the biggest weirdo among them
Discord: Kizoky#0375
Operating System: Windows 10/8.1/8 64-bit
Graphics Processor: nVidia with Vulkan support

Re: SimSun Shader - Simulated directional light for models

Postby Cherno » Sun Feb 02, 2020 7:54 am

Looks great as well! :)

The shader can easily be customized (not a truntime, though), chiefly by modifying these lines:

Code: Select allExpand view
vec3 lightDir = vec3(0.75,-1.0,0.5);


and
the
Code: Select allExpand view
lightLevel

variable.

lightDir is just the direction of the light source as a Vector3. To have it come from straight above, it would be vec3(0,-1,0), for example (note that this is GLSL language, not zScript, so the second Vector3 variable (y) is up-down).
lightLevel by default goes from 1.0 to 0.0, where 1.0 faces the light source directly and results in the texture's color, and 0.0 is directly away from the light source and darkens the texture. You could change this by adding your own calculation, for example by making the light-facing pixels brighter than the texture, and so on.
User avatar
Cherno
 
Joined: 06 Dec 2016

Re: SimSun Shader - Simulated directional light for models

Postby Darkcrafter » Thu Feb 06, 2020 4:58 am

This needs to make into GZDoom and into Doom Builder, imagine if sector would have this direction/lighting settings how convenient it would be. Or even having additional setup per actor overriding sector properties.
User avatar
Darkcrafter
 
Joined: 23 Sep 2017
Location: South Russia
Operating System: Windows 10/8.1/8 64-bit
OS Test Version: No (Using Stable Public Version)
Graphics Processor: nVidia with Vulkan support

Re: SimSun Shader - Simulated directional light for models

Postby Redneckerz » Thu Feb 06, 2020 11:45 am

So subtle but its definitely noticeable. I see Kizoky's Share The Doom looks even more like its inspiration by it :)

This is really useful stuff. Sadly ZDforums has no ping mechanism, but Nash, this is the kind of stuff i know you like a lot!
User avatar
Redneckerz
A Doomer in H.A/R.M's way
 
Joined: 25 Nov 2019
Discord: Redneckerz#8399
Operating System: Windows Vista/7 64-bit
Graphics Processor: nVidia (Legacy GZDoom)

Re: SimSun Shader - Simulated directional light for models

Postby MFG38 » Fri Feb 07, 2020 8:46 am

I'm curious, though: how good would this look on a 2D sprite?
User avatar
MFG38
 
Joined: 14 Apr 2019
Location: Finland
Operating System: Windows 10/8.1/8 64-bit

Re: SimSun Shader - Simulated directional light for models

Postby Cherno » Fri Feb 07, 2020 11:35 am

I haven't thought about it; I'd wager it wouldn't be looking too great ;) If it works at all, that is.
User avatar
Cherno
 
Joined: 06 Dec 2016

Re: SimSun Shader - Simulated directional light for models

Postby Nash » Tue Feb 11, 2020 12:20 pm

It most likely won't work with sprites because sprites are lit uniformly (same reason why you can't have materials on sprites).

Speaking of materials - this doesn't look like it has material handling (diffuse + specular + normal map, or PBR), does it?
User avatar
Nash
 
 
 
Joined: 27 Oct 2003
Location: Kuala Lumpur, Malaysia
Github ID: nashmuhandes

Re: SimSun Shader - Simulated directional light for models

Postby Cherno » Tue Feb 11, 2020 1:43 pm

No material support. I had thought about adding support for normal maps so the get the same lighting from an imaginary source, but I personally don't use normal maps in my GZDoom projects (yet) so I didn't bother. Some other user on Discord wrote that he had written something similar for normal maps, can't remember who it was but at least it seems doable. If anyone wants to have a god at it, I'm sure it would be welcomed as well.
User avatar
Cherno
 
Joined: 06 Dec 2016


Return to Shaders

Who is online

Users browsing this forum: No registered users and 0 guests