Compare commits
20 Commits
teemun_sha
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
| ad8abed4d2 | |||
| dea77c1ec7 | |||
| bd8c146348 | |||
| b62df3ff88 | |||
| 292a05096f | |||
| 04e2761e04 | |||
| 353c4440ea | |||
| 266e4bd85d | |||
| 1d8d47b374 | |||
| 16f844a633 | |||
| ddade2ab44 | |||
| 3a9737ce18 | |||
| 7d79c75aa6 | |||
| 3f71dd30e0 | |||
| 2b9b576f78 | |||
| 80ca9a1d40 | |||
| bc263cfcb9 | |||
| efac210beb | |||
| b1f6fab663 | |||
| aa949ba2a7 |
@ -23,7 +23,9 @@ static unsigned int bit_reverse(unsigned int x, int log2n) {
|
|||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void compute_fft(float* time_data, float* freq_out) {
|
void compute_fft(float* time_data, float* freq_out) {
|
||||||
|
|
||||||
static float real[FFT_SIZE];
|
static float real[FFT_SIZE];
|
||||||
static float imag[FFT_SIZE];
|
static float imag[FFT_SIZE];
|
||||||
|
|
||||||
@ -32,7 +34,7 @@ void compute_fft(float* time_data, float* freq_out) {
|
|||||||
|
|
||||||
// Apply Hamming window
|
// Apply Hamming window
|
||||||
for (int i = 0; i < FFT_SIZE; i++) {
|
for (int i = 0; i < FFT_SIZE; i++) {
|
||||||
real[i] = time_data[i] * window[i];
|
real[i] = time_data[i];// *window[i];
|
||||||
imag[i] = 0.0f;
|
imag[i] = 0.0f;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -75,4 +77,4 @@ void compute_fft(float* time_data, float* freq_out) {
|
|||||||
float normalized = (db + 60.0f) / 60.0f; // [0,1]
|
float normalized = (db + 60.0f) / 60.0f; // [0,1]
|
||||||
freq_out[i] = mag;
|
freq_out[i] = mag;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -4,4 +4,5 @@
|
|||||||
|
|
||||||
#define FFT_SIZE 2048
|
#define FFT_SIZE 2048
|
||||||
void init_hamming_window();
|
void init_hamming_window();
|
||||||
void compute_fft(float* time_data, float* freq_out);
|
void compute_fft(float* time_data, float* freq_out);
|
||||||
|
|
||||||
|
|||||||
148
src/main.cpp
148
src/main.cpp
@ -1,32 +1,29 @@
|
|||||||
// custom build and feature flags
|
// custom build and feature flags
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
#define OPENGL_DEBUG 0
|
#define OPENGL_DEBUG 0
|
||||||
#define FULLSCREEN 0
|
#define FULLSCREEN 1
|
||||||
#define DESPERATE 0
|
#define DESPERATE 0
|
||||||
#define BREAK_COMPATIBILITY 0
|
#define BREAK_COMPATIBILITY 0
|
||||||
#else
|
#else
|
||||||
#define OPENGL_DEBUG 0
|
#define OPENGL_DEBUG 0
|
||||||
#define FULLSCREEN 0
|
#define FULLSCREEN 1
|
||||||
#define DESPERATE 0
|
#define DESPERATE 0
|
||||||
#define BREAK_COMPATIBILITY 0
|
#define BREAK_COMPATIBILITY 0
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define POST_PASS 0
|
#define POST_PASS 0
|
||||||
#define USE_MIPMAPS 1
|
#define USE_MIPMAPS 0
|
||||||
#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"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "glext.h"
|
#include "glext.h"
|
||||||
|
#include "fft.h"
|
||||||
|
|
||||||
#pragma data_seg(".shader")
|
#pragma data_seg(".shader")
|
||||||
#include "shaders/fragment.inl"
|
#include "shaders/fragment.inl"
|
||||||
#if POST_PASS
|
#if POST_PASS
|
||||||
@ -34,8 +31,6 @@
|
|||||||
#include "shaders/post.inl"
|
#include "shaders/post.inl"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "fft.h"
|
|
||||||
|
|
||||||
#pragma data_seg(".pids")
|
#pragma data_seg(".pids")
|
||||||
// static allocation saves a few bytes
|
// static allocation saves a few bytes
|
||||||
static int pidMain;
|
static int pidMain;
|
||||||
@ -44,6 +39,15 @@ static int pidPost;
|
|||||||
|
|
||||||
#ifndef EDITOR_CONTROLS
|
#ifndef EDITOR_CONTROLS
|
||||||
#pragma code_seg(".main")
|
#pragma code_seg(".main")
|
||||||
|
// FFT buffers
|
||||||
|
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)
|
void entrypoint(void)
|
||||||
#else
|
#else
|
||||||
#include "editor.h"
|
#include "editor.h"
|
||||||
@ -96,7 +100,7 @@ int __cdecl main(int argc, char* argv[])
|
|||||||
|
|
||||||
LPVOID p1;
|
LPVOID p1;
|
||||||
DWORD l1;
|
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);
|
CreateThread(0, 0, (LPTHREAD_START_ROUTINE)su_render_song, p1, 0, 0);
|
||||||
|
|
||||||
@ -112,63 +116,21 @@ int __cdecl main(int argc, char* argv[])
|
|||||||
track.play();
|
track.play();
|
||||||
double position = 0.0;
|
double position = 0.0;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
long playCursor = 0;
|
long playCursor = 0;
|
||||||
long lastPlayCursor = -1;
|
long lastPlayCursor = -1;
|
||||||
volatile float maximum = 0.0; // Helper variable to calculate maximum fft output for normalization
|
|
||||||
|
|
||||||
// Unlock buffer for next use
|
// 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
|
// Play sound
|
||||||
direct_sound_buffer->Play(0, 0, 0);
|
direct_sound_buffer->Play(0, 0, 0);
|
||||||
|
|
||||||
static float syncs[1 + SU_NUMSYNCS];
|
|
||||||
|
|
||||||
// Init FFT
|
// Init FFT
|
||||||
init_hamming_window();
|
init_hamming_window();
|
||||||
// FFT buffers
|
|
||||||
static float fft_input[FFT_SIZE];
|
|
||||||
static float fft_output[FFT_SIZE / 2]; // Magnitudes
|
|
||||||
static float fft_uniform[FFT_SIZE / 4];
|
|
||||||
|
|
||||||
static float shapesData[SHAPES_TEX_SIZE];
|
|
||||||
|
|
||||||
// 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 {
|
|
||||||
float x, y, z;
|
|
||||||
};
|
|
||||||
|
|
||||||
PFNGLUNIFORM1FVPROC glUniform1fvProc = ((PFNGLUNIFORM1FVPROC)wglGetProcAddress("glUniform1fv"));
|
PFNGLUNIFORM1FVPROC glUniform1fvProc = ((PFNGLUNIFORM1FVPROC)wglGetProcAddress("glUniform1fv"));
|
||||||
PFNGLACTIVETEXTUREPROC glActiveTexture = ((PFNGLACTIVETEXTUREPROC)wglGetProcAddress("glActiveTexture"));
|
|
||||||
PFNGLUNIFORM1IPROC glUniform1i = ((PFNGLUNIFORM1IPROC)wglGetProcAddress("glUniform1i"));
|
|
||||||
PFNGLGETUNIFORMLOCATIONPROC glGetUniformLocation = ((PFNGLGETUNIFORMLOCATIONPROC)wglGetProcAddress("glGetUniformLocation"));
|
|
||||||
|
|
||||||
GLuint ShapesTex;
|
ULONGLONG targetIntervalMs = 1000 / 60; // For 60 FPS FFT updates
|
||||||
|
|
||||||
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
|
|
||||||
|
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
@ -217,7 +179,7 @@ int __cdecl main(int argc, char* argv[])
|
|||||||
HRESULT hr = IDirectSoundBuffer_Lock(direct_sound_buffer, 0, FFT_SIZE * sizeof(SUsample), &audio_ptr, &audio_size, NULL, NULL, DSBLOCK_FROMWRITECURSOR);
|
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 (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;
|
SUsample* samples = (SUsample*)audio_ptr;
|
||||||
for (int i = 0; i < FFT_SIZE; ++i) {
|
for (int i = 0; i < FFT_SIZE; ++i) {
|
||||||
@ -235,85 +197,21 @@ int __cdecl main(int argc, char* argv[])
|
|||||||
for (int i = 0; i < (FFT_SIZE / 4); i++)
|
for (int i = 0; i < (FFT_SIZE / 4); i++)
|
||||||
{
|
{
|
||||||
float gain = 50.0f;
|
float gain = 50.0f;
|
||||||
float alpha = 0.10f; // "Hidastaa" FFT:n piikkej<EFBFBD>
|
float alpha = 0.10f; // "Hidastaa" FFT:n piikkejä
|
||||||
float threshhold = 0.015f; // Alin arvo mik<EFBFBD> p<EFBFBD><EFBFBD>stet<EFBFBD><EFBFBD>n shaderille (v<EFBFBD>hent<EFBFBD><EFBFBD> "noisea")
|
float threshhold = 0.05f; // Alin arvo mikä päästetään shaderille (vähentää "noisea")
|
||||||
float x_t = (fft_output[i] < threshhold) ? 0.f : fft_output[i] * gain;
|
float x_t = fft_output[i] * gain;
|
||||||
// Exponential smoothing kaava
|
// Exponential smoothing kaava
|
||||||
// s(t) = alpha*x(t)+(1-alpha)*s(t-1)
|
// s(t) = alpha*x(t)+(1-alpha)*s(t-1)
|
||||||
fft_uniform[i] = alpha * (x_t)+(1 - alpha) * fft_uniform[i];
|
fft_uniform[i] = (x_t < threshhold) ? 0.f : alpha * (x_t)+(1 - alpha) * fft_uniform[i];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
syncs[0] = (float)playCursor / (SU_SAMPLE_RATE * SU_CHANNEL_COUNT * SU_SAMPLE_SIZE); // Aika sekunteina.
|
syncs[0] = (float)playCursor / (SU_SAMPLE_RATE * SU_CHANNEL_COUNT * SU_SAMPLE_SIZE); // Aika sekunteina.
|
||||||
|
|
||||||
for (int i = 0; i < SU_NUMSYNCS; ++i)
|
for (int i = 0; i < SU_NUMSYNCS; ++i)
|
||||||
{
|
{
|
||||||
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);
|
||||||
|
|
||||||
|
|||||||
@ -1,30 +1,26 @@
|
|||||||
#version 460
|
#version 460
|
||||||
precision mediump float;
|
precision mediump float;
|
||||||
out vec4 o;
|
out vec4 o;
|
||||||
const float PI = 3.14159265;
|
float PHI = sqrt(5.) * 0.5 + 0.5;
|
||||||
const float TAU = (2. * PI);
|
|
||||||
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
|
float u_time = syncs[0];
|
||||||
layout(location = 700) uniform vec3 test; // shapes test
|
//float u_time = syncs[0];
|
||||||
//layout(binding = 1) uniform sampler2D u_hexGridTex; //uniform sampler2D u_fft_texture;
|
|
||||||
|
|
||||||
layout(binding = 0) uniform sampler2D u_ShapesTex; // uniform sampler2D shapes texture
|
// paletti muunnos: arg 0.8 --> 0.5
|
||||||
// float u_time = syncs[0];
|
vec3 palette(float t, float arg, float arg2){
|
||||||
|
vec3 a=vec3(0.52,0.56,0.47);
|
||||||
vec3 palette(float t){
|
vec3 b=vec3(0.62,0.56,0.51);
|
||||||
vec3 a=vec3(0.46,0.2,0.94);
|
vec3 c=vec3(0.43,0.79,0.42);
|
||||||
vec3 b=vec3(0.66,0.64,0.77);
|
vec3 d=vec3(arg,0.42,arg2);
|
||||||
vec3 c=vec3(0.91,0.62,0.97);
|
|
||||||
vec3 d=vec3(0.26,0.2,0.84);
|
|
||||||
return a+b*cos(6.28318*(c*t+d));
|
return a+b*cos(6.28318*(c*t+d));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
vec2 getUV() {
|
vec2 getUV() {
|
||||||
const vec2 scale = vec2(0.00104166667, 0.00185185185);
|
vec2 u_resolution = vec2(1920, 1080);
|
||||||
return gl_FragCoord.xy * scale - 1.0;
|
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
mat2 rot2D(float angle) {
|
mat2 rot2D(float angle) {
|
||||||
@ -37,6 +33,12 @@ float noise(in vec2 xy, in float seed) {
|
|||||||
return fract(tan(distance(xy * PHI, xy) * seed) * xy.x);
|
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 lev2(vec2 s) { return length(s); }
|
||||||
|
|
||||||
|
|
||||||
/////////////////
|
/////////////////
|
||||||
// GEOMETRY //
|
// GEOMETRY //
|
||||||
/////////////////
|
/////////////////
|
||||||
@ -85,80 +87,38 @@ float hexDistance(vec2 axial) {
|
|||||||
return max(abs(q), max(abs(r), abs(s)));
|
return max(abs(q), max(abs(r), abs(s)));
|
||||||
}
|
}
|
||||||
|
|
||||||
float sdSphere(vec3 p, float r) {
|
// Scene mapping with occlusion-aware SDF blending
|
||||||
return length(p) - r;
|
vec2 mapScene(vec3 p) {
|
||||||
}
|
float dist = 20.;
|
||||||
|
int repeat = 0;
|
||||||
|
if((lev2(p.xz)) < 2*dist){
|
||||||
|
repeat = 2;
|
||||||
|
}
|
||||||
|
if((lev2(p.xz)) < 1.5*dist){
|
||||||
|
repeat = 3;
|
||||||
|
}
|
||||||
|
if((lev2(p.xz)) < dist){
|
||||||
|
repeat = 5;
|
||||||
|
}
|
||||||
|
|
||||||
float hexPylon(vec3 p, vec2 h) {
|
// mitigate neighbor occlusion with anti-bleed blending
|
||||||
//vec3 p = vec3(p.x, p.z, p2.y);
|
float minDist = 1e9;
|
||||||
vec3 b = vec3(h.x, h.y, h.x);
|
for (int dx = -repeat; dx <= repeat; ++dx) {
|
||||||
|
for (int dy = -repeat; dy <= repeat; ++dy) {
|
||||||
// Hexagon.
|
vec3 hexpos = vec3(p.x-dx, p.y-8.0, p.z-dy);
|
||||||
p.xz = abs(p.xz);
|
HexData hex = hexTile(hexpos, 1.1);
|
||||||
p.xz = vec2(p.x * .866025 + p.z * .5, p.z);
|
float distFromCenter = hexDistance(hex.axial);
|
||||||
// The ".015" is a subtle rounding factor. Zero gives sharp edges,
|
int fftIndex = int(cl(distFromCenter + 1., 0.0, 511.0));
|
||||||
// and larger numbers give a more rounded look.
|
float noise = mix(noise(hex.axial+1., 0.1), noise(hex.axial+1., 0.2), sin(u_time * 4.));
|
||||||
return length(max(abs(p) - b + .15, 0.)) - .15;
|
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);
|
||||||
// SCENE //
|
float d = fHexagonCircumcircle(r, vec2(0.85, hexHeight));
|
||||||
//////////////
|
minDist = min(minDist, d);
|
||||||
|
|
||||||
// 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 opU( float d1, float d2 ) { return -max( -d1, -d2 ); }
|
|
||||||
|
|
||||||
vec2 mapScene(in vec3 p) {
|
|
||||||
|
|
||||||
float res = p.y;
|
|
||||||
float mat = 0.;
|
|
||||||
|
|
||||||
float hexRadius = 0.85;
|
|
||||||
vec3 hexpos = vec3(p.x, p.y - 2.5, p.z);
|
|
||||||
HexData hex = hexTile(hexpos, 1.5);
|
|
||||||
|
|
||||||
float distFromCenter = hexDistance(hex.axial);
|
|
||||||
int fftIndex = int(clamp(distFromCenter + 1.0, 0.0, 511.0));
|
|
||||||
float fftVal = fft_output[fftIndex];
|
|
||||||
float hexHeight = 1.0 + fftVal * 4.0;
|
|
||||||
|
|
||||||
// Rotate individual hex tiles if needed
|
|
||||||
vec3 r = hex.local;
|
|
||||||
// r.yz *= rot2D(PI * 0.5);
|
|
||||||
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));
|
|
||||||
|
|
||||||
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(minDist,0.);
|
||||||
return vec2(res, mat);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////
|
////////////////
|
||||||
@ -166,35 +126,45 @@ vec2 mapScene(in vec3 p) {
|
|||||||
////////////////
|
////////////////
|
||||||
|
|
||||||
vec3 castRay(vec3 ro, vec3 rd, inout vec3 pos) {
|
vec3 castRay(vec3 ro, vec3 rd, inout vec3 pos) {
|
||||||
float mat = 0.;
|
|
||||||
float hit = 0.;
|
float hit = 0.;
|
||||||
float t = 0.;
|
float t = 0.; // total distance travelled
|
||||||
vec2 res;
|
|
||||||
|
|
||||||
// Raymarching
|
// Raymarching
|
||||||
for(int i = 0; i < 20; i++) {
|
for (int i = 0; i < 50; i++) {
|
||||||
pos = ro + rd * t;
|
pos = ro + rd * t;
|
||||||
res = mapScene(pos); // Get distance to objects, x = dist, y = material
|
vec2 res = mapScene(pos); // Get distance to objects
|
||||||
mat = res.y;
|
if (t > 200.) break;
|
||||||
t += res.x; // "march" the ray
|
if (abs(res.x) < 1e-4) {
|
||||||
|
hit = 1.0;
|
||||||
// if(abs(t) < tolerance * (t * 0.0125 + 1.0)) {
|
|
||||||
if(abs(res.x) < 0.0001) {
|
|
||||||
hit = 1.;
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if(t > 200)
|
t += res.x; // "march" the ray
|
||||||
break;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
// t -= Z_REPEAT_DIST/2.0;
|
||||||
|
//
|
||||||
|
// for( int i=0; i<20; i++ )
|
||||||
|
// {
|
||||||
|
// vec3 pos2 = ro + rd * t;
|
||||||
|
// res = mapScene(pos2); // get distance to objects
|
||||||
|
// ad = abs(res.x);
|
||||||
|
// mat = res.y;
|
||||||
|
// if (ad < (tolerance))
|
||||||
|
// {
|
||||||
|
// hit = 1.0;
|
||||||
|
// pos = pos2;
|
||||||
|
// break;
|
||||||
|
// }
|
||||||
|
// if (t > tmax) break;
|
||||||
|
// t += min(d.x, Z_REPEAT_DIST/5.0); // "march" the ray
|
||||||
|
// }
|
||||||
|
|
||||||
return vec3(t, mat, hit);
|
return vec3(t, 0., hit);
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////
|
////////////////
|
||||||
// SHADING //
|
// SHADING //
|
||||||
////////////////
|
////////////////
|
||||||
|
/*
|
||||||
float softshadow(in vec3 ro, in vec3 rd, float mint, float maxt, float w) {
|
float softshadow(in vec3 ro, in vec3 rd, float mint, float maxt, float w) {
|
||||||
float res = 1.0;
|
float res = 1.0;
|
||||||
float t = mint;
|
float t = mint;
|
||||||
@ -203,25 +173,21 @@ float softshadow(in vec3 ro, in vec3 rd, float mint, float maxt, float w) {
|
|||||||
break;
|
break;
|
||||||
float h = mapScene(ro + t * rd).x;
|
float h = mapScene(ro + t * rd).x;
|
||||||
res = min(res, h / (w * t));
|
res = min(res, h / (w * t));
|
||||||
t += clamp(h, 0.1, 0.80);
|
t += cl(h, 0.1, 0.80);
|
||||||
if(res < -1.0)
|
if(res < -1.0)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
res = max(res, -1.0);
|
res = max(res, -1.0);
|
||||||
return 0.25 * (1.0 + res) * (1.0 + res) * (2.0 - res);
|
return 0.25 * (1.0 + res) * (1.0 + res) * (2.0 - res);
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
vec3 calcNormal(vec3 pos) {
|
vec3 addPointLight(vec3 lightPos, vec3 lightColor, float intensity, vec3 worldPos, vec3 viewDir, vec3 normal) {
|
||||||
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
|
// Light vector from surface to light
|
||||||
|
//float roughness = 1.0;
|
||||||
vec3 lightDir = lightPos - worldPos;
|
vec3 lightDir = lightPos - worldPos;
|
||||||
float lightDistance = length(lightDir);
|
float lightDistance = length(lightDir);
|
||||||
lightDir = normalize(lightDir);
|
lightDir = no(lightDir);
|
||||||
|
|
||||||
// Attenuation (quadratic falloff)
|
// Attenuation (quadratic falloff)
|
||||||
float attenuation = intensity / (1.0 + 0.09 * lightDistance + 0.032 * lightDistance * lightDistance);
|
float attenuation = intensity / (1.0 + 0.09 * lightDistance + 0.032 * lightDistance * lightDistance);
|
||||||
@ -231,201 +197,136 @@ vec3 addPointLight(vec3 lightPos, vec3 lightColor, float intensity, vec3 worldPo
|
|||||||
vec3 diffuse = lightColor * NdotL * attenuation;
|
vec3 diffuse = lightColor * NdotL * attenuation;
|
||||||
|
|
||||||
// Specular lighting (Blinn-Phong)
|
// Specular lighting (Blinn-Phong)
|
||||||
vec3 halfDir = normalize(lightDir + (-viewDir));
|
/*
|
||||||
|
vec3 halfDir = no(lightDir + (-viewDir));
|
||||||
float NdotH = max(dot(normal, halfDir), 0.0);
|
float NdotH = max(dot(normal, halfDir), 0.0);
|
||||||
float shininess = mix(128.0, 8.0, roughness); // Convert roughness to shininess
|
float shininess = mix(128.0, 8.0, roughness); // Convert roughness to shininess
|
||||||
vec3 specular = lightColor * pow(NdotH, shininess) * attenuation;
|
*/
|
||||||
|
vec3 specular = lightColor * attenuation;
|
||||||
|
|
||||||
// Fresnel effect
|
// Fresnel effect
|
||||||
vec3 F0 = vec3(0.04); // Base reflectance for dielectrics
|
//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);
|
//vec3 fresnel = F0 + (1.0 - F0) * pow(cl(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
|
// Combine diffuse and specular with shadow
|
||||||
return (diffuse + specular * fresnel) * shadow;
|
// return (diffuse + specular * fresnel) * shadow * shadow;
|
||||||
|
//return (diffuse * fresnel);
|
||||||
|
return diffuse + specular;
|
||||||
}
|
}
|
||||||
|
|
||||||
float getAmbientOcc(vec3 p, vec3 n) {
|
vec3 calcNormal(vec3 pos) {
|
||||||
float occ = 0.;
|
vec2 e = vec2(.01, 0.);
|
||||||
float weight = 1.;
|
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);
|
||||||
for(int i = 0; i < 8; i++) {
|
return no(n);
|
||||||
float len = 0.01 + 0.02 * float(i * i);
|
|
||||||
float dist = mapScene(p + n * len).x;
|
|
||||||
occ += (len - dist) * weight;
|
|
||||||
weight *= 0.85;
|
|
||||||
}
|
|
||||||
return 1.0 - clamp(0.6 * occ, 0., 1.);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
vec3 applyFog(vec3 col, float t, vec3 rd, vec3 lightDir, float fogAmount) {
|
vec3 pal(float color) {
|
||||||
|
//color *= 0.2;
|
||||||
|
vec3 c = palette(color, 0.25, 0.63);
|
||||||
|
vec3 c2 = palette(color, 0.5 ,0.2);
|
||||||
|
|
||||||
float syncsBass = clamp((syncs[1] + syncs[2] + syncs[3]), 0., 1.);
|
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
|
||||||
float fogAmount2 = 1.0 - exp(-t * fogAmount);
|
//return c2;
|
||||||
float sunAmount = max(dot(rd, lightDir), 0.0);
|
|
||||||
// highlight color
|
|
||||||
vec3 fogColor = mix(vec3(0.2706, 0.2706, 0.2863), vec3(0.2314, 0.2314, 0.2314), // Main color
|
|
||||||
pow(sunAmount, syncsBass * 1.0));
|
|
||||||
return mix(col, fogColor, fogAmount2);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Point light with no shadow and radius based falloff
|
vec3 applyFog(vec3 color, float dist, vec3 fogColor, float fogDensity) {
|
||||||
vec3 addPointLightNoShadow(vec3 lightPos, vec3 lightColor, float intensity, float radius, vec3 worldPos, vec3 viewDir, vec3 normal, float roughness) {
|
float fogFactor = exp(-dist * fogDensity);
|
||||||
// Light vector from surface to light
|
return mix(fogColor, color, fogFactor);
|
||||||
vec3 lightDir = lightPos - worldPos;
|
|
||||||
float lightDistance = length(lightDir);
|
|
||||||
lightDir = normalize(lightDir);
|
|
||||||
|
|
||||||
// Attenuation (radius based falloff)
|
|
||||||
float attenuation = clamp(intensity - lightDistance * lightDistance / (radius * radius), 0.0, 1.0);
|
|
||||||
|
|
||||||
// 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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*vec3 addPointLight(vec3 lightPos, vec3 lightColor, float intensity, vec3 worldPos, vec3 viewDir, vec3 normal) {
|
//vec3 applyFog(vec3 col, float t, vec3 rd, vec3 lightDir, float fogAmount) {
|
||||||
vec3 lightDir = normalize(lightPos - worldPos);
|
//
|
||||||
float lightDistance = length(lightPos - worldPos);
|
// 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);
|
||||||
|
//}
|
||||||
|
|
||||||
// Attenuation
|
/*
|
||||||
float attenuation = intensity / (1.0 + 0.1 * lightDistance + 0.01 * lightDistance * lightDistance);
|
vec3 shading(vec3 p, vec3 n, vec3 dir, vec3 caPos) {
|
||||||
|
vec3 outMaterial = vec3(0.0);
|
||||||
|
|
||||||
// Diffuse
|
outMaterial = pal(p.y*p.y*0.01);
|
||||||
float NdotL = max(dot(normal, lightDir), 0.0);
|
|
||||||
|
|
||||||
// Specular (Blinn-Phong)
|
|
||||||
vec3 halfDir = normalize(lightDir - viewDir);
|
|
||||||
float NdotH = max(dot(normal, halfDir), 0.0);
|
|
||||||
float specular = pow(NdotH, 32.0);
|
|
||||||
|
|
||||||
// Shadow
|
|
||||||
float shadow = softshadow(worldPos + normal * 0.01, lightDir, 0.01, lightDistance, 8.0);
|
|
||||||
|
|
||||||
return lightColor * (NdotL + specular * 0.5) * attenuation * shadow;
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
vec3 shading(vec3 p, vec3 n, vec3 dir, float material) {
|
|
||||||
float shininess = 0.01;
|
|
||||||
|
|
||||||
vec3 outMaterial = vec3(0.);
|
|
||||||
|
|
||||||
if(material == 0.) {
|
|
||||||
outMaterial = vec3(0.4941, 0.4941, 0.4941);
|
|
||||||
shininess = 0.6;
|
|
||||||
} else if(material == 1.) {
|
|
||||||
outMaterial = vec3(0.6196, 0.6118, 0.6118);
|
|
||||||
shininess = .7;
|
|
||||||
} else if(material == 2.) {
|
|
||||||
outMaterial = vec3(0.3255, 0.4784, 0.3255);
|
|
||||||
shininess = .2;
|
|
||||||
} else if(material == 3.) {
|
|
||||||
outMaterial = vec3(0.2471, 0.3059, 0.6314);
|
|
||||||
shininess = 1.0;
|
|
||||||
} else if(material == 4.) {
|
|
||||||
outMaterial = vec3(0.9961, 1.0, 0.9922);
|
|
||||||
shininess = .1;
|
|
||||||
} else if(material == 5.) {
|
|
||||||
outMaterial = vec3(0.9961, 1.0, 0.9922);
|
|
||||||
shininess = .3;
|
|
||||||
}
|
|
||||||
|
|
||||||
vec3 lights = vec3(0.);
|
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 += phongLighting(p, n, camPos, dir, vec3(0.51), outMaterial);
|
||||||
lights += addPointLight(vec3(-10., 20.0, -10.), vec3(0.18, 0.61, 0.86), 15., p, dir, n, shininess);
|
lights += addPointLight(vec3(0., 20.0, 0.), vec3(0.7, 0.3, 0.7), 15.0, p, dir, n);
|
||||||
|
|
||||||
// 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
|
// LIGHT CHANGING WITH CIRCLE RADIUS
|
||||||
|
float maxRadius = 25.; // Circle radius
|
||||||
|
float particleHeight = 15.; //(syncs[5] * 40.);
|
||||||
|
float particlePos = (u_time * 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 = no(vec3(cos(particleStartPos), 0.0, sin(particleStartPos))); // XZ direction
|
||||||
|
|
||||||
vec3 hexPos = hexData.rgb;
|
float r = max(maxRadius - 0.0, maxRadius);
|
||||||
float hexDist = hexData.a;
|
|
||||||
|
|
||||||
// Optionally use hexDist for ripple effect with FFT
|
vec3 particleOffset = vec3(0. , particleHeight, 0.); // particle offset
|
||||||
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);
|
// 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);
|
vec3 lightDir = vec3(0., 2., 3);
|
||||||
//float sun_dif = clamp(dot(n, lightDir), 0., 1.);
|
float ind = cl(dot(n, no(lightDir * vec3(.0, 1.0, -2.0))), 0.0, 1.0);
|
||||||
//float shadow = softshadow(v + n * 0.01, lightDir, .01, 30., 18.);
|
lights += vec3(0.6, 0.6, 0.6) * ind * 0.4;
|
||||||
//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);
|
|
||||||
lights += vec3(0.08, 0.62, 0.75) * ind * 0.8;
|
|
||||||
|
|
||||||
outMaterial *= max(vec3(0.), lights); // output with lights;
|
outMaterial *= max(vec3(0.), lights); // output with lights;
|
||||||
|
|
||||||
return outMaterial;
|
return outMaterial;
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
vec3 postProcess(vec3 col) {
|
vec3 postProcess(vec3 col) {
|
||||||
// Contrast
|
// Contrast
|
||||||
float contrast = 0.75;
|
float contrast = 0.85;
|
||||||
|
|
||||||
col = mix(col, smoothstep(0.0, 1.0, col), contrast);
|
col = mix(col, smoothstep(0.0, 1.0, col), contrast);
|
||||||
|
|
||||||
// Colour mapping
|
// Colour mapping
|
||||||
// col *= vec3(1.0, 1.0, 1.0);
|
//col *= vec3(1.0, 1.0, 1.0);
|
||||||
|
|
||||||
// Gamma
|
// Gamma
|
||||||
col = pow(col, vec3(0.4545)); // gamma 2.2
|
col = pow(col, vec3(.55)); // gamma 2.2
|
||||||
|
|
||||||
// fade in at the beginning
|
// fade in at the beginning
|
||||||
//col*=vec3(clamp((u_time-1.8)*0.5,0., 1.));
|
//col*=vec3(cl((u_time-1.8)*0.5,0., 1.));
|
||||||
|
|
||||||
// fade out at the end
|
// fade out at the end
|
||||||
// col*=vec3(clamp((120.-u_time)*.35, 0., 1.));
|
// col*=vec3(cl((120.-u_time)*.35, 0., 1.));
|
||||||
|
|
||||||
return col;
|
return col;
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
//////////////////
|
//////////////////
|
||||||
// RENDERING //
|
// RENDERING //
|
||||||
//////////////////
|
//////////////////
|
||||||
|
|
||||||
vec3 getCameraRayDir(vec2 uv, vec3 camPos, vec3 camTarget, float fov) {
|
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;
|
return d;
|
||||||
}
|
}
|
||||||
|
|
||||||
vec3 render(vec2 uv) {
|
vec3 render(vec2 uv) {
|
||||||
vec3 camPos = vec3(-20.0 + sin(syncs[0] * 0.25) * 5, abs(sin(syncs[0] * 0.25) * 10) + 25.0, -20.0);
|
vec3 camPos = vec3(-20.0 + sin(u_time * 0.25) * 5, abs(sin(u_time * 0.25) * 10) + 25.0, -20.0);
|
||||||
vec3 camTarget = vec3(0.0, 0.0, 0.0); // Adjust target as needed
|
// vec3 camTarget = vec3(0.) // Adjust target as needed
|
||||||
float fov = 1.0;
|
//float fov = 1.0;
|
||||||
|
|
||||||
vec3 rayDir = getCameraRayDir(uv, camPos, camTarget, fov);
|
vec3 rayDir = getCameraRayDir(uv, camPos, vec3(0.), 1.0);
|
||||||
|
|
||||||
vec3 col = vec3(0.); // background color
|
vec3 col = vec3(0.); // background color
|
||||||
|
|
||||||
@ -434,54 +335,43 @@ vec3 render(vec2 uv) {
|
|||||||
|
|
||||||
if(t.x > 0.0) {
|
if(t.x > 0.0) {
|
||||||
vec3 nor = calcNormal(hitPos);
|
vec3 nor = calcNormal(hitPos);
|
||||||
col = shading(hitPos, nor, rayDir, t.y);
|
//col = shading(hitPos, nor, rayDir, camPos);
|
||||||
|
|
||||||
|
//vec3 mat = vec3(0.0);
|
||||||
|
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), 5.0, hitPos, rayDir, nor);
|
||||||
|
mat *= max(vec3(0.), lights); // output with lights;
|
||||||
|
col = mat;
|
||||||
}
|
}
|
||||||
|
|
||||||
//glow from the bottom
|
//glow from the bottom
|
||||||
vec3 bGlowColor = palette(syncs[0] * .5); // color change
|
vec3 bGlowColor = pal(u_time * .075); // color change
|
||||||
float bGlowDistance = 0.3;
|
float bGlowDistance = 0.8;
|
||||||
vec3 p = camPos + t.x * rayDir;
|
vec3 p = camPos + t.x * rayDir;
|
||||||
|
|
||||||
vec3 bGlowLevel = bGlowColor * exp(-(p.y + 0.0) / bGlowDistance) * 9900.;
|
vec3 bGlowLevel = bGlowColor * exp(-(p.y + 0.0) / bGlowDistance) * 9e3;
|
||||||
col += bGlowLevel;
|
col += bGlowLevel;
|
||||||
col = clamp(mix(bGlowLevel, col, t.z), 0.0, 1.0);
|
col = clamp(mix(bGlowLevel, col, t.z), 0.0, 1.0);
|
||||||
|
|
||||||
// distance fog + bass thunder
|
// distance fog + bass thunder
|
||||||
float fogAmount = 0.01;
|
vec3 fogColor = vec3(0.1, 0.2, 0.3); // light gray-blue fog
|
||||||
col = col * exp(-t.x * fogAmount) + applyFog(col, t.x, rayDir, vec3(0., -0.5, 1.8), fogAmount) * (1.0 - exp(-t.x * fogAmount));
|
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;
|
return col;
|
||||||
}
|
}
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
vec3 finalColor = render(getUV());
|
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.);
|
o = vec4(finalColor, 1.);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
vec3 render2(vec2 uv, float time) {
|
|
||||||
|
|
||||||
vec3 res = vec3(.0);
|
|
||||||
|
|
||||||
float pos = syncs[5];
|
|
||||||
if (uv.x >= pos && uv.x <= pos+0.01 ) {
|
|
||||||
res += vec3(1.);
|
|
||||||
}
|
|
||||||
|
|
||||||
//if (uv.x >= 0.0 && uv.x <= 0.01 ) {
|
|
||||||
// res += vec3(abs(syncs[4]*2));
|
|
||||||
//}
|
|
||||||
|
|
||||||
//res += vec3(0.1, 0.2, 0.3) * abs(syncs[2]*1.2);
|
|
||||||
|
|
||||||
return res;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void main() {
|
|
||||||
vec2 uv = gl_FragCoord.xy * 2. / vec2(1920,1080);
|
|
||||||
vec3 col = render2(uv, u_time);
|
|
||||||
o = vec4(col,1.0);
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
Reference in New Issue
Block a user