Files
Dawn-Godot/shaders/NPC Shader.gdshader
2025-05-01 19:08:20 -05:00

40 lines
940 B
Plaintext

shader_type spatial;
render_mode cull_disabled;
uniform sampler2D npcTexture : filter_nearest;
uniform int frame;
uniform int direction;
const int FRAMES = 3;
const int DIRECTIONS = 4;
void vertex() {
vec2 tileSize = vec2(1.0 / float(FRAMES), 1.0 / float(DIRECTIONS));
vec2 topLeft = tileSize * vec2(float(frame % FRAMES), float(direction % DIRECTIONS));
vec2 bottomRight = topLeft + tileSize;
if(VERTEX_ID == 3) {
UV = topLeft;
} else if(VERTEX_ID == 2) {
UV = vec2(bottomRight.x, topLeft.y);
} else if(VERTEX_ID == 1) {
UV = vec2(topLeft.x, bottomRight.y);
} else if(VERTEX_ID == 0) {
UV = bottomRight;
}
}
void fragment() {
vec4 npcColor = texture(npcTexture, UV);
// Remove PINK background
if(npcColor.r == 1.0 && npcColor.g == 0.0 && npcColor.b == 1.0)
discard;
// Remove GREEN borders
if(npcColor.r == 0.00392156862745 && npcColor.g == 1.0 && npcColor.b == 0.0)
discard;
ALBEDO.rgb = npcColor.rgb;
}