전장의 안개 기능 개선
미탐험 구역의 모든 오브젝트는 보이지 않음 적이 시야를 제공하는 문제 수정 높은 장애물은 더 먼 거리에서부터 보일 수 있음
This commit is contained in:
@@ -14,6 +14,14 @@ namespace Northbound
|
||||
public float updateInterval = 0.1f;
|
||||
public float fogHeight = 5f; // 안개 높이 (지형보다 약간 위)
|
||||
|
||||
[Header("Smoothing")]
|
||||
[Tooltip("Enable smooth circular vision edges")]
|
||||
public bool enableSmoothing = true;
|
||||
|
||||
[Tooltip("Smoothing strength (higher = smoother but more blurry)")]
|
||||
[Range(1, 5)]
|
||||
public int smoothingPasses = 2;
|
||||
|
||||
[Header("Colors")]
|
||||
public Color unexploredColor = new Color(0, 0, 0, 1f); // 완전히 어두움
|
||||
public Color exploredColor = new Color(0, 0, 0, 0.6f); // 반투명
|
||||
@@ -51,11 +59,12 @@ namespace Northbound
|
||||
return;
|
||||
}
|
||||
|
||||
// 텍스처 생성
|
||||
// 텍스처 생성 (Bilinear filtering for smooth edges)
|
||||
_fogTexture = new Texture2D(fogSystem.gridWidth, fogSystem.gridHeight)
|
||||
{
|
||||
filterMode = FilterMode.Bilinear,
|
||||
wrapMode = TextureWrapMode.Clamp
|
||||
wrapMode = TextureWrapMode.Clamp,
|
||||
anisoLevel = 0 // Disable anisotropic filtering for fog overlay
|
||||
};
|
||||
_colors = new Color[fogSystem.gridWidth * fogSystem.gridHeight];
|
||||
|
||||
@@ -133,10 +142,66 @@ namespace Northbound
|
||||
}
|
||||
}
|
||||
|
||||
// Apply smoothing if enabled
|
||||
if (enableSmoothing)
|
||||
{
|
||||
SmoothFogTexture(fogSystem.gridWidth, fogSystem.gridHeight);
|
||||
}
|
||||
|
||||
_fogTexture.SetPixels(_colors);
|
||||
_fogTexture.Apply();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Apply box blur smoothing to create smooth circular vision edges
|
||||
/// </summary>
|
||||
private void SmoothFogTexture(int width, int height)
|
||||
{
|
||||
Color[] smoothed = new Color[_colors.Length];
|
||||
|
||||
for (int pass = 0; pass < smoothingPasses; pass++)
|
||||
{
|
||||
for (int y = 0; y < height; y++)
|
||||
{
|
||||
for (int x = 0; x < width; x++)
|
||||
{
|
||||
int index = y * width + x;
|
||||
|
||||
// Box blur: average with neighbors
|
||||
float r = 0, g = 0, b = 0, a = 0;
|
||||
int samples = 0;
|
||||
|
||||
// Sample 3x3 kernel
|
||||
for (int dy = -1; dy <= 1; dy++)
|
||||
{
|
||||
for (int dx = -1; dx <= 1; dx++)
|
||||
{
|
||||
int nx = x + dx;
|
||||
int ny = y + dy;
|
||||
|
||||
if (nx >= 0 && nx < width && ny >= 0 && ny < height)
|
||||
{
|
||||
int nIndex = ny * width + nx;
|
||||
Color c = _colors[nIndex];
|
||||
r += c.r;
|
||||
g += c.g;
|
||||
b += c.b;
|
||||
a += c.a;
|
||||
samples++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Average
|
||||
smoothed[index] = new Color(r / samples, g / samples, b / samples, a / samples);
|
||||
}
|
||||
}
|
||||
|
||||
// Copy smoothed back to colors for next pass
|
||||
System.Array.Copy(smoothed, _colors, _colors.Length);
|
||||
}
|
||||
}
|
||||
|
||||
private void CreatePlaneMesh(FogOfWarSystem fogSystem)
|
||||
{
|
||||
MeshFilter meshFilter = GetComponent<MeshFilter>();
|
||||
|
||||
Reference in New Issue
Block a user