public static void SetExtendAo(List <MeshTool.BlockSurface> surface, RayCastManager scene, int normalIndex, VecInt3 gpos) { for (int i = 0; i < surface.Count; i++) { VecInt3 pos = surface[i].pos; VecInt3 adjPos = new VecInt3(); adjPos.x = pos.x + Const.AdjacencyOffsetV[normalIndex].x + gpos.x; adjPos.y = pos.y + Const.AdjacencyOffsetV[normalIndex].y + gpos.y; adjPos.z = pos.z + Const.AdjacencyOffsetV[normalIndex].z + gpos.z; for (int v = 0; v < 4; v++) { int curLight = scene.getLight(adjPos.x, adjPos.y, adjPos.z); int num = 1; for (int b = 0; b < 3; b++) { int sx = Const.VertexSharedOffset[normalIndex, v, b, 0]; int sy = Const.VertexSharedOffset[normalIndex, v, b, 1]; int sz = Const.VertexSharedOffset[normalIndex, v, b, 2]; if (!scene.testBlock(adjPos.x + sx, adjPos.y + sy, adjPos.z + sz, RayCastBlockType.Opacity)) { curLight += scene.getLight(adjPos.x + sx, adjPos.y + sy, adjPos.z + sz); num++; } } surface[i].extendAo[v] = curLight / (Const.MaxLightIteration * num * 1.0f); } } }
public void updateLight(VecInt3 start, VecInt3 size) { List <VecInt3> extendSurface = new List <VecInt3>(); for (int i = start.x; i < start.x + size.x; i++) { for (int j = start.y; j < start.y + size.y; j++) { for (int k = start.z; k < start.z + size.z; k++) { if (airBlocksInSun[i, k] <= j) { light[i, j, k] = Const.MaxLightIteration; bool x0InSun = airBlocksInSun[i == 0 ? sizeX - 1 : i - 1, k] <= j; bool x1InSun = airBlocksInSun[i == sizeX - 1 ? 0 : i + 1, k] <= j; bool z0InSun = airBlocksInSun[i, k == 0 ? sizeZ - 1 : k - 1] <= j; bool z1InSun = airBlocksInSun[i, k == sizeZ - 1 ? 0 : k + 1] <= j; if ((!x0InSun) || (!x1InSun) || (!z0InSun) || (!z1InSun)) { extendSurface.Add(new VecInt3(i, j, k)); } } } } } byte currentLight = Const.MaxLightIteration - 1; while (currentLight > 0 && extendSurface.Count > 0) { //Debug.Log("light = " + currentLight + ", count = " + extendSurface.Count); List <VecInt3> newExtendSurface = new List <VecInt3>(); for (int s = 0; s < extendSurface.Count; s++) { VecInt3 v = extendSurface[s]; for (int f = 0; f < 6; f++) { VecInt3 offset = Const.AdjacencyOffsetV[f]; int ax = v.x + offset.x; int ay = v.y + offset.y; int az = v.z + offset.z; ax = ((ax % sizeX) + sizeX) % sizeX; az = ((az % sizeZ) + sizeZ) % sizeZ; if (ay >= 0 && ay < sizeY) { if (light[ax, ay, az] < currentLight && ((blocks[ax, ay, az] & RayCastBlockType.Opacity) == 0)) { newExtendSurface.Add(new VecInt3(ax, ay, az)); light[ax, ay, az] = (byte)currentLight; } } } } extendSurface = newExtendSurface; currentLight -= 1; } }
public void Encapsulate(VecInt3 point) { if (!valid) { min = point; max = point; valid = true; } else { min.x = Mathf.Min(min.x, point.x); min.y = Mathf.Min(min.y, point.y); min.z = Mathf.Min(min.z, point.z); max.x = Mathf.Max(max.x, point.x); max.y = Mathf.Max(max.y, point.y); max.z = Mathf.Max(max.z, point.z); } }
public BlockSurface(VecInt3 pos, short type, float[] ao, float[] raytraceAo, float[] extendAo) { this.pos = pos; this.type = type; smallAo = ao; this.raytraceAo = raytraceAo; this.extendAo = extendAo; }