nyt alle 4k, valot poistettu, uusi paletti

This commit is contained in:
Teemu Järvisalo
2025-07-31 21:19:00 +03:00
parent bc263cfcb9
commit 80ca9a1d40
2 changed files with 21 additions and 54 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

@ -9,10 +9,10 @@ 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);
vec3 a=vec3(0.39,0.56,0.47);
vec3 b=vec3(0.54,0.56,0.51);
vec3 c=vec3(0.45,0.79,0.42);
vec3 d=vec3(0.08,0.37,0.75); // 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));
}
@ -31,6 +31,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 //
/////////////////
@ -80,7 +86,7 @@ float hexDistance(vec2 axial) {
}
float sdSphere(vec3 p, float r) {
return length(p) - r;
return le(p) - r;
}
float hexPylon(vec3 p, vec2 h) {
@ -92,7 +98,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;
}
//////////////
@ -121,7 +127,7 @@ 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);
@ -183,7 +189,7 @@ float softshadow(in vec3 ro, in vec3 rd, float mint, float maxt, float w) {
break;
float h = mapScene(ro + t * rd).x;
res = min(res, h / (w * t));
t += clamp(h, 0.1, 0.80);
t += cl(h, 0.1, 0.80);
if(res < -1.0)
break;
}
@ -194,47 +200,17 @@ float softshadow(in vec3 ro, in vec3 rd, float mint, float maxt, float w) {
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) {
// Light vector from surface to light
vec3 lightDir = lightPos - worldPos;
float lightDistance = length(lightDir);
lightDir = normalize(lightDir);
// Attenuation (quadratic falloff)
float attenuation = intensity / (1.0 + 0.09 * lightDistance + 0.032 * lightDistance * lightDistance);
// Diffuse lighting (Lambert)
float NdotL = max(dot(normal, lightDir), 0.0);
vec3 diffuse = lightColor * NdotL * attenuation;
// Specular lighting (Blinn-Phong)
vec3 halfDir = normalize(lightDir + (-viewDir));
float NdotH = max(dot(normal, halfDir), 0.0);
float shininess = mix(128.0, 8.0, roughness); // Convert roughness to shininess
vec3 specular = lightColor * pow(NdotH, shininess) * attenuation;
// Fresnel effect
vec3 F0 = vec3(0.04); // Base reflectance for dielectrics
vec3 fresnel = F0 + (1.0 - F0) * pow(clamp(1.0 - max(dot(halfDir, lightDir), 0.0), 0.0, 1.0), 5.0);
// Soft shadows
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 no(n);
}
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);
}
@ -258,12 +234,10 @@ vec3 shading(vec3 p, vec3 n, vec3 dir, float material) {
}
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);
vec3 lightDir = vec3(0., 2., 3);
float ind = clamp(dot(n, normalize(lightDir * vec3(.0, 1.0, -2.0))), 0.0, 1.0);
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;
@ -297,7 +271,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;
}