poistettu valot
This commit is contained in:
97
src/main.cpp
97
src/main.cpp
@ -16,11 +16,6 @@
|
|||||||
#define USE_AUDIO 1
|
#define USE_AUDIO 1
|
||||||
#define NO_UNIFORMS 0
|
#define NO_UNIFORMS 0
|
||||||
|
|
||||||
#define SHAPES 16
|
|
||||||
#define SHAPES_TEX_SIZE (SHAPES * SHAPES * 4)
|
|
||||||
#define SHAPES_TOTAL (SHAPES * SHAPES)
|
|
||||||
#define MAX_DISTANCE 100.f
|
|
||||||
|
|
||||||
#include "definitions.h"
|
#include "definitions.h"
|
||||||
#if OPENGL_DEBUG
|
#if OPENGL_DEBUG
|
||||||
#include "debug.h"
|
#include "debug.h"
|
||||||
@ -47,9 +42,7 @@ static int pidPost;
|
|||||||
// FFT buffers
|
// FFT buffers
|
||||||
static Complex signal[FFT_SIZE];
|
static Complex signal[FFT_SIZE];
|
||||||
static Complex buffer[3 * FFT_SIZE];
|
static Complex buffer[3 * FFT_SIZE];
|
||||||
|
|
||||||
static float fft_uniform[FFT_SIZE / 4];
|
static float fft_uniform[FFT_SIZE / 4];
|
||||||
static float shapesData[SHAPES_TEX_SIZE];
|
|
||||||
|
|
||||||
void entrypoint(void)
|
void entrypoint(void)
|
||||||
#else
|
#else
|
||||||
@ -130,19 +123,6 @@ int __cdecl main(int argc, char* argv[])
|
|||||||
// Play sound
|
// Play sound
|
||||||
direct_sound_buffer->Play(0, 0, 0);
|
direct_sound_buffer->Play(0, 0, 0);
|
||||||
|
|
||||||
// main note effect
|
|
||||||
boolean beenPlaying = false;
|
|
||||||
const int SHAPES_SIZE = 15;
|
|
||||||
float shapeIncrement = 0.15f;
|
|
||||||
|
|
||||||
int currentShape = 0; // mark location which shape we are currently building
|
|
||||||
|
|
||||||
boolean isPlaying = false;
|
|
||||||
|
|
||||||
float lastPlayPos = 0;
|
|
||||||
float lastNote = 0.0f;
|
|
||||||
|
|
||||||
|
|
||||||
struct Vec3 {
|
struct Vec3 {
|
||||||
float x, y, z;
|
float x, y, z;
|
||||||
};
|
};
|
||||||
@ -152,18 +132,6 @@ int __cdecl main(int argc, char* argv[])
|
|||||||
PFNGLUNIFORM1IPROC glUniform1i = ((PFNGLUNIFORM1IPROC)wglGetProcAddress("glUniform1i"));
|
PFNGLUNIFORM1IPROC glUniform1i = ((PFNGLUNIFORM1IPROC)wglGetProcAddress("glUniform1i"));
|
||||||
PFNGLGETUNIFORMLOCATIONPROC glGetUniformLocation = ((PFNGLGETUNIFORMLOCATIONPROC)wglGetProcAddress("glGetUniformLocation"));
|
PFNGLGETUNIFORMLOCATIONPROC glGetUniformLocation = ((PFNGLGETUNIFORMLOCATIONPROC)wglGetProcAddress("glGetUniformLocation"));
|
||||||
|
|
||||||
GLuint ShapesTex;
|
|
||||||
|
|
||||||
glGenTextures(1, &ShapesTex);
|
|
||||||
glBindTexture(GL_TEXTURE_2D, ShapesTex);
|
|
||||||
|
|
||||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA16F, SHAPES, SHAPES, 0, GL_RGBA, GL_FLOAT, nullptr);
|
|
||||||
|
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
|
||||||
|
|
||||||
const ULONGLONG targetIntervalMs = 1000 / 60; // For 60 FPS FFT updates
|
const ULONGLONG targetIntervalMs = 1000 / 60; // For 60 FPS FFT updates
|
||||||
|
|
||||||
do
|
do
|
||||||
@ -248,71 +216,6 @@ int __cdecl main(int argc, char* argv[])
|
|||||||
{
|
{
|
||||||
syncs[i + 1] = syncBuf[(playCursor / (2 * sizeof(SUsample)) >> 8) * SU_NUMSYNCS + i];
|
syncs[i + 1] = syncBuf[(playCursor / (2 * sizeof(SUsample)) >> 8) * SU_NUMSYNCS + i];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//////////////////////////////////////////////////////
|
|
||||||
// Shape builder
|
|
||||||
//////////////////////////////////////////////////////
|
|
||||||
|
|
||||||
// if sound is playing, start a shape, if shape is already started - add length
|
|
||||||
// if sound has stopped, end shape
|
|
||||||
// if shape is finished, move shape forward
|
|
||||||
float captureSync = syncs[5];
|
|
||||||
|
|
||||||
bool shapeJustFinished = false;
|
|
||||||
bool shapeJustStarted = false;
|
|
||||||
|
|
||||||
// Detect note change to start a new shape
|
|
||||||
bool noteChanged = (captureSync != lastNote) ? TRUE : FALSE;
|
|
||||||
lastNote = captureSync;
|
|
||||||
|
|
||||||
// If note changed and value is significant, start new shape
|
|
||||||
if (noteChanged) {
|
|
||||||
int index = currentShape * 4;
|
|
||||||
|
|
||||||
// Reset and activate current shape
|
|
||||||
shapesData[index + 0] = 0.0f; // x start
|
|
||||||
shapesData[index + 1] = captureSync; // y from audio
|
|
||||||
shapesData[index + 2] = 1.0f; // z (unused or length)
|
|
||||||
shapesData[index + 3] = 1.0f; // active
|
|
||||||
|
|
||||||
// Advance to next shape slot (circular)
|
|
||||||
currentShape = (currentShape + 1) % SHAPES_TOTAL;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Move active shapes
|
|
||||||
for (int i = 0; i < SHAPES_TOTAL; ++i) {
|
|
||||||
int index = i * 4;
|
|
||||||
|
|
||||||
// Check if shape is active
|
|
||||||
if (shapesData[index + 3] > 0.5f) {
|
|
||||||
// Move shape right
|
|
||||||
shapesData[index + 0] += shapeIncrement;
|
|
||||||
|
|
||||||
// Update y (optional, reflect live audio)
|
|
||||||
//shapesData[index + 1] = captureSync;
|
|
||||||
|
|
||||||
// Optional: grow z value to show duration
|
|
||||||
//shapesData[index + 2] += shapeIncrement * 0.2f;
|
|
||||||
|
|
||||||
// If x exceeds max distance, deactivate and reset
|
|
||||||
if (shapesData[index + 0] > MAX_DISTANCE) {
|
|
||||||
shapesData[index + 0] = 0.0f;
|
|
||||||
shapesData[index + 1] = 0.0f;
|
|
||||||
shapesData[index + 2] = 0.0f;
|
|
||||||
shapesData[index + 3] = 0.0f; // inactive
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Bind and update u_ShapesTex
|
|
||||||
glUniform1i(glGetUniformLocation(pidMain, "u_ShapesTex"), 0);
|
|
||||||
glActiveTexture(GL_TEXTURE0 + 0);
|
|
||||||
glBindTexture(GL_TEXTURE_2D, ShapesTex);
|
|
||||||
glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, SHAPES, SHAPES, GL_RGBA, GL_FLOAT, shapesData);
|
|
||||||
|
|
||||||
|
|
||||||
glUniform1fvProc(0, SU_NUMSYNCS + 1, syncs);
|
glUniform1fvProc(0, SU_NUMSYNCS + 1, syncs);
|
||||||
glUniform1fvProc(20, FFT_SIZE / 4, fft_uniform);
|
glUniform1fvProc(20, FFT_SIZE / 4, fft_uniform);
|
||||||
|
|
||||||
|
|||||||
@ -6,10 +6,6 @@ const float TAU = (2. * PI);
|
|||||||
const float PHI = sqrt(5.) * 0.5 + 0.5;
|
const float PHI = sqrt(5.) * 0.5 + 0.5;
|
||||||
layout(location = 0) uniform float syncs[11];
|
layout(location = 0) uniform float syncs[11];
|
||||||
layout(location = 20) uniform float fft_output[512]; // FFT_SIZE / 4
|
layout(location = 20) uniform float fft_output[512]; // FFT_SIZE / 4
|
||||||
layout(location = 600) uniform vec3 shapes[15]; // shapes - x = horizontal position, y = vertical position, z = length
|
|
||||||
layout(location = 700) uniform vec3 test; // shapes test
|
|
||||||
//layout(binding = 1) uniform sampler2D u_hexGridTex; //uniform sampler2D u_fft_texture;
|
|
||||||
|
|
||||||
layout(binding = 0) uniform sampler2D u_ShapesTex; // uniform sampler2D shapes texture
|
layout(binding = 0) uniform sampler2D u_ShapesTex; // uniform sampler2D shapes texture
|
||||||
// float u_time = syncs[0];
|
// float u_time = syncs[0];
|
||||||
|
|
||||||
@ -136,28 +132,6 @@ vec2 mapScene(in vec3 p) {
|
|||||||
|
|
||||||
res = (d1 < res) ? d1 : res;
|
res = (d1 < res) ? d1 : res;
|
||||||
|
|
||||||
/* const float gridSize = 16.;
|
|
||||||
|
|
||||||
for(float j = 0.; j < gridSize; j++) {
|
|
||||||
for(float i = 0.; i < gridSize; i++) {
|
|
||||||
ivec2 texSize = textureSize(u_ShapesTex, 0);
|
|
||||||
vec2 texCoord = (vec2(i, j)) / vec2(texSize);
|
|
||||||
vec4 shapeData = texture(u_ShapesTex, texCoord); // RGBA: x, y, length, active
|
|
||||||
float shapeActive = shapeData.a;
|
|
||||||
|
|
||||||
if(shapeActive < 0.5)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
vec3 shapePos = p - vec3(-70.0 + (shapeData.x * 2.), 12. + (shapeData.y * 80.), 0.0);
|
|
||||||
|
|
||||||
float a = sdSphere(shapePos, 0.8);
|
|
||||||
res = min(res, a);
|
|
||||||
if(res == a) {
|
|
||||||
mat = 1.0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}*/
|
|
||||||
|
|
||||||
return vec2(res, mat);
|
return vec2(res, mat);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -353,34 +327,7 @@ vec3 shading(vec3 p, vec3 n, vec3 dir, float material) {
|
|||||||
lights += addPointLight(vec3(0., 20.0, 10.), vec3(0.77, 0.26, 0.73), 15.0, p, dir, n, shininess);
|
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 += addPointLight(vec3(-10., 20.0, -10.), vec3(0.18, 0.61, 0.86), 15., p, dir, n, shininess);
|
||||||
|
|
||||||
// LIGHTS IN HEX GRID PATTERN
|
|
||||||
/*
|
|
||||||
float gridsize = 16.0; // or GRID if you want full size
|
|
||||||
vec3 p = vec3(0.);
|
|
||||||
for(float j = 0.; j < gridsize; j++) {
|
|
||||||
for(float i = 0.; i < gridsize; i++) {
|
|
||||||
ivec2 texSize = textureSize(u_hexGridTex, 0);
|
|
||||||
vec2 texCoord = (vec2(i, j)) / vec2(texSize);
|
|
||||||
|
|
||||||
vec4 hexData = texture(u_hexGridTex, texCoord); // RGBA: x, y, z, dist
|
|
||||||
|
|
||||||
vec3 hexPos = hexData.rgb;
|
|
||||||
float hexDist = hexData.a;
|
|
||||||
|
|
||||||
// Optionally use hexDist for ripple effect with FFT
|
|
||||||
int index = clamp(int((hexDist / 34.)*512.), 0, 511);
|
|
||||||
float hexSize = getScaledFFT(index, 15. ,0.);
|
|
||||||
//float a = sdHex(p - hexPos, 1.0 + hexSize, 0.0);
|
|
||||||
|
|
||||||
lights += addPointLightNoShadow(vec3(hexPos.x, (hexPos.y + hexSize) + 2., hexPos.z), palette(hexSize* 1.5), clamp(hexSize * 5., 0., 1.), 3.4 ,v, dir, n, shininess);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
vec3 lightDir = vec3(0., 2., 3);
|
vec3 lightDir = vec3(0., 2., 3);
|
||||||
//float sun_dif = clamp(dot(n, lightDir), 0., 1.);
|
|
||||||
//float shadow = softshadow(v + n * 0.01, lightDir, .01, 30., 18.);
|
|
||||||
//lights += vec3(0.6431, 0.7804, 0.8588) * sun_dif * shadow * occ;
|
|
||||||
|
|
||||||
float ind = clamp(dot(n, normalize(lightDir * vec3(.0, 1.0, -2.0))), 0.0, 1.0);
|
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;
|
lights += vec3(0.08, 0.62, 0.75) * ind * 0.8;
|
||||||
|
|||||||
Reference in New Issue
Block a user