1 /** 2 Copyright: Copyright (c) 2017 Andrey Penechko. 3 License: $(WEB boost.org/LICENSE_1_0.txt, Boost License 1.0). 4 Authors: Andrey Penechko. 5 */ 6 module voxelman.world.mesh.blockmeshers.slope; 7 8 import voxelman.log; 9 import voxelman.container.buffer; 10 import voxelman.math; 11 import voxelman.geometry.cube; 12 13 import voxelman.world.block; 14 import voxelman.world.mesh.chunkmesh; 15 16 import voxelman.world.mesh.config; 17 import voxelman.world.mesh.sidemeshers.full; 18 import voxelman.world.mesh.sidemeshers.slope; 19 import voxelman.world.mesh.sidemeshers.utils; 20 import voxelman.world.mesh.tables.slope; 21 22 void makeColoredSlopeBlockMesh(BlockMeshingData data) 23 { 24 static if (RANDOM_BLOCK_TINT_ENABLED) 25 auto color = calcColor(data.blockIndex, data.color); 26 else 27 auto color = data.color; 28 29 if (data.sides != 0) 30 { 31 SideParams sideParams = SideParams(data.chunkPos, color, 0, data.buffer); 32 auto sideMasks = slopeShapeFromMeta(data.metadata).sideMasks; 33 34 foreach(ubyte i, sideMask; sideMasks) 35 { 36 auto cubeSide = cast(CubeSide)i; 37 switch(sideMask) { 38 case ShapeSideMask.empty: break; 39 case ShapeSideMask.full: 40 if (data.sides & (1 << cubeSide)) { 41 ubyte[4] occlusions = data.occlusionHandler(data.blockIndex, cubeSide); 42 meshFullSideOccluded(cubeSide, occlusions, sideParams); 43 } 44 break; 45 case ShapeSideMask.slope0: goto case; 46 case ShapeSideMask.slope1: goto case; 47 case ShapeSideMask.slope2: goto case; 48 case ShapeSideMask.slope3: 49 if (data.sides & (1 << cubeSide)) { 50 sideParams.rotation = cast(ubyte)(sideMask - ShapeSideMask.slope0); 51 ubyte[4] occlusions = data.occlusionHandler(data.blockIndex, cubeSide); 52 meshSlopeSideOccluded(cubeSide, occlusions, sideParams); 53 } 54 break; 55 default: break; 56 } 57 } 58 } 59 60 // mesh internal geometry 61 CubeSide[2] occlusionSides = slopeOcclusionSides[data.metadata]; 62 ubyte[4] occlusions0 = data.occlusionHandler(data.blockIndex, occlusionSides[0]); 63 ubyte[4] occlusions1 = data.occlusionHandler(data.blockIndex, occlusionSides[1]); 64 ubyte[4] occIndicies = slopeInternalOcclusionIndicies[data.metadata]; 65 ubyte[4] occlusionInternal = [ 66 occlusions0[occIndicies[0]], 67 occlusions1[occIndicies[2]], 68 occlusions1[occIndicies[3]], 69 occlusions0[occIndicies[1]]]; 70 71 immutable float mult = (shadowMultipliers[occlusionSides[0]] + shadowMultipliers[occlusionSides[1]])/2; 72 float[3] colorInternal = [mult * color[0], mult * color[1], mult * color[2]]; 73 74 meshOccludedQuad(*data.buffer, occlusionInternal, colorInternal, data.chunkPos, 75 slopeInternalIndicies[data.metadata], cubeVerticies.ptr); 76 }