sprite3d outline shader, use it for sprouts
This commit is contained in:
parent
1a5889bc7a
commit
21ba71373c
32
scenes/interactivity_outline2.gdshader
Normal file
32
scenes/interactivity_outline2.gdshader
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
shader_type spatial;
|
||||||
|
|
||||||
|
|
||||||
|
uniform float width : hint_range(0.0, 16.0);
|
||||||
|
uniform vec4 outline_color : source_color;
|
||||||
|
uniform sampler2D albedo_texture : source_color, filter_nearest;
|
||||||
|
|
||||||
|
|
||||||
|
void vertex() {
|
||||||
|
MODELVIEW_MATRIX = VIEW_MATRIX * mat4(INV_VIEW_MATRIX[0], vec4(0, 1, 0, 0), INV_VIEW_MATRIX[2], MODEL_MATRIX[3]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* thanks gdquest */
|
||||||
|
void fragment() {
|
||||||
|
vec2 size = vec2(width) / vec2(textureSize(albedo_texture, 0));
|
||||||
|
|
||||||
|
vec4 sprite_color = texture(albedo_texture, UV);
|
||||||
|
|
||||||
|
float alpha = sprite_color.a;
|
||||||
|
alpha += texture(albedo_texture, UV + vec2(0.0, -size.y)).a;
|
||||||
|
alpha += texture(albedo_texture, UV + vec2(size.x, -size.y)).a;
|
||||||
|
alpha += texture(albedo_texture, UV + vec2(size.x, 0.0)).a;
|
||||||
|
alpha += texture(albedo_texture, UV + vec2(size.x, size.y)).a;
|
||||||
|
alpha += texture(albedo_texture, UV + vec2(0.0, size.y)).a;
|
||||||
|
alpha += texture(albedo_texture, UV + vec2(-size.x, size.y)).a;
|
||||||
|
alpha += texture(albedo_texture, UV + vec2(-size.x, 0.0)).a;
|
||||||
|
alpha += texture(albedo_texture, UV + vec2(-size.x, -size.y)).a;
|
||||||
|
|
||||||
|
vec3 final_color = mix(outline_color.rgb, sprite_color.rgb, sprite_color.a);
|
||||||
|
ALBEDO = final_color;
|
||||||
|
ALPHA = clamp(alpha, 0.0, 1.0);
|
||||||
|
}
|
@ -2,7 +2,7 @@ extends Node3D
|
|||||||
|
|
||||||
@export var _need_water_drop: Sprite3D
|
@export var _need_water_drop: Sprite3D
|
||||||
@export var _production_timer: Timer
|
@export var _production_timer: Timer
|
||||||
@export var _sprite: Sprite3D
|
@export var _mesh: MeshInstance3D
|
||||||
|
|
||||||
var needs_water := true
|
var needs_water := true
|
||||||
var stage: int = 1
|
var stage: int = 1
|
||||||
@ -19,17 +19,12 @@ func _on_production_timer_timeout() -> void:
|
|||||||
_need_water_drop.show()
|
_need_water_drop.show()
|
||||||
|
|
||||||
|
|
||||||
@rpc("authority", "call_local", "reliable")
|
|
||||||
func _reflect_texture(p_stage: int) -> void:
|
|
||||||
_sprite.texture = load("res://assets/sprout%s.png" % p_stage)
|
|
||||||
|
|
||||||
|
|
||||||
@rpc("authority", "call_local", "reliable")
|
@rpc("authority", "call_local", "reliable")
|
||||||
func _water_shared(sender_id: int) -> void:
|
func _water_shared(sender_id: int) -> void:
|
||||||
if stage >= final_stage:
|
if stage >= final_stage:
|
||||||
return
|
return
|
||||||
stage += 1
|
stage += 1
|
||||||
_sprite.texture = load("res://assets/sprout%s.png" % stage)
|
_mesh.material_override.set("shader_parameter/albedo_texture", load("res://assets/sprout%s.png" % stage))
|
||||||
if sender_id != 0:
|
if sender_id != 0:
|
||||||
GameState.fetch().player_data[sender_id].chain_water_combo(1)
|
GameState.fetch().player_data[sender_id].chain_water_combo(1)
|
||||||
|
|
||||||
|
@ -1,7 +1,8 @@
|
|||||||
[gd_scene load_steps=6 format=3 uid="uid://bysgtksvovyur"]
|
[gd_scene load_steps=9 format=3 uid="uid://bysgtksvovyur"]
|
||||||
|
|
||||||
[ext_resource type="Script" path="res://src/ingame/sprout.gd" id="1_snma1"]
|
[ext_resource type="Script" path="res://src/ingame/sprout.gd" id="1_snma1"]
|
||||||
[ext_resource type="Texture2D" uid="uid://d35y5ckne72qe" path="res://assets/sprout1.png" id="2_ipgad"]
|
[ext_resource type="Texture2D" uid="uid://d35y5ckne72qe" path="res://assets/sprout1.png" id="2_ipgad"]
|
||||||
|
[ext_resource type="Shader" path="res://scenes/interactivity_outline2.gdshader" id="2_oa2it"]
|
||||||
[ext_resource type="Texture2D" uid="uid://cwbl0r1e26eja" path="res://assets/drop.png" id="3_kghdv"]
|
[ext_resource type="Texture2D" uid="uid://cwbl0r1e26eja" path="res://assets/drop.png" id="3_kghdv"]
|
||||||
|
|
||||||
[sub_resource type="SceneReplicationConfig" id="SceneReplicationConfig_rs2qp"]
|
[sub_resource type="SceneReplicationConfig" id="SceneReplicationConfig_rs2qp"]
|
||||||
@ -12,27 +13,35 @@ properties/1/path = NodePath("NeedWaterDrop:visible")
|
|||||||
properties/1/spawn = true
|
properties/1/spawn = true
|
||||||
properties/1/replication_mode = 2
|
properties/1/replication_mode = 2
|
||||||
|
|
||||||
|
[sub_resource type="ShaderMaterial" id="ShaderMaterial_3ul7y"]
|
||||||
|
resource_local_to_scene = true
|
||||||
|
render_priority = 0
|
||||||
|
shader = ExtResource("2_oa2it")
|
||||||
|
shader_parameter/width = 1.0
|
||||||
|
shader_parameter/outline_color = Color(0, 0, 0, 1)
|
||||||
|
shader_parameter/albedo_texture = ExtResource("2_ipgad")
|
||||||
|
|
||||||
|
[sub_resource type="QuadMesh" id="QuadMesh_0x06e"]
|
||||||
|
size = Vector2(0.5, 1)
|
||||||
|
|
||||||
[sub_resource type="CapsuleShape3D" id="CapsuleShape3D_cwbye"]
|
[sub_resource type="CapsuleShape3D" id="CapsuleShape3D_cwbye"]
|
||||||
radius = 0.3
|
radius = 0.3
|
||||||
height = 0.8
|
height = 0.8
|
||||||
|
|
||||||
[node name="Sprout" type="Node3D" node_paths=PackedStringArray("_need_water_drop", "_production_timer", "_sprite")]
|
[node name="Sprout" type="Node3D" node_paths=PackedStringArray("_need_water_drop", "_production_timer", "_mesh")]
|
||||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0.00401986, -0.00383317, 0.00119042)
|
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0.00401986, -0.00383317, 0.00119042)
|
||||||
script = ExtResource("1_snma1")
|
script = ExtResource("1_snma1")
|
||||||
_need_water_drop = NodePath("NeedWaterDrop")
|
_need_water_drop = NodePath("NeedWaterDrop")
|
||||||
_production_timer = NodePath("ProductionTimer")
|
_production_timer = NodePath("ProductionTimer")
|
||||||
_sprite = NodePath("Sprite3D")
|
_mesh = NodePath("Mesh")
|
||||||
|
|
||||||
[node name="MultiplayerSynchronizer" type="MultiplayerSynchronizer" parent="."]
|
[node name="MultiplayerSynchronizer" type="MultiplayerSynchronizer" parent="."]
|
||||||
replication_config = SubResource("SceneReplicationConfig_rs2qp")
|
replication_config = SubResource("SceneReplicationConfig_rs2qp")
|
||||||
|
|
||||||
[node name="Sprite3D" type="Sprite3D" parent="."]
|
[node name="Mesh" type="MeshInstance3D" parent="."]
|
||||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.3, 0)
|
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.25, 0)
|
||||||
pixel_size = 0.02
|
material_override = SubResource("ShaderMaterial_3ul7y")
|
||||||
billboard = 2
|
mesh = SubResource("QuadMesh_0x06e")
|
||||||
shaded = true
|
|
||||||
texture_filter = 2
|
|
||||||
texture = ExtResource("2_ipgad")
|
|
||||||
|
|
||||||
[node name="NeedWaterDrop" type="Sprite3D" parent="."]
|
[node name="NeedWaterDrop" type="Sprite3D" parent="."]
|
||||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.3, 0)
|
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.3, 0)
|
||||||
|
Loading…
Reference in New Issue
Block a user