4 Commits

Author SHA1 Message Date
3a9737ce18 uudet valot 2025-08-01 13:26:19 +03:00
3f71dd30e0 paletti + post process säätö 2025-08-01 11:11:30 +03:00
2b9b576f78 colors 2025-07-31 22:08:10 +03:00
80ca9a1d40 nyt alle 4k, valot poistettu, uusi paletti 2025-07-31 21:19:00 +03:00
2 changed files with 114 additions and 69 deletions

View File

@ -123,14 +123,7 @@ int __cdecl main(int argc, char* argv[])
// Play sound
direct_sound_buffer->Play(0, 0, 0);
struct Vec3 {
float x, y, z;
};
PFNGLUNIFORM1FVPROC glUniform1fvProc = ((PFNGLUNIFORM1FVPROC)wglGetProcAddress("glUniform1fv"));
PFNGLACTIVETEXTUREPROC glActiveTexture = ((PFNGLACTIVETEXTUREPROC)wglGetProcAddress("glActiveTexture"));
PFNGLUNIFORM1IPROC glUniform1i = ((PFNGLUNIFORM1IPROC)wglGetProcAddress("glUniform1i"));
PFNGLGETUNIFORMLOCATIONPROC glGetUniformLocation = ((PFNGLGETUNIFORMLOCATIONPROC)wglGetProcAddress("glGetUniformLocation"));
const ULONGLONG targetIntervalMs = 1000 / 60; // For 60 FPS FFT updates

View File

@ -8,14 +8,24 @@ layout(location = 0) uniform float syncs[11];
layout(location = 20) uniform float fft_output[512]; // FFT_SIZE / 4
// float u_time = syncs[0];
vec3 palette(float t) {
vec3 a = vec3(0.46, 0.2, 0.94);
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);
// paletti muunnos: arg 0.8 --> 0.5
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
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;
@ -31,6 +41,12 @@ float noise(in vec2 xy, in float seed) {
return fract(tan(distance(xy * PHI, xy) * seed) * xy.x);
}
// shorted functions
vec3 no(vec3 v) { return normalize(v); }
float cl(float a, float b, float c) { return clamp(a,b,c); }
float le(vec3 s) { return length(s); }
/////////////////
// GEOMETRY //
/////////////////
@ -79,10 +95,6 @@ float hexDistance(vec2 axial) {
return max(abs(q), max(abs(r), abs(s)));
}
float sdSphere(vec3 p, float r) {
return length(p) - r;
}
float hexPylon(vec3 p, vec2 h) {
//vec3 p = vec3(p.x, p.z, p2.y);
vec3 b = vec3(h.x, h.y, h.x);
@ -92,7 +104,7 @@ float hexPylon(vec3 p, vec2 h) {
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 le(max(abs(p) - b + .15, 0.)) - .15;
}
//////////////
@ -104,11 +116,8 @@ vec2 opU(vec2 d1, vec2 d2) {
return (d1.x < d2.x) ? d1 : d2;
}
float noyce(vec2 axial) {
if(mod(floor(syncs[0]), 2.) == 0.) {
return mix(noise(axial, 0.1), noise(axial, 0.2), sin(syncs[0] * 2.));
}
return mix(noise(axial, 0.2), noise(axial, 0.1), sin(syncs[0] * 2.));
float sdSphere(vec3 p, float r){
return length(p) -r;
}
vec2 mapScene(in vec3 p) {
@ -121,12 +130,10 @@ vec2 mapScene(in vec3 p) {
HexData hex = hexTile(hexpos, 1.1);
float distFromCenter = hexDistance(hex.axial);
int fftIndex = int(clamp(distFromCenter + 1.0, 0.0, 511.0));
int fftIndex = int(cl(distFromCenter + 1.0, 0.0, 511.0));
float fftVal = fft_output[fftIndex];
float noise = noyce(hex.axial);
// float hexHeight = 1.0 + fftVal * 5.0 + noise;
float hexHeight = 1.0 + noise;
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;
@ -134,10 +141,34 @@ vec2 mapScene(in vec3 p) {
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));
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);
}
@ -152,7 +183,7 @@ vec3 castRay(vec3 ro, vec3 rd, inout vec3 pos) {
vec2 res;
// Raymarching
for(int i = 0; i < 20; i++) {
for(int i = 0; i < 40; i++) {
pos = ro + rd * t;
res = mapScene(pos); // Get distance to objects, x = dist, y = material
mat = res.y;
@ -174,7 +205,6 @@ vec3 castRay(vec3 ro, vec3 rd, inout vec3 pos) {
////////////////
// SHADING //
////////////////
float softshadow(in vec3 ro, in vec3 rd, float mint, float maxt, float w) {
float res = 1.0;
float t = mint;
@ -191,14 +221,9 @@ float softshadow(in vec3 ro, in vec3 rd, float mint, float maxt, float w) {
return 0.25 * (1.0 + res) * (1.0 + res) * (2.0 - res);
}
vec3 calcNormal(vec3 pos) {
vec2 e = vec2(.01, 0.);
vec3 n = vec3(mapScene(pos + e.xyy).x - mapScene(pos - e.xyy).x, mapScene(pos + e.yxy).x - mapScene(pos - e.yxy).x, mapScene(pos + e.yyx).x - mapScene(pos - e.yyx).x);
return normalize(n);
}
vec3 addPointLight(vec3 lightPos, vec3 lightColor, float intensity, vec3 worldPos, vec3 viewDir, vec3 normal, float roughness) {
vec3 addPointLight(vec3 lightPos, vec3 lightColor, float intensity, vec3 worldPos, vec3 viewDir, vec3 normal) {
// Light vector from surface to light
float roughness = 1.0;
vec3 lightDir = lightPos - worldPos;
float lightDistance = length(lightDir);
lightDir = normalize(lightDir);
@ -224,47 +249,74 @@ vec3 addPointLight(vec3 lightPos, vec3 lightColor, float intensity, vec3 worldPo
float shadow = softshadow(worldPos + normal * 0.01, lightDir, 0.02, lightDistance, 4.0);
// Combine diffuse and specular with shadow
return (diffuse + specular * fresnel) * shadow;
return (diffuse + specular * fresnel) * shadow * shadow;
}
vec3 calcNormal(vec3 pos) {
vec2 e = vec2(.01, 0.);
vec3 n = vec3(mapScene(pos + e.xyy).x - mapScene(pos - e.xyy).x, mapScene(pos + e.yxy).x - mapScene(pos - e.yxy).x, mapScene(pos + e.yyx).x - mapScene(pos - e.yyx).x);
return no(n);
}
vec3 pal(float color) {
color *= 0.2;
vec3 c = palette(color, 0.25, 0.63);
vec3 c2 = palette(color, 0.5 ,0.2);
float t = clamp((syncs[0] - 129.0) / 2.0, 0.0, 1.0); // Smoothly ramps from 0 to 1 after 12s
return mix(c, c2, t); // Blend between c and c2 over ~2 seconds
//return c2;
}
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 = cl((syncs[1] + syncs[2] + syncs[3]), 0., 1.);
float fogAmount2 = 1.0 - exp(-t * fogAmount);
float sunAmount = max(dot(rd, lightDir), 1.0);
// highlight color
vec3 fogColor = mix(vec3(0.2706, 0.2706, 0.2863), vec3(0.2314, 0.2314, 0.2314), // Main color
vec3 fogColor = mix(vec3(0.3, 0.3, 0.3), vec3(0.2, 0.2, 0.2), // Main color
pow(sunAmount, syncsBass * 1.0));
return mix(col, fogColor, fogAmount2);
}
vec3 shading(vec3 p, vec3 n, vec3 dir, float material) {
float shininess = 0.0;
vec3 outMaterial = vec3(0.);
vec3 shading(vec3 p, vec3 n, vec3 dir, vec3 camPos) {
vec3 outMaterial = vec3(0.0);
if(material == 0.) {
outMaterial = palette(p.y * 0.1);
if(syncs[0] > 5.) {
outMaterial = vec3(0.5);
}
outMaterial = mix(palette(p.y * 0.1), vec3(0.5), abs(sin(syncs[0] * 0.2)));
shininess = 0.6;
}
if(material == 1.) {
outMaterial = vec3(0.5);
shininess = 0.6;
}
outMaterial = pal(p.y*p.y*0.01);
vec3 lights = vec3(0.);
lights += addPointLight(vec3(0., 20.0, 10.), vec3(0.77, 0.26, 0.73), 15.0, p, dir, n, shininess);
lights += addPointLight(vec3(-10., 20.0, -10.), vec3(0.18, 0.61, 0.86), 15., p, dir, n, shininess);
//lights += phongLighting(p, n, camPos, dir, vec3(0.51), outMaterial);
lights += addPointLight(vec3(0., 20.0, 0.), vec3(0.77, 0.26, 0.73), 30.0, p, dir, n);
// LIGHT CHANGING WITH CIRCLE RADIUS
float maxRadius = 25.; // Circle radius
float particleHeight = 15.; //(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 r = max(maxRadius - 0.0, 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 * r; // Object slides inward
//res = opU(res, vec2(sdSphere(p - objPos, sphereRadius), 1.));
lights += addPointLight(objPos, vec3(0.33, 0.91, 0.93), 30.0, p, dir, n);
vec3 lightDir = vec3(0., 2., 3);
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;
float ind = cl(dot(n, no(lightDir * vec3(.0, 1.0, -2.0))), 0.0, 1.0);
//lights += vec3(0.08, 0.62, 0.75) * ind * 0.8;
outMaterial *= max(vec3(0.), lights); // output with lights;
@ -273,7 +325,7 @@ vec3 shading(vec3 p, vec3 n, vec3 dir, float material) {
vec3 postProcess(vec3 col) {
// Contrast
float contrast = 0.75;
float contrast = 0.85;
col = mix(col, smoothstep(0.0, 1.0, col), contrast);
@ -281,7 +333,7 @@ vec3 postProcess(vec3 col) {
//col *= vec3(1.0, 1.0, 1.0);
// Gamma
col = pow(col, vec3(0.4545)); // gamma 2.2
col = pow(col, vec3(.55)); // gamma 2.2
// fade in at the beginning
//col*=vec3(clamp((u_time-1.8)*0.5,0., 1.));
@ -297,7 +349,7 @@ vec3 postProcess(vec3 col) {
//////////////////
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 = no(camTarget - camPos), r = no(cross(vec3(0, 1, 0), f)), u = cross(f, r), c = f * fov, i = c + uv.x * r + uv.y * u, d = no(i);
return d;
}
@ -315,12 +367,12 @@ vec3 render(vec2 uv) {
if(t.x > 0.0) {
vec3 nor = calcNormal(hitPos);
col = shading(hitPos, nor, rayDir, t.y);
col = shading(hitPos, nor, rayDir, camPos);
}
//glow from the bottom
vec3 bGlowColor = palette(syncs[0] * .075); // color change
float bGlowDistance = 0.3;
vec3 bGlowColor = pal(syncs[0] * .075); // color change
float bGlowDistance = 0.8;
vec3 p = camPos + t.x * rayDir;
vec3 bGlowLevel = bGlowColor * exp(-(p.y + 0.0) / bGlowDistance) * 9900.;