Implements tree visibility occlusion system.

Adds tree fading based on camera line of sight.
Trees now fade out when they obstruct the player's view,
improving visibility.

Also includes several fixes:
- Fixes tree distribution.
- Adds a see-through shader.
- Adds camera and occlusion scripts.
This commit is contained in:
Dan Baker 2025-07-01 10:32:21 +01:00
parent a1efaf6294
commit f98773237e
10 changed files with 314 additions and 137 deletions

41
see_through.gdshader Normal file
View file

@ -0,0 +1,41 @@
shader_type spatial;
// Uniforms that can be controlled from GDScript
uniform float model_height : hint_range(0.1, 100.0) = 10.0;
uniform float transition_width : hint_range(0.01, 0.5) = 0.1;
uniform vec4 base_color : source_color = vec4(1.0, 1.0, 1.0, 1.0);
uniform float effect_strength : hint_range(0.0, 1.0) = 1.0;
uniform sampler2D main_texture : source_color;
uniform float metallic : hint_range(0.0, 1.0) = 0.0;
uniform float roughness : hint_range(0.0, 1.0) = 0.5;
varying vec3 world_position;
void vertex() {
world_position = VERTEX;
}
void fragment() {
// Get the base texture color
vec4 tex_color = texture(main_texture, UV);
// Calculate normalized Y position (0.0 at bottom, 1.0 at top)
// This uses the local vertex position - adjust based on your model's bounds
float normalized_y = (world_position.y + model_height * 0.5) / model_height;
// Define fade boundaries - top 80% invisible, bottom 20% visible
float fade_start = 0.2; // Start fading at 20% from bottom
float fade_end = fade_start - transition_width;
// Calculate position-based alpha
float position_alpha = smoothstep(fade_end, fade_start, normalized_y);
// Blend between full visibility and position-based alpha based on effect strength
float final_alpha = mix(1.0, position_alpha, effect_strength);
// Set material properties
ALBEDO = base_color.rgb * tex_color.rgb;
ALPHA = base_color.a * tex_color.a * final_alpha;
METALLIC = metallic;
ROUGHNESS = roughness;
}