feat(all): 迁移扩展相关功能

This commit is contained in:
plum
2026-04-08 15:34:43 +08:00
parent ad2dd979eb
commit d7c0dba569
278 changed files with 25207 additions and 62 deletions
@@ -0,0 +1,22 @@
precision highp float;
precision highp int;
#include <utils>
#include <cylinder_utils>
in vec3 oldPos;
in vec3 newPos;
in vec3 ray;
out vec4 fragColor;
void main() {
float oldArea = length(dFdx(oldPos)) * length(dFdy(oldPos));
float newArea = length(dFdx(newPos)) * length(dFdy(newPos));
fragColor = vec4(oldArea / newArea * 0.2, 1.0, 0.0, 0.0);
vec3 refractedLight = refract(-light, vec3(0.0, 1.0, 0.0), IOR_AIR / IOR_WATER);
vec2 t = intersectCylinder(newPos, -refractedLight, poolRadius, -poolHeight, poolHeight * 2.0);
fragColor.r *= 1.0 / (1.0 + exp(-200.0 / (1.0 + 10.0 * (t.y - t.x)) * (newPos.y - refractedLight.y * t.y - poolHeight * 2.0 / 12.0)));
}
@@ -0,0 +1,42 @@
out vec3 oldPos;
out vec3 newPos;
out vec3 ray;
in vec3 position;
#include <utils>
#include <cylinder_utils>
vec3 project(vec3 origin, vec3 ray, vec3 refractedLight) {
vec2 tcyl = intersectCylinder(origin, ray, poolRadius, -poolHeight, poolHeight * 2.0);
origin += ray * tcyl.y;
float tplane = (-origin.y - poolHeight) / refractedLight.y;
return origin + refractedLight * tplane;
}
void main() {
// Collapse vertices outside the unit circle to avoid degenerate caustic triangles
if (position.x * position.x + position.y * position.y > 1.0) {
oldPos = vec3(0.0);
newPos = vec3(0.0);
ray = vec3(0.0);
gl_Position = vec4(0.0);
return;
}
vec4 info = texture(water, position.xy * 0.5 + 0.5);
info.ba *= 0.5;
vec3 normal = vec3(info.b, sqrt(1.0 - dot(info.ba, info.ba)), info.a);
vec3 refractedLight = refract(-light, vec3(0.0, 1.0, 0.0), IOR_AIR / IOR_WATER);
vec3 basePos = vec3(position.x * poolRadius, 0.0, position.y * poolRadius);
ray = refract(-light, normal, IOR_AIR / IOR_WATER);
oldPos = project(basePos, refractedLight, refractedLight);
newPos = project(basePos + vec3(0.0, info.r, 0.0), ray, refractedLight);
vec2 normalizedPos = newPos.xz / poolRadius;
vec2 refractedOffset = (refractedLight.xz / poolRadius) / refractedLight.y;
gl_Position = vec4(0.75 * (normalizedPos + refractedOffset), 0.0, 1.0);
}