techkaczynski.dev / code

summaryrefslogtreecommitdiff
path: root/res/sdr/mdl_foliage.vs
diff options
context:
space:
mode:
Diffstat (limited to 'res/sdr/mdl_foliage.vs')
-rw-r--r--res/sdr/mdl_foliage.vs23
1 files changed, 12 insertions, 11 deletions
diff --git a/res/sdr/mdl_foliage.vs b/res/sdr/mdl_foliage.vs
index 1198009..366290a 100644
--- a/res/sdr/mdl_foliage.vs
+++ b/res/sdr/mdl_foliage.vs
@@ -27,20 +27,21 @@ out vec4 frag_colour;
out vec3 frag_lighting;
void main() {
- vec3 world_normal = normalize((matNormal * vec4(vertexNormal, 0.0)).xyz);
+ vec3 canopy_center = vec3(0.0, 4.0, 0.0);
+ vec3 canopy_normal = vertexNormal;
+ vec3 offset = vertexPosition - canopy_center;
- // float sun_diffuse = abs(dot(world_normal, sun_direction));
- // float moon_diffuse = abs(dot(world_normal, moon_direction));
+ if (dot(offset, offset) > 0.0001) {
+ canopy_normal = normalize(offset);
+ }
- // for stronger shading, use 0.3 + 0.7 * abs(...)
- // float sun_diffuse = 0.5 + 0.5 * abs(dot(world_normal, sun_direction));
- // float moon_diffuse = 0.5 + 0.5 * abs(dot(world_normal, moon_direction));
- float sun_diffuse = abs(dot(world_normal, sun_direction));
- float moon_diffuse = abs(dot(world_normal, moon_direction));
+ vec3 world_normal = normalize((matNormal * vec4(canopy_normal, 0.0)).xyz);
- // hack to fix lighting at midday
- float midday = smoothstep(0.7, 1.0, sun_direction.y);
- sun_diffuse = mix(sun_diffuse, 0.65, midday);
+ float sun_facing = dot(world_normal, sun_direction);
+ float moon_facing = dot(world_normal, moon_direction);
+
+ float sun_diffuse = max(sun_facing, 0.0) + 0.1 * max(-sun_facing, 0.0);
+ float moon_diffuse = max(moon_facing, 0.0) + 0.1 * max(-moon_facing, 0.0);
vec3 ambient_light = ambient_colour * ambient_intensity;
vec3 sun_light = sun_colour * sun_intensity * sun_diffuse;