notSpore/game-of-life-test/dot_matrix.gdshader

37 lines
832 B
Plaintext

shader_type canvas_item;
uniform sampler2D unlitTex;
uniform sampler2D litTex;
uniform sampler2D binDataTex;
uniform int n;
const int cellSize = 8;
void vertex() {
// Called for every vertex the material is visible on.
}
void fragment() {
// Called for every pixel the material is visible on.
vec2 totalGridSize = vec2(float(n) * float(cellSize));
vec2 scaledUV = UV * float(n);
ivec2 cellIdx = ivec2(floor(scaledUV));
vec2 cellUV = fract(scaledUV);
float binVal = texelFetch(binDataTex, cellIdx, 0).r;
bool isWhite = binVal > 0.5;
vec4 color = texture(unlitTex, cellUV);
if (isWhite) {
color = texture(litTex, cellUV);
}
COLOR = color;
}
//void light() {
// // Called for every pixel for every light affecting the material.
// // Uncomment to replace the default light processing function with this one.
//}