Compare commits
2 Commits
04e2761e04
...
b62df3ff88
| Author | SHA1 | Date | |
|---|---|---|---|
| b62df3ff88 | |||
| 292a05096f |
@ -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];
|
||||
|
||||
|
||||
20
src/main.cpp
20
src/main.cpp
@ -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) {
|
||||
|
||||
@ -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.;
|
||||
@ -156,18 +127,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 +159,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,6 +225,7 @@ 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;
|
||||
|
||||
Reference in New Issue
Block a user