shaderiin muutoksia
This commit is contained in:
@ -4,21 +4,14 @@ out vec4 o;
|
||||
const float PI = 3.14159265;
|
||||
const float TAU = (2. * PI);
|
||||
const float PHI = sqrt(5.) * 0.5 + 0.5;
|
||||
layout(location = 0) uniform float syncs[12];
|
||||
layout(location = 0) uniform float syncs[11];
|
||||
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
|
||||
float u_time = syncs[0];
|
||||
|
||||
vec3 palette(float t){
|
||||
vec3 a=vec3(0.46,0.2,0.94);
|
||||
vec3 b=vec3(0.66,0.64,0.77);
|
||||
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));
|
||||
}
|
||||
layout(binding = 0) uniform sampler2D u_ShapesTex; // uniform sampler2D shapes texture
|
||||
// float u_time = syncs[0];
|
||||
|
||||
vec2 getUV() {
|
||||
const vec2 scale = vec2(0.00104166667, 0.00185185185);
|
||||
@ -44,19 +37,6 @@ float fHexagonCircumcircle(vec3 p, vec2 h) {
|
||||
return max(q.y - h.y, max(q.x * sqrt(3.) * 0.5 + q.z * 0.5, q.z) - h.x);
|
||||
}
|
||||
|
||||
float hexPylon(vec3 p, vec2 h) {//float r, float ht){
|
||||
|
||||
//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 length(max(abs(p) - b + .15, 0.)) - .15;
|
||||
}
|
||||
|
||||
// Return local coordinates inside hex AND axial ID
|
||||
struct HexData {
|
||||
vec3 local; // Local position inside hex
|
||||
@ -64,8 +44,8 @@ struct HexData {
|
||||
};
|
||||
|
||||
HexData hexTile(vec3 p, float radius) {
|
||||
float q = (sqrt(3.0)/3.0 * p.x - 1.0/3.0 * p.z) / radius;
|
||||
float r = (2.0/3.0 * p.z) / radius;
|
||||
float q = (sqrt(3.0) / 3.0 * p.x - 1.0 / 3.0 * p.z) / radius;
|
||||
float r = (2.0 / 3.0 * p.z) / radius;
|
||||
|
||||
float rq = round(q);
|
||||
float rr = round(r);
|
||||
@ -75,8 +55,10 @@ HexData hexTile(vec3 p, float radius) {
|
||||
float dr = abs(rr - r);
|
||||
float ds = abs(rs + q + r);
|
||||
|
||||
if (dq > dr && dq > ds) rq = -rr - rs;
|
||||
else if (dr > ds) rr = -rq - rs;
|
||||
if(dq > dr && dq > ds)
|
||||
rq = -rr - rs;
|
||||
else if(dr > ds)
|
||||
rr = -rq - rs;
|
||||
|
||||
float hx = radius * sqrt(3.0) * (rq + rr * 0.5);
|
||||
float hz = radius * 1.5 * rr;
|
||||
@ -87,11 +69,6 @@ HexData hexTile(vec3 p, float radius) {
|
||||
return outData;
|
||||
}
|
||||
|
||||
struct HexData {
|
||||
vec3 local;
|
||||
vec2 axial;
|
||||
};
|
||||
|
||||
float hexDistance(vec2 axial) {
|
||||
float q = axial.x;
|
||||
float r = axial.y;
|
||||
@ -99,9 +76,20 @@ float hexDistance(vec2 axial) {
|
||||
return max(abs(q), max(abs(r), abs(s)));
|
||||
}
|
||||
|
||||
float sdSphere(vec3 p, float r) {
|
||||
return length(p) - r;
|
||||
}
|
||||
|
||||
float sdSphere(vec3 p, float r){
|
||||
return length(p) -r;
|
||||
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 length(max(abs(p) - b + .15, 0.)) - .15;
|
||||
}
|
||||
|
||||
//////////////
|
||||
@ -109,58 +97,59 @@ float sdSphere(vec3 p, float r){
|
||||
//////////////
|
||||
|
||||
// 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;
|
||||
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) {
|
||||
|
||||
vec2 res = vec2( p.y, 0.0 );
|
||||
float res = 1e8;
|
||||
float mat = 0.;
|
||||
|
||||
float mat = 1.;
|
||||
float d = 1e9;
|
||||
float a = 0.;
|
||||
float hexRadius = 0.83;
|
||||
|
||||
float hexRadius = 0.85;
|
||||
vec3 hexpos = vec3(p.x, p.y - 2.5, p.z);
|
||||
HexData hex = hexTile(hexpos, 1.5);
|
||||
|
||||
HexData hex = hexTile(hexpos, 1.0);
|
||||
|
||||
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));
|
||||
float fftVal = fft_output[fftIndex];
|
||||
float hexHeight = 1.0 + fftVal * 3.0;
|
||||
float hexHeight = 1.0 + fftVal * 4.0;
|
||||
|
||||
// Rotate individual hex tiles if needed
|
||||
vec3 r = hex.local;
|
||||
//r.yz *= rot2D(1.0);
|
||||
r.xz *= rot2D(0.5);
|
||||
// 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));
|
||||
res = min(res, vec2(d1,0.));
|
||||
//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));
|
||||
|
||||
float gridSize2 = 16.;
|
||||
for(float j = 0.; j < gridSize2; j++) {
|
||||
for(float i = 0.; i < gridSize2; i++) {
|
||||
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;
|
||||
|
||||
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, vec2(a, 1.));
|
||||
res = min(res, a);
|
||||
if(res == a) {
|
||||
mat = 1.0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}*/
|
||||
|
||||
return res;
|
||||
return vec2(res, mat);
|
||||
}
|
||||
|
||||
////////////////
|
||||
@ -170,64 +159,25 @@ vec2 mapScene(in vec3 p) {
|
||||
vec3 castRay(vec3 ro, vec3 rd, inout vec3 pos) {
|
||||
float mat = 0.;
|
||||
float hit = 0.;
|
||||
vec3 d;
|
||||
float t = 0.,ad,tmax=400.; // total distance travelled
|
||||
const float tolerance = 0.001;
|
||||
const float Z_REPEAT_DIST = 2.;
|
||||
float t = 0.;
|
||||
vec2 res;
|
||||
|
||||
// Raymarching
|
||||
for (int i = 0; i < 50; i++) {
|
||||
for(int i = 0; i < 20; i++) {
|
||||
pos = ro + rd * t;
|
||||
res = mapScene(pos); // Get distance to objects
|
||||
ad = abs(res.x);
|
||||
res = mapScene(pos); // Get distance to objects, x = dist, y = material
|
||||
mat = res.y;
|
||||
if (t > tmax) break;
|
||||
if (ad < tolerance*(t*0.0125 + 1.0)) {
|
||||
hit = 1.0;
|
||||
t += res.x; // "march" the ray
|
||||
|
||||
// if(abs(t) < tolerance * (t * 0.0125 + 1.0)) {
|
||||
if(abs(res.x) < 0.0001) {
|
||||
hit = 1.;
|
||||
break;
|
||||
}
|
||||
t += res.x; // "march" the ray
|
||||
if(t > 200)
|
||||
break;
|
||||
|
||||
}
|
||||
// t -= Z_REPEAT_DIST*1.;
|
||||
//
|
||||
// for( int i=0; i<30; 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/2.0); // "march" the ray
|
||||
// }
|
||||
//if (t >= tmax) {
|
||||
// t= - 1.0;
|
||||
// hit = 0.;
|
||||
//}
|
||||
//Reduced from 40 to 24 steps
|
||||
// for(int i = 0; i < 30; i++) {
|
||||
// pos = ro + rd * t;
|
||||
// vec2 res = mapScene(pos);
|
||||
// // Increase step size multiplier for faster marching
|
||||
// t += res.x;
|
||||
// mat = res.y;
|
||||
// if(t > 400.) { // Reduced max distance
|
||||
// break;
|
||||
// }
|
||||
// if(res.x < 0.00001 * (t*0.00125 + 1.0)) { // Less precise hit detection
|
||||
// hit = 1.;
|
||||
// break;
|
||||
// }
|
||||
// }
|
||||
// This will break fog effect
|
||||
//if (t > 100.)
|
||||
// t = 0.;
|
||||
|
||||
return vec3(t, mat, hit);
|
||||
}
|
||||
@ -288,16 +238,28 @@ vec3 addPointLight(vec3 lightPos, vec3 lightColor, float intensity, vec3 worldPo
|
||||
return (diffuse + specular * fresnel) * shadow;
|
||||
}
|
||||
|
||||
vec3 applyFog(vec3 col, float t, vec3 rd, vec3 lightDir, float b ) {
|
||||
float getAmbientOcc(vec3 p, vec3 n) {
|
||||
float occ = 0.;
|
||||
float weight = 1.;
|
||||
for(int i = 0; i < 8; i++) {
|
||||
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) {
|
||||
|
||||
float syncsBass = clamp((syncs[1] + syncs[2] + syncs[3]), 0., 1.);
|
||||
|
||||
float fogAmount = 1.0 - exp(-t*b);
|
||||
float sunAmount = max( dot(rd, lightDir), 0.0 );
|
||||
vec3 fogColor = mix( vec3(0.2667, 0.2941, 0.3451), // blue
|
||||
vec3(0.302, 0.3176, 0.3725), // yellow
|
||||
pow(sunAmount, syncsBass * 5.0) );
|
||||
return mix( col, fogColor, fogAmount );
|
||||
float fogAmount2 = 1.0 - exp(-t * fogAmount);
|
||||
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
|
||||
@ -308,8 +270,8 @@ vec3 addPointLightNoShadow(vec3 lightPos, vec3 lightColor, float intensity, floa
|
||||
lightDir = normalize(lightDir);
|
||||
|
||||
// Attenuation (radius based falloff)
|
||||
float attenuation = clamp(intensity - lightDistance*lightDistance/(radius*radius), 0.0, 1.0);
|
||||
|
||||
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;
|
||||
@ -331,7 +293,6 @@ vec3 addPointLightNoShadow(vec3 lightPos, vec3 lightColor, float intensity, floa
|
||||
return diffuse + specular * fresnel;
|
||||
}
|
||||
|
||||
|
||||
/*vec3 addPointLight(vec3 lightPos, vec3 lightColor, float intensity, vec3 worldPos, vec3 viewDir, vec3 normal) {
|
||||
vec3 lightDir = normalize(lightPos - worldPos);
|
||||
float lightDistance = length(lightPos - worldPos);
|
||||
@ -354,14 +315,14 @@ vec3 addPointLightNoShadow(vec3 lightPos, vec3 lightColor, float intensity, floa
|
||||
}
|
||||
*/
|
||||
|
||||
vec3 shading(vec3 v, vec3 n, vec3 dir, float material) {
|
||||
vec3 shading(vec3 p, vec3 n, vec3 dir, float material) {
|
||||
float shininess = 0.01;
|
||||
|
||||
vec3 outMaterial = vec3(0.);
|
||||
|
||||
if(material == 0.) {
|
||||
outMaterial = vec3(0.8314, 0.2941, 0.2941);
|
||||
shininess = 0.1;
|
||||
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;
|
||||
@ -380,8 +341,8 @@ vec3 shading(vec3 v, vec3 n, vec3 dir, float material) {
|
||||
}
|
||||
|
||||
vec3 lights = vec3(0.);
|
||||
lights += addPointLight(vec3(0., 40.0, -10.), vec3(0.77, 0.26, 0.73), 30.0, v, dir, n, shininess);
|
||||
lights += addPointLight(vec3(0., 20.0, 15.), vec3(0.77, 0.26, 0.73), 30.0, v, 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 IN HEX GRID PATTERN
|
||||
/*
|
||||
@ -407,12 +368,12 @@ vec3 shading(vec3 v, vec3 n, vec3 dir, float material) {
|
||||
}
|
||||
*/
|
||||
|
||||
vec3 lightDir = vec3(0., 1., -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;
|
||||
|
||||
outMaterial *= max(vec3(0.), lights); // output with lights;
|
||||
@ -421,26 +382,16 @@ vec3 shading(vec3 v, vec3 n, vec3 dir, float material) {
|
||||
}
|
||||
|
||||
vec3 postProcess(vec3 col) {
|
||||
// float random = noise(gl_FragCoord.xy, 0.01+u_time);
|
||||
// float random2 = noise(gl_FragCoord.xy, .2+u_time);
|
||||
//col += 0.075*clamp(vec3(0.5*random, 0.5*random2, 0.5*random), 0.02, 1.); // dither
|
||||
|
||||
// Normalized pixel coordinates (from 0 to 1)
|
||||
vec2 screenCoord = getUV();
|
||||
|
||||
// Vignette
|
||||
float radius = 0.8;
|
||||
float d = smoothstep(radius, radius - 0.4, length(screenCoord - vec2(0.5)));
|
||||
col = mix(col, col * d, 1.);
|
||||
|
||||
// Contrast
|
||||
float contrast = .75;
|
||||
float contrast = 0.75;
|
||||
|
||||
col = mix(col, smoothstep(0.0, 1.0, col), contrast);
|
||||
|
||||
// Colour mapping
|
||||
col *= vec3(1.0, 1.0, 1.0);
|
||||
// col *= vec3(1.0, 1.0, 1.0);
|
||||
|
||||
col = pow(col, vec3(0.4545)); // gamma
|
||||
// Gamma
|
||||
col = pow(col, vec3(0.4545)); // gamma 2.2
|
||||
|
||||
// fade in at the beginning
|
||||
//col*=vec3(clamp((u_time-1.8)*0.5,0., 1.));
|
||||
@ -455,21 +406,14 @@ vec3 postProcess(vec3 col) {
|
||||
// RENDERING //
|
||||
//////////////////
|
||||
|
||||
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 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);
|
||||
return d;
|
||||
}
|
||||
|
||||
vec3 render(vec2 uv) {
|
||||
|
||||
vec3 camPos = vec3(-20.0, 20.0, -20.0);
|
||||
vec3 camTarget = vec3(0.0, 10.0, 0.0); // Adjust target as needed
|
||||
vec3 camPos = vec3(-20.0 + sin(syncs[0] * 0.25) * 5, abs(sin(syncs[0] * 0.25) * 10) + 25.0, -20.0);
|
||||
vec3 camTarget = vec3(0.0, 0.0, 0.0); // Adjust target as needed
|
||||
float fov = 1.0;
|
||||
|
||||
vec3 rayDir = getCameraRayDir(uv, camPos, camTarget, fov);
|
||||
@ -485,34 +429,33 @@ vec3 render(vec2 uv) {
|
||||
}
|
||||
|
||||
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));
|
||||
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);
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user