säätöä
This commit is contained in:
76
src/main.cpp
76
src/main.cpp
@ -16,6 +16,11 @@
|
|||||||
#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"
|
||||||
@ -126,28 +131,14 @@ int __cdecl main(int argc, char* argv[])
|
|||||||
static float fft_input[FFT_SIZE];
|
static float fft_input[FFT_SIZE];
|
||||||
static float fft_output[FFT_SIZE / 2]; // Magnitudes
|
static float fft_output[FFT_SIZE / 2]; // Magnitudes
|
||||||
static float fft_uniform[FFT_SIZE / 4];
|
static float fft_uniform[FFT_SIZE / 4];
|
||||||
|
|
||||||
|
static float shapesData[SHAPES_TEX_SIZE];
|
||||||
|
|
||||||
// main note effect
|
// main note effect
|
||||||
boolean beenPlaying = false;
|
boolean beenPlaying = false;
|
||||||
const int SHAPES_SIZE = 15;
|
const int SHAPES_SIZE = 15;
|
||||||
float shapeIncrement = 0.15f;
|
float shapeIncrement = 0.15f;
|
||||||
|
|
||||||
/**
|
|
||||||
* Definition of shape with 3 parameters in a vec3
|
|
||||||
*
|
|
||||||
* h position, v position, length
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
float vec3ShapeArray[5][3] = {
|
|
||||||
{ 0.0f, 0.0f, 0.0f },
|
|
||||||
{ 0.0f, 0.0f, 0.0f },
|
|
||||||
{ 0.0f, 0.0f, 0.0f },
|
|
||||||
{ 0.0f, 0.0f, 0.0f },
|
|
||||||
{ 0.0f, 0.0f, 0.0f }
|
|
||||||
};
|
|
||||||
|
|
||||||
float test[3] = { 0.0f, 0.0f, 0.0f }; // test float of one shape
|
|
||||||
|
|
||||||
int currentShape = 0; // mark location which shape we are currently building
|
int currentShape = 0; // mark location which shape we are currently building
|
||||||
|
|
||||||
boolean isPlaying = false;
|
boolean isPlaying = false;
|
||||||
@ -155,43 +146,17 @@ int __cdecl main(int argc, char* argv[])
|
|||||||
float lastPlayPos = 0;
|
float lastPlayPos = 0;
|
||||||
float lastNote = 0.0f;
|
float lastNote = 0.0f;
|
||||||
|
|
||||||
/*GLfloat shapes[5][3] = {
|
|
||||||
{ 0.0f, 0.0f, 0.0f },
|
|
||||||
{ 0.0f, 0.0f, 0.0f },
|
|
||||||
{ 0.0f, 0.0f, 0.0f },
|
|
||||||
{ 0.0f, 0.0f, 0.0f },
|
|
||||||
{ 0.0f, 0.0f, 0.0f }
|
|
||||||
};*/
|
|
||||||
|
|
||||||
|
|
||||||
struct Vec3 {
|
struct Vec3 {
|
||||||
float x, y, z;
|
float x, y, z;
|
||||||
};
|
};
|
||||||
|
|
||||||
#define GRID 32
|
|
||||||
#define HEX_TEX_SIZE (GRID * GRID * 4) // RGBA: 4 floats per texel
|
|
||||||
|
|
||||||
#define SHAPES 16
|
|
||||||
#define SHAPES_TEX_SIZE (SHAPES * SHAPES * 4)
|
|
||||||
#define SHAPES_TOTAL (SHAPES * SHAPES)
|
|
||||||
#define MAX_DISTANCE 100.f
|
|
||||||
|
|
||||||
PFNGLUNIFORM1FVPROC glUniform1fvProc = ((PFNGLUNIFORM1FVPROC)wglGetProcAddress("glUniform1fv"));
|
PFNGLUNIFORM1FVPROC glUniform1fvProc = ((PFNGLUNIFORM1FVPROC)wglGetProcAddress("glUniform1fv"));
|
||||||
PFNGLACTIVETEXTUREPROC glActiveTexture = ((PFNGLACTIVETEXTUREPROC)wglGetProcAddress("glActiveTexture"));
|
PFNGLACTIVETEXTUREPROC glActiveTexture = ((PFNGLACTIVETEXTUREPROC)wglGetProcAddress("glActiveTexture"));
|
||||||
PFNGLUNIFORM1IPROC glUniform1i = ((PFNGLUNIFORM1IPROC)wglGetProcAddress("glUniform1i"));
|
PFNGLUNIFORM1IPROC glUniform1i = ((PFNGLUNIFORM1IPROC)wglGetProcAddress("glUniform1i"));
|
||||||
PFNGLGETUNIFORMLOCATIONPROC glGetUniformLocation = ((PFNGLGETUNIFORMLOCATIONPROC)wglGetProcAddress("glGetUniformLocation"));
|
PFNGLGETUNIFORMLOCATIONPROC glGetUniformLocation = ((PFNGLGETUNIFORMLOCATIONPROC)wglGetProcAddress("glGetUniformLocation"));
|
||||||
|
|
||||||
GLuint hexGridTex, ShapesTex;
|
GLuint ShapesTex;
|
||||||
glGenTextures(1, &hexGridTex);
|
|
||||||
glBindTexture(GL_TEXTURE_2D, hexGridTex);
|
|
||||||
|
|
||||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA32F, GRID, GRID, 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);
|
|
||||||
|
|
||||||
|
|
||||||
glGenTextures(1, &ShapesTex);
|
glGenTextures(1, &ShapesTex);
|
||||||
glBindTexture(GL_TEXTURE_2D, ShapesTex);
|
glBindTexture(GL_TEXTURE_2D, ShapesTex);
|
||||||
@ -271,11 +236,11 @@ int __cdecl main(int argc, char* argv[])
|
|||||||
{
|
{
|
||||||
float gain = 50.0f;
|
float gain = 50.0f;
|
||||||
float alpha = 0.10f; // "Hidastaa" FFT:n piikkej<65>
|
float alpha = 0.10f; // "Hidastaa" FFT:n piikkej<65>
|
||||||
float threshhold = 0.05f; // Alin arvo mik<69> p<><70>stet<65><74>n shaderille (v<>hent<6E><74> "noisea")
|
float threshhold = 0.015f; // Alin arvo mik<69> p<><70>stet<65><74>n shaderille (v<>hent<6E><74> "noisea")
|
||||||
float x_t = fft_output[i] * gain;
|
float x_t = (fft_output[i] < threshhold) ? 0.f : 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] = (x_t < threshhold) ? 0.f : alpha * (x_t)+(1 - alpha) * fft_uniform[i];
|
fft_uniform[i] = 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.
|
||||||
@ -294,7 +259,6 @@ int __cdecl main(int argc, char* argv[])
|
|||||||
// if sound is playing, start a shape, if shape is already started - add length
|
// if sound is playing, start a shape, if shape is already started - add length
|
||||||
// if sound has stopped, end shape
|
// if sound has stopped, end shape
|
||||||
// if shape is finished, move shape forward
|
// if shape is finished, move shape forward
|
||||||
static float shapesData[SHAPES_TEX_SIZE];
|
|
||||||
float captureSync = syncs[5];
|
float captureSync = syncs[5];
|
||||||
|
|
||||||
bool shapeJustFinished = false;
|
bool shapeJustFinished = false;
|
||||||
@ -304,7 +268,6 @@ int __cdecl main(int argc, char* argv[])
|
|||||||
bool noteChanged = (captureSync != lastNote) ? TRUE : FALSE;
|
bool noteChanged = (captureSync != lastNote) ? TRUE : FALSE;
|
||||||
lastNote = captureSync;
|
lastNote = captureSync;
|
||||||
|
|
||||||
|
|
||||||
// If note changed and value is significant, start new shape
|
// If note changed and value is significant, start new shape
|
||||||
if (noteChanged) {
|
if (noteChanged) {
|
||||||
int index = currentShape * 4;
|
int index = currentShape * 4;
|
||||||
@ -349,23 +312,6 @@ int __cdecl main(int argc, char* argv[])
|
|||||||
glActiveTexture(GL_TEXTURE0 + 0);
|
glActiveTexture(GL_TEXTURE0 + 0);
|
||||||
glBindTexture(GL_TEXTURE_2D, ShapesTex);
|
glBindTexture(GL_TEXTURE_2D, ShapesTex);
|
||||||
glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, SHAPES, SHAPES, GL_RGBA, GL_FLOAT, shapesData);
|
glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, SHAPES, SHAPES, GL_RGBA, GL_FLOAT, shapesData);
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
float flatShapes[15] = {
|
|
||||||
vec3ShapeArray[0][0], vec3ShapeArray[0][1], vec3ShapeArray[0][2],
|
|
||||||
vec3ShapeArray[1][0], vec3ShapeArray[1][1], vec3ShapeArray[1][2],
|
|
||||||
vec3ShapeArray[2][0], vec3ShapeArray[2][1], vec3ShapeArray[2][2],
|
|
||||||
vec3ShapeArray[3][0], vec3ShapeArray[3][1], vec3ShapeArray[3][2],
|
|
||||||
vec3ShapeArray[4][0], vec3ShapeArray[4][1], vec3ShapeArray[4][2]
|
|
||||||
};
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//PFNGLUNIFORM3FVPROC glUniform3fvProc = ((PFNGLUNIFORM3FVPROC)wglGetProcAddress("glUniform3fv"));
|
|
||||||
//glUniform3fvProc(600, 1, flatShapes); // array of shapes
|
|
||||||
//glUniform3fvProc(700, 1, test); // test shape
|
|
||||||
|
|
||||||
|
|
||||||
glUniform1fvProc(0, SU_NUMSYNCS + 1, syncs);
|
glUniform1fvProc(0, SU_NUMSYNCS + 1, syncs);
|
||||||
|
|||||||
@ -54,43 +54,7 @@ float hexPylon(vec3 p, vec2 h) {//float r, float ht){
|
|||||||
p.xz = vec2(p.x*.866025 + p.z*.5, p.z);
|
p.xz = vec2(p.x*.866025 + p.z*.5, p.z);
|
||||||
// The ".015" is a subtle rounding factor. Zero gives sharp edges,
|
// The ".015" is a subtle rounding factor. Zero gives sharp edges,
|
||||||
// and larger numbers give a more rounded look.
|
// and larger numbers give a more rounded look.
|
||||||
return length(max(abs(p) - b + .015, 0.)) - .015;
|
return length(max(abs(p) - b + .15, 0.)) - .15;
|
||||||
}
|
|
||||||
|
|
||||||
#define zclamp(a) max(a,0.0) //Clamp negative values at zero
|
|
||||||
float DF_RoundedHex( vec3 p, vec2 h) //float width, float height)
|
|
||||||
{
|
|
||||||
float width = h.x;
|
|
||||||
float height = h.y;
|
|
||||||
//Modified version (smooth edges) of the exagon prism found here:
|
|
||||||
//https://iquilezles.org/articles/distfunctions
|
|
||||||
float smoothRadius = 0.05;
|
|
||||||
width -= smoothRadius*2.0;
|
|
||||||
|
|
||||||
//Hexagon prism constructed using X,Y,Z symmetry.
|
|
||||||
//Only quadrant 1 needs to be solved, but the joining diagonal to quadrant IV is also
|
|
||||||
//required for distance blending (see db).
|
|
||||||
p = abs(p);
|
|
||||||
|
|
||||||
//Hexagonal edge distances :
|
|
||||||
//Note : [.8666,0.5] = [sin(PI/3,cos(PI/3)] -> Hexagon edges rotation coeff (60 degrees).
|
|
||||||
float da = (p.x*0.866025+p.z*0.5)-width; //quadrant I diagonal edge distance
|
|
||||||
float db = (p.x*0.866025-p.z*0.5)-width; //quadrant IV diagonal edge distance (needed for blending)
|
|
||||||
float dc = p.z-width; //upper distance
|
|
||||||
|
|
||||||
vec3 d = zclamp(vec3(da,db,dc));
|
|
||||||
//Note: this is not an euclidian length, therefore this operation slightly distorts our distance field.
|
|
||||||
//Yet, it is harmless to convergence, and does the smoothing job quite well.
|
|
||||||
float dw = length(d)-smoothRadius; //hexagonal part smoothness (blending at 60 deg)
|
|
||||||
float dh = p.y-height;
|
|
||||||
|
|
||||||
//Now that we have xz distance(dw) and y distance (dh), we can compute the distance
|
|
||||||
//for the given isovalue (the smoothing radius).
|
|
||||||
//Note : internal distance (maxX,maxY,maxZ) is also used to genereate internal signed dist,
|
|
||||||
// helping convergence when overstepping (very frequent with domain repetition).
|
|
||||||
float externalDistance = length(zclamp(vec2(dh,dw)))-smoothRadius; //Smoothed, unsigned
|
|
||||||
float internalDistance = max(max(da,dc),dh); //Sharp, signed.
|
|
||||||
return min(externalDistance,internalDistance);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Return local coordinates inside hex AND axial ID
|
// Return local coordinates inside hex AND axial ID
|
||||||
@ -164,20 +128,18 @@ vec2 mapScene(in vec3 p) {
|
|||||||
vec3 hexpos = vec3(p.x, p.y - 2.5, p.z);
|
vec3 hexpos = vec3(p.x, p.y - 2.5, p.z);
|
||||||
|
|
||||||
HexData hex = hexTile(hexpos, 1.0);
|
HexData hex = hexTile(hexpos, 1.0);
|
||||||
|
|
||||||
// Use axial coordinates as a stable hex ID
|
|
||||||
float distFromCenter = hexDistance(hex.axial);
|
float distFromCenter = hexDistance(hex.axial);
|
||||||
int fftIndex = int(clamp(distFromCenter +1.0, 0.0, 511.0)); // tweak 15.0 to taste
|
int fftIndex = int(clamp(distFromCenter +1.0, 0.0, 511.0)); // tweak 15.0 to taste
|
||||||
|
|
||||||
float fftVal = fft_output[fftIndex];
|
float fftVal = fft_output[fftIndex];
|
||||||
float hexHeight = 1.0 + fftVal * 3.0;
|
float hexHeight = 1.0 + fftVal * 3.0;
|
||||||
|
|
||||||
// Rotate individual hex tiles if needed
|
// Rotate individual hex tiles if needed
|
||||||
vec3 r = hex.local;
|
vec3 r = hex.local;
|
||||||
//r.yz *= rot2D(1.0);
|
//r.yz *= rot2D(1.0);
|
||||||
r.xz *= rot2D(0.5);
|
r.xz *= rot2D(0.5);
|
||||||
|
|
||||||
float d1 = fHexagonCircumcircle(vec3(r.x,(r.y-hexHeight/2),r.z), vec2(hexRadius, hexHeight/2));
|
float d1 = hexPylon(vec3(r.x,(r.y-hexHeight/2),r.z), vec2(hexRadius, hexHeight/2));
|
||||||
res = min(res, vec2(d1,0.));
|
res = min(res, vec2(d1,0.));
|
||||||
|
|
||||||
float gridSize2 = 16.;
|
float gridSize2 = 16.;
|
||||||
@ -211,22 +173,22 @@ vec3 castRay(vec3 ro, vec3 rd, inout vec3 pos) {
|
|||||||
vec3 d;
|
vec3 d;
|
||||||
float t = 0.,ad,tmax=400.; // total distance travelled
|
float t = 0.,ad,tmax=400.; // total distance travelled
|
||||||
const float tolerance = 0.001;
|
const float tolerance = 0.001;
|
||||||
const float Z_REPEAT_DIST = 1.;
|
const float Z_REPEAT_DIST = 2.;
|
||||||
vec2 res;
|
vec2 res;
|
||||||
|
|
||||||
// // Raymarching
|
// Raymarching
|
||||||
// for (int i = 0; i < 50; i++) {
|
for (int i = 0; i < 50; i++) {
|
||||||
// pos = ro + rd * t;
|
pos = ro + rd * t;
|
||||||
// res = mapScene(pos); // Get distance to objects
|
res = mapScene(pos); // Get distance to objects
|
||||||
// ad = abs(res.x);
|
ad = abs(res.x);
|
||||||
// mat = res.y;
|
mat = res.y;
|
||||||
// if (t > tmax) break;
|
if (t > tmax) break;
|
||||||
// if (ad < tolerance*(t*0.125 + 1.0)) {
|
if (ad < tolerance*(t*0.0125 + 1.0)) {
|
||||||
// hit = 1.0;
|
hit = 1.0;
|
||||||
// break;
|
break;
|
||||||
// }
|
}
|
||||||
// t += res.x; // "march" the ray
|
t += res.x; // "march" the ray
|
||||||
// }
|
}
|
||||||
// t -= Z_REPEAT_DIST*1.;
|
// t -= Z_REPEAT_DIST*1.;
|
||||||
//
|
//
|
||||||
// for( int i=0; i<30; i++ )
|
// for( int i=0; i<30; i++ )
|
||||||
@ -249,20 +211,20 @@ vec3 castRay(vec3 ro, vec3 rd, inout vec3 pos) {
|
|||||||
// hit = 0.;
|
// hit = 0.;
|
||||||
//}
|
//}
|
||||||
//Reduced from 40 to 24 steps
|
//Reduced from 40 to 24 steps
|
||||||
for(int i = 0; i < 30; i++) {
|
// for(int i = 0; i < 30; i++) {
|
||||||
pos = ro + rd * t;
|
// pos = ro + rd * t;
|
||||||
vec2 res = mapScene(pos);
|
// vec2 res = mapScene(pos);
|
||||||
// Increase step size multiplier for faster marching
|
// // Increase step size multiplier for faster marching
|
||||||
t += res.x;
|
// t += res.x;
|
||||||
mat = res.y;
|
// mat = res.y;
|
||||||
if(t > 400.) { // Reduced max distance
|
// if(t > 400.) { // Reduced max distance
|
||||||
break;
|
// break;
|
||||||
}
|
// }
|
||||||
if(res.x < 0.00001 * (t*0.00125 + 1.0)) { // Less precise hit detection
|
// if(res.x < 0.00001 * (t*0.00125 + 1.0)) { // Less precise hit detection
|
||||||
hit = 1.;
|
// hit = 1.;
|
||||||
break;
|
// break;
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
// This will break fog effect
|
// This will break fog effect
|
||||||
//if (t > 100.)
|
//if (t > 100.)
|
||||||
// t = 0.;
|
// t = 0.;
|
||||||
|
|||||||
@ -2,174 +2,176 @@
|
|||||||
#ifndef FRAGMENT_INL_
|
#ifndef FRAGMENT_INL_
|
||||||
# define FRAGMENT_INL_
|
# define FRAGMENT_INL_
|
||||||
# define VAR_fft_output "f"
|
# define VAR_fft_output "f"
|
||||||
# define VAR_o "v"
|
# define VAR_o "l"
|
||||||
# define VAR_shapes "H"
|
# define VAR_shapes "H"
|
||||||
# define VAR_syncs "m"
|
# define VAR_syncs "m"
|
||||||
# define VAR_test "l"
|
# define VAR_test "k"
|
||||||
# define VAR_u_ShapesTex "a"
|
# define VAR_u_ShapesTex "x"
|
||||||
|
|
||||||
const char *fragment_frag =
|
const char *fragment_frag =
|
||||||
"#version 460\n"
|
"#version 460\n"
|
||||||
"precision mediump float;"
|
"precision mediump float;"
|
||||||
"out vec4 v;"
|
"out vec4 l;"
|
||||||
"const float i=2.*acos(-1.),n=sqrt(5.)*.5+.5;"
|
"const float i=2.*acos(-1.),v=sqrt(5.)*.5+.5;"
|
||||||
"layout(location=0)uniform float m[12];"
|
"layout(location=0)uniform float m[12];"
|
||||||
"layout(location=20)uniform float f[512];"
|
"layout(location=20)uniform float f[512];"
|
||||||
"layout(location=600)uniform vec3 H[15];"
|
"layout(location=600)uniform vec3 H[15];"
|
||||||
"layout(location=700)uniform vec3 l;"
|
"layout(location=700)uniform vec3 k;"
|
||||||
"layout(binding=0)uniform sampler2D a;"
|
"layout(binding=0)uniform sampler2D x;"
|
||||||
"float g=m[0];"
|
"float n=m[0];"
|
||||||
"mat2 t()"
|
"mat2 s()"
|
||||||
"{"
|
"{"
|
||||||
"float v=sin(.5),a=cos(.5);"
|
"float v=sin(.5),x=cos(.5);"
|
||||||
"return mat2(a,-v,v,a);"
|
"return mat2(x,-v,v,x);"
|
||||||
"}"
|
"}"
|
||||||
"float t(vec3 v,vec2 i)"
|
"float s(vec3 v,vec2 l)"
|
||||||
"{"
|
"{"
|
||||||
"v=abs(v);"
|
"v.xz=abs(v.xz);"
|
||||||
"return max(v.y-i.y,max(v.x*sqrt(3.)*.5+v.z*.5,v.z)-i.x);"
|
"v.xz=vec2(v.x*.866025+v.z*.5,v.z);"
|
||||||
"}\n"
|
"return length(max(abs(v)-vec3(l.xyx)+.15,0.))-.15;"
|
||||||
"#define zclamp(a)max(a,0.0)\n"
|
|
||||||
"struct HexData{vec3 local;vec2 axial;};"
|
|
||||||
"HexData t(vec3 v)"
|
|
||||||
"{"
|
|
||||||
"float i=sqrt(3.)/3.*v.x-1./3.*v.z,f=2./3.*v.z,a=round(i),x=round(f),l=round(-i-f),m=abs(a-i),n=abs(x-f);"
|
|
||||||
"i=abs(l+i+f);"
|
|
||||||
"if(m>n&&m>i)"
|
|
||||||
"a=-x-l;"
|
|
||||||
"else if(n>i)"
|
|
||||||
"x=-a-l;"
|
|
||||||
"i=sqrt(3.)*(a+x*.5);"
|
|
||||||
"f=1.5*x;"
|
|
||||||
"HexData r;"
|
|
||||||
"r.local=v-vec3(i,0,f);"
|
|
||||||
"r.axial=vec2(a,x);"
|
|
||||||
"return r;"
|
|
||||||
"}"
|
"}"
|
||||||
"struct HexData{vec3 local;vec2 axial;};"
|
"struct HexData{vec3 local;vec2 axial;};"
|
||||||
"float t(vec2 v)"
|
"HexData s(vec3 v)"
|
||||||
"{"
|
"{"
|
||||||
"float i=v.x,a=v.y;"
|
"float x=sqrt(3.)/3.*v.x-1./3.*v.z,l=2./3.*v.z,m=round(x),y=round(l),t=round(-x-l),n=abs(m-x),d=abs(y-l);"
|
||||||
"return max(abs(i),max(abs(a),abs(-i-a)));"
|
"x=abs(t+x+l);"
|
||||||
|
"if(n>d&&n>x)"
|
||||||
|
"m=-y-t;"
|
||||||
|
"else if(d>x)"
|
||||||
|
"y=-m-t;"
|
||||||
|
"x=sqrt(3.)*(m+y*.5);"
|
||||||
|
"l=1.5*y;"
|
||||||
|
"HexData f;"
|
||||||
|
"f.local=v-vec3(x,0,l);"
|
||||||
|
"f.axial=vec2(m,y);"
|
||||||
|
"return f;"
|
||||||
"}"
|
"}"
|
||||||
"vec2 s(vec3 v)"
|
"struct HexData{vec3 local;vec2 axial;};"
|
||||||
|
"float s(vec2 v)"
|
||||||
"{"
|
"{"
|
||||||
"vec2 i=vec2(v.y,0);"
|
"float x=v.x,l=v.y;"
|
||||||
"HexData m=t(vec3(v.x,v.y-2.5,v.z));"
|
"return max(abs(x),max(abs(l),abs(-x-l)));"
|
||||||
"float l=1.+f[int(clamp(t(m.axial)+1.,0.,511.))]*3.;"
|
"}"
|
||||||
"vec3 r=m.local;"
|
"vec2 t(vec3 v)"
|
||||||
"r.xz*=t();"
|
"{"
|
||||||
"l=t(vec3(r.x,r.y-l/2,r.z),vec2(.83,l/2));"
|
"vec2 l=vec2(v.y,0);"
|
||||||
"i=min(i,vec2(l,0));"
|
"HexData m=s(vec3(v.x,v.y-2.5,v.z));"
|
||||||
|
"float i=1.+f[int(clamp(s(m.axial)+1.,0.,511.))]*3.;"
|
||||||
|
"vec3 n=m.local;"
|
||||||
|
"n.xz*=s();"
|
||||||
|
"i=s(vec3(n.x,n.y-i/2,n.z),vec2(.83,i/2));"
|
||||||
|
"l=min(l,vec2(i,0));"
|
||||||
"for(float f=0.;f<16.;f++)"
|
"for(float f=0.;f<16.;f++)"
|
||||||
"for(float l=0.;l<16.;l++)"
|
"for(float i=0.;i<16.;i++)"
|
||||||
"{"
|
"{"
|
||||||
"ivec2 m=textureSize(a,0);"
|
"ivec2 m=textureSize(x,0);"
|
||||||
"vec2 n=vec2(l,f)/vec2(m);"
|
"vec2 n=vec2(i,f)/vec2(m);"
|
||||||
"vec4 r=texture(a,n);"
|
"vec4 d=texture(x,n);"
|
||||||
"if(r.w<.5)"
|
"if(d.w<.5)"
|
||||||
"continue;"
|
"continue;"
|
||||||
"i=min(i,vec2(length(v-vec3(-70.+r.x*2.,12.+r.y*80.,0))-.8,1));"
|
"l=min(l,vec2(length(v-vec3(-70.+d.x*2.,12.+d.y*80.,0))-.8,1));"
|
||||||
"}"
|
"}"
|
||||||
"return i;"
|
"return l;"
|
||||||
"}"
|
"}"
|
||||||
"vec3 s(vec3 v,vec3 i,inout vec3 f)"
|
"vec3 s(vec3 v,vec3 x,inout vec3 l)"
|
||||||
"{"
|
"{"
|
||||||
"float l=0.,a=0.,x=0.;"
|
"float i=0.,n=0.,m=0.,f;"
|
||||||
"for(int r=0;r<30;r++)"
|
"vec2 d;"
|
||||||
|
"for(int r=0;r<50;r++)"
|
||||||
"{"
|
"{"
|
||||||
"f=v+i*x;"
|
"l=v+x*m;"
|
||||||
"vec2 m=s(f);"
|
"d=t(l);"
|
||||||
"x+=m.x;"
|
"f=abs(d.x);"
|
||||||
"l=m.y;"
|
"i=d.y;"
|
||||||
"if(x>4e2)"
|
"if(m>4e2)"
|
||||||
"break;"
|
"break;"
|
||||||
"if(m.x<1e-5*(x*.00125+1.))"
|
"if(f<.001*(m*.0125+1.))"
|
||||||
"{"
|
"{"
|
||||||
"a=1.;"
|
"n=1.;"
|
||||||
"break;"
|
"break;"
|
||||||
"}"
|
"}"
|
||||||
|
"m+=d.x;"
|
||||||
"}"
|
"}"
|
||||||
"return vec3(x,l,a);"
|
"return vec3(m,i,n);"
|
||||||
"}"
|
"}"
|
||||||
"float s(vec3 v,vec3 i,float f)"
|
"float s(vec3 v,vec3 x,float l)"
|
||||||
"{"
|
"{"
|
||||||
"float l=1.,a=.02;"
|
"float i=1.,m=.02;"
|
||||||
"for(int r=0;r<6;r++)"
|
"for(int f=0;f<6;f++)"
|
||||||
"{"
|
"{"
|
||||||
"if(a>f)"
|
"if(m>l)"
|
||||||
"break;"
|
"break;"
|
||||||
"float m=s(v+a*i).x;"
|
"float n=t(v+m*x).x;"
|
||||||
"l=min(l,m/(4.*a));"
|
"i=min(i,n/(4.*m));"
|
||||||
"a+=clamp(m,.1,.8);"
|
"m+=clamp(n,.1,.8);"
|
||||||
"if(l<-1.)"
|
"if(i<-1.)"
|
||||||
"break;"
|
"break;"
|
||||||
"}"
|
"}"
|
||||||
"l=max(l,-1.);"
|
"i=max(i,-1.);"
|
||||||
"return.25*(1.+l)*(1.+l)*(2.-l);"
|
"return.25*(1.+i)*(1.+i)*(2.-i);"
|
||||||
"}"
|
"}"
|
||||||
"vec3 x(vec3 v)"
|
"vec3 e(vec3 v)"
|
||||||
"{"
|
"{"
|
||||||
"vec2 i=vec2(.01,0);"
|
"vec2 i=vec2(.01,0);"
|
||||||
"v=vec3(s(v+i.xyy).x-s(v-i.xyy).x,s(v+i.yxy).x-s(v-i.yxy).x,s(v+i.yyx).x-s(v-i.yyx).x);"
|
"v=vec3(t(v+i.xyy).x-t(v-i.xyy).x,t(v+i.yxy).x-t(v-i.yxy).x,t(v+i.yyx).x-t(v-i.yyx).x);"
|
||||||
"return normalize(v);"
|
"return normalize(v);"
|
||||||
"}"
|
"}"
|
||||||
"vec3 s(vec3 v,vec3 l,vec3 i,vec3 a,float f)"
|
"vec3 e(vec3 v,vec3 m,vec3 l,vec3 x,float i)"
|
||||||
"{"
|
"{"
|
||||||
"vec3 m=vec3(.77,.26,.73);"
|
"vec3 n=vec3(.77,.26,.73);"
|
||||||
"v-=l;"
|
"v-=m;"
|
||||||
"float r=length(v);"
|
"float f=length(v);"
|
||||||
"v=normalize(v);"
|
"v=normalize(v);"
|
||||||
"float x=30./(1.+.09*r+.032*r*r),n=max(dot(a,v),0.);"
|
"float y=30./(1.+.09*f+.032*f*f),d=max(dot(x,v),0.);"
|
||||||
"i=normalize(v-i);"
|
"l=normalize(v-l);"
|
||||||
"vec3 e=vec3(.04);"
|
"vec3 r=vec3(.04);"
|
||||||
"e+=(1.-e)*pow(clamp(1.-max(dot(i,v),0.),0.,1.),5.);"
|
"r+=(1.-r)*pow(clamp(1.-max(dot(l,v),0.),0.,1.),5.);"
|
||||||
"r=s(l+a*.01,v,r);"
|
"f=s(m+x*.01,v,f);"
|
||||||
"return(m*n*x+m*pow(max(dot(a,i),0.),mix(128.,8.,f))*x*e)*r;"
|
"return(n*d*y+n*pow(max(dot(x,l),0.),mix(128.,8.,i))*y*r)*f;"
|
||||||
"}"
|
"}"
|
||||||
"vec3 s(vec3 v,vec3 a,vec3 i,float l)"
|
"vec3 e(vec3 v,vec3 m,vec3 i,float l)"
|
||||||
"{"
|
"{"
|
||||||
"float f=.01;"
|
"float n=.01;"
|
||||||
"vec3 m=vec3(0);"
|
"vec3 x=vec3(0);"
|
||||||
"if(l==0.)"
|
"if(l==0.)"
|
||||||
"m=vec3(.8314,.2941,.2941),f=.1;"
|
"x=vec3(.8314,.2941,.2941),n=.1;"
|
||||||
"else if(l==1.)"
|
"else if(l==1.)"
|
||||||
"m=vec3(.6196,.6118,.6118),f=.7;"
|
"x=vec3(.6196,.6118,.6118),n=.7;"
|
||||||
"else if(l==2.)"
|
"else if(l==2.)"
|
||||||
"m=vec3(.3255,.4784,.3255),f=.2;"
|
"x=vec3(.3255,.4784,.3255),n=.2;"
|
||||||
"else if(l==3.)"
|
"else if(l==3.)"
|
||||||
"m=vec3(.2471,.3059,.6314),f=1.;"
|
"x=vec3(.2471,.3059,.6314),n=1.;"
|
||||||
"else if(l==4.)"
|
"else if(l==4.)"
|
||||||
"m=vec3(.9961,1,.9922),f=.1;"
|
"x=vec3(.9961,1,.9922),n=.1;"
|
||||||
"else if(l==5.)"
|
"else if(l==5.)"
|
||||||
"m=vec3(.9961,1,.9922),f=.3;"
|
"x=vec3(.9961,1,.9922),n=.3;"
|
||||||
"vec3 r=vec3(0);"
|
"vec3 f=vec3(0);"
|
||||||
"r+=s(vec3(0,40,-10),v,i,a,f);"
|
"f+=e(vec3(0,40,-10),v,i,m,n);"
|
||||||
"r+=s(vec3(0,20,15),v,i,a,f);"
|
"f+=e(vec3(0,20,15),v,i,m,n);"
|
||||||
"r+=vec3(.08,.62,.75)*clamp(dot(a,normalize(vec3(0,1,-3)*vec3(0,-1,-2))),0.,1.)*.8;"
|
"f+=vec3(.08,.62,.75)*clamp(dot(m,normalize(vec3(0,1,-3)*vec3(0,-1,-2))),0.,1.)*.8;"
|
||||||
"return m*max(vec3(0),r);"
|
"return x*max(vec3(0),f);"
|
||||||
"}"
|
"}"
|
||||||
"vec3 s(vec2 i,vec3 v)"
|
"vec3 e(vec2 v,vec3 l)"
|
||||||
"{"
|
"{"
|
||||||
"v=normalize(vec3(0,10,0)-v);"
|
"l=normalize(vec3(0,10,0)-l);"
|
||||||
"vec3 f=normalize(cross(vec3(0,1,0),v));"
|
"vec3 n=normalize(cross(vec3(0,1,0),l));"
|
||||||
"return normalize(v+i.x*f+i.y*cross(v,f));"
|
"return normalize(l+v.x*n+v.y*cross(l,n));"
|
||||||
"}"
|
"}"
|
||||||
"vec3 s(vec2 v)"
|
"vec3 e(vec2 v)"
|
||||||
"{"
|
"{"
|
||||||
"vec3 i=vec3(-20,20,-20),a=s(v,i),l=vec3(0),f=vec3(0);"
|
"vec3 l=vec3(-20,20,-20),n=e(v,l),i=vec3(0),x=vec3(0);"
|
||||||
"i=s(i,a,f);"
|
"l=s(l,n,x);"
|
||||||
"if(i.x>0.)"
|
"if(l.x>0.)"
|
||||||
"{"
|
"{"
|
||||||
"vec3 v=x(f);"
|
"vec3 v=e(x);"
|
||||||
"l=s(f,v,a,i.y);"
|
"i=e(x,v,n,l.y);"
|
||||||
"}"
|
"}"
|
||||||
"return l*exp(-i.x*.01)+mix(l,mix(vec3(.2667,.2941,.3451),vec3(.302,.3176,.3725),pow(max(dot(a,vec3(0,-.5,1.8)),0.),clamp(m[1]+m[2]+m[3],0.,1.)*5.)),1.-exp(-i.x*.01))*(1.-exp(-i.x*.01));"
|
"return i*exp(-l.x*.01)+mix(i,mix(vec3(.2667,.2941,.3451),vec3(.302,.3176,.3725),pow(max(dot(n,vec3(0,-.5,1.8)),0.),clamp(m[1]+m[2]+m[3],0.,1.)*5.)),1.-exp(-l.x*.01))*(1.-exp(-l.x*.01));"
|
||||||
"}"
|
"}"
|
||||||
"void main()"
|
"void main()"
|
||||||
"{"
|
"{"
|
||||||
"vec3 l=s(gl_FragCoord.xy*vec2(.00104166667,.00185185185)-1.);"
|
"vec3 v=e(gl_FragCoord.xy*vec2(.00104166667,.00185185185)-1.);"
|
||||||
"v=vec4(l,1);"
|
"l=vec4(v,1);"
|
||||||
"}";
|
"}";
|
||||||
|
|
||||||
#endif // FRAGMENT_INL_
|
#endif // FRAGMENT_INL_
|
||||||
|
|||||||
Reference in New Issue
Block a user