säätöä

This commit is contained in:
2025-07-28 16:39:34 +03:00
parent c11d86922c
commit 35c08c5e80
3 changed files with 154 additions and 244 deletions

View File

@ -54,43 +54,7 @@ float hexPylon(vec3 p, vec2 h) {//float r, float ht){
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 + .015, 0.)) - .015;
}
#define zclamp(a) max(a,0.0) //Clamp negative values at zero
float DF_RoundedHex( vec3 p, vec2 h) //float width, float height)
{
float width = h.x;
float height = h.y;
//Modified version (smooth edges) of the exagon prism found here:
//https://iquilezles.org/articles/distfunctions
float smoothRadius = 0.05;
width -= smoothRadius*2.0;
//Hexagon prism constructed using X,Y,Z symmetry.
//Only quadrant 1 needs to be solved, but the joining diagonal to quadrant IV is also
//required for distance blending (see db).
p = abs(p);
//Hexagonal edge distances :
//Note : [.8666,0.5] = [sin(PI/3,cos(PI/3)] -> Hexagon edges rotation coeff (60 degrees).
float da = (p.x*0.866025+p.z*0.5)-width; //quadrant I diagonal edge distance
float db = (p.x*0.866025-p.z*0.5)-width; //quadrant IV diagonal edge distance (needed for blending)
float dc = p.z-width; //upper distance
vec3 d = zclamp(vec3(da,db,dc));
//Note: this is not an euclidian length, therefore this operation slightly distorts our distance field.
//Yet, it is harmless to convergence, and does the smoothing job quite well.
float dw = length(d)-smoothRadius; //hexagonal part smoothness (blending at 60 deg)
float dh = p.y-height;
//Now that we have xz distance(dw) and y distance (dh), we can compute the distance
//for the given isovalue (the smoothing radius).
//Note : internal distance (maxX,maxY,maxZ) is also used to genereate internal signed dist,
// helping convergence when overstepping (very frequent with domain repetition).
float externalDistance = length(zclamp(vec2(dh,dw)))-smoothRadius; //Smoothed, unsigned
float internalDistance = max(max(da,dc),dh); //Sharp, signed.
return min(externalDistance,internalDistance);
return length(max(abs(p) - b + .15, 0.)) - .15;
}
// Return local coordinates inside hex AND axial ID
@ -164,20 +128,18 @@ vec2 mapScene(in vec3 p) {
vec3 hexpos = vec3(p.x, p.y - 2.5, p.z);
HexData hex = hexTile(hexpos, 1.0);
// Use axial coordinates as a stable hex ID
float distFromCenter = hexDistance(hex.axial);
int fftIndex = int(clamp(distFromCenter +1.0, 0.0, 511.0)); // tweak 15.0 to taste
float fftVal = fft_output[fftIndex];
float hexHeight = 1.0 + fftVal * 3.0;
// Rotate individual hex tiles if needed
vec3 r = hex.local;
//r.yz *= rot2D(1.0);
r.xz *= rot2D(0.5);
r.xz *= rot2D(0.5);
float d1 = fHexagonCircumcircle(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 gridSize2 = 16.;
@ -211,22 +173,22 @@ vec3 castRay(vec3 ro, vec3 rd, inout vec3 pos) {
vec3 d;
float t = 0.,ad,tmax=400.; // total distance travelled
const float tolerance = 0.001;
const float Z_REPEAT_DIST = 1.;
const float Z_REPEAT_DIST = 2.;
vec2 res;
// // Raymarching
// for (int i = 0; i < 50; i++) {
// pos = ro + rd * t;
// res = mapScene(pos); // Get distance to objects
// ad = abs(res.x);
// mat = res.y;
// if (t > tmax) break;
// if (ad < tolerance*(t*0.125 + 1.0)) {
// hit = 1.0;
// break;
// }
// t += res.x; // "march" the ray
// }
// Raymarching
for (int i = 0; i < 50; i++) {
pos = ro + rd * t;
res = mapScene(pos); // Get distance to objects
ad = abs(res.x);
mat = res.y;
if (t > tmax) break;
if (ad < tolerance*(t*0.0125 + 1.0)) {
hit = 1.0;
break;
}
t += res.x; // "march" the ray
}
// t -= Z_REPEAT_DIST*1.;
//
// for( int i=0; i<30; i++ )
@ -249,20 +211,20 @@ vec3 castRay(vec3 ro, vec3 rd, inout vec3 pos) {
// 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;
}
}
// 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.;