1 /**
2 Copyright: Copyright (c) 2017-2018 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.sidemeshers.slope;
7 
8 import voxelman.log;
9 import voxelman.container.buffer;
10 import voxelman.math;
11 import voxelman.geometry;
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.utils;
18 import voxelman.world.mesh.tables.slope;
19 
20 void meshSlopeSideOccluded(CubeSide side, ubyte[4] cornerOcclusion, SideParams d)
21 {
22 	immutable float mult = shadowMultipliers[side];
23 
24 	// apply fake lighting
25 	float r = mult * d.color.r;
26 	float g = mult * d.color.g;
27 	float b = mult * d.color.b;
28 
29 	// Ambient occlusion multipliers
30 	//float vert0AoMult = occlusionTable[cornerOcclusion[0]];
31 	//float vert1AoMult = occlusionTable[cornerOcclusion[1]];
32 	//float vert2AoMult = occlusionTable[cornerOcclusion[2]];
33 	//float vert3AoMult = occlusionTable[cornerOcclusion[3]];
34 	ubyte vert0AoMult = cast(ubyte)(255 * occlusionTable[cornerOcclusion[0]]);
35 	ubyte vert1AoMult = cast(ubyte)(255 * occlusionTable[cornerOcclusion[1]]);
36 	ubyte vert2AoMult = cast(ubyte)(255 * occlusionTable[cornerOcclusion[2]]);
37 	ubyte vert3AoMult = cast(ubyte)(255 * occlusionTable[cornerOcclusion[3]]);
38 	immutable ubyte[4] finalColors = [vert0AoMult, vert1AoMult, vert2AoMult, vert3AoMult];
39 	immutable ubyte[2][4] uvs = [d.uv, [d.uv[0], cast(ubyte)(d.uv[1]+1)], [cast(ubyte)(d.uv[0]+1), cast(ubyte)(d.uv[1]+1)], [cast(ubyte)(d.uv[0]+1), d.uv[1]]];
40 
41 	//static if (AO_DEBUG_ENABLED)
42 	//	immutable ubyte[3][4] finalColors = getDebugAOColors(cornerOcclusion);
43 	//else
44 	//	immutable ubyte[3][4] finalColors = [
45 	//		[cast(ubyte)(vert0AoMult * r), cast(ubyte)(vert0AoMult * g), cast(ubyte)(vert0AoMult * b)],
46 	//		[cast(ubyte)(vert1AoMult * r), cast(ubyte)(vert1AoMult * g), cast(ubyte)(vert1AoMult * b)],
47 	//		[cast(ubyte)(vert2AoMult * r), cast(ubyte)(vert2AoMult * g), cast(ubyte)(vert2AoMult * b)],
48 	//		[cast(ubyte)(vert3AoMult * r), cast(ubyte)(vert3AoMult * g), cast(ubyte)(vert3AoMult * b)]];
49 
50 	ubyte[3] indicies = slopeFaceIndicies[d.rotation][side];
51 	ubyte[3] colorIndicies = slopeColorIndicies[d.rotation];
52 	MeshVertex[] buf = d.buffer.voidPut(3);
53 	buf[0].set(
54 		cubeVerticies[indicies[0]][0] + d.blockPos.x,
55 		cubeVerticies[indicies[0]][1] + d.blockPos.y,
56 		cubeVerticies[indicies[0]][2] + d.blockPos.z,
57 		uvs[colorIndicies[0]],
58 		finalColors[colorIndicies[0]]);
59 	buf[1].set(
60 		cubeVerticies[indicies[1]][0] + d.blockPos.x,
61 		cubeVerticies[indicies[1]][1] + d.blockPos.y,
62 		cubeVerticies[indicies[1]][2] + d.blockPos.z,
63 		uvs[colorIndicies[1]],
64 		finalColors[colorIndicies[1]]);
65 	buf[2].set(
66 		cubeVerticies[indicies[2]][0] + d.blockPos.x,
67 		cubeVerticies[indicies[2]][1] + d.blockPos.y,
68 		cubeVerticies[indicies[2]][2] + d.blockPos.z,
69 		uvs[colorIndicies[2]],
70 		finalColors[colorIndicies[2]]);
71 }