Compare commits
1 Commits
750fc2f7d5
...
9414b936c7
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9414b936c7 |
@ -83,9 +83,6 @@ function App() {
|
|||||||
<option value="default">Default Theme</option>
|
<option value="default">Default Theme</option>
|
||||||
<option value="blackhole">Blackhole Theme</option>
|
<option value="blackhole">Blackhole Theme</option>
|
||||||
<option value="star">Star Theme</option>
|
<option value="star">Star Theme</option>
|
||||||
<option value="ball">Universe Ball Theme</option>
|
|
||||||
<option value="reflect">Ball Cage Theme</option>
|
|
||||||
<option value="clouds">Clouds Theme</option>
|
|
||||||
</select>
|
</select>
|
||||||
</div>
|
</div>
|
||||||
{isShaderTheme && <ShaderBackground theme= {theme} />}
|
{isShaderTheme && <ShaderBackground theme= {theme} />}
|
||||||
|
|||||||
@ -2,9 +2,6 @@ import { useEffect, useRef } from "react";
|
|||||||
|
|
||||||
import BLACKHOLE_SHADER_CODE from "./assets/blackhole.glsl?raw";
|
import BLACKHOLE_SHADER_CODE from "./assets/blackhole.glsl?raw";
|
||||||
import STAR_SHADER_CODE from "./assets/star.glsl?raw";
|
import STAR_SHADER_CODE from "./assets/star.glsl?raw";
|
||||||
import BALL_SHADER_CODE from "./assets/ball.glsl?raw";
|
|
||||||
import REFLECT_BALL_SHADER_CODE from "./assets/reflect.glsl?raw";
|
|
||||||
import CLOUDS_SHADER_CODE from "./assets/clouds.glsl?raw";
|
|
||||||
|
|
||||||
function buildProgram(
|
function buildProgram(
|
||||||
ctx: WebGL2RenderingContext,
|
ctx: WebGL2RenderingContext,
|
||||||
@ -120,9 +117,7 @@ type ShaderBackgroundProps = {
|
|||||||
theme: string;
|
theme: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const ShaderBackground: React.FC<ShaderBackgroundProps> = ({
|
export const ShaderBackground: React.FC<ShaderBackgroundProps> = ({ theme }) => {
|
||||||
theme,
|
|
||||||
}) => {
|
|
||||||
const canvasRef = useRef<HTMLCanvasElement>(null);
|
const canvasRef = useRef<HTMLCanvasElement>(null);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
@ -144,15 +139,6 @@ export const ShaderBackground: React.FC<ShaderBackgroundProps> = ({
|
|||||||
case "star":
|
case "star":
|
||||||
shader_code = STAR_SHADER_CODE;
|
shader_code = STAR_SHADER_CODE;
|
||||||
break;
|
break;
|
||||||
case "ball":
|
|
||||||
shader_code = BALL_SHADER_CODE;
|
|
||||||
break;
|
|
||||||
case "reflect":
|
|
||||||
shader_code = REFLECT_BALL_SHADER_CODE;
|
|
||||||
break;
|
|
||||||
case "clouds":
|
|
||||||
shader_code = CLOUDS_SHADER_CODE;
|
|
||||||
break;
|
|
||||||
default:
|
default:
|
||||||
console.error("Unknown shader theme:", theme);
|
console.error("Unknown shader theme:", theme);
|
||||||
return;
|
return;
|
||||||
@ -193,13 +179,7 @@ export const ShaderBackground: React.FC<ShaderBackgroundProps> = ({
|
|||||||
|
|
||||||
function setResolution(program: WebGLProgram) {
|
function setResolution(program: WebGLProgram) {
|
||||||
const loc = gl!.getUniformLocation(program, "iResolution");
|
const loc = gl!.getUniformLocation(program, "iResolution");
|
||||||
canvas!.width = window.visualViewport!.width;
|
if (loc) gl!.uniform3fv(loc, [canvas!.width, canvas!.height, 1]);
|
||||||
canvas!.height = window.visualViewport!.height;
|
|
||||||
if (loc) gl!.uniform3fv(loc, [
|
|
||||||
window.visualViewport!.width,
|
|
||||||
window.visualViewport!.height,
|
|
||||||
1,
|
|
||||||
]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function setTime(program: WebGLProgram, now: number) {
|
function setTime(program: WebGLProgram, now: number) {
|
||||||
@ -211,12 +191,7 @@ export const ShaderBackground: React.FC<ShaderBackgroundProps> = ({
|
|||||||
|
|
||||||
const ichannel1_texture = loadTexture(gl, "assets/small_noise.png");
|
const ichannel1_texture = loadTexture(gl, "assets/small_noise.png");
|
||||||
|
|
||||||
gl!.viewport(
|
gl!.viewport(0, 0, canvas!.width, canvas!.height);
|
||||||
0,
|
|
||||||
0,
|
|
||||||
window.visualViewport!.width,
|
|
||||||
window.visualViewport!.height
|
|
||||||
);
|
|
||||||
|
|
||||||
gl!.useProgram(finalProgram);
|
gl!.useProgram(finalProgram);
|
||||||
setResolution(finalProgram!);
|
setResolution(finalProgram!);
|
||||||
@ -226,24 +201,9 @@ export const ShaderBackground: React.FC<ShaderBackgroundProps> = ({
|
|||||||
gl!.bindTexture(gl!.TEXTURE_2D, ichannel1_texture);
|
gl!.bindTexture(gl!.TEXTURE_2D, ichannel1_texture);
|
||||||
gl!.uniform1i(final_iChannel1, 1);
|
gl!.uniform1i(final_iChannel1, 1);
|
||||||
|
|
||||||
let last_update: number = 0;
|
|
||||||
|
|
||||||
const compiled_theme = theme;
|
|
||||||
|
|
||||||
function update(now: number) {
|
function update(now: number) {
|
||||||
// time in seconds
|
// time in seconds
|
||||||
const time = now / 1000;
|
const time = now / 1000;
|
||||||
|
|
||||||
if (compiled_theme !== theme) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (time - last_update < (1 / 30)) {
|
|
||||||
requestAnimationFrame(update);
|
|
||||||
return;
|
|
||||||
};
|
|
||||||
last_update = time;
|
|
||||||
|
|
||||||
gl!.clear(gl!.COLOR_BUFFER_BIT);
|
gl!.clear(gl!.COLOR_BUFFER_BIT);
|
||||||
|
|
||||||
setTime(finalProgram!, time);
|
setTime(finalProgram!, time);
|
||||||
@ -267,6 +227,7 @@ export const ShaderBackground: React.FC<ShaderBackgroundProps> = ({
|
|||||||
top: 0,
|
top: 0,
|
||||||
left: 0,
|
left: 0,
|
||||||
zIndex: -1,
|
zIndex: -1,
|
||||||
|
pointerEvents: "none",
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
|
|||||||
@ -1,23 +0,0 @@
|
|||||||
#version 300 es
|
|
||||||
precision highp float;
|
|
||||||
uniform vec3 iResolution;
|
|
||||||
uniform float iTime;
|
|
||||||
|
|
||||||
out vec4 FragColor;
|
|
||||||
|
|
||||||
#define PALETTE vec3(9,4,0)
|
|
||||||
|
|
||||||
void mainImage(out vec4 o, vec2 u) {
|
|
||||||
float n, i, s, t = iTime * .2, d, v;
|
|
||||||
vec3 q, p = iResolution, c;
|
|
||||||
u = (u + u - p.xy) / p.y;
|
|
||||||
vec2 l = u - (u.yx * .9 + .3 - vec2(-.35, .15));
|
|
||||||
for(; i++ < 5e1 && d < 5e1; d += s = min(q.y = .01 + .6 * abs(24. - length(q.xy)), v = max(s, dot(abs(fract(p) - .5), vec3(.04)))), c += (1. + cos(p.z + PALETTE)) / v + d * vec3(5, 2, 1) / q.y / 1e1 + 7. * vec3(3, 4, 1) / length(l)) for(q = p = vec3(u * d, d - 16.), s = length(p) - 8., p.xy *= mat2(cos(t + p.z * .6 + vec4(0, 33, 11, 0))), p += cos(t + p.zxy) + cos(t + p.yzx * s) / s / 4., p += .5 * cos(t + dot(cos(t + p), p) * p), n = .02; n < 2.; n *= 1.6) q.y -= abs(dot(sin(4. * t + .3 * q / n), q - q + n));
|
|
||||||
|
|
||||||
c = mix(c, c.yzx, smoothstep(2., .1, length(u) * 1.));
|
|
||||||
o.rgb = tanh(c * c / 6e7 / length(u - .3) + .1 * length(u));
|
|
||||||
}
|
|
||||||
|
|
||||||
void main() {
|
|
||||||
mainImage(FragColor, gl_FragCoord.xy);
|
|
||||||
}
|
|
||||||
@ -1,62 +0,0 @@
|
|||||||
#version 300 es
|
|
||||||
precision highp float;
|
|
||||||
uniform vec3 iResolution;
|
|
||||||
uniform float iTime;
|
|
||||||
|
|
||||||
out vec4 FragColor;
|
|
||||||
|
|
||||||
#define T (iTime)
|
|
||||||
|
|
||||||
float orb(vec3 p) {
|
|
||||||
// orb time
|
|
||||||
float t = T * 4.;
|
|
||||||
return length(p - vec3(sin(sin(t * .2) + t * .4) * 6., 1. + sin(sin(t * .5) + t * .2) * 4., 12. + T + cos(t * .3) * 8.));
|
|
||||||
}
|
|
||||||
|
|
||||||
void mainImage(out vec4 o, vec2 u) {
|
|
||||||
float d, a, e, i, s, t = T;
|
|
||||||
vec3 p = iResolution;
|
|
||||||
|
|
||||||
// scale coords
|
|
||||||
u = (u + u - p.xy) / p.y;
|
|
||||||
|
|
||||||
// camera movement
|
|
||||||
u += vec2(cos(t * .1) * .3, cos(t * .3) * .1);
|
|
||||||
|
|
||||||
for(o *= i; i++ < 128.;
|
|
||||||
|
|
||||||
// accumulate distance
|
|
||||||
d += s = min(.03 + .2 * abs(s), e = max(.5 * e, .01)),
|
|
||||||
|
|
||||||
// grayscale color and orb light
|
|
||||||
o += 1. / (s + e * 3.))
|
|
||||||
|
|
||||||
// noise loop start, march
|
|
||||||
for(p = vec3(u * d, d + t), // p = ro + rd *d, p.z + t;
|
|
||||||
|
|
||||||
// entity (orb)
|
|
||||||
e = orb(p) - .1,
|
|
||||||
|
|
||||||
// spin by t, twist by p.z
|
|
||||||
p.xy *= mat2(cos(.1 * t + p.z / 8. + vec4(0, 33, 11, 0))),
|
|
||||||
|
|
||||||
// mirrored planes 4 units apart
|
|
||||||
s = 4. - abs(p.y),
|
|
||||||
|
|
||||||
// noise starts at .8 up to 32., grow by a+=a
|
|
||||||
a = .8; a < 32.; a += a)
|
|
||||||
|
|
||||||
// apply turbulence
|
|
||||||
p += cos(.7 * t + p.yzx) * .2,
|
|
||||||
|
|
||||||
// apply noise
|
|
||||||
s -= abs(dot(sin(.1 * t + p * a), .6 + p - p)) / a;
|
|
||||||
|
|
||||||
// tanh tonemap, brightness, light off-screen
|
|
||||||
o = tanh(o / 1e1);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void main() {
|
|
||||||
mainImage(FragColor, gl_FragCoord.xy);
|
|
||||||
}
|
|
||||||
1
frontend/src/assets/react.svg
Normal file
1
frontend/src/assets/react.svg
Normal file
@ -0,0 +1 @@
|
|||||||
|
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" class="iconify iconify--logos" width="35.93" height="32" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 228"><path fill="#00D8FF" d="M210.483 73.824a171.49 171.49 0 0 0-8.24-2.597c.465-1.9.893-3.777 1.273-5.621c6.238-30.281 2.16-54.676-11.769-62.708c-13.355-7.7-35.196.329-57.254 19.526a171.23 171.23 0 0 0-6.375 5.848a155.866 155.866 0 0 0-4.241-3.917C100.759 3.829 77.587-4.822 63.673 3.233C50.33 10.957 46.379 33.89 51.995 62.588a170.974 170.974 0 0 0 1.892 8.48c-3.28.932-6.445 1.924-9.474 2.98C17.309 83.498 0 98.307 0 113.668c0 15.865 18.582 31.778 46.812 41.427a145.52 145.52 0 0 0 6.921 2.165a167.467 167.467 0 0 0-2.01 9.138c-5.354 28.2-1.173 50.591 12.134 58.266c13.744 7.926 36.812-.22 59.273-19.855a145.567 145.567 0 0 0 5.342-4.923a168.064 168.064 0 0 0 6.92 6.314c21.758 18.722 43.246 26.282 56.54 18.586c13.731-7.949 18.194-32.003 12.4-61.268a145.016 145.016 0 0 0-1.535-6.842c1.62-.48 3.21-.974 4.76-1.488c29.348-9.723 48.443-25.443 48.443-41.52c0-15.417-17.868-30.326-45.517-39.844Zm-6.365 70.984c-1.4.463-2.836.91-4.3 1.345c-3.24-10.257-7.612-21.163-12.963-32.432c5.106-11 9.31-21.767 12.459-31.957c2.619.758 5.16 1.557 7.61 2.4c23.69 8.156 38.14 20.213 38.14 29.504c0 9.896-15.606 22.743-40.946 31.14Zm-10.514 20.834c2.562 12.94 2.927 24.64 1.23 33.787c-1.524 8.219-4.59 13.698-8.382 15.893c-8.067 4.67-25.32-1.4-43.927-17.412a156.726 156.726 0 0 1-6.437-5.87c7.214-7.889 14.423-17.06 21.459-27.246c12.376-1.098 24.068-2.894 34.671-5.345a134.17 134.17 0 0 1 1.386 6.193ZM87.276 214.515c-7.882 2.783-14.16 2.863-17.955.675c-8.075-4.657-11.432-22.636-6.853-46.752a156.923 156.923 0 0 1 1.869-8.499c10.486 2.32 22.093 3.988 34.498 4.994c7.084 9.967 14.501 19.128 21.976 27.15a134.668 134.668 0 0 1-4.877 4.492c-9.933 8.682-19.886 14.842-28.658 17.94ZM50.35 144.747c-12.483-4.267-22.792-9.812-29.858-15.863c-6.35-5.437-9.555-10.836-9.555-15.216c0-9.322 13.897-21.212 37.076-29.293c2.813-.98 5.757-1.905 8.812-2.773c3.204 10.42 7.406 21.315 12.477 32.332c-5.137 11.18-9.399 22.249-12.634 32.792a134.718 134.718 0 0 1-6.318-1.979Zm12.378-84.26c-4.811-24.587-1.616-43.134 6.425-47.789c8.564-4.958 27.502 2.111 47.463 19.835a144.318 144.318 0 0 1 3.841 3.545c-7.438 7.987-14.787 17.08-21.808 26.988c-12.04 1.116-23.565 2.908-34.161 5.309a160.342 160.342 0 0 1-1.76-7.887Zm110.427 27.268a347.8 347.8 0 0 0-7.785-12.803c8.168 1.033 15.994 2.404 23.343 4.08c-2.206 7.072-4.956 14.465-8.193 22.045a381.151 381.151 0 0 0-7.365-13.322Zm-45.032-43.861c5.044 5.465 10.096 11.566 15.065 18.186a322.04 322.04 0 0 0-30.257-.006c4.974-6.559 10.069-12.652 15.192-18.18ZM82.802 87.83a323.167 323.167 0 0 0-7.227 13.238c-3.184-7.553-5.909-14.98-8.134-22.152c7.304-1.634 15.093-2.97 23.209-3.984a321.524 321.524 0 0 0-7.848 12.897Zm8.081 65.352c-8.385-.936-16.291-2.203-23.593-3.793c2.26-7.3 5.045-14.885 8.298-22.6a321.187 321.187 0 0 0 7.257 13.246c2.594 4.48 5.28 8.868 8.038 13.147Zm37.542 31.03c-5.184-5.592-10.354-11.779-15.403-18.433c4.902.192 9.899.29 14.978.29c5.218 0 10.376-.117 15.453-.343c-4.985 6.774-10.018 12.97-15.028 18.486Zm52.198-57.817c3.422 7.8 6.306 15.345 8.596 22.52c-7.422 1.694-15.436 3.058-23.88 4.071a382.417 382.417 0 0 0 7.859-13.026a347.403 347.403 0 0 0 7.425-13.565Zm-16.898 8.101a358.557 358.557 0 0 1-12.281 19.815a329.4 329.4 0 0 1-23.444.823c-7.967 0-15.716-.248-23.178-.732a310.202 310.202 0 0 1-12.513-19.846h.001a307.41 307.41 0 0 1-10.923-20.627a310.278 310.278 0 0 1 10.89-20.637l-.001.001a307.318 307.318 0 0 1 12.413-19.761c7.613-.576 15.42-.876 23.31-.876H128c7.926 0 15.743.303 23.354.883a329.357 329.357 0 0 1 12.335 19.695a358.489 358.489 0 0 1 11.036 20.54a329.472 329.472 0 0 1-11 20.722Zm22.56-122.124c8.572 4.944 11.906 24.881 6.52 51.026c-.344 1.668-.73 3.367-1.15 5.09c-10.622-2.452-22.155-4.275-34.23-5.408c-7.034-10.017-14.323-19.124-21.64-27.008a160.789 160.789 0 0 1 5.888-5.4c18.9-16.447 36.564-22.941 44.612-18.3ZM128 90.808c12.625 0 22.86 10.235 22.86 22.86s-10.235 22.86-22.86 22.86s-22.86-10.235-22.86-22.86s10.235-22.86 22.86-22.86Z"></path></svg>
|
||||||
|
After Width: | Height: | Size: 4.0 KiB |
@ -1,375 +0,0 @@
|
|||||||
#version 300 es
|
|
||||||
precision highp float;
|
|
||||||
uniform vec3 iResolution;
|
|
||||||
uniform float iTime;
|
|
||||||
|
|
||||||
out vec4 FragColor;
|
|
||||||
|
|
||||||
// CC0: Let's self reflect
|
|
||||||
// Always enjoyed the videos of Platonic solids with inner mirrors
|
|
||||||
// I made some previous attempts but thought I make another attempt it
|
|
||||||
|
|
||||||
// Reducing the alias effects on the inner reflections turned out to be a bit tricky.
|
|
||||||
// Simplest solution is just to run run fullscreen on a 4K screen ;)
|
|
||||||
|
|
||||||
// Function to generate the solid found here: https://www.shadertoy.com/view/MsKGzw
|
|
||||||
|
|
||||||
// Tinker with these parameters to create different solids
|
|
||||||
// -------------------------------------------------------
|
|
||||||
const float rotation_speed = 0.25f;
|
|
||||||
|
|
||||||
const float poly_U = 1.f; // [0, inf]
|
|
||||||
const float poly_V = 0.5f; // [0, inf]
|
|
||||||
const float poly_W = 1.0f; // [0, inf]
|
|
||||||
const int poly_type = 5; // [2, 5]
|
|
||||||
const float poly_zoom = 2.5f;
|
|
||||||
|
|
||||||
const float inner_sphere = 1.f;
|
|
||||||
|
|
||||||
const float refr_index = 0.9f;
|
|
||||||
|
|
||||||
#define MAX_BOUNCES2 6
|
|
||||||
// -------------------------------------------------------
|
|
||||||
|
|
||||||
#define TIME iTime
|
|
||||||
#define RESOLUTION iResolution
|
|
||||||
#define PI 3.141592654
|
|
||||||
#define TAU (2.0*PI)
|
|
||||||
|
|
||||||
// License: WTFPL, author: sam hocevar, found: https://stackoverflow.com/a/17897228/418488
|
|
||||||
const vec4 hsv2rgb_K = vec4(1.0f, 2.0f / 3.0f, 1.0f / 3.0f, 3.0f);
|
|
||||||
vec3 hsv2rgb(vec3 c) {
|
|
||||||
vec3 p = abs(fract(c.xxx + hsv2rgb_K.xyz) * 6.0f - hsv2rgb_K.www);
|
|
||||||
return c.z * mix(hsv2rgb_K.xxx, clamp(p - hsv2rgb_K.xxx, 0.0f, 1.0f), c.y);
|
|
||||||
}
|
|
||||||
// License: WTFPL, author: sam hocevar, found: https://stackoverflow.com/a/17897228/418488
|
|
||||||
// Macro version of above to enable compile-time constants
|
|
||||||
#define HSV2RGB(c) (c.z * mix(hsv2rgb_K.xxx, clamp(abs(fract(c.xxx + hsv2rgb_K.xyz) * 6.0 - hsv2rgb_K.www) - hsv2rgb_K.xxx, 0.0, 1.0), c.y))
|
|
||||||
|
|
||||||
#define TOLERANCE2 0.0005
|
|
||||||
//#define MAX_RAY_LENGTH2 10.0
|
|
||||||
#define MAX_RAY_MARCHES2 50
|
|
||||||
#define NORM_OFF2 0.005
|
|
||||||
#define BACKSTEP2
|
|
||||||
|
|
||||||
#define TOLERANCE3 0.0005
|
|
||||||
#define MAX_RAY_LENGTH3 10.0
|
|
||||||
#define MAX_RAY_MARCHES3 90
|
|
||||||
#define NORM_OFF3 0.005
|
|
||||||
|
|
||||||
const vec3 rayOrigin = vec3(0.0f, 1.f, -5.f);
|
|
||||||
const vec3 sunDir = normalize(-rayOrigin);
|
|
||||||
|
|
||||||
const vec3 sunCol = HSV2RGB(vec3(0.06f, 0.90f, 1E-2f)) * 1.f;
|
|
||||||
const vec3 bottomBoxCol = HSV2RGB(vec3(0.66f, 0.80f, 0.5f)) * 1.f;
|
|
||||||
const vec3 topBoxCol = HSV2RGB(vec3(0.60f, 0.90f, 1.f)) * 1.f;
|
|
||||||
const vec3 glowCol0 = HSV2RGB(vec3(0.05f, 0.7f, 1E-3f)) * 1.f;
|
|
||||||
const vec3 glowCol1 = HSV2RGB(vec3(0.95f, 0.7f, 1E-3f)) * 1.f;
|
|
||||||
const vec3 beerCol = -HSV2RGB(vec3(0.15f + 0.5f, 0.7f, 2.f));
|
|
||||||
const float rrefr_index = 1.f / refr_index;
|
|
||||||
|
|
||||||
// License: Unknown, author: knighty, found: https://www.shadertoy.com/view/MsKGzw
|
|
||||||
const float poly_cospin = cos(PI / float(poly_type));
|
|
||||||
const float poly_scospin = sqrt(0.75f - poly_cospin * poly_cospin);
|
|
||||||
const vec3 poly_nc = vec3(-0.5f, -poly_cospin, poly_scospin);
|
|
||||||
const vec3 poly_pab = vec3(0.f, 0.f, 1.f);
|
|
||||||
const vec3 poly_pbc_ = vec3(poly_scospin, 0.f, 0.5f);
|
|
||||||
const vec3 poly_pca_ = vec3(0.f, poly_scospin, poly_cospin);
|
|
||||||
const vec3 poly_p = normalize((poly_U * poly_pab + poly_V * poly_pbc_ + poly_W * poly_pca_));
|
|
||||||
const vec3 poly_pbc = normalize(poly_pbc_);
|
|
||||||
const vec3 poly_pca = normalize(poly_pca_);
|
|
||||||
|
|
||||||
mat3 g_rot;
|
|
||||||
vec2 g_gd;
|
|
||||||
|
|
||||||
// License: MIT, author: Inigo Quilez, found: https://iquilezles.org/articles/noacos/
|
|
||||||
mat3 rot(vec3 d, vec3 z) {
|
|
||||||
vec3 v = cross(z, d);
|
|
||||||
float c = dot(z, d);
|
|
||||||
float k = 1.0f / (1.0f + c);
|
|
||||||
|
|
||||||
return mat3(v.x * v.x * k + c, v.y * v.x * k - v.z, v.z * v.x * k + v.y, v.x * v.y * k + v.z, v.y * v.y * k + c, v.z * v.y * k - v.x, v.x * v.z * k - v.y, v.y * v.z * k + v.x, v.z * v.z * k + c);
|
|
||||||
}
|
|
||||||
|
|
||||||
// License: Unknown, author: Matt Taylor (https://github.com/64), found: https://64.github.io/tonemapping/
|
|
||||||
vec3 aces_approx(vec3 v) {
|
|
||||||
v = max(v, 0.0f);
|
|
||||||
v *= 0.6f;
|
|
||||||
float a = 2.51f;
|
|
||||||
float b = 0.03f;
|
|
||||||
float c = 2.43f;
|
|
||||||
float d = 0.59f;
|
|
||||||
float e = 0.14f;
|
|
||||||
return clamp((v * (a * v + b)) / (v * (c * v + d) + e), 0.0f, 1.0f);
|
|
||||||
}
|
|
||||||
|
|
||||||
float sphere(vec3 p, float r) {
|
|
||||||
return length(p) - r;
|
|
||||||
}
|
|
||||||
|
|
||||||
// License: MIT, author: Inigo Quilez, found: https://iquilezles.org/articles/distfunctions/
|
|
||||||
float box(vec2 p, vec2 b) {
|
|
||||||
vec2 d = abs(p) - b;
|
|
||||||
return length(max(d, 0.0f)) + min(max(d.x, d.y), 0.0f);
|
|
||||||
}
|
|
||||||
|
|
||||||
// License: Unknown, author: knighty, found: https://www.shadertoy.com/view/MsKGzw
|
|
||||||
void poly_fold(inout vec3 pos) {
|
|
||||||
vec3 p = pos;
|
|
||||||
|
|
||||||
for(int i = 0; i < poly_type; ++i) {
|
|
||||||
p.xy = abs(p.xy);
|
|
||||||
p -= 2.f * min(0.f, dot(p, poly_nc)) * poly_nc;
|
|
||||||
}
|
|
||||||
|
|
||||||
pos = p;
|
|
||||||
}
|
|
||||||
|
|
||||||
float poly_plane(vec3 pos) {
|
|
||||||
float d0 = dot(pos, poly_pab);
|
|
||||||
float d1 = dot(pos, poly_pbc);
|
|
||||||
float d2 = dot(pos, poly_pca);
|
|
||||||
float d = d0;
|
|
||||||
d = max(d, d1);
|
|
||||||
d = max(d, d2);
|
|
||||||
return d;
|
|
||||||
}
|
|
||||||
|
|
||||||
float poly_corner(vec3 pos) {
|
|
||||||
float d = length(pos) - .0125f;
|
|
||||||
return d;
|
|
||||||
}
|
|
||||||
|
|
||||||
float dot2(vec3 p) {
|
|
||||||
return dot(p, p);
|
|
||||||
}
|
|
||||||
|
|
||||||
float poly_edge(vec3 pos) {
|
|
||||||
float dla = dot2(pos - min(0.f, pos.x) * vec3(1.f, 0.f, 0.f));
|
|
||||||
float dlb = dot2(pos - min(0.f, pos.y) * vec3(0.f, 1.f, 0.f));
|
|
||||||
float dlc = dot2(pos - min(0.f, dot(pos, poly_nc)) * poly_nc);
|
|
||||||
return sqrt(min(min(dla, dlb), dlc)) - 2E-3f;
|
|
||||||
}
|
|
||||||
|
|
||||||
vec3 shape(vec3 pos) {
|
|
||||||
pos *= g_rot;
|
|
||||||
pos /= poly_zoom;
|
|
||||||
poly_fold(pos);
|
|
||||||
pos -= poly_p;
|
|
||||||
|
|
||||||
return vec3(poly_plane(pos), poly_edge(pos), poly_corner(pos)) * poly_zoom;
|
|
||||||
}
|
|
||||||
|
|
||||||
vec3 render0(vec3 ro, vec3 rd) {
|
|
||||||
vec3 col = vec3(0.0f);
|
|
||||||
|
|
||||||
float srd = sign(rd.y);
|
|
||||||
float tp = -(ro.y - 6.f) / abs(rd.y);
|
|
||||||
|
|
||||||
if(srd < 0.f) {
|
|
||||||
col += bottomBoxCol * exp(-0.5f * (length((ro + tp * rd).xz)));
|
|
||||||
}
|
|
||||||
|
|
||||||
if(srd > 0.0f) {
|
|
||||||
vec3 pos = ro + tp * rd;
|
|
||||||
vec2 pp = pos.xz;
|
|
||||||
float db = box(pp, vec2(5.0f, 9.0f)) - 3.0f;
|
|
||||||
|
|
||||||
col += topBoxCol * rd.y * rd.y * smoothstep(0.25f, 0.0f, db);
|
|
||||||
col += 0.2f * topBoxCol * exp(-0.5f * max(db, 0.0f));
|
|
||||||
col += 0.05f * sqrt(topBoxCol) * max(-db, 0.0f);
|
|
||||||
}
|
|
||||||
|
|
||||||
col += sunCol / (1.001f - dot(sunDir, rd));
|
|
||||||
return col;
|
|
||||||
}
|
|
||||||
|
|
||||||
float df2(vec3 p) {
|
|
||||||
vec3 ds = shape(p);
|
|
||||||
float d2 = ds.y - 5E-3f;
|
|
||||||
float d0 = min(-ds.x, d2);
|
|
||||||
float d1 = sphere(p, inner_sphere);
|
|
||||||
g_gd = min(g_gd, vec2(d2, d1));
|
|
||||||
float d = (min(d0, d1));
|
|
||||||
return d;
|
|
||||||
}
|
|
||||||
|
|
||||||
float rayMarch2(vec3 ro, vec3 rd, float tinit) {
|
|
||||||
float t = tinit;
|
|
||||||
#if defined(BACKSTEP2)
|
|
||||||
vec2 dti = vec2(1e10f, 0.0f);
|
|
||||||
#endif
|
|
||||||
int i;
|
|
||||||
for(i = 0; i < MAX_RAY_MARCHES2; ++i) {
|
|
||||||
float d = df2(ro + rd * t);
|
|
||||||
#if defined(BACKSTEP2)
|
|
||||||
if(d < dti.x) {
|
|
||||||
dti = vec2(d, t);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
// Bouncing in a closed shell, will never miss
|
|
||||||
if(d < TOLERANCE2/* || t > MAX_RAY_LENGTH3 */) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
t += d;
|
|
||||||
}
|
|
||||||
#if defined(BACKSTEP2)
|
|
||||||
if(i == MAX_RAY_MARCHES2) {
|
|
||||||
t = dti.y;
|
|
||||||
};
|
|
||||||
#endif
|
|
||||||
return t;
|
|
||||||
}
|
|
||||||
|
|
||||||
vec3 normal2(vec3 pos) {
|
|
||||||
vec2 eps = vec2(NORM_OFF2, 0.0f);
|
|
||||||
vec3 nor;
|
|
||||||
nor.x = df2(pos + eps.xyy) - df2(pos - eps.xyy);
|
|
||||||
nor.y = df2(pos + eps.yxy) - df2(pos - eps.yxy);
|
|
||||||
nor.z = df2(pos + eps.yyx) - df2(pos - eps.yyx);
|
|
||||||
return normalize(nor);
|
|
||||||
}
|
|
||||||
|
|
||||||
vec3 render2(vec3 ro, vec3 rd, float db) {
|
|
||||||
vec3 agg = vec3(0.0f);
|
|
||||||
float ragg = 1.f;
|
|
||||||
float tagg = 0.f;
|
|
||||||
|
|
||||||
for(int bounce = 0; bounce < MAX_BOUNCES2; ++bounce) {
|
|
||||||
if(ragg < 0.1f)
|
|
||||||
break;
|
|
||||||
g_gd = vec2(1E3f);
|
|
||||||
float t2 = rayMarch2(ro, rd, min(db + 0.05f, 0.3f));
|
|
||||||
vec2 gd2 = g_gd;
|
|
||||||
tagg += t2;
|
|
||||||
|
|
||||||
vec3 p2 = ro + rd * t2;
|
|
||||||
vec3 n2 = normal2(p2);
|
|
||||||
vec3 r2 = reflect(rd, n2);
|
|
||||||
vec3 rr2 = refract(rd, n2, rrefr_index);
|
|
||||||
float fre2 = 1.f + dot(n2, rd);
|
|
||||||
|
|
||||||
vec3 beer = ragg * exp(0.2f * beerCol * tagg);
|
|
||||||
agg += glowCol1 * beer * ((1.f + tagg * tagg * 4E-2f) * 6.f / max(gd2.x, 5E-4f + tagg * tagg * 2E-4f / ragg));
|
|
||||||
vec3 ocol = 0.2f * beer * render0(p2, rr2);
|
|
||||||
if(gd2.y <= TOLERANCE2) {
|
|
||||||
ragg *= 1.f - 0.9f * fre2;
|
|
||||||
} else {
|
|
||||||
agg += ocol;
|
|
||||||
ragg *= 0.8f;
|
|
||||||
}
|
|
||||||
|
|
||||||
ro = p2;
|
|
||||||
rd = r2;
|
|
||||||
db = gd2.x;
|
|
||||||
}
|
|
||||||
|
|
||||||
return agg;
|
|
||||||
}
|
|
||||||
|
|
||||||
float df3(vec3 p) {
|
|
||||||
vec3 ds = shape(p);
|
|
||||||
g_gd = min(g_gd, ds.yz);
|
|
||||||
const float sw = 0.02f;
|
|
||||||
float d1 = min(ds.y, ds.z) - sw;
|
|
||||||
float d0 = ds.x;
|
|
||||||
d0 = min(d0, ds.y);
|
|
||||||
d0 = min(d0, ds.z);
|
|
||||||
return d0;
|
|
||||||
}
|
|
||||||
|
|
||||||
float rayMarch3(vec3 ro, vec3 rd, float tinit, out int iter) {
|
|
||||||
float t = tinit;
|
|
||||||
int i;
|
|
||||||
for(i = 0; i < MAX_RAY_MARCHES3; ++i) {
|
|
||||||
float d = df3(ro + rd * t);
|
|
||||||
if(d < TOLERANCE3 || t > MAX_RAY_LENGTH3) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
t += d;
|
|
||||||
}
|
|
||||||
iter = i;
|
|
||||||
return t;
|
|
||||||
}
|
|
||||||
|
|
||||||
vec3 normal3(vec3 pos) {
|
|
||||||
vec2 eps = vec2(NORM_OFF3, 0.0f);
|
|
||||||
vec3 nor;
|
|
||||||
nor.x = df3(pos + eps.xyy) - df3(pos - eps.xyy);
|
|
||||||
nor.y = df3(pos + eps.yxy) - df3(pos - eps.yxy);
|
|
||||||
nor.z = df3(pos + eps.yyx) - df3(pos - eps.yyx);
|
|
||||||
return normalize(nor);
|
|
||||||
}
|
|
||||||
|
|
||||||
vec3 render3(vec3 ro, vec3 rd) {
|
|
||||||
int iter;
|
|
||||||
|
|
||||||
vec3 skyCol = render0(ro, rd);
|
|
||||||
vec3 col = skyCol;
|
|
||||||
|
|
||||||
g_gd = vec2(1E3f);
|
|
||||||
float t1 = rayMarch3(ro, rd, 0.1f, iter);
|
|
||||||
vec2 gd1 = g_gd;
|
|
||||||
vec3 p1 = ro + t1 * rd;
|
|
||||||
vec3 n1 = normal3(p1);
|
|
||||||
vec3 r1 = reflect(rd, n1);
|
|
||||||
vec3 rr1 = refract(rd, n1, refr_index);
|
|
||||||
float fre1 = 1.f + dot(rd, n1);
|
|
||||||
fre1 *= fre1;
|
|
||||||
|
|
||||||
float ifo = mix(0.5f, 1.f, smoothstep(1.0f, 0.9f, float(iter) / float(MAX_RAY_MARCHES3)));
|
|
||||||
|
|
||||||
if(t1 < MAX_RAY_LENGTH3) {
|
|
||||||
col = render0(p1, r1) * (0.5f + 0.5f * fre1) * ifo;
|
|
||||||
vec3 icol = render2(p1, rr1, gd1.x);
|
|
||||||
if(gd1.x > TOLERANCE3 && gd1.y > TOLERANCE3 && rr1 != vec3(0.f)) {
|
|
||||||
col += icol * (1.f - 0.75f * fre1) * ifo;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
col += (glowCol0 + 1.f * fre1 * (glowCol0)) / max(gd1.x, 3E-4f);
|
|
||||||
return col;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
vec3 effect(vec2 p, vec2 pp) {
|
|
||||||
const float fov = 2.0f;
|
|
||||||
|
|
||||||
const vec3 up = vec3(0.f, 1.f, 0.f);
|
|
||||||
const vec3 la = vec3(0.0f);
|
|
||||||
|
|
||||||
const vec3 ww = normalize(normalize(la - rayOrigin));
|
|
||||||
const vec3 uu = normalize(cross(up, ww));
|
|
||||||
const vec3 vv = cross(ww, uu);
|
|
||||||
|
|
||||||
vec3 rd = normalize(-p.x * uu + p.y * vv + fov * ww);
|
|
||||||
|
|
||||||
vec3 col = vec3(0.0f);
|
|
||||||
col = render3(rayOrigin, rd);
|
|
||||||
|
|
||||||
col -= 2E-2f * vec3(2.f, 3.f, 1.f) * (length(p) + 0.25f);
|
|
||||||
col = aces_approx(col);
|
|
||||||
col = sqrt(col);
|
|
||||||
return col;
|
|
||||||
}
|
|
||||||
|
|
||||||
void mainImage(out vec4 fragColor, in vec2 fragCoord) {
|
|
||||||
vec2 q = fragCoord / RESOLUTION.xy;
|
|
||||||
vec2 p = -1.f + 2.f * q;
|
|
||||||
vec2 pp = p;
|
|
||||||
p.x *= RESOLUTION.x / RESOLUTION.y;
|
|
||||||
|
|
||||||
float a = TIME * rotation_speed;
|
|
||||||
vec3 r0 = vec3(1.0f, sin(vec2(sqrt(0.5f), 1.0f) * a));
|
|
||||||
vec3 r1 = vec3(cos(vec2(sqrt(0.5f), 1.0f) * 0.913f * a), 1.0f);
|
|
||||||
mat3 rot = rot(normalize(r0), normalize(r1));
|
|
||||||
g_rot = rot;
|
|
||||||
|
|
||||||
vec3 col = effect(p, pp);
|
|
||||||
|
|
||||||
fragColor = vec4(col, 1.0f);
|
|
||||||
}
|
|
||||||
|
|
||||||
void main() {
|
|
||||||
mainImage(FragColor, gl_FragCoord.xy);
|
|
||||||
}
|
|
||||||
Loading…
x
Reference in New Issue
Block a user