5 Commits

Author SHA1 Message Date
ad8abed4d2 Final v1 2025-08-01 16:53:39 +03:00
dea77c1ec7 säätö 2025-08-01 15:59:59 +03:00
bd8c146348 4082k / fog poistettu 2025-08-01 15:50:23 +03:00
b62df3ff88 Heavy release tasan 4096 2025-08-01 15:42:11 +03:00
292a05096f optimointeja 2025-08-01 15:38:19 +03:00
3 changed files with 54 additions and 73 deletions

View File

@ -23,7 +23,9 @@ static unsigned int bit_reverse(unsigned int x, int log2n) {
return n;
}
void compute_fft(float* time_data, float* freq_out) {
static float real[FFT_SIZE];
static float imag[FFT_SIZE];

View File

@ -1,7 +1,7 @@
// custom build and feature flags
#ifdef DEBUG
#define OPENGL_DEBUG 0
#define FULLSCREEN 0
#define FULLSCREEN 1
#define DESPERATE 0
#define BREAK_COMPATIBILITY 0
#else
@ -12,7 +12,7 @@
#endif
#define POST_PASS 0
#define USE_MIPMAPS 1
#define USE_MIPMAPS 0
#define USE_AUDIO 1
#define NO_UNIFORMS 0
@ -44,6 +44,10 @@ static float fft_input[FFT_SIZE];
static float fft_output[FFT_SIZE / 2];
static float fft_uniform[FFT_SIZE / 4];
static float syncs[1 + SU_NUMSYNCS];
#define SU_VALUE SU_LENGTH_IN_SAMPLES * SU_CHANNEL_COUNT * SU_SAMPLE_SIZE
void entrypoint(void)
#else
#include "editor.h"
@ -96,7 +100,7 @@ int __cdecl main(int argc, char* argv[])
LPVOID p1;
DWORD l1;
IDirectSoundBuffer_Lock(direct_sound_buffer, 0, SU_LENGTH_IN_SAMPLES * SU_CHANNEL_COUNT * SU_SAMPLE_SIZE, &p1, &l1, NULL, NULL, 0);
IDirectSoundBuffer_Lock(direct_sound_buffer, 0, SU_VALUE, &p1, &l1, NULL, NULL, 0);
CreateThread(0, 0, (LPTHREAD_START_ROUTINE)su_render_song, p1, 0, 0);
@ -112,23 +116,21 @@ int __cdecl main(int argc, char* argv[])
track.play();
double position = 0.0;
#endif
static float syncs[1 + SU_NUMSYNCS];
long playCursor = 0;
long lastPlayCursor = -1;
volatile float maximum = 0.0; // Helper variable to calculate maximum fft output for normalization
// Unlock buffer for next use
IDirectSoundBuffer_Unlock(direct_sound_buffer, p1, SU_LENGTH_IN_SAMPLES * SU_CHANNEL_COUNT * SU_SAMPLE_SIZE, NULL, NULL);
IDirectSoundBuffer_Unlock(direct_sound_buffer, p1, SU_VALUE, NULL, NULL);
// Play sound
direct_sound_buffer->Play(0, 0, 0);
// Init FFT
init_hamming_window();
init_hamming_window();
PFNGLUNIFORM1FVPROC glUniform1fvProc = ((PFNGLUNIFORM1FVPROC)wglGetProcAddress("glUniform1fv"));
const ULONGLONG targetIntervalMs = 1000 / 60; // For 60 FPS FFT updates
ULONGLONG targetIntervalMs = 1000 / 60; // For 60 FPS FFT updates
do
{
@ -177,7 +179,7 @@ init_hamming_window();
HRESULT hr = IDirectSoundBuffer_Lock(direct_sound_buffer, 0, FFT_SIZE * sizeof(SUsample), &audio_ptr, &audio_size, NULL, NULL, DSBLOCK_FROMWRITECURSOR);
if (SUCCEEDED(hr) && audio_ptr) {
if (playCursor < ((SU_LENGTH_IN_SAMPLES * SU_CHANNEL_COUNT * SU_SAMPLE_SIZE) - (FFT_SIZE * SU_CHANNEL_COUNT * SU_SAMPLE_SIZE)))
if (playCursor < ((SU_VALUE) - (FFT_SIZE * SU_CHANNEL_COUNT * SU_SAMPLE_SIZE)))
{
SUsample* samples = (SUsample*)audio_ptr;
for (int i = 0; i < FFT_SIZE; ++i) {

View File

@ -1,12 +1,11 @@
#version 460
precision mediump float;
out vec4 o;
const float PI = 3.14159265;
const float TAU = (2. * PI);
const float PHI = sqrt(5.) * 0.5 + 0.5;
float PHI = sqrt(5.) * 0.5 + 0.5;
layout(location = 0) uniform float syncs[11];
layout(location = 20) uniform float fft_output[512]; // FFT_SIZE / 4
float u_time = syncs[0];
//float u_time = syncs[0];
// paletti muunnos: arg 0.8 --> 0.5
vec3 palette(float t, float arg, float arg2){
@ -18,7 +17,7 @@ vec3 palette(float t, float arg, float arg2){
}
vec2 getUV() {
const vec2 u_resolution = vec2(1920, 1080);
vec2 u_resolution = vec2(1920, 1080);
return ((gl_FragCoord.xy * 2. - u_resolution.xy) / u_resolution.y);
//const vec2 scale = vec2(0.00104166667, 0.00185185185);
//return gl_FragCoord.xy * scale - 1.0;
@ -88,34 +87,6 @@ float hexDistance(vec2 axial) {
return max(abs(q), max(abs(r), abs(s)));
}
/*
float hexPylon(vec3 p, vec2 h) {
//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 lev3(max(abs(p) - b + .15, 0.)) - .15;
}
*/
//////////////
// SCENE //
//////////////
/*
// instructions -> opU( { float to union with } , vec2( {put shape here}, {put material here} ) )
vec2 opU(vec2 d1, vec2 d2) {
return (d1.x < d2.x) ? d1 : d2;
}
float sdSphere(vec3 p, float r){
return lev3(p) -r;
}
*/
// Scene mapping with occlusion-aware SDF blending
vec2 mapScene(vec3 p) {
float dist = 20.;
@ -134,14 +105,13 @@ vec2 mapScene(vec3 p) {
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, 511.0));
float noise = mix(noise(hex.axial+1., 0.1), noise(hex.axial+1., 0.2), sin(u_time * 4.));
float hexHeight = cl(1.0 + (fft_output[fftIndex] * 2.0 + noise), 0., 15.);
vec3 r = vec3(hex.local.x + offset.x,hex.local.y,hex.local.z+offset.y);
float hexHeight = cl(1.0 + (fft_output[fftIndex] * 2.0) * cl(distFromCenter*0.25, 0.6, 1.5) + noise, 0., 9.);
vec3 r = vec3(hex.local.x + dx,hex.local.y,hex.local.z+dy);
// r.yz *= rot2D(PI * 0.5);
r.xz *= rot2D(0.5);
float d = fHexagonCircumcircle(r, vec2(0.85, hexHeight));
@ -156,18 +126,15 @@ vec2 mapScene(vec3 p) {
////////////////
vec3 castRay(vec3 ro, vec3 rd, inout vec3 pos) {
float mat = 0.;
float hit = 0.;
float t = 0.; // total distance travelled
const float Z_REPEAT_DIST = 1.5;
// Raymarching
for (int i = 0; i < 50; i++) {
pos = ro + rd * t;
vec2 res = mapScene(pos); // Get distance to objects
mat = res.y;
if (t > 200.) break;
if (abs(res.x) < 1e-4*(t*0.00125 + 1.0)) {
if (abs(res.x) < 1e-4) {
hit = 1.0;
break;
}
@ -191,7 +158,7 @@ vec3 castRay(vec3 ro, vec3 rd, inout vec3 pos) {
// t += min(d.x, Z_REPEAT_DIST/5.0); // "march" the ray
// }
return vec3(t, mat, hit);
return vec3(t, 0., hit);
}
////////////////
@ -257,25 +224,29 @@ 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 = cl((u_time - 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 = 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.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 applyFog(vec3 color, float dist, vec3 fogColor, float fogDensity) {
float fogFactor = exp(-dist * fogDensity);
return mix(fogColor, color, fogFactor);
}
*/
//vec3 applyFog(vec3 col, float t, vec3 rd, vec3 lightDir, float fogAmount) {
//
// float syncsBass = cl((syncs[1]), 0., 1.);
//
// float fogAmount2 = 1.0 - exp(-t * fogAmount);
// float sunAmount = max(dot(rd, lightDir), 1.0);
// // highlight color
// vec3 fogColor = vec3(0.2, 0.2, 0.2);
// return mix(col, fogColor, fogAmount2);
//}
/*
vec3 shading(vec3 p, vec3 n, vec3 dir, vec3 caPos) {
vec3 outMaterial = vec3(0.0);
@ -285,7 +256,7 @@ vec3 shading(vec3 p, vec3 n, vec3 dir, vec3 caPos) {
//lights += phongLighting(p, n, camPos, dir, vec3(0.51), outMaterial);
lights += addPointLight(vec3(0., 20.0, 0.), vec3(0.7, 0.3, 0.7), 15.0, p, dir, n);
/*
// LIGHT CHANGING WITH CIRCLE RADIUS
float maxRadius = 25.; // Circle radius
float particleHeight = 15.; //(syncs[5] * 40.);
@ -307,18 +278,18 @@ vec3 shading(vec3 p, vec3 n, vec3 dir, vec3 caPos) {
//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 = cl(dot(n, no(lightDir * vec3(.0, 1.0, -2.0))), 0.0, 1.0);
lights += vec3(0.6, 0.6, 0.6) * ind * 0.4;
*/
outMaterial *= max(vec3(0.), lights); // output with lights;
return outMaterial;
}
*/
/*
vec3 postProcess(vec3 col) {
// Contrast
float contrast = 0.85;
@ -339,6 +310,7 @@ vec3 postProcess(vec3 col) {
return col;
}
*/
//////////////////
// RENDERING //
@ -369,7 +341,7 @@ vec3 render(vec2 uv) {
vec3 mat = pal(hitPos.y*hitPos.y*0.01);
//vec3 lights = vec3(0.);
vec3 lights = addPointLight(vec3(0., 20.0, 0.), vec3(0.7, 0.3, 0.7), 15.0, hitPos, rayDir, nor);
vec3 lights = addPointLight(vec3(0., 20.0, 0.), vec3(0.7, 0.3, 0.7), 5.0, hitPos, rayDir, nor);
mat *= max(vec3(0.), lights); // output with lights;
col = mat;
}
@ -379,22 +351,27 @@ vec3 render(vec2 uv) {
float bGlowDistance = 0.8;
vec3 p = camPos + t.x * rayDir;
vec3 bGlowLevel = bGlowColor * exp(-(p.y + 0.0) / bGlowDistance) * 10000.;
vec3 bGlowLevel = bGlowColor * exp(-(p.y + 0.0) / bGlowDistance) * 9e3;
col += bGlowLevel;
col = clamp(mix(bGlowLevel, col, t.z), 0.0, 1.0);
// distance fog + bass thunder
/*
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));
*/
vec3 fogColor = vec3(0.1, 0.2, 0.3); // light gray-blue fog
float fogDensity = 5e-3;
col = applyFog(col, t.x, fogColor, fogDensity);
//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));
return col;
}
void main() {
vec3 finalColor = render(getUV());
finalColor = postProcess(finalColor);
//finalColor = postProcess(finalColor);
finalColor = mix(finalColor, smoothstep(0.0, 1.0, finalColor), 0.8); // contrast
finalColor = pow(finalColor, vec3(.4)); // gamma 2.2
o = vec4(finalColor, 1.);
}