38 lines
1.3 KiB
GLSL
38 lines
1.3 KiB
GLSL
float getSignedDistance(vec2 uv, highp sampler2D clippingDistance) {
|
|
float signedDistance = texture(clippingDistance, uv).r;
|
|
return (signedDistance - 0.5) * 2.0;
|
|
}
|
|
|
|
void czm_clipPolygons(highp sampler2D clippingDistance, int extentsLength, vec2 clippingPosition, int regionIndex) {
|
|
// Position is completely outside of polygons bounds
|
|
vec2 rectUv = clippingPosition;
|
|
if (regionIndex < 0 || rectUv.x <= 0.0 || rectUv.y <= 0.0 || rectUv.x >= 1.0 || rectUv.y >= 1.0) {
|
|
#ifdef CLIPPING_INVERSE
|
|
discard;
|
|
#endif
|
|
return;
|
|
}
|
|
|
|
vec2 clippingDistanceTextureDimensions = vec2(textureSize(clippingDistance, 0));
|
|
vec2 sampleOffset = max(1.0 / clippingDistanceTextureDimensions, vec2(0.005));
|
|
float dimension = float(extentsLength);
|
|
if (extentsLength > 2) {
|
|
dimension = ceil(log2(float(extentsLength)));
|
|
}
|
|
|
|
vec2 textureOffset = vec2(mod(float(regionIndex), dimension), floor(float(regionIndex) / dimension)) / dimension;
|
|
vec2 uv = textureOffset + rectUv / dimension;
|
|
|
|
float signedDistance = getSignedDistance(uv, clippingDistance);
|
|
|
|
#ifdef CLIPPING_INVERSE
|
|
if (signedDistance > 0.0) {
|
|
discard;
|
|
}
|
|
#else
|
|
if (signedDistance < 0.0) {
|
|
discard;
|
|
}
|
|
#endif
|
|
}
|