public override float4[] CreateMap() { m_currentType = m_residualType; float4[] map = new float4[width * height]; var elevations = new List <float>(); for (int y = 0; y < height; y++) { for (int x = 0; x < width; x++) { elevations.Clear(); for (int i = -m_window; i <= m_window; i++) { for (int j = -m_window; j <= m_window; j++) { int xi = x + i; int yj = y + j; if (xi < 0 || xi >= width) { continue; } if (yj < 0 || yj >= height) { continue; } float h = GetNormalizedHeight(xi, yj); elevations.Add(h); } } float residual = 0; float h0 = GetNormalizedHeight(x, y); float4 color = white; switch (m_residualType) { case RESIDUAL_TYPE.ELEVATION: residual = h0; color = Colorize(residual, 0, true); break; case RESIDUAL_TYPE.MEAN: residual = MeanElevation(elevations); color = Colorize(residual, 0, true); break; case RESIDUAL_TYPE.DIFFERENCE: residual = DifferenceFromMeanElevation(h0, elevations); color = Colorize(residual, 4, false); break; case RESIDUAL_TYPE.STDEV: residual = DeviationFromMeanElevation(h0, elevations); color = Colorize(residual, 0.6f, true); break; case RESIDUAL_TYPE.DEVIATION: residual = DeviationFromMeanElevation(h0, elevations); color = Colorize(residual, 0.6f, false); break; case RESIDUAL_TYPE.PERCENTILE: residual = Percentile(h0, elevations); color = Colorize(residual, 0.3f, true); break; } map[x + y * width] = color; } } return(map); }
protected override void CreateMap() { m_currentType = m_residualType; Texture2D residualMap = new Texture2D(m_width, m_height); var elevations = new List <float>(); for (int y = 0; y < m_height; y++) { for (int x = 0; x < m_width; x++) { elevations.Clear(); for (int i = -m_window; i <= m_window; i++) { for (int j = -m_window; j <= m_window; j++) { int xi = x + i; int yj = y + j; if (xi < 0 || xi >= m_width) { continue; } if (yj < 0 || yj >= m_height) { continue; } float h = GetNormalizedHeight(xi, yj); elevations.Add(h); } } float residual = 0; float h0 = GetNormalizedHeight(x, y); Color color = Color.white; switch (m_residualType) { case RESIDUAL_TYPE.ELEVATION: residual = h0; color = Colorize(residual, 0, true); break; case RESIDUAL_TYPE.MEAN: residual = MeanElevation(elevations); color = Colorize(residual, 0, true); break; case RESIDUAL_TYPE.DIFFERENCE: residual = DifferenceFromMeanElevation(h0, elevations); color = Colorize(residual, 4, false); break; case RESIDUAL_TYPE.STDEV: residual = DeviationFromMeanElevation(h0, elevations); color = Colorize(residual, 0.6f, true); break; case RESIDUAL_TYPE.DEVIATION: residual = DeviationFromMeanElevation(h0, elevations); color = Colorize(residual, 0.6f, false); break; case RESIDUAL_TYPE.PERCENTILE: residual = Percentile(h0, elevations); color = Colorize(residual, 0.3f, true); break; } residualMap.SetPixel(x, y, color); } } residualMap.Apply(); m_material.mainTexture = residualMap; }