diff options
| author | yum <yum.food.vr@gmail.com> | 2026-01-17 17:35:13 -0800 |
|---|---|---|
| committer | yum <yum.food.vr@gmail.com> | 2026-01-17 17:37:06 -0800 |
| commit | b925b4b1bf79e3d6f930a4d799a7194673b62bde (patch) | |
| tree | 1c45dbf95f66c4948ef6bcf64d9622b259fce624 /Scripts | |
| parent | c6923a553c98da7805407fe1fbfdb6c69c8d7530 (diff) | |
Impostors: continue work on depth, getting closer
Diffstat (limited to 'Scripts')
| -rw-r--r-- | Scripts/Impostors.cs | 17 |
1 files changed, 14 insertions, 3 deletions
diff --git a/Scripts/Impostors.cs b/Scripts/Impostors.cs index e1447b6..9769aa1 100644 --- a/Scripts/Impostors.cs +++ b/Scripts/Impostors.cs @@ -298,17 +298,25 @@ public class Impostors : MonoBehaviour Color[] origAlpha = preserveAlpha ? (Color[])alpha.Clone() : null; Color[] buffer = (Color[])pixels.Clone(); + bool[] filled = new bool[pixels.Length]; + for (int i = 0; i < pixels.Length; i++) + filled[i] = alpha[i].a > 0.01f; + bool[] filledNext = new bool[filled.Length]; + int[] dx = { -1, 1, 0, 0 }; int[] dy = { 0, 0, -1, 1 }; for (int iter = 0; iter < iterations; iter++) { + System.Array.Copy(pixels, buffer, pixels.Length); + System.Array.Copy(filled, filledNext, filled.Length); + for (int y = 0; y < h; y++) { for (int x = 0; x < w; x++) { int i = y * w + x; - if (alpha[i].a > 0.01f) continue; + if (filled[i]) continue; Color sum = Color.clear; int count = 0; @@ -317,7 +325,7 @@ public class Impostors : MonoBehaviour int nx = x + dx[d], ny = y + dy[d]; if (nx < 0 || nx >= w || ny < 0 || ny >= h) continue; int ni = ny * w + nx; - if (alpha[ni].a > 0.01f || (iter > 0 && pixels[ni].a > 0)) + if (filled[ni]) { sum += pixels[ni]; count++; @@ -327,10 +335,12 @@ public class Impostors : MonoBehaviour { buffer[i] = sum / count; buffer[i].a = 1; + filledNext[i] = true; } } } - var tmp = pixels; pixels = buffer; buffer = tmp; + var tmpFilled = filled; filled = filledNext; filledNext = tmpFilled; + var tmpPixels = pixels; pixels = buffer; buffer = tmpPixels; } if (preserveAlpha) @@ -488,6 +498,7 @@ public class Impostors : MonoBehaviour impostorMaterial.SetFloat("_Impostors_Sphere_Radius", sphere_radius_); impostorMaterial.SetFloat("_Impostors_Near_Clip", nearClippingDistance); impostorMaterial.SetFloat("_Impostors_Far_Clip", sphere_radius_ * 2f + nearClippingDistance); + impostorMaterial.SetFloat("_ZTest", (float)UnityEngine.Rendering.CompareFunction.LessEqual); impostorMaterial.SetFloat("_Impostors_Enabled", 1); impostorMaterial.SetFloat("_Impostors_Parallax", 1); impostorMaterial.SetFloat("_Cull", (float)UnityEngine.Rendering.CullMode.Front); |
