Got the basic sum of sines shader translated to buoyancy
This commit is contained in:
parent
09d1c37d9d
commit
e93af3f8f0
25
Materials/Water2.tres
Normal file
25
Materials/Water2.tres
Normal file
@ -0,0 +1,25 @@
|
||||
[gd_resource type="ShaderMaterial" load_steps=4 format=3 uid="uid://doo0lbnv6560s"]
|
||||
|
||||
[ext_resource type="Shader" path="res://Shaders/Water2.gdshader" id="1_qkwc8"]
|
||||
|
||||
[sub_resource type="FastNoiseLite" id="FastNoiseLite_qwrmt"]
|
||||
frequency = 0.0126
|
||||
fractal_type = 2
|
||||
|
||||
[sub_resource type="NoiseTexture2D" id="NoiseTexture2D_lju3n"]
|
||||
seamless = true
|
||||
noise = SubResource("FastNoiseLite_qwrmt")
|
||||
|
||||
[resource]
|
||||
render_priority = 0
|
||||
shader = ExtResource("1_qkwc8")
|
||||
shader_parameter/color = Vector3(0.05, 0.2, 0.4)
|
||||
shader_parameter/foamHeight = 0.58
|
||||
shader_parameter/speed = 1.355
|
||||
shader_parameter/amplitude = 0.085
|
||||
shader_parameter/frequency = 1.0
|
||||
shader_parameter/waveCount = 20
|
||||
shader_parameter/amplitudeScaleFactor = 0.835
|
||||
shader_parameter/frequencyScaleFactor = 1.145
|
||||
shader_parameter/dirs = PackedFloat32Array(0.981, -0.588, 0.035, -0.977, -0.809, -0.351, 0.989, -0.24, -0.192, 0.907, -0.479, 0.499, 0.388, -0.97, 0.882, -0.845, 0.246, -0.068, -0.41, -0.202, -0.914, 0.605, -0.618, 0.898, -0.615, -0.508, -0.223, -0.841, 0.396, -0.609, 0.746, 0.129, 0.724, 0.54, -0.936, 0.589, 0.874, -0.715, -0.353, 0.243)
|
||||
shader_parameter/foamTex = SubResource("NoiseTexture2D_lju3n")
|
@ -1,9 +1,11 @@
|
||||
[gd_scene load_steps=15 format=3 uid="uid://cvgligyy2psi8"]
|
||||
[gd_scene load_steps=17 format=3 uid="uid://cvgligyy2psi8"]
|
||||
|
||||
[ext_resource type="Material" uid="uid://b1f46mvfaphsh" path="res://Materials/Water.tres" id="1_p35v0"]
|
||||
[ext_resource type="Shader" path="res://Shaders/Water2.gdshader" id="2_07p2y"]
|
||||
[ext_resource type="Material" uid="uid://doo0lbnv6560s" path="res://Materials/Water2.tres" id="2_qhg81"]
|
||||
[ext_resource type="Texture2D" uid="uid://v6apgwie2maw" path="res://autumn_field_puresky_4k.exr" id="3_vl8or"]
|
||||
[ext_resource type="Script" path="res://Scripts/BuoyantBody.gd" id="4_f67eq"]
|
||||
[ext_resource type="Shader" path="res://Shaders/TimeTest.gdshader" id="5_25la2"]
|
||||
[ext_resource type="Script" path="res://Scripts/BadWaterShader.gd" id="5_ltuhf"]
|
||||
|
||||
[sub_resource type="PlaneMesh" id="PlaneMesh_gqyhx"]
|
||||
lightmap_size_hint = Vector2i(52, 52)
|
||||
@ -12,30 +14,8 @@ size = Vector2(10, 10)
|
||||
subdivide_width = 200
|
||||
subdivide_depth = 200
|
||||
|
||||
[sub_resource type="FastNoiseLite" id="FastNoiseLite_qwrmt"]
|
||||
frequency = 0.0126
|
||||
fractal_type = 2
|
||||
|
||||
[sub_resource type="NoiseTexture2D" id="NoiseTexture2D_lju3n"]
|
||||
seamless = true
|
||||
noise = SubResource("FastNoiseLite_qwrmt")
|
||||
|
||||
[sub_resource type="ShaderMaterial" id="ShaderMaterial_0tjqc"]
|
||||
render_priority = 0
|
||||
shader = ExtResource("2_07p2y")
|
||||
shader_parameter/color = Vector3(0.05, 0.2, 0.4)
|
||||
shader_parameter/foamHeight = 0.58
|
||||
shader_parameter/speed = 1.355
|
||||
shader_parameter/amplitude = 0.085
|
||||
shader_parameter/frequency = 1.0
|
||||
shader_parameter/waveCount = 20
|
||||
shader_parameter/amplitudeScaleFactor = 0.835
|
||||
shader_parameter/frequencyScaleFactor = 1.145
|
||||
shader_parameter/dirs = PackedFloat32Array(0.981, -0.588, 0.035, -0.977, -0.809, -0.351, 0.989, -0.24, -0.192, 0.907, -0.479, 0.499, 0.388, -0.97, 0.882, -0.845, 0.246, -0.068, -0.41, -0.202, -0.914, 0.605, -0.618, 0.898, -0.615, -0.508, -0.223, -0.841, 0.396, -0.609, 0.746, 0.129, 0.724, 0.54, -0.936, 0.589, 0.874, -0.715, -0.353, 0.243)
|
||||
shader_parameter/foamTex = SubResource("NoiseTexture2D_lju3n")
|
||||
|
||||
[sub_resource type="PlaneMesh" id="PlaneMesh_w7hsm"]
|
||||
material = SubResource("ShaderMaterial_0tjqc")
|
||||
material = ExtResource("2_qhg81")
|
||||
size = Vector2(50, 50)
|
||||
subdivide_width = 1000
|
||||
subdivide_depth = 1000
|
||||
@ -58,10 +38,24 @@ fog_light_color = Color(0.302729, 0.545879, 0.912975, 1)
|
||||
fog_density = 1.0
|
||||
volumetric_fog_emission = Color(0.427666, 0.607438, 0.994933, 1)
|
||||
|
||||
[sub_resource type="ShaderMaterial" id="ShaderMaterial_g1sji"]
|
||||
render_priority = 0
|
||||
shader = ExtResource("5_25la2")
|
||||
|
||||
[sub_resource type="BoxMesh" id="BoxMesh_ffhgb"]
|
||||
material = SubResource("ShaderMaterial_g1sji")
|
||||
|
||||
[sub_resource type="BoxShape3D" id="BoxShape3D_bt6if"]
|
||||
|
||||
[sub_resource type="PlaneMesh" id="PlaneMesh_wuatm"]
|
||||
size = Vector2(50, 50)
|
||||
subdivide_width = 20
|
||||
subdivide_depth = 20
|
||||
|
||||
[sub_resource type="StandardMaterial3D" id="StandardMaterial3D_84jie"]
|
||||
transparency = 1
|
||||
albedo_color = Color(0, 0.372549, 1, 0.6)
|
||||
|
||||
[node name="WaterPlane" type="Node3D"]
|
||||
|
||||
[node name="MeshInstance3D" type="MeshInstance3D" parent="."]
|
||||
@ -70,7 +64,6 @@ mesh = SubResource("PlaneMesh_gqyhx")
|
||||
|
||||
[node name="MeshInstance3D2" type="MeshInstance3D" parent="."]
|
||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0.400336, 0, 11.821)
|
||||
visible = false
|
||||
cast_shadow = 0
|
||||
mesh = SubResource("PlaneMesh_w7hsm")
|
||||
|
||||
@ -82,9 +75,18 @@ transform = Transform3D(-0.718151, 0, 0.695888, 0, 1, 0, -0.695888, 0, -0.718151
|
||||
fov = 70.0
|
||||
|
||||
[node name="RigidBody3D" type="RigidBody3D" parent="." node_paths=PackedStringArray("samplePoints")]
|
||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 15.105, 1.67, -3.79)
|
||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 12.0169, 1.67, -1.69189)
|
||||
linear_damp = 1.5
|
||||
angular_damp = 5.0
|
||||
script = ExtResource("4_f67eq")
|
||||
buoyancy = 3.0
|
||||
samplePoints = [NodePath("Node3D"), NodePath("Node3D2"), NodePath("Node3D3"), NodePath("Node3D4"), NodePath("Node3D5"), NodePath("Node3D6"), NodePath("Node3D7"), NodePath("Node3D8")]
|
||||
amplitude = 0.085
|
||||
speed = 1.355
|
||||
waveCount = 4
|
||||
amplitudeScaleFactor = 0.835
|
||||
frequencyScaleFactor = 1.145
|
||||
dirs = Array[Vector2]([Vector2(0.981, -0.588), Vector2(0.035, -0.977), Vector2(-0.809, -0.351), Vector2(0.989, -0.24)])
|
||||
|
||||
[node name="MeshInstance3D" type="MeshInstance3D" parent="RigidBody3D"]
|
||||
mesh = SubResource("BoxMesh_ffhgb")
|
||||
@ -115,3 +117,15 @@ transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -0.5, -0.5, -0.5)
|
||||
|
||||
[node name="Node3D8" type="Node3D" parent="RigidBody3D"]
|
||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0.5, -0.5, -0.5)
|
||||
|
||||
[node name="MeshInstance3D3" type="MeshInstance3D" parent="."]
|
||||
visible = false
|
||||
mesh = SubResource("PlaneMesh_wuatm")
|
||||
surface_material_override/0 = SubResource("StandardMaterial3D_84jie")
|
||||
script = ExtResource("5_ltuhf")
|
||||
amplitude = 0.085
|
||||
speed = 1.355
|
||||
waveCount = 1
|
||||
amplitudeScaleFactor = 0.85
|
||||
frequencyScaleFactor = 1.145
|
||||
dirs = Array[Vector2]([Vector2(0.981, -0.588)])
|
||||
|
46
Scripts/BadWaterShader.gd
Normal file
46
Scripts/BadWaterShader.gd
Normal file
@ -0,0 +1,46 @@
|
||||
extends MeshInstance3D
|
||||
|
||||
@export var amplitude: float = 1
|
||||
@export var frequency: float = 1
|
||||
@export var speed: float = 1
|
||||
@export var waveCount: int = 5
|
||||
@export var amplitudeScaleFactor: float = 0.82
|
||||
@export var frequencyScaleFactor: float = 1.18
|
||||
@export var dirs: Array[Vector2]
|
||||
|
||||
func TIME() -> float:
|
||||
return fmod(float(Time.get_ticks_msec()) / 1000, 3600)
|
||||
|
||||
func getSumEHeight(x: float, y: float) -> float:
|
||||
var amp: float = 1
|
||||
var freq: float = 1
|
||||
var offset: float = 0
|
||||
for i: int in range(waveCount):
|
||||
offset += amplitude * amp * pow(exp(1), sin(frequency * freq * (speed * TIME() + (dirs[i].x * x) + (dirs[i].y * y))))
|
||||
amp *= amplitudeScaleFactor
|
||||
freq *= frequencyScaleFactor
|
||||
return offset
|
||||
|
||||
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
||||
func _process(delta: float) -> void:
|
||||
if (!visible): return
|
||||
var plane: PlaneMesh = PlaneMesh.new()
|
||||
plane.size = Vector2(50, 50)
|
||||
plane.subdivide_depth = 50
|
||||
plane.subdivide_width = 50
|
||||
var msh: ArrayMesh = ArrayMesh.new()
|
||||
msh.add_surface_from_arrays(Mesh.PRIMITIVE_TRIANGLES, plane.get_mesh_arrays())
|
||||
|
||||
var mdt: MeshDataTool = MeshDataTool.new()
|
||||
mdt.create_from_surface(msh, 0)
|
||||
for i: int in range(mdt.get_vertex_count()):
|
||||
var vertex: Vector3 = mdt.get_vertex(i)
|
||||
vertex.y = getSumEHeight(global_position.x + vertex.x, global_position.z + vertex.z)
|
||||
var b: Vector3 = Vector3(global_position.x + vertex.x + 0.01, getSumEHeight(global_position.x + vertex.x + 0.01, global_position.z + vertex.z), global_position.z + vertex.z)
|
||||
var c: Vector3 = Vector3(global_position.x + vertex.x, getSumEHeight(global_position.x + vertex.x, global_position.z + vertex.z + 0.01), global_position.z + vertex.z + 0.01)
|
||||
var normal: Vector3 = (c - vertex).cross(b - vertex).normalized()
|
||||
mdt.set_vertex(i, vertex)
|
||||
mdt.set_vertex_normal(i, normal)
|
||||
msh.clear_surfaces()
|
||||
mdt.commit_to_surface(msh)
|
||||
mesh = msh
|
@ -5,10 +5,30 @@ enum WaveType{
|
||||
SUM_G
|
||||
}
|
||||
|
||||
@export var buoyancy: float = 1
|
||||
@export var samplePoints: Array[Node3D]
|
||||
|
||||
@export_category("E^Sin Configuration")
|
||||
@export var amplitude: float = 1
|
||||
@export var frequency: float = 1
|
||||
@export var speed: float = 1
|
||||
@export var waveCount: int = 5
|
||||
@export var amplitudeScaleFactor: float = 0.82
|
||||
@export var frequencyScaleFactor: float = 1.18
|
||||
@export var dirs: Array[Vector2]
|
||||
|
||||
func TIME() -> float:
|
||||
return fmod(float(Time.get_ticks_msec()) / 1000, 3600)
|
||||
|
||||
func getSumEHeight(x: float, y: float) -> float:
|
||||
return 0
|
||||
var amp: float = 1
|
||||
var freq: float = 1
|
||||
var offset: float = 0
|
||||
for i: int in range(waveCount):
|
||||
offset += amplitude * amp * pow(exp(1), sin(frequency * freq * (speed * TIME() + (dirs[i].x * x) + (dirs[i].y * y))))
|
||||
amp *= amplitudeScaleFactor
|
||||
freq *= frequencyScaleFactor
|
||||
return offset
|
||||
|
||||
func getSumGHeight(x: float, y: float) -> float:
|
||||
return 0
|
||||
@ -18,4 +38,7 @@ func _ready() -> void:
|
||||
pass # Replace with function body.
|
||||
|
||||
func _physics_process(delta: float) -> void:
|
||||
pass
|
||||
for i: int in range(samplePoints.size()):
|
||||
var distance: float = clampf(getSumEHeight(samplePoints[i].global_position.x, samplePoints[i].global_position.z) - samplePoints[i].global_position.y, 0, 1);
|
||||
if (distance > 0):
|
||||
apply_force(abs(get_gravity()) * distance, samplePoints[i].position)
|
||||
|
16
Shaders/TimeTest.gdshader
Normal file
16
Shaders/TimeTest.gdshader
Normal file
@ -0,0 +1,16 @@
|
||||
shader_type spatial;
|
||||
|
||||
void fragment() {
|
||||
if (TIME < 0.5){
|
||||
ALBEDO = vec3(0.0, 0.0, 0.0);
|
||||
}else if (TIME >= 0.5 && TIME <= 1.0){
|
||||
ALBEDO = vec3(0.5, 0.5, 0.5);
|
||||
}else if (TIME > 1.0){
|
||||
ALBEDO = vec3(1.0, 0.0, 0.0);
|
||||
}
|
||||
}
|
||||
|
||||
//void light() {
|
||||
// Called for every pixel for every light affecting the material.
|
||||
// Uncomment to replace the default light processing function with this one.
|
||||
//}
|
Loading…
x
Reference in New Issue
Block a user