private CoordSurfaceStatus lightValueAt(Coord chunkCo, Coord offsetStart, Vector3 nudgeV) { CoordLine testLine = new CoordLine(); //radius is chunkLength for (int i = 1; i < Chunk.CHUNKLENGTH; ++i) { Coord nudgeC = LightDataProvider.BlockCoordFromVectorBlockRadius(nudgeV, i); Coord totalOffset = offsetStart + nudgeC; //TEST if (i == 1) { testLine.start = CoordUtil.WorldCoordForChunkCoord(chunkCo) + totalOffset; } //END TEST // TODO: if already a result at this coord return that result. CoordSurfaceStatus surfaceStatus = m_noisePatch.coordIsAboveSurface(chunkCo, totalOffset); if (surfaceStatus == CoordSurfaceStatus.ABOVE_SURFACE || surfaceStatus == CoordSurfaceStatus.BELOW_SURFACE_SOLID) { // if (surfaceStatus == CoordSurfaceStatus.BELOW_SURFACE_SOLID) //TEST // { // testLine.end = CoordUtil.WorldCoordForChunkCoord(chunkCo) + totalOffset; // debugLinesAssistant.addCoordLine(testLine.start, testLine.end); //TEST // } return(surfaceStatus); } } return(CoordSurfaceStatus.BELOW_SURFACE_TRANSLUCENT); }
private byte lightValueAt(Coord chunkCo, Coord offsetStart, Direction dir) { // get a bunch of angles for the correct hemisphere // keep a list of coords that already resulted int result = 0; Vector3[] sampler = HemiSphereData.NorthernHemispherePoints30; int sampleCount = sampler.Length; Vector3 v; foreach (Vector3 vec in sampler) { v = LightDataProvider.ConvertFromYPosToDirection(vec, dir); CoordSurfaceStatus surfaceStatus = lightValueAt(chunkCo, offsetStart, v); if (surfaceStatus == CoordSurfaceStatus.ABOVE_SURFACE) { result++; // dead simple! // really want to word with the angles in question... } if (result > 2 * sampleCount / 3) { return(3); } } if (result > sampleCount / 3) { return(2); } if (result > sampleCount / 4) { return(1); } return(0); return((byte)(result / (2 * sampleCount / 3))); }
public Color32 lightDataForQuad(Quad quad, Direction dir, int normalOffset) { // if (debugLinesAssistant == null) // debugLinesAssistant = ChunkManager.debugLinesAssistant; if (m_noisePatch == null) { m_noisePatch = m_chunk.m_noisePatch; } if (m_noisePatch == null) { throw new Exception("what? noisepatch still null?"); } Coord chunkRelCoOfOrigin = chunkRelativeCoordFrom(quad, dir, normalOffset); if (dir != Direction.xpos && dir != Direction.zpos) { chunkRelCoOfOrigin += DirectionUtil.NudgeCoordForDirection(dir); } // check the nine blocks right in front. // for those that are not solid // check the windows. // Coord noisePatchRelCo = CoordUtil.PatchRelativeCoordWithChunkCoordOffset(chunkRelCoOfOrigin, new Coord(0)); int[] rows = new int[4]; // for (int i = 0; i < quad.dimensions.s; ++i) // { // for (int j = 0; j < quad.dimensions.t; ++j) // { // Coord quadOffset = DirectionUtil.CoordForPTwoAndNormalDirectionWithFaceAggregatorRules(new PTwo(i,j), dir); // int lightValue = (int) ( m_noisePatch.lightValueAtPatchRelativeCoord(noisePatchRelCo + quadOffset) * LIGHT_VALUE_CONVERTER); // // } // } // Coord chunkWoco = CoordUtil.WorldCoordForChunkCoord(this.chunkCoord); CoordSurfaceStatus surfaceStatus = m_noisePatch.coordIsAboveSurface(this.chunkCoord, chunkRelCoOfOrigin); // if (surfaceStatus == CoordSurfaceStatus.ABOVE_SURFACE) if (surfaceStatus == CoordSurfaceStatus.ABOVE_SURFACE) { return(new Color32(255, 255, 255, 255)); //for now...origin above == all above } //for now.... return(new Color32(0, 0, 0, 0)); // ********************************* // // int[] rows = new int[4]; for (int i = 0; i < quad.dimensions.s; ++i) { for (int j = 0; j < quad.dimensions.t; ++j) { Coord quadOffset = DirectionUtil.CoordForPTwoAndNormalDirectionWithFaceAggregatorRules(new PTwo(i, j), dir); byte lightVal = lightValueAt(this.chunkCoord, chunkRelCoOfOrigin + quadOffset, dir); rows[i] |= colorValueWith(j, lightVal); } } return(new Color32((byte)rows[0], (byte)rows[1], (byte)rows[2], (byte)rows[3])); }