Adding procedural textures to the ground

This commit is contained in:
Zacharie Guet 2024-09-01 15:30:51 +02:00
parent f9e1a56615
commit e0293db640
14 changed files with 259 additions and 17 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.2 MiB

BIN
assets/texture/sky.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 373 B

View File

@ -2,16 +2,16 @@
importer="texture"
type="CompressedTexture2D"
uid="uid://dtvde6oxrfuk1"
path="res://.godot/imported/ground.jpg-2eec989771def1cab2ea361da548425a.ctex"
uid="uid://c84bc7d0f8gtn"
path="res://.godot/imported/sky.png-797942cf14c3d3c2fe0d423f60874e07.ctex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://assets/texture/ground.jpg"
dest_files=["res://.godot/imported/ground.jpg-2eec989771def1cab2ea361da548425a.ctex"]
source_file="res://assets/texture/sky.png"
dest_files=["res://.godot/imported/sky.png-797942cf14c3d3c2fe0d423f60874e07.ctex"]
[params]
@ -21,7 +21,7 @@ compress/lossy_quality=0.7
compress/hdr_compression=1
compress/normal_map=0
compress/channel_pack=0
mipmaps/generate=true
mipmaps/generate=false
mipmaps/limit=-1
roughness/mode=0
roughness/src_normal=""

Binary file not shown.

After

Width:  |  Height:  |  Size: 1006 KiB

View File

@ -0,0 +1,34 @@
[remap]
importer="texture"
type="CompressedTexture2D"
uid="uid://bkwi6yurko7gm"
path="res://.godot/imported/sol_gamejam_fleurs.png-6738458a238310dbe8f60c5cf63411e2.ctex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://assets/texture/sol_gamejam_fleurs.png"
dest_files=["res://.godot/imported/sol_gamejam_fleurs.png-6738458a238310dbe8f60c5cf63411e2.ctex"]
[params]
compress/mode=0
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/limit=-1
roughness/mode=0
roughness/src_normal=""
process/fix_alpha_border=true
process/premult_alpha=false
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

Binary file not shown.

After

Width:  |  Height:  |  Size: 752 KiB

View File

@ -0,0 +1,34 @@
[remap]
importer="texture"
type="CompressedTexture2D"
uid="uid://6h5ieh6ba7re"
path="res://.godot/imported/sol_gamejam_mort.png-7c2094d2cb902ffcfaa9567b3e7302ae.ctex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://assets/texture/sol_gamejam_mort.png"
dest_files=["res://.godot/imported/sol_gamejam_mort.png-7c2094d2cb902ffcfaa9567b3e7302ae.ctex"]
[params]
compress/mode=0
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/limit=-1
roughness/mode=0
roughness/src_normal=""
process/fix_alpha_border=true
process/premult_alpha=false
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

Binary file not shown.

After

Width:  |  Height:  |  Size: 114 KiB

View File

@ -0,0 +1,34 @@
[remap]
importer="texture"
type="CompressedTexture2D"
uid="uid://c85s1vwryvngb"
path="res://.godot/imported/sol_gamejam_normal.png-1de8f8345ab1c6fba1ed806c59d2001e.ctex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://assets/texture/sol_gamejam_normal.png"
dest_files=["res://.godot/imported/sol_gamejam_normal.png-1de8f8345ab1c6fba1ed806c59d2001e.ctex"]
[params]
compress/mode=0
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/limit=-1
roughness/mode=0
roughness/src_normal=""
process/fix_alpha_border=true
process/premult_alpha=false
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

View File

@ -1,21 +1,72 @@
[gd_scene load_steps=5 format=3 uid="uid://d3hul8b7hlmj7"]
[gd_scene load_steps=14 format=3 uid="uid://d3hul8b7hlmj7"]
[ext_resource type="Script" path="res://scripts/map.gd" id="1_3np0o"]
[ext_resource type="PackedScene" uid="uid://6ferubyu2uy1" path="res://scenes/Scanners.tscn" id="1_6mlj0"]
[ext_resource type="Texture2D" uid="uid://dtvde6oxrfuk1" path="res://assets/texture/ground.jpg" id="3_20ci8"]
[ext_resource type="PackedScene" uid="uid://cj457q2fx5mim" path="res://objects/Animal.tscn" id="4_pkphc"]
[ext_resource type="PackedScene" path="res://objects/Animal.tscn" id="4_pkphc"]
[ext_resource type="Texture2D" uid="uid://c84bc7d0f8gtn" path="res://assets/texture/sky.png" id="4_uy8vn"]
[ext_resource type="Texture2D" uid="uid://bkwi6yurko7gm" path="res://assets/texture/sol_gamejam_fleurs.png" id="5_6sl35"]
[ext_resource type="Shader" path="res://scripts/shaders/TextureSplit.gdshader" id="5_iqvbx"]
[ext_resource type="Texture2D" uid="uid://6h5ieh6ba7re" path="res://assets/texture/sol_gamejam_mort.png" id="6_wj5l3"]
[ext_resource type="Texture2D" uid="uid://c85s1vwryvngb" path="res://assets/texture/sol_gamejam_normal.png" id="7_iuq0o"]
[sub_resource type="ShaderMaterial" id="ShaderMaterial_h3thu"]
shader = ExtResource("5_iqvbx")
shader_parameter/data_texture_size = null
shader_parameter/texture_low_threshold = 0.3
shader_parameter/texture_high_threshold = 0.7
shader_parameter/dimension = null
shader_parameter/texture_size = Vector2(384, 216)
shader_parameter/smooth_change_range = 0.15
shader_parameter/texture_low = ExtResource("6_wj5l3")
shader_parameter/texture_medium = ExtResource("7_iuq0o")
shader_parameter/texture_high = ExtResource("5_6sl35")
[sub_resource type="CompressedTexture2D" id="CompressedTexture2D_rhtup"]
load_path = "res://.godot/imported/normal.png-c44c610586e914477a8ee139158bfa7e.ctex"
[sub_resource type="Gradient" id="Gradient_u5wcm"]
offsets = PackedFloat32Array(1)
colors = PackedColorArray(0.481789, 0.481789, 0.481789, 0)
[sub_resource type="GradientTexture1D" id="GradientTexture1D_hwe6p"]
gradient = SubResource("Gradient_u5wcm")
[sub_resource type="ShaderMaterial" id="ShaderMaterial_4rqj7"]
shader = ExtResource("5_iqvbx")
shader_parameter/data_texture_size = Vector2(1000, 1000)
shader_parameter/texture_low_threshold = 0.3
shader_parameter/texture_high_threshold = 0.711
shader_parameter/dimension = 1
shader_parameter/texture_size = Vector2(100, 100)
shader_parameter/smooth_change_range = 0.0
shader_parameter/texture_medium = SubResource("GradientTexture1D_hwe6p")
[node name="Map" type="Node2D"]
script = ExtResource("1_3np0o")
[node name="Scanners" parent="." instance=ExtResource("1_6mlj0")]
[node name="OutOfBound" type="Polygon2D" parent="."]
z_index = -3
texture_repeat = 2
texture = ExtResource("4_uy8vn")
texture_scale = Vector2(5, 5)
[node name="Ground" type="Polygon2D" parent="."]
z_index = -2
texture_repeat = 2
material = SubResource("ShaderMaterial_h3thu")
texture = SubResource("CompressedTexture2D_rhtup")
texture_scale = Vector2(5, 5)
[node name="Fertility" type="Polygon2D" parent="."]
visible = false
z_index = -1
texture_repeat = 2
texture = ExtResource("3_20ci8")
material = SubResource("ShaderMaterial_4rqj7")
color = Color(1, 1, 1, 0)
texture_scale = Vector2(5, 5)
polygon = PackedVector2Array(571, 76, 228, 282, 987, 657, 1379, 208)
polygon = PackedVector2Array(27, 788, 54, 1452, 1715, 1163, 1439, -501, -416, -340)
[node name="Animals" type="Node" parent="."]

View File

@ -16,7 +16,6 @@ func _process(delta):
if Input.is_action_pressed("grab"):
var grabbing_movement = mouse_last_global_position - get_global_mouse_position()
print(grabbing_movement)
movement += grabbing_movement
var mouse_pos = get_viewport().get_mouse_position()

View File

@ -2,16 +2,31 @@ class_name Map
extends Node2D
const OUT_OF_BOUND_DIST = 2000
@export var n_animals_to_liberate := 4
func _ready():
var map_size = GameTerrain.TERRAIN_SIZE * GameTerrain.MAP_RATIO
$Ground.set_polygon(PackedVector2Array([
Vector2(0,0),
Vector2(map_size.x, 0),
Vector2(map_size.x, map_size.y),
Vector2(0, map_size.y),
for polygon in [$Ground, $Fertility]:
polygon.set_polygon(PackedVector2Array([
Vector2(0,0),
Vector2(map_size.x, 0),
Vector2(map_size.x, map_size.y),
Vector2(0, map_size.y),
]))
polygon.material.set_shader_parameter("data_texture", GameTerrain.texture)
polygon.material.set_shader_parameter(
"data_texture_size",
GameTerrain.TERRAIN_SIZE * GameTerrain.MAP_RATIO
)
$OutOfBound.set_polygon(PackedVector2Array([
Vector2(-OUT_OF_BOUND_DIST,-OUT_OF_BOUND_DIST),
Vector2(map_size.x + OUT_OF_BOUND_DIST, -OUT_OF_BOUND_DIST),
Vector2(map_size.x + OUT_OF_BOUND_DIST, map_size.y + OUT_OF_BOUND_DIST),
Vector2(-OUT_OF_BOUND_DIST, map_size.y + OUT_OF_BOUND_DIST),
]))
func _on_gui_scanner_selected(type : Scanners.Type):

View File

@ -0,0 +1,57 @@
shader_type canvas_item;
#define pow2(x) (x * x)
#define iResolution 1.0/SCREEN_PIXEL_SIZE
uniform sampler2D data_texture;
uniform vec2 data_texture_size;
uniform sampler2D texture_low : filter_nearest, repeat_enable;
uniform float texture_low_threshold : hint_range(0, 1) = 0.3;
uniform sampler2D texture_medium : filter_nearest, repeat_enable;
uniform sampler2D texture_high : filter_nearest, repeat_enable;
uniform float texture_high_threshold : hint_range(0, 1) = 0.7;
uniform int dimension;
uniform vec2 texture_size = vec2(100,100);
uniform float smooth_change_range = 0.15;
varying vec2 vert;
void vertex() {
vert = VERTEX;
}
void fragment() {
vec4 pixel_color = texture(data_texture, vert/data_texture_size);
float value = pixel_color.x;
if (dimension == 1) value = pixel_color.y;
if (dimension == 2) value = pixel_color.z;
vec4 color = texture(texture_medium, vert/texture_size);
if (value < texture_low_threshold)
color =
min(
(texture_low_threshold - value) / smooth_change_range,
1.0
) * texture(texture_low, vert/texture_size)
+ (1.0 - min(
(texture_low_threshold - value) / smooth_change_range,
1.0
)
) * texture(texture_medium, vert/texture_size);
if (value > texture_high_threshold)
color =
min(
(value - texture_high_threshold) / smooth_change_range,
1.0
) * texture(texture_high, vert/texture_size)
+ (1.0 - min(
(value - texture_high_threshold) / smooth_change_range,
1.0
)
) * texture(texture_medium, vert/texture_size);
COLOR = color;
}

View File

@ -151,11 +151,29 @@ func get_stat(
func setup_texture(
levels : Vector3i
):
var water_noise := generate_noise()
var fertility_noise := generate_noise()
for x in range(0, TERRAIN_SIZE.x) :
for y in range(0, TERRAIN_SIZE.y):
set_pixel(Vector2i(x,y), levels)
set_pixel(
Vector2i(x,y),
Vector3i(
color_value_to_level(water_noise.get_noise_2d(x, y)),
color_value_to_level(fertility_noise.get_noise_2d(x, y)/2),
-5
)
)
update_texture()
func generate_noise() -> Noise:
var noise := FastNoiseLite.new()
noise.seed = randi()
noise.fractal_lacunarity = 1
noise.frequency = 0.005
return noise
func update_texture():
texture.update(image)