Skip to content

Commit

Permalink
new method to remove childen with free() instead of queue_free() and …
Browse files Browse the repository at this point in the history
…new shader to mix albedo textures on terrain
  • Loading branch information
ninetailsrabbit committed Oct 28, 2024
1 parent f684de4 commit 752f60c
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 6 deletions.
13 changes: 7 additions & 6 deletions icon.svg.import
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,26 @@
importer="texture"
type="CompressedTexture2D"
uid="uid://g1k1oqsoq1tp"
path="res://.godot/imported/icon.svg-218a8f2b3041327d8a5756f3a245f83b.ctex"
path.s3tc="res://.godot/imported/icon.svg-218a8f2b3041327d8a5756f3a245f83b.s3tc.ctex"
metadata={
"vram_texture": false
"imported_formats": ["s3tc_bptc"],
"vram_texture": true
}

[deps]

source_file="res://icon.svg"
dest_files=["res://.godot/imported/icon.svg-218a8f2b3041327d8a5756f3a245f83b.ctex"]
dest_files=["res://.godot/imported/icon.svg-218a8f2b3041327d8a5756f3a245f83b.s3tc.ctex"]

[params]

compress/mode=0
compress/mode=2
compress/high_quality=false
compress/lossy_quality=0.7
compress/hdr_compression=1
compress/normal_map=0
compress/channel_pack=0
mipmaps/generate=false
mipmaps/generate=true
mipmaps/limit=-1
roughness/mode=0
roughness/src_normal=""
Expand All @@ -31,7 +32,7 @@ process/normal_map_invert_y=false
process/hdr_as_srgb=false
process/hdr_clamp_exposure=false
process/size_limit=0
detect_3d/compress_to=1
detect_3d/compress_to=0
svg/scale=1.0
editor/scale_with_editor_scale=false
editor/convert_colors_with_editor_theme=false
38 changes: 38 additions & 0 deletions shaders/terrain/albedo_terrain_mix.gdshader
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// https://godotshaders.com/shader/albedo-terrain-mix-shader/
shader_type spatial;

uniform sampler2D source_texture_mask : source_color;
uniform sampler2D source_texture_black : source_color;
uniform sampler2D source_texture_red : source_color;
uniform sampler2D source_texture_green : source_color;
uniform sampler2D source_texture_blue : source_color;

uniform float uv_size : hint_range(0.01, 100.0, 0.01) = 1.0;

void fragment() {

vec2 UV_Scaled = UV * uv_size;

// texture_rgbmask UV is not scaled.
vec3 texture_rgbmask= texture(source_texture_mask, UV).rgb;
vec3 texture_black = texture(source_texture_black, UV_Scaled).rgb;
vec3 texture_red = texture(source_texture_red, UV_Scaled).rgb;
vec3 texture_green = texture(source_texture_green, UV_Scaled).rgb;
vec3 texture_blue = texture(source_texture_blue, UV_Scaled).rgb;

float summed_texture_channels = (
texture_rgbmask.r +
texture_rgbmask.g +
texture_rgbmask.b);

vec3 mixed_terrain = clamp(
( texture_rgbmask.r * texture_red +
texture_rgbmask.g * texture_green +
texture_rgbmask.b * texture_blue) /
summed_texture_channels,
vec3(0.0), vec3(1.0) // Clamp min, max values.
);

ALBEDO = mix(mixed_terrain,texture_black,1.0 - summed_texture_channels);

} // Fragment end
14 changes: 14 additions & 0 deletions utilities/nodes/node_remover.gd
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,17 @@ static func queue_free_children(node: Node, except: Array = []) -> void:
remove(child)

except.clear()


## Exceptions are passed as [Area3D.new().get_class)
static func free_children(node: Node, except: Array = []) -> void:
if node.get_child_count() == 0:
return

var childrens = node.get_children().filter(func(child): return not child.get_class() in except)
childrens.reverse()

for child in childrens.filter(func(_node: Node): return is_node_valid(_node)):
child.free()

except.clear()

0 comments on commit 752f60c

Please sign in to comment.