Skip to content

Instantly share code, notes, and snippets.

@pcwalton
Created May 13, 2020 04:08
Show Gist options
  • Save pcwalton/6456bbadc3514f07d616f553ddeedeca to your computer and use it in GitHub Desktop.
Save pcwalton/6456bbadc3514f07d616f553ddeedeca to your computer and use it in GitHub Desktop.
#version 430
precision highp float;
precision highp sampler2D;
uniform sampler2D uBSPTree;
uniform sampler2D uSDF;
uniform vec4 uBGColor;
uniform vec4 uFGColor;
in vec2 vTexCoord;
out vec4 oFragCoord;
void main() {
vec4 data;
int node = 0;
while ((data = texelFetch(uBSPTree, ivec2(0, node), 0)).w < 1.0) {
float value = data.w == 0.0 ? vTexCoord.x : vTexCoord.y;
node = int(data.x <= value ? data.y : data.z);
}
vec4 srcRect = texelFetch(uBSPTree, ivec2(1, node), 0);
vec4 uvRect = texelFetch(uBSPTree, ivec2(2, node), 0);
vec2 uv = mix((vTexCoord - srcRect.xy) / (srcRect.zw - srcRect.xy), uvRect.xy, uvRect.zw);
vec4 texel = texture(uSDF, uv);
float alpha = texel.b == 0.0 ? min(texel.r, texel.g) : max(texel.r, texel.g);
oFragCoord = mix(uBGColor, uFGColor, alpha);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment