some diffuse added for funzies
This commit is contained in:
@@ -1,8 +1,17 @@
|
|||||||
shader_type canvas_item;
|
shader_type canvas_item;
|
||||||
|
|
||||||
|
// Snippets of code drawn from https://gist.github.com/Bleuje/1e497df4505ca24c39ab3930a95700b3
|
||||||
|
|
||||||
uniform sampler2D sim_texture;
|
uniform sampler2D sim_texture;
|
||||||
|
|
||||||
void fragment() {
|
float gn(in vec2 coordinate, in float seed){
|
||||||
vec3 c = texture(sim_texture, UV).rgb;
|
return fract(tan(distance(coordinate*(seed+0.118446744073709551614), vec2(0.118446744073709551614, 0.314159265358979323846264)))*0.141421356237309504880169);
|
||||||
COLOR = vec4(c, 1.0);
|
}
|
||||||
|
|
||||||
|
void fragment() {
|
||||||
|
vec3 orig = texture(sim_texture, UV).rgb;
|
||||||
|
float agent = orig.r;
|
||||||
|
float trail = orig.g;
|
||||||
|
|
||||||
|
COLOR = vec4(agent, trail, orig.b, 1.0);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,7 +5,16 @@ uniform sampler2D sim_texture;
|
|||||||
uniform float decay_factor;
|
uniform float decay_factor;
|
||||||
|
|
||||||
void fragment() {
|
void fragment() {
|
||||||
float c = texture(sim_texture, UV).r;
|
vec3 orig = texture(sim_texture, UV).rgb;
|
||||||
c = c * decay_factor;
|
float trail = texture(sim_texture, UV).g;
|
||||||
COLOR = vec4(c, c, c, 1.0);
|
|
||||||
|
float sum = 0.0;
|
||||||
|
for(int i=-1;i<=1;i++) {
|
||||||
|
for(int j=-1;j<=1;j++) {
|
||||||
|
sum += texture(sim_texture, UV).g;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
trail = sum / 9.0;
|
||||||
|
trail = trail * decay_factor;
|
||||||
|
COLOR = vec4(orig.r, trail, orig.b, 1.0);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,8 +12,8 @@ extends Node2D
|
|||||||
@onready var trail_shader: ShaderMaterial = $SubViewport2/Pass.material
|
@onready var trail_shader: ShaderMaterial = $SubViewport2/Pass.material
|
||||||
|
|
||||||
const MAX_TEXTURES: int = 2
|
const MAX_TEXTURES: int = 2
|
||||||
var next_texture: int = 0
|
var _next_texture: int = 0
|
||||||
var frame_count: int = 0
|
var _frame_count: int = 0
|
||||||
|
|
||||||
|
|
||||||
func _ready():
|
func _ready():
|
||||||
@@ -21,12 +21,12 @@ func _ready():
|
|||||||
|
|
||||||
|
|
||||||
func _process(_delta: float) -> void:
|
func _process(_delta: float) -> void:
|
||||||
next_texture = (next_texture + 1) % MAX_TEXTURES
|
_next_texture = (_next_texture + 1) % MAX_TEXTURES
|
||||||
RenderingServer.call_on_render_thread(
|
RenderingServer.call_on_render_thread(
|
||||||
_render_process.bind(next_texture, frame_count, decay_factor)
|
_render_process.bind(_next_texture, _frame_count, decay_factor)
|
||||||
)
|
)
|
||||||
|
|
||||||
frame_count = frame_count + 1
|
_frame_count = _frame_count + 1
|
||||||
|
|
||||||
|
|
||||||
# Below is for rendering
|
# Below is for rendering
|
||||||
@@ -42,14 +42,14 @@ func _create_initial_sim_texture(width: int, height: int) -> ImageTexture:
|
|||||||
return sim_texture
|
return sim_texture
|
||||||
|
|
||||||
|
|
||||||
func _initialize_render(width: int, height: int) -> void:
|
func _initialize_render(_width: int, _height: int) -> void:
|
||||||
rd = RenderingServer.get_rendering_device()
|
rd = RenderingServer.get_rendering_device()
|
||||||
|
|
||||||
trail_shader.set_shader_parameter("sim_texture", pass_viewport.get_texture().get_rid())
|
trail_shader.set_shader_parameter("sim_texture", pass_viewport.get_texture().get_rid())
|
||||||
trail_shader.set_shader_parameter("decay_factor", decay_factor)
|
trail_shader.set_shader_parameter("decay_factor", decay_factor)
|
||||||
|
|
||||||
|
|
||||||
func _render_process(next_texture: int, frame_count: int, decay_factor: float) -> void:
|
func _render_process(__next_texture: int, frame_count: int, decay_factor: float) -> void:
|
||||||
if frame_count > 0:
|
if frame_count > 0:
|
||||||
agent_shader.set_shader_parameter("sim_texture", pass2_viewport.get_texture().get_rid())
|
agent_shader.set_shader_parameter("sim_texture", pass2_viewport.get_texture().get_rid())
|
||||||
|
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ size = Vector2(1920, 1080)
|
|||||||
[sub_resource type="ShaderMaterial" id="ShaderMaterial_g2c28"]
|
[sub_resource type="ShaderMaterial" id="ShaderMaterial_g2c28"]
|
||||||
shader = ExtResource("3_s6nlv")
|
shader = ExtResource("3_s6nlv")
|
||||||
shader_parameter/sim_texture = SubResource("Texture2DRD_s6nlv")
|
shader_parameter/sim_texture = SubResource("Texture2DRD_s6nlv")
|
||||||
shader_parameter/decay_factor = 0.95
|
shader_parameter/decay_factor = 0.99
|
||||||
|
|
||||||
[node name="SlimeSimulation" type="Node2D"]
|
[node name="SlimeSimulation" type="Node2D"]
|
||||||
script = ExtResource("1_s6nlv")
|
script = ExtResource("1_s6nlv")
|
||||||
|
|||||||
Reference in New Issue
Block a user