SimSun Shader - Simulated directional light for models

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.
User avatar
Graf Zahl
Lead GZDoom+Raze Developer
Lead GZDoom+Raze Developer
Posts: 49130
Joined: Sat Jul 19, 2003 10:19 am
Location: Germany

Re: SimSun Shader - Simulated directional light for models

Post by Graf Zahl »

dpJudas wrote: 2) The physical correct falloff is actually not to convert it to an angle. Light level should be "float lightLevel = clamp(dot(l,n), 0.0, 1.0);".
For a case like this, where it's only supposed to improve contrast, wouldn't it make sense to keep a certain amount of ambient light?, e.g.

float lightLevel = 0.4 + 0.6 * clamp(dot(l,n), 0.0, 1.0);

?
User avatar
Cherno
Posts: 1318
Joined: Tue Dec 06, 2016 11:25 am

Re: SimSun Shader - Simulated directional light for models

Post by Cherno »

Thanks for the suggestions and help. If the shader is improved in any way by it, I am more than willing to change the code :)
dpJudas
 
 
Posts: 3109
Joined: Sat May 28, 2016 1:01 pm

Re: SimSun Shader - Simulated directional light for models

Post by dpJudas »

Graf Zahl wrote:For a case like this, where it's only supposed to improve contrast, wouldn't it make sense to keep a certain amount of ambient light?, e.g.

float lightLevel = 0.4 + 0.6 * clamp(dot(l,n), 0.0, 1.0);

?
Yes, it would.

Overall doing this in the material shader is problematic anyway as it changes the base color that then in turn is used by dynamic lights. I created a lightlevelcontrast branch that does it at right point in the fragment shader. Currently it is applying it to everything (so walls and flats, too), but both contrast strength and which object types we want to apply it to could be configurable by changing the strength variable to an uniform. Or the uniform could be controlled by the texture, like the SimSun Shader is doing.
User avatar
Cherno
Posts: 1318
Joined: Tue Dec 06, 2016 11:25 am

Re: SimSun Shader - Simulated directional light for models

Post by Cherno »

Update:
SimSun 1.1
Corrected the lightdir shader variable so it now doesn't need an inverted z value.
Shifted the light level by 0.25 to lessen the amount of extremely dark areas.
Added a cube model to the TESTMAP.

See first post for the latest version.
3336655445
Posts: 34
Joined: Wed Jul 24, 2019 6:54 pm
Graphics Processor: Not Listed
Location: Odessa

Re: SimSun Shader - Simulated directional light for models

Post by 3336655445 »

stupid question: is this mod (?) working fine with LZDoom?
edit answer: yes it works with LZDoom
User avatar
Kizoky
Posts: 291
Joined: Mon Nov 14, 2011 9:59 am
Preferred Pronouns: He/Him
Operating System Version (Optional): Windows 11
Graphics Processor: nVidia with Vulkan support
Location: Around weirdos, I'm the biggest weirdo among them

Re: SimSun Shader - Simulated directional light for models

Post by Kizoky »

I finally got tired of .bat files, so I wrote a program in C# for use with this shader:
https://github.com/Kizoky/simsun_output_gen
User avatar
Enjay
 
 
Posts: 26540
Joined: Tue Jul 15, 2003 4:58 pm
Location: Scotland

Re: SimSun Shader - Simulated directional light for models

Post by Enjay »

I tried this by the drag-drop method and there was no output (in fact, Windows Explorer hung the first time that I tried and I had to reboot). After restarting, several tries with several different files didn't seem to be generating anything.

So I went to the command prompt and typed simsungen and got:

Code: Select all

A fatal error occurred. The required library hostfxr.dll could not be found.
If this is a self-contained application, that library should exist in [C:\Users\[username]\AppData\Local\Temp\.net\SimSunGen\c23qeulz.eur\].
If this is a framework-dependent application, install the runtime in the global location [C:\Program Files (x86)\dotnet] or use the DOTNET_ROOT(x86) environment variable to specify the runtime location or register the runtime location in [HKLM\SOFTWARE\dotnet\Setup\InstalledVersions\x86\InstallLocation].

The .NET Core runtime can be found at:
  - https://aka.ms/dotnet-core-applaunch?missing_runtime=true&arch=x86&rid=win10-x86
User avatar
Kizoky
Posts: 291
Joined: Mon Nov 14, 2011 9:59 am
Preferred Pronouns: He/Him
Operating System Version (Optional): Windows 11
Graphics Processor: nVidia with Vulkan support
Location: Around weirdos, I'm the biggest weirdo among them

Re: SimSun Shader - Simulated directional light for models

Post by Kizoky »

Enjay wrote:I tried this by the drag-drop method and there was no output (in fact, Windows Explorer hung the first time that I tried and I had to reboot). After restarting, several tries with several different files didn't seem to be generating anything.

So I went to the command prompt and typed simsungen and got:

Code: Select all

A fatal error occurred. The required library hostfxr.dll could not be found.
If this is a self-contained application, that library should exist in [C:\Users\[username]\AppData\Local\Temp\.net\SimSunGen\c23qeulz.eur\].
If this is a framework-dependent application, install the runtime in the global location [C:\Program Files (x86)\dotnet] or use the DOTNET_ROOT(x86) environment variable to specify the runtime location or register the runtime location in [HKLM\SOFTWARE\dotnet\Setup\InstalledVersions\x86\InstallLocation].

The .NET Core runtime can be found at:
  - https://aka.ms/dotnet-core-applaunch?missing_runtime=true&arch=x86&rid=win10-x86
Uh oh
Do you use Windows 10 or some earlier OS?

edit: nevermind, I know what's the issue here :(
Last edited by Kizoky on Sat Aug 14, 2021 6:34 am, edited 1 time in total.
User avatar
Enjay
 
 
Posts: 26540
Joined: Tue Jul 15, 2003 4:58 pm
Location: Scotland

Re: SimSun Shader - Simulated directional light for models

Post by Enjay »

Windows 10 Pro 64-bit - fully updated.
User avatar
Kizoky
Posts: 291
Joined: Mon Nov 14, 2011 9:59 am
Preferred Pronouns: He/Him
Operating System Version (Optional): Windows 11
Graphics Processor: nVidia with Vulkan support
Location: Around weirdos, I'm the biggest weirdo among them

Re: SimSun Shader - Simulated directional light for models

Post by Kizoky »

Enjay wrote:Windows 10 Pro 64-bit - fully updated.
Could you please go here (https://github.com/Kizoky/simsun_output ... es/tag/1.1) and download SimSunGen_L.exe ?
It seems I totally forgot how .NET apps work, with that app it should now work fine, ofc with the downside that it's file size is now much bigger :shock:

edit:
Above link is dead, use this: https://github.com/Kizoky/GLDEFGenerato ... s/tag/v1.0
Last edited by Kizoky on Sun Aug 15, 2021 2:40 pm, edited 1 time in total.
User avatar
Enjay
 
 
Posts: 26540
Joined: Tue Jul 15, 2003 4:58 pm
Location: Scotland

Re: SimSun Shader - Simulated directional light for models

Post by Enjay »

That works, thank you kindly. :)
Kazudra
Posts: 126
Joined: Mon May 25, 2015 10:52 am

Re: SimSun Shader - Simulated directional light for models

Post by Kazudra »

MFG38 wrote:I'm curious, though: how good would this look on a 2D sprite?
If you prep the sprites in a way that all shading is handled by the normalmap it'll basically look like a 3d Model.
This is how Mario Maker Handles New Super Mario Assets (aside from Mario, the only 3D asset).

It only leaves the vital question; How big does the sprites NEED to be to be handled this way proper?
User avatar
ramon.dexter
Posts: 1557
Joined: Tue Oct 20, 2015 12:50 pm
Graphics Processor: nVidia with Vulkan support
Location: Kozolupy, Bohemia

Re: SimSun Shader - Simulated directional light for models

Post by ramon.dexter »

Wait, there is automatic GLDEFS generator? :shock: Great to know that after spending two days writing defs for my models to use the simsum shader :)
User avatar
Enjay
 
 
Posts: 26540
Joined: Tue Jul 15, 2003 4:58 pm
Location: Scotland

Re: SimSun Shader - Simulated directional light for models

Post by Enjay »

I finally got around to trying this properly with a lot of models from model resource folder I have.

Firstly, Kizoky's GLDEF generator was a godsend. I just dropped the models folder onto the exe and it spat out a flawless GLDEFS for every graphic in the folder - including sub folders - with correct paths and everything. Almost 800 models skins allocated to the SimSun shader in less than a second.

Then "all" I had to do was browse through my models folder to try and identify the skins that I didn't think would work too well with this. This turned out mostly to be skins for models that are meant to be light sources. The shader darkens them and the problem is particularly obvious for ceiling lights where the underside gets darkened the most.

Fortunately, it was an easy job to go through the folder to identify these and a few others. The skins that I deemed unsuitable for shading were very much in the minority and visually pretty obvious when scanning through the thumbnails by eye.

There were, also, one or two model skins where I was already using another shader on them and these can't co exist so I had to decide wither to keep the original shader or go with SimSun. Again, this selection process was pretty easy because there were only a handful of these and, of course, they are all already listed in a GLDEFS file so it was easy to find them in that file, search for the same graphics in the SimSun generated file then decide which one to comment out.

I guess the whole process took about 20 minutes - so no big deal really for so many models.

And the end result is very nice. As others have said, it's subtle (which is good) but definitely there and when switching back and forth between using the shader and not, the unshaded models very quickly started to look quite flat in comparison.

I'll still have to go through the models and evaluate them more thoroughly in game where they are most likely to be used but as a big, brutal, bulk test of both the GLDEFS generator and the SimSun shader, everything worked very well and the whole thing was surprisingly painless and error free to set up.
User avatar
Cherno
Posts: 1318
Joined: Tue Dec 06, 2016 11:25 am

Re: SimSun Shader - Simulated directional light for models

Post by Cherno »

SimSun can be combined with brightmaps, which I suggest for any light source models.

A SimSun-like feature will be integrated into one of the future GZDoom releases and automaticaly work without the need for GLDEFS entries, so this whole thing can be made obsolete, which I am looking forward to.

Return to “Shaders”