Jump to content
The Dark Mod Forums

Recommended Posts

v 0.69 .. (nice)

  • added cap to ambient rimlight, so brighter/lighter surfaces (eg white sheet-covered furniture, status/busts, etc) don't stick out like a sore thumb in the dark
  • added direct light boost option to compensate if ambient light darkening is on
  • everything has fake spec enhancing light dot to act as base layer of specular; real spec maps get layered on top as extra spec enhancement for things that have it.
  • in "interactions.funcs.glsl", added #define AMBIENT_HALF_LAMBERT to swap ambient light dot between doing valve-style half-lambert vs. full NdotL

Rimlighting part is self-explanatory. Was messing with Blackgrove Manor with ambient light reduction, and light/white textures had gaudy rimlighting. So, had to set a limit cap.

Direct Light Boost

Direct light boost option compensates when ambient light darkening is on.. Basically, it does about 1/3 of the opposite of the ambient reduction.

EG: if you reduce ambient light to 25%, then direct light will boost

  • 1.0 + (1.0 - 0.25) * 0.33
  • 1.0 + 0.75  * 0.33
  • 1.0 + 0.2475
  • ~1.25 (125% boost)

This is because ambient light doesn't contribute to total light as much as direct light does. So, just b/c we reduce ambient light to 25% doesn't mean we should boost direct light up 75% to compensate.

Spec Maps

Got tired of "if real spec map use it, else use fake" ... decided to experiment and just put fake spec map light dot enhancement on everything, then layer real speculars on top for things that have it. Turned out pretty nice after tweaking some values. Gets rid of some branching, too. I'll mess with some levels with it, and clean up the code more if I decide to stick with it, b/c that part of the code is a hot mess of experiments right now.

Half-Lambert vs Full-Lambert Light Dot

When objects multiply by the NdotL light dot for diffuse (color) lighting, if they have a surface angle 90 degrees or more to the light source, then they get an NdotL of 0. This would make the sides of boxes pitch black, ceilings pitch black, etc.. b/c ambient light source direction is coming down from directly overhead.

The valve-style half-lambert acts like an all-in-one solution to this, because it takes the 0 to 1 NdotL range, and shifts it to 0.7 to 1.0 (if you use sqrt(lightdot*0.5+05)). So, it prevents pitch-black surfaces by automatically creating a constant minimal light value.. but does so on the light dot. Since it tightens the dot range, it also evens out the lighting more.

But, the NdotL provides a greater range, and thus, greater contrast in lighting. In using it, we have to apply a final ambient light constant value to keep things from being pitch black. So, I just use the diffuse lighting a second time... in following fashion...

  • diffuse light = diffuse light * diffuse texture * diffuse light dot (NdotL)
  • ambient light = diffuse light * diffuse texture * "ambient light dot"
  • total ambient light = diffuse light + ambient light

That faux "ambient light dot" is just a constant value to determine how much ambient light to add on to keep things from being pitch-black. Even though this method isn't using valve half-lambert, it still calculates the ratios for that, because it uses them to determine that "ambient light dot". I did this, because TDM has a variable to set a minimum level, so I check if that exists and use it.. if it doesn't exist, then I use a different default value.. 0.5 in this case, b/c it works well for both half-lambert and the NdotL methods. 0.25 as default looks more like default TDM shaders, but the added speculars in my shaders make the light gem boost a bit more. So, shifting the default to 0.5 darkens the level a bit but also makes the light gem work well again.

Anyways.. there's a bunch of TMI

Hopefully this doesn't muck up Bloom again.

 

 

glprogs.stages.interaction.069.zip

Link to post
Share on other sites
  • Replies 160
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

Popular Posts

3 days w/o power in texas. Froze my nuts off. But, power's back on. Upgraded to 2.09, then messed with shaders some more. Mainly the glprogs/stages/interaction/ ... common & ambient, b/c they

v 0.22 BRDF & PBR implemented... in faux fashion Snagged code from... https://github.com/urho3d/Urho3D/blob/master/bin/CoreData/Shaders/GLSL/PBR.glsl        // BRDF main rou

v 0.71 fake spec diffuse light enhancement boosted a bit to be more noticeable added the direct light rimlight boost back in Fake Spec Boost Fake Specs enhance diffuse light

Posted Images

Here's a gif of the NdotL vs. Half-Lambert, so you get an idea of the difference. The NdotL seems stark around the bottom of boxes, but when you have SSAO on, it blends them into the ground. NdotL is more true to math / scene, but half-lambert is a crutch technique to help with blending. Again, this is only done on ambient lighting shader. Direct/Common lighting shader does NdotL to provide a stark contrast between light and "not light" (IE: opposite sides of light where AO from lightdot being 0 sets in)

YzkKbZy.gif

Link to post
Share on other sites
Posted (edited)

Is there a way to tell the light sources apart?

I was looking over the default TDM shaders again (now that I have a better understanding of what's doing what), and there's a variable called "R2f" in interaction.common.fs that shapes light to make it seem like lamps cast more light downwards than upwards (b/c their glass / metal hoods block some light). But, it looks odd on torches, candles, sconces, etc that would shoot more light upwards and less down due to their implement blocking light downwards.

I can use modify the R2f function to make it shoot upwards or downwards.. that was easy enough. But, if I can't build logic into the shader to differentiate light sources, I don't know which should get upwards & which should get downwards....

Here's some picks as example from Coercion...

A lamp looks better with light shaped downwards...

IkRvSHX.png

... not upwards ...

Z2OiNNc.png

 

But, a candle looks better with light shaped upwards...

6CSp2xg.png

... not downwards ...

1IDOyZj.png

 

However, without being able to tell the light sources apart, the shader can't tell how to shape the light to benefit.

Original shaders used R2f as-is, and it blended well enough I guess to not be noticeable. But, I'd really like to leverage it for nicer lighting.

Do light objects have some flag that could get piped through as a uniform to the shaders?

(edit)

I should also mention... fireplaces look better without any R2f shaping.

So, an ideal variable would be able to tell me if light should get shaped up, down, or not at all.

Is there something like that?

Edited by totallytubular
extra info
Link to post
Share on other sites
11 hours ago, totallytubular said:

I was looking over the default TDM shaders again (now that I have a better understanding of what's doing what), and there's a variable called "R2f" in interaction.common.fs that shapes light to make it seem like lamps cast more light downwards than upwards (b/c their glass / metal hoods block some light).

Admittedly I'm only a newb when it comes to shaders, but that seems very odd to me. Why should the global interaction shader make assumptions about the directionality of in-game light sources, rather than having this controlled by the falloff textures which can vary from light to light?

If you can have a per-light interaction shader I suppose this would make sense, but if there is such a mechanism in game I certainly don't know how it would be configured in DarkRadiant (I suppose you could have a "shader" spawnarg on the light entity itself).

Link to post
Share on other sites
1 hour ago, OrbWeaver said:

Admittedly I'm only a newb when it comes to shaders, but that seems very odd to me. Why should the global interaction shader make assumptions about the directionality of in-game light sources, rather than having this controlled by the falloff textures which can vary from light to light?

If you can have a per-light interaction shader I suppose this would make sense, but if there is such a mechanism in game I certainly don't know how it would be configured in DarkRadiant (I suppose you could have a "shader" spawnarg on the light entity itself).

 

Interaction shaders were designed with alternate fallback methods in case certain things weren't set.

EG: if a surface is missing specular texture, then it would apply a minor amount as fallback. But, it was multiplying all speculars by specular light color params. Surfaces w/o specular had their specular light color set to 0 rgb (pitch-black), which negated any fallback specular amount being applied.

The fallback methods basically act as crutches in case something isn't set for whatever reason... a likely scenario is because it would take more effort to do it "right" than it's worth. EG: going through all textures and making sure they all had a proper specular texture.. that's a lot of work, and would possibly add a lot of memory bloat to things.. especially for inconsequential stuff that will just have a very minor amount of specular applied. It's cheaper to just have a catch-all fallback method to do it in the shader.

The R2f in default direct light shader is applied regardless, so doesn't look like it was done as a fallback method.

But, it could be shifted to being one.

I think the problem would be level designers can position lights in all kinds of weird ways. I've seen hooded lamps parked on the ground and shooting upwards to highlight statues. The R2f shapes the light by just boosting the light direction up or down. If a lamp was flagged to boost downwards, but level designer parked it to shoot upwards, it would shape those weird. Who knows.

I'm gonna keep the R2f disabled in the shaders I'm farting with.

 

Link to post
Share on other sites

v 0.71

  • fake spec diffuse light enhancement boosted a bit to be more noticeable
  • added the direct light rimlight boost back in

Fake Spec Boost

Fake Specs enhance diffuse lighting overall, creating subtle specular shines on things that don't normally have specs, and enhancing stuff that does. When I'm working on them, I'm hyper-focused on them, and notice very subtle amounts. But, regular players are going to be blowing through areas, and won't notice anything that is barely noticeable by me when I'm hyper-focused on them. So, I boosted the amount a bit. The idea isn't for it to be "in your face", but just to add detail that the player might actually notice every now and then as it enhances the scene.

Direct Light Rimlight Boost

Default TDM shaders have a wonderful effect where the rimlighting in direct light would brighten the more direct line-of-sight the player had with the light source, and the closer the player's eye level was to the surface the light source lit up.

When tearing the shaders down and testing each variable to figure out what was doing what, I omitted this, b/c the two parts of it, when tested individually, don't seem like they do much. (one part super-dulls the shine while another part super-brightens). But, going back and looking at default TDM shaders to see what I've missed or did differently, I noticed that when those two var's combine, they create the great rimlight shine boost.

So, I added it back in.. but did so by treating rimlight like a two-step light as well. Base rimlight is done, then it's used to create a specular rimlight that gets added into base rimlight.. and then, that all gets added into specular lighting if the surface has a real specular texture map, or diffuse lighting if it doesn't (and shaped by the fake spec map before doing so).

So, the nice, bright edge is back on the direct rimlighting...

7e9U5XN.gif

If you're wondering why my rimlighting wraps around more...

  1. The normal map intensity has been boosted, making detail pop out more.
  2. I don't know 😕

I know the normal map adjustment will create more detail to pop out, which means things stick out further and thus get hit by light more. But, other than that, I'm not sure why it wraps more. But, it acts like light bouncing off one pillar onto the backside of the other to extend the rimlight range. I like the effect, so keeping it.

glprogs.stages.interaction.071.zip

  • Like 3
Link to post
Share on other sites
15 hours ago, totallytubular said:

I'm gonna keep the R2f disabled in the shaders I'm farting with.

That sounds like a good idea to me. If content creators want lights to shine more strongly downwards than upwards, they can set the Z falloff texture to accomplish this (by having brighter grey values in the bottom half of the texture). It certainly shouldn't be done in the shader for all lights, regardless of light texture or positioning.

  • Like 2
Link to post
Share on other sites
Posted (edited)

Just noticed some surfaces have specular light color set (params[var_DrawId].specularColor.rgb), but don't have a specular texture.

In default TDM shaders:

ambient does a specular texture pull regardless

	vec3 matSpecular = textureSpecular( var_TexSpecular ).rgb;

.. but, common checks if specular light color is pitch-black first.. if it's not, then it does the specular texture pull

	if (dot(params[var_DrawId].specularColor, params[var_DrawId].specularColor) > 0.0)
		specular = textureSpecular(var_TexSpecular).rgb;

 

While messing with specular, I noticed this one dark-reddish-brown door/gate (left-side of image) never had specular, excepte for the metal fittings. Didn't matter what I did, in my shader I couldn't get specular to apply to it.

bPvWp5l.png

So, I piped specular light color through to see if it was flagged as a specular texture surface. Yup.. it has specular light color param set...

upYkoeR.png

With the specular light color set, the specular texture should pull. So, I pipe specular textures through to see what they impact...

xWOJb8y.png

Only the metal fittings have specular textures.

So...

specular = specular texture * specular light color * specular dot (brightness)

But, if the specular light color isn't set, or the specular texture doesn't exist, specular is 0.

So, this dark red-brown door/gate is never getting specular unless there's some double-checking going on to fallback to an alternate method (like applying a generic amount of spec, or, what I've been doing, grayscaling the diffuse texture as a faux spec map).

Not sure if surfaces having specular color light set, but not having a specular texture, is by design or a bug.

I was going to work some error-checking into my shaders to test if specular texture is pitch-black. But, that's a "meh" prospect, since specular texture maps could literally have pitch-black areas to create shine-free surface details.

Not sure how to approach this.

(edit)

I stared at the default TDM ambient / common shaders more.

  • Ambient doesn't use specular light color at all. It just pulls specular texture, then muls it by specdot & specpow in a way to adjust specular lighting. So, specular light color never comes into that equation.
  • Common does use specular light color, and uses it to decide if a surface has a specular map. Since the dark-brown door/gate is covered by specular light color, it does a specular texture pull, but it doesn't have a specular texture (or it's defaulted to pitch black). So, it ends up with no specular.

In my ambient shaders, I added in specular light color, and was using it (like in common) to check if a spec map pull needed to be done. Figured it was good to skip an unnecessary texture call.

I think in my shaders, I'll just check if both specular light color & specular texture are pitch-black (empty), and fallback to faux spec maps.

Edited by totallytubular
extra info
Link to post
Share on other sites

v 0.75

  • cubic / non-cubic branching added back to common/direct lighting (guess I removed it when sorting out diffuse vs specular light color.. realized it was broken when playing a level and the tiffany-style desk lamps made the room super bright)
  • called rimlight boost "rimshine" (rimlight is the soft fresnel while rimshine is the bright, crisp edgy part)
  • added rimshine to ambient lighting, but there it enhances all not just following specular trail up wall (had to make it enhance more than just the specular trail, b/c the specular trail going straight up becomes too over-powered with specular + rimlight + rimshine)
  • In ambient, ditched the sqrt() part in the lightdot*X+Y linear algorithm. Valve's half-lambert style was meant for light dots in -1 to 1 range, so sqrt(dot*0.5+0.5) was boosting it to 0.7 to 1 range.
  • AMBIENT_HALF_LAMBERT #define lets you decide if you want to do NdotL*X+Y half-lambert, or full-lambert with NdotL. When doing full-lambert, it will create a final, constant ambient light to add to total light at the end (basically diffuse texture * diffuse light color * constant value to create a constant light not impacted by light direction.. this keeps NdotL = 0 surfaces from being pitch-black).
  • Changed linear lightdot*X+Y formula to minBrightness & mulBrightness ... minBrightness is the additive (Y) part, and is used to see if u_minLevel exists (which it will use as an override). mulBrightness is the multiplier (X), which gets calcualted as (1-minBrightness). (it's basically reverse of how I was doing it with p/q, b/c I realized u_minLevel needed to be the additive, not the multiplier .. d'oh).
  • surfaces in specular light color area that don't have a specular texture (it comes back pitch-black) get the fake specular diffuse brightness boost now. (which my previous post was discussing). So, that dark reddish-brown gate door is speculared, but via diffuse dot enhancement.
  • added a test if specular texture does exist after it's pulled, and that flag is used going forward to do real spec parts. This may or may not help performance much, but it's purpose is to skip more specular math on parts that don't have real specular textures.
  • ripped out phong specular from ambient... it's blinn-phong again, but still uses double-speculars to cover both floors & ceiliings and such. (Phong specular is just too hit or miss.. it looks good in some places, then awful the next. Blinn-phong has more consistent look and quality).
  • added #define to switch ambient light back to original TDM specular style.

 

glprogs.stages.interaction.075.zip

  • Like 1
Link to post
Share on other sites

v 0.77

  • ambient light amount matches up to original TDM shader ambient light amount better now
  • ambient rimshine applies to all rimlighting as edge highlighting, and tweaked to hopefully not be too gaudy
  • direct lighting rimshine toned down a bit, b/c it was super-bright
  • fake spec math changed, b/c averaging fakespec + (1-fakespec) was just making 0.5 regardless (d'oh). Switched to using a percent frequency curve to reduce shine on both very bright/dark textures while boosting the mid-tones. This evens out the shine a bit while still giving color variation.
  • tweaked ambient spec floors/ceilings to actually dim them instead of whatever it was I thought they were doing when I wasn't thinking straight while high on vaccine
  • added #define AMBIENT_DARKEN_UNDER ... this slightly darkens light on the underside of objects / surfaces (opposite light direction) in ambient light to help them blend into shadow maps / ssao better

My ambient shader created darker shadows than TDM originals. I originally kept it, b/c switching to an ambient light that matched original TDM caused the light gem to brighten slightly. But, after I tested it for a bit on more levels, it was only in a few places and didn't really impact game play. So, I just switched ambient lighting over to look more like original TDM shaders. My goal is to enhance the shaders while still keeping towards the original artistic look & feel. Not force darker shadows on folks. (If you want darker shadows, there's a #define in the "interaction.funcs" file called AMBIENT_LIGHT_DARKER you can play with to do that in optional fashion.)

Ambient rim shine was multiplying by specular dot, which basically culled the rim shine too much and accentuated it too much in specular trails up walls. Decided to just use rim shine as a generic boost. It branches on whether things have a real vs fake spec map, so metallic objects and stuff will use their specular texture and specular light color to do the rim shine while other things will use the fake spec map to tone it down.

Rimlight in ambient shader didn't take light direction into account. So, we ended up with bright rimlight highlights on the underside of objects (like canvas packages) that looked odd. I created a reverse light direction hack to dim the rimlight on the underside of things. Then I figured to just apply it to all ambient lighting (diffuse, specular, rimlight) to dim the lighting on underside of objects & surfaces. By using the reverse light direction, we have better control over how much gets dimmed (finer control than a half-lambert). I reduced the light slighlly, because too dark and it has opposite effect of sticking out like sore thumb being too dark. So, I faded it slightly to help blend into shadows / shadow maps / ssao.

AJg4vsO.gif

On the under-side of the canvas package, the ambient rimlight, et.al. create an unnatural shine. Shadow maps & SSAO don't get rid of it; there's still a slight unnatural seam of light. So, applying a hack with the reverse light direction, we can tone down the lighting on the underside of it (and other surfaces) to help it blend into shaows & ssao better.

This is just a brightness reducer, not an "anti-light" / black-light rgb light source (which I've seen used in some games to create fake shadows, and it always looks fugly.)

glprogs.stages.interaction.077.zip

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...