shaderiin muutoksia

This commit is contained in:
2025-07-29 19:14:56 +03:00
parent c6cccbcb0e
commit 700d7caf6d
2 changed files with 194 additions and 268 deletions

View File

@ -4,21 +4,14 @@ out vec4 o;
const float PI = 3.14159265; const float PI = 3.14159265;
const float TAU = (2. * PI); const float TAU = (2. * PI);
const float PHI = sqrt(5.) * 0.5 + 0.5; const float PHI = sqrt(5.) * 0.5 + 0.5;
layout(location = 0) uniform float syncs[12]; layout(location = 0) uniform float syncs[11];
layout(location = 20) uniform float fft_output[512]; // FFT_SIZE / 4 layout(location = 20) uniform float fft_output[512]; // FFT_SIZE / 4
layout(location = 600) uniform vec3 shapes[15]; // shapes - x = horizontal position, y = vertical position, z = length layout(location = 600) uniform vec3 shapes[15]; // shapes - x = horizontal position, y = vertical position, z = length
layout(location = 700) uniform vec3 test; // shapes test layout(location = 700) uniform vec3 test; // shapes test
//layout(binding = 1) uniform sampler2D u_hexGridTex; //uniform sampler2D u_fft_texture; //layout(binding = 1) uniform sampler2D u_hexGridTex; //uniform sampler2D u_fft_texture;
layout(binding = 0) uniform sampler2D u_ShapesTex; // uniform sampler2D shapes texture
float u_time = syncs[0];
vec3 palette(float t){ layout(binding = 0) uniform sampler2D u_ShapesTex; // uniform sampler2D shapes texture
vec3 a=vec3(0.46,0.2,0.94); // float u_time = syncs[0];
vec3 b=vec3(0.66,0.64,0.77);
vec3 c=vec3(0.91,0.62,0.97);
vec3 d=vec3(0.26,0.2,0.84);
return a+b*cos(6.28318*(c*t+d));
}
vec2 getUV() { vec2 getUV() {
const vec2 scale = vec2(0.00104166667, 0.00185185185); const vec2 scale = vec2(0.00104166667, 0.00185185185);
@ -44,19 +37,6 @@ float fHexagonCircumcircle(vec3 p, vec2 h) {
return max(q.y - h.y, max(q.x * sqrt(3.) * 0.5 + q.z * 0.5, q.z) - h.x); return max(q.y - h.y, max(q.x * sqrt(3.) * 0.5 + q.z * 0.5, q.z) - h.x);
} }
float hexPylon(vec3 p, vec2 h) {//float r, float ht){
//vec3 p = vec3(p.x, p.z, p2.y);
vec3 b = vec3(h.x, h.y, h.x);
// Hexagon.
p.xz = abs(p.xz);
p.xz = vec2(p.x*.866025 + p.z*.5, p.z);
// The ".015" is a subtle rounding factor. Zero gives sharp edges,
// and larger numbers give a more rounded look.
return length(max(abs(p) - b + .15, 0.)) - .15;
}
// Return local coordinates inside hex AND axial ID // Return local coordinates inside hex AND axial ID
struct HexData { struct HexData {
vec3 local; // Local position inside hex vec3 local; // Local position inside hex
@ -64,8 +44,8 @@ struct HexData {
}; };
HexData hexTile(vec3 p, float radius) { HexData hexTile(vec3 p, float radius) {
float q = (sqrt(3.0)/3.0 * p.x - 1.0/3.0 * p.z) / radius; float q = (sqrt(3.0) / 3.0 * p.x - 1.0 / 3.0 * p.z) / radius;
float r = (2.0/3.0 * p.z) / radius; float r = (2.0 / 3.0 * p.z) / radius;
float rq = round(q); float rq = round(q);
float rr = round(r); float rr = round(r);
@ -75,8 +55,10 @@ HexData hexTile(vec3 p, float radius) {
float dr = abs(rr - r); float dr = abs(rr - r);
float ds = abs(rs + q + r); float ds = abs(rs + q + r);
if (dq > dr && dq > ds) rq = -rr - rs; if(dq > dr && dq > ds)
else if (dr > ds) rr = -rq - rs; rq = -rr - rs;
else if(dr > ds)
rr = -rq - rs;
float hx = radius * sqrt(3.0) * (rq + rr * 0.5); float hx = radius * sqrt(3.0) * (rq + rr * 0.5);
float hz = radius * 1.5 * rr; float hz = radius * 1.5 * rr;
@ -87,11 +69,6 @@ HexData hexTile(vec3 p, float radius) {
return outData; return outData;
} }
struct HexData {
vec3 local;
vec2 axial;
};
float hexDistance(vec2 axial) { float hexDistance(vec2 axial) {
float q = axial.x; float q = axial.x;
float r = axial.y; float r = axial.y;
@ -99,9 +76,20 @@ float hexDistance(vec2 axial) {
return max(abs(q), max(abs(r), abs(s))); return max(abs(q), max(abs(r), abs(s)));
} }
float sdSphere(vec3 p, float r) {
return length(p) - r;
}
float sdSphere(vec3 p, float r){ float hexPylon(vec3 p, vec2 h) {
return length(p) -r; //vec3 p = vec3(p.x, p.z, p2.y);
vec3 b = vec3(h.x, h.y, h.x);
// Hexagon.
p.xz = abs(p.xz);
p.xz = vec2(p.x * .866025 + p.z * .5, p.z);
// The ".015" is a subtle rounding factor. Zero gives sharp edges,
// and larger numbers give a more rounded look.
return length(max(abs(p) - b + .15, 0.)) - .15;
} }
////////////// //////////////
@ -109,58 +97,59 @@ float sdSphere(vec3 p, float r){
////////////// //////////////
// instructions -> opU( { float to union with } , vec2( {put shape here}, {put material here} ) ) // instructions -> opU( { float to union with } , vec2( {put shape here}, {put material here} ) )
vec2 opU( vec2 d1, vec2 d2 ) vec2 opU(vec2 d1, vec2 d2) {
{ return (d1.x < d2.x) ? d1 : d2;
return (d1.x<d2.x) ? d1 : d2;
} }
// float opU( float d1, float d2 ) { return -max( -d1, -d2 ); } // float opU( float d1, float d2 ) { return -max( -d1, -d2 ); }
vec2 mapScene(in vec3 p) { vec2 mapScene(in vec3 p) {
vec2 res = vec2( p.y, 0.0 ); float res = 1e8;
float mat = 0.;
float mat = 1.; float hexRadius = 0.85;
float d = 1e9;
float a = 0.;
float hexRadius = 0.83;
vec3 hexpos = vec3(p.x, p.y - 2.5, p.z); vec3 hexpos = vec3(p.x, p.y - 2.5, p.z);
HexData hex = hexTile(hexpos, 1.5);
HexData hex = hexTile(hexpos, 1.0);
float distFromCenter = hexDistance(hex.axial); float distFromCenter = hexDistance(hex.axial);
int fftIndex = int(clamp(distFromCenter +1.0, 0.0, 511.0)); // tweak 15.0 to taste int fftIndex = int(clamp(distFromCenter + 1.0, 0.0, 511.0));
float fftVal = fft_output[fftIndex]; float fftVal = fft_output[fftIndex];
float hexHeight = 1.0 + fftVal * 3.0; float hexHeight = 1.0 + fftVal * 4.0;
// Rotate individual hex tiles if needed // Rotate individual hex tiles if needed
vec3 r = hex.local; vec3 r = hex.local;
//r.yz *= rot2D(1.0); // r.yz *= rot2D(PI * 0.5);
r.xz *= rot2D(0.5); r.xz *= rot2D(0.5);
float d1 = hexPylon(vec3(r.x,(r.y-hexHeight/2),r.z), vec2(hexRadius, hexHeight/2)); //float d1 = hexPylon(vec3(r.x, (r.y + hexHeight / 2), r.z), vec2(hexRadius, hexHeight / 2));
res = min(res, vec2(d1,0.)); float d1 = hexPylon(vec3(r.x, r.y, r.z), vec2(hexRadius, hexHeight));
float gridSize2 = 16.; res = (d1 < res) ? d1 : res;
for(float j = 0.; j < gridSize2; j++) {
for(float i = 0.; i < gridSize2; i++) { /* const float gridSize = 16.;
for(float j = 0.; j < gridSize; j++) {
for(float i = 0.; i < gridSize; i++) {
ivec2 texSize = textureSize(u_ShapesTex, 0); ivec2 texSize = textureSize(u_ShapesTex, 0);
vec2 texCoord = (vec2(i, j)) / vec2(texSize); vec2 texCoord = (vec2(i, j)) / vec2(texSize);
vec4 shapeData = texture(u_ShapesTex, texCoord); // RGBA: x, y, length, active vec4 shapeData = texture(u_ShapesTex, texCoord); // RGBA: x, y, length, active
float shapeActive = shapeData.a; float shapeActive = shapeData.a;
if(shapeActive < 0.5) continue;
if(shapeActive < 0.5)
continue;
vec3 shapePos = p - vec3(-70.0 + (shapeData.x * 2.), 12. + (shapeData.y * 80.), 0.0); vec3 shapePos = p - vec3(-70.0 + (shapeData.x * 2.), 12. + (shapeData.y * 80.), 0.0);
float a = sdSphere(shapePos, 0.8); float a = sdSphere(shapePos, 0.8);
res = min(res, a);
res = min(res, vec2(a, 1.)); if(res == a) {
mat = 1.0;
}
} }
} }*/
return res; return vec2(res, mat);
} }
//////////////// ////////////////
@ -170,64 +159,25 @@ vec2 mapScene(in vec3 p) {
vec3 castRay(vec3 ro, vec3 rd, inout vec3 pos) { vec3 castRay(vec3 ro, vec3 rd, inout vec3 pos) {
float mat = 0.; float mat = 0.;
float hit = 0.; float hit = 0.;
vec3 d; float t = 0.;
float t = 0.,ad,tmax=400.; // total distance travelled
const float tolerance = 0.001;
const float Z_REPEAT_DIST = 2.;
vec2 res; vec2 res;
// Raymarching // Raymarching
for (int i = 0; i < 50; i++) { for(int i = 0; i < 20; i++) {
pos = ro + rd * t; pos = ro + rd * t;
res = mapScene(pos); // Get distance to objects res = mapScene(pos); // Get distance to objects, x = dist, y = material
ad = abs(res.x);
mat = res.y; mat = res.y;
if (t > tmax) break; t += res.x; // "march" the ray
if (ad < tolerance*(t*0.0125 + 1.0)) {
hit = 1.0; // if(abs(t) < tolerance * (t * 0.0125 + 1.0)) {
if(abs(res.x) < 0.0001) {
hit = 1.;
break; break;
} }
t += res.x; // "march" the ray if(t > 200)
break;
} }
// t -= Z_REPEAT_DIST*1.;
//
// for( int i=0; i<30; i++ )
// {
// vec3 pos2 = ro + rd * t;
// res = mapScene(pos2); // get distance to objects
// ad = abs(res.x);
// mat = res.y;
// if (ad < (tolerance))
// {
// hit = 1.0;
// pos = pos2;
// break;
// }
// if (t > tmax) break;
// t += min(d.x, Z_REPEAT_DIST/2.0); // "march" the ray
// }
//if (t >= tmax) {
// t= - 1.0;
// hit = 0.;
//}
//Reduced from 40 to 24 steps
// for(int i = 0; i < 30; i++) {
// pos = ro + rd * t;
// vec2 res = mapScene(pos);
// // Increase step size multiplier for faster marching
// t += res.x;
// mat = res.y;
// if(t > 400.) { // Reduced max distance
// break;
// }
// if(res.x < 0.00001 * (t*0.00125 + 1.0)) { // Less precise hit detection
// hit = 1.;
// break;
// }
// }
// This will break fog effect
//if (t > 100.)
// t = 0.;
return vec3(t, mat, hit); return vec3(t, mat, hit);
} }
@ -288,16 +238,28 @@ vec3 addPointLight(vec3 lightPos, vec3 lightColor, float intensity, vec3 worldPo
return (diffuse + specular * fresnel) * shadow; return (diffuse + specular * fresnel) * shadow;
} }
vec3 applyFog(vec3 col, float t, vec3 rd, vec3 lightDir, float b ) { float getAmbientOcc(vec3 p, vec3 n) {
float occ = 0.;
float weight = 1.;
for(int i = 0; i < 8; i++) {
float len = 0.01 + 0.02 * float(i * i);
float dist = mapScene(p + n * len).x;
occ += (len - dist) * weight;
weight *= 0.85;
}
return 1.0 - clamp(0.6 * occ, 0., 1.);
}
vec3 applyFog(vec3 col, float t, vec3 rd, vec3 lightDir, float fogAmount) {
float syncsBass = clamp((syncs[1] + syncs[2] + syncs[3]), 0., 1.); float syncsBass = clamp((syncs[1] + syncs[2] + syncs[3]), 0., 1.);
float fogAmount = 1.0 - exp(-t*b); float fogAmount2 = 1.0 - exp(-t * fogAmount);
float sunAmount = max( dot(rd, lightDir), 0.0 ); float sunAmount = max(dot(rd, lightDir), 0.0);
vec3 fogColor = mix( vec3(0.2667, 0.2941, 0.3451), // blue // highlight color
vec3(0.302, 0.3176, 0.3725), // yellow vec3 fogColor = mix(vec3(0.2706, 0.2706, 0.2863), vec3(0.2314, 0.2314, 0.2314), // Main color
pow(sunAmount, syncsBass * 5.0) ); pow(sunAmount, syncsBass * 1.0));
return mix( col, fogColor, fogAmount ); return mix(col, fogColor, fogAmount2);
} }
// Point light with no shadow and radius based falloff // Point light with no shadow and radius based falloff
@ -308,8 +270,8 @@ vec3 addPointLightNoShadow(vec3 lightPos, vec3 lightColor, float intensity, floa
lightDir = normalize(lightDir); lightDir = normalize(lightDir);
// Attenuation (radius based falloff) // Attenuation (radius based falloff)
float attenuation = clamp(intensity - lightDistance*lightDistance/(radius*radius), 0.0, 1.0); float attenuation = clamp(intensity - lightDistance * lightDistance / (radius * radius), 0.0, 1.0);
// Diffuse lighting (Lambert) // Diffuse lighting (Lambert)
float NdotL = max(dot(normal, lightDir), 0.0); float NdotL = max(dot(normal, lightDir), 0.0);
vec3 diffuse = lightColor * NdotL * attenuation; vec3 diffuse = lightColor * NdotL * attenuation;
@ -331,7 +293,6 @@ vec3 addPointLightNoShadow(vec3 lightPos, vec3 lightColor, float intensity, floa
return diffuse + specular * fresnel; return diffuse + specular * fresnel;
} }
/*vec3 addPointLight(vec3 lightPos, vec3 lightColor, float intensity, vec3 worldPos, vec3 viewDir, vec3 normal) { /*vec3 addPointLight(vec3 lightPos, vec3 lightColor, float intensity, vec3 worldPos, vec3 viewDir, vec3 normal) {
vec3 lightDir = normalize(lightPos - worldPos); vec3 lightDir = normalize(lightPos - worldPos);
float lightDistance = length(lightPos - worldPos); float lightDistance = length(lightPos - worldPos);
@ -354,14 +315,14 @@ vec3 addPointLightNoShadow(vec3 lightPos, vec3 lightColor, float intensity, floa
} }
*/ */
vec3 shading(vec3 v, vec3 n, vec3 dir, float material) { vec3 shading(vec3 p, vec3 n, vec3 dir, float material) {
float shininess = 0.01; float shininess = 0.01;
vec3 outMaterial = vec3(0.); vec3 outMaterial = vec3(0.);
if(material == 0.) { if(material == 0.) {
outMaterial = vec3(0.8314, 0.2941, 0.2941); outMaterial = vec3(0.4941, 0.4941, 0.4941);
shininess = 0.1; shininess = 0.6;
} else if(material == 1.) { } else if(material == 1.) {
outMaterial = vec3(0.6196, 0.6118, 0.6118); outMaterial = vec3(0.6196, 0.6118, 0.6118);
shininess = .7; shininess = .7;
@ -380,8 +341,8 @@ vec3 shading(vec3 v, vec3 n, vec3 dir, float material) {
} }
vec3 lights = vec3(0.); vec3 lights = vec3(0.);
lights += addPointLight(vec3(0., 40.0, -10.), vec3(0.77, 0.26, 0.73), 30.0, v, dir, n, shininess); lights += addPointLight(vec3(0., 20.0, 10.), vec3(0.77, 0.26, 0.73), 15.0, p, dir, n, shininess);
lights += addPointLight(vec3(0., 20.0, 15.), vec3(0.77, 0.26, 0.73), 30.0, v, dir, n, shininess); lights += addPointLight(vec3(-10., 20.0, -10.), vec3(0.18, 0.61, 0.86), 15., p, dir, n, shininess);
// LIGHTS IN HEX GRID PATTERN // LIGHTS IN HEX GRID PATTERN
/* /*
@ -407,12 +368,12 @@ vec3 shading(vec3 v, vec3 n, vec3 dir, float material) {
} }
*/ */
vec3 lightDir = vec3(0., 1., -3); vec3 lightDir = vec3(0., 2., 3);
//float sun_dif = clamp(dot(n, lightDir), 0., 1.); //float sun_dif = clamp(dot(n, lightDir), 0., 1.);
//float shadow = softshadow(v + n * 0.01, lightDir, .01, 30., 18.); //float shadow = softshadow(v + n * 0.01, lightDir, .01, 30., 18.);
//lights += vec3(0.6431, 0.7804, 0.8588) * sun_dif * shadow * occ; //lights += vec3(0.6431, 0.7804, 0.8588) * sun_dif * shadow * occ;
float ind = clamp(dot(n, normalize(lightDir * vec3(.0, -1.0, -2.0))), 0.0, 1.0); float ind = clamp(dot(n, normalize(lightDir * vec3(.0, 1.0, -2.0))), 0.0, 1.0);
lights += vec3(0.08, 0.62, 0.75) * ind * 0.8; lights += vec3(0.08, 0.62, 0.75) * ind * 0.8;
outMaterial *= max(vec3(0.), lights); // output with lights; outMaterial *= max(vec3(0.), lights); // output with lights;
@ -421,26 +382,16 @@ vec3 shading(vec3 v, vec3 n, vec3 dir, float material) {
} }
vec3 postProcess(vec3 col) { vec3 postProcess(vec3 col) {
// float random = noise(gl_FragCoord.xy, 0.01+u_time);
// float random2 = noise(gl_FragCoord.xy, .2+u_time);
//col += 0.075*clamp(vec3(0.5*random, 0.5*random2, 0.5*random), 0.02, 1.); // dither
// Normalized pixel coordinates (from 0 to 1)
vec2 screenCoord = getUV();
// Vignette
float radius = 0.8;
float d = smoothstep(radius, radius - 0.4, length(screenCoord - vec2(0.5)));
col = mix(col, col * d, 1.);
// Contrast // Contrast
float contrast = .75; float contrast = 0.75;
col = mix(col, smoothstep(0.0, 1.0, col), contrast); col = mix(col, smoothstep(0.0, 1.0, col), contrast);
// Colour mapping // Colour mapping
col *= vec3(1.0, 1.0, 1.0); // col *= vec3(1.0, 1.0, 1.0);
col = pow(col, vec3(0.4545)); // gamma // Gamma
col = pow(col, vec3(0.4545)); // gamma 2.2
// fade in at the beginning // fade in at the beginning
//col*=vec3(clamp((u_time-1.8)*0.5,0., 1.)); //col*=vec3(clamp((u_time-1.8)*0.5,0., 1.));
@ -455,21 +406,14 @@ vec3 postProcess(vec3 col) {
// RENDERING // // RENDERING //
////////////////// //////////////////
vec3 getCameraRayDir(vec2 uv, vec3 camPos, vec3 camTarget, float fov) vec3 getCameraRayDir(vec2 uv, vec3 camPos, vec3 camTarget, float fov) {
{ vec3 f = normalize(camTarget - camPos), r = normalize(cross(vec3(0, 1, 0), f)), u = cross(f, r), c = f * fov, i = c + uv.x * r + uv.y * u, d = normalize(i);
vec3 f = normalize(camTarget-camPos),
r = normalize(cross(vec3(0,1,0), f)),
u = cross(f,r),
c = f*fov,
i = c + uv.x*r + uv.y*u,
d = normalize(i);
return d; return d;
} }
vec3 render(vec2 uv) { vec3 render(vec2 uv) {
vec3 camPos = vec3(-20.0 + sin(syncs[0] * 0.25) * 5, abs(sin(syncs[0] * 0.25) * 10) + 25.0, -20.0);
vec3 camPos = vec3(-20.0, 20.0, -20.0); vec3 camTarget = vec3(0.0, 0.0, 0.0); // Adjust target as needed
vec3 camTarget = vec3(0.0, 10.0, 0.0); // Adjust target as needed
float fov = 1.0; float fov = 1.0;
vec3 rayDir = getCameraRayDir(uv, camPos, camTarget, fov); vec3 rayDir = getCameraRayDir(uv, camPos, camTarget, fov);
@ -485,34 +429,33 @@ vec3 render(vec2 uv) {
} }
float fogAmount = 0.01; float fogAmount = 0.01;
col = col *exp(-t.x*fogAmount) + applyFog(col, t.x, rayDir, vec3(0., -0.5, 1.8), fogAmount) * (1.0-exp(-t.x*fogAmount)); col = col * exp(-t.x * fogAmount) + applyFog(col, t.x, rayDir, vec3(0., -0.5, 1.8), fogAmount) * (1.0 - exp(-t.x * fogAmount));
return col; return col;
} }
void main() { void main() {
vec3 finalColor = render(getUV()); vec3 finalColor = render(getUV());
//finalColor = postProcess(finalColor); finalColor = postProcess(finalColor);
o = vec4(finalColor, 1.); o = vec4(finalColor, 1.);
} }
/* /*
vec3 render2(vec2 uv, float time) { vec3 render2(vec2 uv, float time) {
vec3 res = vec3(.0); vec3 res = vec3(.0);
float pos = syncs[5]; float pos = syncs[5];
if (uv.x >= pos && uv.x <= pos+0.01 ) { if (uv.x >= pos && uv.x <= pos+0.01 ) {
res += vec3(1.); res += vec3(1.);
} }
//if (uv.x >= 0.0 && uv.x <= 0.01 ) { //if (uv.x >= 0.0 && uv.x <= 0.01 ) {
// res += vec3(abs(syncs[4]*2)); // res += vec3(abs(syncs[4]*2));
//} //}
//res += vec3(0.1, 0.2, 0.3) * abs(syncs[2]*1.2); //res += vec3(0.1, 0.2, 0.3) * abs(syncs[2]*1.2);
return res; return res;
} }

View File

@ -3,7 +3,7 @@
# define FRAGMENT_INL_ # define FRAGMENT_INL_
# define VAR_fft_output "f" # define VAR_fft_output "f"
# define VAR_o "l" # define VAR_o "l"
# define VAR_shapes "H" # define VAR_shapes "n"
# define VAR_syncs "m" # define VAR_syncs "m"
# define VAR_test "k" # define VAR_test "k"
# define VAR_u_ShapesTex "x" # define VAR_u_ShapesTex "x"
@ -13,164 +13,147 @@ const char *fragment_frag =
"precision mediump float;" "precision mediump float;"
"out vec4 l;" "out vec4 l;"
"const float i=2.*acos(-1.),v=sqrt(5.)*.5+.5;" "const float i=2.*acos(-1.),v=sqrt(5.)*.5+.5;"
"layout(location=0)uniform float m[12];" "layout(location=0)uniform float m[11];"
"layout(location=20)uniform float f[512];" "layout(location=20)uniform float f[512];"
"layout(location=600)uniform vec3 H[15];" "layout(location=600)uniform vec3 n[15];"
"layout(location=700)uniform vec3 k;" "layout(location=700)uniform vec3 k;"
"layout(binding=0)uniform sampler2D x;" "layout(binding=0)uniform sampler2D x;"
"float n=m[0];"
"mat2 s()" "mat2 s()"
"{" "{"
"float v=sin(.5),x=cos(.5);" "float v=sin(.5),m=cos(.5);"
"return mat2(x,-v,v,x);" "return mat2(m,-v,v,m);"
"}"
"float s(vec3 v,vec2 l)"
"{"
"v.xz=abs(v.xz);"
"v.xz=vec2(v.x*.866025+v.z*.5,v.z);"
"return length(max(abs(v)-vec3(l.xyx)+.15,0.))-.15;"
"}" "}"
"struct HexData{vec3 local;vec2 axial;};" "struct HexData{vec3 local;vec2 axial;};"
"HexData s(vec3 v)" "HexData s(vec3 v)"
"{" "{"
"float x=sqrt(3.)/3.*v.x-1./3.*v.z,l=2./3.*v.z,m=round(x),y=round(l),t=round(-x-l),n=abs(m-x),d=abs(y-l);" "float m=(sqrt(3.)/3.*v.x-1./3.*v.z)/1.5,l=2./3.*v.z/1.5,x=round(m),y=round(l),t=round(-m-l),a=abs(x-m),d=abs(y-l);"
"x=abs(t+x+l);" "m=abs(t+m+l);"
"if(n>d&&n>x)" "if(a>d&&a>m)"
"m=-y-t;" "x=-y-t;"
"else if(d>x)" "else if(d>m)"
"y=-m-t;" "y=-x-t;"
"x=sqrt(3.)*(m+y*.5);" "m=1.5*sqrt(3.)*(x+y*.5);"
"l=1.5*y;" "l=2.25*y;"
"HexData f;" "HexData i;"
"f.local=v-vec3(x,0,l);" "i.local=v-vec3(m,0,l);"
"f.axial=vec2(m,y);" "i.axial=vec2(x,y);"
"return f;" "return i;"
"}" "}"
"struct HexData{vec3 local;vec2 axial;};"
"float s(vec2 v)" "float s(vec2 v)"
"{" "{"
"float x=v.x,l=v.y;" "float m=v.x,l=v.y;"
"return max(abs(x),max(abs(l),abs(-x-l)));" "return max(abs(m),max(abs(l),abs(-m-l)));"
"}"
"float s(vec3 v,vec2 m)"
"{"
"v.xz=abs(v.xz);"
"v.xz=vec2(v.x*.866025+v.z*.5,v.z);"
"return length(max(abs(v)-vec3(m.xyx)+.15,0.))-.15;"
"}" "}"
"vec2 t(vec3 v)" "vec2 t(vec3 v)"
"{" "{"
"vec2 l=vec2(v.y,0);" "float m=1e8;"
"HexData m=s(vec3(v.x,v.y-2.5,v.z));" "HexData l=s(vec3(v.x,v.y-2.5,v.z));"
"float i=1.+f[int(clamp(s(m.axial)+1.,0.,511.))]*3.;" "vec3 i=l.local;"
"vec3 n=m.local;" "i.xz*=s();"
"n.xz*=s();" "float n=s(vec3(i),vec2(.85,1.+f[int(clamp(s(l.axial)+1.,0.,511.))]*4.));"
"i=s(vec3(n.x,n.y-i/2,n.z),vec2(.83,i/2));" "m=n<m?"
"l=min(l,vec2(i,0));" "n:"
"for(float f=0.;f<16.;f++)" "m;"
"for(float i=0.;i<16.;i++)" "return vec2(m,0);"
"{"
"ivec2 m=textureSize(x,0);"
"vec2 n=vec2(i,f)/vec2(m);"
"vec4 d=texture(x,n);"
"if(d.w<.5)"
"continue;"
"l=min(l,vec2(length(v-vec3(-70.+d.x*2.,12.+d.y*80.,0))-.8,1));"
"}"
"return l;"
"}" "}"
"vec3 s(vec3 v,vec3 x,inout vec3 l)" "vec3 s(vec3 v,vec3 m,inout vec3 l)"
"{" "{"
"float i=0.,n=0.,m=0.,f;" "float i=0.,f=0.,x=0.;"
"vec2 d;" "vec2 n;"
"for(int r=0;r<50;r++)" "for(int r=0;r<20;r++)"
"{" "{"
"l=v+x*m;" "l=v+m*x;"
"d=t(l);" "n=t(l);"
"f=abs(d.x);" "i=n.y;"
"i=d.y;" "x+=n.x;"
"if(m>4e2)" "if(abs(n.x)<1e-4)"
"break;"
"if(f<.001*(m*.0125+1.))"
"{" "{"
"n=1.;" "f=1.;"
"break;" "break;"
"}" "}"
"m+=d.x;" "if(x>200)"
"}"
"return vec3(m,i,n);"
"}"
"float s(vec3 v,vec3 x,float l)"
"{"
"float i=1.,m=.02;"
"for(int f=0;f<6;f++)"
"{"
"if(m>l)"
"break;" "break;"
"float n=t(v+m*x).x;" "}"
"i=min(i,n/(4.*m));" "return vec3(x,i,f);"
"m+=clamp(n,.1,.8);" "}"
"float s(vec3 v,vec3 m,float l)"
"{"
"float i=1.,x=.02;"
"for(int r=0;r<6;r++)"
"{"
"if(x>l)"
"break;"
"float n=t(v+x*m).x;"
"i=min(i,n/(4.*x));"
"x+=clamp(n,.1,.8);"
"if(i<-1.)" "if(i<-1.)"
"break;" "break;"
"}" "}"
"i=max(i,-1.);" "i=max(i,-1.);"
"return.25*(1.+i)*(1.+i)*(2.-i);" "return.25*(1.+i)*(1.+i)*(2.-i);"
"}" "}"
"vec3 e(vec3 v)" "vec3 p(vec3 v)"
"{" "{"
"vec2 i=vec2(.01,0);" "vec2 m=vec2(.01,0);"
"v=vec3(t(v+i.xyy).x-t(v-i.xyy).x,t(v+i.yxy).x-t(v-i.yxy).x,t(v+i.yyx).x-t(v-i.yyx).x);" "return normalize(vec3(t(v+m.xyy).x-t(v-m.xyy).x,t(v+m.yxy).x-t(v-m.yxy).x,t(v+m.yyx).x-t(v-m.yyx).x));"
"return normalize(v);"
"}" "}"
"vec3 e(vec3 v,vec3 m,vec3 l,vec3 x,float i)" "vec3 p(vec3 v,vec3 m,vec3 i,vec3 l,vec3 x,float f)"
"{" "{"
"vec3 n=vec3(.77,.26,.73);" "v-=i;"
"v-=m;" "float r=length(v);"
"float f=length(v);"
"v=normalize(v);" "v=normalize(v);"
"float y=30./(1.+.09*f+.032*f*f),d=max(dot(x,v),0.);" "float n=15./(1.+.09*r+.032*r*r),y=max(dot(x,v),0.);"
"l=normalize(v-l);" "l=normalize(v-l);"
"vec3 r=vec3(.04);" "vec3 e=vec3(.04);"
"r+=(1.-r)*pow(clamp(1.-max(dot(l,v),0.),0.,1.),5.);" "e+=(1.-e)*pow(clamp(1.-max(dot(l,v),0.),0.,1.),5.);"
"f=s(m+x*.01,v,f);" "r=s(i+x*.01,v,r);"
"return(n*d*y+n*pow(max(dot(x,l),0.),mix(128.,8.,i))*y*r)*f;" "return(m*y*n+m*pow(max(dot(x,l),0.),mix(128.,8.,f))*n*e)*r;"
"}" "}"
"vec3 e(vec3 v,vec3 m,vec3 i,float l)" "vec3 p(vec3 v,vec3 m,vec3 i,float l)"
"{" "{"
"float n=.01;" "float f=.01;"
"vec3 x=vec3(0);" "vec3 n=vec3(0);"
"if(l==0.)" "if(l==0.)"
"x=vec3(.8314,.2941,.2941),n=.1;" "n=vec3(.4941),f=.6;"
"else if(l==1.)" "else if(l==1.)"
"x=vec3(.6196,.6118,.6118),n=.7;" "n=vec3(.6196,.6118,.6118),f=.7;"
"else if(l==2.)" "else if(l==2.)"
"x=vec3(.3255,.4784,.3255),n=.2;" "n=vec3(.3255,.4784,.3255),f=.2;"
"else if(l==3.)" "else if(l==3.)"
"x=vec3(.2471,.3059,.6314),n=1.;" "n=vec3(.2471,.3059,.6314),f=1.;"
"else if(l==4.)" "else if(l==4.)"
"x=vec3(.9961,1,.9922),n=.1;" "n=vec3(.9961,1,.9922),f=.1;"
"else if(l==5.)" "else if(l==5.)"
"x=vec3(.9961,1,.9922),n=.3;" "n=vec3(.9961,1,.9922),f=.3;"
"vec3 f=vec3(0);" "v=vec3(0)+p(vec3(0,20,10),vec3(.77,.26,.73),v,i,m,f)+p(vec3(-10,20,-10),vec3(.18,.61,.86),v,i,m,f)+vec3(.08,.62,.75)*clamp(dot(m,normalize(vec3(0,2,3)*vec3(0,1,-2))),0.,1.)*.8;"
"f+=e(vec3(0,40,-10),v,i,m,n);" "return n*max(vec3(0),v);"
"f+=e(vec3(0,20,15),v,i,m,n);"
"f+=vec3(.08,.62,.75)*clamp(dot(m,normalize(vec3(0,1,-3)*vec3(0,-1,-2))),0.,1.)*.8;"
"return x*max(vec3(0),f);"
"}" "}"
"vec3 e(vec2 v,vec3 l)" "vec3 p(vec2 v,vec3 m)"
"{" "{"
"l=normalize(vec3(0,10,0)-l);" "m=normalize(vec3(0)-m);"
"vec3 n=normalize(cross(vec3(0,1,0),l));" "vec3 l=normalize(cross(vec3(0,1,0),m));"
"return normalize(l+v.x*n+v.y*cross(l,n));" "return normalize(m+v.x*l+v.y*cross(m,l));"
"}" "}"
"vec3 e(vec2 v)" "vec3 p(vec2 v)"
"{" "{"
"vec3 l=vec3(-20,20,-20),n=e(v,l),i=vec3(0),x=vec3(0);" "vec3 l=vec3(-20.+sin(m[0]*.25)*5,abs(sin(m[0]*.25)*10)+25.,-20),i=p(v,l),f=vec3(0),x=vec3(0);"
"l=s(l,n,x);" "l=s(l,i,x);"
"if(l.x>0.)" "if(l.x>0.)"
"{" "{"
"vec3 v=e(x);" "vec3 v=p(x);"
"i=e(x,v,n,l.y);" "f=p(x,v,i,l.y);"
"}" "}"
"return i*exp(-l.x*.01)+mix(i,mix(vec3(.2667,.2941,.3451),vec3(.302,.3176,.3725),pow(max(dot(n,vec3(0,-.5,1.8)),0.),clamp(m[1]+m[2]+m[3],0.,1.)*5.)),1.-exp(-l.x*.01))*(1.-exp(-l.x*.01));" "return f*exp(-l.x*.01)+mix(f,mix(vec3(.2706,.2706,.2863),vec3(.2314),pow(max(dot(i,vec3(0,-.5,1.8)),0.),clamp(m[1]+m[2]+m[3],0.,1.))),1.-exp(-l.x*.01))*(1.-exp(-l.x*.01));"
"}" "}"
"void main()" "void main()"
"{" "{"
"vec3 v=e(gl_FragCoord.xy*vec2(.00104166667,.00185185185)-1.);" "vec3 v=p(gl_FragCoord.xy*vec2(.00104166667,.00185185185)-1.);"
"l=vec4(v,1);" "l=vec4(v,1);"
"}"; "}";