shader_type spatial; render_mode cull_back, diffuse_burley; // Tree canopies and bushes. Colour comes from per-face vertex colours (set by // proc_mesh.gd), tinted per instance so no two trees are quite the same. // Wind: slow whole-crown sway growing with height, plus a small leaf flutter. #include "res://shaders/common.gdshaderinc" uniform float wind_strength = 0.04; uniform float flutter = 0.03; varying vec3 inst_pos; void vertex() { inst_pos = MODEL_MATRIX[3].xyz; float h = max(VERTEX.y - 1.2, 0.0); float phase = dot(inst_pos.xz, vec2(0.13, 0.17)); float gust = nz(inst_pos.xz * 0.012 + vec2(TIME * 0.02, TIME * 0.013)); vec3 sway = vec3(sin(TIME * 0.9 + phase), 0.0, cos(TIME * 0.7 + phase * 1.3) * 0.6); float wk = min(weather_wind, 2.2); // storms bend crowns, but not into the ground sway *= wind_strength * wk * h * (0.4 + gust); sway += vec3(sin(TIME * 3.7 * (0.7 + 0.3 * wk) + dot(VERTEX, vec3(3.1, 1.7, 2.3)) + phase)) * flutter * wk * clamp(VERTEX.y, 0.0, 1.0); VERTEX += (inverse(MODEL_MATRIX) * vec4(sway, 0.0)).xyz; } void fragment() { float v = nz(inst_pos.xz * 0.045); vec3 tint = mix(vec3(0.88, 1.0, 0.85), vec3(1.12, 1.04, 0.78), v); vec3 col = to_linear(COLOR.rgb) * tint; // Snow on the upper faces of the crowns. float up = (INV_VIEW_MATRIX * vec4(NORMAL, 0.0)).y; col = mix(col, vec3(0.86, 0.89, 0.93), snow_mask(up, v) * 0.9); col = wet_albedo(col, weather_wet * 0.5); ALBEDO = col; ROUGHNESS = 0.85; SPECULAR = 0.3; BACKLIGHT = col * 0.5; // light glowing through leaves when backlit }