Add shader for making phase icons change color

This commit is contained in:
Hamcha 2019-08-16 15:29:00 +02:00
parent 4c984e5b04
commit fd3750546d
3 changed files with 74 additions and 6 deletions

View file

@ -0,0 +1,19 @@
shader_type canvas_item;
render_mode unshaded;
uniform vec4 fillColor: hint_color;
uniform vec4 baseColor: hint_color;
uniform float fillRatio: hint_range(0.0, 1.0);
uniform float fillAngle: hint_range(0.0, 6.28);
void fragment() {
vec4 col = texture(TEXTURE, UV);
vec3 mask = col.xyz * -1.0 + 1.0;
if (UV.y+fillAngle*UV.x > (1.0 - fillRatio)*1.2) {
mask *= fillColor.xyz;
col.xyz += mask.xyz;
} else {
col.xyz += baseColor.xyz;
}
COLOR = col;
}

View file

@ -1,9 +1,53 @@
[gd_scene load_steps=5 format=2] [gd_scene load_steps=10 format=2]
[ext_resource path="res://Scenes/Scripts/BoardUI.gd" type="Script" id=1] [ext_resource path="res://Scenes/Scripts/BoardUI.gd" type="Script" id=1]
[ext_resource path="res://Scenes/Board/UI/PhaseIcon.tscn" type="PackedScene" id=2] [ext_resource path="res://Scenes/Board/UI/PhaseIcon.tscn" type="PackedScene" id=2]
[ext_resource path="res://MLPAssets/Placeholders/unknowncard.jpg" type="Texture" id=3] [ext_resource path="res://MLPAssets/Placeholders/unknowncard.jpg" type="Texture" id=3]
[sub_resource type="Shader" id=2]
code = "shader_type canvas_item;
render_mode unshaded;
uniform vec4 fillColor: hint_color;
uniform vec4 baseColor: hint_color;
uniform float fillRatio: hint_range(0.0, 1.0);
void fragment() {
vec4 col = texture(TEXTURE, UV);
vec3 mask = col.xyz * -1.0 + 1.0;
if (UV.y > 1.0 - fillRatio) {
mask *= fillColor.xyz;
col.xyz += mask.xyz;
} else {
col.xyz += baseColor.xyz;
}
COLOR = col;
}"
[sub_resource type="ShaderMaterial" id=3]
shader = SubResource( 2 )
shader_param/fillColor = Color( 1, 0.298039, 0.137255, 1 )
shader_param/baseColor = Color( 0, 0, 0, 1 )
shader_param/fillRatio = 0.0
[sub_resource type="ShaderMaterial" id=4]
shader = SubResource( 2 )
shader_param/fillColor = Color( 1, 0.298039, 0.137255, 1 )
shader_param/baseColor = Color( 0, 0, 0, 1 )
shader_param/fillRatio = 0.0
[sub_resource type="ShaderMaterial" id=5]
shader = SubResource( 2 )
shader_param/fillColor = Color( 1, 0.298039, 0.137255, 1 )
shader_param/baseColor = Color( 0, 0, 0, 1 )
shader_param/fillRatio = 0.0
[sub_resource type="ShaderMaterial" id=6]
shader = SubResource( 2 )
shader_param/fillColor = Color( 1, 0.298039, 0.137255, 1 )
shader_param/baseColor = Color( 0, 0, 0, 1 )
shader_param/fillRatio = 0.0
[sub_resource type="Animation" id=1] [sub_resource type="Animation" id=1]
resource_name = "fade ui card" resource_name = "fade ui card"
length = 0.1 length = 0.1
@ -85,6 +129,7 @@ size_flags_vertical = 3
alignment = 1 alignment = 1
[node name="ReadyPhase" parent="Panel/HBoxContainer" instance=ExtResource( 2 )] [node name="ReadyPhase" parent="Panel/HBoxContainer" instance=ExtResource( 2 )]
material = SubResource( 3 )
margin_left = 819.0 margin_left = 819.0
margin_top = 0.0 margin_top = 0.0
margin_right = 899.0 margin_right = 899.0
@ -93,6 +138,7 @@ rect_scale = Vector2( 1, 1 )
mouse_filter = 2 mouse_filter = 2
[node name="TroublePhase" parent="Panel/HBoxContainer" instance=ExtResource( 2 )] [node name="TroublePhase" parent="Panel/HBoxContainer" instance=ExtResource( 2 )]
material = SubResource( 4 )
margin_left = 903.0 margin_left = 903.0
margin_top = 0.0 margin_top = 0.0
margin_right = 983.0 margin_right = 983.0
@ -102,6 +148,7 @@ mouse_filter = 2
phaseID = 1 phaseID = 1
[node name="MainPhase" parent="Panel/HBoxContainer" instance=ExtResource( 2 )] [node name="MainPhase" parent="Panel/HBoxContainer" instance=ExtResource( 2 )]
material = SubResource( 5 )
margin_left = 987.0 margin_left = 987.0
margin_top = 0.0 margin_top = 0.0
margin_right = 1067.0 margin_right = 1067.0
@ -111,6 +158,7 @@ mouse_filter = 2
phaseID = 2 phaseID = 2
[node name="ScorePhase" parent="Panel/HBoxContainer" instance=ExtResource( 2 )] [node name="ScorePhase" parent="Panel/HBoxContainer" instance=ExtResource( 2 )]
material = SubResource( 6 )
margin_left = 1071.0 margin_left = 1071.0
margin_top = 0.0 margin_top = 0.0
margin_right = 1151.0 margin_right = 1151.0
@ -121,7 +169,6 @@ phaseID = 3
[node name="CardZoom" type="TextureRect" parent="."] [node name="CardZoom" type="TextureRect" parent="."]
visible = false visible = false
modulate = Color( 1, 1, 1, 0 )
anchor_bottom = 1.0 anchor_bottom = 1.0
margin_left = 40.0 margin_left = 40.0
margin_top = 20.0 margin_top = 20.0
@ -135,5 +182,7 @@ texture = ExtResource( 3 )
expand = true expand = true
stretch_mode = 5 stretch_mode = 5
[node name="AnimationPlayer" type="AnimationPlayer" parent="."] [node name="PhaseAnimations" type="AnimationPlayer" parent="."]
[node name="CardAnimations" type="AnimationPlayer" parent="."]
"anims/fade ui card" = SubResource( 1 ) "anims/fade ui card" = SubResource( 1 )

View file

@ -1,6 +1,6 @@
extends Control extends Control
onready var animation = $AnimationPlayer onready var cardanim = $CardAnimations
onready var cardPic = $CardZoom onready var cardPic = $CardZoom
var menu: PopupMenu = null var menu: PopupMenu = null
@ -8,10 +8,10 @@ var menu: PopupMenu = null
func _card_selected(card: Card): func _card_selected(card: Card):
# TODO Hide card if it shouldn't be visible # TODO Hide card if it shouldn't be visible
cardPic.texture = card.texture cardPic.texture = card.texture
animation.play("fade ui card") cardanim.play("fade ui card")
func _card_unselected(card: Card): func _card_unselected(card: Card):
animation.play_backwards("fade ui card") cardanim.play_backwards("fade ui card")
func show_card_menu(card: Card, cbobj: Object, cbfn): func show_card_menu(card: Card, cbobj: Object, cbfn):
# Close any open menus # Close any open menus