generalise shader #4
This commit is contained in:
parent
d044beb3d5
commit
500fa6ddb8
|
@ -4,6 +4,6 @@
|
||||||
|
|
||||||
[resource]
|
[resource]
|
||||||
shader = ExtResource( 1 )
|
shader = ExtResource( 1 )
|
||||||
shader_param/baseColor = Color( 0.992157, 1, 0, 1 )
|
shader_param/lowColor = Color( 1, 0.960784, 0, 1 )
|
||||||
shader_param/highlightColor = Color( 1, 0, 0.984314, 1 )
|
shader_param/highColor = Color( 0.921569, 0, 1, 1 )
|
||||||
shader_param/isHighlighted = 0
|
shader_param/t = null
|
||||||
|
|
|
@ -5,6 +5,6 @@
|
||||||
[resource]
|
[resource]
|
||||||
resource_local_to_scene = true
|
resource_local_to_scene = true
|
||||||
shader = ExtResource( 1 )
|
shader = ExtResource( 1 )
|
||||||
shader_param/baseColor = Color( 0.0823529, 0, 1, 1 )
|
shader_param/lowColor = Color( 0.0313726, 0, 1, 1 )
|
||||||
shader_param/highlightColor = Color( 1, 0, 0, 1 )
|
shader_param/highColor = Color( 1, 0, 0, 1 )
|
||||||
shader_param/isHighlighted = null
|
shader_param/t = null
|
||||||
|
|
|
@ -8,7 +8,7 @@ public class GridCursor : Sprite
|
||||||
private WorldGrid _grid;
|
private WorldGrid _grid;
|
||||||
private ShaderMaterial _material;
|
private ShaderMaterial _material;
|
||||||
|
|
||||||
private const string IS_HIGHLIGHTED = "isHighlighted";
|
private const string T = "t";
|
||||||
|
|
||||||
public override void _Ready()
|
public override void _Ready()
|
||||||
{
|
{
|
||||||
|
@ -38,11 +38,11 @@ public class GridCursor : Sprite
|
||||||
var pos = mouseButtonEvent.Position;
|
var pos = mouseButtonEvent.Position;
|
||||||
_grid.GetGridPos(pos, out var x, out var y);
|
_grid.GetGridPos(pos, out var x, out var y);
|
||||||
_grid.ToggleTileHighlight(x, y);
|
_grid.ToggleTileHighlight(x, y);
|
||||||
_material.SetShaderParam(IS_HIGHLIGHTED, 1);
|
_material.SetShaderParam(T, 1f);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
_material.SetShaderParam(IS_HIGHLIGHTED, 0);
|
_material.SetShaderParam(T, 0f);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,7 +30,7 @@ public class WorldGrid : Node2D
|
||||||
{
|
{
|
||||||
var tile = _tiles[x, y];
|
var tile = _tiles[x, y];
|
||||||
var material = tile.material;
|
var material = tile.material;
|
||||||
material.SetShaderParam("isHighlighted", tile.isHighlighted ? 1 : 0);
|
material.SetShaderParam("t", tile.isHighlighted ? 1f : 0f);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
shader_type canvas_item;
|
shader_type canvas_item;
|
||||||
|
|
||||||
uniform vec4 baseColor : hint_color;
|
uniform vec4 lowColor : hint_color;
|
||||||
uniform vec4 highlightColor : hint_color;
|
uniform vec4 highColor : hint_color;
|
||||||
uniform int isHighlighted;
|
uniform float t;
|
||||||
|
|
||||||
void fragment() {
|
void fragment() {
|
||||||
COLOR = mix(baseColor, highlightColor, float(isHighlighted));
|
COLOR = mix(lowColor, highColor, t);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue