shader_type spatial; render_mode diffuse_burley, specular_schlick_ggx; // Luneraria MOON WATER: the glowing water of the grotto channel and the light that fills the // depth of the cave mouth (G2). A dark, glossy surface with slow flowing ripples whose crests // carry the tint; `energy` is the state channel (bright when the grotto is awake, almost dark // when it is exhausted), `flicker` lets it stutter. uniform float flow_speed = .35; uniform float ripple_scale = 2.2; instance uniform vec4 tint : source_color, instance_index(4) = vec4(.7, .5, 1.0, 1.0); instance uniform float energy : instance_index(5) = 1.0; instance uniform float flicker : instance_index(6) = 0.0; instance uniform float fade : instance_index(1) = 0.0; instance uniform float fade_floor : instance_index(2) = 2.2; instance uniform float seed : instance_index(3) = 0.0; varying vec3 world_pos; varying vec3 local_pos; #include "res://scripts/luneraria/view/materials/lune_common.gdshaderinc" void vertex() { world_pos = (MODEL_MATRIX * vec4(VERTEX, 1.0)).xyz; local_pos = VERTEX; } void fragment() { if (PROJECTION_MATRIX[3][3] < .5 && faded(fade, fade_floor, world_pos.y, FRAGCOORD.xy)) discard; float t = TIME * flow_speed; vec3 p = local_pos * ripple_scale; float ripple = fbm3(p + vec3(t, t * .6, -t * .8) + seed); float crest = smoothstep(.55, .8, ripple); float live = energy; if (flicker > 0.0) live *= mix(1.0, .4 + .6 * step(.4, noise3(vec3(TIME * 2.3, seed, 1.0))), flicker); ALBEDO = tint.rgb * .04 + vec3(.02, .02, .03); ROUGHNESS = .08; METALLIC = 0.0; SPECULAR = .8; // Mostly dark water; only the moving crests catch the moonlight. EMISSION = tint.rgb * (.04 + crest * .7 + ripple * .06) * live; }