diff --git a/src/dev-util/particles_tester.tscn b/src/dev-util/particles_tester.tscn index cf94427..0f81ae5 100644 --- a/src/dev-util/particles_tester.tscn +++ b/src/dev-util/particles_tester.tscn @@ -1,134 +1,8 @@ -[gd_scene load_steps=14 format=3 uid="uid://bj3tbkmppabfq"] +[gd_scene load_steps=5 format=3 uid="uid://bj3tbkmppabfq"] -[ext_resource type="Shader" path="res://vfx/particle_mixer.gdshader" id="1_g8u1t"] +[ext_resource type="PackedScene" uid="uid://bdnesuqroi7ss" path="res://vfx/collectable_particles.tscn" id="1_7bqxo"] [ext_resource type="Texture2D" uid="uid://dq7jm5ufknbb6" path="res://vfx/lens-flare-particle.png" id="2_mi0wa"] -[sub_resource type="ShaderMaterial" id="ShaderMaterial_lpenh"] -render_priority = 0 -shader = ExtResource("1_g8u1t") -shader_parameter/particle_color = null -shader_parameter/particle_texture = ExtResource("2_mi0wa") - -[sub_resource type="Gradient" id="Gradient_tjuvm"] -offsets = PackedFloat32Array(0, 0.50813, 1) -colors = PackedColorArray(1, 0.877403, 0.516545, 1, 0.94702, 0.505309, 0.59484, 1, 0.735853, 0.324231, 0.687053, 1) - -[sub_resource type="GradientTexture1D" id="GradientTexture1D_d2t20"] -gradient = SubResource("Gradient_tjuvm") - -[sub_resource type="Gradient" id="Gradient_c8r4y"] -offsets = PackedFloat32Array(0, 0.00813008, 0.52439, 1) -colors = PackedColorArray(0, 0, 0, 1, 0.0284553, 0.0284553, 0.0284553, 1, 0.244776, 0.244776, 0.244776, 1, 0, 0, 0, 1) - -[sub_resource type="GradientTexture1D" id="GradientTexture1D_2vogp"] -gradient = SubResource("Gradient_c8r4y") - -[sub_resource type="ParticleProcessMaterial" id="ParticleProcessMaterial_eegys"] -emission_shape = 1 -emission_sphere_radius = 0.3 -spread = 180.0 -gravity = Vector3(0, 0.02, 0) -initial_velocity_max = 0.2 -color_ramp = SubResource("GradientTexture1D_2vogp") -color_initial_ramp = SubResource("GradientTexture1D_d2t20") -turbulence_enabled = true -turbulence_noise_strength = 0.1 -turbulence_noise_scale = 2.0 -turbulence_noise_speed = Vector3(0.1, 0.3, 0.5) -turbulence_noise_speed_random = 0.3 -turbulence_influence_min = 0.01 -turbulence_influence_max = 0.03 -turbulence_initial_displacement_max = 1.0 - -[sub_resource type="Shader" id="Shader_p2314"] -code = "// NOTE: Shader automatically converted from Godot Engine 4.0.stable's StandardMaterial3D. - -shader_type spatial; -render_mode blend_mix,depth_draw_opaque,cull_back,diffuse_burley,specular_disabled; -uniform vec4 albedo : source_color; -uniform sampler2D texture_albedo : source_color,filter_linear_mipmap,repeat_enable; -uniform float point_size : hint_range(0,128); -uniform float roughness : hint_range(0,1); -uniform sampler2D texture_metallic : hint_default_white,filter_linear_mipmap,repeat_enable; -uniform vec4 metallic_texture_channel; -uniform sampler2D texture_roughness : hint_roughness_r,filter_linear_mipmap,repeat_enable; -uniform float specular; -uniform float metallic; -uniform int particles_anim_h_frames; -uniform int particles_anim_v_frames; -uniform bool particles_anim_loop; -uniform vec4 backlight : source_color; -uniform sampler2D texture_backlight : hint_default_black,filter_linear_mipmap,repeat_enable; -uniform vec3 uv1_scale; -uniform vec3 uv1_offset; -uniform vec3 uv2_scale; -uniform vec3 uv2_offset; - - -void vertex() { - UV=UV*uv1_scale.xy+uv1_offset.xy; - mat4 mat_world = mat4(normalize(INV_VIEW_MATRIX[0]), normalize(INV_VIEW_MATRIX[1]) ,normalize(INV_VIEW_MATRIX[2]), MODEL_MATRIX[3]); - mat_world = mat_world * mat4(vec4(cos(INSTANCE_CUSTOM.x), -sin(INSTANCE_CUSTOM.x), 0.0, 0.0), vec4(sin(INSTANCE_CUSTOM.x), cos(INSTANCE_CUSTOM.x), 0.0, 0.0), vec4(0.0, 0.0, 1.0, 0.0), vec4(0.0, 0.0, 0.0, 1.0)); - MODELVIEW_MATRIX = VIEW_MATRIX * mat_world; - MODELVIEW_NORMAL_MATRIX = mat3(MODELVIEW_MATRIX); - float h_frames = float(particles_anim_h_frames); - float v_frames = float(particles_anim_v_frames); - float particle_total_frames = float(particles_anim_h_frames * particles_anim_v_frames); - float particle_frame = floor(INSTANCE_CUSTOM.z * float(particle_total_frames)); - if (!particles_anim_loop) { - particle_frame = clamp(particle_frame, 0.0, particle_total_frames - 1.0); - } else { - particle_frame = mod(particle_frame, particle_total_frames); - } - UV /= vec2(h_frames, v_frames); - UV += vec2(mod(particle_frame, h_frames) / h_frames, floor((particle_frame + 0.5) / h_frames) / v_frames); -} - - - - - - -void fragment() { - vec2 base_uv = UV; - vec4 albedo_tex = texture(texture_albedo,base_uv); - albedo_tex *= COLOR; - ALBEDO = albedo.rgb * albedo_tex.rgb; - float metallic_tex = dot(texture(texture_metallic,base_uv),metallic_texture_channel); - METALLIC = metallic_tex * metallic; - vec4 roughness_texture_channel = vec4(1.0,0.0,0.0,0.0); - float roughness_tex = dot(texture(texture_roughness,base_uv),roughness_texture_channel); - ROUGHNESS = roughness_tex * roughness; - SPECULAR = specular; - vec3 backlight_tex = texture(texture_backlight,base_uv).rgb; - BACKLIGHT = (backlight.rgb+backlight_tex); -} -" - -[sub_resource type="ShaderMaterial" id="ShaderMaterial_fgrmi"] -render_priority = 0 -shader = SubResource("Shader_p2314") -shader_parameter/albedo = Color(1, 1, 1, 1) -shader_parameter/point_size = 1.0 -shader_parameter/roughness = 1.0 -shader_parameter/metallic_texture_channel = Plane(1, 0, 0, 0) -shader_parameter/specular = 0.5 -shader_parameter/metallic = 0.0 -shader_parameter/particles_anim_h_frames = 1 -shader_parameter/particles_anim_v_frames = 1 -shader_parameter/particles_anim_loop = false -shader_parameter/backlight = Color(0, 0, 0, 1) -shader_parameter/uv1_scale = Vector3(1, 1, 1) -shader_parameter/uv1_offset = Vector3(0, 0, 0) -shader_parameter/uv2_scale = Vector3(1, 1, 1) -shader_parameter/uv2_offset = Vector3(0, 0, 0) -shader_parameter/texture_albedo = ExtResource("2_mi0wa") -shader_parameter/texture_backlight = ExtResource("2_mi0wa") - -[sub_resource type="QuadMesh" id="QuadMesh_ea2fp"] -material = SubResource("ShaderMaterial_fgrmi") -size = Vector2(0.1, 0.1) - [sub_resource type="StandardMaterial3D" id="StandardMaterial3D_xd7ns"] specular_mode = 2 vertex_color_use_as_albedo = true @@ -147,14 +21,7 @@ metallic_specular = 1.0 [node name="Node3D" type="Node3D"] -[node name="collectable_particles" type="GPUParticles3D" parent="."] -material_override = SubResource("ShaderMaterial_lpenh") -material_overlay = SubResource("ShaderMaterial_lpenh") -cast_shadow = 0 -amount = 100 -lifetime = 10.0 -process_material = SubResource("ParticleProcessMaterial_eegys") -draw_pass_1 = SubResource("QuadMesh_ea2fp") +[node name="collectable_particles" parent="." instance=ExtResource("1_7bqxo")] [node name="CSGBox3D" type="CSGBox3D" parent="."] transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, -2.66951) diff --git a/src/vfx/collectable_particles.tscn b/src/vfx/collectable_particles.tscn index f75ebb7..e93420f 100644 --- a/src/vfx/collectable_particles.tscn +++ b/src/vfx/collectable_particles.tscn @@ -1,30 +1,138 @@ -[gd_scene load_steps=4 format=3 uid="uid://bdnesuqroi7ss"] +[gd_scene load_steps=12 format=3 uid="uid://bdnesuqroi7ss"] -[sub_resource type="StandardMaterial3D" id="StandardMaterial3D_nbr3v"] -blend_mode = 1 -billboard_mode = 3 -particles_anim_h_frames = 1 -particles_anim_v_frames = 1 -particles_anim_loop = false +[ext_resource type="Shader" path="res://vfx/particle_mixer.gdshader" id="1_i6oe2"] +[ext_resource type="Texture2D" uid="uid://dq7jm5ufknbb6" path="res://vfx/lens-flare-particle.png" id="2_h5y3k"] -[sub_resource type="ParticleProcessMaterial" id="ParticleProcessMaterial_d61lg"] +[sub_resource type="ShaderMaterial" id="ShaderMaterial_lpenh"] +render_priority = 0 +shader = ExtResource("1_i6oe2") +shader_parameter/particle_color = null +shader_parameter/particle_texture = ExtResource("2_h5y3k") + +[sub_resource type="Gradient" id="Gradient_tjuvm"] +offsets = PackedFloat32Array(0, 0.50813, 1) +colors = PackedColorArray(1, 0.877403, 0.516545, 1, 0.94702, 0.505309, 0.59484, 1, 0.735853, 0.324231, 0.687053, 1) + +[sub_resource type="GradientTexture1D" id="GradientTexture1D_d2t20"] +gradient = SubResource("Gradient_tjuvm") + +[sub_resource type="Gradient" id="Gradient_c8r4y"] +offsets = PackedFloat32Array(0, 0.00813008, 0.52439, 1) +colors = PackedColorArray(0, 0, 0, 1, 0.0284553, 0.0284553, 0.0284553, 1, 0.244776, 0.244776, 0.244776, 1, 0, 0, 0, 1) + +[sub_resource type="GradientTexture1D" id="GradientTexture1D_2vogp"] +gradient = SubResource("Gradient_c8r4y") + +[sub_resource type="ParticleProcessMaterial" id="ParticleProcessMaterial_eegys"] emission_shape = 1 -emission_sphere_radius = 1.0 +emission_sphere_radius = 0.3 spread = 180.0 -gravity = Vector3(0, 1, 0) -initial_velocity_min = 0.2 -initial_velocity_max = 1.0 +gravity = Vector3(0, 0.02, 0) +initial_velocity_max = 0.2 +color_ramp = SubResource("GradientTexture1D_2vogp") +color_initial_ramp = SubResource("GradientTexture1D_d2t20") turbulence_enabled = true +turbulence_noise_strength = 0.1 +turbulence_noise_scale = 2.0 turbulence_noise_speed = Vector3(0.1, 0.3, 0.5) turbulence_noise_speed_random = 0.3 -turbulence_influence_min = 0.05 +turbulence_influence_min = 0.01 +turbulence_influence_max = 0.03 turbulence_initial_displacement_max = 1.0 +[sub_resource type="Shader" id="Shader_p2314"] +code = "// NOTE: Shader automatically converted from Godot Engine 4.0.stable's StandardMaterial3D. + +shader_type spatial; +render_mode blend_mix,depth_draw_opaque,cull_back,diffuse_burley,specular_disabled; +uniform vec4 albedo : source_color; +uniform sampler2D texture_albedo : source_color,filter_linear_mipmap,repeat_enable; +uniform float point_size : hint_range(0,128); +uniform float roughness : hint_range(0,1); +uniform sampler2D texture_metallic : hint_default_white,filter_linear_mipmap,repeat_enable; +uniform vec4 metallic_texture_channel; +uniform sampler2D texture_roughness : hint_roughness_r,filter_linear_mipmap,repeat_enable; +uniform float specular; +uniform float metallic; +uniform int particles_anim_h_frames; +uniform int particles_anim_v_frames; +uniform bool particles_anim_loop; +uniform vec4 backlight : source_color; +uniform sampler2D texture_backlight : hint_default_black,filter_linear_mipmap,repeat_enable; +uniform vec3 uv1_scale; +uniform vec3 uv1_offset; +uniform vec3 uv2_scale; +uniform vec3 uv2_offset; + + +void vertex() { + UV=UV*uv1_scale.xy+uv1_offset.xy; + mat4 mat_world = mat4(normalize(INV_VIEW_MATRIX[0]), normalize(INV_VIEW_MATRIX[1]) ,normalize(INV_VIEW_MATRIX[2]), MODEL_MATRIX[3]); + mat_world = mat_world * mat4(vec4(cos(INSTANCE_CUSTOM.x), -sin(INSTANCE_CUSTOM.x), 0.0, 0.0), vec4(sin(INSTANCE_CUSTOM.x), cos(INSTANCE_CUSTOM.x), 0.0, 0.0), vec4(0.0, 0.0, 1.0, 0.0), vec4(0.0, 0.0, 0.0, 1.0)); + MODELVIEW_MATRIX = VIEW_MATRIX * mat_world; + MODELVIEW_NORMAL_MATRIX = mat3(MODELVIEW_MATRIX); + float h_frames = float(particles_anim_h_frames); + float v_frames = float(particles_anim_v_frames); + float particle_total_frames = float(particles_anim_h_frames * particles_anim_v_frames); + float particle_frame = floor(INSTANCE_CUSTOM.z * float(particle_total_frames)); + if (!particles_anim_loop) { + particle_frame = clamp(particle_frame, 0.0, particle_total_frames - 1.0); + } else { + particle_frame = mod(particle_frame, particle_total_frames); + } + UV /= vec2(h_frames, v_frames); + UV += vec2(mod(particle_frame, h_frames) / h_frames, floor((particle_frame + 0.5) / h_frames) / v_frames); +} + + + + + + +void fragment() { + vec2 base_uv = UV; + vec4 albedo_tex = texture(texture_albedo,base_uv); + albedo_tex *= COLOR; + ALBEDO = albedo.rgb * albedo_tex.rgb; + float metallic_tex = dot(texture(texture_metallic,base_uv),metallic_texture_channel); + METALLIC = metallic_tex * metallic; + vec4 roughness_texture_channel = vec4(1.0,0.0,0.0,0.0); + float roughness_tex = dot(texture(texture_roughness,base_uv),roughness_texture_channel); + ROUGHNESS = roughness_tex * roughness; + SPECULAR = specular; + vec3 backlight_tex = texture(texture_backlight,base_uv).rgb; + BACKLIGHT = (backlight.rgb+backlight_tex); +} +" + +[sub_resource type="ShaderMaterial" id="ShaderMaterial_fgrmi"] +render_priority = 0 +shader = SubResource("Shader_p2314") +shader_parameter/albedo = Color(1, 1, 1, 1) +shader_parameter/point_size = 1.0 +shader_parameter/roughness = 1.0 +shader_parameter/metallic_texture_channel = Plane(1, 0, 0, 0) +shader_parameter/specular = 0.5 +shader_parameter/metallic = 0.0 +shader_parameter/particles_anim_h_frames = 1 +shader_parameter/particles_anim_v_frames = 1 +shader_parameter/particles_anim_loop = false +shader_parameter/backlight = Color(0, 0, 0, 1) +shader_parameter/uv1_scale = Vector3(1, 1, 1) +shader_parameter/uv1_offset = Vector3(0, 0, 0) +shader_parameter/uv2_scale = Vector3(1, 1, 1) +shader_parameter/uv2_offset = Vector3(0, 0, 0) +shader_parameter/texture_albedo = ExtResource("2_h5y3k") +shader_parameter/texture_backlight = ExtResource("2_h5y3k") + [sub_resource type="QuadMesh" id="QuadMesh_ea2fp"] +material = SubResource("ShaderMaterial_fgrmi") +size = Vector2(0.1, 0.1) [node name="collectable_particles" type="GPUParticles3D"] -material_override = SubResource("StandardMaterial3D_nbr3v") -amount = 30 +material_override = SubResource("ShaderMaterial_lpenh") +cast_shadow = 0 +amount = 50 lifetime = 10.0 -process_material = SubResource("ParticleProcessMaterial_d61lg") +process_material = SubResource("ParticleProcessMaterial_eegys") draw_pass_1 = SubResource("QuadMesh_ea2fp") diff --git a/src/vfx/particle_mixer.gdshader b/src/vfx/particle_mixer.gdshader index 6f2f6c5..21139bc 100644 --- a/src/vfx/particle_mixer.gdshader +++ b/src/vfx/particle_mixer.gdshader @@ -4,6 +4,7 @@ render_mode blend_add, specular_disabled; uniform sampler2D particle_texture; uniform vec4 particle_color : source_color; +uniform sampler2D DEPTH_TEXTURE: hint_depth_texture; void vertex() { mat4 mat_world = mat4(normalize(INV_VIEW_MATRIX[0]), normalize(INV_VIEW_MATRIX[1]) ,normalize(INV_VIEW_MATRIX[2]), MODEL_MATRIX[3]); @@ -14,9 +15,13 @@ void vertex() { } void fragment() { - ALBEDO = texture(particle_texture,UV/2.0).xyz * COLOR.xyz; + float depth = texture(DEPTH_TEXTURE, SCREEN_UV).r; + depth = PROJECTION_MATRIX[3][2] / (depth + PROJECTION_MATRIX[2][2]); + depth += VERTEX.z; + depth = max(0.0,min(1.0, (depth*10.0 - 0.1))); + ALBEDO = texture(particle_texture,UV/2.0).xyz * COLOR.xyz * depth; EMISSION = ALBEDO/8.0; BACKLIGHT = ALBEDO; - SPECULAR = 0.0; + SPECULAR = 0.0; }