-
-
Save GarethIW/eb8bdef368a1d30f8a45 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
static void Quad(Vector3 topLeft, Vector3 topRight, Vector3 bottomRight,Vector3 bottomLeft,float voxelSize,VoxelFace voxel, bool backFace,float selfShadeIntensity,List<Vector3> vertices, List<int> indexes, List<Color32> colors, List<Vector2> uvs) | |
{ | |
int index = vertices.Count; | |
vertices.Add(bottomLeft * voxelSize); | |
vertices.Add(bottomRight * voxelSize); | |
vertices.Add(topLeft * voxelSize); | |
vertices.Add(topRight * voxelSize); | |
Color temp = IntToColor(voxel.Color); | |
int test1 = (((voxel.VertShade & Corners.TopRight) == Corners.TopRight) ? 1 : 0) + (((voxel.VertShade & Corners.BottomLeft) == Corners.BottomLeft) ? 1 : 0) + (((voxel.VertShade & Corners.TopLeft) == Corners.TopLeft) ? 1 : 0) + (((voxel.VertShade & Corners.BottomRight) == Corners.BottomRight) ? 1 : 0); | |
int test2 = (((voxel.VertShade & Corners.TopRight) == Corners.TopRight) ? 1 : 0) + (((voxel.VertShade & Corners.BottomLeft) == Corners.BottomLeft) ? 1 : 0); | |
int test3 = (((voxel.VertShade & Corners.TopLeft) == Corners.TopLeft) ? 1 : 0) + (((voxel.VertShade & Corners.BottomRight) == Corners.BottomRight) ? 1 : 0); | |
if (((test2 > test3) && (test1>2)) || ((test2<=test3) && (test1==1))) | |
{ | |
//colors.Add(new Color(temp.r * ((voxel.VertShade & Corners.TopLeft) == Corners.TopLeft ? (1f - selfShadeIntensity) : 1f), temp.g * ((voxel.VertShade & Corners.TopLeft) == Corners.TopLeft ? (1f - selfShadeIntensity) : 1f), temp.b * ((voxel.VertShade & Corners.TopLeft) == Corners.TopLeft ? (1f - selfShadeIntensity) : 1f), temp.a)); | |
//colors.Add(new Color(temp.r * ((voxel.VertShade & Corners.BottomLeft) == Corners.BottomLeft ? (1f - selfShadeIntensity) : 1f), temp.g * ((voxel.VertShade & Corners.BottomLeft) == Corners.BottomLeft ? (1f - selfShadeIntensity) : 1f), temp.b * ((voxel.VertShade & Corners.BottomLeft) == Corners.BottomLeft ? (1f - selfShadeIntensity) : 1f), temp.a)); | |
//colors.Add(new Color(temp.r * ((voxel.VertShade & Corners.TopRight) == Corners.TopRight ? (1f - selfShadeIntensity) : 1f), temp.g * ((voxel.VertShade & Corners.TopRight) == Corners.TopRight ? (1f - selfShadeIntensity) : 1f), temp.b * ((voxel.VertShade & Corners.TopRight) == Corners.TopRight ? (1f - selfShadeIntensity) : 1f), temp.a)); | |
//colors.Add(new Color(temp.r * ((voxel.VertShade & Corners.BottomRight) == Corners.BottomRight ? (1f - selfShadeIntensity) : 1f), temp.g * ((voxel.VertShade & Corners.BottomRight) == Corners.BottomRight ? (1f - selfShadeIntensity) : 1f), temp.b * ((voxel.VertShade & Corners.BottomRight) == Corners.BottomRight ? (1f - selfShadeIntensity) : 1f), temp.a)); | |
if(voxel.VertShade>0) | |
{ | |
colors.Add(new Color(temp.r * (1f - selfShadeIntensity), temp.g * (1f - selfShadeIntensity), temp.b *(1f - selfShadeIntensity), temp.a)); | |
colors.Add(new Color(temp.r * (1f - selfShadeIntensity), temp.g * (1f - selfShadeIntensity) , temp.b *(1f - selfShadeIntensity), temp.a)); | |
colors.Add(new Color(temp.r * (1f - selfShadeIntensity), temp.g *(1f - selfShadeIntensity) , temp.b * (1f - selfShadeIntensity) , temp.a)); | |
colors.Add(new Color(temp.r * (1f - selfShadeIntensity), temp.g * (1f - selfShadeIntensity), temp.b * (1f - selfShadeIntensity) , temp.a)); | |
} | |
else | |
{ | |
colors.Add(new Color(temp.r , temp.g , temp.b , temp.a)); | |
colors.Add(new Color(temp.r , temp.g, temp.b , temp.a)); | |
colors.Add(new Color(temp.r , temp.g, temp.b , temp.a)); | |
colors.Add(new Color(temp.r , temp.g, temp.b , temp.a)); | |
} | |
if (backFace) | |
{ | |
indexes.Add(index + 2); | |
indexes.Add(index); | |
indexes.Add(index + 1); | |
indexes.Add(index + 1); | |
indexes.Add(index + 3); | |
indexes.Add(index + 2); | |
} | |
else | |
{ | |
indexes.Add(index + 2); | |
indexes.Add(index + 3); | |
indexes.Add(index + 1); | |
indexes.Add(index + 1); | |
indexes.Add(index); | |
indexes.Add(index + 2); | |
} | |
} | |
else | |
{ | |
//colors.Add(new Color(temp.r * ((voxel.VertShade & Corners.TopLeft) == Corners.TopLeft ? (1f - selfShadeIntensity) : 1f), temp.g * ((voxel.VertShade & Corners.TopLeft) == Corners.TopLeft ? (1f - selfShadeIntensity) : 1f), temp.b * ((voxel.VertShade & Corners.TopLeft) == Corners.TopLeft ? (1f - selfShadeIntensity) : 1f), temp.a)); | |
//colors.Add(new Color(temp.r * ((voxel.VertShade & Corners.BottomLeft) == Corners.BottomLeft ? (1f - selfShadeIntensity) : 1f), temp.g * ((voxel.VertShade & Corners.BottomLeft) == Corners.BottomLeft ? (1f - selfShadeIntensity) : 1f), temp.b * ((voxel.VertShade & Corners.BottomLeft) == Corners.BottomLeft ? (1f - selfShadeIntensity) : 1f), temp.a)); | |
//colors.Add(new Color(temp.r * ((voxel.VertShade & Corners.TopRight) == Corners.TopRight ? (1f - selfShadeIntensity) : 1f), temp.g * ((voxel.VertShade & Corners.TopRight) == Corners.TopRight ? (1f - selfShadeIntensity) : 1f), temp.b * ((voxel.VertShade & Corners.TopRight) == Corners.TopRight ? (1f - selfShadeIntensity) : 1f), temp.a)); | |
//colors.Add(new Color(temp.r * ((voxel.VertShade & Corners.BottomRight) == Corners.BottomRight ? (1f - selfShadeIntensity) : 1f), temp.g * ((voxel.VertShade & Corners.BottomRight) == Corners.BottomRight ? (1f - selfShadeIntensity) : 1f), temp.b * ((voxel.VertShade & Corners.BottomRight) == Corners.BottomRight ? (1f - selfShadeIntensity) : 1f), temp.a)); | |
if (voxel.VertShade > 0) | |
{ | |
colors.Add(new Color(temp.r * (1f - selfShadeIntensity), temp.g * (1f - selfShadeIntensity), temp.b * (1f - selfShadeIntensity), temp.a)); | |
colors.Add(new Color(temp.r * (1f - selfShadeIntensity), temp.g * (1f - selfShadeIntensity), temp.b * (1f - selfShadeIntensity), temp.a)); | |
colors.Add(new Color(temp.r * (1f - selfShadeIntensity), temp.g * (1f - selfShadeIntensity), temp.b * (1f - selfShadeIntensity), temp.a)); | |
colors.Add(new Color(temp.r * (1f - selfShadeIntensity), temp.g * (1f - selfShadeIntensity), temp.b * (1f - selfShadeIntensity), temp.a)); | |
} | |
else | |
{ | |
colors.Add(new Color(temp.r, temp.g, temp.b, temp.a)); | |
colors.Add(new Color(temp.r, temp.g, temp.b, temp.a)); | |
colors.Add(new Color(temp.r, temp.g, temp.b, temp.a)); | |
colors.Add(new Color(temp.r, temp.g, temp.b, temp.a)); | |
} | |
if (backFace) | |
{ | |
indexes.Add(index + 3); | |
indexes.Add(index + 2); | |
indexes.Add(index); | |
indexes.Add(index); | |
indexes.Add(index + 1); | |
indexes.Add(index + 3); | |
} | |
else | |
{ | |
indexes.Add(index + 3); | |
indexes.Add(index + 1); | |
indexes.Add(index); | |
indexes.Add(index); | |
indexes.Add(index + 2); | |
indexes.Add(index + 3); | |
} | |
} | |
uvs.Add(new Vector2(1f, 1f)); | |
uvs.Add(new Vector2(0f, 1f)); | |
uvs.Add(new Vector2(0f, 0f)); | |
uvs.Add(new Vector2(1f, 0f)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment