Created
May 14, 2023 09:57
-
-
Save Forenard/7eb5a752759f4ce2863dd668ea8522cb to your computer and use it in GitHub Desktop.
POOL.glsl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
precision highp float; | |
uniform vec2 resolution; | |
uniform vec2 mouse; | |
uniform float time; | |
uniform sampler2D backbuffer; | |
out vec4 outColor; | |
#define iChannel1 backbuffer | |
#define iResolution resolution | |
#define iTime time | |
#define iMouse mouse | |
//Parameters--------------------------------------------------------------- | |
#define PI 3.14159265359 | |
#define TAU 6.28318530718 | |
#define LoopMax 128 | |
#define DistMin 0.001 | |
#define LenMax 1000.0 | |
#define NormalEPS 0.001 | |
#define ResolutionEPS (2.0/max(iResolution.x, iResolution.y)) | |
#define sabs(x) sqrt(x*x+1e-2) | |
#define smin(a,b) (a+b-sabs(a-b))*.5 | |
#define smax(a,b) (a+b+sabs(a-b))*.5 | |
#define opRep(p,c) (mod(p,c)-(c)*.5) | |
#define opRepLim(p,c,l,r) (p-(c)*clamp(round((p)/(c)),l,r)) | |
#define remap(x,a,b,c,d) (((x-a)/(b-a))*(d-c)+c) | |
#define remapc(x,a,b,c,d) clamp(remap(x,a,b,c,d),min(c,d),max(c,d)) | |
#define RGBColor(r,b,g) (vec3(r,g,b)/255.0) | |
#define BackBuffer(uv) texture(iChannel1,mod(uv,vec2(1))) | |
float LocalTime; | |
float ABSLocalTime; | |
float T = 0.0; | |
#define MAX_SCID 24 | |
float SCID[MAX_SCID]; | |
#define SC(l,r) if((T=LocalTime-l),(l<=LocalTime&&LocalTime<r)) | |
#define SCI(id) if((T=LocalTime-SCID[id-1]),(SCID[id-1]<=LocalTime&&LocalTime<SCID[id])) | |
#define SCIR(il,ir) if((T=LocalTime-SCID[il]),(SCID[il]<=LocalTime&&LocalTime<SCID[ir])) | |
#define SCIR01(il,ir) if((T=(LocalTime-SCID[il])/(SCID[ir]-SCID[il])),(SCID[il]<=LocalTime&&LocalTime<SCID[ir])) | |
#define SCI01(id) if((T=(LocalTime-SCID[id-1])/(SCID[id]-SCID[id-1])),(SCID[id-1]<=LocalTime&&LocalTime<SCID[id])) | |
#define OPENINGSC SCIR01(0,6) | |
#define POORSC SCIR01(6,19) | |
struct MatInfo | |
{ | |
float roughness; | |
float metalic; | |
float emission; | |
float lightRange; | |
vec3 color; | |
}; | |
#define MatInfo() MatInfo(0.0,0.0,0.0,1.0,vec3(0.0)) | |
//UI-------------------------------------------------------------------- | |
// https://www.shadertoy.com/view/Mt2GWD | |
#define MAX_INT_DIGITS 5 | |
#define CHAR_SIZE vec2(8, 12) | |
#define CHAR_SPACING vec2(8, 12) | |
#define STRWIDTH(c) (c * CHAR_SPACING.x) | |
#define STRHEIGHT(c) (c * CHAR_SPACING.y) | |
const vec4 ch_spc = vec4(0x000000, 0x000000, 0x000000, 0x000000); | |
const vec4 ch_per = vec4(0x000000, 0x000000, 0x000038, 0x380000); | |
const vec4 ch_0 = vec4(0x007CC6, 0xD6D6D6, 0xD6D6C6, 0x7C0000); | |
const vec4 ch_1 = vec4(0x001030, 0xF03030, 0x303030, 0xFC0000); | |
const vec4 ch_2 = vec4(0x0078CC, 0xCC0C18, 0x3060CC, 0xFC0000); | |
const vec4 ch_3 = vec4(0x0078CC, 0x0C0C38, 0x0C0CCC, 0x780000); | |
const vec4 ch_4 = vec4(0x000C1C, 0x3C6CCC, 0xFE0C0C, 0x1E0000); | |
const vec4 ch_5 = vec4(0x00FCC0, 0xC0C0F8, 0x0C0CCC, 0x780000); | |
const vec4 ch_6 = vec4(0x003860, 0xC0C0F8, 0xCCCCCC, 0x780000); | |
const vec4 ch_7 = vec4(0x00FEC6, 0xC6060C, 0x183030, 0x300000); | |
const vec4 ch_8 = vec4(0x0078CC, 0xCCEC78, 0xDCCCCC, 0x780000); | |
const vec4 ch_9 = vec4(0x0078CC, 0xCCCC7C, 0x181830, 0x700000); | |
const vec4 ch_col = vec4(0x000000, 0x383800, 0x003838, 0x000000); | |
const vec4 ch_A = vec4(0x003078, 0xCCCCCC, 0xFCCCCC, 0xCC0000); | |
const vec4 ch_C = vec4(0x003C66, 0xC6C0C0, 0xC0C666, 0x3C0000); | |
const vec4 ch_E = vec4(0x00FE62, 0x60647C, 0x646062, 0xFE0000); | |
const vec4 ch_L = vec4(0x00F060, 0x606060, 0x626666, 0xFE0000); | |
const vec4 ch_O = vec4(0x00386C, 0xC6C6C6, 0xC6C66C, 0x380000); | |
const vec4 ch_P = vec4(0x00FC66, 0x66667C, 0x606060, 0xF00000); | |
const vec4 ch_R = vec4(0x00FC66, 0x66667C, 0x6C6666, 0xE60000); | |
const vec4 ch_Y = vec4(0x00CCCC, 0xCCCC78, 0x303030, 0x780000); | |
vec2 res = vec2(0); | |
vec2 print_pos = vec2(0); | |
//Extracts bit b from the given number. | |
//Shifts bits right (num / 2^bit) then ANDs the result with 1 (mod(result,2.0)). | |
float extract_bit(float n, float b) | |
{ | |
b = clamp(b, -1.0, 24.0); | |
return floor(mod(floor(n / pow(2.0, floor(b))), 2.0)); | |
} | |
//Returns the pixel at uv in the given bit-packed sprite. | |
float sprite(vec4 spr, vec2 size, vec2 uv) | |
{ | |
uv = floor(uv); | |
//Calculate the bit to extract (x + y * width) (flipped on x-axis) | |
float bit = (size.x - uv.x - 1.0) + uv.y * size.x; | |
//Clipping bound to remove garbage outside the sprite's boundaries. | |
bool bounds = all(greaterThanEqual(uv, vec2(0))) && all(lessThan(uv, size)); | |
float pixels = 0.0; | |
pixels += extract_bit(spr.x, bit - 72.0); | |
pixels += extract_bit(spr.y, bit - 48.0); | |
pixels += extract_bit(spr.z, bit - 24.0); | |
pixels += extract_bit(spr.w, bit - 0.0); | |
return bounds ? pixels : 0.0; | |
} | |
//Prints a character and moves the print position forward by 1 character width. | |
float char(vec4 ch, vec2 uv) | |
{ | |
float px = sprite(ch, CHAR_SIZE, uv - print_pos); | |
print_pos.x += CHAR_SPACING.x; | |
return px; | |
} | |
const vec4 ch_digits[10] = vec4[](ch_0, ch_1, ch_2, ch_3, ch_4, ch_5, ch_6, ch_7, ch_8, ch_9); | |
//Returns the digit sprite for the given number. | |
vec4 get_digit(float d) | |
{ | |
return ch_digits[int(d) % 10]; | |
} | |
float print_integer(float number, int zeros, vec2 uv) | |
{ | |
float result = 0.0; | |
for(int i = MAX_INT_DIGITS; i >= 0; i--) | |
{ | |
float digit = mod(number / pow(10.0, float(i)), 10.0); | |
if(abs(number) > pow(10.0, float(i)) || zeros > i || i == 0) //Clip off leading zeros. | |
{ | |
result += char(get_digit(digit), uv); | |
} | |
} | |
return result; | |
} | |
//Easing------------------------------------------------------------------- | |
#define MAX_CATMULL_LENGTH 16 | |
vec3 CATMULL_ROM_POINTS[MAX_CATMULL_LENGTH]; | |
float CATMULL_ROM_LENGTH[MAX_CATMULL_LENGTH]; | |
void setCatmull(int id, vec3 point) | |
{ | |
CATMULL_ROM_POINTS[id] = point; | |
CATMULL_ROM_LENGTH[id] = (id > 0 ? (length(CATMULL_ROM_POINTS[id] - CATMULL_ROM_POINTS[id - 1]) + CATMULL_ROM_LENGTH[id - 1]) : 0.0); | |
} | |
vec3 getCatmull(int count, float t) | |
{ | |
t = clamp(t, 0.0, 1.0); | |
float sl = CATMULL_ROM_LENGTH[count - 1]; | |
for(int i = 1; i < count; i++) | |
{ | |
if(t * sl <= CATMULL_ROM_LENGTH[i]) | |
{ | |
t = clamp((t * sl - CATMULL_ROM_LENGTH[i - 1]) / (CATMULL_ROM_LENGTH[i] - CATMULL_ROM_LENGTH[i - 1]), 0.0, 1.0); | |
if(i == 1) | |
{ | |
vec3 p0 = CATMULL_ROM_POINTS[0]; | |
vec3 p1 = CATMULL_ROM_POINTS[1]; | |
vec3 p2 = CATMULL_ROM_POINTS[2]; | |
return 0.5 * ((p0 - 2.0 * p1 + p2) * t * t + (-3.0 * p0 + 4.0 * p1 - p2) * t + 2.0 * p0); | |
} | |
else if(i == count - 1) | |
{ | |
vec3 p0 = CATMULL_ROM_POINTS[i - 2]; | |
vec3 p1 = CATMULL_ROM_POINTS[i - 1]; | |
vec3 p2 = CATMULL_ROM_POINTS[i]; | |
return 0.5 * ((p0 - 2.0 * p1 + p2) * t * t + (-p0 + p2) * t + 2.0 * p1); | |
} | |
else | |
{ | |
vec3 p0 = CATMULL_ROM_POINTS[i - 2]; | |
vec3 p1 = CATMULL_ROM_POINTS[i - 1]; | |
vec3 p2 = CATMULL_ROM_POINTS[i]; | |
vec3 p3 = CATMULL_ROM_POINTS[i + 1]; | |
return 0.5 * ((-p0 + 3.0 * p1 - 3.0 * p2 + p3) * t * t * t + (2.0 * p0 - 5.0 * p1 + 4.0 * p2 - p3) * t * t + (-p0 + p2) * t + 2.0 * p1); | |
} | |
} | |
} | |
} | |
//General Functions-------------------------------------------------------- | |
vec3 hsv2rgb(vec3 hsv) | |
{ | |
vec4 K = vec4(1.0, 2.0 / 3.0, 1.0 / 3.0, 3.0); | |
vec3 p = abs(fract(hsv.xxx + K.xyz) * 6.0 - K.www); | |
return hsv.z * mix(K.xxx, clamp(p - K.xxx, 0.0, 1.0), hsv.y); | |
} | |
vec3 rgb2hsv(vec3 rgb) | |
{ | |
vec4 K = vec4(0.0, -1.0 / 3.0, 2.0 / 3.0, -1.0); | |
vec4 p = mix(vec4(rgb.bg, K.wz), vec4(rgb.gb, K.xy), step(rgb.b, rgb.g)); | |
vec4 q = mix(vec4(p.xyw, rgb.r), vec4(rgb.r, p.yzx), step(p.x, rgb.r)); | |
float d = q.x - min(q.w, q.y); | |
float e = 1.0e-10; | |
return vec3(abs(q.z + (q.w - q.y) / (6.0 * d + e)), d / (q.x + e), q.x); | |
} | |
#define HexColor(c) vec3(float(c >> 16) / 255.0, float((c >> 8) & 0xFF) / 255.0, float(c & 0xFF) / 255.0) | |
float roughnessFix(float roughness) | |
{ | |
return clamp(remap(roughness, 0.0, 1.0, 10000.0, 0.0), 0.0, 10000.0); | |
} | |
float lightAttenuation(MatInfo lightInfo, float dist) | |
{ | |
dist = max(dist, 0.0); | |
float range = max(lightInfo.lightRange, 0.1); | |
return pow(clamp(1.0 - (1.0 / range) * dist, 0.0, 1.0), 2.0) * lightInfo.emission; | |
} | |
// Hash without Sine by David Hoskins. | |
// https://www.shadertoy.com/view/4djSRW | |
float hash11(float p) | |
{ | |
p = fract(p * .1031); | |
p *= p + 33.33; | |
p *= p + p; | |
return fract(p); | |
} | |
float hash12(vec2 p) | |
{ | |
vec3 p3 = fract(vec3(p.xyx) * .1031); | |
p3 += dot(p3, p3.yzx + 33.33); | |
return fract((p3.x + p3.y) * p3.z); | |
} | |
vec2 hash23(vec3 p3) | |
{ | |
p3 = fract(p3 * vec3(.1031, .1030, .0973)); | |
p3 += dot(p3, p3.yzx + 33.33); | |
return fract((p3.xx + p3.yz) * p3.zy); | |
} | |
float noise11(float x) | |
{ | |
float i = floor(x); | |
float f = fract(x); | |
float u = f * f * (3.0 - 2.0 * f); | |
return mix(hash11(i), hash11(i + 1.0), u); | |
} | |
vec2 rot2d(vec2 p, float a) | |
{ | |
a *= PI / 180.0; | |
float c = cos(a); | |
float s = sin(a); | |
return vec2(c * p.x - s * p.y, s * p.x + c * p.y); | |
} | |
vec4 permute(vec4 x) | |
{ | |
return mod(((x * 34.0) + 1.0) * x, 289.0); | |
} | |
float taylorInvSqrt(float r) | |
{ | |
return 1.79284291400159 - 0.85373472095314 * r; | |
} | |
vec4 taylorInvSqrt(vec4 r) | |
{ | |
return vec4(taylorInvSqrt(r.x), taylorInvSqrt(r.y), taylorInvSqrt(r.z), taylorInvSqrt(r.w)); | |
} | |
// Simplex 3D Noise | |
// by Ian McEwan, Ashima Arts | |
// | |
float snoise(vec3 v) | |
{ | |
const vec2 C = vec2(0.5, 1.0) / 3.0; | |
const vec4 D = vec4(0.0, 0.5, 1.0, 2.0); | |
// First corner | |
vec3 i = floor(v + dot(v, C.yyy)); | |
vec3 x0 = v - i + dot(i, C.xxx); | |
// Other corners | |
vec3 g = step(x0.yzx, x0.xyz); | |
vec3 l = 1.0 - g; | |
vec3 i1 = min(g.xyz, l.zxy); | |
vec3 i2 = max(g.xyz, l.zxy); | |
// x0 = x0 - 0. + 0.0 * C | |
vec3 x1 = x0 - i1 + 1.0 * C.xxx; | |
vec3 x2 = x0 - i2 + 2.0 * C.xxx; | |
vec3 x3 = x0 - 1. + 3.0 * C.xxx; | |
// Permutations | |
i = mod(i, 289.0); | |
vec4 p = permute(permute(permute(i.z + vec4(0.0, i1.z, i2.z, 1.0)) + i.y + vec4(0.0, i1.y, i2.y, 1.0)) + i.x + vec4(0.0, i1.x, i2.x, 1.0)); | |
// Gradients | |
// ( N*N points uniformly over a square, mapped onto an octahedron.) | |
float n_ = 1.0 / 7.0; // N=7 | |
vec3 ns = n_ * D.wyz - D.xzx; | |
vec4 j = p - 49.0 * floor(p * ns.z * ns.z); // mod(p,N*N) | |
vec4 x_ = floor(j * ns.z); | |
vec4 y_ = floor(j - 7.0 * x_); // mod(j,N) | |
vec4 x = x_ * ns.x + ns.yyyy; | |
vec4 y = y_ * ns.x + ns.yyyy; | |
vec4 h = 1.0 - abs(x) - abs(y); | |
vec4 b0 = vec4(x.xy, y.xy); | |
vec4 b1 = vec4(x.zw, y.zw); | |
vec4 s0 = floor(b0) * 2.0 + 1.0; | |
vec4 s1 = floor(b1) * 2.0 + 1.0; | |
vec4 sh = -step(h, vec4(0, 0, 0, 0)); | |
vec4 a0 = b0.xzyw + s0.xzyw * sh.xxyy; | |
vec4 a1 = b1.xzyw + s1.xzyw * sh.zzww; | |
vec3 p0 = vec3(a0.xy, h.x); | |
vec3 p1 = vec3(a0.zw, h.y); | |
vec3 p2 = vec3(a1.xy, h.z); | |
vec3 p3 = vec3(a1.zw, h.w); | |
//Normalise gradients | |
vec4 norm = taylorInvSqrt(vec4(dot(p0, p0), dot(p1, p1), dot(p2, p2), dot(p3, p3))); | |
p0 *= norm.x; | |
p1 *= norm.y; | |
p2 *= norm.z; | |
p3 *= norm.w; | |
// lerp final noise value | |
vec4 m = max(0.6 - vec4(dot(x0, x0), dot(x1, x1), dot(x2, x2), dot(x3, x3)), 0.0); | |
m = m * m; | |
float res = clamp(42.0 * dot(m * m, vec4(dot(p0, x0), dot(p1, x1), dot(p2, x2), dot(p3, x3))), -1.0, 1.0); | |
return clamp((res + 1.0) * 0.5, 0.0, 1.0); | |
} | |
#define NumOctaves 4 | |
float fbm(vec3 x, in float H) | |
{ | |
float G = exp2(-H); | |
float f = 1.0; | |
float a = 1.0; | |
float t = 0.0; | |
for(int i = 0; i < NumOctaves; i++) | |
{ | |
t += a * snoise(f * x); | |
f *= 2.0; | |
a *= G; | |
} | |
return clamp(t, 0.0, 1.0); | |
} | |
vec3 pattern(vec3 p) | |
{ | |
vec3 q; | |
q.x = fbm(p, 2.0); | |
q.y = fbm(p + vec3(4.2, 1.3, 0.42), 2.0); | |
q.z = fbm(p + vec3(5.3, .1, 3.12), 2.0); | |
vec3 r; | |
r.x = fbm(p + 4.0 * q + vec3(0.2, 6.7, 3.2), 2.0); | |
r.y = fbm(p + 4.0 * q + vec3(4.2, 2.2, 1.1), 2.0); | |
r.z = fbm(p + 4.0 * q + vec3(1.2, 4.1, 7.1), 2.0); | |
vec3 res, ss = p + 4.0 * r; | |
res.x = fbm(vec3(ss.x, 0, 0), 2.0); | |
res.y = fbm(vec3(0, ss.y, 0), 2.0); | |
res.z = fbm(vec3(0, 0, ss.z), 2.0); | |
return res; | |
} | |
float smoothMin(float a, float b, float k) | |
{ | |
float h = clamp(0.5 + 0.5 * (b - a) / k, 0.0, 1.0); | |
return mix(b, a, h) - k * h * (1.0 - h); | |
} | |
float foldPlus(float x, float f) | |
{ | |
return f - abs(x - f); | |
} | |
float foldMinus(float x, float f) | |
{ | |
return f + abs(x - f); | |
} | |
void tangentSpaceBasis(vec3 normal, out vec3 tangent, out vec3 binormal) | |
{ | |
vec3 n = normalize(normal); | |
vec3 t = vec3(0.0, 0.0, 0.0); | |
vec3 b = vec3(0.0, 0.0, 0.0); | |
if(n.x < 0.9999) | |
{ | |
t = normalize(cross(n, vec3(1.0, 0.0, 0.0))); | |
} | |
else | |
{ | |
t = normalize(cross(n, vec3(0.0, 1.0, 0.0))); | |
} | |
b = cross(n, t); | |
tangent = t; | |
binormal = b; | |
} | |
vec3 localToWorld(vec3 local, vec3 tangent, vec3 normal, vec3 binormal) | |
{ | |
return tangent * local.x + normal * local.y + binormal * local.z; | |
} | |
vec3 reflSample(vec2 rnd, float n) | |
{ | |
float theta = acos(pow(1.0 - rnd.x, 1.0 / (1.0 + n))); | |
float phi = 2.0 * PI * rnd.y; | |
return vec3(sin(theta) * cos(phi), cos(theta), sin(theta) * sin(phi)); | |
} | |
vec3 randomSphereDir(vec2 rnd) | |
{ | |
float s = rnd.x * PI * 2.; | |
float t = rnd.y * 2. - 1.; | |
return vec3(sin(s), cos(s), t) / sqrt(1.0 + t * t); | |
} | |
//SDF---------------------------------------------------------------------- | |
float sdBox(vec3 p, vec3 b) | |
{ | |
vec3 q = abs(p) - b; | |
return length(max(q, 0.0)) + min(max(q.x, max(q.y, q.z)), 0.0); | |
} | |
float sdVerticalCapsule(vec3 p, float h, float r) | |
{ | |
p.y -= clamp(p.y, 0.0, h); | |
return length(p) - r; | |
} | |
float sdHolizontalCapsule(vec3 p, float h, float r) | |
{ | |
p.x -= clamp(p.x, 0.0, h); | |
return length(p) - r; | |
} | |
float sdTorus(vec3 p, vec2 t) | |
{ | |
vec2 q = vec2(length(p.xy) - t.x, p.z); | |
return length(q) - t.y; | |
} | |
float sdTorusYZ(vec3 p, vec2 t) | |
{ | |
vec2 q = vec2(length(p.yz) - t.x, p.x); | |
return length(q) - t.y; | |
} | |
float sdCappedCylinder(vec3 p, float h, float r) | |
{ | |
vec2 d = abs(vec2(length(p.xz), p.y)) - vec2(r, h); | |
return min(max(d.x, d.y), 0.0) + length(max(d, 0.0)); | |
} | |
float sdSphere(vec3 p, in float r) | |
{ | |
return length(p) - r; | |
} | |
//Map---------------------------------------------------------------------- | |
float sofa(vec3 p) | |
{ | |
float n = 0.0; | |
p.x = foldPlus(p.x, 1.05); | |
float d = sdBox(p, vec3(1, 0.3, 0.6)); | |
n = 0.05 * clamp(snoise(p * 50.0) * 15.0, 0.95, 1.0); | |
return d - n; | |
} | |
MatInfo _sofa(vec3 p) | |
{ | |
MatInfo info = MatInfo(); | |
float ha = 1.0; | |
vec3 c = HexColor(0xDEDAC5); | |
info.roughness = 1.0; | |
info.metalic = 0.0; | |
ha = remapc(hash12(hash23(p * 42.0)), 0.0, 1.0, 0.8, 1.0); | |
info.color = c * ha; | |
return info; | |
} | |
float room(vec3 p) | |
{ | |
const float h = 4.0; | |
const float f = 6.0 * PI; | |
const float a = 7.0; | |
const float m = 0.02; | |
vec3 uv = p; | |
float n = 0.0; | |
float d = -sdBox(p - vec3(0, 2, 0), vec3(8, 2, 6)); | |
d = max(d, -sdBox(p - vec3(1.5, 0, 0), vec3(1.5, 2.0, 4))); | |
d = min(d, sdBox(p - vec3(4.5, h * 0.5, 0), vec3(1.5, h, 4))); | |
d = min(d, sdBox(p - vec3(-6.0, h * 0.5, 4.0), vec3(3, h, 2))); | |
n = clamp(abs(cos(uv.x * f) + 1.0) * a, 0.0, 1.0) * | |
clamp(abs(cos(uv.y * f) + 1.0) * a, 0.0, 1.0) * | |
clamp(abs(cos(uv.z * f) + 1.0) * a, 0.0, 1.0) * | |
(1.0 + (snoise(p * 20.0) - 0.5) * 0.1) * m; | |
return d - n; | |
} | |
const vec3 _roomCols[4] = vec3[4](HexColor(0x425C78), HexColor(0xC3CED6), HexColor(0x4D7085), HexColor(0xA8BDCB)); | |
MatInfo _room(vec3 p) | |
{ | |
MatInfo info = MatInfo(); | |
const float f = 6.0 * PI; | |
const float a = 7.0; | |
const float m = 0.02; | |
vec3 uv = p; | |
float n = clamp(abs(cos(uv.x * f) + 1.0) * a, 0.0, 1.0) * | |
clamp(abs(cos(uv.y * f) + 1.0) * a, 0.0, 1.0) * | |
clamp(abs(cos(uv.z * f) + 1.0) * a, 0.0, 1.0) * | |
(1.0 + (snoise(p * 20.0) - 0.5) * 0.1) * m; | |
int id = int(hash12(hash23(floor(p * 3.0 + 1.5) * 42.0)) * 4.0); | |
vec3 maincol = _roomCols[id]; | |
const vec3 mizocol = HexColor(0x040D18); | |
float mizu = pow(remapc(snoise(p * 0.5), 0.5, 1.0, 0.0, 1.0), 0.5) * remapc(p.y, 0.2, 0.5, 1.0, 0.0); | |
info.roughness = 0.05; | |
info.metalic = mizu * 0.5; | |
info.color = (n > m * 0.2 ? maincol : mizocol); | |
return info; | |
} | |
float handrail(vec3 p) | |
{ | |
const float h = 5.0; | |
const float b = 0.02; | |
const float a = 15.0 * PI / 180.0; | |
float d = LenMax; | |
float r = 0.0; | |
r = 0.25; | |
float tp = r / tan(a); | |
vec3 p0 = p; | |
p0.x -= h * 0.5; | |
p0.y -= h - h * 0.5 * sqrt(3.0); | |
p0.xy = rot2d(p0.xy, -30.0); | |
float d0 = sdVerticalCapsule(p, h - tp, b); | |
float d1 = sdVerticalCapsule(p0, h - tp, b); | |
vec3 p1 = p - vec3(r, h - tp, 0); | |
float rt = atan(p1.y, p1.x); | |
float d2 = sdTorus(p1, vec2(r, b)); | |
d = min(d, d0); | |
d = min(d, d1); | |
d = (PI / 6.0 <= rt && rt <= PI) ? d2 : d; | |
return d; | |
} | |
MatInfo _handrail(vec3 p) | |
{ | |
MatInfo info = MatInfo(); | |
info.roughness = 0.0; | |
info.metalic = 1.0; | |
info.color = vec3(1.0); | |
return info; | |
} | |
float desk(vec3 p) | |
{ | |
float d = LenMax; | |
d = min(d, sdBox(p - vec3(0.0, 1.5, 0.0), vec3(1.0, 0.05, 2.0))); | |
vec3 p0 = p; | |
p0.x = foldPlus(p0.x, 0.0); | |
p0.z = foldPlus(p0.z, 0.0); | |
d = min(d, sdBox(p0 - vec3(-0.8, 0.5, -1.8), vec3(0.04, 1.0, 0.04))); | |
return d; | |
} | |
const vec3 _deskCols[4] = vec3[4](HexColor(0xAD8974), HexColor(0x9E765D), HexColor(0x755240), HexColor(0x4C392C)); | |
MatInfo _desk(vec3 p) | |
{ | |
MatInfo info = MatInfo(); | |
const vec3 cz = HexColor(0x1E0E04); | |
float n = fract(fbm(p * vec3(2.0, 2.0, 0.5), 2.0) * 7.0) * 3.0; | |
int id = int(n); | |
float ca = fract(n); | |
vec3 c = mix(_deskCols[id], _deskCols[id + 1], ca); | |
info.roughness = 0.15; | |
info.color = p.y < 1.44 ? cz : c; | |
info.metalic = float(p.y < 1.44); | |
return info; | |
} | |
float computerFrame(vec3 p) | |
{ | |
const float fu = 14.0 * PI; | |
const float fv = 6.0 * PI; | |
const float a = 5.0; | |
float d = LenMax; | |
p.y -= 1.5; | |
vec2 uv = remap(p.xz, vec2(-0.25, -0.45), vec2(0.05, 0.45), vec2(0, 0), vec2(1, 1)).yx; | |
float n = 0.0; | |
n = clamp(abs(sin(uv.x * fu)) * a, 0.0, 1.0) * clamp(abs(sin(uv.y * fv)) * a, 0.0, 1.0) * 0.005; | |
n *= float(0.0 <= uv.x && uv.x <= 1.0 && 0.0 <= uv.y && uv.y <= 1.0); | |
d = min(d, sdBox(p - vec3(0.0, 0.1, 0.0), vec3(0.3, 0.0, 0.5)) - 0.01); | |
d = max(d, -sdBox(p - vec3(0.175, 0.1 + 0.01, 0.0), vec3(0.11, 0.006, 0.2))); | |
return d - n; | |
} | |
MatInfo _computerFrame(vec3 p) | |
{ | |
const float fu = 14.0 * PI; | |
const float fv = 6.0 * PI; | |
const float a = 5.0; | |
vec2 uv = remap(p.xz, vec2(-0.25, -0.45), vec2(0.05, 0.45), vec2(0, 0), vec2(1, 1)).yx; | |
float n = 0.0; | |
n = clamp(abs(sin(uv.x * fu)) * a, 0.0, 1.0) * clamp(abs(sin(uv.y * fv)) * a, 0.0, 1.0) * 0.005; | |
n *= float(0.0 <= uv.x && uv.x <= 1.0 && 0.0 <= uv.y && uv.y <= 1.0); | |
MatInfo info = MatInfo(); | |
info.roughness = n > 0.001 ? 1.0 : 0.9; | |
info.color = n > 0.001 ? vec3(0.1) : HexColor(0xCACBCD); | |
return info; | |
} | |
float computerScreen(vec3 p) | |
{ | |
p -= vec3(-0.4, 1.9, 0); | |
p.xy = rot2d(p.xy, -15.0); | |
return sdBox(p, vec3(0.0, 0.3, 0.5)) - 0.01; | |
} | |
vec2 _rotate(vec2 p, float a) | |
{ | |
float s = sin(a); | |
float c = cos(a); | |
mat2 m = mat2(c, -s, s, c); | |
return m * p; | |
} | |
float d2_sdf_arc(vec2 p, vec2 sc, float ra, float rb) | |
{ | |
p.x = abs(p.x); | |
return ((sc.y * p.x > sc.x * p.y) ? length(p - sc * ra) : abs(length(p) - ra)) - rb; | |
} | |
float sessions_s(vec2 uv) | |
{ | |
const float angle = 4.4; | |
const float thin = 0.1; | |
const vec2 offset_S = vec2(-0.35, 0.0); | |
uv *= 0.57; | |
uv += vec2(0.4, 0.14); | |
uv += offset_S; | |
uv = _rotate(uv, -0.2); | |
uv -= offset_S; | |
uv = uv * 2.0 - 1.0; | |
uv.y *= 1.25; | |
vec2 uv1 = uv + offset_S; | |
uv1.y -= 0.2 + thin; | |
uv1 = _rotate(uv1, angle); | |
float d1 = d2_sdf_arc(uv1, vec2(sin(angle), cos(angle)), 0.3, thin); | |
vec2 uv2 = uv + offset_S; | |
uv2.y += 0.2 + thin; | |
uv2 = _rotate(uv2, angle + PI); | |
float d2 = d2_sdf_arc(uv2, vec2(sin(angle), cos(angle)), 0.3, thin); | |
return float(min(d1, d2) < 0.0); | |
} | |
float sessions(vec2 uv) | |
{ | |
float pl = 1.0; | |
pl *= float(uv.x < 0.25); | |
pl *= float(mod(0.5 + uv.x + uv.y, 0.3) < 0.15); | |
float pr = 1.0; | |
pr *= float(uv.x >= 0.25); | |
pr -= sessions_s(uv); | |
float p = pl + pr; | |
return clamp(1.0 - p, 0.0, 1.0); | |
} | |
float easing(float t) | |
{ | |
return pow(t, 0.1); | |
} | |
const vec3 _scolpalette0[4] = vec3[](HexColor(0x2B3467), HexColor(0xBAD7F9), vec3(1), HexColor(0xEB455F)); | |
vec3 sessionsCol(vec2 uv) | |
{ | |
float lt = ABSLocalTime * 0.5; | |
lt = floor(lt) + easing(fract(lt)); | |
float amp = 1.0; | |
SCI01(5) | |
{ | |
amp = mix(1.0, 0.0, clamp(T * 2.0, 0.0, 1.0)); | |
} | |
float n0 = floor(hash11(floor(lt)) * 10.0 * amp + 1.0); | |
vec3 scol = vec3(0); | |
vec2 div = vec2(16. / 9., 1.) * n0; | |
vec2 id = floor(uv * div); | |
lt += 0.25 * id.y / div.y; | |
uv.x += 0.1 * (cos(2.0 * PI * lt) + 2.0 * PI * lt); | |
id = floor(uv * div); | |
uv = mod(uv, 1. / div) * div; | |
float pix = sessions(uv); | |
vec3 col = _scolpalette0[int(hash12(id) * 4.0)]; | |
scol = mix(scol, col, pix); | |
float thresh = 0.05; | |
SCI01(5) | |
{ | |
thresh = mix(0.05, 1.0, clamp(T / 0.8, 0.0, 1.0)); | |
} | |
scol = hash12(id + 42.42) < thresh ? vec3(length(scol) < .1, 0, 0) : scol; | |
return scol; | |
} | |
vec3 screenCol(vec2 uv) | |
{ | |
float lt = ABSLocalTime * 0.5; | |
lt = floor(lt) + easing(fract(lt)); | |
float mt = mod(lt, 1.0); | |
float s = mt < 0.8 ? 0.0 : pow(mix(0.0, 1.0, (mt - 0.8) * 5.0), 5.0); | |
vec2 sh = vec2(s, 0) * 0.025; | |
return vec3(sessionsCol(uv + sh).r, sessionsCol(uv).g, sessionsCol(uv - sh).b); | |
} | |
//LIGHT | |
MatInfo _computerScreen(vec3 p) | |
{ | |
MatInfo info = MatInfo(); | |
p -= vec3(-0.4, 1.9, 0); | |
p.xy = rot2d(p.xy, -15.0); | |
vec2 uv = remap(p.zy, vec2(-0.5, -9. / 32.), vec2(0.5, 9. / 32.), vec2(0), vec2(1)); | |
bool inSide = 0.0 < uv.x && uv.x < 1.0 && 0.0 < uv.y && uv.y < 1.0 && p.x > 0.0; | |
info.color = inSide ? screenCol(uv) : HexColor(0xCACBCD); | |
info.emission = float(inSide && length(info.color) > .1) * 4.0; | |
info.roughness = 1.0; | |
info.lightRange = 14.0; | |
POORSC | |
{ | |
info.color = inSide ? BackBuffer(uv).rgb : HexColor(0xCACBCD); | |
info.emission = float(inSide && length(info.color) > .1); | |
info.lightRange = 4.0; | |
} | |
return info; | |
} | |
float coffee(vec3 p) | |
{ | |
float d = LenMax; | |
d = min(d, sdCappedCylinder(p - vec3(0.0, 1.67, 0.0), 0.1, 0.1)); | |
d = max(d, -sdCappedCylinder(p - vec3(0.0, 1.67 + 0.1, 0.0), 0.04, 0.09)); | |
d -= 0.001; | |
d = smoothMin(d, sdTorusYZ(p - vec3(0.0, 1.65, 0.1), vec2(0.06, 0.01)), 0.01); | |
return d; | |
} | |
MatInfo _coffee(vec3 p) | |
{ | |
MatInfo info = MatInfo(); | |
bool isCoffee = length(p.xz) < 0.09; | |
info.roughness = isCoffee ? 0.0 : 0.5; | |
info.color = isCoffee ? vec3(0.1) : vec3(0.932813, 0.867187, 0.7125); | |
return info; | |
} | |
float ceilLattice(vec3 p) | |
{ | |
float d = LenMax; | |
float mz = 0.25, mx = 1.0; | |
p.z = opRep(p.z, mz); | |
d = min(d, length(p.yz) - 0.01); | |
p.x = opRep(p.x, mx); | |
d = smoothMin(d, length(p.xy) - 0.025, 0.01); | |
return d; | |
} | |
MatInfo _ceilLattice(vec3 p) | |
{ | |
MatInfo info = MatInfo(); | |
info.roughness = 0.05; | |
info.color = vec3(0.9); | |
return info; | |
} | |
float ceilLightFrame(vec3 p) | |
{ | |
float d = LenMax; | |
const float m = 3.25; | |
const float y = -0.25; | |
p.xz = opRepLim(p.xz, m, vec2(-2.0, -2.0), vec2(0.0, 1.0)); | |
d = min(d, sdBox(p - vec3(0.0, -0.125 + y, 0.0), vec3(m * 0.25 + 0.05, 0.025, 0.175))); | |
p.z = foldPlus(p.z, 0.0); | |
p.x = opRepLim(p.x - m * 0.25, m * 0.5, -1.0, 0.0); | |
d = min(d, sdBox(p - vec3(0.0, -0.2 + y, -0.1), vec3(0.025, 0.05, 0.05))); | |
d = min(d, sdVerticalCapsule(p - vec3(0.0, -0.2 + y, -0.1), m * 0.5, 0.005)); | |
return d; | |
} | |
MatInfo _ceilLightFrame(vec3 p) | |
{ | |
MatInfo info = MatInfo(); | |
info.roughness = 0.05; | |
info.color = vec3(0.9); | |
return info; | |
} | |
float ceilLightLight(vec3 p) | |
{ | |
const float m = 3.25; | |
const float y = -0.25; | |
p.xz = opRepLim(p.xz, m, vec2(-2.0, -2.0), vec2(0.0, 1.0)); | |
p.z = foldPlus(p.z, 0.0); | |
return sdHolizontalCapsule(p - vec3(-m * 0.25, -0.2 + y, -0.1), m * 0.5, 0.02); | |
} | |
//LIGHT | |
MatInfo _ceilLightLight(vec3 p) | |
{ | |
MatInfo info = MatInfo(); | |
POORSC | |
{ | |
info.emission = mix(hash11(floor(LocalTime * 3.0)) < 0.5 ? 0.4 : 0.7, 1.0, pow(clamp(noise11(LocalTime * 6.5) * 4.0, 0.0, 1.0), 16.0)); | |
info.emission *= 0.75; | |
} | |
info.lightRange = 5.0; | |
info.color = HexColor(0xDDE6FF); | |
return info; | |
} | |
#define SnakeLights 6 | |
float sdSnake3D(vec2 plane, float t, float tmin, float tmax, float start, float end, float seed) | |
{ | |
const float a = 0.2; | |
const float f = 2.0; | |
vec3 p0 = vec3((t + seed) * f, 0.0, 0.0); | |
float x = remapc(t, tmin, tmax, 0.0, 1.0); | |
float v = a * (noise11(p0.x) - 0.5) + mix(start, end, x * x); | |
float sdplanex = abs(plane.x - v); | |
float sdplaney = abs(plane.y); | |
float sdplanez = max(max(t - tmax, tmin - t), 0.0); | |
return sqrt(sdplanex * sdplanex + sdplaney * sdplaney + sdplanez * sdplanez); | |
} | |
float snakeLightLine(vec3 p, int index) | |
{ | |
const float radius = 0.02; | |
p.y -= 0.1; | |
float seed = float(index + 1); | |
float d = LenMax; | |
// Yuka | |
const vec2 trange0 = vec2(-8.0, 0.0 + radius * 2.0), startrange0 = vec2(-3.0, -1.0), endrange0 = vec2(-3.5, 2.0); | |
float start = mix(startrange0.x, startrange0.y, hash12(vec2(seed))); | |
float end = mix(endrange0.x, endrange0.y, hash12(vec2(seed + float(SnakeLights) * 42.0))); | |
d = min(d, sdSnake3D(p.zy - vec2(0, 2.0 * radius), p.x, trange0.x, trange0.y, start, end, seed) - radius); | |
// Kabe | |
const vec2 trange1 = vec2(0.0, 1.5); | |
const float end1 = -2.0; | |
d = min(d, sdSnake3D(p.zx - vec2(0, 2.0 * radius + trange0.x), p.y, trange1.x, trange1.y, start, end1, seed + trange0.x) - radius); | |
// Pool | |
const vec2 trange2 = vec2(-2.0, 0.0 + radius * 2.0); | |
d = min(d, sdSnake3D(p.zx - vec2(0, 2.0 * radius), p.y, trange2.x, trange2.y, end, end, seed) - radius); | |
return d; | |
} | |
const vec3 _cols[4] = vec3[](HexColor(0x7D6D94), HexColor(0xB57BBE), HexColor(0x5976CB), HexColor(0x6EB8D7)); | |
//LIGHT | |
MatInfo _snakeLightLine(vec3 p, int index) | |
{ | |
const float emitr = 0.1, nonemitr = 0.2; | |
const float emitsumr = emitr + nonemitr; | |
p.y -= 0.1; | |
float seed = float(index + 1); | |
float emits = -mix(0.1, 1.0, hash12(vec2(seed, 0))); | |
float emitn = hash12(vec2(seed, 42)); | |
float emitx = mod(p.x - p.y + emits * LocalTime + emitn * emitsumr, emitsumr); | |
bool isemit = emitx < emitr; | |
MatInfo info = MatInfo(); | |
info.color = vec3(0.9); | |
POORSC | |
{ | |
info.color = _cols[index % 4] * (isemit ? 1.0 : 0.15); | |
info.emission = 1.0; | |
} | |
info.roughness = 1.0; | |
info.lightRange = 2.0; | |
return info; | |
} | |
float snakeLights(vec3 p) | |
{ | |
float d = LenMax; | |
for(int i = 0; i < SnakeLights; i++) | |
{ | |
d = min(d, snakeLightLine(p, i)); | |
} | |
return d; | |
} | |
#define NazoLights 3 | |
const vec3 _nazoPoses[NazoLights] = vec3[](vec3(-6.25, 1.26 - 0.3, -5.3), vec3(-6.25 + 4.5, 1.26 - 0.3, -5.3 + 10.5), vec3(2.4, 1.26 - 3.0, 3.4)); | |
const vec3 _nazoCols[NazoLights] = vec3[](HexColor(0xB5CDFF), HexColor(0xFFC99D), vec3(0.9)); | |
float nazoLight(vec3 p, int index) | |
{ | |
float d = LenMax; | |
d = sdSphere(p - _nazoPoses[index % NazoLights] - vec3(0, 0.3, 0), 0.5); | |
return d; | |
} | |
// LIGHT | |
MatInfo _nazoLight(vec3 p, int index) | |
{ | |
MatInfo info = MatInfo(); | |
info.emission = 1.0; | |
OPENINGSC | |
{ | |
info.emission = 0.0; | |
} | |
info.roughness = 1.0; | |
info.color = _nazoCols[index % NazoLights]; | |
info.lightRange = 4.0; | |
return info; | |
} | |
float nazoLights(vec3 p) | |
{ | |
float d = LenMax; | |
for(int i = 0; i < NazoLights; i++) | |
{ | |
d = min(d, nazoLight(p, i)); | |
} | |
return d; | |
} | |
float sdf(vec3 p) | |
{ | |
float d = LenMax; | |
d = min(d, room(p)); | |
d = min(d, sofa(p - vec3(-1.7, 0.35, 5.3))); | |
vec3 p0 = p; | |
p0.z = foldMinus(p0.z, -2.0); | |
d = min(d, sofa(p0 - vec3(-6.3, 0.35, 1.3))); | |
vec3 p1 = p; | |
p1.z = foldMinus(p1.z, -2.5); | |
d = min(d, handrail(p1 - vec3(-0.2, -3.0, -2.0))); | |
d = min(d, desk(p - vec3(-7.0, 0.0, -2.0))); | |
d = min(d, computerFrame(p - vec3(-7.0, 0.0, -2.0))); | |
d = min(d, computerScreen(p - vec3(-7.0, 0.0, -2.0))); | |
d = min(d, nazoLights(p)); | |
d = min(d, ceilLightFrame(p - vec3(1.5, 3.5, 1.5))); | |
d = min(d, ceilLightLight(p - vec3(1.5, 3.5, 1.5))); | |
d = min(d, ceilLattice(p - vec3(0.0, 3.5, 0.0))); | |
d = min(d, coffee(p - vec3(-7.0, 0.0, -1.0))); | |
d = min(d, snakeLights(p)); | |
return d; | |
} | |
// dist,id | |
vec2 map(vec3 p) | |
{ | |
#define opMatUnion(sdf) (id = ((dt = sdf) < d ? (d = dt, mid): id)), mid++ | |
int id = -1, mid = 0; | |
float d = LenMax, dt = 0.0; | |
vec3 p0 = p, p1 = p; | |
p0.z = foldMinus(p0.z, -2.0); | |
p1.z = foldMinus(p1.z, -2.5); | |
opMatUnion(room(p)); | |
opMatUnion(sofa(p - vec3(-1.7, 0.35, 5.3))); | |
opMatUnion(sofa(p0 - vec3(-6.3, 0.35, 1.3))); | |
opMatUnion(handrail(p1 - vec3(-0.2, -3.0, -2.0))); | |
opMatUnion(desk(p - vec3(-7.0, 0.0, -2.0))); | |
opMatUnion(computerFrame(p - vec3(-7.0, 0.0, -2.0))); | |
opMatUnion(computerScreen(p - vec3(-7.0, 0.0, -2.0))); | |
for(int i = 0; i < NazoLights; i++) | |
{ | |
opMatUnion(nazoLight(p, i)); | |
} | |
opMatUnion(ceilLightFrame(p - vec3(1.5, 3.5, 1.5))); | |
opMatUnion(ceilLightLight(p - vec3(1.5, 3.5, 1.5))); | |
opMatUnion(ceilLattice(p - vec3(0.0, 3.5, 0.0))); | |
opMatUnion(coffee(p - vec3(-7.0, 0.0, -1.0))); | |
for(int i = 0; i < SnakeLights; i++) | |
{ | |
opMatUnion(snakeLightLine(p, i)); | |
} | |
return vec2(d, id); | |
} | |
MatInfo getMatInfo(vec3 p, float fid) | |
{ | |
#define ifMat(mat) if(id == mid++)return mat | |
#define elifMat(mat) else if(id == mid++)return mat | |
int id = int(fid + 0.5), mid = 0; | |
vec3 p0 = p, p1 = p; | |
p0.z = foldMinus(p0.z, -2.0); | |
p1.z = foldMinus(p1.z, -2.5); | |
ifMat(_room(p)); | |
elifMat(_sofa(p - vec3(-1.7, 0.35, 5.3))); | |
elifMat(_sofa(p0 - vec3(-6.3, 0.35, 1.3))); | |
elifMat(_handrail(p1 - vec3(-0.2, -3.0, -2.0))); | |
elifMat(_desk(p - vec3(-7.0, 0.0, -2.0))); | |
elifMat(_computerFrame(p - vec3(-7.0, 0.0, -2.0))); | |
elifMat(_computerScreen(p - vec3(-7.0, 0.0, -2.0))); | |
for(int i = 0; i < NazoLights; i++) | |
{ | |
ifMat(_nazoLight(p, i)); | |
} | |
ifMat(_ceilLightFrame(p - vec3(1.5, 3.5, 1.5))); | |
elifMat(_ceilLightLight(p - vec3(1.5, 3.5, 1.5))); | |
elifMat(_ceilLattice(p - vec3(0.0, 3.5, 0.0))); | |
elifMat(_coffee(p - vec3(-7.0, 0.0, -1.0))); | |
for(int i = 0; i < SnakeLights; i++) | |
{ | |
ifMat(_snakeLightLine(p, i)); | |
} | |
return MatInfo(); | |
} | |
MatInfo getMatInfo(vec3 p) | |
{ | |
return getMatInfo(p, map(p).y); | |
} | |
vec3 normal(vec3 p) | |
{ | |
const float h = NormalEPS; | |
const vec2 k = vec2(1, -1); | |
return normalize(k.xyy * sdf(p + k.xyy * h) + k.yyx * sdf(p + k.yyx * h) + k.yxy * sdf(p + k.yxy * h) + k.xxx * sdf(p + k.xxx * h)); | |
} | |
// Intersect | |
void calcIntersect(out vec3 rp0, out float len0, vec3 rd0, vec3 ro0) | |
{ | |
int i; | |
float dist = 0.0; | |
len0 = 0.0; | |
for(i = 0; i < LoopMax; i++) | |
{ | |
rp0 = ro0 + rd0 * len0; | |
dist = sdf(rp0); | |
len0 += dist; | |
if(dist < DistMin || len0 > LenMax) | |
{ | |
break; | |
} | |
} | |
} | |
// Light | |
#define OtherLights 2 | |
#define LightCount (OtherLights+NazoLights+SnakeLights) | |
float lightsdf(vec3 p, int id) | |
{ | |
int mid = 0; | |
#define ifLSDF(sdf) if(id == mid++)return sdf | |
#define elifLSDF(sdf) else if(id == mid++)return sdf | |
ifLSDF(computerScreen(p - vec3(-7.0, 0.0, -2.0))); | |
elifLSDF(ceilLightLight(p - vec3(1.5, 3.5, 1.5))); | |
for(int i = 0; i < NazoLights; i++) | |
{ | |
ifLSDF(nazoLight(p, i)); | |
} | |
for(int i = 0; i < SnakeLights; i++) | |
{ | |
ifLSDF(snakeLightLine(p, i)); | |
} | |
return LenMax; | |
} | |
MatInfo getLightInfo(vec3 p, int id) | |
{ | |
#define ifMat(mat) if(id == mid++)return mat | |
#define elifMat(mat) else if(id == mid++)return mat | |
int mid = 0; | |
ifMat(_computerScreen(p - vec3(-7.0, 0.0, -2.0))); | |
elifMat(_ceilLightLight(p - vec3(1.5, 3.5, 1.5))); | |
for(int i = 0; i < NazoLights; i++) | |
{ | |
ifMat(_nazoLight(p, i)); | |
} | |
for(int i = 0; i < SnakeLights; i++) | |
{ | |
ifMat(_snakeLightLine(p, i)); | |
} | |
return MatInfo(); | |
} | |
vec3 lightDirection(vec3 p, in int lightIndex) | |
{ | |
const float h = NormalEPS; | |
const vec2 k = vec2(1, -1); | |
return -normalize(k.xyy * lightsdf(p + k.xyy * h, lightIndex) + k.yyx * lightsdf(p + k.yyx * h, lightIndex) + k.yxy * lightsdf(p + k.yxy * h, lightIndex) + k.xxx * lightsdf(p + k.xxx * h, lightIndex)); | |
} | |
#define ApporximateLightSamples 5 | |
void apporximateLight(out vec3 lightCol, out vec3 lightDir, out float lightLen, out float laRes, vec3 ro, int lightIndex) | |
{ | |
const float maxdiff = 0.2; | |
const float distFactor = 1.0; | |
MatInfo lightInfo = MatInfo(); | |
float la = 0.0; | |
float emission = 0.0, dist = 0.0; | |
vec3 col = vec3(0); | |
vec3 rp, rd; | |
rp = ro; | |
dist = lightsdf(rp, lightIndex); | |
lightInfo = getLightInfo(rp, lightIndex); | |
la = lightAttenuation(lightInfo, dist); | |
col += lightInfo.color * la; | |
emission += la; | |
for(int j = 0; j < ApporximateLightSamples; j++) | |
{ | |
rd = lightDirection(rp, lightIndex); | |
float diff = clamp(1.0 - float(j) / float(ApporximateLightSamples - 1), 0.0, 1.0) * maxdiff; | |
rd = normalize(rd + diff * randomSphereDir(hash23(vec3(float(j) + LocalTime, hash23(rd * 42.0) * 42.0 - vec2(float(lightIndex) * 0.42))))); | |
dist = lightsdf(rp, lightIndex); | |
lightInfo = getLightInfo(rp, lightIndex); | |
la = lightAttenuation(lightInfo, dist); | |
col += lightInfo.color; | |
emission += la; | |
rp += rd * dist * distFactor; | |
} | |
col /= float(ApporximateLightSamples + 1); | |
emission /= float(ApporximateLightSamples + 1); | |
lightLen = length(rp - ro); | |
lightDir = (rp - ro) / lightLen; | |
lightInfo.emission = emission; | |
laRes = lightAttenuation(lightInfo, lightLen); | |
lightCol = laRes * col; | |
} | |
void calcMixColAndShadow(out vec3 mixCol, out float mixLa, vec3 roOrigin, vec3 rdOrigin, vec3 normal, in MatInfo infoOrigin) | |
{ | |
const float laFactor = 1.0, laMax = 1.0; | |
const float shadowThresh = 0.1; | |
mixCol = vec3(0.0); | |
mixLa = 0.0; | |
vec3 ro = roOrigin + normal * NormalEPS * 50.0; | |
int loopCount = LightCount; | |
OPENINGSC | |
{ | |
loopCount = 1; | |
} | |
for(int i = 0; i < loopCount; i++) | |
{ | |
vec3 lightCol, lightDir; | |
float lightLen, la; | |
apporximateLight(lightCol, lightDir, lightLen, la, ro, i); | |
if(la == 0.0) | |
{ | |
continue; | |
} | |
vec3 diffShadow = vec3(1.0); | |
OPENINGSC | |
{ | |
vec3 rd = lightDir, rp; | |
float len = 0.0, dist = 0.0; | |
int k; | |
for(k = 0; k < LoopMax / 2; k++) | |
{ | |
rp = ro + rd * len; | |
dist = sdf(rp); | |
len += dist; | |
if(dist < DistMin || len > LenMax || len > lightLen) | |
{ | |
break; | |
} | |
} | |
float shelter = lightLen - len; | |
diffShadow = shelter < shadowThresh ? vec3(1.0) : vec3(0.1); | |
} | |
lightCol *= diffShadow; | |
la *= (diffShadow.x + diffShadow.y + diffShadow.z) / 3.0; | |
float ndotl = clamp(dot(normal, lightDir), 0.1, 1.0); | |
vec3 diffCol = infoOrigin.color * ndotl * (1.0 - clamp(infoOrigin.metalic, 0.0, 1.0)) * lightCol; | |
vec3 specCol = pow(clamp(dot(reflect(lightDir, normal), rdOrigin), 0., 1.), 64.0) * (1.0 - infoOrigin.roughness) * lightCol; | |
diffCol = clamp(diffCol, 0.0, 1.0); | |
specCol = clamp(specCol, 0.0, 1.0); | |
mixCol += diffCol + specCol; | |
mixLa += la * laFactor; | |
} | |
mixCol = clamp(mixCol, 0.0, 1.0); | |
mixLa = clamp(mixLa, 0.0, laMax); | |
} | |
// Reflection | |
void calcReflectionCol(out vec3 reflCol, float roughness, vec3 rd0, vec3 rp0, vec3 normal, float fakeEmission, float seed) | |
{ | |
vec3 t, b; | |
tangentSpaceBasis(normal, t, b); | |
vec3 rp1, lrd1, hd1, rd1, ro1; | |
float len1 = 0.0, dist, roughnessfx = roughnessFix(roughness); | |
MatInfo info1 = MatInfo(); | |
ro1 = rp0 + normal * NormalEPS * 50.0; | |
lrd1 = reflSample(hash23(vec3(seed, 0, LocalTime)), roughnessfx); | |
hd1 = localToWorld(lrd1, t, normal, b); | |
rd1 = reflect(rd0, hd1); | |
for(int j = 0; j < LoopMax / 2; j++) | |
{ | |
rp1 = ro1 + rd1 * len1; | |
dist = sdf(rp1); | |
len1 += dist; | |
if(dist < DistMin || len1 > LenMax) | |
{ | |
break; | |
} | |
} | |
info1 = getMatInfo(rp1); | |
float nfactor = 8.0 * PI / (roughnessfx + 8.0); | |
reflCol = (1.0 - info1.metalic) * (info1.emission + 1.0) * fakeEmission * info1.color * nfactor * 4.0 * dot(hd1, rd1); | |
reflCol = clamp(reflCol, 0.0, 1.0); | |
} | |
//Render------------------------------------------------------------------- | |
vec3 mainTracer(vec3 rd0, vec3 rp0, in float seed) | |
{ | |
MatInfo info0 = getMatInfo(rp0); | |
vec3 normal = normal(rp0); | |
// reflection | |
const float fakeEmission = 20.0; | |
vec3 reflCol = vec3(0.0); | |
if(info0.roughness < 0.99) | |
{ | |
calcReflectionCol(reflCol, info0.roughness, rd0, rp0, normal, fakeEmission, seed); | |
} | |
// diffuse&shadow | |
vec3 mixCol = vec3(0.0); | |
float mixLa = 1.0; | |
calcMixColAndShadow(mixCol, mixLa, rp0, rd0, normal, info0); | |
// result | |
vec3 sumCol = (info0.emission >= 1.0 ? 1.0 : info0.emission) * info0.color + reflCol * mixLa + mixCol; | |
return sumCol; | |
} | |
// vec3 subTracer(vec3 ro0, vec3 rd0, vec3 rp0, in float len0, in MatInfo info0, in float seed, bool isShadow) | |
// { | |
// vec3 normal = normal(rp0); | |
// // diffuse&shadow | |
// vec3 mixCol = vec3(0.0); | |
// float mixLa = 0.0; | |
// calcMixColAndShadow(mixCol, mixLa, rp0, rd0, normal, info0, isShadow); | |
// // result | |
// vec3 sumCol = (info0.emission >= 1.0 ? 1.0 : info0.emission) * info0.color + mixCol; | |
// return clamp(sumCol, 0.0, 1.0); | |
// } | |
// dist,iswater | |
float _stWater(vec3 p) | |
{ | |
float d = LenMax; | |
float a = 0.01; | |
float y = remap(sin(LocalTime * 0.25), -1.0, 1.0, -1.5, 1.5); | |
y = -6.0; | |
POORSC | |
{ | |
y = mix(-0.6, 0.6, T); | |
} | |
float n = (2.0 * snoise(vec3(p.xz * 2.0, LocalTime)) - 1.0) * a; | |
y += n; | |
d = min(d, p.y - y); | |
return d; | |
} | |
vec3 _waterNormal(vec3 p) | |
{ | |
const float h = NormalEPS; | |
const vec2 k = vec2(1, -1); | |
return normalize(k.xyy * _stWater(p + k.xyy * h) + k.yyx * _stWater(p + k.yyx * h) + k.yxy * _stWater(p + k.yxy * h) + k.xxx * _stWater(p + k.xxx * h)); | |
} | |
// Intersect | |
void calcIntersectPool(out vec3 rp0, out float len0, vec3 rd0, vec3 ro0) | |
{ | |
int i; | |
float dist = 0.0; | |
len0 = 0.0; | |
for(i = 0; i < LoopMax / 2; i++) | |
{ | |
rp0 = ro0 + rd0 * len0; | |
dist = _stWater(rp0); | |
len0 += dist; | |
if(dist < DistMin || len0 > LenMax) | |
{ | |
break; | |
} | |
} | |
} | |
float fresnel(float f0, float u) | |
{ | |
return clamp(f0 + (1.0 - f0) * pow(1.0 - u, 5.0), 0.0, 1.0); | |
} | |
vec3 superTracer(vec3 ro, vec3 rd, in float seed) | |
{ | |
vec3 resCol = vec3(0); | |
vec3 rporigin; | |
float lenorigin; | |
calcIntersect(rporigin, lenorigin, rd, ro); | |
resCol = mainTracer(rd, rporigin, seed); | |
if(_stWater(rporigin) > 0.0) | |
{ | |
// intersect other | |
return resCol; | |
} | |
vec3 rp; | |
float len; | |
calcIntersectPool(rp, len, rd, ro); | |
vec3 normal = _waterNormal(rp); | |
vec3 reflCol = vec3(0.4), refrCol = vec3(0); | |
float vdotn = max(0.0, dot(-rd, normal)); | |
float fresnel = fresnel(0.02, vdotn); | |
float len1 = lenorigin - len; | |
refrCol = resCol; | |
vec3 waterBaseCol = vec3(0.35, 0.1, 0.15); | |
const float density = 1.0, falloff = 0.5; | |
float fog = clamp(exp(-(len1 - falloff) * density), 0.0, 1.0); | |
refrCol = refrCol * mix(waterBaseCol, vec3(1.0), fog); | |
return mix(refrCol, reflCol, fresnel); | |
} | |
void setParameters(vec2 coord) | |
{ | |
#define LOOP_TIME 160.0 | |
#define TIME_OFFSET 0.0 | |
SCID[0] = 0.0; | |
SCID[1] = 20.0; | |
SCID[2] = 20.5; | |
SCID[3] = 35.0; | |
SCID[4] = 35.5; | |
SCID[5] = 50.0; | |
SCID[6] = 51.0; | |
SCID[7] = 53.0; | |
SCID[8] = 54.0; | |
SCID[9] = 70.0; | |
SCID[10] = 70.5; | |
SCID[11] = 85.0; | |
SCID[12] = 85.5; | |
SCID[13] = 105.0; | |
SCID[14] = 105.5; | |
SCID[15] = 125.0; | |
SCID[16] = 125.5; | |
SCID[17] = 150.0; | |
SCID[18] = 155.0; | |
SCID[19] = 160.0; | |
LocalTime = iTime + TIME_OFFSET; | |
ABSLocalTime = iTime + TIME_OFFSET; | |
LocalTime += (hash12(hash23(vec3(LocalTime, coord)))) * 0.005; | |
LocalTime = mod(LocalTime, LOOP_TIME); | |
ABSLocalTime = mod(ABSLocalTime, LOOP_TIME); | |
// LocalTime = ABSLocalTime = 70.0; | |
} | |
void getUVandSeed(out vec2 uv, out vec2 suv, out float seed, inout vec2 fragCoord) | |
{ | |
// CRT | |
uv = fragCoord / iResolution.xy; | |
POORSC | |
{ | |
uv.x += uv.y < 0.01 ? (0.01 - uv.y) * 2.0 + noise11(ABSLocalTime * 50.0) * 0.05 : (hash11(floor(uv.y * 128.0 + hash11(mod(ABSLocalTime, hash11(floor(ABSLocalTime + 42.0)) * 4.0)) * 42.0)) - 0.5) * 0.0025; | |
} | |
fragCoord = uv * iResolution.xy; | |
vec2 taa = hash23(vec3(LocalTime, fragCoord)) - 0.5; | |
seed = hash12(taa * 42.0 - 0.42) * 42.0; | |
suv = (2.0 * (fragCoord + taa) - iResolution.xy) / min(iResolution.x, iResolution.y); | |
} | |
void getRORD(out vec3 ro, out vec3 rd, vec2 suv) | |
{ | |
// Parameter | |
// #define CONTROLL_CAMERA | |
float fov = 90.0; | |
float fisheye = 0.0; | |
vec3 dir = vec3(0); | |
vec3 tebrue = (pattern(vec3(ABSLocalTime * 0.03, ABSLocalTime * 0.03 + 42.42, ABSLocalTime * 0.03 - 42.42)) - 0.5) * 0.07; | |
// CAMERA Sequence | |
SCI01(1) | |
{ | |
float LT = pow(T, 0.5); | |
// dir | |
setCatmull(0, vec3(-.98387, -.17546, -.03472)); | |
setCatmull(1, vec3(-.88153, -.11387, .45818)); | |
setCatmull(2, vec3(-.8165, -.06842, .57326)); | |
setCatmull(3, vec3(-.76864, -.32789, .54924)); | |
setCatmull(4, vec3(-.43677, -.53729, .72147)); | |
dir = normalize(getCatmull(5, LT)); | |
// ro | |
setCatmull(0, vec3(6.9117, .6681, -2.5893)); | |
setCatmull(1, vec3(6.9117, .6681, -5.0495)); | |
setCatmull(2, vec3(.7727, .9317, -4.8827)); | |
setCatmull(3, vec3(-3.6579, 3.2047, -3.5855)); | |
setCatmull(4, vec3(-5.5876, 3.1361, -2.239)); | |
ro = getCatmull(5, LT); | |
} | |
else SCI01(2) | |
{ | |
dir = vec3(-.43677, -.53729, .72147); | |
ro = vec3(-5.5876, 3.1361, -2.239); | |
} | |
else SCI01(3) | |
{ | |
float LT = T; | |
fov = 110.0; | |
// dir | |
setCatmull(0, vec3(.38601, .00619, -.92247)); | |
setCatmull(1, vec3(-.93411, -.08463, -.3468)); | |
setCatmull(2, vec3(-.8165, -.06842, .57326)); | |
setCatmull(3, vec3(-.88438, .12164, .45061)); | |
dir = normalize(getCatmull(4, LT)); | |
// ro | |
setCatmull(0, vec3(-7.7526, 1.7481, -.656)); | |
setCatmull(1, vec3(-6.2829, 1.7481, -1.1716)); | |
setCatmull(2, vec3(-6.2829, 1.7481, -1.9093)); | |
setCatmull(3, vec3(-5.3722, 1.5269, -4.4661)); | |
ro = getCatmull(4, LT); | |
} | |
else SCI01(4) | |
{ | |
fov = 110.0; | |
dir = vec3(-.88438, .12164, .45061); | |
ro = vec3(-5.3722, 1.5269, -4.4661); | |
} | |
else SCI01(5) | |
{ | |
float LT = T; | |
fov = mix(110.0, 80.0, LT); | |
dir = mix(vec3(-.99341, -.11422, .00932), vec3(-.97075, -.23973, -.01275), LT); | |
ro = mix(vec3(-5.7884, 1.9151, -1.9602), vec3(-7.1226, 1.9617, -1.9573), LT); | |
} | |
else SCI01(9) | |
{ | |
float LT = T; | |
fov = 100.0; | |
fisheye = 0.5; | |
// dir | |
setCatmull(0, vec3(.46515, -.61874, .63307)); | |
setCatmull(1, vec3(-.19055, -.50834, .8398)); | |
setCatmull(2, vec3(-.68175, -.72116, .123)); | |
dir = normalize(getCatmull(3, LT)); | |
// ro | |
setCatmull(0, vec3(1.6878, 3.6381, -5.4813)); | |
setCatmull(1, vec3(1.6878, 3.6381, -5.4813)); | |
setCatmull(2, vec3(1.6878, 3.6381, -5.4813)); | |
ro = getCatmull(3, LT); | |
tebrue *= 0.0; | |
} | |
else SCI01(11) | |
{ | |
float LT = T; | |
fov = 100.0; | |
fisheye = 0.5; | |
// dir | |
setCatmull(0, vec3(-.07618, -.31368, .94646)); | |
setCatmull(1, vec3(-.99302, .10023, .06211)); | |
setCatmull(2, vec3(-.26109, -.52743, -.80847)); | |
dir = normalize(getCatmull(3, LT)); | |
// ro | |
setCatmull(0, vec3(1.0689, .1884, 2.0751)); | |
setCatmull(1, vec3(1.0689, .1884, 2.0751)); | |
setCatmull(2, vec3(1.0689, .1884, 2.0751)); | |
ro = getCatmull(3, LT); | |
tebrue *= 0.0; | |
} | |
else SCI01(13) | |
{ | |
float LT = T; | |
// dir | |
setCatmull(0, vec3(-.96212, -.13568, .23644)); | |
setCatmull(1, vec3(.07011, -.184113, -.98039)); | |
setCatmull(2, vec3(.75603, -.50064, -.42162)); | |
setCatmull(3, vec3(-.05268, -.75428, -.65442)); | |
dir = normalize(getCatmull(4, LT)); | |
// ro | |
setCatmull(0, vec3(-6.76, .9662, -2.9276)); | |
setCatmull(1, vec3(-5.578, .9662, -2.9276)); | |
setCatmull(2, vec3(-.841, 1.2763, -1.5016)); | |
setCatmull(3, vec3(1.6679, 2.2187, -1.1792)); | |
ro = getCatmull(4, LT); | |
} | |
else SCI01(15) | |
{ | |
float LT = T; | |
fov = 130.0; | |
fisheye = 0.5; | |
// dir | |
setCatmull(0, vec3(.0103, -.92302, .3846)); | |
setCatmull(1, vec3(-.6002, -.7992, .03217)); | |
setCatmull(2, vec3(-.02958, -.74839, -.66259)); | |
setCatmull(3, vec3(.5756, -.81758, -.01541)); | |
dir = normalize(getCatmull(4, LT)); | |
// ro | |
setCatmull(0, vec3(-3.1782, 3.1775, -1.7176)); | |
setCatmull(1, vec3(-3.1782, 3.1775, -1.7176)); | |
setCatmull(2, vec3(-3.1782, 3.1775, -1.7176)); | |
setCatmull(3, vec3(-3.1782, 3.1775, -1.7176)); | |
ro = getCatmull(4, LT); | |
tebrue *= 0.0; | |
} | |
else SCI01(17) | |
{ | |
float LT = pow(T, 0.6); | |
// dir | |
setCatmull(0, vec3(-.98387, -.17535, .03513)); | |
setCatmull(1, vec3(-.96224, -.09579, -.25476)); | |
setCatmull(2, vec3(-.92195, -.13568, -.36274)); | |
setCatmull(3, vec3(-.9816, -.11798, -.15008)); | |
setCatmull(4, vec3(-.98534, -.16216, .05281)); | |
setCatmull(5, vec3(-.96596, -.2581, .01724)); | |
setCatmull(6, vec3(-.97057, -.24081, .0)); | |
dir = normalize(getCatmull(7, LT)); | |
// ro | |
setCatmull(0, vec3(6.1963, 1.0471, 4.8724)); | |
setCatmull(1, vec3(2.9209, 1.0471, 4.8724)); | |
setCatmull(2, vec3(-.13, 1.0471, 3.5894)); | |
setCatmull(3, vec3(-2.5181, 1.6534, -0.3591)); | |
setCatmull(4, vec3(-4.7409, 1.6534, -1.9903)); | |
setCatmull(5, vec3(-6.4135, 1.9834, -1.9903)); | |
setCatmull(6, vec3(-7.2869, 1.9834, -1.9903)); | |
ro = getCatmull(7, LT); | |
tebrue *= mix(1.0, 0.0, LT); | |
} | |
#ifdef CONTROLL_CAMERA | |
ro = vec3(-7.7526, 1.7481, -.656) + GetCameraPosition(); | |
vec2 mouse = 180.0 * (2.0 * iMouse.xy - iResolution.xy) / min(iResolution.x, iResolution.y); | |
dir = vec3(0.0, 0.0, 1.0); | |
dir.yz = rot2d(dir.yz, -mouse.y * 0.5); | |
dir.xz = rot2d(dir.xz, -mouse.x); | |
dir = normalize(dir); | |
fov = 90.0 + GetAlpha(); | |
#else | |
ro += tebrue; | |
#endif | |
float cr = 0.0; | |
vec3 cw = normalize(dir); | |
vec3 cp = vec3(sin(cr), cos(cr), 0.0); | |
vec3 cu = normalize(cross(cw, cp)); | |
vec3 cv = normalize(cross(cu, cw)); | |
float zf = 1.0 / tan(fov * PI / 360.0); | |
zf -= zf * length(suv) * fisheye; | |
rd = normalize(-cu * suv.x + cv * suv.y + cw * zf); | |
} | |
void postprocess1(inout vec3 sCol, vec2 uv) | |
{ | |
// RGB Motion Blur | |
float backstr = 0.5, srcstr = 0.5; | |
vec3 bs; | |
POORSC | |
{ | |
float no = remapc(snoise(vec3(uv.y * 42.0, LocalTime, 0.0)), 0.0, 1.0, 0.5, 1.0); | |
float off = 0.005 * no; | |
bs = vec3(BackBuffer(uv + vec2(off, 0)).r, BackBuffer(uv).g, BackBuffer(uv - vec2(off, 0)).b); | |
} | |
else OPENINGSC | |
{ | |
backstr = 0.8; | |
srcstr = 0.4; | |
const float gc = 5.0; | |
float gs = 0.0; | |
bs = vec3(0); | |
int blur = 2; | |
for(int x = -blur; x <= blur; x++) | |
{ | |
for(int y = -blur; y <= blur; y++) | |
{ | |
vec2 cd = vec2(x, y); | |
float l = length(cd); | |
float g = exp(-l * l / (2.0 * gc * gc)); | |
bs += g * BackBuffer(uv + cd / iResolution.xy).rgb; | |
gs += g; | |
} | |
} | |
bs /= gs; | |
} | |
else | |
{ | |
bs = BackBuffer(uv).rgb; | |
} | |
sCol = clamp(bs * backstr + sCol * srcstr, 0.0, 1.0); | |
} | |
// https://www.shadertoy.com/view/7tK3zW | |
vec3 liftGammaGain(vec3 rgb, vec4 LIFT, vec4 GAMMA, vec4 GAIN, vec3 LUMA) | |
{ | |
vec4 liftt = 1.0 - pow(1.0 - LIFT, log2(GAIN + 1.0)); | |
vec4 gammat = GAMMA.rgba - vec4(0.0, 0.0, 0.0, dot(LUMA, GAMMA.rgb)); | |
vec4 gammatTemp = 1.0 + 4.0 * abs(gammat); | |
gammat = mix(gammatTemp, 1.0 / gammatTemp, step(0.0, gammat)); | |
vec3 col = rgb; | |
float luma = dot(LUMA, col); | |
col = pow(col, gammat.rgb); | |
col *= pow(GAIN.rgb, gammat.rgb); | |
col = max(mix(2.0 * liftt.rgb, vec3(1.0), col), 0.0); | |
luma = pow(luma, gammat.a); | |
luma *= pow(GAIN.a, gammat.a); | |
luma = max(mix(2.0 * liftt.a, 1.0, luma), 0.0); | |
col += luma - dot(LUMA, col); | |
return col; | |
} | |
void postprocess0(inout vec3 sCol, vec2 uv, float seed) | |
{ | |
OPENINGSC | |
{ | |
sCol = clamp(pow(sCol + vec3(0.0, 0.0, 0.0), vec3(0.7)), 0.0, 1.0); | |
} | |
// ColorGrading | |
vec4 lift = vec4(-0.03, -0.01, 0.03, 0.0); | |
vec4 gamma = vec4(0.03, -0.01, -0.03, 0.0); | |
vec4 gain = vec4(1.02, 1.01, 1.02, 1.0); | |
vec3 luma = vec3(0.2126, 0.7152, 0.0722); | |
sCol = clamp(liftGammaGain(sCol, lift, gamma, gain, luma), 0.0, 1.0); | |
SCI01(18) | |
{ | |
sCol = vec3(hash11(seed), hash11(seed + 42.), hash11(seed + 420.42)) * 0.5; | |
} | |
POORSC | |
{ | |
// CRT | |
sCol *= mix(1.0, mix(0.7, 1.0, hash11(seed)), pow(noise11(uv.y * 10.0 + LocalTime * 3.0), 5.0)); | |
// Vinette | |
sCol *= 1.0 - 0.3 * pow(remapc(length(uv - 0.5), 0.0, 0.5, 0.0, 1.0), 3.0); | |
} | |
sCol = clamp(sCol, 0.0, 1.0); | |
} | |
float uitext(vec2 uv) | |
{ | |
float col = 0.0; | |
vec2 leftup = vec2(0, res.y); | |
vec2 leftdown = vec2(0); | |
vec2 rightup = res; | |
// Play | |
print_pos = floor(leftup + vec2(STRWIDTH(4.0), -STRHEIGHT(3.0))); | |
col += char(ch_P, uv); | |
col += char(ch_L, uv); | |
col += char(ch_A, uv); | |
col += char(ch_Y, uv); | |
// REC | |
print_pos = floor(leftup + vec2(STRWIDTH(4.0), -STRHEIGHT(4.5))); | |
col += char(ch_R, uv); | |
col += char(ch_E, uv); | |
col += char(ch_C, uv); | |
// DATE | |
print_pos = floor(leftdown + vec2(STRWIDTH(4.0), STRHEIGHT(2.0))); | |
col += char(ch_A, uv); | |
col += char(ch_P, uv); | |
col += char(ch_R, uv); | |
col += char(ch_per, uv); | |
col += char(ch_spc, uv); | |
col += print_integer(29., 2, uv); | |
col += char(ch_spc, uv); | |
col += print_integer(4., 2, uv); | |
col += char(ch_spc, uv); | |
col += print_integer(2023., 4, uv); | |
// TIME | |
float t = ABSLocalTime; | |
float hour = floor(t / 60.0 / 60.0); | |
float minute = floor(mod(t / 60.0, 60.0)); | |
float sec = floor(mod(t, 60.0)); | |
print_pos = floor(rightup - vec2(STRWIDTH(12.0), STRHEIGHT(4.5))); | |
col += print_integer(hour, 2, uv); | |
col += char(ch_col, uv); | |
col += print_integer(minute, 2, uv); | |
col += char(ch_col, uv); | |
col += print_integer(sec, 2, uv); | |
return clamp(col, 0.0, 1.0); | |
} | |
float uishape0(vec2 uv) | |
{ | |
vec2 leftup = vec2(0, res.y); | |
vec2 anc = floor(leftup + vec2(STRWIDTH(9.0), -STRHEIGHT(3.0))); | |
vec2 luv = remap(uv - anc, vec2(0), vec2(STRWIDTH(1.0), STRHEIGHT(1.0)), vec2(0), vec2(1)); | |
float col = 1.0; | |
col *= float(luv.x > 0.0); | |
col *= float(luv.y < -0.5 * luv.x + 1.0); | |
col *= float(luv.y > 0.5 * luv.x); | |
return col; | |
} | |
float uishape1(vec2 uv) | |
{ | |
vec2 leftup = vec2(0, res.y); | |
vec2 anc = floor(leftup + vec2(STRWIDTH(8.0), -STRHEIGHT(4.5))); | |
vec2 luv = remap(uv - anc, vec2(0), vec2(STRWIDTH(1.0), STRHEIGHT(1.0)), vec2(0), vec2(1)); | |
luv -= 0.5; | |
luv.y /= STRWIDTH(1.0) / STRHEIGHT(1.0); | |
return float(length(luv) < 0.5) * float(mod(ABSLocalTime + .24, 2.0) < 1.0); | |
} | |
#define BATTERY_TIME 100.0 | |
float uishape2(vec2 uv) | |
{ | |
vec2 rightup = res; | |
vec2 anc = floor(rightup - vec2(STRWIDTH(8.0), STRHEIGHT(3.0))); | |
vec2 luv = remap(uv - anc, vec2(0), vec2(STRWIDTH(4.0), STRHEIGHT(1.0)), vec2(0), vec2(1)); | |
float col = 1.0; | |
luv.y = (luv.y - 0.5) * (1.0 + float(luv.x < 0.1)) + 0.5; | |
float fx = 12. / 32., lx = 0.9 - 0.2 * fx, eps = 0.03; | |
float ti = float(mod(ABSLocalTime + .42, 2.0) < 1.0); | |
int lt = 0; | |
POORSC | |
{ | |
lt = int(floor(4.0 - T * 4.0)); | |
} | |
col *= float(luv.x > 0.0 && luv.x < 1.0 && luv.y > 0.0 && luv.y < 1.0); | |
col *= float(!(luv.x > 0.1 + 0.1 * fx && luv.x < 1.0 - 0.1 * fx && luv.y > 0.1 && luv.y < 0.9)); | |
luv = (luv - 0.5) * 1.05 + 0.5; | |
col += float(luv.x > 0.1 + 0.1 * fx + lx * 3. / 4. + eps && luv.x < 1.0 - 0.1 * fx && luv.y > 0.1 && luv.y < 0.9) * (lt < 0 ? 0.0 : lt == 0 ? ti : 1.0); | |
col += float(luv.x > 0.1 + 0.1 * fx + lx * 2. / 4. + eps && luv.x < 0.1 + 0.1 * fx + lx * 3. / 4. && luv.y > 0.1 && luv.y < 0.9) * (lt < 1 ? 0.0 : lt == 1 ? ti : 1.0); | |
col += float(luv.x > 0.1 + 0.1 * fx + lx * 1. / 4. + eps && luv.x < 0.1 + 0.1 * fx + lx * 2. / 4. && luv.y > 0.1 && luv.y < 0.9) * (lt < 2 ? 0.0 : lt == 2 ? ti : 1.0); | |
col += float(luv.x > 0.1 + 0.1 * fx && luv.x < 0.1 + 0.1 * fx + lx * 1. / 4. && luv.y > 0.1 && luv.y < 0.9) * (lt < 3 ? 0.0 : lt == 3 ? ti : 1.0); | |
return col; | |
} | |
#define GLITCH float n = floor(noise11(uv.x * 20.0) * 5.0+1.0) / 6.0;vec2 off = vec2(0, n) * 0.2;sCol = BackBuffer(uv + off).rgb | |
void overlay(inout vec3 sCol, vec2 uv, vec2 coord) | |
{ | |
// Overlay | |
POORSC | |
{ | |
float alpha = 1.0; | |
SCI01(8) | |
{ | |
alpha = mix(0.0, 1.0, T); | |
} | |
float ds = 3.0; | |
res = iResolution.xy / ds; | |
float pix = uitext(coord / ds) + uishape0(coord / ds); | |
sCol = mix(sCol, vec3(1), clamp(pix, 0.0, 1.0) * alpha); | |
pix = uishape1(coord / ds); | |
sCol = mix(sCol, vec3(1, 0, 0), clamp(pix, 0.0, 1.0) * alpha); | |
pix = uishape2(coord / ds); | |
sCol = mix(sCol, vec3(1), clamp(pix, 0.0, 1.0) * alpha); | |
} | |
// Glitch | |
SCI01(2) | |
{ | |
GLITCH; | |
} | |
else SCI01(4) | |
{ | |
GLITCH; | |
} | |
else SCI01(6) | |
{ | |
GLITCH; | |
} | |
else SCI01(7) | |
{ | |
sCol = vec3(0); | |
} | |
else SCI01(10) | |
{ | |
GLITCH; | |
} | |
else SCI01(12) | |
{ | |
GLITCH; | |
} | |
else SCI01(14) | |
{ | |
GLITCH; | |
} | |
else SCI01(16) | |
{ | |
GLITCH; | |
} | |
else SCI01(18) | |
{ | |
print_pos = floor(iResolution.xy * 0.5 * 0.1 + vec2(-STRWIDTH(2.0), -STRHEIGHT(0.5))); | |
sCol = mix(sCol, vec3(1), char(ch_P, coord * 0.1)); | |
sCol = mix(sCol, vec3(1), char(ch_O, coord * 0.1)); | |
sCol = mix(sCol, vec3(1), char(ch_O, coord * 0.1)); | |
sCol = mix(sCol, vec3(1), char(ch_L, coord * 0.1)); | |
} | |
else SCI01(19) | |
{ | |
sCol = vec3(0); | |
} | |
sCol = clamp(sCol, 0.0, 1.0); | |
} | |
void main() | |
{ | |
vec2 fragCoord = gl_FragCoord.xy; | |
setParameters(fragCoord); | |
// Get UV and Seed | |
float seed; | |
vec2 uv, suv; | |
getUVandSeed(uv, suv, seed, fragCoord); | |
// Camera | |
vec3 ro, rd; | |
getRORD(ro, rd, suv); | |
// Render | |
vec3 sCol = superTracer(ro, rd, seed); | |
// PostProcess | |
postprocess0(sCol, uv, seed); | |
postprocess1(sCol, uv); | |
// OverLay | |
overlay(sCol, uv, fragCoord); | |
// Output | |
outColor = vec4(sCol, 1.0); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment