varying vec3 MCPosition;
//Create uniform variables so dots can be spaced and scaled by user
uniform float Scale, DotSize;
uniform sampler2D RandomTex;
// Create colors as uniform variables so they can be easily changed
uniform vec4 BGColor, PolkaDotColor;
uniform vec3 DotOffset;
uniform vec2 PositionTextureMultiplier;
void main(void)
{
float radius2;
vec2 randomXY;
vec3 finalcolor = BGColor.xyz;
vec3 dotSpacing = vec3(Scale);
vec3 scaledXYZ = MCPosition * dotSpacing;
vec3 cell = floor(scaledXYZ);
vec3 offset = scaledXYZ - cell;
vec3 currentOffset;
vec4 random;
float priority = 999.0;
for(float i = -1.0; i <= 0.0; i++)
{
for(float j = -1.0; j <= 0.0; j++)
{
for(float k = -1.0; k <= 0.0; k++)
{
vec3 currentCell = cell + vec3(i, j, k);
vec3 cellOffset = offset - vec3(i, j, k);
randomXY = currentCell.xy * PositionTextureMultiplier + currentCell.z;// * 0.003;
random = texture2D(RandomTex, randomXY);
currentOffset = cellOffset - (vec3(0.5, 0.5, 0.5) + vec3(random));
radius2 = dot(currentOffset, currentOffset);
if(radius2 < priority)
{
//finalcolor = texture2D(RandomTex, randomXY + vec2(0.13,0.4)).xyz;
finalcolor = vec3(radius2 * 2.0);//texture2D(RandomTex, randomXY).xyz;
priority = radius2;
}
}
}
}
gl_FragColor = vec4(finalcolor, 1.0);
}