-
-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use viewport for fluid rendering instead of mask color 💦 (#78)
Marking as draft at the moment since the camera is broken. --------- Co-authored-by: Dragos Daian <daian.dragos@yahoo.com>
- Loading branch information
1 parent
530831c
commit 4314293
Showing
7 changed files
with
129 additions
and
99 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,20 @@ | ||
class_name Fluid2DRenderer | ||
extends MultiMeshInstance2D | ||
|
||
@onready var fluid :Fluid2D = get_parent() | ||
@export var fluid: Fluid2D | ||
@export var color: Color | ||
|
||
func _ready(): | ||
multimesh = multimesh.duplicate(true) | ||
|
||
func _process(_delta): | ||
global_position = fluid.global_position | ||
var index = 0 | ||
multimesh.instance_count = fluid.points.size() | ||
var points = fluid.points | ||
var create_times = fluid.get_create_times() | ||
var current_time = Time.get_ticks_msec() | ||
for i in points.size(): | ||
var point = points[i] | ||
var created_at = create_times[i] | ||
var new_transform: Transform2D = Transform2D() | ||
new_transform.origin = point - position | ||
var new_transform: Transform2D = Transform2D(0, Vector2(5, 5), 0, point) | ||
multimesh.set_instance_transform_2d(index, new_transform) | ||
multimesh.set_instance_color(index, color) | ||
index += 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
extends CanvasLayer | ||
|
||
@export var camera: Camera2D | ||
@export var fluid: Fluid2D | ||
@export var water_material: Material = load("res://samples/godot-rapier2d/water_shader.tres") | ||
@onready var fluid_renderer: Fluid2DRenderer = $SubViewportContainer/SubViewport/Fluid2DRenderer | ||
@onready var inside_camera: Camera2D = $SubViewportContainer/SubViewport/Camera2D | ||
@onready var subviewport_container = $SubViewportContainer | ||
|
||
func _ready() -> void: | ||
inside_camera.offset = camera.offset | ||
inside_camera.zoom = camera.zoom | ||
inside_camera.transform = camera.transform | ||
fluid_renderer.fluid = fluid | ||
subviewport_container.material = water_material |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
[gd_scene load_steps=6 format=3 uid="uid://chujsborpvqgu"] | ||
|
||
[ext_resource type="Script" path="res://samples/godot-rapier2d/Fluid2DShaderRenderer.gd" id="1_fcfg8"] | ||
[ext_resource type="Material" uid="uid://clnmfvqslf2ka" path="res://samples/godot-rapier2d/water_shader.tres" id="2_onxbk"] | ||
[ext_resource type="MultiMesh" uid="uid://d0bhettx43xt1" path="res://samples/godot-rapier2d/fluid_multi_mesh.tres" id="3_hgekb"] | ||
[ext_resource type="Texture2D" uid="uid://cho3shol3rky2" path="res://samples/godot-rapier2d/Radial2D.svg" id="4_rnpc1"] | ||
[ext_resource type="Script" path="res://samples/godot-rapier2d/Fluid2DRenderer.gd" id="5_q35nb"] | ||
|
||
[node name="Fluid2DShader" type="CanvasLayer" node_paths=PackedStringArray("camera", "fluid")] | ||
script = ExtResource("1_fcfg8") | ||
camera = NodePath("") | ||
fluid = NodePath("") | ||
water_material = ExtResource("2_onxbk") | ||
|
||
[node name="SubViewportContainer" type="SubViewportContainer" parent="."] | ||
material = ExtResource("2_onxbk") | ||
anchors_preset = 15 | ||
anchor_right = 1.0 | ||
anchor_bottom = 1.0 | ||
grow_horizontal = 2 | ||
grow_vertical = 2 | ||
stretch = true | ||
|
||
[node name="SubViewport" type="SubViewport" parent="SubViewportContainer"] | ||
disable_3d = true | ||
transparent_bg = true | ||
handle_input_locally = false | ||
size = Vector2i(1920, 1080) | ||
render_target_update_mode = 4 | ||
|
||
[node name="Fluid2DRenderer" type="MultiMeshInstance2D" parent="SubViewportContainer/SubViewport" node_paths=PackedStringArray("fluid")] | ||
multimesh = ExtResource("3_hgekb") | ||
texture = ExtResource("4_rnpc1") | ||
script = ExtResource("5_q35nb") | ||
fluid = NodePath("") | ||
color = Color(1, 1, 1, 1) | ||
|
||
[node name="Camera2D" type="Camera2D" parent="SubViewportContainer/SubViewport"] | ||
position = Vector2(521, 1448) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,24 @@ | ||
[gd_resource type="ShaderMaterial" load_steps=2 format=3 uid="uid://clnmfvqslf2ka"] | ||
[gd_resource type="ShaderMaterial" load_steps=4 format=3 uid="uid://clnmfvqslf2ka"] | ||
|
||
[ext_resource type="Shader" path="res://samples/godot-rapier2d/water_shader.gdshader" id="1_idpys"] | ||
|
||
[sub_resource type="FastNoiseLite" id="FastNoiseLite_y42gw"] | ||
noise_type = 2 | ||
frequency = 0.0182 | ||
domain_warp_enabled = true | ||
domain_warp_type = 1 | ||
|
||
[sub_resource type="NoiseTexture2D" id="NoiseTexture2D_4as7b"] | ||
generate_mipmaps = false | ||
seamless = true | ||
noise = SubResource("FastNoiseLite_y42gw") | ||
|
||
[resource] | ||
resource_local_to_scene = true | ||
shader = ExtResource("1_idpys") | ||
shader_parameter/threshold = 0.83 | ||
shader_parameter/water_color = Color(0, 1, 1, 1) | ||
shader_parameter/threshold = 0.6 | ||
shader_parameter/water_color = Color(0.662745, 0.396078, 0.235294, 0.803922) | ||
shader_parameter/test_color = Color(1, 0, 1, 1) | ||
shader_parameter/speed = 0.1 | ||
shader_parameter/amplitude = 0.1 | ||
shader_parameter/water_texture = SubResource("NoiseTexture2D_4as7b") |