feat: Apply cumulative distortion from all overlapping areas
- 모든 겹치는 영역의 왜곡을 누적하여 적용하도록 변경 - 각 영역별 clamp를 제거하고, 모든 왜곡 계산 후 최종적으로 한 번만 clamp - 불필요한 `found` 변수 및 `break` 문 제거
This commit is contained in:
parent
fed9dc7606
commit
e531a7a762
13
dist/distortion.frag.glsl
vendored
13
dist/distortion.frag.glsl
vendored
@ -51,9 +51,8 @@ vec2 computeUV(vec2 xy, vec2 p0, vec2 p1, vec2 p2, vec2 p3) {
|
|||||||
void main() {
|
void main() {
|
||||||
vec2 xy = vUv * u_resolution; // 픽셀 좌표
|
vec2 xy = vUv * u_resolution; // 픽셀 좌표
|
||||||
vec2 texCoord = vUv;
|
vec2 texCoord = vUv;
|
||||||
bool found = false;
|
|
||||||
|
|
||||||
// Flutter 원본과 동일: 첫 번째 매칭되는 영역만 적용
|
// 모든 겹치는 영역의 왜곡을 누적 적용
|
||||||
for (int i = 0; i < 8; i++) {
|
for (int i = 0; i < 8; i++) {
|
||||||
if (i >= u_numAreas) break;
|
if (i >= u_numAreas) break;
|
||||||
|
|
||||||
@ -68,19 +67,19 @@ void main() {
|
|||||||
if (uv_local.x >= 0.0 && uv_local.x <= 1.0 && uv_local.y >= 0.0 && uv_local.y <= 1.0) {
|
if (uv_local.x >= 0.0 && uv_local.x <= 1.0 && uv_local.y >= 0.0 && uv_local.y <= 1.0) {
|
||||||
vec2 uvCenter = vec2(0.5, 0.5);
|
vec2 uvCenter = vec2(0.5, 0.5);
|
||||||
float distToCenter = distance(uv_local, uvCenter);
|
float distToCenter = distance(uv_local, uvCenter);
|
||||||
float maxUvRadius = 0.5; // Flutter 원본과 동일
|
float maxUvRadius = 0.5;
|
||||||
|
|
||||||
if (distToCenter < maxUvRadius) {
|
if (distToCenter < maxUvRadius) {
|
||||||
float influence = 1.0 - smoothstep(0.0, maxUvRadius, distToCenter);
|
float influence = 1.0 - smoothstep(0.0, maxUvRadius, distToCenter);
|
||||||
// dragVector는 정규화된 좌표(0-1)이므로 바로 사용 (Flutter와 동일한 결과)
|
// dragVector는 정규화된 좌표(0-1)이므로 바로 사용
|
||||||
vec2 distortion = u_dragVectors[i] * influence * u_distortionStrengths[i];
|
vec2 distortion = u_dragVectors[i] * influence * u_distortionStrengths[i];
|
||||||
texCoord += distortion;
|
texCoord += distortion;
|
||||||
texCoord = clamp(texCoord, 0.0, 1.0);
|
// clamp를 루프 내에서 제거: 모든 왜곡을 완전히 누적한 후 마지막에 한 번만 clamp
|
||||||
}
|
}
|
||||||
found = true;
|
|
||||||
break; // Flutter 원본처럼 첫 번째 영역만 적용
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 모든 왜곡을 누적한 후 최종적으로 한 번만 clamp
|
||||||
|
texCoord = clamp(texCoord, 0.0, 1.0);
|
||||||
gl_FragColor = texture2D(u_texture, texCoord);
|
gl_FragColor = texture2D(u_texture, texCoord);
|
||||||
}
|
}
|
||||||
@ -51,9 +51,8 @@ vec2 computeUV(vec2 xy, vec2 p0, vec2 p1, vec2 p2, vec2 p3) {
|
|||||||
void main() {
|
void main() {
|
||||||
vec2 xy = vUv * u_resolution; // 픽셀 좌표
|
vec2 xy = vUv * u_resolution; // 픽셀 좌표
|
||||||
vec2 texCoord = vUv;
|
vec2 texCoord = vUv;
|
||||||
bool found = false;
|
|
||||||
|
|
||||||
// Flutter 원본과 동일: 첫 번째 매칭되는 영역만 적용
|
// 모든 겹치는 영역의 왜곡을 누적 적용
|
||||||
for (int i = 0; i < 8; i++) {
|
for (int i = 0; i < 8; i++) {
|
||||||
if (i >= u_numAreas) break;
|
if (i >= u_numAreas) break;
|
||||||
|
|
||||||
@ -68,19 +67,19 @@ void main() {
|
|||||||
if (uv_local.x >= 0.0 && uv_local.x <= 1.0 && uv_local.y >= 0.0 && uv_local.y <= 1.0) {
|
if (uv_local.x >= 0.0 && uv_local.x <= 1.0 && uv_local.y >= 0.0 && uv_local.y <= 1.0) {
|
||||||
vec2 uvCenter = vec2(0.5, 0.5);
|
vec2 uvCenter = vec2(0.5, 0.5);
|
||||||
float distToCenter = distance(uv_local, uvCenter);
|
float distToCenter = distance(uv_local, uvCenter);
|
||||||
float maxUvRadius = 0.5; // Flutter 원본과 동일
|
float maxUvRadius = 0.5;
|
||||||
|
|
||||||
if (distToCenter < maxUvRadius) {
|
if (distToCenter < maxUvRadius) {
|
||||||
float influence = 1.0 - smoothstep(0.0, maxUvRadius, distToCenter);
|
float influence = 1.0 - smoothstep(0.0, maxUvRadius, distToCenter);
|
||||||
// dragVector는 정규화된 좌표(0-1)이므로 바로 사용 (Flutter와 동일한 결과)
|
// dragVector는 정규화된 좌표(0-1)이므로 바로 사용
|
||||||
vec2 distortion = u_dragVectors[i] * influence * u_distortionStrengths[i];
|
vec2 distortion = u_dragVectors[i] * influence * u_distortionStrengths[i];
|
||||||
texCoord += distortion;
|
texCoord += distortion;
|
||||||
texCoord = clamp(texCoord, 0.0, 1.0);
|
// clamp를 루프 내에서 제거: 모든 왜곡을 완전히 누적한 후 마지막에 한 번만 clamp
|
||||||
}
|
}
|
||||||
found = true;
|
|
||||||
break; // Flutter 원본처럼 첫 번째 영역만 적용
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 모든 왜곡을 누적한 후 최종적으로 한 번만 clamp
|
||||||
|
texCoord = clamp(texCoord, 0.0, 1.0);
|
||||||
gl_FragColor = texture2D(u_texture, texCoord);
|
gl_FragColor = texture2D(u_texture, texCoord);
|
||||||
}
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user