Directional ambient lighting


#1

Since I first noticed it I’ve been bothered by the uniform ambient lighting in the game that can turn whole mountain sides into flat blobs of a single color, as soon as they’re not in direct sunlight. I had some ides of how to change it and yesterday I finally tried messing with the shaders. I must say I’m quite happy with the results. :slight_smile:

With SSAO.

Even more crucial without SSAO.

I made the changes directly in the main code, so no mixins or other proper modding methods. I still know too little about that and I’m not even sure if .glsl and .shader can be changed that way.
Anyway, it’s a small change if anyone wants to try it and I’m posting this as a suggestion because I think it (or something similar) should be in the actual game.

In the file “stonehearth\data\horde\shaders\utilityLib\fragLighting.glsl” I added this function:

float calcDirectionalAmbientShade(const vec3 normal)
{
float shade = dot( normal, -lightDir.xyz );
return (shade * 0.25) + 0.75;
}

In the file “stonehearth\data\horde\shaders\voxel\deferred_lighting.shader” I replaced the last line with:

float ambientShade = calcDirectionalAmbientShade(normal.xyz);
gl_FragColor = vec4(lightColor.rgb + ambientShade * lightAmbientColor, lightColor.a);

That’s all.
With the current settings the range of the ambiant lighting is 0.5 to 1 of the uniform ambient. This can be changed by changing the 0.25 and 0.75. Just make sure that the new values still add up to 1.
The ambient range 0.75 to 1 is on the side of objects that are facing the light. This may seam strange but it is used to see details in shadows.

No noticeable change in performance on my 6 year old laptop.


A wishlist of minor polishes and improvements for 1.0/1.1
#2

This is really cool!

I think you can do a mod with this by using overrides. Do you want help with that?


#3

That’s really cool, thanks for sharing : ). This is definitely something which I think we should fix asap, though we may not use this method exactly.


#4

gotta admit seeing directional and ambient being used together to describe the same thing caught me off guard, but after seeing the before and after, regardless of what you call it, you’ve convinced me.


#5

This is so awesome I decided to pack it into a mod right away. All credit goes to Agon, all I did was writing a manifest file: directional_light_mod.smod (3.2 KB)

Next step would be directional light changing with Sun/Moon position.


Add Some Texture to Blocks
#6

@BrunoSupremo
Thanks and thanks for the offered help! Maybe next time :smile:

@malley
You’re welcome! Looking forward to seeing what you come up with. :smile:
I have been thinking about recalculating the light direction to something like:

vec3 newLightDir = normalize(up + (-lightDir.xyz)); //Unnecessary “+” for clarity

To make sure that the ambient light always come from the sky. I haven’t tried it and it might feel weird if you look too closely at it, but it might be something to try in your implementation as well.
I’ve also thought about doing something like shade = shade^(1/x) to “curve it upwards” (if you think of the shade in a graph), to simulate that the light comes from an area instead of a single direction. I’m a little worried about performance with that one (root is no fun from what I’ve heard) but it’s hopefully ok.

@genboom
I actually haven’t tried to find if there is a real/common name for it. I don’t think I’ve heard about this sort of shading before. I think directional ambient works quite well though. :wink:

@Pawel_Malecki
That’s so cool! Thank you! Got to check it out when I get home. A good base to do future experiments with. :smiley:
The light should already change with the sun and moon, unless I missed something.


#7

Well, I didn’t notice it changing but it may be because of how light sources imitating celestials move right now, I started modding it to resemble the Earth annual cycle recently.


#8

is it this mod that sometimes causes some green thing around structures ect while moving the camera for alpha 22.5?


#9

I haven’t tried it on 22.5 but I don’t see why it would, unless it overrides some change in the alpha, leading to strange behaviors when it interacts with other new things.
It’s a small change and neither green nor around sounds like something it could do. :slight_smile:
Sounds fun though. Got a picture?


#10

Correction: I have tried it on 22.5. Thought you meant the unstable 23.
Thanks for the mention in your video! :smiley: Couldn’t see the green stuff though.


#11

i love this I’ve always had trouble seeing when the map was against the mountains and would resort to always being in the dig mode when looking at the mountains this will help a lot


#13

checked a few things and it’s totally unrelated to this mod, because i even saw it in a different game so probably graphics driver