aboutsummaryrefslogtreecommitdiff
path: root/game/src/Game/Model/unit_colours.gdshader
diff options
context:
space:
mode:
author Hop311 <Hop3114@gmail.com>2024-05-12 17:17:32 +0200
committer GitHub <noreply@github.com>2024-05-12 17:17:32 +0200
commitbfccdb87d66304604ad018037db1581746646bfa (patch)
treeac4394e8ceaca22fa0deaeebd8cf5eafedecaa3e /game/src/Game/Model/unit_colours.gdshader
parentb0a533f945bbc6201fd7df4bc60746cb98efaba4 (diff)
parentac29e4040fc20c50c8f0eb64b1194f6398165eb0 (diff)
Merge pull request #227 from OpenVicProject/models
Models
Diffstat (limited to 'game/src/Game/Model/unit_colours.gdshader')
-rw-r--r--game/src/Game/Model/unit_colours.gdshader31
1 files changed, 31 insertions, 0 deletions
diff --git a/game/src/Game/Model/unit_colours.gdshader b/game/src/Game/Model/unit_colours.gdshader
new file mode 100644
index 0000000..dd0f5e2
--- /dev/null
+++ b/game/src/Game/Model/unit_colours.gdshader
@@ -0,0 +1,31 @@
+
+shader_type spatial;
+
+render_mode blend_mix, depth_draw_opaque, cull_disabled, diffuse_burley, specular_schlick_ggx;
+
+//hold all the textures for the units that need this shader to mix in their
+//nation colours (mostly generic infantry units)
+uniform sampler2D texture_albedo[32] : source_color, filter_linear_mipmap, repeat_enable;
+uniform sampler2D texture_nation_colors_mask[32] : source_color, filter_linear_mipmap, repeat_enable;
+
+instance uniform vec3 colour_primary : source_color;
+instance uniform vec3 colour_secondary : source_color;
+instance uniform vec3 colour_tertiary : source_color;
+
+//used to access the right textures since different units (with different textures)
+//will use this same shader
+instance uniform uint tex_index_specular;
+instance uniform uint tex_index_diffuse;
+
+void fragment() {
+ vec2 base_uv = UV;
+ vec4 albedo_tex = texture(texture_albedo[tex_index_diffuse], base_uv);
+ vec4 nation_colours_tex = texture(texture_nation_colors_mask[tex_index_specular], base_uv);
+
+ //set colours to either be white (1,1,1) or the nation colour based on the mask
+ vec3 primary_col = mix(vec3(1.0, 1.0, 1.0), colour_primary, nation_colours_tex.g);
+ vec3 secondary_col = mix(vec3(1.0, 1.0, 1.0), colour_secondary, nation_colours_tex.b);
+ vec3 tertiary_col = mix(vec3(1.0, 1.0, 1.0), colour_tertiary, nation_colours_tex.r);
+
+ ALBEDO = albedo_tex.rgb * primary_col * secondary_col * tertiary_col;
+}