Skip to content

Instantly share code, notes, and snippets.

@GarethIW
Created August 20, 2015 20:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save GarethIW/eb8bdef368a1d30f8a45 to your computer and use it in GitHub Desktop.
Save GarethIW/eb8bdef368a1d30f8a45 to your computer and use it in GitHub Desktop.
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