From 500fa6ddb88d6f501c722870719f2d1fa0fbfddd Mon Sep 17 00:00:00 2001 From: Cat Flynn Date: Tue, 6 Dec 2022 20:16:24 +0000 Subject: [PATCH] generalise shader #4 --- half-earth/materials/cursor.tres | 6 +++--- half-earth/materials/tile.tres | 6 +++--- half-earth/scripts/GridCursor.cs | 6 +++--- half-earth/scripts/WorldGrid.cs | 2 +- half-earth/shaders/tile_shader.gdshader | 8 ++++---- 5 files changed, 14 insertions(+), 14 deletions(-) diff --git a/half-earth/materials/cursor.tres b/half-earth/materials/cursor.tres index a3218a5..91a714d 100644 --- a/half-earth/materials/cursor.tres +++ b/half-earth/materials/cursor.tres @@ -4,6 +4,6 @@ [resource] shader = ExtResource( 1 ) -shader_param/baseColor = Color( 0.992157, 1, 0, 1 ) -shader_param/highlightColor = Color( 1, 0, 0.984314, 1 ) -shader_param/isHighlighted = 0 +shader_param/lowColor = Color( 1, 0.960784, 0, 1 ) +shader_param/highColor = Color( 0.921569, 0, 1, 1 ) +shader_param/t = null diff --git a/half-earth/materials/tile.tres b/half-earth/materials/tile.tres index 327c5eb..9f921a3 100644 --- a/half-earth/materials/tile.tres +++ b/half-earth/materials/tile.tres @@ -5,6 +5,6 @@ [resource] resource_local_to_scene = true shader = ExtResource( 1 ) -shader_param/baseColor = Color( 0.0823529, 0, 1, 1 ) -shader_param/highlightColor = Color( 1, 0, 0, 1 ) -shader_param/isHighlighted = null +shader_param/lowColor = Color( 0.0313726, 0, 1, 1 ) +shader_param/highColor = Color( 1, 0, 0, 1 ) +shader_param/t = null diff --git a/half-earth/scripts/GridCursor.cs b/half-earth/scripts/GridCursor.cs index fd97c42..6ff61a0 100644 --- a/half-earth/scripts/GridCursor.cs +++ b/half-earth/scripts/GridCursor.cs @@ -8,7 +8,7 @@ public class GridCursor : Sprite private WorldGrid _grid; private ShaderMaterial _material; - private const string IS_HIGHLIGHTED = "isHighlighted"; + private const string T = "t"; public override void _Ready() { @@ -38,11 +38,11 @@ public class GridCursor : Sprite var pos = mouseButtonEvent.Position; _grid.GetGridPos(pos, out var x, out var y); _grid.ToggleTileHighlight(x, y); - _material.SetShaderParam(IS_HIGHLIGHTED, 1); + _material.SetShaderParam(T, 1f); } else { - _material.SetShaderParam(IS_HIGHLIGHTED, 0); + _material.SetShaderParam(T, 0f); } break; } diff --git a/half-earth/scripts/WorldGrid.cs b/half-earth/scripts/WorldGrid.cs index 7f55d6c..8a69681 100644 --- a/half-earth/scripts/WorldGrid.cs +++ b/half-earth/scripts/WorldGrid.cs @@ -30,7 +30,7 @@ public class WorldGrid : Node2D { var tile = _tiles[x, y]; var material = tile.material; - material.SetShaderParam("isHighlighted", tile.isHighlighted ? 1 : 0); + material.SetShaderParam("t", tile.isHighlighted ? 1f : 0f); } } } diff --git a/half-earth/shaders/tile_shader.gdshader b/half-earth/shaders/tile_shader.gdshader index 98f8fe0..537a2b6 100644 --- a/half-earth/shaders/tile_shader.gdshader +++ b/half-earth/shaders/tile_shader.gdshader @@ -1,9 +1,9 @@ shader_type canvas_item; -uniform vec4 baseColor : hint_color; -uniform vec4 highlightColor : hint_color; -uniform int isHighlighted; +uniform vec4 lowColor : hint_color; +uniform vec4 highColor : hint_color; +uniform float t; void fragment() { - COLOR = mix(baseColor, highlightColor, float(isHighlighted)); + COLOR = mix(lowColor, highColor, t); }