3 Commits

View File

@ -13,19 +13,10 @@ vec3 palette(float t, float arg, float arg2){
vec3 a=vec3(0.52,0.56,0.47);
vec3 b=vec3(0.62,0.56,0.51);
vec3 c=vec3(0.43,0.79,0.42);
vec3 d=vec3(arg,0.42,arg2); // t<>st<73> viimenen floatti siirrett<74>v<EFBFBD> 0, kun tehd<68><64>n paletti switch
vec3 d=vec3(arg,0.42,arg2);
return a+b*cos(6.28318*(c*t+d));
}
/*
vec3 palette(float t){
vec3 a=vec3(0.52,0.56,0.47);
vec3 b=vec3(0.62,0.56,0.51);
vec3 c=vec3(0.43,0.79,0.42);
vec3 d=vec3(0,0.42,0.63);
return a+b*cos(6.28318*(c*t+d));
}
*/
vec2 getUV() {
const vec2 scale = vec2(0.00104166667, 0.00185185185);
return gl_FragCoord.xy * scale - 1.0;
@ -120,56 +111,41 @@ float sdSphere(vec3 p, float r){
return length(p) -r;
}
vec2 mapScene(in vec3 p) {
// Scene mapping with occlusion-aware SDF blending
vec2 mapScene(vec3 p) {
float dist = 20.;
int repeat = 0;
if((length(p.xz)) < 2*dist){
repeat = 2;
}
if((length(p.xz)) < 1.5*dist){
repeat = 3;
}
if((length(p.xz)) < dist){
repeat = 5;
}
float res = p.y;
float mat = 0.;
float hexRadius = 0.83;
vec3 hexpos = vec3(p.x, p.y - 2.5, p.z);
HexData hex = hexTile(hexpos, 1.1);
float distFromCenter = hexDistance(hex.axial);
int fftIndex = int(cl(distFromCenter + 1.0, 0.0, 511.0));
float fftVal = fft_output[fftIndex];
float noise = mix(noise(hex.axial+1., 0.1), noise(hex.axial+1., 0.2), sin(syncs[0] * 4.));
float hexHeight = clamp(1.0 + fftVal * 5.0 + noise, 0., 15.);;
// Rotate individual hex tiles if needed
vec3 r = hex.local;
// r.yz *= rot2D(PI * 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, r.z), vec2(hexRadius, hexHeight + 5));
res = (d1 < res) ? d1 : res;
// DEBUGGING --- LIGHT CHANGING WITH CIRCLE RADIUS
float maxRadius = 15.; // Circle radius
float particleHeight = 5. + (syncs[5] * 40.);
float particlePos = (syncs[0] * 0.5) + syncs[5];
// Map param to angle
float particleStartPos = particlePos * 2.0 * PI;
// Direction from center to initial circle position (in XY plane)
vec3 particleDir = normalize(vec3(cos(particleStartPos), 0.0, sin(particleStartPos))); // XZ direction
float rad = max(maxRadius - syncs[5], maxRadius);
vec3 particleOffset = vec3(0. , particleHeight, 0.); // particle offset
// Final object position = center (offset) + radial movement
vec3 center = particleOffset; // Circle center
vec3 objPos = center + particleDir * rad; // Object slides inward
//res = opU(res, vec2(sdSphere(p - objPos, sphereRadius), 1.));
d1 = sdSphere(p - objPos, 1.);
//res = opU(res, vec2(sdSphere(p - objPos, 0.4), 1.));
//res = (d1 < res) ? d1 : res;
return vec2(res, mat);
// mitigate neighbor occlusion with anti-bleed blending
float minDist = 1e9;
for (int dx = -repeat; dx <= repeat; ++dx) {
for (int dy = -repeat; dy <= repeat; ++dy) {
vec2 offset = vec2(dx, dy);
vec3 hexpos = vec3(p.x-dx, p.y-8.0, p.z-dy);
HexData hex = hexTile(hexpos, 1.1);
float distFromCenter = hexDistance(hex.axial);
int fftIndex = int(cl(distFromCenter + 1.0, 0.0, 511.0));
float fftVal = fft_output[fftIndex];
float noise = mix(noise(hex.axial+1., 0.1), noise(hex.axial+1., 0.2), sin(syncs[0] * 4.));
float hexHeight = clamp(1.0 + fftVal * 5.0 + noise, 0., 15.);
vec3 r = vec3(hex.local.x + offset.x,hex.local.y,hex.local.z+offset.y);
// r.yz *= rot2D(PI * 0.5);
r.xz *= rot2D(0.5);
vec3 cellPos = r;
float d = fHexagonCircumcircle(cellPos, vec2(0.85, hexHeight));
minDist = min(minDist, d);
}
}
return vec2(minDist,0.);
}
////////////////
@ -179,25 +155,42 @@ vec2 mapScene(in vec3 p) {
vec3 castRay(vec3 ro, vec3 rd, inout vec3 pos) {
float mat = 0.;
float hit = 0.;
float t = 0.;
vec3 d;
float t = 0.,ad,tmax=200.; // total distance travelled
const float tolerance = 0.0001;
const float Z_REPEAT_DIST = 1.5;
vec2 res;
// Raymarching
for(int i = 0; i < 40; i++) {
for (int i = 0; i < 50; i++) {
pos = ro + rd * t;
res = mapScene(pos); // Get distance to objects, x = dist, y = material
res = mapScene(pos); // Get distance to objects
ad = abs(res.x);
mat = res.y;
t += res.x; // "march" the ray
// if(abs(t) < tolerance * (t * 0.0125 + 1.0)) {
if(abs(res.x) < 0.0001) {
hit = 1.;
if (t > tmax) break;
if (ad < tolerance*(t*0.00125 + 1.0)) {
hit = 1.0;
break;
}
if(t > 200)
break;
t += res.x; // "march" the ray
}
// t -= Z_REPEAT_DIST/2.0;
//
// for( int i=0; i<20; 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/5.0); // "march" the ray
// }
return vec3(t, mat, hit);
}