Spaces:
Running
Running
Upload folder using huggingface_hub
Browse files
ShapeTessellationShader.js
CHANGED
|
@@ -79,24 +79,24 @@ bool insidePolygon(vec2 p, int count) {
|
|
| 79 |
|
| 80 |
// --- Map point inside polygon to unit disk ---
|
| 81 |
vec2 mapToDisk(vec2 p, int count) {
|
| 82 |
-
// Compute
|
| 83 |
-
vec2
|
| 84 |
for (int i = 0; i < 4; i++) {
|
| 85 |
if (i >= count) break;
|
| 86 |
-
|
| 87 |
}
|
| 88 |
-
|
| 89 |
|
| 90 |
-
// Find max distance from
|
| 91 |
float maxDist = 0.0;
|
| 92 |
for (int i = 0; i < 4; i++) {
|
| 93 |
if (i >= count) break;
|
| 94 |
-
float d = length(u_vertices[i] -
|
| 95 |
if (d > maxDist) maxDist = d;
|
| 96 |
}
|
| 97 |
|
| 98 |
-
// Normalize:
|
| 99 |
-
vec2 offset = (p -
|
| 100 |
|
| 101 |
// Clamp to disk
|
| 102 |
float r = length(offset);
|
|
|
|
| 79 |
|
| 80 |
// --- Map point inside polygon to unit disk ---
|
| 81 |
vec2 mapToDisk(vec2 p, int count) {
|
| 82 |
+
// Compute ctr
|
| 83 |
+
vec2 ctr = vec2(0.0);
|
| 84 |
for (int i = 0; i < 4; i++) {
|
| 85 |
if (i >= count) break;
|
| 86 |
+
ctr += u_vertices[i];
|
| 87 |
}
|
| 88 |
+
ctr /= float(count);
|
| 89 |
|
| 90 |
+
// Find max distance from ctr to any vertex
|
| 91 |
float maxDist = 0.0;
|
| 92 |
for (int i = 0; i < 4; i++) {
|
| 93 |
if (i >= count) break;
|
| 94 |
+
float d = length(u_vertices[i] - ctr);
|
| 95 |
if (d > maxDist) maxDist = d;
|
| 96 |
}
|
| 97 |
|
| 98 |
+
// Normalize: ctr -> origin, scale so vertices sit near disk edge
|
| 99 |
+
vec2 offset = (p - ctr) / max(maxDist, 0.001);
|
| 100 |
|
| 101 |
// Clamp to disk
|
| 102 |
float r = length(offset);
|