Created
May 13, 2020 04:08
-
-
Save pcwalton/6456bbadc3514f07d616f553ddeedeca to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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