From e531a7a7622e723336629f91acc8127b764475dc Mon Sep 17 00:00:00 2001 From: BaekRyang Date: Wed, 5 Nov 2025 12:48:36 +0900 Subject: [PATCH] feat: Apply cumulative distortion from all overlapping areas MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 모든 겹치는 영역의 왜곡을 누적하여 적용하도록 변경 - 각 영역별 clamp를 제거하고, 모든 왜곡 계산 후 최종적으로 한 번만 clamp - 불필요한 `found` 변수 및 `break` 문 제거 --- dist/distortion.frag.glsl | 13 ++++++------- src/shaders/distortion.frag.glsl | 13 ++++++------- 2 files changed, 12 insertions(+), 14 deletions(-) diff --git a/dist/distortion.frag.glsl b/dist/distortion.frag.glsl index 20e6c31..aae8800 100644 --- a/dist/distortion.frag.glsl +++ b/dist/distortion.frag.glsl @@ -51,9 +51,8 @@ vec2 computeUV(vec2 xy, vec2 p0, vec2 p1, vec2 p2, vec2 p3) { void main() { vec2 xy = vUv * u_resolution; // 픽셀 좌표 vec2 texCoord = vUv; - bool found = false; - // Flutter 원본과 동일: 첫 번째 매칭되는 영역만 적용 + // 모든 겹치는 영역의 왜곡을 누적 적용 for (int i = 0; i < 8; i++) { 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) { vec2 uvCenter = vec2(0.5, 0.5); float distToCenter = distance(uv_local, uvCenter); - float maxUvRadius = 0.5; // Flutter 원본과 동일 + float maxUvRadius = 0.5; if (distToCenter < maxUvRadius) { 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]; 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); } \ No newline at end of file diff --git a/src/shaders/distortion.frag.glsl b/src/shaders/distortion.frag.glsl index 20e6c31..aae8800 100644 --- a/src/shaders/distortion.frag.glsl +++ b/src/shaders/distortion.frag.glsl @@ -51,9 +51,8 @@ vec2 computeUV(vec2 xy, vec2 p0, vec2 p1, vec2 p2, vec2 p3) { void main() { vec2 xy = vUv * u_resolution; // 픽셀 좌표 vec2 texCoord = vUv; - bool found = false; - // Flutter 원본과 동일: 첫 번째 매칭되는 영역만 적용 + // 모든 겹치는 영역의 왜곡을 누적 적용 for (int i = 0; i < 8; i++) { 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) { vec2 uvCenter = vec2(0.5, 0.5); float distToCenter = distance(uv_local, uvCenter); - float maxUvRadius = 0.5; // Flutter 원본과 동일 + float maxUvRadius = 0.5; if (distToCenter < maxUvRadius) { 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]; 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); } \ No newline at end of file