id
stringlengths
6
6
author
stringclasses
55 values
date
timestamp[ns]
image_code
stringlengths
746
52.3k
license
stringclasses
7 values
func_bytes
sequencelengths
5
5
functions
sequencelengths
1
32
comment
stringlengths
7
1.29k
header
stringlengths
18
169
body
stringlengths
18
2.14k
model_inp
stringlengths
30
1.35k
function_frequency
int64
1
176
header_frequency
int64
1
16.3k
sl3XRn
iq
2021-12-04T00:18:43
// The MIT License // Copyright © 2021 Inigo Quilez // Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. // Intersecting two line segments. float cro( in vec2 a, in vec2 b ) { return a.x*b.y - a.y*b.x; } bool intersect( vec2 a1, vec2 b1, vec2 a2, vec2 b2, out vec2 point ) { float d = cro(b2-a2,b1-a1); float s = cro(a1-a2,b1-a1) / d; float t = cro(a1-a2,b2-a2) / d; point = a1 + (b1-a1)*t; // or point = a2 + (b2-a2)*s; return s>=0.0 && t>=0.0 && t<=1.0 && s<=1.0; } /* // same math as above, alternative writing by mla (see comments) bool intersect( vec2 a1, vec2 b1, vec2 a2, vec2 b2, out vec2 point ) { vec2 st = inverse(mat2(b1-a1,a2-b2))*(a2-a1); point = a1 + (b1-a1)*st.x; return s>=0.0 && t>=0.0 && t<=1.0 && s<=1.0; // alternative range test with single comparison // st = abs(st-0.5); return max(st.x,st.y)<0.5; } */ // https://iquilezles.org/www/articles/distfunctions2d/distfunctions2d.htm float sdLine( in vec2 p, in vec2 a, in vec2 b) { vec2 pa = p-a, ba = b-a; float h = clamp(dot(pa,ba)/(dot(ba,ba)),0.0, 1.0); return length(pa-ba*h); } // https://iquilezles.org/www/articles/distfunctions2d/distfunctions2d.htm float sdDisk( in vec2 p, in vec2 c, in float r ) { return length(p-c)-r; } void mainImage( out vec4 fragColor, in vec2 fragCoord ) { // animate vec2 a1 = vec2(-2.0+vec2(1.5,1.0)*sin(iTime*1.1+vec2(0.0,0.5))); vec2 b1 = vec2( 2.0+vec2(1.5,1.0)*sin(iTime*1.2+vec2(5.0,2.0))); vec2 a2 = vec2(-2.0+vec2(1.5,1.0)*sin(iTime*1.3+vec2(3.0,1.0))); vec2 b2 = vec2( 2.0+vec2(1.5,1.0)*sin(iTime*1.4+vec2(1.5,4.5))); // NDC coords vec2 p = (2.0*fragCoord-iResolution.xy)/iResolution.y; // background vec3 col = vec3(0.15) - 0.04*length(p); p *= 3.5; // segment 1 { float d = sdLine(p,a1,b1)-0.02; d = min( d, sdDisk(p,a1,0.06) ); d = min( d, sdDisk(p,b1,0.06) ); col = mix(col, vec3(0.0,0.7,0.7), smoothstep(0.01,0.0,d) ); } // segment 2 { float d = sdLine(p,a2,b2)-0.02; d = min( d, sdDisk(p,a2,0.06) ); d = min( d, sdDisk(p,b2,0.06) ); col = mix(col, vec3(0.2,0.5,1.0), smoothstep(0.01,0.0,d) ); } // intersection vec2 pos; if( intersect(a1, b1, a2, b2, pos) ) { float d = sdDisk(p,pos,0.03); d = min( d, abs(d-0.2) ) - 0.01; // onion, see https://iquilezles.org/www/articles/distfunctions2d/distfunctions2d.htm col = mix(col, vec3(1.0,0.7,0.0), smoothstep(0.01,0.0,d)); } // cheap dither (color banding removal) col += (1.0/512.0)*sin(fragCoord.x*2.0+13.0*fragCoord.y); fragColor = vec4(col,1.0); }
mit
[ 2083, 2158, 2208, 2208, 2236 ]
[ [ 1114, 1114, 1149, 1149, 1177 ], [ 1179, 1179, 1249, 1249, 1462 ], [ 1844, 1919, 1967, 1967, 2081 ], [ 2083, 2158, 2208, 2208, 2236 ], [ 2238, 2238, 2295, 2310, 3645 ] ]
// https://iquilezles.org/www/articles/distfunctions2d/distfunctions2d.htm
float sdDisk( in vec2 p, in vec2 c, in float r ) {
return length(p-c)-r; }
// https://iquilezles.org/www/articles/distfunctions2d/distfunctions2d.htm float sdDisk( in vec2 p, in vec2 c, in float r ) {
2
2
fslyWN
iq
2022-01-13T20:22:00
// The MIT License // Copyright © 2022 Inigo Quilez // Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. // Distance to a logarithmic spiral. It's inexact, mostly // noticeable when the number of rotations is small. // List of some other 2D distances: https://www.shadertoy.com/playlist/MXdSRf // // and iquilezles.org/articles/distfunctions2d // w is the width / distance from center to tip // k is the number of rotations float sdSpiral( in vec2 p, float w, in float k ) { // body const float kTau = 6.283185307; float r = length(p); float a = atan(p.y,p.x); float n = floor( 0.5/w + (log2(r/w)*k-a)/kTau ); float ra = w*exp2((a+kTau*(min(n+0.0,0.0)-0.5))/k); float rb = w*exp2((a+kTau*(min(n+1.0,0.0)-0.5))/k); float d = min( abs(r-ra), abs(r-rb) ); // tip return min( d, length(p+vec2(w,0.0)) ); } void mainImage( out vec4 fragColor, in vec2 fragCoord ) { // normalized pixel coordinates vec2 p = (2.0*fragCoord-iResolution.xy)/iResolution.y; vec2 m = (2.0*iMouse.xy-iResolution.xy)/iResolution.y; float px = 2.0/iResolution.y; // recenter p -= vec2(0.2,-0.09); m -= vec2(0.2,-0.09); // animation float sw = 1.0; float sk = 1.0 + 10.0*(0.5-0.5*cos(iTime+1.5)); // distance float d = sdSpiral(p, sw, sk); // coloring vec3 col = (d>0.0) ? vec3(0.9,0.6,0.3) : vec3(0.65,0.85,1.0); col *= 1.0 - exp(-7.0*abs(d)); col *= 0.8 + 0.2*cos(160.0*abs(d)); col = mix( col, vec3(1.0), 1.0-smoothstep(-px,px,abs(d)-0.005) ); if( iMouse.z>0.001 ) { d = sdSpiral(m, sw, sk); col = mix(col, vec3(1.0,1.0,0.0), 1.0-smoothstep(-px, px, abs(length(p-m)-abs(d))-0.005)); col = mix(col, vec3(1.0,1.0,0.0), 1.0-smoothstep(-px, px, length(p-m)-0.015)); } fragColor = vec4(col, 1.0); }
mit
[ 1321, 1401, 1451, 1463, 1819 ]
[ [ 1321, 1401, 1451, 1463, 1819 ], [ 1821, 1821, 1878, 1914, 2798 ] ]
// w is the width / distance from center to tip // k is the number of rotations
float sdSpiral( in vec2 p, float w, in float k ) {
const float kTau = 6.283185307; float r = length(p); float a = atan(p.y,p.x); float n = floor( 0.5/w + (log2(r/w)*k-a)/kTau ); float ra = w*exp2((a+kTau*(min(n+0.0,0.0)-0.5))/k); float rb = w*exp2((a+kTau*(min(n+1.0,0.0)-0.5))/k); float d = min( abs(r-ra), abs(r-rb) ); // tip return min( d, length(p+vec2(w,0.0)) ); }
// w is the width / distance from center to tip // k is the number of rotations float sdSpiral( in vec2 p, float w, in float k ) {
1
1
fsXcRN
ForestCSharp
2022-01-09T21:20:20
// Copyright (c) 2021 Felix Westin // // Permission is hereby granted, free of charge, to any person obtaining // a copy of this software and associated documentation files (the // "Software"), to deal in the Software without restriction, including // without limitation the rights to use, copy, modify, merge, publish, // distribute, sublicense, and/or sell copies of the Software, and to // permit persons to whom the Software is furnished to do so, subject to // the following conditions: // // The above copyright notice and this permission notice shall be // included in all copies or substantial portions of the Software. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. // ------------------------------------- // Defines #define EPS 1e-6 #define PI 3.14159265359 #define INFINITY 1.0 / 0.0 #define PLANET_RADIUS 6371000.0 #define PLANET_CENTER vec3(0, -PLANET_RADIUS, 0) #define ATMOSPHERE_HEIGHT 100000.0 #define RAYLEIGH_HEIGHT (ATMOSPHERE_HEIGHT * 0.08) #define MIE_HEIGHT (ATMOSPHERE_HEIGHT * 0.012) // ------------------------------------- // Coefficients #define C_RAYLEIGH (vec3(5.802, 13.558, 33.100) * 1e-6) #define C_MIE (vec3(3.996, 3.996, 3.996) * 1e-6) #define C_OZONE (vec3(0.650, 1.881, 0.085) * 1e-6) #define ATMOSPHERE_DENSITY 1.0 #define EXPOSURE 20.0 // ------------------------------------- // Math vec2 SphereIntersection(vec3 rayStart, vec3 rayDir, vec3 sphereCenter, float sphereRadius) { rayStart -= sphereCenter; float a = dot(rayDir, rayDir); float b = 2.0 * dot(rayStart, rayDir); float c = dot(rayStart, rayStart) - (sphereRadius * sphereRadius); float d = b * b - 4.0 * a * c; if (d < 0.0) { return vec2(-1); } else { d = sqrt(d); return vec2(-b - d, -b + d) / (2.0 * a); } } vec2 PlanetIntersection(vec3 rayStart, vec3 rayDir) { return SphereIntersection(rayStart, rayDir, PLANET_CENTER, PLANET_RADIUS); } vec2 AtmosphereIntersection(vec3 rayStart, vec3 rayDir) { return SphereIntersection(rayStart, rayDir, PLANET_CENTER, PLANET_RADIUS + ATMOSPHERE_HEIGHT); } // ------------------------------------- // Phase functions float PhaseRayleigh(float costh) { return 3.0 * (1.0 + costh*costh) / (16.0 * PI); } float PhaseMie(float costh, float g) { g = min(g, 0.9381); float k = 1.55*g - 0.55*g*g*g; float kcosth = k*costh; return (1.0 - k*k) / ((4.0 * PI) * (1.0-kcosth) * (1.0-kcosth)); } // ------------------------------------- // Atmosphere float AtmosphereHeight(vec3 positionWS) { return distance(positionWS, PLANET_CENTER) - PLANET_RADIUS; } float DensityRayleigh(float h) { return exp(-max(0.0, h / RAYLEIGH_HEIGHT)); } float DensityMie(float h) { return exp(-max(0.0, h / MIE_HEIGHT)); } float DensityOzone(float h) { // The ozone layer is represented as a tent function with a width of 30km, centered around an altitude of 25km. return max(0.0, 1.0 - abs(h - 25000.0) / 15000.0); } vec3 AtmosphereDensity(float h) { return vec3(DensityRayleigh(h), DensityMie(h), DensityOzone(h)); } // Optical depth is a unitless measurement of the amount of absorption of a participating medium (such as the atmosphere). // This function calculates just that for our three atmospheric elements: // R: Rayleigh // G: Mie // B: Ozone // If you find the term "optical depth" confusing, you can think of it as "how much density was found along the ray in total". vec3 IntegrateOpticalDepth(vec3 rayStart, vec3 rayDir) { vec2 intersection = AtmosphereIntersection(rayStart, rayDir); float rayLength = intersection.y; int sampleCount = 8; float stepSize = rayLength / float(sampleCount); vec3 opticalDepth = vec3(0); for (int i = 0; i < sampleCount; i++) { vec3 localPosition = rayStart + rayDir * (float(i) + 0.5) * stepSize; float localHeight = AtmosphereHeight(localPosition); vec3 localDensity = AtmosphereDensity(localHeight); opticalDepth += localDensity * stepSize; } return opticalDepth; } // Calculate a luminance transmittance value from optical depth. vec3 Absorb(vec3 opticalDepth) { // Note that Mie results in slightly more light absorption than scattering, about 10% return exp(-(opticalDepth.x * C_RAYLEIGH + opticalDepth.y * C_MIE * 1.1 + opticalDepth.z * C_OZONE) * ATMOSPHERE_DENSITY); } // Integrate scattering over a ray for a single directional light source. // Also return the transmittance for the same ray as we are already calculating the optical depth anyway. vec3 IntegrateScattering(vec3 rayStart, vec3 rayDir, float rayLength, vec3 lightDir, vec3 lightColor, out vec3 transmittance) { // We can reduce the number of atmospheric samples required to converge by spacing them exponentially closer to the camera. // This breaks space view however, so let's compensate for that with an exponent that "fades" to 1 as we leave the atmosphere. float rayHeight = AtmosphereHeight(rayStart); float sampleDistributionExponent = 1.0 + clamp(1.0 - rayHeight / ATMOSPHERE_HEIGHT, 0.0, 1.0) * 8.0; // Slightly arbitrary max exponent of 9 vec2 intersection = AtmosphereIntersection(rayStart, rayDir); rayLength = min(rayLength, intersection.y); if (intersection.x > 0.0) { // Advance ray to the atmosphere entry point rayStart += rayDir * intersection.x; rayLength -= intersection.x; } float costh = dot(rayDir, lightDir); float phaseR = PhaseRayleigh(costh); float phaseM = PhaseMie(costh, 0.85 /* Default */); int sampleCount = 64; vec3 opticalDepth = vec3(0); vec3 rayleigh = vec3(0); vec3 mie = vec3(0); float prevRayTime = 0.0; for (int i = 0; i < sampleCount; i++) { float rayTime = pow(float(i) / float(sampleCount), sampleDistributionExponent) * rayLength; // Because we are distributing the samples exponentially, we have to calculate the step size per sample. float stepSize = (rayTime - prevRayTime); vec3 localPosition = rayStart + rayDir * rayTime; float localHeight = AtmosphereHeight(localPosition); vec3 localDensity = AtmosphereDensity(localHeight); opticalDepth += localDensity * stepSize; // The atmospheric transmittance from rayStart to localPosition vec3 viewTransmittance = Absorb(opticalDepth); vec3 opticalDepthlight = IntegrateOpticalDepth(localPosition, lightDir); // The atmospheric transmittance of light reaching localPosition vec3 lightTransmittance = Absorb(opticalDepthlight); rayleigh += viewTransmittance * lightTransmittance * phaseR * localDensity.x * stepSize; mie += viewTransmittance * lightTransmittance * phaseM * localDensity.y * stepSize; prevRayTime = rayTime; } transmittance = Absorb(opticalDepth); return (rayleigh * C_RAYLEIGH + mie * C_MIE) * lightColor * EXPOSURE; } void mainImage( out vec4 fragColor, in vec2 fragCoord ) { //camera position vec3 ray_start = vec3(0,0,0); vec2 mouse_vec = iMouse.xy/iResolution.xy; vec3 cam_dir = normalize(vec3(mouse_vec, 1.0)); vec3 u = normalize(cross(cam_dir, vec3(0., 1., 0.))); vec3 v = cross(u, cam_dir); float fdist = 0.3; vec3 ray_dir = normalize(cam_dir*fdist+(fragCoord.x/iResolution.x-0.5)*u+(fragCoord.y-iResolution.y/2.0)/iResolution.x*v); const float ray_length = 1000000000.0f; vec3 light_dir = vec3(0.25,1,0); vec3 light_color = vec3(1,1,1); vec3 transmittance; vec3 sky_color = IntegrateScattering(ray_start, ray_dir, ray_length, light_dir, light_color, transmittance); fragColor = vec4(sky_color,1); }
mit
[ 4459, 4524, 4556, 4643, 4769 ]
[ [ 1840, 1889, 1981, 1981, 2291 ], [ 2292, 2292, 2345, 2345, 2423 ], [ 2424, 2424, 2481, 2481, 2579 ], [ 2581, 2641, 2675, 2675, 2726 ], [ 2728, 2728, 2766, 2766, 2912 ], [ 2914, 2969, 3010, 3010, 3073 ], [ 3074, 3074, 3106, 3106, 3153 ], [ 3154, 3154, 3181, 3181, 3223 ], [ 3224, 3224, 3253, 3366, 3420 ], [ 3421, 3421, 3454, 3454, 3522 ], [ 4459, 4524, 4556, 4643, 4769 ], [ 4771, 4951, 5078, 5331, 7210 ], [ 7213, 7213, 7270, 7296, 7980 ] ]
// Calculate a luminance transmittance value from optical depth.
vec3 Absorb(vec3 opticalDepth) {
return exp(-(opticalDepth.x * C_RAYLEIGH + opticalDepth.y * C_MIE * 1.1 + opticalDepth.z * C_OZONE) * ATMOSPHERE_DENSITY); }
// Calculate a luminance transmittance value from optical depth. vec3 Absorb(vec3 opticalDepth) {
1
2
fsXcRN
ForestCSharp
2022-01-09T21:20:20
// Copyright (c) 2021 Felix Westin // // Permission is hereby granted, free of charge, to any person obtaining // a copy of this software and associated documentation files (the // "Software"), to deal in the Software without restriction, including // without limitation the rights to use, copy, modify, merge, publish, // distribute, sublicense, and/or sell copies of the Software, and to // permit persons to whom the Software is furnished to do so, subject to // the following conditions: // // The above copyright notice and this permission notice shall be // included in all copies or substantial portions of the Software. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. // ------------------------------------- // Defines #define EPS 1e-6 #define PI 3.14159265359 #define INFINITY 1.0 / 0.0 #define PLANET_RADIUS 6371000.0 #define PLANET_CENTER vec3(0, -PLANET_RADIUS, 0) #define ATMOSPHERE_HEIGHT 100000.0 #define RAYLEIGH_HEIGHT (ATMOSPHERE_HEIGHT * 0.08) #define MIE_HEIGHT (ATMOSPHERE_HEIGHT * 0.012) // ------------------------------------- // Coefficients #define C_RAYLEIGH (vec3(5.802, 13.558, 33.100) * 1e-6) #define C_MIE (vec3(3.996, 3.996, 3.996) * 1e-6) #define C_OZONE (vec3(0.650, 1.881, 0.085) * 1e-6) #define ATMOSPHERE_DENSITY 1.0 #define EXPOSURE 20.0 // ------------------------------------- // Math vec2 SphereIntersection(vec3 rayStart, vec3 rayDir, vec3 sphereCenter, float sphereRadius) { rayStart -= sphereCenter; float a = dot(rayDir, rayDir); float b = 2.0 * dot(rayStart, rayDir); float c = dot(rayStart, rayStart) - (sphereRadius * sphereRadius); float d = b * b - 4.0 * a * c; if (d < 0.0) { return vec2(-1); } else { d = sqrt(d); return vec2(-b - d, -b + d) / (2.0 * a); } } vec2 PlanetIntersection(vec3 rayStart, vec3 rayDir) { return SphereIntersection(rayStart, rayDir, PLANET_CENTER, PLANET_RADIUS); } vec2 AtmosphereIntersection(vec3 rayStart, vec3 rayDir) { return SphereIntersection(rayStart, rayDir, PLANET_CENTER, PLANET_RADIUS + ATMOSPHERE_HEIGHT); } // ------------------------------------- // Phase functions float PhaseRayleigh(float costh) { return 3.0 * (1.0 + costh*costh) / (16.0 * PI); } float PhaseMie(float costh, float g) { g = min(g, 0.9381); float k = 1.55*g - 0.55*g*g*g; float kcosth = k*costh; return (1.0 - k*k) / ((4.0 * PI) * (1.0-kcosth) * (1.0-kcosth)); } // ------------------------------------- // Atmosphere float AtmosphereHeight(vec3 positionWS) { return distance(positionWS, PLANET_CENTER) - PLANET_RADIUS; } float DensityRayleigh(float h) { return exp(-max(0.0, h / RAYLEIGH_HEIGHT)); } float DensityMie(float h) { return exp(-max(0.0, h / MIE_HEIGHT)); } float DensityOzone(float h) { // The ozone layer is represented as a tent function with a width of 30km, centered around an altitude of 25km. return max(0.0, 1.0 - abs(h - 25000.0) / 15000.0); } vec3 AtmosphereDensity(float h) { return vec3(DensityRayleigh(h), DensityMie(h), DensityOzone(h)); } // Optical depth is a unitless measurement of the amount of absorption of a participating medium (such as the atmosphere). // This function calculates just that for our three atmospheric elements: // R: Rayleigh // G: Mie // B: Ozone // If you find the term "optical depth" confusing, you can think of it as "how much density was found along the ray in total". vec3 IntegrateOpticalDepth(vec3 rayStart, vec3 rayDir) { vec2 intersection = AtmosphereIntersection(rayStart, rayDir); float rayLength = intersection.y; int sampleCount = 8; float stepSize = rayLength / float(sampleCount); vec3 opticalDepth = vec3(0); for (int i = 0; i < sampleCount; i++) { vec3 localPosition = rayStart + rayDir * (float(i) + 0.5) * stepSize; float localHeight = AtmosphereHeight(localPosition); vec3 localDensity = AtmosphereDensity(localHeight); opticalDepth += localDensity * stepSize; } return opticalDepth; } // Calculate a luminance transmittance value from optical depth. vec3 Absorb(vec3 opticalDepth) { // Note that Mie results in slightly more light absorption than scattering, about 10% return exp(-(opticalDepth.x * C_RAYLEIGH + opticalDepth.y * C_MIE * 1.1 + opticalDepth.z * C_OZONE) * ATMOSPHERE_DENSITY); } // Integrate scattering over a ray for a single directional light source. // Also return the transmittance for the same ray as we are already calculating the optical depth anyway. vec3 IntegrateScattering(vec3 rayStart, vec3 rayDir, float rayLength, vec3 lightDir, vec3 lightColor, out vec3 transmittance) { // We can reduce the number of atmospheric samples required to converge by spacing them exponentially closer to the camera. // This breaks space view however, so let's compensate for that with an exponent that "fades" to 1 as we leave the atmosphere. float rayHeight = AtmosphereHeight(rayStart); float sampleDistributionExponent = 1.0 + clamp(1.0 - rayHeight / ATMOSPHERE_HEIGHT, 0.0, 1.0) * 8.0; // Slightly arbitrary max exponent of 9 vec2 intersection = AtmosphereIntersection(rayStart, rayDir); rayLength = min(rayLength, intersection.y); if (intersection.x > 0.0) { // Advance ray to the atmosphere entry point rayStart += rayDir * intersection.x; rayLength -= intersection.x; } float costh = dot(rayDir, lightDir); float phaseR = PhaseRayleigh(costh); float phaseM = PhaseMie(costh, 0.85 /* Default */); int sampleCount = 64; vec3 opticalDepth = vec3(0); vec3 rayleigh = vec3(0); vec3 mie = vec3(0); float prevRayTime = 0.0; for (int i = 0; i < sampleCount; i++) { float rayTime = pow(float(i) / float(sampleCount), sampleDistributionExponent) * rayLength; // Because we are distributing the samples exponentially, we have to calculate the step size per sample. float stepSize = (rayTime - prevRayTime); vec3 localPosition = rayStart + rayDir * rayTime; float localHeight = AtmosphereHeight(localPosition); vec3 localDensity = AtmosphereDensity(localHeight); opticalDepth += localDensity * stepSize; // The atmospheric transmittance from rayStart to localPosition vec3 viewTransmittance = Absorb(opticalDepth); vec3 opticalDepthlight = IntegrateOpticalDepth(localPosition, lightDir); // The atmospheric transmittance of light reaching localPosition vec3 lightTransmittance = Absorb(opticalDepthlight); rayleigh += viewTransmittance * lightTransmittance * phaseR * localDensity.x * stepSize; mie += viewTransmittance * lightTransmittance * phaseM * localDensity.y * stepSize; prevRayTime = rayTime; } transmittance = Absorb(opticalDepth); return (rayleigh * C_RAYLEIGH + mie * C_MIE) * lightColor * EXPOSURE; } void mainImage( out vec4 fragColor, in vec2 fragCoord ) { //camera position vec3 ray_start = vec3(0,0,0); vec2 mouse_vec = iMouse.xy/iResolution.xy; vec3 cam_dir = normalize(vec3(mouse_vec, 1.0)); vec3 u = normalize(cross(cam_dir, vec3(0., 1., 0.))); vec3 v = cross(u, cam_dir); float fdist = 0.3; vec3 ray_dir = normalize(cam_dir*fdist+(fragCoord.x/iResolution.x-0.5)*u+(fragCoord.y-iResolution.y/2.0)/iResolution.x*v); const float ray_length = 1000000000.0f; vec3 light_dir = vec3(0.25,1,0); vec3 light_color = vec3(1,1,1); vec3 transmittance; vec3 sky_color = IntegrateScattering(ray_start, ray_dir, ray_length, light_dir, light_color, transmittance); fragColor = vec4(sky_color,1); }
mit
[ 4771, 4951, 5078, 5331, 7210 ]
[ [ 1840, 1889, 1981, 1981, 2291 ], [ 2292, 2292, 2345, 2345, 2423 ], [ 2424, 2424, 2481, 2481, 2579 ], [ 2581, 2641, 2675, 2675, 2726 ], [ 2728, 2728, 2766, 2766, 2912 ], [ 2914, 2969, 3010, 3010, 3073 ], [ 3074, 3074, 3106, 3106, 3153 ], [ 3154, 3154, 3181, 3181, 3223 ], [ 3224, 3224, 3253, 3366, 3420 ], [ 3421, 3421, 3454, 3454, 3522 ], [ 4459, 4524, 4556, 4643, 4769 ], [ 4771, 4951, 5078, 5331, 7210 ], [ 7213, 7213, 7270, 7296, 7980 ] ]
// Integrate scattering over a ray for a single directional light source. // Also return the transmittance for the same ray as we are already calculating the optical depth anyway.
vec3 IntegrateScattering(vec3 rayStart, vec3 rayDir, float rayLength, vec3 lightDir, vec3 lightColor, out vec3 transmittance) {
float rayHeight = AtmosphereHeight(rayStart); float sampleDistributionExponent = 1.0 + clamp(1.0 - rayHeight / ATMOSPHERE_HEIGHT, 0.0, 1.0) * 8.0; // Slightly arbitrary max exponent of 9 vec2 intersection = AtmosphereIntersection(rayStart, rayDir); rayLength = min(rayLength, intersection.y); if (intersection.x > 0.0) { // Advance ray to the atmosphere entry point rayStart += rayDir * intersection.x; rayLength -= intersection.x; } float costh = dot(rayDir, lightDir); float phaseR = PhaseRayleigh(costh); float phaseM = PhaseMie(costh, 0.85 /* Default */); int sampleCount = 64; vec3 opticalDepth = vec3(0); vec3 rayleigh = vec3(0); vec3 mie = vec3(0); float prevRayTime = 0.0; for (int i = 0; i < sampleCount; i++) { float rayTime = pow(float(i) / float(sampleCount), sampleDistributionExponent) * rayLength; // Because we are distributing the samples exponentially, we have to calculate the step size per sample. float stepSize = (rayTime - prevRayTime); vec3 localPosition = rayStart + rayDir * rayTime; float localHeight = AtmosphereHeight(localPosition); vec3 localDensity = AtmosphereDensity(localHeight); opticalDepth += localDensity * stepSize; // The atmospheric transmittance from rayStart to localPosition vec3 viewTransmittance = Absorb(opticalDepth); vec3 opticalDepthlight = IntegrateOpticalDepth(localPosition, lightDir); // The atmospheric transmittance of light reaching localPosition vec3 lightTransmittance = Absorb(opticalDepthlight); rayleigh += viewTransmittance * lightTransmittance * phaseR * localDensity.x * stepSize; mie += viewTransmittance * lightTransmittance * phaseM * localDensity.y * stepSize; prevRayTime = rayTime; } transmittance = Absorb(opticalDepth); return (rayleigh * C_RAYLEIGH + mie * C_MIE) * lightColor * EXPOSURE; }
// Integrate scattering over a ray for a single directional light source. // Also return the transmittance for the same ray as we are already calculating the optical depth anyway. vec3 IntegrateScattering(vec3 rayStart, vec3 rayDir, float rayLength, vec3 lightDir, vec3 lightColor, out vec3 transmittance) {
1
2
fsXcz4
bjornornorn
2022-01-09T19:43:30
// Copyright(c) 2022 Björn Ottosson // // Permission is hereby granted, free of charge, to any person obtaining a copy of // this softwareand associated documentation files(the "Software"), to deal in // the Software without restriction, including without limitation the rights to // use, copy, modify, merge, publish, distribute, sublicense, and /or sell copies // of the Software, and to permit persons to whom the Software is furnished to do // so, subject to the following conditions : // The above copyright noticeand this permission notice shall be included in all // copies or substantial portions of the Software. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // SOFTWARE. const float softness_scale = 0.2; // controls softness of RGB clipping const float offset = 0.75; // controls how colors desaturate as they brighten. 0 results in that colors never fluoresce, 1 in very saturated colors const float chroma_scale = 1.2; // overall scale of chroma const mat3 rec2020toSrgb = mat3( 1.6603034854, -0.5875701425, -0.0728900602, -0.1243755953, 1.1328344814, -0.0083597372, -0.0181122800, -0.1005836085, 1.1187703262); const mat3 displayP3toSrgb = mat3( 1.2248021163, -0.2249112615, -0.0000475721, -0.0419281049, 1.0420298967, -0.0000026429, -0.0196088092, -0.0786321233, 1.0983153702); const mat3 SrgbToSrgb = mat3( 1.0,0.0,0.0, 0.0,1.0,0.0, 0.0,0.0,1.0); const mat3 sourceColorSpaceToSrgb = SrgbToSrgb; // change for different input color space // Origin: https://knarkowicz.wordpress.com/2016/01/06/aces-filmic-tone-mapping-curve/ // Using this since it was easy to differentiate, same technique would work for any curve vec3 s_curve(vec3 x) { float a = 2.51f; float b = 0.03f; float c = 2.43f; float d = 0.59f; float e = 0.14f; x = max(x, 0.0); return clamp((x*(a*x+b))/(x*(c*x+d)+e),0.0,1.0); } // derivative of s-curve vec3 d_s_curve(vec3 x) { float a = 2.51f; float b = 0.03f; float c = 2.43f; float d = 0.59f; float e = 0.14f; x = max(x, 0.0); vec3 r = (x*(c*x + d) + e); return (a*x*(d*x + 2.0*e) + b*(e - c*x*x))/(r*r); } vec3 tonemap_per_channel(vec3 c) { return s_curve(c); } vec2 findCenterAndPurity(vec3 x) { // Matrix derived for (c_smooth+s_smooth) to be an approximation of the macadam limit // this makes it some kind of g0-like estimate mat3 M = mat3( 2.26775149, -1.43293879, 0.1651873, -0.98535505, 2.1260072, -0.14065215, -0.02501605, -0.26349465, 1.2885107); x = x*M; float x_min = min(x.r,min(x.g,x.b)); float x_max = max(x.r,max(x.g,x.b)); float c = 0.5*(x_max+x_min); float s = (x_max-x_min); // math trickery to create values close to c and s, but without producing hard edges vec3 y = (x-c)/s; float c_smooth = c + dot(y*y*y, vec3(1.0/3.0))*s; float s_smooth = sqrt(dot(x-c_smooth,x-c_smooth)/2.0); return vec2(c_smooth, s_smooth); } vec3 toLms(vec3 c) { mat3 rgbToLms = mat3( 0.4122214708, 0.5363325363, 0.0514459929, 0.2119034982, 0.6806995451, 0.1073969566, 0.0883024619, 0.2817188376, 0.6299787005); vec3 lms_ = c*rgbToLms; return sign(lms_)*pow(abs(lms_), vec3(1.0/3.0)); } float calculateC(vec3 lms) { // Most of this could be precomputed // Creating a transform that maps R,G,B in the target gamut to have same distance from grey axis vec3 lmsR = toLms(vec3(1.0,0.0,0.0)); vec3 lmsG = toLms(vec3(0.0,1.0,0.0)); vec3 lmsB = toLms(vec3(0.0,0.0,1.0)); vec3 uDir = (lmsR - lmsG)/sqrt(2.0); vec3 vDir = (lmsR + lmsG - 2.0*lmsB)/sqrt(6.0); mat3 to_uv = inverse(mat3( 1.0, uDir.x, vDir.x, 1.0, uDir.y, vDir.y, 1.0, uDir.z, vDir.z )); vec3 _uv = lms * to_uv; return sqrt(_uv.y*_uv.y + _uv.z*_uv.z); float a = 1.9779984951f*lms.x - 2.4285922050f*lms.y + 0.4505937099f*lms.z; float b = 0.0259040371f*lms.x + 0.7827717662f*lms.y - 0.8086757660f*lms.z; return sqrt(a*a + b*b); } vec2 calculateMC(vec3 c) { vec3 lms = toLms(c); float M = findCenterAndPurity(lms).x; return vec2(M, calculateC(lms)); } vec2 expandShape(vec3 rgb, vec2 ST) { vec2 MC = calculateMC(rgb); vec2 STnew = vec2((MC.x)/MC.y, (1.0-MC.x)/MC.y); STnew = (STnew + 3.0*STnew*STnew*MC.y); return vec2(min(ST.x, STnew.x), min(ST.y, STnew.y)); } float expandScale(vec3 rgb, vec2 ST, float scale) { vec2 MC = calculateMC(rgb); float Cnew = (1.0/((ST.x/(MC.x)) + (ST.y/(1.0-MC.x)))); return max(MC.y/Cnew, scale); } vec2 approximateShape() { float m = -softness_scale*0.2; float s = 1.0 + (softness_scale*0.2+softness_scale*0.8); vec2 ST = vec2(1000.0,1000.0); ST = expandShape(m+s*vec3(1.0,0.0,0.0), ST); ST = expandShape(m+s*vec3(1.0,1.0,0.0), ST); ST = expandShape(m+s*vec3(0.0,1.0,0.0), ST); ST = expandShape(m+s*vec3(0.0,1.0,1.0), ST); ST = expandShape(m+s*vec3(0.0,0.0,1.0), ST); ST = expandShape(m+s*vec3(1.0,0.0,1.0), ST); float scale = 0.0; scale = expandScale(m+s*vec3(1.0,0.0,0.0), ST, scale); scale = expandScale(m+s*vec3(1.0,1.0,0.0), ST, scale); scale = expandScale(m+s*vec3(0.0,1.0,0.0), ST, scale); scale = expandScale(m+s*vec3(0.0,1.0,1.0), ST, scale); scale = expandScale(m+s*vec3(0.0,0.0,1.0), ST, scale); scale = expandScale(m+s*vec3(1.0,0.0,1.0), ST, scale); return ST/scale; } vec3 tonemap_hue_preserving(vec3 c) { mat3 toLms = mat3( 0.4122214708, 0.5363325363, 0.0514459929, 0.2119034982, 0.6806995451, 0.1073969566, 0.0883024619, 0.2817188376, 0.6299787005); mat3 fromLms = mat3( +4.0767416621f , -3.3077115913, +0.2309699292, -1.2684380046f , +2.6097574011, -0.3413193965, -0.0041960863f , -0.7034186147, +1.7076147010); vec3 lms_ = c*toLms; vec3 lms = sign(lms_)*pow(abs(lms_), vec3(1.0/3.0)); vec2 MP = findCenterAndPurity(lms); // apply tone curve // Approach 1: scale chroma based on derivative of chrome curve if (true) { float I = (MP.x+(1.0-offset)*MP.y); // Remove comment to see what the results are with Oklab L //I = dot(lms, vec3(0.2104542553f, 0.7936177850f, - 0.0040720468f)); lms = lms*I*I; I = I*I*I; vec3 dLms = lms - I; float Icurve = s_curve(vec3(I)).x; lms = 1.0f + chroma_scale*dLms*d_s_curve(vec3(I))/Icurve; I = pow(Icurve, 1.0/3.0); lms = lms*I; } // Approach 2: Separate color into a whiteness/blackness part, apply scale to them independendtly if (false) { lms = chroma_scale*(lms - MP.x) + MP.x; float invBlackness = (MP.x+MP.y); float whiteness = (MP.x-MP.y); float invBlacknessC = pow(s_curve(vec3(invBlackness*invBlackness*invBlackness)).x, 1.0/3.0); float whitenessC = pow(s_curve(vec3(whiteness*whiteness*whiteness)).x, 1.0/3.0); lms = (invBlacknessC+whitenessC)/2.0 + (lms-(invBlackness+whiteness)/2.0)*(invBlacknessC-whitenessC)/(invBlackness-whiteness); } // compress to a smooth approximation of the target gamut { float M = findCenterAndPurity(lms).x; vec2 ST = approximateShape(); // this can be precomputed, only depends on RGB gamut float C_smooth_gamut = (1.0)/((ST.x/(M)) + (ST.y/(1.0-M))); float C = calculateC(lms); lms = (lms-M)/sqrt(C*C/C_smooth_gamut/C_smooth_gamut+1.0) + M; } vec3 rgb = lms*lms*lms*fromLms; return rgb; } vec3 softSaturate(vec3 x, vec3 a) { a = clamp(a, 0.0,softness_scale); a = 1.0+a; x = min(x, a); vec3 b = (a-1.0)*sqrt(a/(2.0-a)); return 1.0 - (sqrt((x-a)*(x-a) + b*b) - b)/(sqrt(a*a+b*b)-b); } vec3 softClipColor(vec3 color) { // soft clip of rgb values to avoid artifacts of hard clipping // causes hues distortions, but is a smooth mapping // not quite sure this mapping is easy to invert, but should be possible to construct similar ones that do float grey = 0.2; vec3 x = color-grey; vec3 xsgn = sign(x); vec3 xscale = 0.5 + xsgn*(0.5-grey); x /= xscale; float maxRGB = max(color.r, max(color.g, color.b)); float minRGB = min(color.r, min(color.g, color.b)); float softness_0 = maxRGB/(1.0+softness_scale)*softness_scale; float softness_1 = (1.0-minRGB)/(1.0+softness_scale)*softness_scale; vec3 softness = vec3(0.5)*(softness_0+softness_1 + xsgn*(softness_1 - softness_0)); return grey + xscale*xsgn*softSaturate(abs(x), softness); } void mainImage( out vec4 fragColor, in vec2 fragCoord ) { vec2 uv = 2.0*(fragCoord-0.5*iResolution.xy)/min(iResolution.x, iResolution.y); vec3 color; const int N = 8; float time = 0.125*iTime; for (int i = 0; i <= N; i++) { for (int j = 0; j <= i; j++) { float fi = float(i)/float(N); float fj = float(j)/float(N); float x = 1.5*(fi-0.5*fj-0.5); float y = 1.5*sqrt(3.0)/2.0*(fj-0.5); vec2 xyd = vec2(x,y)-uv; float d = min(0.0006/dot(xyd,xyd),1.0); vec3 c = vec3(fi-fj, fj, 1.0-fi); c = c*sourceColorSpaceToSrgb; color += pow(2.0,-3.0*cos(2.0*3.14159*time))*d*c; } } color = tonemap_hue_preserving(color); color = softClipColor(color); //color = tonemap_per_channel(color); // highlight colors that clip if any float diff = length(color - clamp(color, 0., 1.)); if(diff != 0.) color = vec3(0.5,0.5,0.5); // Output to screen fragColor = vec4(pow(color,vec3(1.0/2.2)),1.0); }
mit
[ 1927, 2105, 2127, 2127, 2308 ]
[ [ 1927, 2105, 2127, 2127, 2308 ], [ 2310, 2335, 2359, 2359, 2578 ], [ 2580, 2580, 2614, 2614, 2639 ], [ 2641, 2641, 2675, 2816, 3409 ], [ 3411, 3411, 3431, 3431, 3692 ], [ 3694, 3694, 3722, 3864, 4483 ], [ 4485, 4485, 4511, 4511, 4628 ], [ 4630, 4630, 4667, 4667, 4860 ], [ 4862, 4862, 4913, 4913, 5042 ], [ 5044, 5044, 5069, 5069, 5909 ], [ 5911, 5911, 5948, 5948, 8095 ], [ 8097, 8097, 8132, 8132, 8310 ], [ 8312, 8312, 8344, 8578, 9137 ], [ 9139, 9139, 9196, 9196, 10327 ] ]
// Origin: https://knarkowicz.wordpress.com/2016/01/06/aces-filmic-tone-mapping-curve/ // Using this since it was easy to differentiate, same technique would work for any curve
vec3 s_curve(vec3 x) {
float a = 2.51f; float b = 0.03f; float c = 2.43f; float d = 0.59f; float e = 0.14f; x = max(x, 0.0); return clamp((x*(a*x+b))/(x*(c*x+d)+e),0.0,1.0); }
// Origin: https://knarkowicz.wordpress.com/2016/01/06/aces-filmic-tone-mapping-curve/ // Using this since it was easy to differentiate, same technique would work for any curve vec3 s_curve(vec3 x) {
2
2
fsXcz4
bjornornorn
2022-01-09T19:43:30
// Copyright(c) 2022 Björn Ottosson // // Permission is hereby granted, free of charge, to any person obtaining a copy of // this softwareand associated documentation files(the "Software"), to deal in // the Software without restriction, including without limitation the rights to // use, copy, modify, merge, publish, distribute, sublicense, and /or sell copies // of the Software, and to permit persons to whom the Software is furnished to do // so, subject to the following conditions : // The above copyright noticeand this permission notice shall be included in all // copies or substantial portions of the Software. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // SOFTWARE. const float softness_scale = 0.2; // controls softness of RGB clipping const float offset = 0.75; // controls how colors desaturate as they brighten. 0 results in that colors never fluoresce, 1 in very saturated colors const float chroma_scale = 1.2; // overall scale of chroma const mat3 rec2020toSrgb = mat3( 1.6603034854, -0.5875701425, -0.0728900602, -0.1243755953, 1.1328344814, -0.0083597372, -0.0181122800, -0.1005836085, 1.1187703262); const mat3 displayP3toSrgb = mat3( 1.2248021163, -0.2249112615, -0.0000475721, -0.0419281049, 1.0420298967, -0.0000026429, -0.0196088092, -0.0786321233, 1.0983153702); const mat3 SrgbToSrgb = mat3( 1.0,0.0,0.0, 0.0,1.0,0.0, 0.0,0.0,1.0); const mat3 sourceColorSpaceToSrgb = SrgbToSrgb; // change for different input color space // Origin: https://knarkowicz.wordpress.com/2016/01/06/aces-filmic-tone-mapping-curve/ // Using this since it was easy to differentiate, same technique would work for any curve vec3 s_curve(vec3 x) { float a = 2.51f; float b = 0.03f; float c = 2.43f; float d = 0.59f; float e = 0.14f; x = max(x, 0.0); return clamp((x*(a*x+b))/(x*(c*x+d)+e),0.0,1.0); } // derivative of s-curve vec3 d_s_curve(vec3 x) { float a = 2.51f; float b = 0.03f; float c = 2.43f; float d = 0.59f; float e = 0.14f; x = max(x, 0.0); vec3 r = (x*(c*x + d) + e); return (a*x*(d*x + 2.0*e) + b*(e - c*x*x))/(r*r); } vec3 tonemap_per_channel(vec3 c) { return s_curve(c); } vec2 findCenterAndPurity(vec3 x) { // Matrix derived for (c_smooth+s_smooth) to be an approximation of the macadam limit // this makes it some kind of g0-like estimate mat3 M = mat3( 2.26775149, -1.43293879, 0.1651873, -0.98535505, 2.1260072, -0.14065215, -0.02501605, -0.26349465, 1.2885107); x = x*M; float x_min = min(x.r,min(x.g,x.b)); float x_max = max(x.r,max(x.g,x.b)); float c = 0.5*(x_max+x_min); float s = (x_max-x_min); // math trickery to create values close to c and s, but without producing hard edges vec3 y = (x-c)/s; float c_smooth = c + dot(y*y*y, vec3(1.0/3.0))*s; float s_smooth = sqrt(dot(x-c_smooth,x-c_smooth)/2.0); return vec2(c_smooth, s_smooth); } vec3 toLms(vec3 c) { mat3 rgbToLms = mat3( 0.4122214708, 0.5363325363, 0.0514459929, 0.2119034982, 0.6806995451, 0.1073969566, 0.0883024619, 0.2817188376, 0.6299787005); vec3 lms_ = c*rgbToLms; return sign(lms_)*pow(abs(lms_), vec3(1.0/3.0)); } float calculateC(vec3 lms) { // Most of this could be precomputed // Creating a transform that maps R,G,B in the target gamut to have same distance from grey axis vec3 lmsR = toLms(vec3(1.0,0.0,0.0)); vec3 lmsG = toLms(vec3(0.0,1.0,0.0)); vec3 lmsB = toLms(vec3(0.0,0.0,1.0)); vec3 uDir = (lmsR - lmsG)/sqrt(2.0); vec3 vDir = (lmsR + lmsG - 2.0*lmsB)/sqrt(6.0); mat3 to_uv = inverse(mat3( 1.0, uDir.x, vDir.x, 1.0, uDir.y, vDir.y, 1.0, uDir.z, vDir.z )); vec3 _uv = lms * to_uv; return sqrt(_uv.y*_uv.y + _uv.z*_uv.z); float a = 1.9779984951f*lms.x - 2.4285922050f*lms.y + 0.4505937099f*lms.z; float b = 0.0259040371f*lms.x + 0.7827717662f*lms.y - 0.8086757660f*lms.z; return sqrt(a*a + b*b); } vec2 calculateMC(vec3 c) { vec3 lms = toLms(c); float M = findCenterAndPurity(lms).x; return vec2(M, calculateC(lms)); } vec2 expandShape(vec3 rgb, vec2 ST) { vec2 MC = calculateMC(rgb); vec2 STnew = vec2((MC.x)/MC.y, (1.0-MC.x)/MC.y); STnew = (STnew + 3.0*STnew*STnew*MC.y); return vec2(min(ST.x, STnew.x), min(ST.y, STnew.y)); } float expandScale(vec3 rgb, vec2 ST, float scale) { vec2 MC = calculateMC(rgb); float Cnew = (1.0/((ST.x/(MC.x)) + (ST.y/(1.0-MC.x)))); return max(MC.y/Cnew, scale); } vec2 approximateShape() { float m = -softness_scale*0.2; float s = 1.0 + (softness_scale*0.2+softness_scale*0.8); vec2 ST = vec2(1000.0,1000.0); ST = expandShape(m+s*vec3(1.0,0.0,0.0), ST); ST = expandShape(m+s*vec3(1.0,1.0,0.0), ST); ST = expandShape(m+s*vec3(0.0,1.0,0.0), ST); ST = expandShape(m+s*vec3(0.0,1.0,1.0), ST); ST = expandShape(m+s*vec3(0.0,0.0,1.0), ST); ST = expandShape(m+s*vec3(1.0,0.0,1.0), ST); float scale = 0.0; scale = expandScale(m+s*vec3(1.0,0.0,0.0), ST, scale); scale = expandScale(m+s*vec3(1.0,1.0,0.0), ST, scale); scale = expandScale(m+s*vec3(0.0,1.0,0.0), ST, scale); scale = expandScale(m+s*vec3(0.0,1.0,1.0), ST, scale); scale = expandScale(m+s*vec3(0.0,0.0,1.0), ST, scale); scale = expandScale(m+s*vec3(1.0,0.0,1.0), ST, scale); return ST/scale; } vec3 tonemap_hue_preserving(vec3 c) { mat3 toLms = mat3( 0.4122214708, 0.5363325363, 0.0514459929, 0.2119034982, 0.6806995451, 0.1073969566, 0.0883024619, 0.2817188376, 0.6299787005); mat3 fromLms = mat3( +4.0767416621f , -3.3077115913, +0.2309699292, -1.2684380046f , +2.6097574011, -0.3413193965, -0.0041960863f , -0.7034186147, +1.7076147010); vec3 lms_ = c*toLms; vec3 lms = sign(lms_)*pow(abs(lms_), vec3(1.0/3.0)); vec2 MP = findCenterAndPurity(lms); // apply tone curve // Approach 1: scale chroma based on derivative of chrome curve if (true) { float I = (MP.x+(1.0-offset)*MP.y); // Remove comment to see what the results are with Oklab L //I = dot(lms, vec3(0.2104542553f, 0.7936177850f, - 0.0040720468f)); lms = lms*I*I; I = I*I*I; vec3 dLms = lms - I; float Icurve = s_curve(vec3(I)).x; lms = 1.0f + chroma_scale*dLms*d_s_curve(vec3(I))/Icurve; I = pow(Icurve, 1.0/3.0); lms = lms*I; } // Approach 2: Separate color into a whiteness/blackness part, apply scale to them independendtly if (false) { lms = chroma_scale*(lms - MP.x) + MP.x; float invBlackness = (MP.x+MP.y); float whiteness = (MP.x-MP.y); float invBlacknessC = pow(s_curve(vec3(invBlackness*invBlackness*invBlackness)).x, 1.0/3.0); float whitenessC = pow(s_curve(vec3(whiteness*whiteness*whiteness)).x, 1.0/3.0); lms = (invBlacknessC+whitenessC)/2.0 + (lms-(invBlackness+whiteness)/2.0)*(invBlacknessC-whitenessC)/(invBlackness-whiteness); } // compress to a smooth approximation of the target gamut { float M = findCenterAndPurity(lms).x; vec2 ST = approximateShape(); // this can be precomputed, only depends on RGB gamut float C_smooth_gamut = (1.0)/((ST.x/(M)) + (ST.y/(1.0-M))); float C = calculateC(lms); lms = (lms-M)/sqrt(C*C/C_smooth_gamut/C_smooth_gamut+1.0) + M; } vec3 rgb = lms*lms*lms*fromLms; return rgb; } vec3 softSaturate(vec3 x, vec3 a) { a = clamp(a, 0.0,softness_scale); a = 1.0+a; x = min(x, a); vec3 b = (a-1.0)*sqrt(a/(2.0-a)); return 1.0 - (sqrt((x-a)*(x-a) + b*b) - b)/(sqrt(a*a+b*b)-b); } vec3 softClipColor(vec3 color) { // soft clip of rgb values to avoid artifacts of hard clipping // causes hues distortions, but is a smooth mapping // not quite sure this mapping is easy to invert, but should be possible to construct similar ones that do float grey = 0.2; vec3 x = color-grey; vec3 xsgn = sign(x); vec3 xscale = 0.5 + xsgn*(0.5-grey); x /= xscale; float maxRGB = max(color.r, max(color.g, color.b)); float minRGB = min(color.r, min(color.g, color.b)); float softness_0 = maxRGB/(1.0+softness_scale)*softness_scale; float softness_1 = (1.0-minRGB)/(1.0+softness_scale)*softness_scale; vec3 softness = vec3(0.5)*(softness_0+softness_1 + xsgn*(softness_1 - softness_0)); return grey + xscale*xsgn*softSaturate(abs(x), softness); } void mainImage( out vec4 fragColor, in vec2 fragCoord ) { vec2 uv = 2.0*(fragCoord-0.5*iResolution.xy)/min(iResolution.x, iResolution.y); vec3 color; const int N = 8; float time = 0.125*iTime; for (int i = 0; i <= N; i++) { for (int j = 0; j <= i; j++) { float fi = float(i)/float(N); float fj = float(j)/float(N); float x = 1.5*(fi-0.5*fj-0.5); float y = 1.5*sqrt(3.0)/2.0*(fj-0.5); vec2 xyd = vec2(x,y)-uv; float d = min(0.0006/dot(xyd,xyd),1.0); vec3 c = vec3(fi-fj, fj, 1.0-fi); c = c*sourceColorSpaceToSrgb; color += pow(2.0,-3.0*cos(2.0*3.14159*time))*d*c; } } color = tonemap_hue_preserving(color); color = softClipColor(color); //color = tonemap_per_channel(color); // highlight colors that clip if any float diff = length(color - clamp(color, 0., 1.)); if(diff != 0.) color = vec3(0.5,0.5,0.5); // Output to screen fragColor = vec4(pow(color,vec3(1.0/2.2)),1.0); }
mit
[ 2310, 2335, 2359, 2359, 2578 ]
[ [ 1927, 2105, 2127, 2127, 2308 ], [ 2310, 2335, 2359, 2359, 2578 ], [ 2580, 2580, 2614, 2614, 2639 ], [ 2641, 2641, 2675, 2816, 3409 ], [ 3411, 3411, 3431, 3431, 3692 ], [ 3694, 3694, 3722, 3864, 4483 ], [ 4485, 4485, 4511, 4511, 4628 ], [ 4630, 4630, 4667, 4667, 4860 ], [ 4862, 4862, 4913, 4913, 5042 ], [ 5044, 5044, 5069, 5069, 5909 ], [ 5911, 5911, 5948, 5948, 8095 ], [ 8097, 8097, 8132, 8132, 8310 ], [ 8312, 8312, 8344, 8578, 9137 ], [ 9139, 9139, 9196, 9196, 10327 ] ]
// derivative of s-curve
vec3 d_s_curve(vec3 x) {
float a = 2.51f; float b = 0.03f; float c = 2.43f; float d = 0.59f; float e = 0.14f; x = max(x, 0.0); vec3 r = (x*(c*x + d) + e); return (a*x*(d*x + 2.0*e) + b*(e - c*x*x))/(r*r); }
// derivative of s-curve vec3 d_s_curve(vec3 x) {
2
2
7lVXRt
iq
2022-01-03T19:29:58
// The MIT License // Copyright © 2022 Inigo Quilez // Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. // Exact distance to a sphere cut by another sphere. Note // that doing the boolean subtration of a sphere from another // sphere using max() won't produce a correct Euclidean distance // than cab be used for rounding. This shape is basically a // revolution operator (https://www.shadertoy.com/view/4lyfzw) // applied to a moon (https://www.shadertoy.com/view/WtdBRS) // List of other 3D SDFs: https://www.shadertoy.com/playlist/43cXRl // // and https://iquilezles.org/articles/distfunctions // ra = sphere's radius // rb = small sphere's radius // d = distance between the two spheres float sdDeathStar( in vec3 p2, in float ra, float rb, in float d ) { vec2 p = vec2( p2.x, length(p2.yz) ); float a = (ra*ra - rb*rb + d*d)/(2.0*d); float b = sqrt(max(ra*ra-a*a,0.0)); if( p.x*b-p.y*a > d*max(b-p.y,0.0) ) { return length(p-vec2(a,b)); } else { return max( (length(p )-ra), -(length(p-vec2(d,0))-rb)); } } float map( in vec3 pos ) { float ra = 0.5; float rb = 0.35+0.20*cos(iTime*1.1+4.0); float di = 0.50+0.15*cos(iTime*1.7); return sdDeathStar(pos, ra, rb, di ); } // https://iquilezles.org/articles/rmshadows float calcSoftshadow( in vec3 ro, in vec3 rd, float tmin, float tmax, const float k ) { float res = 1.0; float t = tmin; for( int i=0; i<64; i++ ) { float h = map( ro + rd*t ); res = min( res, k*h/t ); t += clamp( h, 0.003, 0.10 ); if( res<0.002 || t>tmax ) break; } return clamp( res, 0.0, 1.0 ); } // https://iquilezles.org/articles/normalsSDF vec3 calcNormal( in vec3 pos ) { vec2 e = vec2(1.0,-1.0)*0.5773; const float eps = 0.0005; return normalize( e.xyy*map( pos + e.xyy*eps ) + e.yyx*map( pos + e.yyx*eps ) + e.yxy*map( pos + e.yxy*eps ) + e.xxx*map( pos + e.xxx*eps ) ); } #if HW_PERFORMANCE==0 #define AA 1 #else #define AA 3 #endif void mainImage( out vec4 fragColor, in vec2 fragCoord ) { // camera movement float an = 1.0*sin(0.38*iTime+3.0); vec3 ro = vec3( 1.0*cos(an), -0.1, 1.0*sin(an) ); vec3 ta = vec3( 0.0, 0.0, 0.0 ); // camera matrix vec3 ww = normalize( ta - ro ); vec3 uu = normalize( cross(ww,vec3(0.0,1.0,0.0) ) ); vec3 vv = normalize( cross(uu,ww)); vec3 tot = vec3(0.0); #if AA>1 for( int m=0; m<AA; m++ ) for( int n=0; n<AA; n++ ) { // pixel coordinates vec2 o = vec2(float(m),float(n)) / float(AA) - 0.5; vec2 p = (2.0*(fragCoord+o)-iResolution.xy)/iResolution.y; #else vec2 p = (2.0*fragCoord-iResolution.xy)/iResolution.y; #endif // create view ray vec3 rd = normalize( p.x*uu + p.y*vv + 1.5*ww ); // raymarch const float tmax = 5.0; float t = 0.0; for( int i=0; i<256; i++ ) { vec3 pos = ro + t*rd; float h = map(pos); if( h<0.0001 || t>tmax ) break; t += h; } // shading/lighting vec3 col = vec3(0.0); if( t<tmax ) { vec3 pos = ro + t*rd; vec3 nor = calcNormal(pos); vec3 lig = vec3(0.57703); float dif = clamp( dot(nor,lig), 0.0, 1.0 ); if( dif>0.001 ) dif *= calcSoftshadow( pos+nor*0.001, lig, 0.001, 1.0, 32.0 ); float amb = 0.5 + 0.5*dot(nor,vec3(0.0,1.0,0.0)); col = vec3(0.2,0.3,0.4)*amb + vec3(0.8,0.7,0.5)*dif; } // gamma col = sqrt( col ); tot += col; #if AA>1 } tot /= float(AA*AA); #endif fragColor = vec4( tot, 1.0 ); }
mit
[ 1574, 1669, 1737, 1737, 2070 ]
[ [ 1574, 1669, 1737, 1737, 2070 ], [ 2072, 2072, 2098, 2098, 2248 ], [ 2250, 2295, 2382, 2382, 2641 ], [ 2643, 2689, 2721, 2721, 2960 ] ]
// ra = sphere's radius // rb = small sphere's radius // d = distance between the two spheres
float sdDeathStar( in vec3 p2, in float ra, float rb, in float d ) {
vec2 p = vec2( p2.x, length(p2.yz) ); float a = (ra*ra - rb*rb + d*d)/(2.0*d); float b = sqrt(max(ra*ra-a*a,0.0)); if( p.x*b-p.y*a > d*max(b-p.y,0.0) ) { return length(p-vec2(a,b)); } else { return max( (length(p )-ra), -(length(p-vec2(d,0))-rb)); } }
// ra = sphere's radius // rb = small sphere's radius // d = distance between the two spheres float sdDeathStar( in vec3 p2, in float ra, float rb, in float d ) {
1
1
7tVXRt
iq
2022-01-03T19:29:53
// The MIT License // Copyright © 2022 Inigo Quilez // Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. // Exact distance to a hollow sphere cut by a plane. Basically a // revolution operator (https://www.shadertoy.com/view/4lyfzw) // applied to a 2D arc (https://www.shadertoy.com/view/wl23RK) // List of other 3D SDFs: https://www.shadertoy.com/playlist/43cXRl // // and https://iquilezles.org/articles/distfunctions // r = sphere's radius // h = cutting's plane's position // t = thickness float sdCutHollowSphere( vec3 p, float r, float h, float t ) { vec2 q = vec2( length(p.xz), p.y ); float w = sqrt(r*r-h*h); return ((h*q.x<w*q.y) ? length(q-vec2(w,h)) : abs(length(q)-r) ) - t; } float map( in vec3 pos ) { pos.xy = (mat2(3,4,-4,3)/5.0)*pos.xy; float r = 0.5; float h = 0.2 + 0.2*cos(iTime*1.0); float t = 0.01; return sdCutHollowSphere(pos, r, h, t ); } // https://iquilezles.org/articles/rmshadows float calcSoftshadow( in vec3 ro, in vec3 rd, float tmin, float tmax, const float k ) { float res = 1.0; float t = tmin; for( int i=0; i<64; i++ ) { float h = map( ro + rd*t ); res = min( res, k*h/t ); t += clamp( h, 0.01, 0.10 ); if( res<0.002 || t>tmax ) break; } return clamp( res, 0.0, 1.0 ); } // https://iquilezles.org/articles/normalsSDF vec3 calcNormal( in vec3 pos ) { vec2 e = vec2(1.0,-1.0)*0.5773; const float eps = 0.0005; return normalize( e.xyy*map( pos + e.xyy*eps ) + e.yyx*map( pos + e.yyx*eps ) + e.yxy*map( pos + e.yxy*eps ) + e.xxx*map( pos + e.xxx*eps ) ); } #if HW_PERFORMANCE==0 #define AA 1 #else #define AA 3 #endif void mainImage( out vec4 fragColor, in vec2 fragCoord ) { // camera movement float an = sin(0.2*iTime); vec3 ro = vec3( 1.0*cos(an), 0.0, 1.0*sin(an) ); vec3 ta = vec3( 0.0, 0.0, 0.0 ); // camera matrix vec3 ww = normalize( ta - ro ); vec3 uu = normalize( cross(ww,vec3(0.0,1.0,0.0) ) ); vec3 vv = normalize( cross(uu,ww)); vec3 tot = vec3(0.0); #if AA>1 for( int m=0; m<AA; m++ ) for( int n=0; n<AA; n++ ) { // pixel coordinates vec2 o = vec2(float(m),float(n)) / float(AA) - 0.5; vec2 p = (2.0*(fragCoord+o)-iResolution.xy)/iResolution.y; #else vec2 p = (2.0*fragCoord-iResolution.xy)/iResolution.y; #endif // create view ray vec3 rd = normalize( p.x*uu + p.y*vv + 1.5*ww ); // raymarch const float tmax = 5.0; float t = 0.0; for( int i=0; i<256; i++ ) { vec3 pos = ro + t*rd; float h = map(pos); if( h<0.0001 || t>tmax ) break; t += h; } // shading/lighting vec3 col = vec3(0.0); if( t<tmax ) { vec3 pos = ro + t*rd; vec3 nor = calcNormal(pos); vec3 lig = vec3(0.57703); float dif = clamp( dot(nor,lig), 0.0, 1.0 ); if( dif>0.001 ) dif *= calcSoftshadow( pos+nor*0.001, lig, 0.001, 1.0, 32.0 ); float amb = 0.5 + 0.5*dot(nor,vec3(0.0,1.0,0.0)); col = vec3(0.2,0.3,0.4)*amb + vec3(0.8,0.7,0.5)*dif; } // gamma col = sqrt( col ); tot += col; #if AA>1 } tot /= float(AA*AA); #endif fragColor = vec4( tot, 1.0 ); }
mit
[ 1396, 1470, 1532, 1532, 1716 ]
[ [ 1396, 1470, 1532, 1532, 1716 ], [ 1718, 1718, 1744, 1744, 1912 ], [ 1914, 1959, 2046, 2046, 2304 ], [ 2306, 2352, 2384, 2384, 2623 ] ]
// r = sphere's radius // h = cutting's plane's position // t = thickness
float sdCutHollowSphere( vec3 p, float r, float h, float t ) {
vec2 q = vec2( length(p.xz), p.y ); float w = sqrt(r*r-h*h); return ((h*q.x<w*q.y) ? length(q-vec2(w,h)) : abs(length(q)-r) ) - t; }
// r = sphere's radius // h = cutting's plane's position // t = thickness float sdCutHollowSphere( vec3 p, float r, float h, float t ) {
2
6
7tVXRt
iq
2022-01-03T19:29:53
// The MIT License // Copyright © 2022 Inigo Quilez // Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. // Exact distance to a hollow sphere cut by a plane. Basically a // revolution operator (https://www.shadertoy.com/view/4lyfzw) // applied to a 2D arc (https://www.shadertoy.com/view/wl23RK) // List of other 3D SDFs: https://www.shadertoy.com/playlist/43cXRl // // and https://iquilezles.org/articles/distfunctions // r = sphere's radius // h = cutting's plane's position // t = thickness float sdCutHollowSphere( vec3 p, float r, float h, float t ) { vec2 q = vec2( length(p.xz), p.y ); float w = sqrt(r*r-h*h); return ((h*q.x<w*q.y) ? length(q-vec2(w,h)) : abs(length(q)-r) ) - t; } float map( in vec3 pos ) { pos.xy = (mat2(3,4,-4,3)/5.0)*pos.xy; float r = 0.5; float h = 0.2 + 0.2*cos(iTime*1.0); float t = 0.01; return sdCutHollowSphere(pos, r, h, t ); } // https://iquilezles.org/articles/rmshadows float calcSoftshadow( in vec3 ro, in vec3 rd, float tmin, float tmax, const float k ) { float res = 1.0; float t = tmin; for( int i=0; i<64; i++ ) { float h = map( ro + rd*t ); res = min( res, k*h/t ); t += clamp( h, 0.01, 0.10 ); if( res<0.002 || t>tmax ) break; } return clamp( res, 0.0, 1.0 ); } // https://iquilezles.org/articles/normalsSDF vec3 calcNormal( in vec3 pos ) { vec2 e = vec2(1.0,-1.0)*0.5773; const float eps = 0.0005; return normalize( e.xyy*map( pos + e.xyy*eps ) + e.yyx*map( pos + e.yyx*eps ) + e.yxy*map( pos + e.yxy*eps ) + e.xxx*map( pos + e.xxx*eps ) ); } #if HW_PERFORMANCE==0 #define AA 1 #else #define AA 3 #endif void mainImage( out vec4 fragColor, in vec2 fragCoord ) { // camera movement float an = sin(0.2*iTime); vec3 ro = vec3( 1.0*cos(an), 0.0, 1.0*sin(an) ); vec3 ta = vec3( 0.0, 0.0, 0.0 ); // camera matrix vec3 ww = normalize( ta - ro ); vec3 uu = normalize( cross(ww,vec3(0.0,1.0,0.0) ) ); vec3 vv = normalize( cross(uu,ww)); vec3 tot = vec3(0.0); #if AA>1 for( int m=0; m<AA; m++ ) for( int n=0; n<AA; n++ ) { // pixel coordinates vec2 o = vec2(float(m),float(n)) / float(AA) - 0.5; vec2 p = (2.0*(fragCoord+o)-iResolution.xy)/iResolution.y; #else vec2 p = (2.0*fragCoord-iResolution.xy)/iResolution.y; #endif // create view ray vec3 rd = normalize( p.x*uu + p.y*vv + 1.5*ww ); // raymarch const float tmax = 5.0; float t = 0.0; for( int i=0; i<256; i++ ) { vec3 pos = ro + t*rd; float h = map(pos); if( h<0.0001 || t>tmax ) break; t += h; } // shading/lighting vec3 col = vec3(0.0); if( t<tmax ) { vec3 pos = ro + t*rd; vec3 nor = calcNormal(pos); vec3 lig = vec3(0.57703); float dif = clamp( dot(nor,lig), 0.0, 1.0 ); if( dif>0.001 ) dif *= calcSoftshadow( pos+nor*0.001, lig, 0.001, 1.0, 32.0 ); float amb = 0.5 + 0.5*dot(nor,vec3(0.0,1.0,0.0)); col = vec3(0.2,0.3,0.4)*amb + vec3(0.8,0.7,0.5)*dif; } // gamma col = sqrt( col ); tot += col; #if AA>1 } tot /= float(AA*AA); #endif fragColor = vec4( tot, 1.0 ); }
mit
[ 1914, 1959, 2046, 2046, 2304 ]
[ [ 1396, 1470, 1532, 1532, 1716 ], [ 1718, 1718, 1744, 1744, 1912 ], [ 1914, 1959, 2046, 2046, 2304 ], [ 2306, 2352, 2384, 2384, 2623 ] ]
// https://iquilezles.org/articles/rmshadows
float calcSoftshadow( in vec3 ro, in vec3 rd, float tmin, float tmax, const float k ) {
float res = 1.0; float t = tmin; for( int i=0; i<64; i++ ) { float h = map( ro + rd*t ); res = min( res, k*h/t ); t += clamp( h, 0.01, 0.10 ); if( res<0.002 || t>tmax ) break; } return clamp( res, 0.0, 1.0 ); }
// https://iquilezles.org/articles/rmshadows float calcSoftshadow( in vec3 ro, in vec3 rd, float tmin, float tmax, const float k ) {
1
10
stKSzc
iq
2022-01-03T03:36:24
// The MIT License // Copyright © 2021 Inigo Quilez // Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. // Exact distance to a sphere cut by a plane. Beware doing the max() of // a sphere and a plane won't produce an exact Euclidean distance. // Based on sdCutDisk(): https://www.shadertoy.com/view/ftVXRc // // It is a useful primitive when combined with rounding/inflating, which // cannot be done with the non-Euclidean max() approach, since you can do // things like mushroom heads. // List of other 3D SDFs: https://www.shadertoy.com/playlist/43cXRl // // and https://iquilezles.org/articles/distfunctions // r is the sphere's radius, h is the plane's position float sdCutSphere( in vec3 p, in float r, in float h ) { float w = sqrt(r*r-h*h); // constant for a given shape vec2 q = vec2( length(p.xz), p.y ); float s = max( (h-r)*q.x*q.x+w*w*(h+r-2.0*q.y), h*q.x-w*q.y ); return (s<0.0) ? length(q)-r : (q.x<w) ? h - q.y : length(q-vec2(w,h)); } float map( in vec3 pos ) { if( sin(iTime*0.8)>-0.1 ) { pos.yz = (mat2(-4,3,-3,-4)/5.0)*pos.yz; return sdCutSphere(pos, 0.5, -0.2 ); } else { pos.y += 0.1; float d = sdCutSphere(pos, 0.5, 0.2 ) - 0.1; return min( d, max(length(pos.xz)-0.15,pos.y-0.2) ); } } // https://iquilezles.org/articles/normalsSDF vec3 calcNormal( in vec3 pos ) { vec2 e = vec2(1.0,-1.0)*0.5773; const float eps = 0.0005; return normalize( e.xyy*map( pos + e.xyy*eps ) + e.yyx*map( pos + e.yyx*eps ) + e.yxy*map( pos + e.yxy*eps ) + e.xxx*map( pos + e.xxx*eps ) ); } #if HW_PERFORMANCE==0 #define AA 1 #else #define AA 3 #endif void mainImage( out vec4 fragColor, in vec2 fragCoord ) { // camera movement float an = 0.8*iTime; vec3 ro = vec3( 1.0*cos(an), 0.0, 1.0*sin(an) ); vec3 ta = vec3( 0.0, 0.0, 0.0 ); // camera matrix vec3 ww = normalize( ta - ro ); vec3 uu = normalize( cross(ww,vec3(0.0,1.0,0.0) ) ); vec3 vv = normalize( cross(uu,ww)); vec3 tot = vec3(0.0); #if AA>1 for( int m=0; m<AA; m++ ) for( int n=0; n<AA; n++ ) { // pixel coordinates vec2 o = vec2(float(m),float(n)) / float(AA) - 0.5; vec2 p = (2.0*(fragCoord+o)-iResolution.xy)/iResolution.y; #else vec2 p = (2.0*fragCoord-iResolution.xy)/iResolution.y; #endif // create view ray vec3 rd = normalize( p.x*uu + p.y*vv + 1.5*ww ); // raymarch const float tmax = 5.0; float t = 0.0; for( int i=0; i<256; i++ ) { vec3 pos = ro + t*rd; float h = map(pos); if( h<0.0001 || t>tmax ) break; t += h; } // shading/lighting vec3 col = vec3(0.0); if( t<tmax ) { vec3 pos = ro + t*rd; vec3 nor = calcNormal(pos); float dif = clamp( dot(nor,vec3(0.57703)), 0.0, 1.0 ); float amb = 0.5 + 0.5*dot(nor,vec3(0.0,1.0,0.0)); col = vec3(0.2,0.3,0.4)*amb + vec3(0.8,0.7,0.5)*dif; } // gamma col = sqrt( col ); tot += col; #if AA>1 } tot /= float(AA*AA); #endif fragColor = vec4( tot, 1.0 ); }
mit
[ 1588, 1643, 1699, 1699, 1990 ]
[ [ 1588, 1643, 1699, 1699, 1990 ], [ 1992, 1992, 2018, 2018, 2292 ], [ 2294, 2340, 2372, 2372, 2611 ] ]
// r is the sphere's radius, h is the plane's position
float sdCutSphere( in vec3 p, in float r, in float h ) {
float w = sqrt(r*r-h*h); // constant for a given shape vec2 q = vec2( length(p.xz), p.y ); float s = max( (h-r)*q.x*q.x+w*w*(h+r-2.0*q.y), h*q.x-w*q.y ); return (s<0.0) ? length(q)-r : (q.x<w) ? h - q.y : length(q-vec2(w,h)); }
// r is the sphere's radius, h is the plane's position float sdCutSphere( in vec3 p, in float r, in float h ) {
1
2
stKSzc
iq
2022-01-03T03:36:24
// The MIT License // Copyright © 2021 Inigo Quilez // Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. // Exact distance to a sphere cut by a plane. Beware doing the max() of // a sphere and a plane won't produce an exact Euclidean distance. // Based on sdCutDisk(): https://www.shadertoy.com/view/ftVXRc // // It is a useful primitive when combined with rounding/inflating, which // cannot be done with the non-Euclidean max() approach, since you can do // things like mushroom heads. // List of other 3D SDFs: https://www.shadertoy.com/playlist/43cXRl // // and https://iquilezles.org/articles/distfunctions // r is the sphere's radius, h is the plane's position float sdCutSphere( in vec3 p, in float r, in float h ) { float w = sqrt(r*r-h*h); // constant for a given shape vec2 q = vec2( length(p.xz), p.y ); float s = max( (h-r)*q.x*q.x+w*w*(h+r-2.0*q.y), h*q.x-w*q.y ); return (s<0.0) ? length(q)-r : (q.x<w) ? h - q.y : length(q-vec2(w,h)); } float map( in vec3 pos ) { if( sin(iTime*0.8)>-0.1 ) { pos.yz = (mat2(-4,3,-3,-4)/5.0)*pos.yz; return sdCutSphere(pos, 0.5, -0.2 ); } else { pos.y += 0.1; float d = sdCutSphere(pos, 0.5, 0.2 ) - 0.1; return min( d, max(length(pos.xz)-0.15,pos.y-0.2) ); } } // https://iquilezles.org/articles/normalsSDF vec3 calcNormal( in vec3 pos ) { vec2 e = vec2(1.0,-1.0)*0.5773; const float eps = 0.0005; return normalize( e.xyy*map( pos + e.xyy*eps ) + e.yyx*map( pos + e.yyx*eps ) + e.yxy*map( pos + e.yxy*eps ) + e.xxx*map( pos + e.xxx*eps ) ); } #if HW_PERFORMANCE==0 #define AA 1 #else #define AA 3 #endif void mainImage( out vec4 fragColor, in vec2 fragCoord ) { // camera movement float an = 0.8*iTime; vec3 ro = vec3( 1.0*cos(an), 0.0, 1.0*sin(an) ); vec3 ta = vec3( 0.0, 0.0, 0.0 ); // camera matrix vec3 ww = normalize( ta - ro ); vec3 uu = normalize( cross(ww,vec3(0.0,1.0,0.0) ) ); vec3 vv = normalize( cross(uu,ww)); vec3 tot = vec3(0.0); #if AA>1 for( int m=0; m<AA; m++ ) for( int n=0; n<AA; n++ ) { // pixel coordinates vec2 o = vec2(float(m),float(n)) / float(AA) - 0.5; vec2 p = (2.0*(fragCoord+o)-iResolution.xy)/iResolution.y; #else vec2 p = (2.0*fragCoord-iResolution.xy)/iResolution.y; #endif // create view ray vec3 rd = normalize( p.x*uu + p.y*vv + 1.5*ww ); // raymarch const float tmax = 5.0; float t = 0.0; for( int i=0; i<256; i++ ) { vec3 pos = ro + t*rd; float h = map(pos); if( h<0.0001 || t>tmax ) break; t += h; } // shading/lighting vec3 col = vec3(0.0); if( t<tmax ) { vec3 pos = ro + t*rd; vec3 nor = calcNormal(pos); float dif = clamp( dot(nor,vec3(0.57703)), 0.0, 1.0 ); float amb = 0.5 + 0.5*dot(nor,vec3(0.0,1.0,0.0)); col = vec3(0.2,0.3,0.4)*amb + vec3(0.8,0.7,0.5)*dif; } // gamma col = sqrt( col ); tot += col; #if AA>1 } tot /= float(AA*AA); #endif fragColor = vec4( tot, 1.0 ); }
mit
[ 2294, 2340, 2372, 2372, 2611 ]
[ [ 1588, 1643, 1699, 1699, 1990 ], [ 1992, 1992, 2018, 2018, 2292 ], [ 2294, 2340, 2372, 2372, 2611 ] ]
// https://iquilezles.org/articles/normalsSDF
vec3 calcNormal( in vec3 pos ) {
vec2 e = vec2(1.0,-1.0)*0.5773; const float eps = 0.0005; return normalize( e.xyy*map( pos + e.xyy*eps ) + e.yyx*map( pos + e.yyx*eps ) + e.yxy*map( pos + e.yxy*eps ) + e.xxx*map( pos + e.xxx*eps ) ); }
// https://iquilezles.org/articles/normalsSDF vec3 calcNormal( in vec3 pos ) {
23
360
ftVXRc
iq
2022-01-02T22:49:00
// The MIT License // Copyright © 2022 Inigo Quilez // Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. // Signed distance to a disk that's been clipped by a line // // List of some other 2D distances: https://www.shadertoy.com/playlist/MXdSRf // // and iquilezles.org/articles/distfunctions2d // r=radius, h=height float sdCutDisk( in vec2 p, in float r, in float h ) { float w = sqrt(r*r-h*h); // constant for a given shape p.x = abs(p.x); // select circle or segment float s = max( (h-r)*p.x*p.x+w*w*(h+r-2.0*p.y), h*p.x-w*p.y ); return (s<0.0) ? length(p)-r : // circle (p.x<w) ? h - p.y : // segment line length(p-vec2(w,h)); // segment corner } void mainImage( out vec4 fragColor, in vec2 fragCoord ) { // normalized pixel coordinates vec2 p = (2.0*fragCoord-iResolution.xy)/iResolution.y; vec2 m = (2.0*iMouse.xy-iResolution.xy)/iResolution.y; // animation float ra = 0.75; float he = ra*clamp(cos(iTime*0.8),-0.999999,0.999999); // distance float d = sdCutDisk(p,ra,he); // coloring vec3 col = (d>0.0) ? vec3(0.9,0.6,0.3) : vec3(0.5,0.85,1.0); col *= 1.0 - exp(-7.0*abs(d)); col *= 0.8 + 0.2*cos(128.0*abs(d)); col = mix( col, vec3(1.0), 1.0-smoothstep(0.0,0.015,abs(d)) ); // interactivity if( iMouse.z>0.001 ) { d = sdCutDisk(m,ra,he); col = mix(col, vec3(1.0,1.0,0.0), 1.0-smoothstep(0.0, 0.005, abs(length(p-m)-abs(d))-0.0025)); col = mix(col, vec3(1.0,1.0,0.0), 1.0-smoothstep(0.0, 0.005, length(p-m)-0.015)); } fragColor = vec4(col, 1.0); }
mit
[ 1272, 1294, 1348, 1348, 1709 ]
[ [ 1272, 1294, 1348, 1348, 1709 ], [ 1713, 1713, 1770, 1806, 2611 ] ]
// r=radius, h=height
float sdCutDisk( in vec2 p, in float r, in float h ) {
float w = sqrt(r*r-h*h); // constant for a given shape p.x = abs(p.x); // select circle or segment float s = max( (h-r)*p.x*p.x+w*w*(h+r-2.0*p.y), h*p.x-w*p.y ); return (s<0.0) ? length(p)-r : // circle (p.x<w) ? h - p.y : // segment line length(p-vec2(w,h)); // segment corner }
// r=radius, h=height float sdCutDisk( in vec2 p, in float r, in float h ) {
2
2
fdsBzs
spqr
2022-02-26T10:52:06
//CC0 1.0 Universal https://creativecommons.org/publicdomain/zero/1.0/ //To the extent possible under law, Blackle Mori has waived all copyright and related or neighboring rights to this work. //returns a vector pointing in the direction of the closest neighbouring cell #define saturate(a) (clamp((a),0.,1.)) mat2 rot(float a){ float s = sin(a); float c = cos(a); return mat2(c,s,-s,c); } mat3 m = mat3( 0.00, 0.80, 0.60, -0.80, 0.36, -0.48, -0.60, -0.48, 0.64 ); float hash( float n ) { return fract(sin(n)*43758.5453123); } // 3d noise function float noise( in vec3 x ) { vec3 p = floor(x); vec3 f = fract(x); f = f*f*(3.0-2.0*f); float n = p.x + p.y*57.0 + 113.0*p.z; float res = mix(mix(mix( hash(n+ 0.0), hash(n+ 1.0),f.x), mix( hash(n+ 57.0), hash(n+ 58.0),f.x),f.y), mix(mix( hash(n+113.0), hash(n+114.0),f.x), mix( hash(n+170.0), hash(n+171.0),f.x),f.y),f.z); return res; } // fbm noise for 2-4 octaves including rotation per octave float fbm( vec3 p ) { float f = 0.0; f += 0.5000*noise( p ); p = m*p*2.02; f += 0.2500*noise( p ); p = m*p*2.03; f += 0.1250*noise( p ); p = m*p*2.01; f += 0.0625*noise( p ); return f/0.9375; } float box(vec3 p,vec3 s) { vec3 d=abs(p)-s; return length(max(d,0.)); } float hash(float a, float b) { return fract(sin(a*1.2664745 + b*.9560333 + 3.) * 14958.5453); } float tick (float t){ float i = floor(t); float r = fract(t); r = smoothstep(0.,1.,r); r = smoothstep(0.,1.,r); r = smoothstep(0.,1.,r); r = smoothstep(0.,1.,r); return i + r; } float tock (float t){ float i = floor(t); float r = fract(t); r = smoothstep(0.,1.,r); return i + r; } float ball; #define MOD3 vec3(.1031,.11369,.13787) //value noise hash float hash31(vec3 p3) { p3 = fract(p3 * MOD3); p3 += dot(p3, p3.yzx + 19.19); return -1.0 + 2.0 * fract((p3.x + p3.y) * p3.z); } vec3 randomdir (float n) { return fract(vec3(5.1283,9.3242,13.8381) * hash(n) * 8421.4242); } float glow = 0.; float sph(vec3 p,float r) { return length(p) -r ; } float map(vec3 p) { //geo float tt = iTime * .3; vec3 q = p; // wierd skylights q.xy *= rot(q.z/10.); q.x += tt * 10.; q = mod( q, 16.) - 8.; float uu = sph(q,.00001); glow += .1/(.1+pow(uu,2.)); float domain = 1.5; ; vec3 id = floor((p*.1)/domain); vec3 id2 = floor((p)/domain); p = mod(p,domain) - domain/2.; float thresh = fbm(id); float rando = hash31(id2); vec3 flit = vec3(.1); flit.xz *= rot(rando*5.1+tt*2.3); flit.yz *= rot(rando*4.2+tt*1.4); flit.xy *= rot(rando*3.3+tt*1.1); //vec3 flit = randomdir(hash31(id)) * .2; vec3 jitter = flit * sin((tt*9.1+rando*12.1)); //(.5)hash(float(id)) * vec3(.5) * sin(iTime*6.+3.*hash(float(id))); if ( rando *.6< thresh) { p = abs(p); if (p.x > p.y) p.xy = p.yx; if (p.y > p.z) p.yz = p.zy; if (p.x > p.y) p.xy = p.yx; p.z -= domain; //return length(p)-1.; float u = box(p + jitter, vec3(.4)); return min(uu,u*.5); } else { //return length(p)-1.; float u = box(p + jitter, vec3(.4)); return min(uu,u*.5); } } vec3 norm(vec3 p,vec2 d) { return normalize(vec3( map(p+d.yxx)-map(p-d.yxx), map(p+d.xyx)-map(p-d.xyx), map(p+d.xxy)-map(p-d.xxy) )); } vec3 norm(vec3 p) { mat3 k = mat3(p,p,p)-mat3(0.01); return normalize(map(p) - vec3( map(k[0]),map(k[1]),map(k[2]) )); } const float PI = acos(-1.); vec3 pixel_color(vec2 uv) { // nav float tt = iTime ; vec3 jump = vec3(1) * tick(tt*.05)*77.2; jump.xz *= rot(tt*.00001); vec3 s = vec3(10.,3.2,7.1)*tt*.18 + jump; vec3 arm = vec3(1,0,0); arm.xz *= rot(sin(tt* .19)); arm.yz *= rot(sin(tt*.23)); //arm.yx *= rot(sin(tt*.28)); vec3 t = s + arm; vec3 cz=normalize(t-s); vec3 cx=normalize(cross(cz,vec3(0,1,0))); vec3 cy=-normalize(cross(cz,cx)); cz -= dot(uv,uv)/15.; vec3 r=normalize(cx*uv.x+cy*uv.y+cz); vec3 p = s; bool hit = false; float d; float i; float dd = 0.; //ray marching for ( i = 0.; i < 800.; i++) { d = map(p); d = abs(d); if ( d < .001) { hit = true; break; } if (dd>1000.) { break;} dd += d; p+=d*r; } vec3 col = vec3(.8, .5, .2); col = vec3(.1,.1,.2)*1.; float ao = pow(1. - i/500.,1.); col *= ao; col += glow*.6; vec3 light = normalize(vec3(1)); vec3 n = norm(p); // if ( dot(light,n) < 0.) { light = -light;} float spec =pow(max(dot(reflect(-light,n),-r),0.),40.) * 10.; col += spec * .1; float diff = max(0., dot(n,light)*.5 +.5); col *= diff; vec3 n2 = norm(p, vec2(0.0, 1E-2 ));// + 3E-2*.01) ); vec3 n1 = norm(p, vec2(0.0, 1.03E-2) ); float edge = saturate(length(n1-n2)/0.1); if ( edge > 0.01) { col = vec3(0); } if (! hit){ col = vec3(0); } return col; } void mainImage( out vec4 fragColor, in vec2 fragCoord ) { vec2 uv = (fragCoord-.5*iResolution.xy)/iResolution.y; fragColor = vec4(0); fragColor += vec4(pixel_color(uv), 1.); fragColor.xyz = sqrt(fragColor.xyz/fragColor.w); } /* //float uniformity = (sin(iTime*.01)*.5 + .5) * 10. + 5.; float uniformity = 15.; vec3 hue = 1.-sin(p/uniformity); vec3 light =normalize(vec3(60,10,10)); if ( dot(light,n) < 0.) { light = -light;} float diff = max(0., dot(n,light)*.5 +.5); float spec =pow(max(dot(reflect(-light,n),-r),0.),40.) * 10.; vec3 fog = vec3(0); // vec3 col = mix(spec * 0.2 + hue * ( diff ),fog, min(fren,.8)); vec3 col = mix(spec * 0.2 + hue * ( diff ),fog,.5); col = mix(col,fog,1. - exp(-.000003*dd*dd*dd)); */
cc0-1.0
[ 581, 602, 628, 628, 1030 ]
[ [ 313, 313, 331, 331, 404 ], [ 514, 514, 537, 537, 579 ], [ 581, 602, 628, 628, 1030 ], [ 1032, 1091, 1112, 1112, 1312 ], [ 1313, 1313, 1339, 1339, 1388 ], [ 1392, 1392, 1422, 1422, 1491 ], [ 1495, 1495, 1516, 1516, 1705 ], [ 1707, 1707, 1728, 1728, 1833 ], [ 1887, 1906, 1929, 1929, 2044 ], [ 2045, 2045, 2071, 2071, 2142 ], [ 2160, 2160, 2187, 2187, 2215 ], [ 2216, 2216, 2235, 2246, 3480 ], [ 3483, 3483, 3509, 3509, 3634 ], [ 3636, 3636, 3655, 3655, 3764 ], [ 3796, 3796, 3823, 3836, 5333 ], [ 5336, 5336, 5393, 5393, 5575 ] ]
// 3d noise function
float noise( in vec3 x ) {
vec3 p = floor(x); vec3 f = fract(x); f = f*f*(3.0-2.0*f); float n = p.x + p.y*57.0 + 113.0*p.z; float res = mix(mix(mix( hash(n+ 0.0), hash(n+ 1.0),f.x), mix( hash(n+ 57.0), hash(n+ 58.0),f.x),f.y), mix(mix( hash(n+113.0), hash(n+114.0),f.x), mix( hash(n+170.0), hash(n+171.0),f.x),f.y),f.z); return res; }
// 3d noise function float noise( in vec3 x ) {
5
193
fdsBzs
spqr
2022-02-26T10:52:06
//CC0 1.0 Universal https://creativecommons.org/publicdomain/zero/1.0/ //To the extent possible under law, Blackle Mori has waived all copyright and related or neighboring rights to this work. //returns a vector pointing in the direction of the closest neighbouring cell #define saturate(a) (clamp((a),0.,1.)) mat2 rot(float a){ float s = sin(a); float c = cos(a); return mat2(c,s,-s,c); } mat3 m = mat3( 0.00, 0.80, 0.60, -0.80, 0.36, -0.48, -0.60, -0.48, 0.64 ); float hash( float n ) { return fract(sin(n)*43758.5453123); } // 3d noise function float noise( in vec3 x ) { vec3 p = floor(x); vec3 f = fract(x); f = f*f*(3.0-2.0*f); float n = p.x + p.y*57.0 + 113.0*p.z; float res = mix(mix(mix( hash(n+ 0.0), hash(n+ 1.0),f.x), mix( hash(n+ 57.0), hash(n+ 58.0),f.x),f.y), mix(mix( hash(n+113.0), hash(n+114.0),f.x), mix( hash(n+170.0), hash(n+171.0),f.x),f.y),f.z); return res; } // fbm noise for 2-4 octaves including rotation per octave float fbm( vec3 p ) { float f = 0.0; f += 0.5000*noise( p ); p = m*p*2.02; f += 0.2500*noise( p ); p = m*p*2.03; f += 0.1250*noise( p ); p = m*p*2.01; f += 0.0625*noise( p ); return f/0.9375; } float box(vec3 p,vec3 s) { vec3 d=abs(p)-s; return length(max(d,0.)); } float hash(float a, float b) { return fract(sin(a*1.2664745 + b*.9560333 + 3.) * 14958.5453); } float tick (float t){ float i = floor(t); float r = fract(t); r = smoothstep(0.,1.,r); r = smoothstep(0.,1.,r); r = smoothstep(0.,1.,r); r = smoothstep(0.,1.,r); return i + r; } float tock (float t){ float i = floor(t); float r = fract(t); r = smoothstep(0.,1.,r); return i + r; } float ball; #define MOD3 vec3(.1031,.11369,.13787) //value noise hash float hash31(vec3 p3) { p3 = fract(p3 * MOD3); p3 += dot(p3, p3.yzx + 19.19); return -1.0 + 2.0 * fract((p3.x + p3.y) * p3.z); } vec3 randomdir (float n) { return fract(vec3(5.1283,9.3242,13.8381) * hash(n) * 8421.4242); } float glow = 0.; float sph(vec3 p,float r) { return length(p) -r ; } float map(vec3 p) { //geo float tt = iTime * .3; vec3 q = p; // wierd skylights q.xy *= rot(q.z/10.); q.x += tt * 10.; q = mod( q, 16.) - 8.; float uu = sph(q,.00001); glow += .1/(.1+pow(uu,2.)); float domain = 1.5; ; vec3 id = floor((p*.1)/domain); vec3 id2 = floor((p)/domain); p = mod(p,domain) - domain/2.; float thresh = fbm(id); float rando = hash31(id2); vec3 flit = vec3(.1); flit.xz *= rot(rando*5.1+tt*2.3); flit.yz *= rot(rando*4.2+tt*1.4); flit.xy *= rot(rando*3.3+tt*1.1); //vec3 flit = randomdir(hash31(id)) * .2; vec3 jitter = flit * sin((tt*9.1+rando*12.1)); //(.5)hash(float(id)) * vec3(.5) * sin(iTime*6.+3.*hash(float(id))); if ( rando *.6< thresh) { p = abs(p); if (p.x > p.y) p.xy = p.yx; if (p.y > p.z) p.yz = p.zy; if (p.x > p.y) p.xy = p.yx; p.z -= domain; //return length(p)-1.; float u = box(p + jitter, vec3(.4)); return min(uu,u*.5); } else { //return length(p)-1.; float u = box(p + jitter, vec3(.4)); return min(uu,u*.5); } } vec3 norm(vec3 p,vec2 d) { return normalize(vec3( map(p+d.yxx)-map(p-d.yxx), map(p+d.xyx)-map(p-d.xyx), map(p+d.xxy)-map(p-d.xxy) )); } vec3 norm(vec3 p) { mat3 k = mat3(p,p,p)-mat3(0.01); return normalize(map(p) - vec3( map(k[0]),map(k[1]),map(k[2]) )); } const float PI = acos(-1.); vec3 pixel_color(vec2 uv) { // nav float tt = iTime ; vec3 jump = vec3(1) * tick(tt*.05)*77.2; jump.xz *= rot(tt*.00001); vec3 s = vec3(10.,3.2,7.1)*tt*.18 + jump; vec3 arm = vec3(1,0,0); arm.xz *= rot(sin(tt* .19)); arm.yz *= rot(sin(tt*.23)); //arm.yx *= rot(sin(tt*.28)); vec3 t = s + arm; vec3 cz=normalize(t-s); vec3 cx=normalize(cross(cz,vec3(0,1,0))); vec3 cy=-normalize(cross(cz,cx)); cz -= dot(uv,uv)/15.; vec3 r=normalize(cx*uv.x+cy*uv.y+cz); vec3 p = s; bool hit = false; float d; float i; float dd = 0.; //ray marching for ( i = 0.; i < 800.; i++) { d = map(p); d = abs(d); if ( d < .001) { hit = true; break; } if (dd>1000.) { break;} dd += d; p+=d*r; } vec3 col = vec3(.8, .5, .2); col = vec3(.1,.1,.2)*1.; float ao = pow(1. - i/500.,1.); col *= ao; col += glow*.6; vec3 light = normalize(vec3(1)); vec3 n = norm(p); // if ( dot(light,n) < 0.) { light = -light;} float spec =pow(max(dot(reflect(-light,n),-r),0.),40.) * 10.; col += spec * .1; float diff = max(0., dot(n,light)*.5 +.5); col *= diff; vec3 n2 = norm(p, vec2(0.0, 1E-2 ));// + 3E-2*.01) ); vec3 n1 = norm(p, vec2(0.0, 1.03E-2) ); float edge = saturate(length(n1-n2)/0.1); if ( edge > 0.01) { col = vec3(0); } if (! hit){ col = vec3(0); } return col; } void mainImage( out vec4 fragColor, in vec2 fragCoord ) { vec2 uv = (fragCoord-.5*iResolution.xy)/iResolution.y; fragColor = vec4(0); fragColor += vec4(pixel_color(uv), 1.); fragColor.xyz = sqrt(fragColor.xyz/fragColor.w); } /* //float uniformity = (sin(iTime*.01)*.5 + .5) * 10. + 5.; float uniformity = 15.; vec3 hue = 1.-sin(p/uniformity); vec3 light =normalize(vec3(60,10,10)); if ( dot(light,n) < 0.) { light = -light;} float diff = max(0., dot(n,light)*.5 +.5); float spec =pow(max(dot(reflect(-light,n),-r),0.),40.) * 10.; vec3 fog = vec3(0); // vec3 col = mix(spec * 0.2 + hue * ( diff ),fog, min(fren,.8)); vec3 col = mix(spec * 0.2 + hue * ( diff ),fog,.5); col = mix(col,fog,1. - exp(-.000003*dd*dd*dd)); */
cc0-1.0
[ 1032, 1091, 1112, 1112, 1312 ]
[ [ 313, 313, 331, 331, 404 ], [ 514, 514, 537, 537, 579 ], [ 581, 602, 628, 628, 1030 ], [ 1032, 1091, 1112, 1112, 1312 ], [ 1313, 1313, 1339, 1339, 1388 ], [ 1392, 1392, 1422, 1422, 1491 ], [ 1495, 1495, 1516, 1516, 1705 ], [ 1707, 1707, 1728, 1728, 1833 ], [ 1887, 1906, 1929, 1929, 2044 ], [ 2045, 2045, 2071, 2071, 2142 ], [ 2160, 2160, 2187, 2187, 2215 ], [ 2216, 2216, 2235, 2246, 3480 ], [ 3483, 3483, 3509, 3509, 3634 ], [ 3636, 3636, 3655, 3655, 3764 ], [ 3796, 3796, 3823, 3836, 5333 ], [ 5336, 5336, 5393, 5393, 5575 ] ]
// fbm noise for 2-4 octaves including rotation per octave
float fbm( vec3 p ) {
float f = 0.0; f += 0.5000*noise( p ); p = m*p*2.02; f += 0.2500*noise( p ); p = m*p*2.03; f += 0.1250*noise( p ); p = m*p*2.01; f += 0.0625*noise( p ); return f/0.9375; }
// fbm noise for 2-4 octaves including rotation per octave float fbm( vec3 p ) {
3
54
fdsBzs
spqr
2022-02-26T10:52:06
//CC0 1.0 Universal https://creativecommons.org/publicdomain/zero/1.0/ //To the extent possible under law, Blackle Mori has waived all copyright and related or neighboring rights to this work. //returns a vector pointing in the direction of the closest neighbouring cell #define saturate(a) (clamp((a),0.,1.)) mat2 rot(float a){ float s = sin(a); float c = cos(a); return mat2(c,s,-s,c); } mat3 m = mat3( 0.00, 0.80, 0.60, -0.80, 0.36, -0.48, -0.60, -0.48, 0.64 ); float hash( float n ) { return fract(sin(n)*43758.5453123); } // 3d noise function float noise( in vec3 x ) { vec3 p = floor(x); vec3 f = fract(x); f = f*f*(3.0-2.0*f); float n = p.x + p.y*57.0 + 113.0*p.z; float res = mix(mix(mix( hash(n+ 0.0), hash(n+ 1.0),f.x), mix( hash(n+ 57.0), hash(n+ 58.0),f.x),f.y), mix(mix( hash(n+113.0), hash(n+114.0),f.x), mix( hash(n+170.0), hash(n+171.0),f.x),f.y),f.z); return res; } // fbm noise for 2-4 octaves including rotation per octave float fbm( vec3 p ) { float f = 0.0; f += 0.5000*noise( p ); p = m*p*2.02; f += 0.2500*noise( p ); p = m*p*2.03; f += 0.1250*noise( p ); p = m*p*2.01; f += 0.0625*noise( p ); return f/0.9375; } float box(vec3 p,vec3 s) { vec3 d=abs(p)-s; return length(max(d,0.)); } float hash(float a, float b) { return fract(sin(a*1.2664745 + b*.9560333 + 3.) * 14958.5453); } float tick (float t){ float i = floor(t); float r = fract(t); r = smoothstep(0.,1.,r); r = smoothstep(0.,1.,r); r = smoothstep(0.,1.,r); r = smoothstep(0.,1.,r); return i + r; } float tock (float t){ float i = floor(t); float r = fract(t); r = smoothstep(0.,1.,r); return i + r; } float ball; #define MOD3 vec3(.1031,.11369,.13787) //value noise hash float hash31(vec3 p3) { p3 = fract(p3 * MOD3); p3 += dot(p3, p3.yzx + 19.19); return -1.0 + 2.0 * fract((p3.x + p3.y) * p3.z); } vec3 randomdir (float n) { return fract(vec3(5.1283,9.3242,13.8381) * hash(n) * 8421.4242); } float glow = 0.; float sph(vec3 p,float r) { return length(p) -r ; } float map(vec3 p) { //geo float tt = iTime * .3; vec3 q = p; // wierd skylights q.xy *= rot(q.z/10.); q.x += tt * 10.; q = mod( q, 16.) - 8.; float uu = sph(q,.00001); glow += .1/(.1+pow(uu,2.)); float domain = 1.5; ; vec3 id = floor((p*.1)/domain); vec3 id2 = floor((p)/domain); p = mod(p,domain) - domain/2.; float thresh = fbm(id); float rando = hash31(id2); vec3 flit = vec3(.1); flit.xz *= rot(rando*5.1+tt*2.3); flit.yz *= rot(rando*4.2+tt*1.4); flit.xy *= rot(rando*3.3+tt*1.1); //vec3 flit = randomdir(hash31(id)) * .2; vec3 jitter = flit * sin((tt*9.1+rando*12.1)); //(.5)hash(float(id)) * vec3(.5) * sin(iTime*6.+3.*hash(float(id))); if ( rando *.6< thresh) { p = abs(p); if (p.x > p.y) p.xy = p.yx; if (p.y > p.z) p.yz = p.zy; if (p.x > p.y) p.xy = p.yx; p.z -= domain; //return length(p)-1.; float u = box(p + jitter, vec3(.4)); return min(uu,u*.5); } else { //return length(p)-1.; float u = box(p + jitter, vec3(.4)); return min(uu,u*.5); } } vec3 norm(vec3 p,vec2 d) { return normalize(vec3( map(p+d.yxx)-map(p-d.yxx), map(p+d.xyx)-map(p-d.xyx), map(p+d.xxy)-map(p-d.xxy) )); } vec3 norm(vec3 p) { mat3 k = mat3(p,p,p)-mat3(0.01); return normalize(map(p) - vec3( map(k[0]),map(k[1]),map(k[2]) )); } const float PI = acos(-1.); vec3 pixel_color(vec2 uv) { // nav float tt = iTime ; vec3 jump = vec3(1) * tick(tt*.05)*77.2; jump.xz *= rot(tt*.00001); vec3 s = vec3(10.,3.2,7.1)*tt*.18 + jump; vec3 arm = vec3(1,0,0); arm.xz *= rot(sin(tt* .19)); arm.yz *= rot(sin(tt*.23)); //arm.yx *= rot(sin(tt*.28)); vec3 t = s + arm; vec3 cz=normalize(t-s); vec3 cx=normalize(cross(cz,vec3(0,1,0))); vec3 cy=-normalize(cross(cz,cx)); cz -= dot(uv,uv)/15.; vec3 r=normalize(cx*uv.x+cy*uv.y+cz); vec3 p = s; bool hit = false; float d; float i; float dd = 0.; //ray marching for ( i = 0.; i < 800.; i++) { d = map(p); d = abs(d); if ( d < .001) { hit = true; break; } if (dd>1000.) { break;} dd += d; p+=d*r; } vec3 col = vec3(.8, .5, .2); col = vec3(.1,.1,.2)*1.; float ao = pow(1. - i/500.,1.); col *= ao; col += glow*.6; vec3 light = normalize(vec3(1)); vec3 n = norm(p); // if ( dot(light,n) < 0.) { light = -light;} float spec =pow(max(dot(reflect(-light,n),-r),0.),40.) * 10.; col += spec * .1; float diff = max(0., dot(n,light)*.5 +.5); col *= diff; vec3 n2 = norm(p, vec2(0.0, 1E-2 ));// + 3E-2*.01) ); vec3 n1 = norm(p, vec2(0.0, 1.03E-2) ); float edge = saturate(length(n1-n2)/0.1); if ( edge > 0.01) { col = vec3(0); } if (! hit){ col = vec3(0); } return col; } void mainImage( out vec4 fragColor, in vec2 fragCoord ) { vec2 uv = (fragCoord-.5*iResolution.xy)/iResolution.y; fragColor = vec4(0); fragColor += vec4(pixel_color(uv), 1.); fragColor.xyz = sqrt(fragColor.xyz/fragColor.w); } /* //float uniformity = (sin(iTime*.01)*.5 + .5) * 10. + 5.; float uniformity = 15.; vec3 hue = 1.-sin(p/uniformity); vec3 light =normalize(vec3(60,10,10)); if ( dot(light,n) < 0.) { light = -light;} float diff = max(0., dot(n,light)*.5 +.5); float spec =pow(max(dot(reflect(-light,n),-r),0.),40.) * 10.; vec3 fog = vec3(0); // vec3 col = mix(spec * 0.2 + hue * ( diff ),fog, min(fren,.8)); vec3 col = mix(spec * 0.2 + hue * ( diff ),fog,.5); col = mix(col,fog,1. - exp(-.000003*dd*dd*dd)); */
cc0-1.0
[ 1887, 1906, 1929, 1929, 2044 ]
[ [ 313, 313, 331, 331, 404 ], [ 514, 514, 537, 537, 579 ], [ 581, 602, 628, 628, 1030 ], [ 1032, 1091, 1112, 1112, 1312 ], [ 1313, 1313, 1339, 1339, 1388 ], [ 1392, 1392, 1422, 1422, 1491 ], [ 1495, 1495, 1516, 1516, 1705 ], [ 1707, 1707, 1728, 1728, 1833 ], [ 1887, 1906, 1929, 1929, 2044 ], [ 2045, 2045, 2071, 2071, 2142 ], [ 2160, 2160, 2187, 2187, 2215 ], [ 2216, 2216, 2235, 2246, 3480 ], [ 3483, 3483, 3509, 3509, 3634 ], [ 3636, 3636, 3655, 3655, 3764 ], [ 3796, 3796, 3823, 3836, 5333 ], [ 5336, 5336, 5393, 5393, 5575 ] ]
//value noise hash
float hash31(vec3 p3) {
p3 = fract(p3 * MOD3); p3 += dot(p3, p3.yzx + 19.19); return -1.0 + 2.0 * fract((p3.x + p3.y) * p3.z); }
//value noise hash float hash31(vec3 p3) {
21
43
NdfBDl
jackakers13
2022-02-22T10:11:58
// Created by Jack Akers on February 22, 2022. // Made available under the CC0 license - https://creativecommons.org/publicdomain/zero/1.0/ void mainImage(out vec4 fragColor, in vec2 fragCoord) { // Spiral vec2 center = vec2(iResolution.x/2.0, iResolution.y/2.0); float dist = distance(center, fragCoord); float angle = atan(fragCoord.y - iResolution.y/2.0, fragCoord.x - iResolution.x/2.0); float col = cos(0.25 * dist + angle + 4.0 * iTime); // Fade float distToEdge = distance(center, vec2(iResolution.x/2.0, iResolution.y)); float percentDistToEdge = clamp(dist / distToEdge, 0.0, 1.0); col = mix(0.0, col, 1.0 - percentDistToEdge); // Return fragColor = vec4(vec3(col), 1.0); }
cc0-1.0
[ 0, 140, 195, 214, 746 ]
[ [ 0, 140, 195, 214, 746 ] ]
// Created by Jack Akers on February 22, 2022. // Made available under the CC0 license - https://creativecommons.org/publicdomain/zero/1.0/
void mainImage(out vec4 fragColor, in vec2 fragCoord) {
vec2 center = vec2(iResolution.x/2.0, iResolution.y/2.0); float dist = distance(center, fragCoord); float angle = atan(fragCoord.y - iResolution.y/2.0, fragCoord.x - iResolution.x/2.0); float col = cos(0.25 * dist + angle + 4.0 * iTime); // Fade float distToEdge = distance(center, vec2(iResolution.x/2.0, iResolution.y)); float percentDistToEdge = clamp(dist / distToEdge, 0.0, 1.0); col = mix(0.0, col, 1.0 - percentDistToEdge); // Return fragColor = vec4(vec3(col), 1.0); }
// Created by Jack Akers on February 22, 2022. // Made available under the CC0 license - https://creativecommons.org/publicdomain/zero/1.0/ void mainImage(out vec4 fragColor, in vec2 fragCoord) {
1
901
NdsfW4
mrange
2022-02-14T20:37:08
// License CC0: Into the techno dome // A simple extension of "Follow the Light" I made earlier. // The tunnel forks and the fork is picked randomly. // Thought it turned out nice. // Based on: https://www.shadertoy.com/view/XsBXWt #define PI 3.141592654 #define TAU (2.0*PI) #define TIME iTime #define RESOLUTION iResolution #define ROT(a) mat2(cos(a), sin(a), -sin(a), cos(a)) #define TOLERANCE 0.00001 #define MAX_RAY_LENGTH 17.0 #define MAX_RAY_MARCHES 70 #define NORM_OFF 0.0001 #define PCOS(x) (0.5 + 0.5*cos(x)) #define TWISTS #if defined(TWISTS) #define PATHA (0.75*vec2(0.1147, 0.2093)) #define PATHB (0.5*vec2(13.0, 3.0)) vec3 cam(float z) { return vec3(sin(z*PATHA)*PATHB, z); } vec3 dcam(float z) { return vec3(PATHA*PATHB*cos(PATHA*z), 1.0); } vec3 ddcam(float z) { return vec3(-PATHA*PATHA*PATHB*sin(PATHA*z), 0.0); } #else vec3 cam(float z) { return vec3(0.0, 0.0, z); } vec3 dcam(float z) { return vec3(0.0, 0.0, 1.0); } vec3 ddcam(float z) { return vec3(0.0); } #endif // License: Unknown, author: Unknown, found: don't remember float tanh_approx(float x) { // return tanh(x); float x2 = x*x; return clamp(x*(27.0 + x2)/(27.0+9.0*x2), -1.0, 1.0); } // License: Unknown, author: Unknown, found: don't remember float hash(float co) { return fract(sin(co*12.9898) * 13758.5453); } // License: MIT, author: Inigo Quilez, found: https://iquilezles.org/articles/smin float pmin(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 pabs(float a, float k) { return -pmin(a, -a, k); } // License: MIT, author: Inigo Quilez, found: https://iquilezles.org/articles/spherefunctions float sphered(vec3 ro, vec3 rd, vec4 sph, float dbuffer) { float ndbuffer = dbuffer/sph.w; vec3 rc = (ro - sph.xyz)/sph.w; float b = dot(rd,rc); float c = dot(rc,rc) - 1.0; float h = b*b - c; if( h<0.0 ) return 0.0; h = sqrt( h ); float t1 = -b - h; float t2 = -b + h; if( t2<0.0 || t1>ndbuffer ) return 0.0; t1 = max( t1, 0.0 ); t2 = min( t2, ndbuffer ); float i1 = -(c*t1 + b*t1*t1 + t1*t1*t1/3.0); float i2 = -(c*t2 + b*t2*t2 + t2*t2*t2/3.0); return (i2-i1)*(3.0/4.0); } // "Amazing Surface" fractal // https://www.shadertoy.com/view/XsBXWt vec4 formula(vec4 p) { p.xz = abs(p.xz+1.)-abs(p.xz-1.)-p.xz; p.y-=.25; p.xy*=ROT(radians(30.0)); p=p*2.0/clamp(dot(p.xyz,p.xyz),0.24,1.0); return p; } vec3 g_trap0 = vec3(0.0); float fractal(vec3 pos) { vec3 tpos =pos; const float sz = 6.0; tpos.z = abs(0.5*sz-mod(tpos.z, sz)); vec4 p = vec4(tpos,1.); vec3 trap0pos = vec3(-2., 0.2, -3.0); vec3 trap0 = vec3(1E6); for (int i=0; i < 4; ++i) { p = formula(p); trap0 = min(trap0, abs(p.xyz-trap0pos)); } g_trap0 = trap0; float fr=(length(max(vec3(0.),p.xyz-1.5))-1.0)/p.w; return fr; } float df(vec3 p) { // Space distortion found somewhere on shadertoy, don't remember where vec3 wrap = cam(p.z); vec3 wrapDeriv = normalize(dcam(p.z)); p.xy -= wrap.xy; p -= wrapDeriv*dot(vec3(p.xy, 0), wrapDeriv)*0.5*vec3(1,1,-1); #if defined(TWISTS) vec3 ddcam = ddcam(p.z); p.xy *= ROT(-16.0*ddcam.x); #endif // Splits the tunnel const float splitDist = 50.0; float mz = mod(p.z, splitDist); float n = floor(p.z/splitDist); float h = hash(n); float off = 1.75*smoothstep(15.0, 35.0, mz); p.x -= h>0.5 ? off : -off; p.x = abs(p.x); p.x -= 1.0+off; p.y = -pabs(p.y, 1.5); p.y -= -1.5; return fractal(p); } float rayMarch(vec3 ro, vec3 rd, out int iter) { float t = 0.0; int i = 0; for (i = 0; i < MAX_RAY_MARCHES; i++) { float d = df(ro + rd*t); if (d < TOLERANCE || t > MAX_RAY_LENGTH) break; t += d; } iter = i; return t; } vec3 normal(vec3 pos) { vec2 eps = vec2(NORM_OFF,0.0); vec3 nor; nor.x = df(pos+eps.xyy) - df(pos-eps.xyy); nor.y = df(pos+eps.yxy) - df(pos-eps.yxy); nor.z = df(pos+eps.yyx) - df(pos-eps.yyx); return normalize(nor); } vec3 render(vec3 ro, vec3 rd) { vec3 lightPos = cam(ro.z+10.0); float alpha = 0.05*TIME; const vec3 skyCol = vec3(0.0); int iter = 0; float t = rayMarch(ro, rd, iter); vec3 trap0 = g_trap0; float pulse = smoothstep(0.0, 1.0, sin(TAU*TIME*0.25)); float sr = mix(2.0, 3.0, pulse); float sd = sphered(ro, rd, vec4(lightPos, sr), t); const vec3 bgcol = vec3(2.0, 1.0, 0.75).zyx; vec3 gcol = mix(1.0, 1.75, pulse)*sd*sd*bgcol; if (t >= MAX_RAY_LENGTH) { return gcol; } vec3 pos = ro + t*rd; vec3 nor = normal(pos); vec3 refl = reflect(rd, nor); float ii = float(iter)/float(MAX_RAY_MARCHES); vec3 lv = lightPos - pos; float ll2 = dot(lv, lv); float ll = sqrt(ll2); vec3 ld = lv / ll; float fre = abs(dot(rd, nor)); fre *= fre; fre *= fre; float dm = 4.0/ll2; float dif = pow(max(dot(nor,ld),0.0), 1.0); float spe = fre*pow(max(dot(refl, ld), 0.), 10.); float fo = smoothstep(0.9, 0.4, t/MAX_RAY_LENGTH); float ao = 1.0-ii; vec3 col = vec3(0.0); col += pow(smoothstep(0.5, 1.0, trap0.x*0.25)*1.3, mix(6.0, 2.0, pulse))*0.5*bgcol*mix(0.75, 2.25, pulse); col += smoothstep(0.7, 0.6, trap0.z)*smoothstep(0.4, 0.5, trap0.z)*ao*bgcol*mix(0.2, 1.4, pulse); col += spe*bgcol*mix(0.66, 1.75, pulse); col *= 1.0-sd*sd; col *= fo; col += gcol; return col; } vec3 effect3d(vec2 p, vec2 q) { float z = TIME*2.5; vec3 cam = cam(z); vec3 dcam = dcam(z); vec3 ddcam= ddcam(z); vec3 ro = cam; vec3 ww = normalize(dcam); vec3 uu = normalize(cross(vec3(0.0,1.0,0.0)+ddcam*06.0, ww )); vec3 vv = normalize(cross(ww,uu)); const float fov = 2.0/tanh(TAU/6.0); vec3 rd = normalize(-p.x*uu + p.y*vv + fov*ww ); return render(ro, rd); } // License: Unknown, author: nmz (twitter: @stormoid), found: https://www.shadertoy.com/view/NdfyRM float sRGB(float t) { return mix(1.055*pow(t, 1./2.4) - 0.055, 12.92*t, step(t, 0.0031308)); } // License: Unknown, author: nmz (twitter: @stormoid), found: https://www.shadertoy.com/view/NdfyRM vec3 sRGB(in vec3 c) { return vec3 (sRGB(c.x), sRGB(c.y), sRGB(c.z)); } void mainImage(out vec4 fragColor, in vec2 fragCoord) { vec2 q = fragCoord/RESOLUTION.xy; vec2 p = -1. + 2. * q; p.x *= RESOLUTION.x/RESOLUTION.y; vec3 col = effect3d(p, q); col = sRGB(col); fragColor = vec4(col, 1.0); }
cc0-1.0
[ 1282, 1342, 1364, 1364, 1412 ]
[ [ 1096, 1156, 1184, 1204, 1280 ], [ 1282, 1342, 1364, 1364, 1412 ], [ 1414, 1497, 1536, 1536, 1625 ], [ 1627, 1627, 1657, 1657, 1685 ], [ 1687, 1781, 1839, 1839, 2320 ], [ 2322, 2392, 2414, 2414, 2553 ], [ 2583, 2583, 2608, 2608, 2985 ], [ 2987, 2987, 3005, 3078, 3637 ], [ 3639, 3639, 3687, 3687, 3882 ], [ 3884, 3884, 3907, 3907, 4115 ], [ 4117, 4117, 4148, 4148, 5487 ], [ 5489, 5489, 5520, 5520, 5884 ], [ 5886, 5986, 6007, 6007, 6080 ], [ 6081, 6181, 6203, 6203, 6252 ], [ 6254, 6254, 6309, 6309, 6486 ] ]
// License: Unknown, author: Unknown, found: don't remember
float hash(float co) {
return fract(sin(co*12.9898) * 13758.5453); }
// License: Unknown, author: Unknown, found: don't remember float hash(float co) {
48
58
7sXfDH
mrange
2022-02-13T22:28:54
// License CC0: Follow the light // Result after messing around on sunday night // Based on an old favorite: https://www.shadertoy.com/view/XsBXWt #define PI 3.141592654 #define TAU (2.0*PI) #define TIME iTime #define RESOLUTION iResolution #define ROT(a) mat2(cos(a), sin(a), -sin(a), cos(a)) #define TOLERANCE 0.00001 #define MAX_RAY_LENGTH 17.0 #define MAX_RAY_MARCHES 60 #define NORM_OFF 0.0001 #define TWISTS #if defined(TWISTS) #define PATHA (0.75*vec2(0.1147, 0.2093)) #define PATHB (0.5*vec2(13.0, 3.0)) vec3 cam(float z) { return vec3(sin(z*PATHA)*PATHB, z); } vec3 dcam(float z) { return vec3(PATHA*PATHB*cos(PATHA*z), 1.0); } vec3 ddcam(float z) { return vec3(-PATHA*PATHA*PATHB*sin(PATHA*z), 0.0); } #else vec3 cam(float z) { return vec3(0.0, 0.0, z); } vec3 dcam(float z) { return vec3(0.0, 0.0, 1.0); } vec3 ddcam(float z) { return vec3(0.0); } #endif // License: Unknown, author: nmz (twitter: @stormoid), found: https://www.shadertoy.com/view/NdfyRM float sRGB(float t) { return mix(1.055*pow(t, 1./2.4) - 0.055, 12.92*t, step(t, 0.0031308)); } // License: Unknown, author: nmz (twitter: @stormoid), found: https://www.shadertoy.com/view/NdfyRM vec3 sRGB(in vec3 c) { return vec3 (sRGB(c.x), sRGB(c.y), sRGB(c.z)); } // License: Unknown, author: Unknown, found: don't remember float tanh_approx(float x) { // return tanh(x); float x2 = x*x; return clamp(x*(27.0 + x2)/(27.0+9.0*x2), -1.0, 1.0); } // License: MIT, author: Inigo Quilez, found: https://iquilezles.org/articles/smin float pmin(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 pabs(float a, float k) { return -pmin(a, -a, k); } // License: MIT, author: Inigo Quilez, found: https://iquilezles.org/articles/spherefunctions float sphered(vec3 ro, vec3 rd, vec4 sph, float dbuffer) { float ndbuffer = dbuffer/sph.w; vec3 rc = (ro - sph.xyz)/sph.w; float b = dot(rd,rc); float c = dot(rc,rc) - 1.0; float h = b*b - c; if( h<0.0 ) return 0.0; h = sqrt( h ); float t1 = -b - h; float t2 = -b + h; if( t2<0.0 || t1>ndbuffer ) return 0.0; t1 = max( t1, 0.0 ); t2 = min( t2, ndbuffer ); float i1 = -(c*t1 + b*t1*t1 + t1*t1*t1/3.0); float i2 = -(c*t2 + b*t2*t2 + t2*t2*t2/3.0); return (i2-i1)*(3.0/4.0); } // "Amazing Surface" fractal // https://www.shadertoy.com/view/XsBXWt vec4 formula(vec4 p) { p.xz = abs(p.xz+1.)-abs(p.xz-1.)-p.xz; p.y-=.25; p.xy*=ROT(radians(30.0)); p=p*2.0/clamp(dot(p.xyz,p.xyz),0.24,1.0); return p; } vec3 g_trap0 = vec3(0.0); float rail(vec3 pos) { vec3 tpos =pos; tpos.z = abs(3.-mod(tpos.z, 6.)); vec4 p = vec4(tpos,1.); vec3 trap0pos = vec3(-2., 0.2, -3.0); vec3 trap0 = vec3(1E6); for (int i=0; i < 4; ++i) { p = formula(p); trap0 = min(trap0, abs(p.xyz-trap0pos)); } g_trap0 = trap0; float fr=(length(max(vec3(0.),p.xyz-1.5))-1.0)/p.w; return fr; } float df(vec3 p) { // Space distortion found somewhere on shadertoy, don't remember where vec3 wrap = cam(p.z); vec3 wrapDeriv = normalize(dcam(p.z)); p.xy -= wrap.xy; p -= wrapDeriv*dot(vec3(p.xy, 0), wrapDeriv)*0.5*vec3(1,1,-1); #if defined(TWISTS) vec3 ddcam = ddcam(p.z); p.xy *= ROT(-16.0*ddcam.x); #endif p.x -= 1.0; p.y = -pabs(p.y, 1.5); p.y -= -1.5; float dr = rail(p); return dr; } float rayMarch(vec3 ro, vec3 rd, out int iter) { float t = 0.0; int i = 0; for (i = 0; i < MAX_RAY_MARCHES; i++) { float d = df(ro + rd*t); if (d < TOLERANCE || t > MAX_RAY_LENGTH) break; t += d; } iter = i; return t; } vec3 normal(vec3 pos) { vec2 eps = vec2(NORM_OFF,0.0); vec3 nor; nor.x = df(pos+eps.xyy) - df(pos-eps.xyy); nor.y = df(pos+eps.yxy) - df(pos-eps.yxy); nor.z = df(pos+eps.yyx) - df(pos-eps.yyx); return normalize(nor); } vec3 render(vec3 ro, vec3 rd) { const vec3 bgcol = vec3(2.0, 1.0, 0.75).zyx; vec3 lightPos = cam(ro.z+10.0); int iter = 0; float t = rayMarch(ro, rd, iter); vec3 trap0 = g_trap0; float pulse = smoothstep(0.0, 1.0, sin(TAU*TIME*0.25)); float sr = mix(2.0, 3.0, pulse); float sd = sphered(ro, rd, vec4(lightPos, sr), t); vec3 gcol = mix(1.0, 1.75, pulse)*sd*sd*bgcol; if (t >= MAX_RAY_LENGTH) { return gcol; } vec3 pos = ro + t*rd; vec3 nor = normal(pos); vec3 refl = reflect(rd, nor); float ii = float(iter)/float(MAX_RAY_MARCHES); vec3 ld = normalize(lightPos - pos); float fre = abs(dot(rd, nor)); fre *= fre; fre *= fre; float spe = fre*pow(max(dot(refl, ld), 0.), 10.); float fo = smoothstep(0.9, 0.4, t/MAX_RAY_LENGTH); float ao = 1.0-ii; vec3 col = vec3(0.0); col += pow(smoothstep(0.5, 1.0, trap0.x*0.25)*1.3, mix(6.0, 2.0, pulse))*0.5*bgcol*mix(0.5, 1.6, pulse); col += smoothstep(0.7, 0.6, trap0.z)*smoothstep(0.4, 0.5, trap0.z)*ao*bgcol*mix(0.05, 0.4, pulse); col += spe*bgcol*mix(0.66, 1.5, pulse); col *= 1.0-sd*sd; col *= fo; col += gcol; return col; } vec3 effect3d(vec2 p, vec2 q) { float z = TIME*2.5; vec3 cam = cam(z); vec3 dcam = dcam(z); vec3 ddcam= ddcam(z); vec3 ro = cam; vec3 ww = normalize(dcam); vec3 uu = normalize(cross(vec3(0.0,1.0,0.0)+ddcam*4.0, ww )); vec3 vv = normalize(cross(ww,uu)); const float fov = 2.0/tanh(TAU/6.0); vec3 rd = normalize(-p.x*uu + p.y*vv + fov*ww ); return render(ro, rd); } void mainImage(out vec4 fragColor, in vec2 fragCoord) { vec2 q = fragCoord/RESOLUTION.xy; vec2 p = -1. + 2. * q; p.x *= RESOLUTION.x/RESOLUTION.y; vec3 col = effect3d(p, q); col = sRGB(col); fragColor = vec4(col, 1.0); }
cc0-1.0
[ 968, 1068, 1089, 1089, 1162 ]
[ [ 968, 1068, 1089, 1089, 1162 ], [ 1163, 1263, 1285, 1285, 1334 ], [ 1336, 1396, 1424, 1444, 1520 ], [ 1522, 1605, 1644, 1644, 1733 ], [ 1735, 1735, 1765, 1765, 1793 ], [ 1795, 1889, 1947, 1947, 2428 ], [ 2430, 2500, 2522, 2522, 2661 ], [ 2691, 2691, 2713, 2713, 3062 ], [ 3064, 3064, 3082, 3155, 3487 ], [ 3489, 3489, 3537, 3537, 3732 ], [ 3734, 3734, 3757, 3757, 3965 ], [ 3967, 3967, 3998, 3998, 5131 ], [ 5133, 5133, 5164, 5164, 5528 ], [ 5530, 5530, 5585, 5585, 5762 ] ]
// License: Unknown, author: nmz (twitter: @stormoid), found: https://www.shadertoy.com/view/NdfyRM
float sRGB(float t) {
return mix(1.055*pow(t, 1./2.4) - 0.055, 12.92*t, step(t, 0.0031308)); }
// License: Unknown, author: nmz (twitter: @stormoid), found: https://www.shadertoy.com/view/NdfyRM float sRGB(float t) {
21
21
7sXfDH
mrange
2022-02-13T22:28:54
// License CC0: Follow the light // Result after messing around on sunday night // Based on an old favorite: https://www.shadertoy.com/view/XsBXWt #define PI 3.141592654 #define TAU (2.0*PI) #define TIME iTime #define RESOLUTION iResolution #define ROT(a) mat2(cos(a), sin(a), -sin(a), cos(a)) #define TOLERANCE 0.00001 #define MAX_RAY_LENGTH 17.0 #define MAX_RAY_MARCHES 60 #define NORM_OFF 0.0001 #define TWISTS #if defined(TWISTS) #define PATHA (0.75*vec2(0.1147, 0.2093)) #define PATHB (0.5*vec2(13.0, 3.0)) vec3 cam(float z) { return vec3(sin(z*PATHA)*PATHB, z); } vec3 dcam(float z) { return vec3(PATHA*PATHB*cos(PATHA*z), 1.0); } vec3 ddcam(float z) { return vec3(-PATHA*PATHA*PATHB*sin(PATHA*z), 0.0); } #else vec3 cam(float z) { return vec3(0.0, 0.0, z); } vec3 dcam(float z) { return vec3(0.0, 0.0, 1.0); } vec3 ddcam(float z) { return vec3(0.0); } #endif // License: Unknown, author: nmz (twitter: @stormoid), found: https://www.shadertoy.com/view/NdfyRM float sRGB(float t) { return mix(1.055*pow(t, 1./2.4) - 0.055, 12.92*t, step(t, 0.0031308)); } // License: Unknown, author: nmz (twitter: @stormoid), found: https://www.shadertoy.com/view/NdfyRM vec3 sRGB(in vec3 c) { return vec3 (sRGB(c.x), sRGB(c.y), sRGB(c.z)); } // License: Unknown, author: Unknown, found: don't remember float tanh_approx(float x) { // return tanh(x); float x2 = x*x; return clamp(x*(27.0 + x2)/(27.0+9.0*x2), -1.0, 1.0); } // License: MIT, author: Inigo Quilez, found: https://iquilezles.org/articles/smin float pmin(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 pabs(float a, float k) { return -pmin(a, -a, k); } // License: MIT, author: Inigo Quilez, found: https://iquilezles.org/articles/spherefunctions float sphered(vec3 ro, vec3 rd, vec4 sph, float dbuffer) { float ndbuffer = dbuffer/sph.w; vec3 rc = (ro - sph.xyz)/sph.w; float b = dot(rd,rc); float c = dot(rc,rc) - 1.0; float h = b*b - c; if( h<0.0 ) return 0.0; h = sqrt( h ); float t1 = -b - h; float t2 = -b + h; if( t2<0.0 || t1>ndbuffer ) return 0.0; t1 = max( t1, 0.0 ); t2 = min( t2, ndbuffer ); float i1 = -(c*t1 + b*t1*t1 + t1*t1*t1/3.0); float i2 = -(c*t2 + b*t2*t2 + t2*t2*t2/3.0); return (i2-i1)*(3.0/4.0); } // "Amazing Surface" fractal // https://www.shadertoy.com/view/XsBXWt vec4 formula(vec4 p) { p.xz = abs(p.xz+1.)-abs(p.xz-1.)-p.xz; p.y-=.25; p.xy*=ROT(radians(30.0)); p=p*2.0/clamp(dot(p.xyz,p.xyz),0.24,1.0); return p; } vec3 g_trap0 = vec3(0.0); float rail(vec3 pos) { vec3 tpos =pos; tpos.z = abs(3.-mod(tpos.z, 6.)); vec4 p = vec4(tpos,1.); vec3 trap0pos = vec3(-2., 0.2, -3.0); vec3 trap0 = vec3(1E6); for (int i=0; i < 4; ++i) { p = formula(p); trap0 = min(trap0, abs(p.xyz-trap0pos)); } g_trap0 = trap0; float fr=(length(max(vec3(0.),p.xyz-1.5))-1.0)/p.w; return fr; } float df(vec3 p) { // Space distortion found somewhere on shadertoy, don't remember where vec3 wrap = cam(p.z); vec3 wrapDeriv = normalize(dcam(p.z)); p.xy -= wrap.xy; p -= wrapDeriv*dot(vec3(p.xy, 0), wrapDeriv)*0.5*vec3(1,1,-1); #if defined(TWISTS) vec3 ddcam = ddcam(p.z); p.xy *= ROT(-16.0*ddcam.x); #endif p.x -= 1.0; p.y = -pabs(p.y, 1.5); p.y -= -1.5; float dr = rail(p); return dr; } float rayMarch(vec3 ro, vec3 rd, out int iter) { float t = 0.0; int i = 0; for (i = 0; i < MAX_RAY_MARCHES; i++) { float d = df(ro + rd*t); if (d < TOLERANCE || t > MAX_RAY_LENGTH) break; t += d; } iter = i; return t; } vec3 normal(vec3 pos) { vec2 eps = vec2(NORM_OFF,0.0); vec3 nor; nor.x = df(pos+eps.xyy) - df(pos-eps.xyy); nor.y = df(pos+eps.yxy) - df(pos-eps.yxy); nor.z = df(pos+eps.yyx) - df(pos-eps.yyx); return normalize(nor); } vec3 render(vec3 ro, vec3 rd) { const vec3 bgcol = vec3(2.0, 1.0, 0.75).zyx; vec3 lightPos = cam(ro.z+10.0); int iter = 0; float t = rayMarch(ro, rd, iter); vec3 trap0 = g_trap0; float pulse = smoothstep(0.0, 1.0, sin(TAU*TIME*0.25)); float sr = mix(2.0, 3.0, pulse); float sd = sphered(ro, rd, vec4(lightPos, sr), t); vec3 gcol = mix(1.0, 1.75, pulse)*sd*sd*bgcol; if (t >= MAX_RAY_LENGTH) { return gcol; } vec3 pos = ro + t*rd; vec3 nor = normal(pos); vec3 refl = reflect(rd, nor); float ii = float(iter)/float(MAX_RAY_MARCHES); vec3 ld = normalize(lightPos - pos); float fre = abs(dot(rd, nor)); fre *= fre; fre *= fre; float spe = fre*pow(max(dot(refl, ld), 0.), 10.); float fo = smoothstep(0.9, 0.4, t/MAX_RAY_LENGTH); float ao = 1.0-ii; vec3 col = vec3(0.0); col += pow(smoothstep(0.5, 1.0, trap0.x*0.25)*1.3, mix(6.0, 2.0, pulse))*0.5*bgcol*mix(0.5, 1.6, pulse); col += smoothstep(0.7, 0.6, trap0.z)*smoothstep(0.4, 0.5, trap0.z)*ao*bgcol*mix(0.05, 0.4, pulse); col += spe*bgcol*mix(0.66, 1.5, pulse); col *= 1.0-sd*sd; col *= fo; col += gcol; return col; } vec3 effect3d(vec2 p, vec2 q) { float z = TIME*2.5; vec3 cam = cam(z); vec3 dcam = dcam(z); vec3 ddcam= ddcam(z); vec3 ro = cam; vec3 ww = normalize(dcam); vec3 uu = normalize(cross(vec3(0.0,1.0,0.0)+ddcam*4.0, ww )); vec3 vv = normalize(cross(ww,uu)); const float fov = 2.0/tanh(TAU/6.0); vec3 rd = normalize(-p.x*uu + p.y*vv + fov*ww ); return render(ro, rd); } void mainImage(out vec4 fragColor, in vec2 fragCoord) { vec2 q = fragCoord/RESOLUTION.xy; vec2 p = -1. + 2. * q; p.x *= RESOLUTION.x/RESOLUTION.y; vec3 col = effect3d(p, q); col = sRGB(col); fragColor = vec4(col, 1.0); }
cc0-1.0
[ 1163, 1263, 1285, 1285, 1334 ]
[ [ 968, 1068, 1089, 1089, 1162 ], [ 1163, 1263, 1285, 1285, 1334 ], [ 1336, 1396, 1424, 1444, 1520 ], [ 1522, 1605, 1644, 1644, 1733 ], [ 1735, 1735, 1765, 1765, 1793 ], [ 1795, 1889, 1947, 1947, 2428 ], [ 2430, 2500, 2522, 2522, 2661 ], [ 2691, 2691, 2713, 2713, 3062 ], [ 3064, 3064, 3082, 3155, 3487 ], [ 3489, 3489, 3537, 3537, 3732 ], [ 3734, 3734, 3757, 3757, 3965 ], [ 3967, 3967, 3998, 3998, 5131 ], [ 5133, 5133, 5164, 5164, 5528 ], [ 5530, 5530, 5585, 5585, 5762 ] ]
// License: Unknown, author: nmz (twitter: @stormoid), found: https://www.shadertoy.com/view/NdfyRM
vec3 sRGB(in vec3 c) {
return vec3 (sRGB(c.x), sRGB(c.y), sRGB(c.z)); }
// License: Unknown, author: nmz (twitter: @stormoid), found: https://www.shadertoy.com/view/NdfyRM vec3 sRGB(in vec3 c) {
23
24
7sXfDH
mrange
2022-02-13T22:28:54
// License CC0: Follow the light // Result after messing around on sunday night // Based on an old favorite: https://www.shadertoy.com/view/XsBXWt #define PI 3.141592654 #define TAU (2.0*PI) #define TIME iTime #define RESOLUTION iResolution #define ROT(a) mat2(cos(a), sin(a), -sin(a), cos(a)) #define TOLERANCE 0.00001 #define MAX_RAY_LENGTH 17.0 #define MAX_RAY_MARCHES 60 #define NORM_OFF 0.0001 #define TWISTS #if defined(TWISTS) #define PATHA (0.75*vec2(0.1147, 0.2093)) #define PATHB (0.5*vec2(13.0, 3.0)) vec3 cam(float z) { return vec3(sin(z*PATHA)*PATHB, z); } vec3 dcam(float z) { return vec3(PATHA*PATHB*cos(PATHA*z), 1.0); } vec3 ddcam(float z) { return vec3(-PATHA*PATHA*PATHB*sin(PATHA*z), 0.0); } #else vec3 cam(float z) { return vec3(0.0, 0.0, z); } vec3 dcam(float z) { return vec3(0.0, 0.0, 1.0); } vec3 ddcam(float z) { return vec3(0.0); } #endif // License: Unknown, author: nmz (twitter: @stormoid), found: https://www.shadertoy.com/view/NdfyRM float sRGB(float t) { return mix(1.055*pow(t, 1./2.4) - 0.055, 12.92*t, step(t, 0.0031308)); } // License: Unknown, author: nmz (twitter: @stormoid), found: https://www.shadertoy.com/view/NdfyRM vec3 sRGB(in vec3 c) { return vec3 (sRGB(c.x), sRGB(c.y), sRGB(c.z)); } // License: Unknown, author: Unknown, found: don't remember float tanh_approx(float x) { // return tanh(x); float x2 = x*x; return clamp(x*(27.0 + x2)/(27.0+9.0*x2), -1.0, 1.0); } // License: MIT, author: Inigo Quilez, found: https://iquilezles.org/articles/smin float pmin(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 pabs(float a, float k) { return -pmin(a, -a, k); } // License: MIT, author: Inigo Quilez, found: https://iquilezles.org/articles/spherefunctions float sphered(vec3 ro, vec3 rd, vec4 sph, float dbuffer) { float ndbuffer = dbuffer/sph.w; vec3 rc = (ro - sph.xyz)/sph.w; float b = dot(rd,rc); float c = dot(rc,rc) - 1.0; float h = b*b - c; if( h<0.0 ) return 0.0; h = sqrt( h ); float t1 = -b - h; float t2 = -b + h; if( t2<0.0 || t1>ndbuffer ) return 0.0; t1 = max( t1, 0.0 ); t2 = min( t2, ndbuffer ); float i1 = -(c*t1 + b*t1*t1 + t1*t1*t1/3.0); float i2 = -(c*t2 + b*t2*t2 + t2*t2*t2/3.0); return (i2-i1)*(3.0/4.0); } // "Amazing Surface" fractal // https://www.shadertoy.com/view/XsBXWt vec4 formula(vec4 p) { p.xz = abs(p.xz+1.)-abs(p.xz-1.)-p.xz; p.y-=.25; p.xy*=ROT(radians(30.0)); p=p*2.0/clamp(dot(p.xyz,p.xyz),0.24,1.0); return p; } vec3 g_trap0 = vec3(0.0); float rail(vec3 pos) { vec3 tpos =pos; tpos.z = abs(3.-mod(tpos.z, 6.)); vec4 p = vec4(tpos,1.); vec3 trap0pos = vec3(-2., 0.2, -3.0); vec3 trap0 = vec3(1E6); for (int i=0; i < 4; ++i) { p = formula(p); trap0 = min(trap0, abs(p.xyz-trap0pos)); } g_trap0 = trap0; float fr=(length(max(vec3(0.),p.xyz-1.5))-1.0)/p.w; return fr; } float df(vec3 p) { // Space distortion found somewhere on shadertoy, don't remember where vec3 wrap = cam(p.z); vec3 wrapDeriv = normalize(dcam(p.z)); p.xy -= wrap.xy; p -= wrapDeriv*dot(vec3(p.xy, 0), wrapDeriv)*0.5*vec3(1,1,-1); #if defined(TWISTS) vec3 ddcam = ddcam(p.z); p.xy *= ROT(-16.0*ddcam.x); #endif p.x -= 1.0; p.y = -pabs(p.y, 1.5); p.y -= -1.5; float dr = rail(p); return dr; } float rayMarch(vec3 ro, vec3 rd, out int iter) { float t = 0.0; int i = 0; for (i = 0; i < MAX_RAY_MARCHES; i++) { float d = df(ro + rd*t); if (d < TOLERANCE || t > MAX_RAY_LENGTH) break; t += d; } iter = i; return t; } vec3 normal(vec3 pos) { vec2 eps = vec2(NORM_OFF,0.0); vec3 nor; nor.x = df(pos+eps.xyy) - df(pos-eps.xyy); nor.y = df(pos+eps.yxy) - df(pos-eps.yxy); nor.z = df(pos+eps.yyx) - df(pos-eps.yyx); return normalize(nor); } vec3 render(vec3 ro, vec3 rd) { const vec3 bgcol = vec3(2.0, 1.0, 0.75).zyx; vec3 lightPos = cam(ro.z+10.0); int iter = 0; float t = rayMarch(ro, rd, iter); vec3 trap0 = g_trap0; float pulse = smoothstep(0.0, 1.0, sin(TAU*TIME*0.25)); float sr = mix(2.0, 3.0, pulse); float sd = sphered(ro, rd, vec4(lightPos, sr), t); vec3 gcol = mix(1.0, 1.75, pulse)*sd*sd*bgcol; if (t >= MAX_RAY_LENGTH) { return gcol; } vec3 pos = ro + t*rd; vec3 nor = normal(pos); vec3 refl = reflect(rd, nor); float ii = float(iter)/float(MAX_RAY_MARCHES); vec3 ld = normalize(lightPos - pos); float fre = abs(dot(rd, nor)); fre *= fre; fre *= fre; float spe = fre*pow(max(dot(refl, ld), 0.), 10.); float fo = smoothstep(0.9, 0.4, t/MAX_RAY_LENGTH); float ao = 1.0-ii; vec3 col = vec3(0.0); col += pow(smoothstep(0.5, 1.0, trap0.x*0.25)*1.3, mix(6.0, 2.0, pulse))*0.5*bgcol*mix(0.5, 1.6, pulse); col += smoothstep(0.7, 0.6, trap0.z)*smoothstep(0.4, 0.5, trap0.z)*ao*bgcol*mix(0.05, 0.4, pulse); col += spe*bgcol*mix(0.66, 1.5, pulse); col *= 1.0-sd*sd; col *= fo; col += gcol; return col; } vec3 effect3d(vec2 p, vec2 q) { float z = TIME*2.5; vec3 cam = cam(z); vec3 dcam = dcam(z); vec3 ddcam= ddcam(z); vec3 ro = cam; vec3 ww = normalize(dcam); vec3 uu = normalize(cross(vec3(0.0,1.0,0.0)+ddcam*4.0, ww )); vec3 vv = normalize(cross(ww,uu)); const float fov = 2.0/tanh(TAU/6.0); vec3 rd = normalize(-p.x*uu + p.y*vv + fov*ww ); return render(ro, rd); } void mainImage(out vec4 fragColor, in vec2 fragCoord) { vec2 q = fragCoord/RESOLUTION.xy; vec2 p = -1. + 2. * q; p.x *= RESOLUTION.x/RESOLUTION.y; vec3 col = effect3d(p, q); col = sRGB(col); fragColor = vec4(col, 1.0); }
cc0-1.0
[ 1522, 1605, 1644, 1644, 1733 ]
[ [ 968, 1068, 1089, 1089, 1162 ], [ 1163, 1263, 1285, 1285, 1334 ], [ 1336, 1396, 1424, 1444, 1520 ], [ 1522, 1605, 1644, 1644, 1733 ], [ 1735, 1735, 1765, 1765, 1793 ], [ 1795, 1889, 1947, 1947, 2428 ], [ 2430, 2500, 2522, 2522, 2661 ], [ 2691, 2691, 2713, 2713, 3062 ], [ 3064, 3064, 3082, 3155, 3487 ], [ 3489, 3489, 3537, 3537, 3732 ], [ 3734, 3734, 3757, 3757, 3965 ], [ 3967, 3967, 3998, 3998, 5131 ], [ 5133, 5133, 5164, 5164, 5528 ], [ 5530, 5530, 5585, 5585, 5762 ] ]
// License: MIT, author: Inigo Quilez, found: https://iquilezles.org/articles/smin
float pmin(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); }
// License: MIT, author: Inigo Quilez, found: https://iquilezles.org/articles/smin float pmin(float a, float b, float k) {
22
107
7sXfDH
mrange
2022-02-13T22:28:54
// License CC0: Follow the light // Result after messing around on sunday night // Based on an old favorite: https://www.shadertoy.com/view/XsBXWt #define PI 3.141592654 #define TAU (2.0*PI) #define TIME iTime #define RESOLUTION iResolution #define ROT(a) mat2(cos(a), sin(a), -sin(a), cos(a)) #define TOLERANCE 0.00001 #define MAX_RAY_LENGTH 17.0 #define MAX_RAY_MARCHES 60 #define NORM_OFF 0.0001 #define TWISTS #if defined(TWISTS) #define PATHA (0.75*vec2(0.1147, 0.2093)) #define PATHB (0.5*vec2(13.0, 3.0)) vec3 cam(float z) { return vec3(sin(z*PATHA)*PATHB, z); } vec3 dcam(float z) { return vec3(PATHA*PATHB*cos(PATHA*z), 1.0); } vec3 ddcam(float z) { return vec3(-PATHA*PATHA*PATHB*sin(PATHA*z), 0.0); } #else vec3 cam(float z) { return vec3(0.0, 0.0, z); } vec3 dcam(float z) { return vec3(0.0, 0.0, 1.0); } vec3 ddcam(float z) { return vec3(0.0); } #endif // License: Unknown, author: nmz (twitter: @stormoid), found: https://www.shadertoy.com/view/NdfyRM float sRGB(float t) { return mix(1.055*pow(t, 1./2.4) - 0.055, 12.92*t, step(t, 0.0031308)); } // License: Unknown, author: nmz (twitter: @stormoid), found: https://www.shadertoy.com/view/NdfyRM vec3 sRGB(in vec3 c) { return vec3 (sRGB(c.x), sRGB(c.y), sRGB(c.z)); } // License: Unknown, author: Unknown, found: don't remember float tanh_approx(float x) { // return tanh(x); float x2 = x*x; return clamp(x*(27.0 + x2)/(27.0+9.0*x2), -1.0, 1.0); } // License: MIT, author: Inigo Quilez, found: https://iquilezles.org/articles/smin float pmin(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 pabs(float a, float k) { return -pmin(a, -a, k); } // License: MIT, author: Inigo Quilez, found: https://iquilezles.org/articles/spherefunctions float sphered(vec3 ro, vec3 rd, vec4 sph, float dbuffer) { float ndbuffer = dbuffer/sph.w; vec3 rc = (ro - sph.xyz)/sph.w; float b = dot(rd,rc); float c = dot(rc,rc) - 1.0; float h = b*b - c; if( h<0.0 ) return 0.0; h = sqrt( h ); float t1 = -b - h; float t2 = -b + h; if( t2<0.0 || t1>ndbuffer ) return 0.0; t1 = max( t1, 0.0 ); t2 = min( t2, ndbuffer ); float i1 = -(c*t1 + b*t1*t1 + t1*t1*t1/3.0); float i2 = -(c*t2 + b*t2*t2 + t2*t2*t2/3.0); return (i2-i1)*(3.0/4.0); } // "Amazing Surface" fractal // https://www.shadertoy.com/view/XsBXWt vec4 formula(vec4 p) { p.xz = abs(p.xz+1.)-abs(p.xz-1.)-p.xz; p.y-=.25; p.xy*=ROT(radians(30.0)); p=p*2.0/clamp(dot(p.xyz,p.xyz),0.24,1.0); return p; } vec3 g_trap0 = vec3(0.0); float rail(vec3 pos) { vec3 tpos =pos; tpos.z = abs(3.-mod(tpos.z, 6.)); vec4 p = vec4(tpos,1.); vec3 trap0pos = vec3(-2., 0.2, -3.0); vec3 trap0 = vec3(1E6); for (int i=0; i < 4; ++i) { p = formula(p); trap0 = min(trap0, abs(p.xyz-trap0pos)); } g_trap0 = trap0; float fr=(length(max(vec3(0.),p.xyz-1.5))-1.0)/p.w; return fr; } float df(vec3 p) { // Space distortion found somewhere on shadertoy, don't remember where vec3 wrap = cam(p.z); vec3 wrapDeriv = normalize(dcam(p.z)); p.xy -= wrap.xy; p -= wrapDeriv*dot(vec3(p.xy, 0), wrapDeriv)*0.5*vec3(1,1,-1); #if defined(TWISTS) vec3 ddcam = ddcam(p.z); p.xy *= ROT(-16.0*ddcam.x); #endif p.x -= 1.0; p.y = -pabs(p.y, 1.5); p.y -= -1.5; float dr = rail(p); return dr; } float rayMarch(vec3 ro, vec3 rd, out int iter) { float t = 0.0; int i = 0; for (i = 0; i < MAX_RAY_MARCHES; i++) { float d = df(ro + rd*t); if (d < TOLERANCE || t > MAX_RAY_LENGTH) break; t += d; } iter = i; return t; } vec3 normal(vec3 pos) { vec2 eps = vec2(NORM_OFF,0.0); vec3 nor; nor.x = df(pos+eps.xyy) - df(pos-eps.xyy); nor.y = df(pos+eps.yxy) - df(pos-eps.yxy); nor.z = df(pos+eps.yyx) - df(pos-eps.yyx); return normalize(nor); } vec3 render(vec3 ro, vec3 rd) { const vec3 bgcol = vec3(2.0, 1.0, 0.75).zyx; vec3 lightPos = cam(ro.z+10.0); int iter = 0; float t = rayMarch(ro, rd, iter); vec3 trap0 = g_trap0; float pulse = smoothstep(0.0, 1.0, sin(TAU*TIME*0.25)); float sr = mix(2.0, 3.0, pulse); float sd = sphered(ro, rd, vec4(lightPos, sr), t); vec3 gcol = mix(1.0, 1.75, pulse)*sd*sd*bgcol; if (t >= MAX_RAY_LENGTH) { return gcol; } vec3 pos = ro + t*rd; vec3 nor = normal(pos); vec3 refl = reflect(rd, nor); float ii = float(iter)/float(MAX_RAY_MARCHES); vec3 ld = normalize(lightPos - pos); float fre = abs(dot(rd, nor)); fre *= fre; fre *= fre; float spe = fre*pow(max(dot(refl, ld), 0.), 10.); float fo = smoothstep(0.9, 0.4, t/MAX_RAY_LENGTH); float ao = 1.0-ii; vec3 col = vec3(0.0); col += pow(smoothstep(0.5, 1.0, trap0.x*0.25)*1.3, mix(6.0, 2.0, pulse))*0.5*bgcol*mix(0.5, 1.6, pulse); col += smoothstep(0.7, 0.6, trap0.z)*smoothstep(0.4, 0.5, trap0.z)*ao*bgcol*mix(0.05, 0.4, pulse); col += spe*bgcol*mix(0.66, 1.5, pulse); col *= 1.0-sd*sd; col *= fo; col += gcol; return col; } vec3 effect3d(vec2 p, vec2 q) { float z = TIME*2.5; vec3 cam = cam(z); vec3 dcam = dcam(z); vec3 ddcam= ddcam(z); vec3 ro = cam; vec3 ww = normalize(dcam); vec3 uu = normalize(cross(vec3(0.0,1.0,0.0)+ddcam*4.0, ww )); vec3 vv = normalize(cross(ww,uu)); const float fov = 2.0/tanh(TAU/6.0); vec3 rd = normalize(-p.x*uu + p.y*vv + fov*ww ); return render(ro, rd); } void mainImage(out vec4 fragColor, in vec2 fragCoord) { vec2 q = fragCoord/RESOLUTION.xy; vec2 p = -1. + 2. * q; p.x *= RESOLUTION.x/RESOLUTION.y; vec3 col = effect3d(p, q); col = sRGB(col); fragColor = vec4(col, 1.0); }
cc0-1.0
[ 1795, 1889, 1947, 1947, 2428 ]
[ [ 968, 1068, 1089, 1089, 1162 ], [ 1163, 1263, 1285, 1285, 1334 ], [ 1336, 1396, 1424, 1444, 1520 ], [ 1522, 1605, 1644, 1644, 1733 ], [ 1735, 1735, 1765, 1765, 1793 ], [ 1795, 1889, 1947, 1947, 2428 ], [ 2430, 2500, 2522, 2522, 2661 ], [ 2691, 2691, 2713, 2713, 3062 ], [ 3064, 3064, 3082, 3155, 3487 ], [ 3489, 3489, 3537, 3537, 3732 ], [ 3734, 3734, 3757, 3757, 3965 ], [ 3967, 3967, 3998, 3998, 5131 ], [ 5133, 5133, 5164, 5164, 5528 ], [ 5530, 5530, 5585, 5585, 5762 ] ]
// License: MIT, author: Inigo Quilez, found: https://iquilezles.org/articles/spherefunctions
float sphered(vec3 ro, vec3 rd, vec4 sph, float dbuffer) {
float ndbuffer = dbuffer/sph.w; vec3 rc = (ro - sph.xyz)/sph.w; float b = dot(rd,rc); float c = dot(rc,rc) - 1.0; float h = b*b - c; if( h<0.0 ) return 0.0; h = sqrt( h ); float t1 = -b - h; float t2 = -b + h; if( t2<0.0 || t1>ndbuffer ) return 0.0; t1 = max( t1, 0.0 ); t2 = min( t2, ndbuffer ); float i1 = -(c*t1 + b*t1*t1 + t1*t1*t1/3.0); float i2 = -(c*t2 + b*t2*t2 + t2*t2*t2/3.0); return (i2-i1)*(3.0/4.0); }
// License: MIT, author: Inigo Quilez, found: https://iquilezles.org/articles/spherefunctions float sphered(vec3 ro, vec3 rd, vec4 sph, float dbuffer) {
8
11
7sXfDH
mrange
2022-02-13T22:28:54
// License CC0: Follow the light // Result after messing around on sunday night // Based on an old favorite: https://www.shadertoy.com/view/XsBXWt #define PI 3.141592654 #define TAU (2.0*PI) #define TIME iTime #define RESOLUTION iResolution #define ROT(a) mat2(cos(a), sin(a), -sin(a), cos(a)) #define TOLERANCE 0.00001 #define MAX_RAY_LENGTH 17.0 #define MAX_RAY_MARCHES 60 #define NORM_OFF 0.0001 #define TWISTS #if defined(TWISTS) #define PATHA (0.75*vec2(0.1147, 0.2093)) #define PATHB (0.5*vec2(13.0, 3.0)) vec3 cam(float z) { return vec3(sin(z*PATHA)*PATHB, z); } vec3 dcam(float z) { return vec3(PATHA*PATHB*cos(PATHA*z), 1.0); } vec3 ddcam(float z) { return vec3(-PATHA*PATHA*PATHB*sin(PATHA*z), 0.0); } #else vec3 cam(float z) { return vec3(0.0, 0.0, z); } vec3 dcam(float z) { return vec3(0.0, 0.0, 1.0); } vec3 ddcam(float z) { return vec3(0.0); } #endif // License: Unknown, author: nmz (twitter: @stormoid), found: https://www.shadertoy.com/view/NdfyRM float sRGB(float t) { return mix(1.055*pow(t, 1./2.4) - 0.055, 12.92*t, step(t, 0.0031308)); } // License: Unknown, author: nmz (twitter: @stormoid), found: https://www.shadertoy.com/view/NdfyRM vec3 sRGB(in vec3 c) { return vec3 (sRGB(c.x), sRGB(c.y), sRGB(c.z)); } // License: Unknown, author: Unknown, found: don't remember float tanh_approx(float x) { // return tanh(x); float x2 = x*x; return clamp(x*(27.0 + x2)/(27.0+9.0*x2), -1.0, 1.0); } // License: MIT, author: Inigo Quilez, found: https://iquilezles.org/articles/smin float pmin(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 pabs(float a, float k) { return -pmin(a, -a, k); } // License: MIT, author: Inigo Quilez, found: https://iquilezles.org/articles/spherefunctions float sphered(vec3 ro, vec3 rd, vec4 sph, float dbuffer) { float ndbuffer = dbuffer/sph.w; vec3 rc = (ro - sph.xyz)/sph.w; float b = dot(rd,rc); float c = dot(rc,rc) - 1.0; float h = b*b - c; if( h<0.0 ) return 0.0; h = sqrt( h ); float t1 = -b - h; float t2 = -b + h; if( t2<0.0 || t1>ndbuffer ) return 0.0; t1 = max( t1, 0.0 ); t2 = min( t2, ndbuffer ); float i1 = -(c*t1 + b*t1*t1 + t1*t1*t1/3.0); float i2 = -(c*t2 + b*t2*t2 + t2*t2*t2/3.0); return (i2-i1)*(3.0/4.0); } // "Amazing Surface" fractal // https://www.shadertoy.com/view/XsBXWt vec4 formula(vec4 p) { p.xz = abs(p.xz+1.)-abs(p.xz-1.)-p.xz; p.y-=.25; p.xy*=ROT(radians(30.0)); p=p*2.0/clamp(dot(p.xyz,p.xyz),0.24,1.0); return p; } vec3 g_trap0 = vec3(0.0); float rail(vec3 pos) { vec3 tpos =pos; tpos.z = abs(3.-mod(tpos.z, 6.)); vec4 p = vec4(tpos,1.); vec3 trap0pos = vec3(-2., 0.2, -3.0); vec3 trap0 = vec3(1E6); for (int i=0; i < 4; ++i) { p = formula(p); trap0 = min(trap0, abs(p.xyz-trap0pos)); } g_trap0 = trap0; float fr=(length(max(vec3(0.),p.xyz-1.5))-1.0)/p.w; return fr; } float df(vec3 p) { // Space distortion found somewhere on shadertoy, don't remember where vec3 wrap = cam(p.z); vec3 wrapDeriv = normalize(dcam(p.z)); p.xy -= wrap.xy; p -= wrapDeriv*dot(vec3(p.xy, 0), wrapDeriv)*0.5*vec3(1,1,-1); #if defined(TWISTS) vec3 ddcam = ddcam(p.z); p.xy *= ROT(-16.0*ddcam.x); #endif p.x -= 1.0; p.y = -pabs(p.y, 1.5); p.y -= -1.5; float dr = rail(p); return dr; } float rayMarch(vec3 ro, vec3 rd, out int iter) { float t = 0.0; int i = 0; for (i = 0; i < MAX_RAY_MARCHES; i++) { float d = df(ro + rd*t); if (d < TOLERANCE || t > MAX_RAY_LENGTH) break; t += d; } iter = i; return t; } vec3 normal(vec3 pos) { vec2 eps = vec2(NORM_OFF,0.0); vec3 nor; nor.x = df(pos+eps.xyy) - df(pos-eps.xyy); nor.y = df(pos+eps.yxy) - df(pos-eps.yxy); nor.z = df(pos+eps.yyx) - df(pos-eps.yyx); return normalize(nor); } vec3 render(vec3 ro, vec3 rd) { const vec3 bgcol = vec3(2.0, 1.0, 0.75).zyx; vec3 lightPos = cam(ro.z+10.0); int iter = 0; float t = rayMarch(ro, rd, iter); vec3 trap0 = g_trap0; float pulse = smoothstep(0.0, 1.0, sin(TAU*TIME*0.25)); float sr = mix(2.0, 3.0, pulse); float sd = sphered(ro, rd, vec4(lightPos, sr), t); vec3 gcol = mix(1.0, 1.75, pulse)*sd*sd*bgcol; if (t >= MAX_RAY_LENGTH) { return gcol; } vec3 pos = ro + t*rd; vec3 nor = normal(pos); vec3 refl = reflect(rd, nor); float ii = float(iter)/float(MAX_RAY_MARCHES); vec3 ld = normalize(lightPos - pos); float fre = abs(dot(rd, nor)); fre *= fre; fre *= fre; float spe = fre*pow(max(dot(refl, ld), 0.), 10.); float fo = smoothstep(0.9, 0.4, t/MAX_RAY_LENGTH); float ao = 1.0-ii; vec3 col = vec3(0.0); col += pow(smoothstep(0.5, 1.0, trap0.x*0.25)*1.3, mix(6.0, 2.0, pulse))*0.5*bgcol*mix(0.5, 1.6, pulse); col += smoothstep(0.7, 0.6, trap0.z)*smoothstep(0.4, 0.5, trap0.z)*ao*bgcol*mix(0.05, 0.4, pulse); col += spe*bgcol*mix(0.66, 1.5, pulse); col *= 1.0-sd*sd; col *= fo; col += gcol; return col; } vec3 effect3d(vec2 p, vec2 q) { float z = TIME*2.5; vec3 cam = cam(z); vec3 dcam = dcam(z); vec3 ddcam= ddcam(z); vec3 ro = cam; vec3 ww = normalize(dcam); vec3 uu = normalize(cross(vec3(0.0,1.0,0.0)+ddcam*4.0, ww )); vec3 vv = normalize(cross(ww,uu)); const float fov = 2.0/tanh(TAU/6.0); vec3 rd = normalize(-p.x*uu + p.y*vv + fov*ww ); return render(ro, rd); } void mainImage(out vec4 fragColor, in vec2 fragCoord) { vec2 q = fragCoord/RESOLUTION.xy; vec2 p = -1. + 2. * q; p.x *= RESOLUTION.x/RESOLUTION.y; vec3 col = effect3d(p, q); col = sRGB(col); fragColor = vec4(col, 1.0); }
cc0-1.0
[ 2430, 2500, 2522, 2522, 2661 ]
[ [ 968, 1068, 1089, 1089, 1162 ], [ 1163, 1263, 1285, 1285, 1334 ], [ 1336, 1396, 1424, 1444, 1520 ], [ 1522, 1605, 1644, 1644, 1733 ], [ 1735, 1735, 1765, 1765, 1793 ], [ 1795, 1889, 1947, 1947, 2428 ], [ 2430, 2500, 2522, 2522, 2661 ], [ 2691, 2691, 2713, 2713, 3062 ], [ 3064, 3064, 3082, 3155, 3487 ], [ 3489, 3489, 3537, 3537, 3732 ], [ 3734, 3734, 3757, 3757, 3965 ], [ 3967, 3967, 3998, 3998, 5131 ], [ 5133, 5133, 5164, 5164, 5528 ], [ 5530, 5530, 5585, 5585, 5762 ] ]
// "Amazing Surface" fractal // https://www.shadertoy.com/view/XsBXWt
vec4 formula(vec4 p) {
p.xz = abs(p.xz+1.)-abs(p.xz-1.)-p.xz; p.y-=.25; p.xy*=ROT(radians(30.0)); p=p*2.0/clamp(dot(p.xyz,p.xyz),0.24,1.0); return p; }
// "Amazing Surface" fractal // https://www.shadertoy.com/view/XsBXWt vec4 formula(vec4 p) {
2
9
flXyRS
iq
2022-03-24T18:04:15
// The MIT License // Copyright © 2022 Inigo Quilez // Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. // sdgEllipsoid() returns the approximated ellipsoid SDF and // the exact normalized gradient/normal of the ellipsoid, by // computing it analytically. This means the normal to // the ellipsoid surface can be used during the raymarch loop // rather inexpensivelly (compared to sampling the SDF // multiple times to evaluate a normal for it) // Other SDF analytic gradients: // // Torus: https://www.shadertoy.com/view/wtcfzM // Capsule: https://www.shadertoy.com/view/WttfR7 // Ellipsoid: https://www.shadertoy.com/view/flXyRS // .x = f(p) // .y = ∂f(p)/∂x // .z = ∂f(p)/∂y // .w = ∂f(p)/∂z // .yzw = ∇f(p) with ‖∇f(p)‖ = 1 vec4 sdgEllipsoid( vec3 p, vec3 r ) { p /= r; float k0 = sqrt(dot(p,p)); p /= r; float k1 = inversesqrt(dot(p,p)); return vec4( k0*(k0-1.0)*k1, p*k1 ); } #define AA 3 void mainImage( out vec4 fragColor, in vec2 fragCoord ) { // camera movement float an = 0.5*iTime; vec3 ro = 1.2*vec3( 1.0*cos(an), 0.65, 1.0*sin(an) ); vec3 ta = vec3( 0.0, -0.15, 0.0 ); // camera matrix vec3 ww = normalize( ta - ro ); vec3 uu = normalize( cross(ww,vec3(0.0,1.0,0.0) ) ); vec3 vv = normalize( cross(uu,ww)); // animate torus vec3 ra = vec3(0.8,0.1,0.5); // render vec3 tot = vec3(0.0); #if AA>1 for( int m=0; m<AA; m++ ) for( int n=0; n<AA; n++ ) { // pixel coordinates vec2 o = vec2(float(m),float(n)) / float(AA) - 0.5; vec2 p = (2.0*(fragCoord+o)-iResolution.xy)/iResolution.y; #else vec2 p = (2.0*fragCoord-iResolution.xy)/iResolution.y; #endif // create view ray vec3 rd = normalize( p.x*uu + p.y*vv + 1.5*ww ); // raymarch const float tmax = 5.0; float t = 0.0; for( int i=0; i<256; i++ ) { vec3 pos = ro + t*rd; float h = sdgEllipsoid(pos,ra).x; if( h<0.0001 || t>tmax ) break; t += h; } // shading/lighting vec3 col = vec3(0.0); if( t<tmax ) { vec3 pos = ro + t*rd; vec3 nor = sdgEllipsoid(pos,ra).yzw; // compute normal numerically, for comparison // https://iquilezles.org/articles/normalsSDF #if 0 const vec2 e = vec2(1,-1); const float eps = 0.0002; nor = normalize( e.xyy*sdgEllipsoid( pos + e.xyy*eps, ra ).x + e.yyx*sdgEllipsoid( pos + e.yyx*eps, ra ).x + e.yxy*sdgEllipsoid( pos + e.yxy*eps, ra ).x + e.xxx*sdgEllipsoid( pos + e.xxx*eps, ra ).x ); #endif float dif = clamp( dot(nor,vec3(0.57703)), 0.0, 1.0 ); float amb = 0.5 + 0.5*dot(nor,vec3(0.0,1.0,0.0)); col = vec3(0.2,0.3,0.4)*amb + vec3(0.85,0.75,0.65)*dif; col *= (0.5+0.5*nor)*(0.5+0.5*nor); } // gamma col = sqrt( col ); tot += col; #if AA>1 } tot /= float(AA*AA); #endif fragColor = vec4( tot, 1.0 ); }
mit
[ 1614, 1731, 1768, 1768, 1903 ]
[ [ 1614, 1731, 1768, 1768, 1903 ] ]
// .x = f(p) // .y = ∂f(p)/∂x // .z = ∂f(p)/∂y // .w = ∂f(p)/∂z // .yzw = ∇f(p) with ‖∇f(p)‖ = 1
vec4 sdgEllipsoid( vec3 p, vec3 r ) {
p /= r; float k0 = sqrt(dot(p,p)); p /= r; float k1 = inversesqrt(dot(p,p)); return vec4( k0*(k0-1.0)*k1, p*k1 ); }
// .x = f(p) // .y = ∂f(p)/∂x // .z = ∂f(p)/∂y // .w = ∂f(p)/∂z // .yzw = ∇f(p) with ‖∇f(p)‖ = 1 vec4 sdgEllipsoid( vec3 p, vec3 r ) {
1
1
7sSfRG
mrange
2022-03-05T20:35:21
// License CC0: Voronoi Glass Panes // Tinkering with the voronoi pattern from a Shane shader on saturday evening // Kind of hackish overall but that never stopped me from sharing a shader before // Shane shader, it's worth a look: https://www.shadertoy.com/view/Mld3Rn #define RESOLUTION iResolution #define TIME iTime #define PI 3.141592654 #define TAU (2.0*PI) #define PI_2 (0.5*3.141592654) #define ROT(a) mat2(cos(a), sin(a), -sin(a), cos(a)) #define DOT2(x) dot(x,x) const float planeDist = 1.0-0.25; float g_hmul = 1.0; // License: Unknown, author: nmz (twitter: @stormoid), found: https://www.shadertoy.com/view/NdfyRM float sRGB(float t) { return mix(1.055*pow(t, 1./2.4) - 0.055, 12.92*t, step(t, 0.0031308)); } // License: Unknown, author: nmz (twitter: @stormoid), found: https://www.shadertoy.com/view/NdfyRM vec3 sRGB(in vec3 c) { return vec3 (sRGB(c.x), sRGB(c.y), sRGB(c.z)); } // License: WTFPL, author: sam hocevar, found: https://stackoverflow.com/a/17897228/418488 const vec4 hsv2rgb_K = vec4(1.0, 2.0 / 3.0, 1.0 / 3.0, 3.0); vec3 hsv2rgb(vec3 c) { vec3 p = abs(fract(c.xxx + hsv2rgb_K.xyz) * 6.0 - hsv2rgb_K.www); return c.z * mix(hsv2rgb_K.xxx, clamp(p - hsv2rgb_K.xxx, 0.0, 1.0), 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)) const float zoomOuter = 1.0; const float zoomInner = 0.2; float tanh_approx(float x) { // return tanh(x); float x2 = x*x; return clamp(x*(27.0 + x2)/(27.0+9.0*x2), -1.0, 1.0); } // License: Unknown, author: Unknown, found: don't remember vec4 alphaBlend(vec4 back, vec4 front) { float w = front.w + back.w*(1.0-front.w); vec3 xyz = (front.xyz*front.w + back.xyz*back.w*(1.0-front.w))/w; return w > 0.0 ? vec4(xyz, w) : vec4(0.0); } // License: Unknown, author: Unknown, found: don't remember vec3 alphaBlend(vec3 back, vec4 front) { return mix(back, front.xyz, front.w); } // License: Unknown, author: Unknown, found: don't remember float hash(float co) { return fract(sin(co*12.9898) * 13758.5453); } vec2 hash2(vec2 p) { p = vec2(dot (p, vec2 (127.1, 311.7)), dot (p, vec2 (269.5, 183.3))); return fract (sin (p)*43758.5453123); } // License: MIT, author: Inigo Quilez, found: https://iquilezles.org/articles/distfunctions2d float hex(vec2 p, float r ) { const vec3 k = 0.5*vec3(-sqrt(3.0), 1.0, sqrt(4.0/3.0)); p = abs(p); p -= 2.0*min(dot(k.xy,p),0.0)*k.xy; p -= vec2(clamp(p.x, -k.z*r, k.z*r), r); return length(p)*sign(p.y); } vec3 offset(float z) { float a = z; vec2 p = -0.1*(vec2(cos(a), sin(a*sqrt(2.0))) + vec2(cos(a*sqrt(0.75)), sin(a*sqrt(0.5)))); return vec3(p, z); } vec3 doffset(float z) { float eps = 0.05; return (offset(z + eps) - offset(z - eps))/(2.0*eps); } vec3 ddoffset(float z) { float eps = 0.05; return (doffset(z + eps) - doffset(z - eps))/(2.0*eps); } vec3 skyColor(vec3 ro, vec3 rd) { float ld = max(dot(rd, vec3(0.0, 0.0, 1.0)), 0.0); vec3 scol = HSV2RGB(vec3(0.1, 0.25, 0.9)); return scol*tanh_approx(3.0*pow(ld, 100.0)); } float voronoi2(vec2 p){ vec2 g = floor(p), o; p -= g; vec3 d = vec3(1); for(int y = -1; y <= 1; y++){ for(int x = -1; x <= 1; x++){ o = vec2(x, y); o += hash2(g + o) - p; d.z = dot(o, o); d.y = max(d.x, min(d.y, d.z)); d.x = min(d.x, d.z); } } return max(d.y/1.2 - d.x, 0.0)/1.2; } float hf2(vec2 p) { const float zo = zoomOuter; const float zi = zoomInner; p /= zo; p /= zi; float d = -voronoi2(p); d *= zi*zo; float h = 0.2*tanh_approx(3.0*smoothstep(0.0, 1.0*zo*zi, -d)); return h*zo*zi; } float height(vec2 p) { return -hf2(p)*g_hmul; } vec3 normal(vec2 p, float eps) { vec2 v; vec2 w; vec2 e = vec2(0.00001, 0); vec3 n; n.x = height(p + e.xy) - height(p - e.xy); n.y = height(p + e.yx) - height(p - e.yx); n.z = -2.0*e.x; return normalize(n); } vec4 plane(vec3 pro, vec3 ro, vec3 rd, vec3 pp, vec3 off, float aa, float n_, out vec3 pnor) { float h0 = hash(n_); float h1 = fract(7793.0*h0); float h2 = fract(6337.0*h0); vec2 p = (pp-off*vec3(1.0, 1.0, 0.0)).xy; const float s = 1.0; vec3 lp1 = vec3(5.0, 1.0, 0.0)*vec3(s, 1.0, s)+pro; vec3 lp2 = vec3(-5.0, 1.0, 0.0)*vec3(s, 1.0, s)+pro; const float hsz = 0.2; float hd = hex(p.yx, hsz); g_hmul = smoothstep(0.0, 0.125, (hd-hsz/2.0)); p += vec2(h0,h1)*20.0; p *= mix(0.5, 1.0, h2); float he = height(p); vec3 nor = normal(p,2.0*aa); vec3 po = pp; pnor = nor; vec3 ld1 = normalize(lp1 - po); vec3 ld2 = normalize(lp2 - po); float diff1 = max(dot(nor, ld1), 0.0); float diff2 = max(dot(nor, ld2), 0.0); diff1 = ld1.z*nor.z;; vec3 ref = reflect(rd, nor); float ref1 = max(dot(ref, ld1), 0.0); float ref2 = max(dot(ref, ld2), 0.0); const vec3 mat = HSV2RGB(vec3(0.55, 0.45, 0.05)); const vec3 lcol1 = HSV2RGB(vec3(0.6, 0.5, 0.9)); const vec3 lcol2 = HSV2RGB(vec3(0.1, 0.65, 0.9)); float hf = smoothstep(0.0, 0.0002, -he); vec3 lpow1 = 1.0*lcol1/DOT2(ld1); vec3 lpow2 = 1.0*lcol2/DOT2(ld2); vec3 col = vec3(0.0); col += hf*mat*diff1*diff1*lpow1; col += hf*mat*diff2*diff2*lpow2; float spes = 20.0; col += pow(ref1, spes)*lcol1; col += pow(ref2, spes)*lcol2; float t = 1.0; t *= smoothstep(aa, -aa, -(hd-hsz/4.0)); t *= mix(1.0, 0.75, hf); return vec4(col, t); } vec3 color(vec3 ww, vec3 uu, vec3 vv, vec3 pro, vec3 ro, vec2 p) { float lp = length(p); vec2 np = p + 1.0/RESOLUTION.xy; float rdd = 2.0+tanh_approx(length(0.25*p)); vec3 rd = normalize(p.x*uu + p.y*vv + rdd*ww); vec3 nrd = normalize(np.x*uu + np.y*vv + rdd*ww); const int furthest = 5; const int fadeFrom = max(furthest-2, 0); const float fadeDist = planeDist*float(furthest - fadeFrom); float nz = floor(ro.z / planeDist); vec3 skyCol = skyColor(ro, rd); vec4 acol = vec4(0.0); const float cutOff = 0.98; bool cutOut = false; // Steps from nearest to furthest plane and accumulates the color for (int i = 1; i <= furthest; ++i) { float pz = planeDist*nz + planeDist*float(i); float pd = (pz - ro.z)/rd.z; if (pd > 0.0 && acol.w < cutOff) { vec3 pp = ro + rd*pd; vec3 npp = ro + nrd*pd; float aa = 3.0*length(pp - npp); vec3 off = offset(pp.z); vec3 pnor = vec3(0.0); vec4 pcol = plane(pro, ro, rd, pp, off, aa, nz+float(i), pnor); vec3 refr = refract(rd, pnor, 1.0-0.075); if (pcol.w > (1.0-cutOff)&&refr != vec3(0.0)) { rd = refr; } float dz = pp.z-ro.z; const float fi = -0.; float fadeIn = smoothstep(planeDist*(float(furthest)+fi), planeDist*(float(fadeFrom)-fi), dz); float fadeOut = smoothstep(0.0, planeDist*0.1, dz); pcol.w *= fadeOut*fadeIn; acol = alphaBlend(pcol, acol); } else { cutOut = true; acol.w = acol.w > cutOff ? 1.0 : acol.w; break; } } vec3 col = alphaBlend(skyCol, acol); // To debug cutouts due to transparency // col += cutOut ? vec3(1.0, -1.0, 0.0) : vec3(0.0); return col; } vec3 effect(vec2 p, vec2 q) { float z = 0.33*planeDist*TIME; vec3 pro = offset(z-1.0); vec3 ro = offset(z); vec3 dro = doffset(z); vec3 ddro = ddoffset(z); vec3 ww = normalize(dro); vec3 uu = normalize(cross(normalize(vec3(0.0,1.0,0.0)+ddro), ww)); vec3 vv = cross(ww, uu); vec3 col = color(ww, uu, vv, pro, ro, p); return col; } void mainImage(out vec4 fragColor, in vec2 fragCoord) { vec2 q = fragCoord/iResolution.xy; vec2 p = -1. + 2. * q; p.x *= RESOLUTION.x/RESOLUTION.y; vec3 col = effect(p, q); col *= smoothstep(0.0, 4.0, TIME); col = sRGB(col); fragColor = vec4(col, 1.0); }
cc0-1.0
[ 1743, 1803, 1843, 1843, 2002 ]
[ [ 575, 675, 696, 696, 769 ], [ 770, 870, 892, 892, 941 ], [ 1095, 1095, 1117, 1117, 1263 ], [ 1617, 1617, 1645, 1665, 1741 ], [ 1743, 1803, 1843, 1843, 2002 ], [ 2004, 2064, 2104, 2104, 2146 ], [ 2148, 2208, 2230, 2230, 2278 ], [ 2280, 2280, 2300, 2300, 2414 ], [ 2416, 2510, 2539, 2539, 2726 ], [ 2728, 2728, 2750, 2750, 2882 ], [ 2884, 2884, 2907, 2907, 2985 ], [ 2987, 2987, 3011, 3011, 3091 ], [ 3093, 3093, 3126, 3126, 3273 ], [ 3275, 3275, 3298, 3298, 3617 ], [ 3619, 3619, 3638, 3638, 3857 ], [ 3859, 3859, 3881, 3881, 3908 ], [ 3910, 3910, 3942, 3942, 4140 ], [ 4142, 4142, 4236, 4236, 5613 ], [ 7322, 7322, 7351, 7351, 7682 ], [ 7684, 7684, 7739, 7739, 7958 ] ]
// License: Unknown, author: Unknown, found: don't remember
vec4 alphaBlend(vec4 back, vec4 front) {
float w = front.w + back.w*(1.0-front.w); vec3 xyz = (front.xyz*front.w + back.xyz*back.w*(1.0-front.w))/w; return w > 0.0 ? vec4(xyz, w) : vec4(0.0); }
// License: Unknown, author: Unknown, found: don't remember vec4 alphaBlend(vec4 back, vec4 front) {
16
18
7sSfRG
mrange
2022-03-05T20:35:21
// License CC0: Voronoi Glass Panes // Tinkering with the voronoi pattern from a Shane shader on saturday evening // Kind of hackish overall but that never stopped me from sharing a shader before // Shane shader, it's worth a look: https://www.shadertoy.com/view/Mld3Rn #define RESOLUTION iResolution #define TIME iTime #define PI 3.141592654 #define TAU (2.0*PI) #define PI_2 (0.5*3.141592654) #define ROT(a) mat2(cos(a), sin(a), -sin(a), cos(a)) #define DOT2(x) dot(x,x) const float planeDist = 1.0-0.25; float g_hmul = 1.0; // License: Unknown, author: nmz (twitter: @stormoid), found: https://www.shadertoy.com/view/NdfyRM float sRGB(float t) { return mix(1.055*pow(t, 1./2.4) - 0.055, 12.92*t, step(t, 0.0031308)); } // License: Unknown, author: nmz (twitter: @stormoid), found: https://www.shadertoy.com/view/NdfyRM vec3 sRGB(in vec3 c) { return vec3 (sRGB(c.x), sRGB(c.y), sRGB(c.z)); } // License: WTFPL, author: sam hocevar, found: https://stackoverflow.com/a/17897228/418488 const vec4 hsv2rgb_K = vec4(1.0, 2.0 / 3.0, 1.0 / 3.0, 3.0); vec3 hsv2rgb(vec3 c) { vec3 p = abs(fract(c.xxx + hsv2rgb_K.xyz) * 6.0 - hsv2rgb_K.www); return c.z * mix(hsv2rgb_K.xxx, clamp(p - hsv2rgb_K.xxx, 0.0, 1.0), 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)) const float zoomOuter = 1.0; const float zoomInner = 0.2; float tanh_approx(float x) { // return tanh(x); float x2 = x*x; return clamp(x*(27.0 + x2)/(27.0+9.0*x2), -1.0, 1.0); } // License: Unknown, author: Unknown, found: don't remember vec4 alphaBlend(vec4 back, vec4 front) { float w = front.w + back.w*(1.0-front.w); vec3 xyz = (front.xyz*front.w + back.xyz*back.w*(1.0-front.w))/w; return w > 0.0 ? vec4(xyz, w) : vec4(0.0); } // License: Unknown, author: Unknown, found: don't remember vec3 alphaBlend(vec3 back, vec4 front) { return mix(back, front.xyz, front.w); } // License: Unknown, author: Unknown, found: don't remember float hash(float co) { return fract(sin(co*12.9898) * 13758.5453); } vec2 hash2(vec2 p) { p = vec2(dot (p, vec2 (127.1, 311.7)), dot (p, vec2 (269.5, 183.3))); return fract (sin (p)*43758.5453123); } // License: MIT, author: Inigo Quilez, found: https://iquilezles.org/articles/distfunctions2d float hex(vec2 p, float r ) { const vec3 k = 0.5*vec3(-sqrt(3.0), 1.0, sqrt(4.0/3.0)); p = abs(p); p -= 2.0*min(dot(k.xy,p),0.0)*k.xy; p -= vec2(clamp(p.x, -k.z*r, k.z*r), r); return length(p)*sign(p.y); } vec3 offset(float z) { float a = z; vec2 p = -0.1*(vec2(cos(a), sin(a*sqrt(2.0))) + vec2(cos(a*sqrt(0.75)), sin(a*sqrt(0.5)))); return vec3(p, z); } vec3 doffset(float z) { float eps = 0.05; return (offset(z + eps) - offset(z - eps))/(2.0*eps); } vec3 ddoffset(float z) { float eps = 0.05; return (doffset(z + eps) - doffset(z - eps))/(2.0*eps); } vec3 skyColor(vec3 ro, vec3 rd) { float ld = max(dot(rd, vec3(0.0, 0.0, 1.0)), 0.0); vec3 scol = HSV2RGB(vec3(0.1, 0.25, 0.9)); return scol*tanh_approx(3.0*pow(ld, 100.0)); } float voronoi2(vec2 p){ vec2 g = floor(p), o; p -= g; vec3 d = vec3(1); for(int y = -1; y <= 1; y++){ for(int x = -1; x <= 1; x++){ o = vec2(x, y); o += hash2(g + o) - p; d.z = dot(o, o); d.y = max(d.x, min(d.y, d.z)); d.x = min(d.x, d.z); } } return max(d.y/1.2 - d.x, 0.0)/1.2; } float hf2(vec2 p) { const float zo = zoomOuter; const float zi = zoomInner; p /= zo; p /= zi; float d = -voronoi2(p); d *= zi*zo; float h = 0.2*tanh_approx(3.0*smoothstep(0.0, 1.0*zo*zi, -d)); return h*zo*zi; } float height(vec2 p) { return -hf2(p)*g_hmul; } vec3 normal(vec2 p, float eps) { vec2 v; vec2 w; vec2 e = vec2(0.00001, 0); vec3 n; n.x = height(p + e.xy) - height(p - e.xy); n.y = height(p + e.yx) - height(p - e.yx); n.z = -2.0*e.x; return normalize(n); } vec4 plane(vec3 pro, vec3 ro, vec3 rd, vec3 pp, vec3 off, float aa, float n_, out vec3 pnor) { float h0 = hash(n_); float h1 = fract(7793.0*h0); float h2 = fract(6337.0*h0); vec2 p = (pp-off*vec3(1.0, 1.0, 0.0)).xy; const float s = 1.0; vec3 lp1 = vec3(5.0, 1.0, 0.0)*vec3(s, 1.0, s)+pro; vec3 lp2 = vec3(-5.0, 1.0, 0.0)*vec3(s, 1.0, s)+pro; const float hsz = 0.2; float hd = hex(p.yx, hsz); g_hmul = smoothstep(0.0, 0.125, (hd-hsz/2.0)); p += vec2(h0,h1)*20.0; p *= mix(0.5, 1.0, h2); float he = height(p); vec3 nor = normal(p,2.0*aa); vec3 po = pp; pnor = nor; vec3 ld1 = normalize(lp1 - po); vec3 ld2 = normalize(lp2 - po); float diff1 = max(dot(nor, ld1), 0.0); float diff2 = max(dot(nor, ld2), 0.0); diff1 = ld1.z*nor.z;; vec3 ref = reflect(rd, nor); float ref1 = max(dot(ref, ld1), 0.0); float ref2 = max(dot(ref, ld2), 0.0); const vec3 mat = HSV2RGB(vec3(0.55, 0.45, 0.05)); const vec3 lcol1 = HSV2RGB(vec3(0.6, 0.5, 0.9)); const vec3 lcol2 = HSV2RGB(vec3(0.1, 0.65, 0.9)); float hf = smoothstep(0.0, 0.0002, -he); vec3 lpow1 = 1.0*lcol1/DOT2(ld1); vec3 lpow2 = 1.0*lcol2/DOT2(ld2); vec3 col = vec3(0.0); col += hf*mat*diff1*diff1*lpow1; col += hf*mat*diff2*diff2*lpow2; float spes = 20.0; col += pow(ref1, spes)*lcol1; col += pow(ref2, spes)*lcol2; float t = 1.0; t *= smoothstep(aa, -aa, -(hd-hsz/4.0)); t *= mix(1.0, 0.75, hf); return vec4(col, t); } vec3 color(vec3 ww, vec3 uu, vec3 vv, vec3 pro, vec3 ro, vec2 p) { float lp = length(p); vec2 np = p + 1.0/RESOLUTION.xy; float rdd = 2.0+tanh_approx(length(0.25*p)); vec3 rd = normalize(p.x*uu + p.y*vv + rdd*ww); vec3 nrd = normalize(np.x*uu + np.y*vv + rdd*ww); const int furthest = 5; const int fadeFrom = max(furthest-2, 0); const float fadeDist = planeDist*float(furthest - fadeFrom); float nz = floor(ro.z / planeDist); vec3 skyCol = skyColor(ro, rd); vec4 acol = vec4(0.0); const float cutOff = 0.98; bool cutOut = false; // Steps from nearest to furthest plane and accumulates the color for (int i = 1; i <= furthest; ++i) { float pz = planeDist*nz + planeDist*float(i); float pd = (pz - ro.z)/rd.z; if (pd > 0.0 && acol.w < cutOff) { vec3 pp = ro + rd*pd; vec3 npp = ro + nrd*pd; float aa = 3.0*length(pp - npp); vec3 off = offset(pp.z); vec3 pnor = vec3(0.0); vec4 pcol = plane(pro, ro, rd, pp, off, aa, nz+float(i), pnor); vec3 refr = refract(rd, pnor, 1.0-0.075); if (pcol.w > (1.0-cutOff)&&refr != vec3(0.0)) { rd = refr; } float dz = pp.z-ro.z; const float fi = -0.; float fadeIn = smoothstep(planeDist*(float(furthest)+fi), planeDist*(float(fadeFrom)-fi), dz); float fadeOut = smoothstep(0.0, planeDist*0.1, dz); pcol.w *= fadeOut*fadeIn; acol = alphaBlend(pcol, acol); } else { cutOut = true; acol.w = acol.w > cutOff ? 1.0 : acol.w; break; } } vec3 col = alphaBlend(skyCol, acol); // To debug cutouts due to transparency // col += cutOut ? vec3(1.0, -1.0, 0.0) : vec3(0.0); return col; } vec3 effect(vec2 p, vec2 q) { float z = 0.33*planeDist*TIME; vec3 pro = offset(z-1.0); vec3 ro = offset(z); vec3 dro = doffset(z); vec3 ddro = ddoffset(z); vec3 ww = normalize(dro); vec3 uu = normalize(cross(normalize(vec3(0.0,1.0,0.0)+ddro), ww)); vec3 vv = cross(ww, uu); vec3 col = color(ww, uu, vv, pro, ro, p); return col; } void mainImage(out vec4 fragColor, in vec2 fragCoord) { vec2 q = fragCoord/iResolution.xy; vec2 p = -1. + 2. * q; p.x *= RESOLUTION.x/RESOLUTION.y; vec3 col = effect(p, q); col *= smoothstep(0.0, 4.0, TIME); col = sRGB(col); fragColor = vec4(col, 1.0); }
cc0-1.0
[ 2004, 2064, 2104, 2104, 2146 ]
[ [ 575, 675, 696, 696, 769 ], [ 770, 870, 892, 892, 941 ], [ 1095, 1095, 1117, 1117, 1263 ], [ 1617, 1617, 1645, 1665, 1741 ], [ 1743, 1803, 1843, 1843, 2002 ], [ 2004, 2064, 2104, 2104, 2146 ], [ 2148, 2208, 2230, 2230, 2278 ], [ 2280, 2280, 2300, 2300, 2414 ], [ 2416, 2510, 2539, 2539, 2726 ], [ 2728, 2728, 2750, 2750, 2882 ], [ 2884, 2884, 2907, 2907, 2985 ], [ 2987, 2987, 3011, 3011, 3091 ], [ 3093, 3093, 3126, 3126, 3273 ], [ 3275, 3275, 3298, 3298, 3617 ], [ 3619, 3619, 3638, 3638, 3857 ], [ 3859, 3859, 3881, 3881, 3908 ], [ 3910, 3910, 3942, 3942, 4140 ], [ 4142, 4142, 4236, 4236, 5613 ], [ 7322, 7322, 7351, 7351, 7682 ], [ 7684, 7684, 7739, 7739, 7958 ] ]
// License: Unknown, author: Unknown, found: don't remember
vec3 alphaBlend(vec3 back, vec4 front) {
return mix(back, front.xyz, front.w); }
// License: Unknown, author: Unknown, found: don't remember vec3 alphaBlend(vec3 back, vec4 front) {
20
22
7sSfRG
mrange
2022-03-05T20:35:21
// License CC0: Voronoi Glass Panes // Tinkering with the voronoi pattern from a Shane shader on saturday evening // Kind of hackish overall but that never stopped me from sharing a shader before // Shane shader, it's worth a look: https://www.shadertoy.com/view/Mld3Rn #define RESOLUTION iResolution #define TIME iTime #define PI 3.141592654 #define TAU (2.0*PI) #define PI_2 (0.5*3.141592654) #define ROT(a) mat2(cos(a), sin(a), -sin(a), cos(a)) #define DOT2(x) dot(x,x) const float planeDist = 1.0-0.25; float g_hmul = 1.0; // License: Unknown, author: nmz (twitter: @stormoid), found: https://www.shadertoy.com/view/NdfyRM float sRGB(float t) { return mix(1.055*pow(t, 1./2.4) - 0.055, 12.92*t, step(t, 0.0031308)); } // License: Unknown, author: nmz (twitter: @stormoid), found: https://www.shadertoy.com/view/NdfyRM vec3 sRGB(in vec3 c) { return vec3 (sRGB(c.x), sRGB(c.y), sRGB(c.z)); } // License: WTFPL, author: sam hocevar, found: https://stackoverflow.com/a/17897228/418488 const vec4 hsv2rgb_K = vec4(1.0, 2.0 / 3.0, 1.0 / 3.0, 3.0); vec3 hsv2rgb(vec3 c) { vec3 p = abs(fract(c.xxx + hsv2rgb_K.xyz) * 6.0 - hsv2rgb_K.www); return c.z * mix(hsv2rgb_K.xxx, clamp(p - hsv2rgb_K.xxx, 0.0, 1.0), 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)) const float zoomOuter = 1.0; const float zoomInner = 0.2; float tanh_approx(float x) { // return tanh(x); float x2 = x*x; return clamp(x*(27.0 + x2)/(27.0+9.0*x2), -1.0, 1.0); } // License: Unknown, author: Unknown, found: don't remember vec4 alphaBlend(vec4 back, vec4 front) { float w = front.w + back.w*(1.0-front.w); vec3 xyz = (front.xyz*front.w + back.xyz*back.w*(1.0-front.w))/w; return w > 0.0 ? vec4(xyz, w) : vec4(0.0); } // License: Unknown, author: Unknown, found: don't remember vec3 alphaBlend(vec3 back, vec4 front) { return mix(back, front.xyz, front.w); } // License: Unknown, author: Unknown, found: don't remember float hash(float co) { return fract(sin(co*12.9898) * 13758.5453); } vec2 hash2(vec2 p) { p = vec2(dot (p, vec2 (127.1, 311.7)), dot (p, vec2 (269.5, 183.3))); return fract (sin (p)*43758.5453123); } // License: MIT, author: Inigo Quilez, found: https://iquilezles.org/articles/distfunctions2d float hex(vec2 p, float r ) { const vec3 k = 0.5*vec3(-sqrt(3.0), 1.0, sqrt(4.0/3.0)); p = abs(p); p -= 2.0*min(dot(k.xy,p),0.0)*k.xy; p -= vec2(clamp(p.x, -k.z*r, k.z*r), r); return length(p)*sign(p.y); } vec3 offset(float z) { float a = z; vec2 p = -0.1*(vec2(cos(a), sin(a*sqrt(2.0))) + vec2(cos(a*sqrt(0.75)), sin(a*sqrt(0.5)))); return vec3(p, z); } vec3 doffset(float z) { float eps = 0.05; return (offset(z + eps) - offset(z - eps))/(2.0*eps); } vec3 ddoffset(float z) { float eps = 0.05; return (doffset(z + eps) - doffset(z - eps))/(2.0*eps); } vec3 skyColor(vec3 ro, vec3 rd) { float ld = max(dot(rd, vec3(0.0, 0.0, 1.0)), 0.0); vec3 scol = HSV2RGB(vec3(0.1, 0.25, 0.9)); return scol*tanh_approx(3.0*pow(ld, 100.0)); } float voronoi2(vec2 p){ vec2 g = floor(p), o; p -= g; vec3 d = vec3(1); for(int y = -1; y <= 1; y++){ for(int x = -1; x <= 1; x++){ o = vec2(x, y); o += hash2(g + o) - p; d.z = dot(o, o); d.y = max(d.x, min(d.y, d.z)); d.x = min(d.x, d.z); } } return max(d.y/1.2 - d.x, 0.0)/1.2; } float hf2(vec2 p) { const float zo = zoomOuter; const float zi = zoomInner; p /= zo; p /= zi; float d = -voronoi2(p); d *= zi*zo; float h = 0.2*tanh_approx(3.0*smoothstep(0.0, 1.0*zo*zi, -d)); return h*zo*zi; } float height(vec2 p) { return -hf2(p)*g_hmul; } vec3 normal(vec2 p, float eps) { vec2 v; vec2 w; vec2 e = vec2(0.00001, 0); vec3 n; n.x = height(p + e.xy) - height(p - e.xy); n.y = height(p + e.yx) - height(p - e.yx); n.z = -2.0*e.x; return normalize(n); } vec4 plane(vec3 pro, vec3 ro, vec3 rd, vec3 pp, vec3 off, float aa, float n_, out vec3 pnor) { float h0 = hash(n_); float h1 = fract(7793.0*h0); float h2 = fract(6337.0*h0); vec2 p = (pp-off*vec3(1.0, 1.0, 0.0)).xy; const float s = 1.0; vec3 lp1 = vec3(5.0, 1.0, 0.0)*vec3(s, 1.0, s)+pro; vec3 lp2 = vec3(-5.0, 1.0, 0.0)*vec3(s, 1.0, s)+pro; const float hsz = 0.2; float hd = hex(p.yx, hsz); g_hmul = smoothstep(0.0, 0.125, (hd-hsz/2.0)); p += vec2(h0,h1)*20.0; p *= mix(0.5, 1.0, h2); float he = height(p); vec3 nor = normal(p,2.0*aa); vec3 po = pp; pnor = nor; vec3 ld1 = normalize(lp1 - po); vec3 ld2 = normalize(lp2 - po); float diff1 = max(dot(nor, ld1), 0.0); float diff2 = max(dot(nor, ld2), 0.0); diff1 = ld1.z*nor.z;; vec3 ref = reflect(rd, nor); float ref1 = max(dot(ref, ld1), 0.0); float ref2 = max(dot(ref, ld2), 0.0); const vec3 mat = HSV2RGB(vec3(0.55, 0.45, 0.05)); const vec3 lcol1 = HSV2RGB(vec3(0.6, 0.5, 0.9)); const vec3 lcol2 = HSV2RGB(vec3(0.1, 0.65, 0.9)); float hf = smoothstep(0.0, 0.0002, -he); vec3 lpow1 = 1.0*lcol1/DOT2(ld1); vec3 lpow2 = 1.0*lcol2/DOT2(ld2); vec3 col = vec3(0.0); col += hf*mat*diff1*diff1*lpow1; col += hf*mat*diff2*diff2*lpow2; float spes = 20.0; col += pow(ref1, spes)*lcol1; col += pow(ref2, spes)*lcol2; float t = 1.0; t *= smoothstep(aa, -aa, -(hd-hsz/4.0)); t *= mix(1.0, 0.75, hf); return vec4(col, t); } vec3 color(vec3 ww, vec3 uu, vec3 vv, vec3 pro, vec3 ro, vec2 p) { float lp = length(p); vec2 np = p + 1.0/RESOLUTION.xy; float rdd = 2.0+tanh_approx(length(0.25*p)); vec3 rd = normalize(p.x*uu + p.y*vv + rdd*ww); vec3 nrd = normalize(np.x*uu + np.y*vv + rdd*ww); const int furthest = 5; const int fadeFrom = max(furthest-2, 0); const float fadeDist = planeDist*float(furthest - fadeFrom); float nz = floor(ro.z / planeDist); vec3 skyCol = skyColor(ro, rd); vec4 acol = vec4(0.0); const float cutOff = 0.98; bool cutOut = false; // Steps from nearest to furthest plane and accumulates the color for (int i = 1; i <= furthest; ++i) { float pz = planeDist*nz + planeDist*float(i); float pd = (pz - ro.z)/rd.z; if (pd > 0.0 && acol.w < cutOff) { vec3 pp = ro + rd*pd; vec3 npp = ro + nrd*pd; float aa = 3.0*length(pp - npp); vec3 off = offset(pp.z); vec3 pnor = vec3(0.0); vec4 pcol = plane(pro, ro, rd, pp, off, aa, nz+float(i), pnor); vec3 refr = refract(rd, pnor, 1.0-0.075); if (pcol.w > (1.0-cutOff)&&refr != vec3(0.0)) { rd = refr; } float dz = pp.z-ro.z; const float fi = -0.; float fadeIn = smoothstep(planeDist*(float(furthest)+fi), planeDist*(float(fadeFrom)-fi), dz); float fadeOut = smoothstep(0.0, planeDist*0.1, dz); pcol.w *= fadeOut*fadeIn; acol = alphaBlend(pcol, acol); } else { cutOut = true; acol.w = acol.w > cutOff ? 1.0 : acol.w; break; } } vec3 col = alphaBlend(skyCol, acol); // To debug cutouts due to transparency // col += cutOut ? vec3(1.0, -1.0, 0.0) : vec3(0.0); return col; } vec3 effect(vec2 p, vec2 q) { float z = 0.33*planeDist*TIME; vec3 pro = offset(z-1.0); vec3 ro = offset(z); vec3 dro = doffset(z); vec3 ddro = ddoffset(z); vec3 ww = normalize(dro); vec3 uu = normalize(cross(normalize(vec3(0.0,1.0,0.0)+ddro), ww)); vec3 vv = cross(ww, uu); vec3 col = color(ww, uu, vv, pro, ro, p); return col; } void mainImage(out vec4 fragColor, in vec2 fragCoord) { vec2 q = fragCoord/iResolution.xy; vec2 p = -1. + 2. * q; p.x *= RESOLUTION.x/RESOLUTION.y; vec3 col = effect(p, q); col *= smoothstep(0.0, 4.0, TIME); col = sRGB(col); fragColor = vec4(col, 1.0); }
cc0-1.0
[ 2416, 2510, 2539, 2539, 2726 ]
[ [ 575, 675, 696, 696, 769 ], [ 770, 870, 892, 892, 941 ], [ 1095, 1095, 1117, 1117, 1263 ], [ 1617, 1617, 1645, 1665, 1741 ], [ 1743, 1803, 1843, 1843, 2002 ], [ 2004, 2064, 2104, 2104, 2146 ], [ 2148, 2208, 2230, 2230, 2278 ], [ 2280, 2280, 2300, 2300, 2414 ], [ 2416, 2510, 2539, 2539, 2726 ], [ 2728, 2728, 2750, 2750, 2882 ], [ 2884, 2884, 2907, 2907, 2985 ], [ 2987, 2987, 3011, 3011, 3091 ], [ 3093, 3093, 3126, 3126, 3273 ], [ 3275, 3275, 3298, 3298, 3617 ], [ 3619, 3619, 3638, 3638, 3857 ], [ 3859, 3859, 3881, 3881, 3908 ], [ 3910, 3910, 3942, 3942, 4140 ], [ 4142, 4142, 4236, 4236, 5613 ], [ 7322, 7322, 7351, 7351, 7682 ], [ 7684, 7684, 7739, 7739, 7958 ] ]
// License: MIT, author: Inigo Quilez, found: https://iquilezles.org/articles/distfunctions2d
float hex(vec2 p, float r ) {
const vec3 k = 0.5*vec3(-sqrt(3.0), 1.0, sqrt(4.0/3.0)); p = abs(p); p -= 2.0*min(dot(k.xy,p),0.0)*k.xy; p -= vec2(clamp(p.x, -k.z*r, k.z*r), r); return length(p)*sign(p.y); }
// License: MIT, author: Inigo Quilez, found: https://iquilezles.org/articles/distfunctions2d float hex(vec2 p, float r ) {
1
2
flXBzB
blackle
2022-04-27T02:22:16
//excluding the function cubicRoot: //CC0 1.0 Universal https://creativecommons.org/publicdomain/zero/1.0/ //To the extent possible under law, Blackle Mori has waived all copyright and related or neighboring rights to this work. //this works by exploiting the fact that there exist polynomials T_n //such that T_n(cos(x)) = cos(n*x). these are chebyshev polynomials //of the first kind. T_2 is a parabola, and we can estimate the //distance to the cosine curve by using the analytic distance to this //parabola. // //to get the distance from p to the sine curve, we first do //p.x = sin(p.x*frequency)/frequency //then we produce the closest point on the parabola //T_2(x) = 2x^2 - 1 //call this point "q". we undo the mapping we made to p with //q.x = asin(q.x*frequency)/frequency //we do need to clamp it between -1 and 1 before passing into asin //but that is the gist of the method. // //this estimate only works for one half of the principal half cycle, //so we need to use two estimates for either side, and take the closest //point to p. finally we do a single newton's method update to finalize //the estimate. I'm not sure how accurate this is, but it looks extremely //close to the ground truth. // // article: https://suricrasia.online/demoscene/sine-distance/ // //other solutions: // iq: https://www.shadertoy.com/view/3t23WG // fabrice: https://www.shadertoy.com/view/tsXXRM // blackle 2: https://www.shadertoy.com/view/3lSyDG #define PI 3.141592653 //perform one step of netwon's method to finalize the estimate #define ONE_NEWTON_STEP // of equation x^3+c1*x+c2=0 /* Stolen from http://perso.ens-lyon.fr/christophe.winisdoerffer/INTRO_NUM/NumericalRecipesinF77.pdf, page 179 */ // subsequently stolen from https://www.shadertoy.com/view/MdfSDn float cubicRoot(float c1, float c2) { float q = -c1/3.; float r = c2/2.; float q3_r2 = q*q*q - r*r; if(q3_r2 < 0.) { float a = -sign(r)*pow(abs(r)+sqrt(-q3_r2),.333333); float b = a == 0. ? 0. : q/a; return a+b; } float theta = acos(r/pow(q,1.5)); return -2.*pow(q,.5)*cos(theta/3.); } vec2 cls_one(vec2 p, float f) { //sorry this is unreadable float f2 = f*f; //sq float cmn = 8.*f2*f2; float x = sin(p.x*f)/f; float pp = ((-4.*p.y-4.)*f2 + 1.)/cmn; float qq = -x/cmn; float sol = cubicRoot(pp, qq); x = asin(clamp(sol*f,-1.,1.))/f; return vec2(x,-cos(f*2.*x)); } vec3 sine_SDF(vec2 p, float freq) { float wavelen = PI/freq; //map p to be within the principal half cycle float cell = round(p.x/wavelen)*wavelen; float sgn = sign(cos(p.x*freq)); p.x = (p.x-cell)*sgn; vec2 off = vec2(-PI/freq/2.,0); //approximate either side of the principal half cycle with //the distance to the 2nd chebyshev polynomial of the 1st kind vec2 a = -off+cls_one(off+p, freq/2.); vec2 b = off-cls_one(off-p, freq/2.); //pick closest, comment out to see how the one-sided approximation looks if (length(p-b) < length(p-a)) a = b; #ifdef ONE_NEWTON_STEP //newton's method update via lagrange multipliers //visually very close after one step, but more increases accuracy quadratically vec3 K = vec3(a,p.x-p.y); //it might be possible to simplify this a lot... vec3 lagrange = vec3(2.*(K.x-p.x)+K.z*-cos(K.x*freq)*freq, 2.*(K.y-p.y)-K.z, K.y+sin(K.x*freq)); K -= (inverse(mat3(2.-K.z*-sin(K.x*freq)*freq*freq,0,cos(K.x*freq)*freq,0,2,1,-cos(K.x*freq)*freq,-1,0))*lagrange); a = K.xy; a.y = -sin(a.x*freq); #endif float dist = length(p-a)*sign(p.y+sin(p.x*freq)); //map the closest point back to global coordinates a.x *= sgn; a.x += cell; return vec3(dist,a); } vec3 shadeDistance(float d) { d *= .5; float dist = d*120.; float banding = max(sin(dist), 0.0); float strength = sqrt(1.-exp(-abs(d)*2.)); float pattern = mix(strength, banding, (0.6-abs(strength-0.5))*0.3); vec3 color = vec3(pattern); color *= d > 0.0 ? vec3(1.0,0.56,0.4) : vec3(0.4,0.9,1.0); return color; } void mainImage( out vec4 fragColor, in vec2 fragCoord ) { vec2 uv = (fragCoord-0.5*iResolution.xy)/iResolution.y; vec2 mouse = (iMouse.xy-0.5*iResolution.xy)/iResolution.y; float scale = 5.; uv*=scale; mouse*=scale; float pixel_size = scale/iResolution.y; float t = sin(iTime)*.5+.5; float freq = mix(20.,.1,sqrt(t)); vec3 mousedist = sine_SDF(mouse, freq); vec3 col = shadeDistance(sine_SDF(uv, freq).x); if (iMouse.z > 0.) { col *= smoothstep(-pixel_size,pixel_size, distance(mouse, uv) - abs(mousedist.x)) *.5 +.5; col = mix(vec3(.8,.9,.4), col, smoothstep(-pixel_size,pixel_size, distance(mousedist.yz, uv) - .05)); } float sn = abs(uv.y+cos(uv.x*freq))-.01; float snl = 0.*smoothstep(fwidth(sn),0.,sn); fragColor = vec4(col,1.0) + snl; }
cc0-1.0
[ 1568, 1780, 1817, 1817, 2078 ]
[ [ 1568, 1780, 1817, 1817, 2078 ], [ 2080, 2080, 2111, 2142, 2399 ], [ 2401, 2401, 2436, 2436, 3701 ], [ 3703, 3703, 3732, 3732, 4057 ], [ 4059, 4059, 4116, 4116, 4877 ] ]
// of equation x^3+c1*x+c2=0 /* Stolen from http://perso.ens-lyon.fr/christophe.winisdoerffer/INTRO_NUM/NumericalRecipesinF77.pdf, page 179 */ // subsequently stolen from https://www.shadertoy.com/view/MdfSDn
float cubicRoot(float c1, float c2) {
float q = -c1/3.; float r = c2/2.; float q3_r2 = q*q*q - r*r; if(q3_r2 < 0.) { float a = -sign(r)*pow(abs(r)+sqrt(-q3_r2),.333333); float b = a == 0. ? 0. : q/a; return a+b; } float theta = acos(r/pow(q,1.5)); return -2.*pow(q,.5)*cos(theta/3.); }
// of equation x^3+c1*x+c2=0 /* Stolen from http://perso.ens-lyon.fr/christophe.winisdoerffer/INTRO_NUM/NumericalRecipesinF77.pdf, page 179 */ // subsequently stolen from https://www.shadertoy.com/view/MdfSDn float cubicRoot(float c1, float c2) {
1
3
stBcW1
mrange
2022-04-10T14:31:46
// License CC0: Stars and galaxy // Bit of sunday tinkering lead to stars and a galaxy // Didn't turn out as I envisioned but it turned out to something // that I liked so sharing it. // Controls how many layers of stars #define LAYERS 5.0 #define PI 3.141592654 #define TAU (2.0*PI) #define TIME mod(iTime, 30.0) #define TTIME (TAU*TIME) #define RESOLUTION iResolution #define ROT(a) mat2(cos(a), sin(a), -sin(a), cos(a)) // License: Unknown, author: nmz (twitter: @stormoid), found: https://www.shadertoy.com/view/NdfyRM float sRGB(float t) { return mix(1.055*pow(t, 1./2.4) - 0.055, 12.92*t, step(t, 0.0031308)); } // License: Unknown, author: nmz (twitter: @stormoid), found: https://www.shadertoy.com/view/NdfyRM vec3 sRGB(in vec3 c) { return vec3 (sRGB(c.x), sRGB(c.y), sRGB(c.z)); } // License: Unknown, author: Matt Taylor (https://github.com/64), found: https://64.github.io/tonemapping/ vec3 aces_approx(vec3 v) { v = max(v, 0.0); 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); } // License: Unknown, author: Unknown, found: don't remember float tanh_approx(float x) { // Found this somewhere on the interwebs // return tanh(x); float x2 = x*x; return clamp(x*(27.0 + x2)/(27.0+9.0*x2), -1.0, 1.0); } // License: WTFPL, author: sam hocevar, found: https://stackoverflow.com/a/17897228/418488 const vec4 hsv2rgb_K = vec4(1.0, 2.0 / 3.0, 1.0 / 3.0, 3.0); vec3 hsv2rgb(vec3 c) { vec3 p = abs(fract(c.xxx + hsv2rgb_K.xyz) * 6.0 - hsv2rgb_K.www); return c.z * mix(hsv2rgb_K.xxx, clamp(p - hsv2rgb_K.xxx, 0.0, 1.0), c.y); } // License: MIT OR CC-BY-NC-4.0, author: mercury, found: https://mercury.sexy/hg_sdf/ vec2 mod2(inout vec2 p, vec2 size) { vec2 c = floor((p + size*0.5)/size); p = mod(p + size*0.5,size) - size*0.5; return c; } // License: Unknown, author: Unknown, found: don't remember vec2 hash2(vec2 p) { p = vec2(dot (p, vec2 (127.1, 311.7)), dot (p, vec2 (269.5, 183.3))); return fract(sin(p)*43758.5453123); } vec2 shash2(vec2 p) { return -1.0+2.0*hash2(p); } vec3 toSpherical(vec3 p) { float r = length(p); float t = acos(p.z/r); float ph = atan(p.y, p.x); return vec3(r, t, ph); } // License: CC BY-NC-SA 3.0, author: Stephane Cuillerdier - Aiekick/2015 (twitter:@aiekick), found: https://www.shadertoy.com/view/Mt3GW2 vec3 blackbody(float Temp) { vec3 col = vec3(255.); col.x = 56100000. * pow(Temp,(-3. / 2.)) + 148.; col.y = 100.04 * log(Temp) - 623.6; if (Temp > 6500.) col.y = 35200000. * pow(Temp,(-3. / 2.)) + 184.; col.z = 194.18 * log(Temp) - 1448.6; col = clamp(col, 0., 255.)/255.; if (Temp < 1000.) col *= Temp/1000.; return col; } // License: MIT, author: Inigo Quilez, found: https://www.shadertoy.com/view/XslGRr float noise(vec2 p) { // Found at https://www.shadertoy.com/view/sdlXWX // Which then redirected to IQ shader vec2 i = floor(p); vec2 f = fract(p); vec2 u = f*f*(3.-2.*f); float n = mix( mix( dot(shash2(i + vec2(0.,0.) ), f - vec2(0.,0.)), dot(shash2(i + vec2(1.,0.) ), f - vec2(1.,0.)), u.x), mix( dot(shash2(i + vec2(0.,1.) ), f - vec2(0.,1.)), dot(shash2(i + vec2(1.,1.) ), f - vec2(1.,1.)), u.x), u.y); return 2.0*n; } float fbm(vec2 p, float o, float s, int iters) { p *= s; p += o; const float aa = 0.5; const mat2 pp = 2.04*ROT(1.0); float h = 0.0; float a = 1.0; float d = 0.0; for (int i = 0; i < iters; ++i) { d += a; h += a*noise(p); p += vec2(10.7, 8.3); p *= pp; a *= aa; } h /= d; return h; } float height(vec2 p) { float h = fbm(p, 0.0, 5.0, 5); h *= 0.3; h += 0.0; return (h); } vec3 stars(vec3 ro, vec3 rd, vec2 sp, float hh) { vec3 col = vec3(0.0); const float m = LAYERS; hh = tanh_approx(20.0*hh); for (float i = 0.0; i < m; ++i) { vec2 pp = sp+0.5*i; float s = i/(m-1.0); vec2 dim = vec2(mix(0.05, 0.003, s)*PI); vec2 np = mod2(pp, dim); vec2 h = hash2(np+127.0+i); vec2 o = -1.0+2.0*h; float y = sin(sp.x); pp += o*dim*0.5; pp.y *= y; float l = length(pp); float h1 = fract(h.x*1667.0); float h2 = fract(h.x*1887.0); float h3 = fract(h.x*2997.0); vec3 scol = mix(8.0*h2, 0.25*h2*h2, s)*blackbody(mix(3000.0, 22000.0, h1*h1)); vec3 ccol = col + exp(-(mix(6000.0, 2000.0, hh)/mix(2.0, 0.25, s))*max(l-0.001, 0.0))*scol; col = h3 < y ? ccol : col; } return col; } // License: MIT, author: Inigo Quilez, found: https://iquilezles.org/articles/spherefunctions vec2 raySphere(vec3 ro, vec3 rd, vec4 sph) { vec3 oc = ro - sph.xyz; float b = dot( oc, rd ); float c = dot( oc, oc ) - sph.w*sph.w; float h = b*b - c; if( h<0.0 ) return vec2(-1.0); h = sqrt( h ); return vec2(-b - h, -b + h); } vec4 moon(vec3 ro, vec3 rd, vec2 sp, vec3 lp, vec4 md) { vec2 mi = raySphere(ro, rd, md); vec3 p = ro + mi.x*rd; vec3 n = normalize(p-md.xyz); vec3 r = reflect(rd, n); vec3 ld = normalize(lp - p); float fre = dot(n, rd)+1.0; fre = pow(fre, 15.0); float dif = max(dot(ld, n), 0.0); float spe = pow(max(dot(ld, r), 0.0), 8.0); float i = 0.5*tanh_approx(20.0*fre*spe+0.05*dif); vec3 col = blackbody(1500.0)*i+hsv2rgb(vec3(0.6, mix(0.6, 0.0, i), i)); float t = tanh_approx(0.25*(mi.y-mi.x)); return vec4(vec3(col), t); } vec3 sky(vec3 ro, vec3 rd, vec2 sp, vec3 lp, out float cf) { float ld = max(dot(normalize(lp-ro), rd),0.0); float y = -0.5+sp.x/PI; y = max(abs(y)-0.02, 0.0)+0.1*smoothstep(0.5, PI, abs(sp.y)); vec3 blue = hsv2rgb(vec3(0.6, 0.75, 0.35*exp(-15.0*y))); float ci = pow(ld, 10.0)*2.0*exp(-25.0*y); vec3 yellow = blackbody(1500.0)*ci; cf = ci; return blue+yellow; } vec3 galaxy(vec3 ro, vec3 rd, vec2 sp, out float sf) { vec2 gp = sp; gp *= ROT(0.67); gp += vec2(-1.0, 0.5); float h1 = height(2.0*sp); float gcc = dot(gp, gp); float gcx = exp(-(abs(3.0*(gp.x)))); float gcy = exp(-abs(10.0*(gp.y))); float gh = gcy*gcx; float cf = smoothstep(0.05, -0.2, -h1); vec3 col = vec3(0.0); col += blackbody(mix(300.0, 1500.0, gcx*gcy))*gcy*gcx; col += hsv2rgb(vec3(0.6, 0.5, 0.00125/gcc)); col *= mix(mix(0.15, 1.0, gcy*gcx), 1.0, cf); sf = gh*cf; return col; } vec3 grid(vec3 ro, vec3 rd, vec2 sp) { const float m = 1.0; const vec2 dim = vec2(1.0/8.0*PI); vec2 pp = sp; vec2 np = mod2(pp, dim); vec3 col = vec3(0.0); float y = sin(sp.x); float d = min(abs(pp.x), abs(pp.y*y)); float aa = 2.0/RESOLUTION.y; col += 2.0*vec3(0.5, 0.5, 1.0)*exp(-2000.0*max(d-0.00025, 0.0)); return 0.25*tanh(col); } vec3 color(vec3 ro, vec3 rd, vec3 lp, vec4 md) { vec2 sp = toSpherical(rd.xzy).yz; float sf = 0.0; float cf = 0.0; vec3 col = vec3(0.0); vec4 mcol = moon(ro, rd, sp, lp, md); col += stars(ro, rd, sp, sf)*(1.0-tanh_approx(2.0*cf)); col += galaxy(ro, rd, sp, sf); col = mix(col, mcol.xyz, mcol.w); col += sky(ro, rd, sp, lp, cf); col += grid(ro, rd, sp); if (rd.y < 0.0) { col = vec3(0.0); } return col; } void mainImage(out vec4 fragColor, in vec2 fragCoord) { vec2 q = fragCoord/iResolution.xy; vec2 p = -1.0 + 2.0*q; p.x *= RESOLUTION.x/RESOLUTION.y; vec3 ro = vec3(0.0, 0.0, 0.0); vec3 lp = 500.0*vec3(1.0, -0.25, 0.0); vec4 md = 50.0*vec4(vec3(1.0, 1., -0.6), 0.5); vec3 la = vec3(1.0, 0.5, 0.0); vec3 up = vec3(0.0, 1.0, 0.0); la.xz *= ROT(TTIME/60.0-PI/2.0); vec3 ww = normalize(la - ro); vec3 uu = normalize(cross(up, ww)); vec3 vv = normalize(cross(ww,uu)); vec3 rd = normalize(p.x*uu + p.y*vv + 2.0*ww); vec3 col= color(ro, rd, lp, md); col *= smoothstep(0.0, 4.0, TIME)*smoothstep(30.0, 26.0, TIME); col = aces_approx(col); col = sRGB(col); fragColor = vec4(col,1.0); }
cc0-1.0
[ 877, 984, 1010, 1010, 1194 ]
[ [ 509, 609, 630, 630, 703 ], [ 704, 804, 826, 826, 875 ], [ 877, 984, 1010, 1010, 1194 ], [ 1196, 1256, 1284, 1350, 1426 ], [ 1581, 1581, 1603, 1603, 1749 ], [ 1751, 1837, 1873, 1873, 1967 ], [ 1969, 2029, 2049, 2049, 2161 ], [ 2163, 2163, 2184, 2184, 2214 ], [ 2216, 2216, 2242, 2242, 2351 ], [ 2354, 2492, 2520, 2520, 2832 ], [ 2835, 2919, 2940, 3032, 3436 ], [ 3438, 3438, 3486, 3486, 3768 ], [ 3770, 3770, 3792, 3792, 3865 ], [ 3867, 3867, 3916, 3916, 4643 ], [ 4645, 4739, 4783, 4783, 4981 ], [ 4984, 4984, 5040, 5040, 5543 ], [ 5545, 5545, 5605, 5605, 5922 ], [ 5924, 5924, 5978, 5978, 6441 ], [ 6443, 6443, 6481, 6481, 6809 ], [ 6811, 6811, 6859, 6859, 7251 ], [ 7253, 7253, 7308, 7308, 7971 ] ]
// License: Unknown, author: Matt Taylor (https://github.com/64), found: https://64.github.io/tonemapping/
vec3 aces_approx(vec3 v) {
v = max(v, 0.0); 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); }
// License: Unknown, author: Matt Taylor (https://github.com/64), found: https://64.github.io/tonemapping/ vec3 aces_approx(vec3 v) {
72
77
stBcW1
mrange
2022-04-10T14:31:46
// License CC0: Stars and galaxy // Bit of sunday tinkering lead to stars and a galaxy // Didn't turn out as I envisioned but it turned out to something // that I liked so sharing it. // Controls how many layers of stars #define LAYERS 5.0 #define PI 3.141592654 #define TAU (2.0*PI) #define TIME mod(iTime, 30.0) #define TTIME (TAU*TIME) #define RESOLUTION iResolution #define ROT(a) mat2(cos(a), sin(a), -sin(a), cos(a)) // License: Unknown, author: nmz (twitter: @stormoid), found: https://www.shadertoy.com/view/NdfyRM float sRGB(float t) { return mix(1.055*pow(t, 1./2.4) - 0.055, 12.92*t, step(t, 0.0031308)); } // License: Unknown, author: nmz (twitter: @stormoid), found: https://www.shadertoy.com/view/NdfyRM vec3 sRGB(in vec3 c) { return vec3 (sRGB(c.x), sRGB(c.y), sRGB(c.z)); } // License: Unknown, author: Matt Taylor (https://github.com/64), found: https://64.github.io/tonemapping/ vec3 aces_approx(vec3 v) { v = max(v, 0.0); 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); } // License: Unknown, author: Unknown, found: don't remember float tanh_approx(float x) { // Found this somewhere on the interwebs // return tanh(x); float x2 = x*x; return clamp(x*(27.0 + x2)/(27.0+9.0*x2), -1.0, 1.0); } // License: WTFPL, author: sam hocevar, found: https://stackoverflow.com/a/17897228/418488 const vec4 hsv2rgb_K = vec4(1.0, 2.0 / 3.0, 1.0 / 3.0, 3.0); vec3 hsv2rgb(vec3 c) { vec3 p = abs(fract(c.xxx + hsv2rgb_K.xyz) * 6.0 - hsv2rgb_K.www); return c.z * mix(hsv2rgb_K.xxx, clamp(p - hsv2rgb_K.xxx, 0.0, 1.0), c.y); } // License: MIT OR CC-BY-NC-4.0, author: mercury, found: https://mercury.sexy/hg_sdf/ vec2 mod2(inout vec2 p, vec2 size) { vec2 c = floor((p + size*0.5)/size); p = mod(p + size*0.5,size) - size*0.5; return c; } // License: Unknown, author: Unknown, found: don't remember vec2 hash2(vec2 p) { p = vec2(dot (p, vec2 (127.1, 311.7)), dot (p, vec2 (269.5, 183.3))); return fract(sin(p)*43758.5453123); } vec2 shash2(vec2 p) { return -1.0+2.0*hash2(p); } vec3 toSpherical(vec3 p) { float r = length(p); float t = acos(p.z/r); float ph = atan(p.y, p.x); return vec3(r, t, ph); } // License: CC BY-NC-SA 3.0, author: Stephane Cuillerdier - Aiekick/2015 (twitter:@aiekick), found: https://www.shadertoy.com/view/Mt3GW2 vec3 blackbody(float Temp) { vec3 col = vec3(255.); col.x = 56100000. * pow(Temp,(-3. / 2.)) + 148.; col.y = 100.04 * log(Temp) - 623.6; if (Temp > 6500.) col.y = 35200000. * pow(Temp,(-3. / 2.)) + 184.; col.z = 194.18 * log(Temp) - 1448.6; col = clamp(col, 0., 255.)/255.; if (Temp < 1000.) col *= Temp/1000.; return col; } // License: MIT, author: Inigo Quilez, found: https://www.shadertoy.com/view/XslGRr float noise(vec2 p) { // Found at https://www.shadertoy.com/view/sdlXWX // Which then redirected to IQ shader vec2 i = floor(p); vec2 f = fract(p); vec2 u = f*f*(3.-2.*f); float n = mix( mix( dot(shash2(i + vec2(0.,0.) ), f - vec2(0.,0.)), dot(shash2(i + vec2(1.,0.) ), f - vec2(1.,0.)), u.x), mix( dot(shash2(i + vec2(0.,1.) ), f - vec2(0.,1.)), dot(shash2(i + vec2(1.,1.) ), f - vec2(1.,1.)), u.x), u.y); return 2.0*n; } float fbm(vec2 p, float o, float s, int iters) { p *= s; p += o; const float aa = 0.5; const mat2 pp = 2.04*ROT(1.0); float h = 0.0; float a = 1.0; float d = 0.0; for (int i = 0; i < iters; ++i) { d += a; h += a*noise(p); p += vec2(10.7, 8.3); p *= pp; a *= aa; } h /= d; return h; } float height(vec2 p) { float h = fbm(p, 0.0, 5.0, 5); h *= 0.3; h += 0.0; return (h); } vec3 stars(vec3 ro, vec3 rd, vec2 sp, float hh) { vec3 col = vec3(0.0); const float m = LAYERS; hh = tanh_approx(20.0*hh); for (float i = 0.0; i < m; ++i) { vec2 pp = sp+0.5*i; float s = i/(m-1.0); vec2 dim = vec2(mix(0.05, 0.003, s)*PI); vec2 np = mod2(pp, dim); vec2 h = hash2(np+127.0+i); vec2 o = -1.0+2.0*h; float y = sin(sp.x); pp += o*dim*0.5; pp.y *= y; float l = length(pp); float h1 = fract(h.x*1667.0); float h2 = fract(h.x*1887.0); float h3 = fract(h.x*2997.0); vec3 scol = mix(8.0*h2, 0.25*h2*h2, s)*blackbody(mix(3000.0, 22000.0, h1*h1)); vec3 ccol = col + exp(-(mix(6000.0, 2000.0, hh)/mix(2.0, 0.25, s))*max(l-0.001, 0.0))*scol; col = h3 < y ? ccol : col; } return col; } // License: MIT, author: Inigo Quilez, found: https://iquilezles.org/articles/spherefunctions vec2 raySphere(vec3 ro, vec3 rd, vec4 sph) { vec3 oc = ro - sph.xyz; float b = dot( oc, rd ); float c = dot( oc, oc ) - sph.w*sph.w; float h = b*b - c; if( h<0.0 ) return vec2(-1.0); h = sqrt( h ); return vec2(-b - h, -b + h); } vec4 moon(vec3 ro, vec3 rd, vec2 sp, vec3 lp, vec4 md) { vec2 mi = raySphere(ro, rd, md); vec3 p = ro + mi.x*rd; vec3 n = normalize(p-md.xyz); vec3 r = reflect(rd, n); vec3 ld = normalize(lp - p); float fre = dot(n, rd)+1.0; fre = pow(fre, 15.0); float dif = max(dot(ld, n), 0.0); float spe = pow(max(dot(ld, r), 0.0), 8.0); float i = 0.5*tanh_approx(20.0*fre*spe+0.05*dif); vec3 col = blackbody(1500.0)*i+hsv2rgb(vec3(0.6, mix(0.6, 0.0, i), i)); float t = tanh_approx(0.25*(mi.y-mi.x)); return vec4(vec3(col), t); } vec3 sky(vec3 ro, vec3 rd, vec2 sp, vec3 lp, out float cf) { float ld = max(dot(normalize(lp-ro), rd),0.0); float y = -0.5+sp.x/PI; y = max(abs(y)-0.02, 0.0)+0.1*smoothstep(0.5, PI, abs(sp.y)); vec3 blue = hsv2rgb(vec3(0.6, 0.75, 0.35*exp(-15.0*y))); float ci = pow(ld, 10.0)*2.0*exp(-25.0*y); vec3 yellow = blackbody(1500.0)*ci; cf = ci; return blue+yellow; } vec3 galaxy(vec3 ro, vec3 rd, vec2 sp, out float sf) { vec2 gp = sp; gp *= ROT(0.67); gp += vec2(-1.0, 0.5); float h1 = height(2.0*sp); float gcc = dot(gp, gp); float gcx = exp(-(abs(3.0*(gp.x)))); float gcy = exp(-abs(10.0*(gp.y))); float gh = gcy*gcx; float cf = smoothstep(0.05, -0.2, -h1); vec3 col = vec3(0.0); col += blackbody(mix(300.0, 1500.0, gcx*gcy))*gcy*gcx; col += hsv2rgb(vec3(0.6, 0.5, 0.00125/gcc)); col *= mix(mix(0.15, 1.0, gcy*gcx), 1.0, cf); sf = gh*cf; return col; } vec3 grid(vec3 ro, vec3 rd, vec2 sp) { const float m = 1.0; const vec2 dim = vec2(1.0/8.0*PI); vec2 pp = sp; vec2 np = mod2(pp, dim); vec3 col = vec3(0.0); float y = sin(sp.x); float d = min(abs(pp.x), abs(pp.y*y)); float aa = 2.0/RESOLUTION.y; col += 2.0*vec3(0.5, 0.5, 1.0)*exp(-2000.0*max(d-0.00025, 0.0)); return 0.25*tanh(col); } vec3 color(vec3 ro, vec3 rd, vec3 lp, vec4 md) { vec2 sp = toSpherical(rd.xzy).yz; float sf = 0.0; float cf = 0.0; vec3 col = vec3(0.0); vec4 mcol = moon(ro, rd, sp, lp, md); col += stars(ro, rd, sp, sf)*(1.0-tanh_approx(2.0*cf)); col += galaxy(ro, rd, sp, sf); col = mix(col, mcol.xyz, mcol.w); col += sky(ro, rd, sp, lp, cf); col += grid(ro, rd, sp); if (rd.y < 0.0) { col = vec3(0.0); } return col; } void mainImage(out vec4 fragColor, in vec2 fragCoord) { vec2 q = fragCoord/iResolution.xy; vec2 p = -1.0 + 2.0*q; p.x *= RESOLUTION.x/RESOLUTION.y; vec3 ro = vec3(0.0, 0.0, 0.0); vec3 lp = 500.0*vec3(1.0, -0.25, 0.0); vec4 md = 50.0*vec4(vec3(1.0, 1., -0.6), 0.5); vec3 la = vec3(1.0, 0.5, 0.0); vec3 up = vec3(0.0, 1.0, 0.0); la.xz *= ROT(TTIME/60.0-PI/2.0); vec3 ww = normalize(la - ro); vec3 uu = normalize(cross(up, ww)); vec3 vv = normalize(cross(ww,uu)); vec3 rd = normalize(p.x*uu + p.y*vv + 2.0*ww); vec3 col= color(ro, rd, lp, md); col *= smoothstep(0.0, 4.0, TIME)*smoothstep(30.0, 26.0, TIME); col = aces_approx(col); col = sRGB(col); fragColor = vec4(col,1.0); }
cc0-1.0
[ 1969, 2029, 2049, 2049, 2161 ]
[ [ 509, 609, 630, 630, 703 ], [ 704, 804, 826, 826, 875 ], [ 877, 984, 1010, 1010, 1194 ], [ 1196, 1256, 1284, 1350, 1426 ], [ 1581, 1581, 1603, 1603, 1749 ], [ 1751, 1837, 1873, 1873, 1967 ], [ 1969, 2029, 2049, 2049, 2161 ], [ 2163, 2163, 2184, 2184, 2214 ], [ 2216, 2216, 2242, 2242, 2351 ], [ 2354, 2492, 2520, 2520, 2832 ], [ 2835, 2919, 2940, 3032, 3436 ], [ 3438, 3438, 3486, 3486, 3768 ], [ 3770, 3770, 3792, 3792, 3865 ], [ 3867, 3867, 3916, 3916, 4643 ], [ 4645, 4739, 4783, 4783, 4981 ], [ 4984, 4984, 5040, 5040, 5543 ], [ 5545, 5545, 5605, 5605, 5922 ], [ 5924, 5924, 5978, 5978, 6441 ], [ 6443, 6443, 6481, 6481, 6809 ], [ 6811, 6811, 6859, 6859, 7251 ], [ 7253, 7253, 7308, 7308, 7971 ] ]
// License: Unknown, author: Unknown, found: don't remember
vec2 hash2(vec2 p) {
p = vec2(dot (p, vec2 (127.1, 311.7)), dot (p, vec2 (269.5, 183.3))); return fract(sin(p)*43758.5453123); }
// License: Unknown, author: Unknown, found: don't remember vec2 hash2(vec2 p) {
6
24
stBcW1
mrange
2022-04-10T14:31:46
// License CC0: Stars and galaxy // Bit of sunday tinkering lead to stars and a galaxy // Didn't turn out as I envisioned but it turned out to something // that I liked so sharing it. // Controls how many layers of stars #define LAYERS 5.0 #define PI 3.141592654 #define TAU (2.0*PI) #define TIME mod(iTime, 30.0) #define TTIME (TAU*TIME) #define RESOLUTION iResolution #define ROT(a) mat2(cos(a), sin(a), -sin(a), cos(a)) // License: Unknown, author: nmz (twitter: @stormoid), found: https://www.shadertoy.com/view/NdfyRM float sRGB(float t) { return mix(1.055*pow(t, 1./2.4) - 0.055, 12.92*t, step(t, 0.0031308)); } // License: Unknown, author: nmz (twitter: @stormoid), found: https://www.shadertoy.com/view/NdfyRM vec3 sRGB(in vec3 c) { return vec3 (sRGB(c.x), sRGB(c.y), sRGB(c.z)); } // License: Unknown, author: Matt Taylor (https://github.com/64), found: https://64.github.io/tonemapping/ vec3 aces_approx(vec3 v) { v = max(v, 0.0); 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); } // License: Unknown, author: Unknown, found: don't remember float tanh_approx(float x) { // Found this somewhere on the interwebs // return tanh(x); float x2 = x*x; return clamp(x*(27.0 + x2)/(27.0+9.0*x2), -1.0, 1.0); } // License: WTFPL, author: sam hocevar, found: https://stackoverflow.com/a/17897228/418488 const vec4 hsv2rgb_K = vec4(1.0, 2.0 / 3.0, 1.0 / 3.0, 3.0); vec3 hsv2rgb(vec3 c) { vec3 p = abs(fract(c.xxx + hsv2rgb_K.xyz) * 6.0 - hsv2rgb_K.www); return c.z * mix(hsv2rgb_K.xxx, clamp(p - hsv2rgb_K.xxx, 0.0, 1.0), c.y); } // License: MIT OR CC-BY-NC-4.0, author: mercury, found: https://mercury.sexy/hg_sdf/ vec2 mod2(inout vec2 p, vec2 size) { vec2 c = floor((p + size*0.5)/size); p = mod(p + size*0.5,size) - size*0.5; return c; } // License: Unknown, author: Unknown, found: don't remember vec2 hash2(vec2 p) { p = vec2(dot (p, vec2 (127.1, 311.7)), dot (p, vec2 (269.5, 183.3))); return fract(sin(p)*43758.5453123); } vec2 shash2(vec2 p) { return -1.0+2.0*hash2(p); } vec3 toSpherical(vec3 p) { float r = length(p); float t = acos(p.z/r); float ph = atan(p.y, p.x); return vec3(r, t, ph); } // License: CC BY-NC-SA 3.0, author: Stephane Cuillerdier - Aiekick/2015 (twitter:@aiekick), found: https://www.shadertoy.com/view/Mt3GW2 vec3 blackbody(float Temp) { vec3 col = vec3(255.); col.x = 56100000. * pow(Temp,(-3. / 2.)) + 148.; col.y = 100.04 * log(Temp) - 623.6; if (Temp > 6500.) col.y = 35200000. * pow(Temp,(-3. / 2.)) + 184.; col.z = 194.18 * log(Temp) - 1448.6; col = clamp(col, 0., 255.)/255.; if (Temp < 1000.) col *= Temp/1000.; return col; } // License: MIT, author: Inigo Quilez, found: https://www.shadertoy.com/view/XslGRr float noise(vec2 p) { // Found at https://www.shadertoy.com/view/sdlXWX // Which then redirected to IQ shader vec2 i = floor(p); vec2 f = fract(p); vec2 u = f*f*(3.-2.*f); float n = mix( mix( dot(shash2(i + vec2(0.,0.) ), f - vec2(0.,0.)), dot(shash2(i + vec2(1.,0.) ), f - vec2(1.,0.)), u.x), mix( dot(shash2(i + vec2(0.,1.) ), f - vec2(0.,1.)), dot(shash2(i + vec2(1.,1.) ), f - vec2(1.,1.)), u.x), u.y); return 2.0*n; } float fbm(vec2 p, float o, float s, int iters) { p *= s; p += o; const float aa = 0.5; const mat2 pp = 2.04*ROT(1.0); float h = 0.0; float a = 1.0; float d = 0.0; for (int i = 0; i < iters; ++i) { d += a; h += a*noise(p); p += vec2(10.7, 8.3); p *= pp; a *= aa; } h /= d; return h; } float height(vec2 p) { float h = fbm(p, 0.0, 5.0, 5); h *= 0.3; h += 0.0; return (h); } vec3 stars(vec3 ro, vec3 rd, vec2 sp, float hh) { vec3 col = vec3(0.0); const float m = LAYERS; hh = tanh_approx(20.0*hh); for (float i = 0.0; i < m; ++i) { vec2 pp = sp+0.5*i; float s = i/(m-1.0); vec2 dim = vec2(mix(0.05, 0.003, s)*PI); vec2 np = mod2(pp, dim); vec2 h = hash2(np+127.0+i); vec2 o = -1.0+2.0*h; float y = sin(sp.x); pp += o*dim*0.5; pp.y *= y; float l = length(pp); float h1 = fract(h.x*1667.0); float h2 = fract(h.x*1887.0); float h3 = fract(h.x*2997.0); vec3 scol = mix(8.0*h2, 0.25*h2*h2, s)*blackbody(mix(3000.0, 22000.0, h1*h1)); vec3 ccol = col + exp(-(mix(6000.0, 2000.0, hh)/mix(2.0, 0.25, s))*max(l-0.001, 0.0))*scol; col = h3 < y ? ccol : col; } return col; } // License: MIT, author: Inigo Quilez, found: https://iquilezles.org/articles/spherefunctions vec2 raySphere(vec3 ro, vec3 rd, vec4 sph) { vec3 oc = ro - sph.xyz; float b = dot( oc, rd ); float c = dot( oc, oc ) - sph.w*sph.w; float h = b*b - c; if( h<0.0 ) return vec2(-1.0); h = sqrt( h ); return vec2(-b - h, -b + h); } vec4 moon(vec3 ro, vec3 rd, vec2 sp, vec3 lp, vec4 md) { vec2 mi = raySphere(ro, rd, md); vec3 p = ro + mi.x*rd; vec3 n = normalize(p-md.xyz); vec3 r = reflect(rd, n); vec3 ld = normalize(lp - p); float fre = dot(n, rd)+1.0; fre = pow(fre, 15.0); float dif = max(dot(ld, n), 0.0); float spe = pow(max(dot(ld, r), 0.0), 8.0); float i = 0.5*tanh_approx(20.0*fre*spe+0.05*dif); vec3 col = blackbody(1500.0)*i+hsv2rgb(vec3(0.6, mix(0.6, 0.0, i), i)); float t = tanh_approx(0.25*(mi.y-mi.x)); return vec4(vec3(col), t); } vec3 sky(vec3 ro, vec3 rd, vec2 sp, vec3 lp, out float cf) { float ld = max(dot(normalize(lp-ro), rd),0.0); float y = -0.5+sp.x/PI; y = max(abs(y)-0.02, 0.0)+0.1*smoothstep(0.5, PI, abs(sp.y)); vec3 blue = hsv2rgb(vec3(0.6, 0.75, 0.35*exp(-15.0*y))); float ci = pow(ld, 10.0)*2.0*exp(-25.0*y); vec3 yellow = blackbody(1500.0)*ci; cf = ci; return blue+yellow; } vec3 galaxy(vec3 ro, vec3 rd, vec2 sp, out float sf) { vec2 gp = sp; gp *= ROT(0.67); gp += vec2(-1.0, 0.5); float h1 = height(2.0*sp); float gcc = dot(gp, gp); float gcx = exp(-(abs(3.0*(gp.x)))); float gcy = exp(-abs(10.0*(gp.y))); float gh = gcy*gcx; float cf = smoothstep(0.05, -0.2, -h1); vec3 col = vec3(0.0); col += blackbody(mix(300.0, 1500.0, gcx*gcy))*gcy*gcx; col += hsv2rgb(vec3(0.6, 0.5, 0.00125/gcc)); col *= mix(mix(0.15, 1.0, gcy*gcx), 1.0, cf); sf = gh*cf; return col; } vec3 grid(vec3 ro, vec3 rd, vec2 sp) { const float m = 1.0; const vec2 dim = vec2(1.0/8.0*PI); vec2 pp = sp; vec2 np = mod2(pp, dim); vec3 col = vec3(0.0); float y = sin(sp.x); float d = min(abs(pp.x), abs(pp.y*y)); float aa = 2.0/RESOLUTION.y; col += 2.0*vec3(0.5, 0.5, 1.0)*exp(-2000.0*max(d-0.00025, 0.0)); return 0.25*tanh(col); } vec3 color(vec3 ro, vec3 rd, vec3 lp, vec4 md) { vec2 sp = toSpherical(rd.xzy).yz; float sf = 0.0; float cf = 0.0; vec3 col = vec3(0.0); vec4 mcol = moon(ro, rd, sp, lp, md); col += stars(ro, rd, sp, sf)*(1.0-tanh_approx(2.0*cf)); col += galaxy(ro, rd, sp, sf); col = mix(col, mcol.xyz, mcol.w); col += sky(ro, rd, sp, lp, cf); col += grid(ro, rd, sp); if (rd.y < 0.0) { col = vec3(0.0); } return col; } void mainImage(out vec4 fragColor, in vec2 fragCoord) { vec2 q = fragCoord/iResolution.xy; vec2 p = -1.0 + 2.0*q; p.x *= RESOLUTION.x/RESOLUTION.y; vec3 ro = vec3(0.0, 0.0, 0.0); vec3 lp = 500.0*vec3(1.0, -0.25, 0.0); vec4 md = 50.0*vec4(vec3(1.0, 1., -0.6), 0.5); vec3 la = vec3(1.0, 0.5, 0.0); vec3 up = vec3(0.0, 1.0, 0.0); la.xz *= ROT(TTIME/60.0-PI/2.0); vec3 ww = normalize(la - ro); vec3 uu = normalize(cross(up, ww)); vec3 vv = normalize(cross(ww,uu)); vec3 rd = normalize(p.x*uu + p.y*vv + 2.0*ww); vec3 col= color(ro, rd, lp, md); col *= smoothstep(0.0, 4.0, TIME)*smoothstep(30.0, 26.0, TIME); col = aces_approx(col); col = sRGB(col); fragColor = vec4(col,1.0); }
cc0-1.0
[ 2354, 2492, 2520, 2520, 2832 ]
[ [ 509, 609, 630, 630, 703 ], [ 704, 804, 826, 826, 875 ], [ 877, 984, 1010, 1010, 1194 ], [ 1196, 1256, 1284, 1350, 1426 ], [ 1581, 1581, 1603, 1603, 1749 ], [ 1751, 1837, 1873, 1873, 1967 ], [ 1969, 2029, 2049, 2049, 2161 ], [ 2163, 2163, 2184, 2184, 2214 ], [ 2216, 2216, 2242, 2242, 2351 ], [ 2354, 2492, 2520, 2520, 2832 ], [ 2835, 2919, 2940, 3032, 3436 ], [ 3438, 3438, 3486, 3486, 3768 ], [ 3770, 3770, 3792, 3792, 3865 ], [ 3867, 3867, 3916, 3916, 4643 ], [ 4645, 4739, 4783, 4783, 4981 ], [ 4984, 4984, 5040, 5040, 5543 ], [ 5545, 5545, 5605, 5605, 5922 ], [ 5924, 5924, 5978, 5978, 6441 ], [ 6443, 6443, 6481, 6481, 6809 ], [ 6811, 6811, 6859, 6859, 7251 ], [ 7253, 7253, 7308, 7308, 7971 ] ]
// License: CC BY-NC-SA 3.0, author: Stephane Cuillerdier - Aiekick/2015 (twitter:@aiekick), found: https://www.shadertoy.com/view/Mt3GW2
vec3 blackbody(float Temp) {
vec3 col = vec3(255.); col.x = 56100000. * pow(Temp,(-3. / 2.)) + 148.; col.y = 100.04 * log(Temp) - 623.6; if (Temp > 6500.) col.y = 35200000. * pow(Temp,(-3. / 2.)) + 184.; col.z = 194.18 * log(Temp) - 1448.6; col = clamp(col, 0., 255.)/255.; if (Temp < 1000.) col *= Temp/1000.; return col; }
// License: CC BY-NC-SA 3.0, author: Stephane Cuillerdier - Aiekick/2015 (twitter:@aiekick), found: https://www.shadertoy.com/view/Mt3GW2 vec3 blackbody(float Temp) {
2
3
stBcW1
mrange
2022-04-10T14:31:46
// License CC0: Stars and galaxy // Bit of sunday tinkering lead to stars and a galaxy // Didn't turn out as I envisioned but it turned out to something // that I liked so sharing it. // Controls how many layers of stars #define LAYERS 5.0 #define PI 3.141592654 #define TAU (2.0*PI) #define TIME mod(iTime, 30.0) #define TTIME (TAU*TIME) #define RESOLUTION iResolution #define ROT(a) mat2(cos(a), sin(a), -sin(a), cos(a)) // License: Unknown, author: nmz (twitter: @stormoid), found: https://www.shadertoy.com/view/NdfyRM float sRGB(float t) { return mix(1.055*pow(t, 1./2.4) - 0.055, 12.92*t, step(t, 0.0031308)); } // License: Unknown, author: nmz (twitter: @stormoid), found: https://www.shadertoy.com/view/NdfyRM vec3 sRGB(in vec3 c) { return vec3 (sRGB(c.x), sRGB(c.y), sRGB(c.z)); } // License: Unknown, author: Matt Taylor (https://github.com/64), found: https://64.github.io/tonemapping/ vec3 aces_approx(vec3 v) { v = max(v, 0.0); 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); } // License: Unknown, author: Unknown, found: don't remember float tanh_approx(float x) { // Found this somewhere on the interwebs // return tanh(x); float x2 = x*x; return clamp(x*(27.0 + x2)/(27.0+9.0*x2), -1.0, 1.0); } // License: WTFPL, author: sam hocevar, found: https://stackoverflow.com/a/17897228/418488 const vec4 hsv2rgb_K = vec4(1.0, 2.0 / 3.0, 1.0 / 3.0, 3.0); vec3 hsv2rgb(vec3 c) { vec3 p = abs(fract(c.xxx + hsv2rgb_K.xyz) * 6.0 - hsv2rgb_K.www); return c.z * mix(hsv2rgb_K.xxx, clamp(p - hsv2rgb_K.xxx, 0.0, 1.0), c.y); } // License: MIT OR CC-BY-NC-4.0, author: mercury, found: https://mercury.sexy/hg_sdf/ vec2 mod2(inout vec2 p, vec2 size) { vec2 c = floor((p + size*0.5)/size); p = mod(p + size*0.5,size) - size*0.5; return c; } // License: Unknown, author: Unknown, found: don't remember vec2 hash2(vec2 p) { p = vec2(dot (p, vec2 (127.1, 311.7)), dot (p, vec2 (269.5, 183.3))); return fract(sin(p)*43758.5453123); } vec2 shash2(vec2 p) { return -1.0+2.0*hash2(p); } vec3 toSpherical(vec3 p) { float r = length(p); float t = acos(p.z/r); float ph = atan(p.y, p.x); return vec3(r, t, ph); } // License: CC BY-NC-SA 3.0, author: Stephane Cuillerdier - Aiekick/2015 (twitter:@aiekick), found: https://www.shadertoy.com/view/Mt3GW2 vec3 blackbody(float Temp) { vec3 col = vec3(255.); col.x = 56100000. * pow(Temp,(-3. / 2.)) + 148.; col.y = 100.04 * log(Temp) - 623.6; if (Temp > 6500.) col.y = 35200000. * pow(Temp,(-3. / 2.)) + 184.; col.z = 194.18 * log(Temp) - 1448.6; col = clamp(col, 0., 255.)/255.; if (Temp < 1000.) col *= Temp/1000.; return col; } // License: MIT, author: Inigo Quilez, found: https://www.shadertoy.com/view/XslGRr float noise(vec2 p) { // Found at https://www.shadertoy.com/view/sdlXWX // Which then redirected to IQ shader vec2 i = floor(p); vec2 f = fract(p); vec2 u = f*f*(3.-2.*f); float n = mix( mix( dot(shash2(i + vec2(0.,0.) ), f - vec2(0.,0.)), dot(shash2(i + vec2(1.,0.) ), f - vec2(1.,0.)), u.x), mix( dot(shash2(i + vec2(0.,1.) ), f - vec2(0.,1.)), dot(shash2(i + vec2(1.,1.) ), f - vec2(1.,1.)), u.x), u.y); return 2.0*n; } float fbm(vec2 p, float o, float s, int iters) { p *= s; p += o; const float aa = 0.5; const mat2 pp = 2.04*ROT(1.0); float h = 0.0; float a = 1.0; float d = 0.0; for (int i = 0; i < iters; ++i) { d += a; h += a*noise(p); p += vec2(10.7, 8.3); p *= pp; a *= aa; } h /= d; return h; } float height(vec2 p) { float h = fbm(p, 0.0, 5.0, 5); h *= 0.3; h += 0.0; return (h); } vec3 stars(vec3 ro, vec3 rd, vec2 sp, float hh) { vec3 col = vec3(0.0); const float m = LAYERS; hh = tanh_approx(20.0*hh); for (float i = 0.0; i < m; ++i) { vec2 pp = sp+0.5*i; float s = i/(m-1.0); vec2 dim = vec2(mix(0.05, 0.003, s)*PI); vec2 np = mod2(pp, dim); vec2 h = hash2(np+127.0+i); vec2 o = -1.0+2.0*h; float y = sin(sp.x); pp += o*dim*0.5; pp.y *= y; float l = length(pp); float h1 = fract(h.x*1667.0); float h2 = fract(h.x*1887.0); float h3 = fract(h.x*2997.0); vec3 scol = mix(8.0*h2, 0.25*h2*h2, s)*blackbody(mix(3000.0, 22000.0, h1*h1)); vec3 ccol = col + exp(-(mix(6000.0, 2000.0, hh)/mix(2.0, 0.25, s))*max(l-0.001, 0.0))*scol; col = h3 < y ? ccol : col; } return col; } // License: MIT, author: Inigo Quilez, found: https://iquilezles.org/articles/spherefunctions vec2 raySphere(vec3 ro, vec3 rd, vec4 sph) { vec3 oc = ro - sph.xyz; float b = dot( oc, rd ); float c = dot( oc, oc ) - sph.w*sph.w; float h = b*b - c; if( h<0.0 ) return vec2(-1.0); h = sqrt( h ); return vec2(-b - h, -b + h); } vec4 moon(vec3 ro, vec3 rd, vec2 sp, vec3 lp, vec4 md) { vec2 mi = raySphere(ro, rd, md); vec3 p = ro + mi.x*rd; vec3 n = normalize(p-md.xyz); vec3 r = reflect(rd, n); vec3 ld = normalize(lp - p); float fre = dot(n, rd)+1.0; fre = pow(fre, 15.0); float dif = max(dot(ld, n), 0.0); float spe = pow(max(dot(ld, r), 0.0), 8.0); float i = 0.5*tanh_approx(20.0*fre*spe+0.05*dif); vec3 col = blackbody(1500.0)*i+hsv2rgb(vec3(0.6, mix(0.6, 0.0, i), i)); float t = tanh_approx(0.25*(mi.y-mi.x)); return vec4(vec3(col), t); } vec3 sky(vec3 ro, vec3 rd, vec2 sp, vec3 lp, out float cf) { float ld = max(dot(normalize(lp-ro), rd),0.0); float y = -0.5+sp.x/PI; y = max(abs(y)-0.02, 0.0)+0.1*smoothstep(0.5, PI, abs(sp.y)); vec3 blue = hsv2rgb(vec3(0.6, 0.75, 0.35*exp(-15.0*y))); float ci = pow(ld, 10.0)*2.0*exp(-25.0*y); vec3 yellow = blackbody(1500.0)*ci; cf = ci; return blue+yellow; } vec3 galaxy(vec3 ro, vec3 rd, vec2 sp, out float sf) { vec2 gp = sp; gp *= ROT(0.67); gp += vec2(-1.0, 0.5); float h1 = height(2.0*sp); float gcc = dot(gp, gp); float gcx = exp(-(abs(3.0*(gp.x)))); float gcy = exp(-abs(10.0*(gp.y))); float gh = gcy*gcx; float cf = smoothstep(0.05, -0.2, -h1); vec3 col = vec3(0.0); col += blackbody(mix(300.0, 1500.0, gcx*gcy))*gcy*gcx; col += hsv2rgb(vec3(0.6, 0.5, 0.00125/gcc)); col *= mix(mix(0.15, 1.0, gcy*gcx), 1.0, cf); sf = gh*cf; return col; } vec3 grid(vec3 ro, vec3 rd, vec2 sp) { const float m = 1.0; const vec2 dim = vec2(1.0/8.0*PI); vec2 pp = sp; vec2 np = mod2(pp, dim); vec3 col = vec3(0.0); float y = sin(sp.x); float d = min(abs(pp.x), abs(pp.y*y)); float aa = 2.0/RESOLUTION.y; col += 2.0*vec3(0.5, 0.5, 1.0)*exp(-2000.0*max(d-0.00025, 0.0)); return 0.25*tanh(col); } vec3 color(vec3 ro, vec3 rd, vec3 lp, vec4 md) { vec2 sp = toSpherical(rd.xzy).yz; float sf = 0.0; float cf = 0.0; vec3 col = vec3(0.0); vec4 mcol = moon(ro, rd, sp, lp, md); col += stars(ro, rd, sp, sf)*(1.0-tanh_approx(2.0*cf)); col += galaxy(ro, rd, sp, sf); col = mix(col, mcol.xyz, mcol.w); col += sky(ro, rd, sp, lp, cf); col += grid(ro, rd, sp); if (rd.y < 0.0) { col = vec3(0.0); } return col; } void mainImage(out vec4 fragColor, in vec2 fragCoord) { vec2 q = fragCoord/iResolution.xy; vec2 p = -1.0 + 2.0*q; p.x *= RESOLUTION.x/RESOLUTION.y; vec3 ro = vec3(0.0, 0.0, 0.0); vec3 lp = 500.0*vec3(1.0, -0.25, 0.0); vec4 md = 50.0*vec4(vec3(1.0, 1., -0.6), 0.5); vec3 la = vec3(1.0, 0.5, 0.0); vec3 up = vec3(0.0, 1.0, 0.0); la.xz *= ROT(TTIME/60.0-PI/2.0); vec3 ww = normalize(la - ro); vec3 uu = normalize(cross(up, ww)); vec3 vv = normalize(cross(ww,uu)); vec3 rd = normalize(p.x*uu + p.y*vv + 2.0*ww); vec3 col= color(ro, rd, lp, md); col *= smoothstep(0.0, 4.0, TIME)*smoothstep(30.0, 26.0, TIME); col = aces_approx(col); col = sRGB(col); fragColor = vec4(col,1.0); }
cc0-1.0
[ 2835, 2919, 2940, 3032, 3436 ]
[ [ 509, 609, 630, 630, 703 ], [ 704, 804, 826, 826, 875 ], [ 877, 984, 1010, 1010, 1194 ], [ 1196, 1256, 1284, 1350, 1426 ], [ 1581, 1581, 1603, 1603, 1749 ], [ 1751, 1837, 1873, 1873, 1967 ], [ 1969, 2029, 2049, 2049, 2161 ], [ 2163, 2163, 2184, 2184, 2214 ], [ 2216, 2216, 2242, 2242, 2351 ], [ 2354, 2492, 2520, 2520, 2832 ], [ 2835, 2919, 2940, 3032, 3436 ], [ 3438, 3438, 3486, 3486, 3768 ], [ 3770, 3770, 3792, 3792, 3865 ], [ 3867, 3867, 3916, 3916, 4643 ], [ 4645, 4739, 4783, 4783, 4981 ], [ 4984, 4984, 5040, 5040, 5543 ], [ 5545, 5545, 5605, 5605, 5922 ], [ 5924, 5924, 5978, 5978, 6441 ], [ 6443, 6443, 6481, 6481, 6809 ], [ 6811, 6811, 6859, 6859, 7251 ], [ 7253, 7253, 7308, 7308, 7971 ] ]
// License: MIT, author: Inigo Quilez, found: https://www.shadertoy.com/view/XslGRr
float noise(vec2 p) {
vec2 i = floor(p); vec2 f = fract(p); vec2 u = f*f*(3.-2.*f); float n = mix( mix( dot(shash2(i + vec2(0.,0.) ), f - vec2(0.,0.)), dot(shash2(i + vec2(1.,0.) ), f - vec2(1.,0.)), u.x), mix( dot(shash2(i + vec2(0.,1.) ), f - vec2(0.,1.)), dot(shash2(i + vec2(1.,1.) ), f - vec2(1.,1.)), u.x), u.y); return 2.0*n; }
// License: MIT, author: Inigo Quilez, found: https://www.shadertoy.com/view/XslGRr float noise(vec2 p) {
1
66
stBcW1
mrange
2022-04-10T14:31:46
// License CC0: Stars and galaxy // Bit of sunday tinkering lead to stars and a galaxy // Didn't turn out as I envisioned but it turned out to something // that I liked so sharing it. // Controls how many layers of stars #define LAYERS 5.0 #define PI 3.141592654 #define TAU (2.0*PI) #define TIME mod(iTime, 30.0) #define TTIME (TAU*TIME) #define RESOLUTION iResolution #define ROT(a) mat2(cos(a), sin(a), -sin(a), cos(a)) // License: Unknown, author: nmz (twitter: @stormoid), found: https://www.shadertoy.com/view/NdfyRM float sRGB(float t) { return mix(1.055*pow(t, 1./2.4) - 0.055, 12.92*t, step(t, 0.0031308)); } // License: Unknown, author: nmz (twitter: @stormoid), found: https://www.shadertoy.com/view/NdfyRM vec3 sRGB(in vec3 c) { return vec3 (sRGB(c.x), sRGB(c.y), sRGB(c.z)); } // License: Unknown, author: Matt Taylor (https://github.com/64), found: https://64.github.io/tonemapping/ vec3 aces_approx(vec3 v) { v = max(v, 0.0); 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); } // License: Unknown, author: Unknown, found: don't remember float tanh_approx(float x) { // Found this somewhere on the interwebs // return tanh(x); float x2 = x*x; return clamp(x*(27.0 + x2)/(27.0+9.0*x2), -1.0, 1.0); } // License: WTFPL, author: sam hocevar, found: https://stackoverflow.com/a/17897228/418488 const vec4 hsv2rgb_K = vec4(1.0, 2.0 / 3.0, 1.0 / 3.0, 3.0); vec3 hsv2rgb(vec3 c) { vec3 p = abs(fract(c.xxx + hsv2rgb_K.xyz) * 6.0 - hsv2rgb_K.www); return c.z * mix(hsv2rgb_K.xxx, clamp(p - hsv2rgb_K.xxx, 0.0, 1.0), c.y); } // License: MIT OR CC-BY-NC-4.0, author: mercury, found: https://mercury.sexy/hg_sdf/ vec2 mod2(inout vec2 p, vec2 size) { vec2 c = floor((p + size*0.5)/size); p = mod(p + size*0.5,size) - size*0.5; return c; } // License: Unknown, author: Unknown, found: don't remember vec2 hash2(vec2 p) { p = vec2(dot (p, vec2 (127.1, 311.7)), dot (p, vec2 (269.5, 183.3))); return fract(sin(p)*43758.5453123); } vec2 shash2(vec2 p) { return -1.0+2.0*hash2(p); } vec3 toSpherical(vec3 p) { float r = length(p); float t = acos(p.z/r); float ph = atan(p.y, p.x); return vec3(r, t, ph); } // License: CC BY-NC-SA 3.0, author: Stephane Cuillerdier - Aiekick/2015 (twitter:@aiekick), found: https://www.shadertoy.com/view/Mt3GW2 vec3 blackbody(float Temp) { vec3 col = vec3(255.); col.x = 56100000. * pow(Temp,(-3. / 2.)) + 148.; col.y = 100.04 * log(Temp) - 623.6; if (Temp > 6500.) col.y = 35200000. * pow(Temp,(-3. / 2.)) + 184.; col.z = 194.18 * log(Temp) - 1448.6; col = clamp(col, 0., 255.)/255.; if (Temp < 1000.) col *= Temp/1000.; return col; } // License: MIT, author: Inigo Quilez, found: https://www.shadertoy.com/view/XslGRr float noise(vec2 p) { // Found at https://www.shadertoy.com/view/sdlXWX // Which then redirected to IQ shader vec2 i = floor(p); vec2 f = fract(p); vec2 u = f*f*(3.-2.*f); float n = mix( mix( dot(shash2(i + vec2(0.,0.) ), f - vec2(0.,0.)), dot(shash2(i + vec2(1.,0.) ), f - vec2(1.,0.)), u.x), mix( dot(shash2(i + vec2(0.,1.) ), f - vec2(0.,1.)), dot(shash2(i + vec2(1.,1.) ), f - vec2(1.,1.)), u.x), u.y); return 2.0*n; } float fbm(vec2 p, float o, float s, int iters) { p *= s; p += o; const float aa = 0.5; const mat2 pp = 2.04*ROT(1.0); float h = 0.0; float a = 1.0; float d = 0.0; for (int i = 0; i < iters; ++i) { d += a; h += a*noise(p); p += vec2(10.7, 8.3); p *= pp; a *= aa; } h /= d; return h; } float height(vec2 p) { float h = fbm(p, 0.0, 5.0, 5); h *= 0.3; h += 0.0; return (h); } vec3 stars(vec3 ro, vec3 rd, vec2 sp, float hh) { vec3 col = vec3(0.0); const float m = LAYERS; hh = tanh_approx(20.0*hh); for (float i = 0.0; i < m; ++i) { vec2 pp = sp+0.5*i; float s = i/(m-1.0); vec2 dim = vec2(mix(0.05, 0.003, s)*PI); vec2 np = mod2(pp, dim); vec2 h = hash2(np+127.0+i); vec2 o = -1.0+2.0*h; float y = sin(sp.x); pp += o*dim*0.5; pp.y *= y; float l = length(pp); float h1 = fract(h.x*1667.0); float h2 = fract(h.x*1887.0); float h3 = fract(h.x*2997.0); vec3 scol = mix(8.0*h2, 0.25*h2*h2, s)*blackbody(mix(3000.0, 22000.0, h1*h1)); vec3 ccol = col + exp(-(mix(6000.0, 2000.0, hh)/mix(2.0, 0.25, s))*max(l-0.001, 0.0))*scol; col = h3 < y ? ccol : col; } return col; } // License: MIT, author: Inigo Quilez, found: https://iquilezles.org/articles/spherefunctions vec2 raySphere(vec3 ro, vec3 rd, vec4 sph) { vec3 oc = ro - sph.xyz; float b = dot( oc, rd ); float c = dot( oc, oc ) - sph.w*sph.w; float h = b*b - c; if( h<0.0 ) return vec2(-1.0); h = sqrt( h ); return vec2(-b - h, -b + h); } vec4 moon(vec3 ro, vec3 rd, vec2 sp, vec3 lp, vec4 md) { vec2 mi = raySphere(ro, rd, md); vec3 p = ro + mi.x*rd; vec3 n = normalize(p-md.xyz); vec3 r = reflect(rd, n); vec3 ld = normalize(lp - p); float fre = dot(n, rd)+1.0; fre = pow(fre, 15.0); float dif = max(dot(ld, n), 0.0); float spe = pow(max(dot(ld, r), 0.0), 8.0); float i = 0.5*tanh_approx(20.0*fre*spe+0.05*dif); vec3 col = blackbody(1500.0)*i+hsv2rgb(vec3(0.6, mix(0.6, 0.0, i), i)); float t = tanh_approx(0.25*(mi.y-mi.x)); return vec4(vec3(col), t); } vec3 sky(vec3 ro, vec3 rd, vec2 sp, vec3 lp, out float cf) { float ld = max(dot(normalize(lp-ro), rd),0.0); float y = -0.5+sp.x/PI; y = max(abs(y)-0.02, 0.0)+0.1*smoothstep(0.5, PI, abs(sp.y)); vec3 blue = hsv2rgb(vec3(0.6, 0.75, 0.35*exp(-15.0*y))); float ci = pow(ld, 10.0)*2.0*exp(-25.0*y); vec3 yellow = blackbody(1500.0)*ci; cf = ci; return blue+yellow; } vec3 galaxy(vec3 ro, vec3 rd, vec2 sp, out float sf) { vec2 gp = sp; gp *= ROT(0.67); gp += vec2(-1.0, 0.5); float h1 = height(2.0*sp); float gcc = dot(gp, gp); float gcx = exp(-(abs(3.0*(gp.x)))); float gcy = exp(-abs(10.0*(gp.y))); float gh = gcy*gcx; float cf = smoothstep(0.05, -0.2, -h1); vec3 col = vec3(0.0); col += blackbody(mix(300.0, 1500.0, gcx*gcy))*gcy*gcx; col += hsv2rgb(vec3(0.6, 0.5, 0.00125/gcc)); col *= mix(mix(0.15, 1.0, gcy*gcx), 1.0, cf); sf = gh*cf; return col; } vec3 grid(vec3 ro, vec3 rd, vec2 sp) { const float m = 1.0; const vec2 dim = vec2(1.0/8.0*PI); vec2 pp = sp; vec2 np = mod2(pp, dim); vec3 col = vec3(0.0); float y = sin(sp.x); float d = min(abs(pp.x), abs(pp.y*y)); float aa = 2.0/RESOLUTION.y; col += 2.0*vec3(0.5, 0.5, 1.0)*exp(-2000.0*max(d-0.00025, 0.0)); return 0.25*tanh(col); } vec3 color(vec3 ro, vec3 rd, vec3 lp, vec4 md) { vec2 sp = toSpherical(rd.xzy).yz; float sf = 0.0; float cf = 0.0; vec3 col = vec3(0.0); vec4 mcol = moon(ro, rd, sp, lp, md); col += stars(ro, rd, sp, sf)*(1.0-tanh_approx(2.0*cf)); col += galaxy(ro, rd, sp, sf); col = mix(col, mcol.xyz, mcol.w); col += sky(ro, rd, sp, lp, cf); col += grid(ro, rd, sp); if (rd.y < 0.0) { col = vec3(0.0); } return col; } void mainImage(out vec4 fragColor, in vec2 fragCoord) { vec2 q = fragCoord/iResolution.xy; vec2 p = -1.0 + 2.0*q; p.x *= RESOLUTION.x/RESOLUTION.y; vec3 ro = vec3(0.0, 0.0, 0.0); vec3 lp = 500.0*vec3(1.0, -0.25, 0.0); vec4 md = 50.0*vec4(vec3(1.0, 1., -0.6), 0.5); vec3 la = vec3(1.0, 0.5, 0.0); vec3 up = vec3(0.0, 1.0, 0.0); la.xz *= ROT(TTIME/60.0-PI/2.0); vec3 ww = normalize(la - ro); vec3 uu = normalize(cross(up, ww)); vec3 vv = normalize(cross(ww,uu)); vec3 rd = normalize(p.x*uu + p.y*vv + 2.0*ww); vec3 col= color(ro, rd, lp, md); col *= smoothstep(0.0, 4.0, TIME)*smoothstep(30.0, 26.0, TIME); col = aces_approx(col); col = sRGB(col); fragColor = vec4(col,1.0); }
cc0-1.0
[ 4645, 4739, 4783, 4783, 4981 ]
[ [ 509, 609, 630, 630, 703 ], [ 704, 804, 826, 826, 875 ], [ 877, 984, 1010, 1010, 1194 ], [ 1196, 1256, 1284, 1350, 1426 ], [ 1581, 1581, 1603, 1603, 1749 ], [ 1751, 1837, 1873, 1873, 1967 ], [ 1969, 2029, 2049, 2049, 2161 ], [ 2163, 2163, 2184, 2184, 2214 ], [ 2216, 2216, 2242, 2242, 2351 ], [ 2354, 2492, 2520, 2520, 2832 ], [ 2835, 2919, 2940, 3032, 3436 ], [ 3438, 3438, 3486, 3486, 3768 ], [ 3770, 3770, 3792, 3792, 3865 ], [ 3867, 3867, 3916, 3916, 4643 ], [ 4645, 4739, 4783, 4783, 4981 ], [ 4984, 4984, 5040, 5040, 5543 ], [ 5545, 5545, 5605, 5605, 5922 ], [ 5924, 5924, 5978, 5978, 6441 ], [ 6443, 6443, 6481, 6481, 6809 ], [ 6811, 6811, 6859, 6859, 7251 ], [ 7253, 7253, 7308, 7308, 7971 ] ]
// License: MIT, author: Inigo Quilez, found: https://iquilezles.org/articles/spherefunctions
vec2 raySphere(vec3 ro, vec3 rd, vec4 sph) {
vec3 oc = ro - sph.xyz; float b = dot( oc, rd ); float c = dot( oc, oc ) - sph.w*sph.w; float h = b*b - c; if( h<0.0 ) return vec2(-1.0); h = sqrt( h ); return vec2(-b - h, -b + h); }
// License: MIT, author: Inigo Quilez, found: https://iquilezles.org/articles/spherefunctions vec2 raySphere(vec3 ro, vec3 rd, vec4 sph) {
2
11
fs3yDM
iq
2022-05-25T18:16:32
// The MIT License // Copyright © 2022 Inigo Quilez // Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. // https://www.youtube.com/c/InigoQuilez // https://iquilezles.org // Correct SDF and gradient to a Squircle. NOTE - this is a brite force // way to do this, it has tesselation artifacts and is slow. But it is exact // (in the limit). Not also this is NOT a great way go blend between a circle // and a square btw; for that you can use https://www.shadertoy.com/view/7sdXz2 // .x = f(p) // .y = ∂f(p)/∂x // .z = ∂f(p)/∂y // .yz = ∇f(p) with ‖∇f(p)‖ = 1 vec3 sdSquircle(vec2 p, float n) { // symmetries vec2 k = sign(p); p = abs(p); bool m = p.y>p.x; if( m ) p=p.yx; const int num = 16; // tesselate into 8x16=128 segments, more denselly at the corners float s = 1.0; float d = 1e20; vec2 oq = vec2(1.0,0.0); vec2 g = vec2(0.0,0.0); for( int i=1; i<=num; i++ ) { float h = (6.283185/8.0)*float(i)/float(num); vec2 q = pow(vec2(cos(h),sin(h)),vec2(2.0/n)); vec2 pa = p-oq; vec2 ba = q-oq; vec2 z = pa - ba*clamp( dot(pa,ba)/dot(ba,ba), 0.0, 1.0 ); float d2 = dot(z,z); if( d2<d ) { d = d2; s = pa.x*ba.y - pa.y*ba.x; g = z; } oq = q; } // undo symmetries if( m ) g=g.yx; g*=k; d = sign(s)*sqrt(d); return vec3( d, g/d ); } float incorrect_sdSquircle(vec2 p, float n) { return pow(pow(abs(p.x),n) + pow(abs(p.y),n),1.0/n) - 1.0; } void mainImage( out vec4 fragColor, in vec2 fragCoord ) { // normalized pixel coordinates vec2 p = (2.0*fragCoord-iResolution.xy)/iResolution.y; vec2 m = (2.0*iMouse.xy-iResolution.xy)/iResolution.y; p *= 1.4; m *= 1.4; // animation float n = 3.0 + 2.5*sin(6.283185*iTime/3.0); // distance vec3 dg = sdSquircle(p, n); float d = dg.x; vec2 g = dg.yz; // central differenes based gradient, for comparison //g = vec2( dFdx(d), dFdy(d) )/(2.0*1.4/iResolution.y); // coloring vec3 col = (d>0.0) ? vec3(0.9,0.6,0.3) : vec3(0.4,0.7,0.85); col *= 1.0 + vec3(0.5*g,0.0); col *= 1.0 - 0.5*exp(-8.0*abs(d)); col *= 0.9 + 0.1*cos(90.0*d); col = mix( col, vec3(1.0), 1.0-smoothstep(0.0,0.015,abs(d)) ); // mouse interaction if( iMouse.z>0.001 ) { d = sdSquircle(m,n).x; col = mix(col, vec3(1.0,1.0,0.0), 1.0-smoothstep(0.0, 0.010, abs(length(p-m)-abs(d))-0.0025)); col = mix(col, vec3(1.0,1.0,0.0), 1.0-smoothstep(0.0, 0.010, length(p-m)-0.015)); } fragColor = vec4(col, 1.0); }
mit
[ 1454, 1549, 1583, 1601, 2412 ]
[ [ 1454, 1549, 1583, 1601, 2412 ], [ 2414, 2414, 2459, 2459, 2524 ], [ 2526, 2526, 2583, 2619, 3613 ] ]
// .x = f(p) // .y = ∂f(p)/∂x // .z = ∂f(p)/∂y // .yz = ∇f(p) with ‖∇f(p)‖ = 1
vec3 sdSquircle(vec2 p, float n) {
vec2 k = sign(p); p = abs(p); bool m = p.y>p.x; if( m ) p=p.yx; const int num = 16; // tesselate into 8x16=128 segments, more denselly at the corners float s = 1.0; float d = 1e20; vec2 oq = vec2(1.0,0.0); vec2 g = vec2(0.0,0.0); for( int i=1; i<=num; i++ ) { float h = (6.283185/8.0)*float(i)/float(num); vec2 q = pow(vec2(cos(h),sin(h)),vec2(2.0/n)); vec2 pa = p-oq; vec2 ba = q-oq; vec2 z = pa - ba*clamp( dot(pa,ba)/dot(ba,ba), 0.0, 1.0 ); float d2 = dot(z,z); if( d2<d ) { d = d2; s = pa.x*ba.y - pa.y*ba.x; g = z; } oq = q; } // undo symmetries if( m ) g=g.yx; g*=k; d = sign(s)*sqrt(d); return vec3( d, g/d ); }
// .x = f(p) // .y = ∂f(p)/∂x // .z = ∂f(p)/∂y // .yz = ∇f(p) with ‖∇f(p)‖ = 1 vec3 sdSquircle(vec2 p, float n) {
1
1
7tBfD3
iq
2022-05-17T20:22:30
// The MIT License // Copyright © 2022 Inigo Quilez // Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. // The Devil's Stairs (https://en.m.wikipedia.org/wiki/Cantor_function) climbs around f(x)=x // but can be generalize to any monotonic function for which we can compute the inverse. float fun_smt( float x, float k ) { return pow(x,k)/(pow(x,k)+pow(1.0-x,k)); } float inv_smt( float x, float k ) { return fun_smt(x,1.0/k); } float fun_pow( float x, float k ) { return pow(x,k); } float inv_pow( float x, float k ) { return fun_pow(x,1.0/k); } float function( float x, float t ) { float k = exp2(3.0*(0.5-0.5*cos(t*6.283185/3.0))); return (t<3.0) ? fun_smt(x,k) : fun_pow(x,k); } float inverse_function( float x, float t ) { float k = exp2(3.0*(0.5-0.5*cos(t*6.283185/3.0))); return (t<3.0) ? inv_smt(x,k) : inv_pow(x,k); } // generalization of Devil's Staircase float cantor( float x, float t ) { float y = 0.0; float sc = 0.5; float bi = 0.0; float xa = 0.0; float xb = 1.0; for( int i=0; i<9; i++ ) { // choose subdivision intervals float ya = function(xa,t); float yb = function(xb,t); float wa = inverse_function(ya+(yb-ya)/3.0,t); float wb = inverse_function(yb-(yb-ya)/3.0,t); // recurse if( x<wa ) { bi+=0.0*sc; y=bi+sc*(x-xa)/(wa-xa); xb=wa; } else if( x>wb ) { bi+=1.0*sc; y=bi+sc*(x-wb)/(xb-wb); xa=wb; } else { bi+=0.0*sc; y=bi+sc; break; } sc *= 0.5; } return y; } // https://iquilezles.org/articles/distfunctions2d/ float sdLine( in vec2 p, in vec2 a, in vec2 b ) { vec2 pa = p-a, ba = b-a; return length(pa-ba*clamp(dot(pa,ba)/dot(ba,ba),0.0,1.0)); } void mainImage( out vec4 fragColor, in vec2 fragCoord ) { // pixel coords float px = 1.0/iResolution.y; vec2 p = (vec2((iResolution.y-iResolution.x)/2.0,0.0)+fragCoord)*px; // animation loop float t = mod(iTime,6.0); // render vec3 col = vec3(0.0); if( p.x>0.0 && p.x<1.0 ) { // background col = vec3( 0.04 + 0.008*mod(floor(p.x*10.0)+floor(p.y*10.0),2.0) ); // plot vec2 d = vec2(1e20); for( int i=-2; i<2; i++ ) { float x0 = p.x + px*float(i+0); float x1 = p.x + px*float(i+1); d.x = min( d.x, sdLine(p, vec2(x0, function(x0,t)), vec2(x1, function(x1,t)))); d.y = min( d.y, sdLine(p, vec2(x0, cantor( x0,t)), vec2(x1, cantor( x1,t)))); } col = mix( col, vec3(0.25,0.25,0.25), 1.0-smoothstep(0.0007,0.0007+px,d.x) ); col = mix( col, vec3(1.00,0.36,0.04), 1.0-smoothstep(0.0007,0.0007+px,d.y) ); } // gamma col = sqrt(col); fragColor = vec4( col, 1.0 ); }
mit
[ 1819, 1858, 1892, 1892, 2519 ]
[ [ 1261, 1261, 1296, 1296, 1339 ], [ 1340, 1340, 1375, 1375, 1402 ], [ 1403, 1403, 1438, 1438, 1457 ], [ 1458, 1458, 1493, 1493, 1520 ], [ 1522, 1522, 1558, 1558, 1665 ], [ 1666, 1666, 1710, 1710, 1817 ], [ 1819, 1858, 1892, 1892, 2519 ], [ 2521, 2573, 2622, 2622, 2710 ], [ 2712, 2712, 2769, 2790, 3835 ] ]
// generalization of Devil's Staircase
float cantor( float x, float t ) {
float y = 0.0; float sc = 0.5; float bi = 0.0; float xa = 0.0; float xb = 1.0; for( int i=0; i<9; i++ ) { // choose subdivision intervals float ya = function(xa,t); float yb = function(xb,t); float wa = inverse_function(ya+(yb-ya)/3.0,t); float wb = inverse_function(yb-(yb-ya)/3.0,t); // recurse if( x<wa ) { bi+=0.0*sc; y=bi+sc*(x-xa)/(wa-xa); xb=wa; } else if( x>wb ) { bi+=1.0*sc; y=bi+sc*(x-wb)/(xb-wb); xa=wb; } else { bi+=0.0*sc; y=bi+sc; break; } sc *= 0.5; } return y; }
// generalization of Devil's Staircase float cantor( float x, float t ) {
1
1
7tBfD3
iq
2022-05-17T20:22:30
// The MIT License // Copyright © 2022 Inigo Quilez // Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. // The Devil's Stairs (https://en.m.wikipedia.org/wiki/Cantor_function) climbs around f(x)=x // but can be generalize to any monotonic function for which we can compute the inverse. float fun_smt( float x, float k ) { return pow(x,k)/(pow(x,k)+pow(1.0-x,k)); } float inv_smt( float x, float k ) { return fun_smt(x,1.0/k); } float fun_pow( float x, float k ) { return pow(x,k); } float inv_pow( float x, float k ) { return fun_pow(x,1.0/k); } float function( float x, float t ) { float k = exp2(3.0*(0.5-0.5*cos(t*6.283185/3.0))); return (t<3.0) ? fun_smt(x,k) : fun_pow(x,k); } float inverse_function( float x, float t ) { float k = exp2(3.0*(0.5-0.5*cos(t*6.283185/3.0))); return (t<3.0) ? inv_smt(x,k) : inv_pow(x,k); } // generalization of Devil's Staircase float cantor( float x, float t ) { float y = 0.0; float sc = 0.5; float bi = 0.0; float xa = 0.0; float xb = 1.0; for( int i=0; i<9; i++ ) { // choose subdivision intervals float ya = function(xa,t); float yb = function(xb,t); float wa = inverse_function(ya+(yb-ya)/3.0,t); float wb = inverse_function(yb-(yb-ya)/3.0,t); // recurse if( x<wa ) { bi+=0.0*sc; y=bi+sc*(x-xa)/(wa-xa); xb=wa; } else if( x>wb ) { bi+=1.0*sc; y=bi+sc*(x-wb)/(xb-wb); xa=wb; } else { bi+=0.0*sc; y=bi+sc; break; } sc *= 0.5; } return y; } // https://iquilezles.org/articles/distfunctions2d/ float sdLine( in vec2 p, in vec2 a, in vec2 b ) { vec2 pa = p-a, ba = b-a; return length(pa-ba*clamp(dot(pa,ba)/dot(ba,ba),0.0,1.0)); } void mainImage( out vec4 fragColor, in vec2 fragCoord ) { // pixel coords float px = 1.0/iResolution.y; vec2 p = (vec2((iResolution.y-iResolution.x)/2.0,0.0)+fragCoord)*px; // animation loop float t = mod(iTime,6.0); // render vec3 col = vec3(0.0); if( p.x>0.0 && p.x<1.0 ) { // background col = vec3( 0.04 + 0.008*mod(floor(p.x*10.0)+floor(p.y*10.0),2.0) ); // plot vec2 d = vec2(1e20); for( int i=-2; i<2; i++ ) { float x0 = p.x + px*float(i+0); float x1 = p.x + px*float(i+1); d.x = min( d.x, sdLine(p, vec2(x0, function(x0,t)), vec2(x1, function(x1,t)))); d.y = min( d.y, sdLine(p, vec2(x0, cantor( x0,t)), vec2(x1, cantor( x1,t)))); } col = mix( col, vec3(0.25,0.25,0.25), 1.0-smoothstep(0.0007,0.0007+px,d.x) ); col = mix( col, vec3(1.00,0.36,0.04), 1.0-smoothstep(0.0007,0.0007+px,d.y) ); } // gamma col = sqrt(col); fragColor = vec4( col, 1.0 ); }
mit
[ 2521, 2573, 2622, 2622, 2710 ]
[ [ 1261, 1261, 1296, 1296, 1339 ], [ 1340, 1340, 1375, 1375, 1402 ], [ 1403, 1403, 1438, 1438, 1457 ], [ 1458, 1458, 1493, 1493, 1520 ], [ 1522, 1522, 1558, 1558, 1665 ], [ 1666, 1666, 1710, 1710, 1817 ], [ 1819, 1858, 1892, 1892, 2519 ], [ 2521, 2573, 2622, 2622, 2710 ], [ 2712, 2712, 2769, 2790, 3835 ] ]
// https://iquilezles.org/articles/distfunctions2d/
float sdLine( in vec2 p, in vec2 a, in vec2 b ) {
vec2 pa = p-a, ba = b-a; return length(pa-ba*clamp(dot(pa,ba)/dot(ba,ba),0.0,1.0)); }
// https://iquilezles.org/articles/distfunctions2d/ float sdLine( in vec2 p, in vec2 a, in vec2 b ) {
1
23
NljfzV
morimea
2022-05-13T15:35:20
// Created by Danil (2022+) https://github.com/danilw // License - CC0 or use as you wish // main point of this shader is - fractal that generate different image depends of parameters // look map function // to play with parameters and use Mouse control, 5 is index in arrays below that size of psz //#define use_func 5 // to test animation loop with mouse //#define mouse_loop #define cam_orbit 2.05 // params #define psz 8 // scale float p0[psz] = float[]( 0.7, 0.7, 0.7, 0.7, 0.57, 0.697, .09, 2.57); // biggest visual impact float p1[psz] = float[]( 0.07, 0.07, -0.107, -0.07, -0.69, -0.69, -0.1069, -0.69); float p2[psz] = float[](-0.15, -0.15, 1.84, -0.15, -0.015, 0.015, -0.02015, -0.015); float p3[psz] = float[]( 0.465, 0.184, 0.465, 0.465, 0.2465, 0.1465, 1.465, 0.2465); // number of loops, keep low (clamped to 1 to 30 to not kill your GPU) int p5[psz] = int[](5,5,10,5,5,5,10,5); // main fractal func float map(in vec3 p, int idx) { float res = 0.; vec3 c = p; for (int i = 0; i < clamp(p5[idx],1,30); ++i) { p =p0[idx]*abs(p)/max(dot(p,p+p2[idx]*p/(p+0.0001*(1.-abs(sign(p))))),0.0001) + p1[idx]; p=p.zxy; res += exp(-33. * abs(dot(p,p3[idx]*c))); } return res; } vec3 postProcess(vec3 col, float ct); vec3 march(vec3 ro, vec3 rd, int idx, float c_timer, float ct2) { float t = 0.; float dt = 0.152; vec3 col = vec3(0.0); float c = 0.; const int max_iter = 48; for(int i = 0; i < max_iter; ++i) { t += dt*exp(-1.50*c); vec3 pos = ro+t*rd; c = map(pos,idx); //c *= 0.025+2.*iMouse.y/iResolution.y; //test color with mouse c *= 0.025+2.*c_timer; float center = -0.35; // center of color shift float dist = (abs(pos.x + pos.y + center))*2.5; vec3 dcol = vec3(c*c+0.5*c*c-c*dist, c*c-c, c); // color func col = col + dcol*1./float(max_iter); } col *= 0.18; col=clamp(col,0.,1.); return postProcess(col, ct2); } vec3 postProcess(vec3 col, float ct) { col = col*0.85+0.85*col*col.brb; col = col*0.6+0.64*col*col*(3.0-2.0*col)+0.5*col*col; col = col+0.4*(col.rrb-vec3(dot(col, vec3(0.33)))); vec3 c1=col-0.344*(col.brb-vec3(dot(col, vec3(0.33)))); vec3 c2=col+0.64*(col.ggr-vec3(dot(col, vec3(0.33)))); col=mix(col,c1,min(ct*2.,1.)); col=mix(col,c2,-clamp(ct*2.-1.,0.,1.)); //col*=1.5; col=col*01.5+0.5*col*col; return col; } // fractal color function #define PI 3.14159265 vec4 get_color(vec2 p , int idx, float timer, float c_timer) { idx = idx%psz; vec4 fragColor; float time = iTime; vec3 ret_col = vec3(0.0); float mouseY = 0.15 * PI; mouseY = (1.0 - 0.5*1.15 * (1.83-timer)) * 0.5 * PI; #ifdef use_func mouseY = (1.0 - 1.15 * iMouse.y / iResolution.y) * 0.5 * PI; //test MOUSE #endif #ifndef mouse_loop if(iMouse.z>0.&&iMouse.w<iResolution.y)mouseY = (1.0 - 1.15 * iMouse.y / iResolution.y) * 0.5 * PI; #endif float mouseX = -1.25*PI; mouseX+=-(timer*1.5+0.25) * .5 * PI; #ifdef use_func mouseX=-1.25*PI-(iMouse.x / iResolution.x) * 3. * PI; //test MOUSE #endif #ifndef mouse_loop if(iMouse.z>0.&&iMouse.z<iResolution.x)mouseX=-1.25*PI-(iMouse.x / iResolution.x) * 3. * PI; #endif vec3 eye = cam_orbit*vec3(cos(mouseX) * cos(mouseY), sin(mouseX) * cos(mouseY), sin(mouseY)); eye = eye+0.0001*(1.-abs(sign(eye))); vec3 ro = eye; vec3 w = normalize(-eye); vec3 up = vec3(0., 0., 1.); vec3 u = normalize(cross(w, up)); vec3 v = cross(u, w); vec3 rd = normalize(w + p.x * u + p.y * v); vec3 col = march(ro, rd, idx, timer*0.30+0.15*timer*timer+0.25, c_timer); col = clamp(col,0.,1.); fragColor = vec4( col, 1.0 ); return fragColor; } // everything else is just Shadertoy presentation, not related to fractal // mainImage has godrays + image slider logic vec2 plane(vec2 uv, float timer); float GetBayerFromCoordLevel(vec2 pixelpos); vec3 pal( in float t, in vec3 a, in vec3 b, in vec3 c, in vec3 d ); float hash(vec2 p); void mainImage( out vec4 fragColor, in vec2 fragCoord) { fragColor = vec4(0.); vec2 res = iResolution.xy/iResolution.y; vec2 uv = fragCoord/iResolution.y; #ifdef use_func fragColor = get_color((uv-res*0.5)*2., use_func, 0.65, 0.); return; #endif const float grn = 7.; // number of tiles for slider float sx = 0.5*(1./grn)+0.5*0.25*(floor(res.x/(1./grn))-0.5*res.x/(1./grn)); uv.x += sx; vec2 gid = floor(uv*grn); uv = fract(uv*grn)-0.5; // timers float gtime = iTime*.645; // gtime=float(psz)*6. sec loop #ifdef mouse_loop gtime=float(psz)*6.*iMouse.x/iResolution.x; //test MOUSE #endif // timer logic float tt = mod(gtime,12.); float tt2 = mod(gtime+6.,12.); float i1 = smoothstep(3.,6.,tt);float i2 = smoothstep(9.,12.,tt); float ltime = (i1+i2)*3.+floor(gtime/12.)*6.; float s_timer = (smoothstep(3.,12.,tt2)); float s_timer2 = (smoothstep(3.,12.,tt)); int itdx = int(ltime+3.)/6; int itdx2 = int(ltime)/6; float gmix1 = 0.5-0.5*cos(gtime/6.*0.35); float gmix2 = 0.5-0.5*cos(gtime/6.*0.25); // godrays vec3 occ_col=vec3(0.); { #define DECAY .974 #define EXPOSURE .116907 #define SAMPLES 32 #define DENSITY .595 #define WEIGHT .25 vec2 coord = fragCoord.xy/iResolution.xy; float cd = 1.75*length(coord-0.5); float occ=0.; vec2 lightpos = vec2(0.51,0.503); float dither = GetBayerFromCoordLevel(fragCoord); vec2 dtc = (coord - lightpos) * (1. / float(SAMPLES) * DENSITY); float illumdecay = 1.; for(int i=0; i<SAMPLES; i++) { coord -= dtc; vec2 otuv = coord+(dtc*dither); vec2 tuv = otuv*res; tuv.x += sx; vec2 lgid = floor(tuv*grn); tuv = fract(tuv*grn)-0.5; float lctimer = 0.0; float lctime = ltime - (lgid.y/grn - lgid.x/(grn*res.x))*1.-grn/16.+2.; lctime = mod(lctime, 6.); lctimer += smoothstep(0.0, 1.0, lctime); lctimer += 1. - smoothstep(3.0, 4.0, lctime); lctimer = abs(lctimer-1.0); vec2 tuv_pl = plane(tuv,lctimer); float noplx = float(abs(tuv_pl.x)>0.5||abs(tuv_pl.y)>0.5); float s = (noplx)*(1.-smoothstep(-0.03,0.75,.5*length(otuv-0.5))); s *= illumdecay * WEIGHT; occ += s; illumdecay *= DECAY; } occ=1.5*occ*EXPOSURE; occ_col = occ*(1./max(cd,0.0001))* pal( mix(cd*occ*0.35,cd+occ*0.35,gmix1), vec3(0.5,0.5,0.5),vec3(0.5,0.5,0.5),vec3(2.0,1.0,0.0),vec3(0.5,0.20,0.25) ).gbr; occ_col=clamp(occ_col,0.,1.); } //---- float timer = 0.0; float time = ltime - (gid.y/grn - gid.x/(grn*res.x))*1.-grn/16.+2.; time = mod(time, 6.); timer += smoothstep(0.0, 1.0, time); timer += 1. - smoothstep(3.0, 4.0, time); timer = abs(timer-1.0); float side = step(0.5, timer); vec2 uv_pl = plane(uv,timer); vec2 tp = (fragCoord.xy/iResolution.xy-0.5)*2.; tp = pow(abs(tp), vec2(2.0)); float tcd = 0.5+0.5*clamp(1.0 - dot(tp, tp),0.,1.); float cineshader_alpha = smoothstep(0.,1.,(timer))*0.5*tcd; //float cineshader_alpha = smoothstep(0.,1.,2.*abs(timer-.5))*0.5*tcd; bool nopl = abs(uv_pl.x)>0.5||abs(uv_pl.y)>0.5; uv_pl += 0.5; if(side<0.5)uv_pl.x=1.-uv_pl.x; if (nopl) { fragColor = vec4(occ_col,cineshader_alpha); return; } vec2 tuv = ((uv_pl*1./res)*1./grn+((gid*1./grn)+vec2(-sx,0.))*1./res); if(side>0.5)fragColor = get_color((tuv-0.5)*res*2.,0+itdx*2,s_timer, gmix2); else fragColor = get_color((tuv-0.5)*res*2.,1+itdx2*2,s_timer2, gmix2); //fragColor.rgb*=smoothstep(0.,1.,2.*abs(timer-.5)); fragColor = vec4(fragColor.rgb+occ_col,cineshader_alpha); fragColor.rgb = clamp(fragColor.rgb,0.,1.); } vec2 plane(vec2 uv, float timer) { timer = radians(timer*180.0); vec4 n = vec4(cos(timer),0,sin(timer),-sin(timer)); vec3 d = vec3(1.0,uv.y,uv.x); vec3 p = vec3(-1.0+n.w/4.0,0.,0.); vec3 up = vec3(0.,1.,0.); vec3 right = cross(up, n.xyz); float dn = dot(d, n.xyz);dn+=0.00001*(1.-abs(sign(dn))); float pn = dot(p, n.xyz); vec3 hit = p - d / dn * pn; return vec2(dot(hit, right), dot(hit, up)); } float GetBayerFromCoordLevel(vec2 pixelpos) { ivec2 ppos = ivec2(pixelpos); int sum = 0; const int MAX_LEVEL = 3; for(int i=0; i<MAX_LEVEL; i++) { ivec2 tv = ppos>>(MAX_LEVEL-1-i)&1; sum += ((4-(tv).x-((tv).y<<1))%4)<<(2*i); } return float(sum) / float(2<<(MAX_LEVEL*2-1)); } vec3 pal( in float t, in vec3 a, in vec3 b, in vec3 c, in vec3 d ) { return a + b*cos( 6.28318*(c*t+d) ); }
cc0-1.0
[ 929, 950, 981, 981, 1259 ]
[ [ 929, 950, 981, 981, 1259 ], [ 1300, 1300, 1365, 1365, 1992 ], [ 1994, 1994, 2032, 2032, 2425 ], [ 2478, 2478, 2540, 2540, 3740 ], [ 4033, 4033, 4089, 4089, 7984 ], [ 7987, 7987, 8021, 8021, 8427 ], [ 8430, 8430, 8475, 8475, 8745 ], [ 8747, 8747, 8815, 8815, 8858 ] ]
// main fractal func
float map(in vec3 p, int idx) {
float res = 0.; vec3 c = p; for (int i = 0; i < clamp(p5[idx],1,30); ++i) { p =p0[idx]*abs(p)/max(dot(p,p+p2[idx]*p/(p+0.0001*(1.-abs(sign(p))))),0.0001) + p1[idx]; p=p.zxy; res += exp(-33. * abs(dot(p,p3[idx]*c))); } return res; }
// main fractal func float map(in vec3 p, int idx) {
1
1
sstfzM
mrange
2022-06-26T19:12:30
// License CC0 - Complex atanh - darkmode edition // More work tinkering based on mlas shader Complex atanh - https://www.shadertoy.com/view/tsBXRW #define DARKMODE #define FASTATAN #define RESOLUTION iResolution #define TIME iTime #define PI 3.141592654 #define PI_2 (0.5*PI) #define TAU (2.0*PI) #define ROT(a) mat2(cos(a), sin(a), -sin(a), cos(a)) #if defined(FASTATAN) #define ATAN atan_approx #else #define ATAN atan #endif // License: WTFPL, author: sam hocevar, found: https://stackoverflow.com/a/17897228/418488 const vec4 hsv2rgb_K = vec4(1.0, 2.0 / 3.0, 1.0 / 3.0, 3.0); vec3 hsv2rgb(vec3 c) { vec3 p = abs(fract(c.xxx + hsv2rgb_K.xyz) * 6.0 - hsv2rgb_K.www); return c.z * mix(hsv2rgb_K.xxx, clamp(p - hsv2rgb_K.xxx, 0.0, 1.0), 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)) // License: MIT OR CC-BY-NC-4.0, author: mercury, found: https://mercury.sexy/hg_sdf/ vec2 mod2(inout vec2 p, vec2 size) { vec2 c = floor((p + size*0.5)/size); p = mod(p + size*0.5,size) - size*0.5; return c; } // License: Unknown, author: Unknown, found: don't remember float tanh_approx(float x) { // Found this somewhere on the interwebs // return tanh(x); float x2 = x*x; return clamp(x*(27.0 + x2)/(27.0+9.0*x2), -1.0, 1.0); } // License: MIT, author: Pascal Gilcher, found: https://www.shadertoy.com/view/flSXRV float atan_approx(float y, float x) { float cosatan2 = x / (abs(x) + abs(y)); float t = PI_2 - cosatan2 * PI_2; return y < 0.0 ? -t : t; } // Complex trig functions found at: Complex Atanh - https://www.shadertoy.com/view/tsBXRW // A very cool shader vec2 cmul(vec2 z, vec2 w) { return vec2 (z.x*w.x-z.y*w.y, z.x*w.y+z.y*w.x); } vec2 cinv(vec2 z) { float t = dot(z,z); return vec2(z.x,-z.y)/t; } vec2 cdiv(vec2 z, vec2 w) { return cmul(z,cinv(w)); } vec2 clog(vec2 z) { float r = length(z); return vec2(log(r),ATAN(z.y,z.x)); } // Inverse hyperbolic tangent vec2 catanh(vec2 z) { return 0.5*clog(cdiv(vec2(1,0)+z,vec2(1,0)-z)); } // My own attempt at an ctanh vec2 cexp(vec2 z) { float r = exp(z.x); return r*vec2(cos(z.y), sin(z.y)); } vec2 ctanh(vec2 z) { z = cexp(2.0*z); return cdiv(vec2(1,0)-z,vec2(1,0)+z); } float circle8(vec2 p, float r) { p *= p; p *= p; return pow(dot(p, p),1.0/8.0)-r; } vec2 transform(vec2 z, out float aa, out vec2 hscale) { float A = 9.0; float B = 2.0; if (iMouse.x > 0.0) { // Get angle from mouse position vec2 m = (2.0*iMouse.xy-iResolution.xy)/iResolution.y; m *= 20.0; A = floor(m.x), B = floor(m.y); } vec2 rot = vec2(A, B); float a = TIME; z *= 2.0; z = catanh(-0.5*z+0.5*vec2(sin(a*0.234*sqrt(0.5)), sin(a*0.234)))+catanh(z*ROT(0.1234*a)); z /= PI; aa = fwidth(z.x); aa *= length(rot); z = cmul(rot,z); z.x += 0.5*a; hscale = 1.0/rot.yx; return z; } vec3 effect(vec3 col, vec2 op) { op *= ROT(0.05*TIME); float aaa = 2.0/RESOLUTION.y; float aa; vec2 hscale; vec2 p = transform(op, aa, hscale); vec2 n = round(p); p -= n; // Neat! float d = circle8(p, 0.45); vec2 pf = p; float sf = sign(pf.x*pf.y); pf = abs(pf); float df = sf*min(pf.x, pf.y); float flip = smoothstep(aa, -aa, df); #if defined(DARKMODE) col = vec3(0.0); float fo = tanh_approx(0.333*aaa/(aa*hscale.x*hscale.y)); vec3 rgb = hsv2rgb(vec3(fract(0.65+0.2*sin(0.5*TIME+0.25*flip+PI*dot(n, hscale))), mix(0.0, 0.75, fo), mix(1.0, 0.05, fo*fo))); #else col = vec3(1.0); float fo = tanh_approx(0.125*aaa/(aa*hscale.x*hscale.y)); vec3 rgb = hsv2rgb(vec3(fract(0.05*TIME+0.125*flip+0.5*dot(hscale, n)), mix(0.0, 0.75, fo), mix(1.0, 0.85, fo*fo))); #endif rgb = mix(rgb, smoothstep(0.5, 1.0, rgb), flip); col = mix(col, rgb, smoothstep(aa, -aa, d)); return col; } void mainImage(out vec4 fragColor, in vec2 fragCoord) { vec2 q = fragCoord/RESOLUTION.xy; vec2 p = -1. + 2. * q; p.x *= RESOLUTION.x/RESOLUTION.y; vec3 col = vec3(1.0); col = effect(col, p); col = clamp(col, 0.0, 1.0); col *= smoothstep(0.0, 3.0, TIME); col = sqrt(col); fragColor = vec4(col, 1.0); }
cc0-1.0
[ 1534, 1620, 1657, 1657, 1764 ]
[ [ 621, 621, 643, 643, 789 ], [ 1084, 1170, 1206, 1206, 1300 ], [ 1302, 1362, 1390, 1456, 1532 ], [ 1534, 1620, 1657, 1657, 1764 ], [ 1766, 1879, 1906, 1906, 1958 ], [ 1960, 1960, 1979, 1979, 2030 ], [ 2032, 2032, 2059, 2059, 2087 ], [ 2089, 2089, 2108, 2108, 2170 ], [ 2172, 2203, 2224, 2224, 2276 ], [ 2278, 2308, 2327, 2327, 2388 ], [ 2390, 2390, 2410, 2410, 2471 ], [ 2473, 2473, 2505, 2505, 2562 ], [ 2564, 2564, 2619, 2619, 3103 ], [ 3105, 3105, 3137, 3137, 4025 ], [ 4027, 4027, 4082, 4082, 4353 ] ]
// License: MIT, author: Pascal Gilcher, found: https://www.shadertoy.com/view/flSXRV
float atan_approx(float y, float x) {
float cosatan2 = x / (abs(x) + abs(y)); float t = PI_2 - cosatan2 * PI_2; return y < 0.0 ? -t : t; }
// License: MIT, author: Pascal Gilcher, found: https://www.shadertoy.com/view/flSXRV float atan_approx(float y, float x) {
14
14
sstfzM
mrange
2022-06-26T19:12:30
// License CC0 - Complex atanh - darkmode edition // More work tinkering based on mlas shader Complex atanh - https://www.shadertoy.com/view/tsBXRW #define DARKMODE #define FASTATAN #define RESOLUTION iResolution #define TIME iTime #define PI 3.141592654 #define PI_2 (0.5*PI) #define TAU (2.0*PI) #define ROT(a) mat2(cos(a), sin(a), -sin(a), cos(a)) #if defined(FASTATAN) #define ATAN atan_approx #else #define ATAN atan #endif // License: WTFPL, author: sam hocevar, found: https://stackoverflow.com/a/17897228/418488 const vec4 hsv2rgb_K = vec4(1.0, 2.0 / 3.0, 1.0 / 3.0, 3.0); vec3 hsv2rgb(vec3 c) { vec3 p = abs(fract(c.xxx + hsv2rgb_K.xyz) * 6.0 - hsv2rgb_K.www); return c.z * mix(hsv2rgb_K.xxx, clamp(p - hsv2rgb_K.xxx, 0.0, 1.0), 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)) // License: MIT OR CC-BY-NC-4.0, author: mercury, found: https://mercury.sexy/hg_sdf/ vec2 mod2(inout vec2 p, vec2 size) { vec2 c = floor((p + size*0.5)/size); p = mod(p + size*0.5,size) - size*0.5; return c; } // License: Unknown, author: Unknown, found: don't remember float tanh_approx(float x) { // Found this somewhere on the interwebs // return tanh(x); float x2 = x*x; return clamp(x*(27.0 + x2)/(27.0+9.0*x2), -1.0, 1.0); } // License: MIT, author: Pascal Gilcher, found: https://www.shadertoy.com/view/flSXRV float atan_approx(float y, float x) { float cosatan2 = x / (abs(x) + abs(y)); float t = PI_2 - cosatan2 * PI_2; return y < 0.0 ? -t : t; } // Complex trig functions found at: Complex Atanh - https://www.shadertoy.com/view/tsBXRW // A very cool shader vec2 cmul(vec2 z, vec2 w) { return vec2 (z.x*w.x-z.y*w.y, z.x*w.y+z.y*w.x); } vec2 cinv(vec2 z) { float t = dot(z,z); return vec2(z.x,-z.y)/t; } vec2 cdiv(vec2 z, vec2 w) { return cmul(z,cinv(w)); } vec2 clog(vec2 z) { float r = length(z); return vec2(log(r),ATAN(z.y,z.x)); } // Inverse hyperbolic tangent vec2 catanh(vec2 z) { return 0.5*clog(cdiv(vec2(1,0)+z,vec2(1,0)-z)); } // My own attempt at an ctanh vec2 cexp(vec2 z) { float r = exp(z.x); return r*vec2(cos(z.y), sin(z.y)); } vec2 ctanh(vec2 z) { z = cexp(2.0*z); return cdiv(vec2(1,0)-z,vec2(1,0)+z); } float circle8(vec2 p, float r) { p *= p; p *= p; return pow(dot(p, p),1.0/8.0)-r; } vec2 transform(vec2 z, out float aa, out vec2 hscale) { float A = 9.0; float B = 2.0; if (iMouse.x > 0.0) { // Get angle from mouse position vec2 m = (2.0*iMouse.xy-iResolution.xy)/iResolution.y; m *= 20.0; A = floor(m.x), B = floor(m.y); } vec2 rot = vec2(A, B); float a = TIME; z *= 2.0; z = catanh(-0.5*z+0.5*vec2(sin(a*0.234*sqrt(0.5)), sin(a*0.234)))+catanh(z*ROT(0.1234*a)); z /= PI; aa = fwidth(z.x); aa *= length(rot); z = cmul(rot,z); z.x += 0.5*a; hscale = 1.0/rot.yx; return z; } vec3 effect(vec3 col, vec2 op) { op *= ROT(0.05*TIME); float aaa = 2.0/RESOLUTION.y; float aa; vec2 hscale; vec2 p = transform(op, aa, hscale); vec2 n = round(p); p -= n; // Neat! float d = circle8(p, 0.45); vec2 pf = p; float sf = sign(pf.x*pf.y); pf = abs(pf); float df = sf*min(pf.x, pf.y); float flip = smoothstep(aa, -aa, df); #if defined(DARKMODE) col = vec3(0.0); float fo = tanh_approx(0.333*aaa/(aa*hscale.x*hscale.y)); vec3 rgb = hsv2rgb(vec3(fract(0.65+0.2*sin(0.5*TIME+0.25*flip+PI*dot(n, hscale))), mix(0.0, 0.75, fo), mix(1.0, 0.05, fo*fo))); #else col = vec3(1.0); float fo = tanh_approx(0.125*aaa/(aa*hscale.x*hscale.y)); vec3 rgb = hsv2rgb(vec3(fract(0.05*TIME+0.125*flip+0.5*dot(hscale, n)), mix(0.0, 0.75, fo), mix(1.0, 0.85, fo*fo))); #endif rgb = mix(rgb, smoothstep(0.5, 1.0, rgb), flip); col = mix(col, rgb, smoothstep(aa, -aa, d)); return col; } void mainImage(out vec4 fragColor, in vec2 fragCoord) { vec2 q = fragCoord/RESOLUTION.xy; vec2 p = -1. + 2. * q; p.x *= RESOLUTION.x/RESOLUTION.y; vec3 col = vec3(1.0); col = effect(col, p); col = clamp(col, 0.0, 1.0); col *= smoothstep(0.0, 3.0, TIME); col = sqrt(col); fragColor = vec4(col, 1.0); }
cc0-1.0
[ 1766, 1879, 1906, 1906, 1958 ]
[ [ 621, 621, 643, 643, 789 ], [ 1084, 1170, 1206, 1206, 1300 ], [ 1302, 1362, 1390, 1456, 1532 ], [ 1534, 1620, 1657, 1657, 1764 ], [ 1766, 1879, 1906, 1906, 1958 ], [ 1960, 1960, 1979, 1979, 2030 ], [ 2032, 2032, 2059, 2059, 2087 ], [ 2089, 2089, 2108, 2108, 2170 ], [ 2172, 2203, 2224, 2224, 2276 ], [ 2278, 2308, 2327, 2327, 2388 ], [ 2390, 2390, 2410, 2410, 2471 ], [ 2473, 2473, 2505, 2505, 2562 ], [ 2564, 2564, 2619, 2619, 3103 ], [ 3105, 3105, 3137, 3137, 4025 ], [ 4027, 4027, 4082, 4082, 4353 ] ]
// Complex trig functions found at: Complex Atanh - https://www.shadertoy.com/view/tsBXRW // A very cool shader
vec2 cmul(vec2 z, vec2 w) {
return vec2 (z.x*w.x-z.y*w.y, z.x*w.y+z.y*w.x); }
// Complex trig functions found at: Complex Atanh - https://www.shadertoy.com/view/tsBXRW // A very cool shader vec2 cmul(vec2 z, vec2 w) {
1
12
sstfzM
mrange
2022-06-26T19:12:30
// License CC0 - Complex atanh - darkmode edition // More work tinkering based on mlas shader Complex atanh - https://www.shadertoy.com/view/tsBXRW #define DARKMODE #define FASTATAN #define RESOLUTION iResolution #define TIME iTime #define PI 3.141592654 #define PI_2 (0.5*PI) #define TAU (2.0*PI) #define ROT(a) mat2(cos(a), sin(a), -sin(a), cos(a)) #if defined(FASTATAN) #define ATAN atan_approx #else #define ATAN atan #endif // License: WTFPL, author: sam hocevar, found: https://stackoverflow.com/a/17897228/418488 const vec4 hsv2rgb_K = vec4(1.0, 2.0 / 3.0, 1.0 / 3.0, 3.0); vec3 hsv2rgb(vec3 c) { vec3 p = abs(fract(c.xxx + hsv2rgb_K.xyz) * 6.0 - hsv2rgb_K.www); return c.z * mix(hsv2rgb_K.xxx, clamp(p - hsv2rgb_K.xxx, 0.0, 1.0), 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)) // License: MIT OR CC-BY-NC-4.0, author: mercury, found: https://mercury.sexy/hg_sdf/ vec2 mod2(inout vec2 p, vec2 size) { vec2 c = floor((p + size*0.5)/size); p = mod(p + size*0.5,size) - size*0.5; return c; } // License: Unknown, author: Unknown, found: don't remember float tanh_approx(float x) { // Found this somewhere on the interwebs // return tanh(x); float x2 = x*x; return clamp(x*(27.0 + x2)/(27.0+9.0*x2), -1.0, 1.0); } // License: MIT, author: Pascal Gilcher, found: https://www.shadertoy.com/view/flSXRV float atan_approx(float y, float x) { float cosatan2 = x / (abs(x) + abs(y)); float t = PI_2 - cosatan2 * PI_2; return y < 0.0 ? -t : t; } // Complex trig functions found at: Complex Atanh - https://www.shadertoy.com/view/tsBXRW // A very cool shader vec2 cmul(vec2 z, vec2 w) { return vec2 (z.x*w.x-z.y*w.y, z.x*w.y+z.y*w.x); } vec2 cinv(vec2 z) { float t = dot(z,z); return vec2(z.x,-z.y)/t; } vec2 cdiv(vec2 z, vec2 w) { return cmul(z,cinv(w)); } vec2 clog(vec2 z) { float r = length(z); return vec2(log(r),ATAN(z.y,z.x)); } // Inverse hyperbolic tangent vec2 catanh(vec2 z) { return 0.5*clog(cdiv(vec2(1,0)+z,vec2(1,0)-z)); } // My own attempt at an ctanh vec2 cexp(vec2 z) { float r = exp(z.x); return r*vec2(cos(z.y), sin(z.y)); } vec2 ctanh(vec2 z) { z = cexp(2.0*z); return cdiv(vec2(1,0)-z,vec2(1,0)+z); } float circle8(vec2 p, float r) { p *= p; p *= p; return pow(dot(p, p),1.0/8.0)-r; } vec2 transform(vec2 z, out float aa, out vec2 hscale) { float A = 9.0; float B = 2.0; if (iMouse.x > 0.0) { // Get angle from mouse position vec2 m = (2.0*iMouse.xy-iResolution.xy)/iResolution.y; m *= 20.0; A = floor(m.x), B = floor(m.y); } vec2 rot = vec2(A, B); float a = TIME; z *= 2.0; z = catanh(-0.5*z+0.5*vec2(sin(a*0.234*sqrt(0.5)), sin(a*0.234)))+catanh(z*ROT(0.1234*a)); z /= PI; aa = fwidth(z.x); aa *= length(rot); z = cmul(rot,z); z.x += 0.5*a; hscale = 1.0/rot.yx; return z; } vec3 effect(vec3 col, vec2 op) { op *= ROT(0.05*TIME); float aaa = 2.0/RESOLUTION.y; float aa; vec2 hscale; vec2 p = transform(op, aa, hscale); vec2 n = round(p); p -= n; // Neat! float d = circle8(p, 0.45); vec2 pf = p; float sf = sign(pf.x*pf.y); pf = abs(pf); float df = sf*min(pf.x, pf.y); float flip = smoothstep(aa, -aa, df); #if defined(DARKMODE) col = vec3(0.0); float fo = tanh_approx(0.333*aaa/(aa*hscale.x*hscale.y)); vec3 rgb = hsv2rgb(vec3(fract(0.65+0.2*sin(0.5*TIME+0.25*flip+PI*dot(n, hscale))), mix(0.0, 0.75, fo), mix(1.0, 0.05, fo*fo))); #else col = vec3(1.0); float fo = tanh_approx(0.125*aaa/(aa*hscale.x*hscale.y)); vec3 rgb = hsv2rgb(vec3(fract(0.05*TIME+0.125*flip+0.5*dot(hscale, n)), mix(0.0, 0.75, fo), mix(1.0, 0.85, fo*fo))); #endif rgb = mix(rgb, smoothstep(0.5, 1.0, rgb), flip); col = mix(col, rgb, smoothstep(aa, -aa, d)); return col; } void mainImage(out vec4 fragColor, in vec2 fragCoord) { vec2 q = fragCoord/RESOLUTION.xy; vec2 p = -1. + 2. * q; p.x *= RESOLUTION.x/RESOLUTION.y; vec3 col = vec3(1.0); col = effect(col, p); col = clamp(col, 0.0, 1.0); col *= smoothstep(0.0, 3.0, TIME); col = sqrt(col); fragColor = vec4(col, 1.0); }
cc0-1.0
[ 2172, 2203, 2224, 2224, 2276 ]
[ [ 621, 621, 643, 643, 789 ], [ 1084, 1170, 1206, 1206, 1300 ], [ 1302, 1362, 1390, 1456, 1532 ], [ 1534, 1620, 1657, 1657, 1764 ], [ 1766, 1879, 1906, 1906, 1958 ], [ 1960, 1960, 1979, 1979, 2030 ], [ 2032, 2032, 2059, 2059, 2087 ], [ 2089, 2089, 2108, 2108, 2170 ], [ 2172, 2203, 2224, 2224, 2276 ], [ 2278, 2308, 2327, 2327, 2388 ], [ 2390, 2390, 2410, 2410, 2471 ], [ 2473, 2473, 2505, 2505, 2562 ], [ 2564, 2564, 2619, 2619, 3103 ], [ 3105, 3105, 3137, 3137, 4025 ], [ 4027, 4027, 4082, 4082, 4353 ] ]
// Inverse hyperbolic tangent
vec2 catanh(vec2 z) {
return 0.5*clog(cdiv(vec2(1,0)+z,vec2(1,0)-z)); }
// Inverse hyperbolic tangent vec2 catanh(vec2 z) {
4
4
sstfzM
mrange
2022-06-26T19:12:30
// License CC0 - Complex atanh - darkmode edition // More work tinkering based on mlas shader Complex atanh - https://www.shadertoy.com/view/tsBXRW #define DARKMODE #define FASTATAN #define RESOLUTION iResolution #define TIME iTime #define PI 3.141592654 #define PI_2 (0.5*PI) #define TAU (2.0*PI) #define ROT(a) mat2(cos(a), sin(a), -sin(a), cos(a)) #if defined(FASTATAN) #define ATAN atan_approx #else #define ATAN atan #endif // License: WTFPL, author: sam hocevar, found: https://stackoverflow.com/a/17897228/418488 const vec4 hsv2rgb_K = vec4(1.0, 2.0 / 3.0, 1.0 / 3.0, 3.0); vec3 hsv2rgb(vec3 c) { vec3 p = abs(fract(c.xxx + hsv2rgb_K.xyz) * 6.0 - hsv2rgb_K.www); return c.z * mix(hsv2rgb_K.xxx, clamp(p - hsv2rgb_K.xxx, 0.0, 1.0), 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)) // License: MIT OR CC-BY-NC-4.0, author: mercury, found: https://mercury.sexy/hg_sdf/ vec2 mod2(inout vec2 p, vec2 size) { vec2 c = floor((p + size*0.5)/size); p = mod(p + size*0.5,size) - size*0.5; return c; } // License: Unknown, author: Unknown, found: don't remember float tanh_approx(float x) { // Found this somewhere on the interwebs // return tanh(x); float x2 = x*x; return clamp(x*(27.0 + x2)/(27.0+9.0*x2), -1.0, 1.0); } // License: MIT, author: Pascal Gilcher, found: https://www.shadertoy.com/view/flSXRV float atan_approx(float y, float x) { float cosatan2 = x / (abs(x) + abs(y)); float t = PI_2 - cosatan2 * PI_2; return y < 0.0 ? -t : t; } // Complex trig functions found at: Complex Atanh - https://www.shadertoy.com/view/tsBXRW // A very cool shader vec2 cmul(vec2 z, vec2 w) { return vec2 (z.x*w.x-z.y*w.y, z.x*w.y+z.y*w.x); } vec2 cinv(vec2 z) { float t = dot(z,z); return vec2(z.x,-z.y)/t; } vec2 cdiv(vec2 z, vec2 w) { return cmul(z,cinv(w)); } vec2 clog(vec2 z) { float r = length(z); return vec2(log(r),ATAN(z.y,z.x)); } // Inverse hyperbolic tangent vec2 catanh(vec2 z) { return 0.5*clog(cdiv(vec2(1,0)+z,vec2(1,0)-z)); } // My own attempt at an ctanh vec2 cexp(vec2 z) { float r = exp(z.x); return r*vec2(cos(z.y), sin(z.y)); } vec2 ctanh(vec2 z) { z = cexp(2.0*z); return cdiv(vec2(1,0)-z,vec2(1,0)+z); } float circle8(vec2 p, float r) { p *= p; p *= p; return pow(dot(p, p),1.0/8.0)-r; } vec2 transform(vec2 z, out float aa, out vec2 hscale) { float A = 9.0; float B = 2.0; if (iMouse.x > 0.0) { // Get angle from mouse position vec2 m = (2.0*iMouse.xy-iResolution.xy)/iResolution.y; m *= 20.0; A = floor(m.x), B = floor(m.y); } vec2 rot = vec2(A, B); float a = TIME; z *= 2.0; z = catanh(-0.5*z+0.5*vec2(sin(a*0.234*sqrt(0.5)), sin(a*0.234)))+catanh(z*ROT(0.1234*a)); z /= PI; aa = fwidth(z.x); aa *= length(rot); z = cmul(rot,z); z.x += 0.5*a; hscale = 1.0/rot.yx; return z; } vec3 effect(vec3 col, vec2 op) { op *= ROT(0.05*TIME); float aaa = 2.0/RESOLUTION.y; float aa; vec2 hscale; vec2 p = transform(op, aa, hscale); vec2 n = round(p); p -= n; // Neat! float d = circle8(p, 0.45); vec2 pf = p; float sf = sign(pf.x*pf.y); pf = abs(pf); float df = sf*min(pf.x, pf.y); float flip = smoothstep(aa, -aa, df); #if defined(DARKMODE) col = vec3(0.0); float fo = tanh_approx(0.333*aaa/(aa*hscale.x*hscale.y)); vec3 rgb = hsv2rgb(vec3(fract(0.65+0.2*sin(0.5*TIME+0.25*flip+PI*dot(n, hscale))), mix(0.0, 0.75, fo), mix(1.0, 0.05, fo*fo))); #else col = vec3(1.0); float fo = tanh_approx(0.125*aaa/(aa*hscale.x*hscale.y)); vec3 rgb = hsv2rgb(vec3(fract(0.05*TIME+0.125*flip+0.5*dot(hscale, n)), mix(0.0, 0.75, fo), mix(1.0, 0.85, fo*fo))); #endif rgb = mix(rgb, smoothstep(0.5, 1.0, rgb), flip); col = mix(col, rgb, smoothstep(aa, -aa, d)); return col; } void mainImage(out vec4 fragColor, in vec2 fragCoord) { vec2 q = fragCoord/RESOLUTION.xy; vec2 p = -1. + 2. * q; p.x *= RESOLUTION.x/RESOLUTION.y; vec3 col = vec3(1.0); col = effect(col, p); col = clamp(col, 0.0, 1.0); col *= smoothstep(0.0, 3.0, TIME); col = sqrt(col); fragColor = vec4(col, 1.0); }
cc0-1.0
[ 2278, 2308, 2327, 2327, 2388 ]
[ [ 621, 621, 643, 643, 789 ], [ 1084, 1170, 1206, 1206, 1300 ], [ 1302, 1362, 1390, 1456, 1532 ], [ 1534, 1620, 1657, 1657, 1764 ], [ 1766, 1879, 1906, 1906, 1958 ], [ 1960, 1960, 1979, 1979, 2030 ], [ 2032, 2032, 2059, 2059, 2087 ], [ 2089, 2089, 2108, 2108, 2170 ], [ 2172, 2203, 2224, 2224, 2276 ], [ 2278, 2308, 2327, 2327, 2388 ], [ 2390, 2390, 2410, 2410, 2471 ], [ 2473, 2473, 2505, 2505, 2562 ], [ 2564, 2564, 2619, 2619, 3103 ], [ 3105, 3105, 3137, 3137, 4025 ], [ 4027, 4027, 4082, 4082, 4353 ] ]
// My own attempt at an ctanh
vec2 cexp(vec2 z) {
float r = exp(z.x); return r*vec2(cos(z.y), sin(z.y)); }
// My own attempt at an ctanh vec2 cexp(vec2 z) {
2
6
sddfR4
mrange
2022-06-25T12:12:31
// License CC0: More Complex Atanh // Inspired by: Complex Atanh - https://www.shadertoy.com/view/tsBXRW // I always thought Complex Atanh by mla was very cool // I tinkered a bit with it on saturday morning and got something // I think is different enough to share #define RESOLUTION iResolution #define TIME iTime #define PI 3.141592654 #define TAU (2.0*PI) #define ROT(a) mat2(cos(a), sin(a), -sin(a), cos(a)) // License: WTFPL, author: sam hocevar, found: https://stackoverflow.com/a/17897228/418488 const vec4 hsv2rgb_K = vec4(1.0, 2.0 / 3.0, 1.0 / 3.0, 3.0); vec3 hsv2rgb(vec3 c) { vec3 p = abs(fract(c.xxx + hsv2rgb_K.xyz) * 6.0 - hsv2rgb_K.www); return c.z * mix(hsv2rgb_K.xxx, clamp(p - hsv2rgb_K.xxx, 0.0, 1.0), 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)) // License: MIT OR CC-BY-NC-4.0, author: mercury, found: https://mercury.sexy/hg_sdf/ vec2 mod2(inout vec2 p, vec2 size) { vec2 c = floor((p + size*0.5)/size); p = mod(p + size*0.5,size) - size*0.5; return c; } float circle8(vec2 p, float r) { p *= p; p *= p; return pow(dot(p, p),1.0/8.0)-r; } // License: Unknown, author: Unknown, found: don't remember float tanh_approx(float x) { // Found this somewhere on the interwebs // return tanh(x); float x2 = x*x; return clamp(x*(27.0 + x2)/(27.0+9.0*x2), -1.0, 1.0); } // Complex trig functions found at: Complex Atanh - https://www.shadertoy.com/view/sl3XW7 // A very cool shader vec2 cmul(vec2 z, vec2 w) { return mat2(z,-z.y,z.x)*w; } vec2 cinv(vec2 z) { float t = dot(z,z); return vec2(z.x,-z.y)/t; } vec2 cdiv(vec2 z, vec2 w) { return cmul(z,cinv(w)); } vec2 clog(vec2 z) { float r = length(z); return vec2(log(r),atan(z.y,z.x)); } vec2 catanh(vec2 z) { return 0.5*clog(cdiv(vec2(1,0)+z,vec2(1,0)-z)); } // My own attempt at a ctanh vec2 cexp(vec2 z) { float r = exp(z.x); return r*vec2(cos(z.y), sin(z.y)); } vec2 ctanh(vec2 z) { z = cexp(2.0*z); return cdiv(vec2(1,0)-z,vec2(1,0)+z); } vec2 transform(vec2 p) { float a = 0.5*TIME; p *= mix(2.0, 0.5, smoothstep(-0.85, 0.85, cos(0.5*a))); p = ctanh(p); p *= ROT(0.2*a); p += 1.5*vec2(cos(0.3*a), sin(0.4*a)); p = catanh(p); p.x -= 0.2*a; return p; } vec3 effect(vec3 col, vec2 p_) { const float scale = 1.0/PI; const float cellw = 0.05; p_ *= ROT(0.05*TIME); float aaa = 2.0/RESOLUTION.y; vec2 np_ = p_+aaa; vec2 p = transform(p_); vec2 np = transform(np_); float aa = distance(p, np)*sqrt(0.5); p *= scale; aa *= scale; vec2 n = floor(p/cellw); p = mod(p, cellw); p -= 0.5*cellw; float fo = tanh_approx(aaa/(aa)); float d = circle8(p, 0.45*cellw); col = mix(col, hsv2rgb(vec3(fract(0.1*n.y+0.05*n.x+0.05*TIME), mix(0., 0.95, fo), mix(0.9, 0.85, fo*fo))), smoothstep(aa, -aa, d)*step(aa, 0.7)); return col; } void mainImage(out vec4 fragColor, in vec2 fragCoord) { vec2 q = fragCoord/iResolution.xy; vec2 p = -1. + 2. * q; p.x *= RESOLUTION.x/RESOLUTION.y; vec3 col = vec3(1.0); col = effect(col, p); col = mix(col, vec3(1.0), smoothstep(4.0, 0.0, TIME)), col = clamp(col, 0.0, 1.0); col = sqrt(col); fragColor = vec4(col, 1.0); }
cc0-1.0
[ 1607, 1721, 1748, 1748, 1779 ]
[ [ 603, 603, 625, 625, 771 ], [ 1066, 1152, 1188, 1188, 1282 ], [ 1284, 1284, 1316, 1316, 1373 ], [ 1375, 1435, 1463, 1529, 1605 ], [ 1607, 1721, 1748, 1748, 1779 ], [ 1781, 1781, 1800, 1800, 1851 ], [ 1853, 1853, 1880, 1880, 1908 ], [ 1910, 1910, 1929, 1929, 1991 ], [ 1993, 1993, 2014, 2014, 2066 ], [ 2068, 2097, 2116, 2116, 2177 ], [ 2179, 2179, 2199, 2199, 2260 ], [ 2262, 2262, 2286, 2286, 2490 ], [ 2492, 2492, 2524, 2524, 3091 ], [ 3093, 3093, 3148, 3148, 3439 ] ]
// Complex trig functions found at: Complex Atanh - https://www.shadertoy.com/view/sl3XW7 // A very cool shader
vec2 cmul(vec2 z, vec2 w) {
return mat2(z,-z.y,z.x)*w; }
// Complex trig functions found at: Complex Atanh - https://www.shadertoy.com/view/sl3XW7 // A very cool shader vec2 cmul(vec2 z, vec2 w) {
3
12
sddfR4
mrange
2022-06-25T12:12:31
// License CC0: More Complex Atanh // Inspired by: Complex Atanh - https://www.shadertoy.com/view/tsBXRW // I always thought Complex Atanh by mla was very cool // I tinkered a bit with it on saturday morning and got something // I think is different enough to share #define RESOLUTION iResolution #define TIME iTime #define PI 3.141592654 #define TAU (2.0*PI) #define ROT(a) mat2(cos(a), sin(a), -sin(a), cos(a)) // License: WTFPL, author: sam hocevar, found: https://stackoverflow.com/a/17897228/418488 const vec4 hsv2rgb_K = vec4(1.0, 2.0 / 3.0, 1.0 / 3.0, 3.0); vec3 hsv2rgb(vec3 c) { vec3 p = abs(fract(c.xxx + hsv2rgb_K.xyz) * 6.0 - hsv2rgb_K.www); return c.z * mix(hsv2rgb_K.xxx, clamp(p - hsv2rgb_K.xxx, 0.0, 1.0), 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)) // License: MIT OR CC-BY-NC-4.0, author: mercury, found: https://mercury.sexy/hg_sdf/ vec2 mod2(inout vec2 p, vec2 size) { vec2 c = floor((p + size*0.5)/size); p = mod(p + size*0.5,size) - size*0.5; return c; } float circle8(vec2 p, float r) { p *= p; p *= p; return pow(dot(p, p),1.0/8.0)-r; } // License: Unknown, author: Unknown, found: don't remember float tanh_approx(float x) { // Found this somewhere on the interwebs // return tanh(x); float x2 = x*x; return clamp(x*(27.0 + x2)/(27.0+9.0*x2), -1.0, 1.0); } // Complex trig functions found at: Complex Atanh - https://www.shadertoy.com/view/sl3XW7 // A very cool shader vec2 cmul(vec2 z, vec2 w) { return mat2(z,-z.y,z.x)*w; } vec2 cinv(vec2 z) { float t = dot(z,z); return vec2(z.x,-z.y)/t; } vec2 cdiv(vec2 z, vec2 w) { return cmul(z,cinv(w)); } vec2 clog(vec2 z) { float r = length(z); return vec2(log(r),atan(z.y,z.x)); } vec2 catanh(vec2 z) { return 0.5*clog(cdiv(vec2(1,0)+z,vec2(1,0)-z)); } // My own attempt at a ctanh vec2 cexp(vec2 z) { float r = exp(z.x); return r*vec2(cos(z.y), sin(z.y)); } vec2 ctanh(vec2 z) { z = cexp(2.0*z); return cdiv(vec2(1,0)-z,vec2(1,0)+z); } vec2 transform(vec2 p) { float a = 0.5*TIME; p *= mix(2.0, 0.5, smoothstep(-0.85, 0.85, cos(0.5*a))); p = ctanh(p); p *= ROT(0.2*a); p += 1.5*vec2(cos(0.3*a), sin(0.4*a)); p = catanh(p); p.x -= 0.2*a; return p; } vec3 effect(vec3 col, vec2 p_) { const float scale = 1.0/PI; const float cellw = 0.05; p_ *= ROT(0.05*TIME); float aaa = 2.0/RESOLUTION.y; vec2 np_ = p_+aaa; vec2 p = transform(p_); vec2 np = transform(np_); float aa = distance(p, np)*sqrt(0.5); p *= scale; aa *= scale; vec2 n = floor(p/cellw); p = mod(p, cellw); p -= 0.5*cellw; float fo = tanh_approx(aaa/(aa)); float d = circle8(p, 0.45*cellw); col = mix(col, hsv2rgb(vec3(fract(0.1*n.y+0.05*n.x+0.05*TIME), mix(0., 0.95, fo), mix(0.9, 0.85, fo*fo))), smoothstep(aa, -aa, d)*step(aa, 0.7)); return col; } void mainImage(out vec4 fragColor, in vec2 fragCoord) { vec2 q = fragCoord/iResolution.xy; vec2 p = -1. + 2. * q; p.x *= RESOLUTION.x/RESOLUTION.y; vec3 col = vec3(1.0); col = effect(col, p); col = mix(col, vec3(1.0), smoothstep(4.0, 0.0, TIME)), col = clamp(col, 0.0, 1.0); col = sqrt(col); fragColor = vec4(col, 1.0); }
cc0-1.0
[ 2068, 2097, 2116, 2116, 2177 ]
[ [ 603, 603, 625, 625, 771 ], [ 1066, 1152, 1188, 1188, 1282 ], [ 1284, 1284, 1316, 1316, 1373 ], [ 1375, 1435, 1463, 1529, 1605 ], [ 1607, 1721, 1748, 1748, 1779 ], [ 1781, 1781, 1800, 1800, 1851 ], [ 1853, 1853, 1880, 1880, 1908 ], [ 1910, 1910, 1929, 1929, 1991 ], [ 1993, 1993, 2014, 2014, 2066 ], [ 2068, 2097, 2116, 2116, 2177 ], [ 2179, 2179, 2199, 2199, 2260 ], [ 2262, 2262, 2286, 2286, 2490 ], [ 2492, 2492, 2524, 2524, 3091 ], [ 3093, 3093, 3148, 3148, 3439 ] ]
// My own attempt at a ctanh
vec2 cexp(vec2 z) {
float r = exp(z.x); return r*vec2(cos(z.y), sin(z.y)); }
// My own attempt at a ctanh vec2 cexp(vec2 z) {
2
6
fddfRn
gehtsiegarnixan
2022-06-23T09:30:54
// The MIT License // Copyright © 2022 Gehtsiegarnixan // Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. /* Rhombic Dodecahedron Tiling perfectly in 3D space. I made four perfectly overlaying Rhombic Dodecahedron Grid Tiles. In the pattern I aranged them they have a very useful property. If you add up the edge distance of all 4 grids they add up to 1 in all points. This allows us to do bilinear interpolation between 4 samples in 3D space. This project contains: - Rhombic Dodecahedron Distance function. - An infinite Rhombic Dodecahedron Gird Tiling with Center Distance, Edge Distance, centered UVW Coordinates, and Cell ID. - Four Rhombic Dodecahedron Girds with the grids being offset so that their edges get perfectly hidden by each other I created this for a 3D version of the Hex Directional Flow with only 4 flowmaps + 4 textures samples. In contrast the original directional flow has 8 flowmaps + 8 textures when used in 3D. But to showcase it here, I need a nice 3D Flow and Texture. Maybe I will make it in future. */ //#define ZEROTOONE // show the alpha instead of UVWs #define ALPHA #define sqrt2 1.4142135624 //sqrt(2.) #define half_sqrt2 0.7071067812 //sqrt(2.)/2. #define qurt_sqrt2 0.3535533906 //sqrt(2.)/4. // Increases the steepness of Alpha while preserving 0-1 range and 1 sum // See 2 value example (https://www.desmos.com/calculator/dpxa6mytnv) vec4 smoothContrast(vec4 alpha, float contrast) { // increase steepness using power vec4 powAlpha = pow(alpha, vec4(contrast)); // normalize back to precentage of 1 return powAlpha/(powAlpha.x + powAlpha.y + powAlpha.z + powAlpha.w); } //Distance from the Edge of Rhombic Dodecahedron float rhomDist(vec3 p) { vec3 hra = vec3(0.5, 0.5, half_sqrt2); //vector to Diagonal Edge p = abs(p); float pBC = max(p.x,p.y); //rigt and top edge float pABC = max(dot(p, hra),pBC); //diagonal edge //optional 0-1 range return (.5-pABC)*2.; } // struct to hold 5 floats at a time of my tiling functions struct tilingVal3D { vec3 grid; // Coordinates of the cell in the grid (UV centered on cell) vec3 id; // ID values float alpha; // Edge distance from the cell's center to its boundaries }; //Rhombic Dodecahedron Tiling tilingVal3D rohmTile(vec3 uvw) { vec3 r = vec3(1.0,1.0,sqrt2); vec3 h = r*.5; vec3 a = mod(uvw, r)-h; vec3 b = mod(uvw-h,r)-h; vec3 gvw = dot(a, a) < dot(b,b) ? a : b; //center rhom uvw float edist = rhomDist(gvw); //Edge distance with range 0-1 //float cdist = dot(gvw, gvw); // squared distance with range 0-1 vec3 id = uvw-gvw; // simple ID calculation return tilingVal3D(gvw, id, edist); } // scaled with offset Rhombic Dodecahedron tiling tilingVal3D rohmCell(vec3 uvw, vec3 offset, float gridRes) { tilingVal3D rohmTiling = rohmTile(uvw*gridRes + offset); vec3 tiledUV = (rohmTiling.id - offset)/gridRes; //rohm pixaltion return tilingVal3D(rohmTiling.grid, tiledUV,rohmTiling.alpha); } // 4 Rhombic Dodecahedron tiles offset so their edges get hidden by each other vec3 quadGrid(vec3 uvw, float gridRes, float contrast) { tilingVal3D a = rohmCell(uvw, vec3( .0, .0, .0), gridRes); tilingVal3D b = rohmCell(uvw, vec3( .5, .0, qurt_sqrt2), gridRes); tilingVal3D c = rohmCell(uvw, vec3( .0, .5, qurt_sqrt2), gridRes); tilingVal3D d = rohmCell(uvw, vec3( .0, .0, half_sqrt2), gridRes); // increase contrast vec4 alpha = smoothContrast(vec4(a.alpha, b.alpha, c.alpha, d.alpha), contrast); #ifdef ZEROTOONE // rescale UVWs to 0-1 a.grid = a.grid *0.5+0.5; b.grid = b.grid *0.5+0.5; c.grid = c.grid *0.5+0.5; d.grid = d.grid *0.5+0.5; #endif // interpolate UVWs cause shadertoy doesn't have nice 3d Textures vec3 col = a.grid * alpha.x + b.grid * alpha.y + c.grid * alpha.z + d.grid * alpha.w; #ifndef ZEROTOONE col *= 2.0; #endif #ifdef ALPHA col = alpha.xyz; #endif return col; } // rotates a vetor from SirBelfer4 (https://www.shadertoy.com/view/ssc3z4) vec3 rotate(vec3 v, vec3 a) { // https://math.stackexchange.com/questions/2975109/how-to-convert-euler-angles-to-quaternions-and-get-the-same-euler-angles-back-fr vec4 q; vec3 c = cos(a * 0.5), s = sin(a * 0.5); q.x = s.x * c.y * c.z - c.x * s.y * s.z; q.y = c.x * s.y * c.z + s.x * c.y * s.z; q.z = c.x * c.y * s.z - s.x * s.y * c.z; q.w = c.x * c.y * c.z + s.x * s.y * s.z; // https://blog.molecular-matters.com/2013/05/24/a-faster-quaternion-vector-multiplication/ vec3 qt = 2.0 * cross(q.xyz, v); return v + q.w * qt + cross(q.xyz, qt); } void mainImage(out vec4 fragColor, in vec2 fragCoord ) { float gridRes = 1.5; //size of Ico float contrast = 1.; //1 no contrast, higher values increase contrast vec2 uv = fragCoord/iResolution.y; //square UV pattern float time = (0.1*iTime); // used as z dimension vec3 point = vec3(uv, time); //animated uv cords //cosmetic rotate for fun hexagons otherwise it looks so square point = rotate(point, normalize(vec3(1.,0.,0.))); vec3 col = quadGrid(point,gridRes, contrast); fragColor = vec4(col, 1); }
mit
[ 2236, 2379, 2428, 2466, 2635 ]
[ [ 2236, 2379, 2428, 2466, 2635 ], [ 2637, 2686, 2710, 2710, 2957 ], [ 3237, 3267, 3299, 3299, 3707 ], [ 3709, 3759, 3819, 3819, 4023 ], [ 4025, 4104, 4160, 4160, 5106 ], [ 5108, 5183, 5212, 5349, 5770 ], [ 5772, 5772, 5828, 5828, 6341 ] ]
// Increases the steepness of Alpha while preserving 0-1 range and 1 sum // See 2 value example (https://www.desmos.com/calculator/dpxa6mytnv)
vec4 smoothContrast(vec4 alpha, float contrast) {
vec4 powAlpha = pow(alpha, vec4(contrast)); // normalize back to precentage of 1 return powAlpha/(powAlpha.x + powAlpha.y + powAlpha.z + powAlpha.w); }
// Increases the steepness of Alpha while preserving 0-1 range and 1 sum // See 2 value example (https://www.desmos.com/calculator/dpxa6mytnv) vec4 smoothContrast(vec4 alpha, float contrast) {
2
2
fddfRn
gehtsiegarnixan
2022-06-23T09:30:54
// The MIT License // Copyright © 2022 Gehtsiegarnixan // Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. /* Rhombic Dodecahedron Tiling perfectly in 3D space. I made four perfectly overlaying Rhombic Dodecahedron Grid Tiles. In the pattern I aranged them they have a very useful property. If you add up the edge distance of all 4 grids they add up to 1 in all points. This allows us to do bilinear interpolation between 4 samples in 3D space. This project contains: - Rhombic Dodecahedron Distance function. - An infinite Rhombic Dodecahedron Gird Tiling with Center Distance, Edge Distance, centered UVW Coordinates, and Cell ID. - Four Rhombic Dodecahedron Girds with the grids being offset so that their edges get perfectly hidden by each other I created this for a 3D version of the Hex Directional Flow with only 4 flowmaps + 4 textures samples. In contrast the original directional flow has 8 flowmaps + 8 textures when used in 3D. But to showcase it here, I need a nice 3D Flow and Texture. Maybe I will make it in future. */ //#define ZEROTOONE // show the alpha instead of UVWs #define ALPHA #define sqrt2 1.4142135624 //sqrt(2.) #define half_sqrt2 0.7071067812 //sqrt(2.)/2. #define qurt_sqrt2 0.3535533906 //sqrt(2.)/4. // Increases the steepness of Alpha while preserving 0-1 range and 1 sum // See 2 value example (https://www.desmos.com/calculator/dpxa6mytnv) vec4 smoothContrast(vec4 alpha, float contrast) { // increase steepness using power vec4 powAlpha = pow(alpha, vec4(contrast)); // normalize back to precentage of 1 return powAlpha/(powAlpha.x + powAlpha.y + powAlpha.z + powAlpha.w); } //Distance from the Edge of Rhombic Dodecahedron float rhomDist(vec3 p) { vec3 hra = vec3(0.5, 0.5, half_sqrt2); //vector to Diagonal Edge p = abs(p); float pBC = max(p.x,p.y); //rigt and top edge float pABC = max(dot(p, hra),pBC); //diagonal edge //optional 0-1 range return (.5-pABC)*2.; } // struct to hold 5 floats at a time of my tiling functions struct tilingVal3D { vec3 grid; // Coordinates of the cell in the grid (UV centered on cell) vec3 id; // ID values float alpha; // Edge distance from the cell's center to its boundaries }; //Rhombic Dodecahedron Tiling tilingVal3D rohmTile(vec3 uvw) { vec3 r = vec3(1.0,1.0,sqrt2); vec3 h = r*.5; vec3 a = mod(uvw, r)-h; vec3 b = mod(uvw-h,r)-h; vec3 gvw = dot(a, a) < dot(b,b) ? a : b; //center rhom uvw float edist = rhomDist(gvw); //Edge distance with range 0-1 //float cdist = dot(gvw, gvw); // squared distance with range 0-1 vec3 id = uvw-gvw; // simple ID calculation return tilingVal3D(gvw, id, edist); } // scaled with offset Rhombic Dodecahedron tiling tilingVal3D rohmCell(vec3 uvw, vec3 offset, float gridRes) { tilingVal3D rohmTiling = rohmTile(uvw*gridRes + offset); vec3 tiledUV = (rohmTiling.id - offset)/gridRes; //rohm pixaltion return tilingVal3D(rohmTiling.grid, tiledUV,rohmTiling.alpha); } // 4 Rhombic Dodecahedron tiles offset so their edges get hidden by each other vec3 quadGrid(vec3 uvw, float gridRes, float contrast) { tilingVal3D a = rohmCell(uvw, vec3( .0, .0, .0), gridRes); tilingVal3D b = rohmCell(uvw, vec3( .5, .0, qurt_sqrt2), gridRes); tilingVal3D c = rohmCell(uvw, vec3( .0, .5, qurt_sqrt2), gridRes); tilingVal3D d = rohmCell(uvw, vec3( .0, .0, half_sqrt2), gridRes); // increase contrast vec4 alpha = smoothContrast(vec4(a.alpha, b.alpha, c.alpha, d.alpha), contrast); #ifdef ZEROTOONE // rescale UVWs to 0-1 a.grid = a.grid *0.5+0.5; b.grid = b.grid *0.5+0.5; c.grid = c.grid *0.5+0.5; d.grid = d.grid *0.5+0.5; #endif // interpolate UVWs cause shadertoy doesn't have nice 3d Textures vec3 col = a.grid * alpha.x + b.grid * alpha.y + c.grid * alpha.z + d.grid * alpha.w; #ifndef ZEROTOONE col *= 2.0; #endif #ifdef ALPHA col = alpha.xyz; #endif return col; } // rotates a vetor from SirBelfer4 (https://www.shadertoy.com/view/ssc3z4) vec3 rotate(vec3 v, vec3 a) { // https://math.stackexchange.com/questions/2975109/how-to-convert-euler-angles-to-quaternions-and-get-the-same-euler-angles-back-fr vec4 q; vec3 c = cos(a * 0.5), s = sin(a * 0.5); q.x = s.x * c.y * c.z - c.x * s.y * s.z; q.y = c.x * s.y * c.z + s.x * c.y * s.z; q.z = c.x * c.y * s.z - s.x * s.y * c.z; q.w = c.x * c.y * c.z + s.x * s.y * s.z; // https://blog.molecular-matters.com/2013/05/24/a-faster-quaternion-vector-multiplication/ vec3 qt = 2.0 * cross(q.xyz, v); return v + q.w * qt + cross(q.xyz, qt); } void mainImage(out vec4 fragColor, in vec2 fragCoord ) { float gridRes = 1.5; //size of Ico float contrast = 1.; //1 no contrast, higher values increase contrast vec2 uv = fragCoord/iResolution.y; //square UV pattern float time = (0.1*iTime); // used as z dimension vec3 point = vec3(uv, time); //animated uv cords //cosmetic rotate for fun hexagons otherwise it looks so square point = rotate(point, normalize(vec3(1.,0.,0.))); vec3 col = quadGrid(point,gridRes, contrast); fragColor = vec4(col, 1); }
mit
[ 2637, 2686, 2710, 2710, 2957 ]
[ [ 2236, 2379, 2428, 2466, 2635 ], [ 2637, 2686, 2710, 2710, 2957 ], [ 3237, 3267, 3299, 3299, 3707 ], [ 3709, 3759, 3819, 3819, 4023 ], [ 4025, 4104, 4160, 4160, 5106 ], [ 5108, 5183, 5212, 5349, 5770 ], [ 5772, 5772, 5828, 5828, 6341 ] ]
//Distance from the Edge of Rhombic Dodecahedron
float rhomDist(vec3 p) {
vec3 hra = vec3(0.5, 0.5, half_sqrt2); //vector to Diagonal Edge p = abs(p); float pBC = max(p.x,p.y); //rigt and top edge float pABC = max(dot(p, hra),pBC); //diagonal edge //optional 0-1 range return (.5-pABC)*2.; }
//Distance from the Edge of Rhombic Dodecahedron float rhomDist(vec3 p) {
2
2
fddfRn
gehtsiegarnixan
2022-06-23T09:30:54
// The MIT License // Copyright © 2022 Gehtsiegarnixan // Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. /* Rhombic Dodecahedron Tiling perfectly in 3D space. I made four perfectly overlaying Rhombic Dodecahedron Grid Tiles. In the pattern I aranged them they have a very useful property. If you add up the edge distance of all 4 grids they add up to 1 in all points. This allows us to do bilinear interpolation between 4 samples in 3D space. This project contains: - Rhombic Dodecahedron Distance function. - An infinite Rhombic Dodecahedron Gird Tiling with Center Distance, Edge Distance, centered UVW Coordinates, and Cell ID. - Four Rhombic Dodecahedron Girds with the grids being offset so that their edges get perfectly hidden by each other I created this for a 3D version of the Hex Directional Flow with only 4 flowmaps + 4 textures samples. In contrast the original directional flow has 8 flowmaps + 8 textures when used in 3D. But to showcase it here, I need a nice 3D Flow and Texture. Maybe I will make it in future. */ //#define ZEROTOONE // show the alpha instead of UVWs #define ALPHA #define sqrt2 1.4142135624 //sqrt(2.) #define half_sqrt2 0.7071067812 //sqrt(2.)/2. #define qurt_sqrt2 0.3535533906 //sqrt(2.)/4. // Increases the steepness of Alpha while preserving 0-1 range and 1 sum // See 2 value example (https://www.desmos.com/calculator/dpxa6mytnv) vec4 smoothContrast(vec4 alpha, float contrast) { // increase steepness using power vec4 powAlpha = pow(alpha, vec4(contrast)); // normalize back to precentage of 1 return powAlpha/(powAlpha.x + powAlpha.y + powAlpha.z + powAlpha.w); } //Distance from the Edge of Rhombic Dodecahedron float rhomDist(vec3 p) { vec3 hra = vec3(0.5, 0.5, half_sqrt2); //vector to Diagonal Edge p = abs(p); float pBC = max(p.x,p.y); //rigt and top edge float pABC = max(dot(p, hra),pBC); //diagonal edge //optional 0-1 range return (.5-pABC)*2.; } // struct to hold 5 floats at a time of my tiling functions struct tilingVal3D { vec3 grid; // Coordinates of the cell in the grid (UV centered on cell) vec3 id; // ID values float alpha; // Edge distance from the cell's center to its boundaries }; //Rhombic Dodecahedron Tiling tilingVal3D rohmTile(vec3 uvw) { vec3 r = vec3(1.0,1.0,sqrt2); vec3 h = r*.5; vec3 a = mod(uvw, r)-h; vec3 b = mod(uvw-h,r)-h; vec3 gvw = dot(a, a) < dot(b,b) ? a : b; //center rhom uvw float edist = rhomDist(gvw); //Edge distance with range 0-1 //float cdist = dot(gvw, gvw); // squared distance with range 0-1 vec3 id = uvw-gvw; // simple ID calculation return tilingVal3D(gvw, id, edist); } // scaled with offset Rhombic Dodecahedron tiling tilingVal3D rohmCell(vec3 uvw, vec3 offset, float gridRes) { tilingVal3D rohmTiling = rohmTile(uvw*gridRes + offset); vec3 tiledUV = (rohmTiling.id - offset)/gridRes; //rohm pixaltion return tilingVal3D(rohmTiling.grid, tiledUV,rohmTiling.alpha); } // 4 Rhombic Dodecahedron tiles offset so their edges get hidden by each other vec3 quadGrid(vec3 uvw, float gridRes, float contrast) { tilingVal3D a = rohmCell(uvw, vec3( .0, .0, .0), gridRes); tilingVal3D b = rohmCell(uvw, vec3( .5, .0, qurt_sqrt2), gridRes); tilingVal3D c = rohmCell(uvw, vec3( .0, .5, qurt_sqrt2), gridRes); tilingVal3D d = rohmCell(uvw, vec3( .0, .0, half_sqrt2), gridRes); // increase contrast vec4 alpha = smoothContrast(vec4(a.alpha, b.alpha, c.alpha, d.alpha), contrast); #ifdef ZEROTOONE // rescale UVWs to 0-1 a.grid = a.grid *0.5+0.5; b.grid = b.grid *0.5+0.5; c.grid = c.grid *0.5+0.5; d.grid = d.grid *0.5+0.5; #endif // interpolate UVWs cause shadertoy doesn't have nice 3d Textures vec3 col = a.grid * alpha.x + b.grid * alpha.y + c.grid * alpha.z + d.grid * alpha.w; #ifndef ZEROTOONE col *= 2.0; #endif #ifdef ALPHA col = alpha.xyz; #endif return col; } // rotates a vetor from SirBelfer4 (https://www.shadertoy.com/view/ssc3z4) vec3 rotate(vec3 v, vec3 a) { // https://math.stackexchange.com/questions/2975109/how-to-convert-euler-angles-to-quaternions-and-get-the-same-euler-angles-back-fr vec4 q; vec3 c = cos(a * 0.5), s = sin(a * 0.5); q.x = s.x * c.y * c.z - c.x * s.y * s.z; q.y = c.x * s.y * c.z + s.x * c.y * s.z; q.z = c.x * c.y * s.z - s.x * s.y * c.z; q.w = c.x * c.y * c.z + s.x * s.y * s.z; // https://blog.molecular-matters.com/2013/05/24/a-faster-quaternion-vector-multiplication/ vec3 qt = 2.0 * cross(q.xyz, v); return v + q.w * qt + cross(q.xyz, qt); } void mainImage(out vec4 fragColor, in vec2 fragCoord ) { float gridRes = 1.5; //size of Ico float contrast = 1.; //1 no contrast, higher values increase contrast vec2 uv = fragCoord/iResolution.y; //square UV pattern float time = (0.1*iTime); // used as z dimension vec3 point = vec3(uv, time); //animated uv cords //cosmetic rotate for fun hexagons otherwise it looks so square point = rotate(point, normalize(vec3(1.,0.,0.))); vec3 col = quadGrid(point,gridRes, contrast); fragColor = vec4(col, 1); }
mit
[ 3237, 3267, 3299, 3299, 3707 ]
[ [ 2236, 2379, 2428, 2466, 2635 ], [ 2637, 2686, 2710, 2710, 2957 ], [ 3237, 3267, 3299, 3299, 3707 ], [ 3709, 3759, 3819, 3819, 4023 ], [ 4025, 4104, 4160, 4160, 5106 ], [ 5108, 5183, 5212, 5349, 5770 ], [ 5772, 5772, 5828, 5828, 6341 ] ]
//Rhombic Dodecahedron Tiling
tilingVal3D rohmTile(vec3 uvw) {
vec3 r = vec3(1.0,1.0,sqrt2); vec3 h = r*.5; vec3 a = mod(uvw, r)-h; vec3 b = mod(uvw-h,r)-h; vec3 gvw = dot(a, a) < dot(b,b) ? a : b; //center rhom uvw float edist = rhomDist(gvw); //Edge distance with range 0-1 //float cdist = dot(gvw, gvw); // squared distance with range 0-1 vec3 id = uvw-gvw; // simple ID calculation return tilingVal3D(gvw, id, edist); }
//Rhombic Dodecahedron Tiling tilingVal3D rohmTile(vec3 uvw) {
2
2
fddfRn
gehtsiegarnixan
2022-06-23T09:30:54
// The MIT License // Copyright © 2022 Gehtsiegarnixan // Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. /* Rhombic Dodecahedron Tiling perfectly in 3D space. I made four perfectly overlaying Rhombic Dodecahedron Grid Tiles. In the pattern I aranged them they have a very useful property. If you add up the edge distance of all 4 grids they add up to 1 in all points. This allows us to do bilinear interpolation between 4 samples in 3D space. This project contains: - Rhombic Dodecahedron Distance function. - An infinite Rhombic Dodecahedron Gird Tiling with Center Distance, Edge Distance, centered UVW Coordinates, and Cell ID. - Four Rhombic Dodecahedron Girds with the grids being offset so that their edges get perfectly hidden by each other I created this for a 3D version of the Hex Directional Flow with only 4 flowmaps + 4 textures samples. In contrast the original directional flow has 8 flowmaps + 8 textures when used in 3D. But to showcase it here, I need a nice 3D Flow and Texture. Maybe I will make it in future. */ //#define ZEROTOONE // show the alpha instead of UVWs #define ALPHA #define sqrt2 1.4142135624 //sqrt(2.) #define half_sqrt2 0.7071067812 //sqrt(2.)/2. #define qurt_sqrt2 0.3535533906 //sqrt(2.)/4. // Increases the steepness of Alpha while preserving 0-1 range and 1 sum // See 2 value example (https://www.desmos.com/calculator/dpxa6mytnv) vec4 smoothContrast(vec4 alpha, float contrast) { // increase steepness using power vec4 powAlpha = pow(alpha, vec4(contrast)); // normalize back to precentage of 1 return powAlpha/(powAlpha.x + powAlpha.y + powAlpha.z + powAlpha.w); } //Distance from the Edge of Rhombic Dodecahedron float rhomDist(vec3 p) { vec3 hra = vec3(0.5, 0.5, half_sqrt2); //vector to Diagonal Edge p = abs(p); float pBC = max(p.x,p.y); //rigt and top edge float pABC = max(dot(p, hra),pBC); //diagonal edge //optional 0-1 range return (.5-pABC)*2.; } // struct to hold 5 floats at a time of my tiling functions struct tilingVal3D { vec3 grid; // Coordinates of the cell in the grid (UV centered on cell) vec3 id; // ID values float alpha; // Edge distance from the cell's center to its boundaries }; //Rhombic Dodecahedron Tiling tilingVal3D rohmTile(vec3 uvw) { vec3 r = vec3(1.0,1.0,sqrt2); vec3 h = r*.5; vec3 a = mod(uvw, r)-h; vec3 b = mod(uvw-h,r)-h; vec3 gvw = dot(a, a) < dot(b,b) ? a : b; //center rhom uvw float edist = rhomDist(gvw); //Edge distance with range 0-1 //float cdist = dot(gvw, gvw); // squared distance with range 0-1 vec3 id = uvw-gvw; // simple ID calculation return tilingVal3D(gvw, id, edist); } // scaled with offset Rhombic Dodecahedron tiling tilingVal3D rohmCell(vec3 uvw, vec3 offset, float gridRes) { tilingVal3D rohmTiling = rohmTile(uvw*gridRes + offset); vec3 tiledUV = (rohmTiling.id - offset)/gridRes; //rohm pixaltion return tilingVal3D(rohmTiling.grid, tiledUV,rohmTiling.alpha); } // 4 Rhombic Dodecahedron tiles offset so their edges get hidden by each other vec3 quadGrid(vec3 uvw, float gridRes, float contrast) { tilingVal3D a = rohmCell(uvw, vec3( .0, .0, .0), gridRes); tilingVal3D b = rohmCell(uvw, vec3( .5, .0, qurt_sqrt2), gridRes); tilingVal3D c = rohmCell(uvw, vec3( .0, .5, qurt_sqrt2), gridRes); tilingVal3D d = rohmCell(uvw, vec3( .0, .0, half_sqrt2), gridRes); // increase contrast vec4 alpha = smoothContrast(vec4(a.alpha, b.alpha, c.alpha, d.alpha), contrast); #ifdef ZEROTOONE // rescale UVWs to 0-1 a.grid = a.grid *0.5+0.5; b.grid = b.grid *0.5+0.5; c.grid = c.grid *0.5+0.5; d.grid = d.grid *0.5+0.5; #endif // interpolate UVWs cause shadertoy doesn't have nice 3d Textures vec3 col = a.grid * alpha.x + b.grid * alpha.y + c.grid * alpha.z + d.grid * alpha.w; #ifndef ZEROTOONE col *= 2.0; #endif #ifdef ALPHA col = alpha.xyz; #endif return col; } // rotates a vetor from SirBelfer4 (https://www.shadertoy.com/view/ssc3z4) vec3 rotate(vec3 v, vec3 a) { // https://math.stackexchange.com/questions/2975109/how-to-convert-euler-angles-to-quaternions-and-get-the-same-euler-angles-back-fr vec4 q; vec3 c = cos(a * 0.5), s = sin(a * 0.5); q.x = s.x * c.y * c.z - c.x * s.y * s.z; q.y = c.x * s.y * c.z + s.x * c.y * s.z; q.z = c.x * c.y * s.z - s.x * s.y * c.z; q.w = c.x * c.y * c.z + s.x * s.y * s.z; // https://blog.molecular-matters.com/2013/05/24/a-faster-quaternion-vector-multiplication/ vec3 qt = 2.0 * cross(q.xyz, v); return v + q.w * qt + cross(q.xyz, qt); } void mainImage(out vec4 fragColor, in vec2 fragCoord ) { float gridRes = 1.5; //size of Ico float contrast = 1.; //1 no contrast, higher values increase contrast vec2 uv = fragCoord/iResolution.y; //square UV pattern float time = (0.1*iTime); // used as z dimension vec3 point = vec3(uv, time); //animated uv cords //cosmetic rotate for fun hexagons otherwise it looks so square point = rotate(point, normalize(vec3(1.,0.,0.))); vec3 col = quadGrid(point,gridRes, contrast); fragColor = vec4(col, 1); }
mit
[ 3709, 3759, 3819, 3819, 4023 ]
[ [ 2236, 2379, 2428, 2466, 2635 ], [ 2637, 2686, 2710, 2710, 2957 ], [ 3237, 3267, 3299, 3299, 3707 ], [ 3709, 3759, 3819, 3819, 4023 ], [ 4025, 4104, 4160, 4160, 5106 ], [ 5108, 5183, 5212, 5349, 5770 ], [ 5772, 5772, 5828, 5828, 6341 ] ]
// scaled with offset Rhombic Dodecahedron tiling
tilingVal3D rohmCell(vec3 uvw, vec3 offset, float gridRes) {
tilingVal3D rohmTiling = rohmTile(uvw*gridRes + offset); vec3 tiledUV = (rohmTiling.id - offset)/gridRes; //rohm pixaltion return tilingVal3D(rohmTiling.grid, tiledUV,rohmTiling.alpha); }
// scaled with offset Rhombic Dodecahedron tiling tilingVal3D rohmCell(vec3 uvw, vec3 offset, float gridRes) {
2
2
fddfRn
gehtsiegarnixan
2022-06-23T09:30:54
// The MIT License // Copyright © 2022 Gehtsiegarnixan // Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. /* Rhombic Dodecahedron Tiling perfectly in 3D space. I made four perfectly overlaying Rhombic Dodecahedron Grid Tiles. In the pattern I aranged them they have a very useful property. If you add up the edge distance of all 4 grids they add up to 1 in all points. This allows us to do bilinear interpolation between 4 samples in 3D space. This project contains: - Rhombic Dodecahedron Distance function. - An infinite Rhombic Dodecahedron Gird Tiling with Center Distance, Edge Distance, centered UVW Coordinates, and Cell ID. - Four Rhombic Dodecahedron Girds with the grids being offset so that their edges get perfectly hidden by each other I created this for a 3D version of the Hex Directional Flow with only 4 flowmaps + 4 textures samples. In contrast the original directional flow has 8 flowmaps + 8 textures when used in 3D. But to showcase it here, I need a nice 3D Flow and Texture. Maybe I will make it in future. */ //#define ZEROTOONE // show the alpha instead of UVWs #define ALPHA #define sqrt2 1.4142135624 //sqrt(2.) #define half_sqrt2 0.7071067812 //sqrt(2.)/2. #define qurt_sqrt2 0.3535533906 //sqrt(2.)/4. // Increases the steepness of Alpha while preserving 0-1 range and 1 sum // See 2 value example (https://www.desmos.com/calculator/dpxa6mytnv) vec4 smoothContrast(vec4 alpha, float contrast) { // increase steepness using power vec4 powAlpha = pow(alpha, vec4(contrast)); // normalize back to precentage of 1 return powAlpha/(powAlpha.x + powAlpha.y + powAlpha.z + powAlpha.w); } //Distance from the Edge of Rhombic Dodecahedron float rhomDist(vec3 p) { vec3 hra = vec3(0.5, 0.5, half_sqrt2); //vector to Diagonal Edge p = abs(p); float pBC = max(p.x,p.y); //rigt and top edge float pABC = max(dot(p, hra),pBC); //diagonal edge //optional 0-1 range return (.5-pABC)*2.; } // struct to hold 5 floats at a time of my tiling functions struct tilingVal3D { vec3 grid; // Coordinates of the cell in the grid (UV centered on cell) vec3 id; // ID values float alpha; // Edge distance from the cell's center to its boundaries }; //Rhombic Dodecahedron Tiling tilingVal3D rohmTile(vec3 uvw) { vec3 r = vec3(1.0,1.0,sqrt2); vec3 h = r*.5; vec3 a = mod(uvw, r)-h; vec3 b = mod(uvw-h,r)-h; vec3 gvw = dot(a, a) < dot(b,b) ? a : b; //center rhom uvw float edist = rhomDist(gvw); //Edge distance with range 0-1 //float cdist = dot(gvw, gvw); // squared distance with range 0-1 vec3 id = uvw-gvw; // simple ID calculation return tilingVal3D(gvw, id, edist); } // scaled with offset Rhombic Dodecahedron tiling tilingVal3D rohmCell(vec3 uvw, vec3 offset, float gridRes) { tilingVal3D rohmTiling = rohmTile(uvw*gridRes + offset); vec3 tiledUV = (rohmTiling.id - offset)/gridRes; //rohm pixaltion return tilingVal3D(rohmTiling.grid, tiledUV,rohmTiling.alpha); } // 4 Rhombic Dodecahedron tiles offset so their edges get hidden by each other vec3 quadGrid(vec3 uvw, float gridRes, float contrast) { tilingVal3D a = rohmCell(uvw, vec3( .0, .0, .0), gridRes); tilingVal3D b = rohmCell(uvw, vec3( .5, .0, qurt_sqrt2), gridRes); tilingVal3D c = rohmCell(uvw, vec3( .0, .5, qurt_sqrt2), gridRes); tilingVal3D d = rohmCell(uvw, vec3( .0, .0, half_sqrt2), gridRes); // increase contrast vec4 alpha = smoothContrast(vec4(a.alpha, b.alpha, c.alpha, d.alpha), contrast); #ifdef ZEROTOONE // rescale UVWs to 0-1 a.grid = a.grid *0.5+0.5; b.grid = b.grid *0.5+0.5; c.grid = c.grid *0.5+0.5; d.grid = d.grid *0.5+0.5; #endif // interpolate UVWs cause shadertoy doesn't have nice 3d Textures vec3 col = a.grid * alpha.x + b.grid * alpha.y + c.grid * alpha.z + d.grid * alpha.w; #ifndef ZEROTOONE col *= 2.0; #endif #ifdef ALPHA col = alpha.xyz; #endif return col; } // rotates a vetor from SirBelfer4 (https://www.shadertoy.com/view/ssc3z4) vec3 rotate(vec3 v, vec3 a) { // https://math.stackexchange.com/questions/2975109/how-to-convert-euler-angles-to-quaternions-and-get-the-same-euler-angles-back-fr vec4 q; vec3 c = cos(a * 0.5), s = sin(a * 0.5); q.x = s.x * c.y * c.z - c.x * s.y * s.z; q.y = c.x * s.y * c.z + s.x * c.y * s.z; q.z = c.x * c.y * s.z - s.x * s.y * c.z; q.w = c.x * c.y * c.z + s.x * s.y * s.z; // https://blog.molecular-matters.com/2013/05/24/a-faster-quaternion-vector-multiplication/ vec3 qt = 2.0 * cross(q.xyz, v); return v + q.w * qt + cross(q.xyz, qt); } void mainImage(out vec4 fragColor, in vec2 fragCoord ) { float gridRes = 1.5; //size of Ico float contrast = 1.; //1 no contrast, higher values increase contrast vec2 uv = fragCoord/iResolution.y; //square UV pattern float time = (0.1*iTime); // used as z dimension vec3 point = vec3(uv, time); //animated uv cords //cosmetic rotate for fun hexagons otherwise it looks so square point = rotate(point, normalize(vec3(1.,0.,0.))); vec3 col = quadGrid(point,gridRes, contrast); fragColor = vec4(col, 1); }
mit
[ 4025, 4104, 4160, 4160, 5106 ]
[ [ 2236, 2379, 2428, 2466, 2635 ], [ 2637, 2686, 2710, 2710, 2957 ], [ 3237, 3267, 3299, 3299, 3707 ], [ 3709, 3759, 3819, 3819, 4023 ], [ 4025, 4104, 4160, 4160, 5106 ], [ 5108, 5183, 5212, 5349, 5770 ], [ 5772, 5772, 5828, 5828, 6341 ] ]
// 4 Rhombic Dodecahedron tiles offset so their edges get hidden by each other
vec3 quadGrid(vec3 uvw, float gridRes, float contrast) {
tilingVal3D a = rohmCell(uvw, vec3( .0, .0, .0), gridRes); tilingVal3D b = rohmCell(uvw, vec3( .5, .0, qurt_sqrt2), gridRes); tilingVal3D c = rohmCell(uvw, vec3( .0, .5, qurt_sqrt2), gridRes); tilingVal3D d = rohmCell(uvw, vec3( .0, .0, half_sqrt2), gridRes); // increase contrast vec4 alpha = smoothContrast(vec4(a.alpha, b.alpha, c.alpha, d.alpha), contrast); #ifdef ZEROTOONE // rescale UVWs to 0-1 a.grid = a.grid *0.5+0.5; b.grid = b.grid *0.5+0.5; c.grid = c.grid *0.5+0.5; d.grid = d.grid *0.5+0.5; #endif // interpolate UVWs cause shadertoy doesn't have nice 3d Textures vec3 col = a.grid * alpha.x + b.grid * alpha.y + c.grid * alpha.z + d.grid * alpha.w; #ifndef ZEROTOONE col *= 2.0; #endif #ifdef ALPHA col = alpha.xyz; #endif return col; }
// 4 Rhombic Dodecahedron tiles offset so their edges get hidden by each other vec3 quadGrid(vec3 uvw, float gridRes, float contrast) {
1
1
sdKcWt
gehtsiegarnixan
2022-06-22T15:20:36
// The MIT License // Copyright © 2022 Gehtsiegarnixan // Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. /* I created an algorithm, that gives you the distance to the nearest edge of an Icosahedron. It has mouse controls to rotated around the center. I made this because I wanted to make a 3D tiling pattern, but I only skim read the Wikipedia article and chose the wrong shape. This shape cannot be seamlessly tiled. Lol */ #define pi 3.1415926536 #define inv_sqrt3 0.5773502693 // 1/sqrt(3) #define nGRa 0.3568220898 // normalized Golden Ration #define nGRc 0.9341723590 // normalized 2 Golden Ration + 1 const vec3 hrA = vec3(inv_sqrt3); //vector to Icosahedron Edge A const vec3 hrB = vec3(0., nGRc, nGRa); //vector to Icosahedron Edge B const vec3 hrC = vec3(nGRa, 0., nGRc); //vector to Icosahedron Edge C const vec3 hrD = vec3(nGRc, nGRa, 0.); //vector to Icosahedron Edge D //Icosahedron Distance from Center float IcoDist(vec3 p) { p = abs(p); float pAB = max(dot(p, hrA),dot(p, hrB)); float pCD = max(dot(p, hrC),dot(p, hrD)); float dist = max(pAB,pCD); // optional makes it 0-1 inside, and negative outside return (.5-dist)*2.; } // makes Cool colormap with polynimal 6 vec3 Cool(float t) { const vec3 c0 = vec3(-0.000941,1.000941,1.000000); const vec3 c1 = vec3(1.001170,-1.001170,-0.000000); const vec3 c2 = vec3(0.004744,-0.004748,0.000001); const vec3 c3 = vec3(-0.011841,0.011841,-0.000005); const vec3 c4 = vec3(0.012964,-0.012943,0.000009); const vec3 c5 = vec3(-0.005110,0.005073,-0.000008); const vec3 c6 = vec3(-0.000046,0.000064,0.000003); return c0+t*(c1+t*(c2+t*(c3+t*(c4+t*(c5+t*c6))))); } // rotates a vetor from SirBelfer4 (https://www.shadertoy.com/view/ssc3z4) vec3 rotate(vec3 v, vec3 a) { // https://math.stackexchange.com/questions/2975109/how-to-convert-euler-angles-to-quaternions-and-get-the-same-euler-angles-back-fr vec4 q; vec3 c = cos(a * 0.5), s = sin(a * 0.5); q.x = s.x * c.y * c.z - c.x * s.y * s.z; q.y = c.x * s.y * c.z + s.x * c.y * s.z; q.z = c.x * c.y * s.z - s.x * s.y * c.z; q.w = c.x * c.y * c.z + s.x * s.y * s.z; // https://blog.molecular-matters.com/2013/05/24/a-faster-quaternion-vector-multiplication/ vec3 qt = 2.0 * cross(q.xyz, v); return v + q.w * qt + cross(q.xyz, qt); } void mainImage( out vec4 fragColor, in vec2 fragCoord ) { vec2 uv = (fragCoord - iResolution.xy*.5)/iResolution.y; //centered square UVs float time = fract(0.2*iTime-0.5)-0.5; // used as z dimension float size = 0.9; //size of Ico vec3 point = vec3(uv, time)/size; //animated uv cords // controls rotates around the center vec3 camRot = vec3(0.5 - iMouse.yx / iResolution.yx, 0) * 2.0 * pi; camRot.y = -camRot.y; point = rotate(point, camRot); float ico = IcoDist(point); ico = clamp(ico, 0.,1.); //saturate so the cmap doesn't break vec3 col = Cool(ico); // applying cosmetic colormap fragColor = vec4(col,0); }
mit
[ 1880, 1915, 1938, 1938, 2168 ]
[ [ 1880, 1915, 1938, 1938, 2168 ], [ 2170, 2210, 2230, 2230, 2675 ], [ 2677, 2752, 2781, 2918, 3339 ], [ 3341, 3341, 3398, 3398, 4035 ] ]
//Icosahedron Distance from Center
float IcoDist(vec3 p) {
p = abs(p); float pAB = max(dot(p, hrA),dot(p, hrB)); float pCD = max(dot(p, hrC),dot(p, hrD)); float dist = max(pAB,pCD); // optional makes it 0-1 inside, and negative outside return (.5-dist)*2.; }
//Icosahedron Distance from Center float IcoDist(vec3 p) {
1
1
sdKcWt
gehtsiegarnixan
2022-06-22T15:20:36
// The MIT License // Copyright © 2022 Gehtsiegarnixan // Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. /* I created an algorithm, that gives you the distance to the nearest edge of an Icosahedron. It has mouse controls to rotated around the center. I made this because I wanted to make a 3D tiling pattern, but I only skim read the Wikipedia article and chose the wrong shape. This shape cannot be seamlessly tiled. Lol */ #define pi 3.1415926536 #define inv_sqrt3 0.5773502693 // 1/sqrt(3) #define nGRa 0.3568220898 // normalized Golden Ration #define nGRc 0.9341723590 // normalized 2 Golden Ration + 1 const vec3 hrA = vec3(inv_sqrt3); //vector to Icosahedron Edge A const vec3 hrB = vec3(0., nGRc, nGRa); //vector to Icosahedron Edge B const vec3 hrC = vec3(nGRa, 0., nGRc); //vector to Icosahedron Edge C const vec3 hrD = vec3(nGRc, nGRa, 0.); //vector to Icosahedron Edge D //Icosahedron Distance from Center float IcoDist(vec3 p) { p = abs(p); float pAB = max(dot(p, hrA),dot(p, hrB)); float pCD = max(dot(p, hrC),dot(p, hrD)); float dist = max(pAB,pCD); // optional makes it 0-1 inside, and negative outside return (.5-dist)*2.; } // makes Cool colormap with polynimal 6 vec3 Cool(float t) { const vec3 c0 = vec3(-0.000941,1.000941,1.000000); const vec3 c1 = vec3(1.001170,-1.001170,-0.000000); const vec3 c2 = vec3(0.004744,-0.004748,0.000001); const vec3 c3 = vec3(-0.011841,0.011841,-0.000005); const vec3 c4 = vec3(0.012964,-0.012943,0.000009); const vec3 c5 = vec3(-0.005110,0.005073,-0.000008); const vec3 c6 = vec3(-0.000046,0.000064,0.000003); return c0+t*(c1+t*(c2+t*(c3+t*(c4+t*(c5+t*c6))))); } // rotates a vetor from SirBelfer4 (https://www.shadertoy.com/view/ssc3z4) vec3 rotate(vec3 v, vec3 a) { // https://math.stackexchange.com/questions/2975109/how-to-convert-euler-angles-to-quaternions-and-get-the-same-euler-angles-back-fr vec4 q; vec3 c = cos(a * 0.5), s = sin(a * 0.5); q.x = s.x * c.y * c.z - c.x * s.y * s.z; q.y = c.x * s.y * c.z + s.x * c.y * s.z; q.z = c.x * c.y * s.z - s.x * s.y * c.z; q.w = c.x * c.y * c.z + s.x * s.y * s.z; // https://blog.molecular-matters.com/2013/05/24/a-faster-quaternion-vector-multiplication/ vec3 qt = 2.0 * cross(q.xyz, v); return v + q.w * qt + cross(q.xyz, qt); } void mainImage( out vec4 fragColor, in vec2 fragCoord ) { vec2 uv = (fragCoord - iResolution.xy*.5)/iResolution.y; //centered square UVs float time = fract(0.2*iTime-0.5)-0.5; // used as z dimension float size = 0.9; //size of Ico vec3 point = vec3(uv, time)/size; //animated uv cords // controls rotates around the center vec3 camRot = vec3(0.5 - iMouse.yx / iResolution.yx, 0) * 2.0 * pi; camRot.y = -camRot.y; point = rotate(point, camRot); float ico = IcoDist(point); ico = clamp(ico, 0.,1.); //saturate so the cmap doesn't break vec3 col = Cool(ico); // applying cosmetic colormap fragColor = vec4(col,0); }
mit
[ 2170, 2210, 2230, 2230, 2675 ]
[ [ 1880, 1915, 1938, 1938, 2168 ], [ 2170, 2210, 2230, 2230, 2675 ], [ 2677, 2752, 2781, 2918, 3339 ], [ 3341, 3341, 3398, 3398, 4035 ] ]
// makes Cool colormap with polynimal 6
vec3 Cool(float t) {
const vec3 c0 = vec3(-0.000941,1.000941,1.000000); const vec3 c1 = vec3(1.001170,-1.001170,-0.000000); const vec3 c2 = vec3(0.004744,-0.004748,0.000001); const vec3 c3 = vec3(-0.011841,0.011841,-0.000005); const vec3 c4 = vec3(0.012964,-0.012943,0.000009); const vec3 c5 = vec3(-0.005110,0.005073,-0.000008); const vec3 c6 = vec3(-0.000046,0.000064,0.000003); return c0+t*(c1+t*(c2+t*(c3+t*(c4+t*(c5+t*c6))))); }
// makes Cool colormap with polynimal 6 vec3 Cool(float t) {
1
1
sdKcWt
gehtsiegarnixan
2022-06-22T15:20:36
// The MIT License // Copyright © 2022 Gehtsiegarnixan // Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. /* I created an algorithm, that gives you the distance to the nearest edge of an Icosahedron. It has mouse controls to rotated around the center. I made this because I wanted to make a 3D tiling pattern, but I only skim read the Wikipedia article and chose the wrong shape. This shape cannot be seamlessly tiled. Lol */ #define pi 3.1415926536 #define inv_sqrt3 0.5773502693 // 1/sqrt(3) #define nGRa 0.3568220898 // normalized Golden Ration #define nGRc 0.9341723590 // normalized 2 Golden Ration + 1 const vec3 hrA = vec3(inv_sqrt3); //vector to Icosahedron Edge A const vec3 hrB = vec3(0., nGRc, nGRa); //vector to Icosahedron Edge B const vec3 hrC = vec3(nGRa, 0., nGRc); //vector to Icosahedron Edge C const vec3 hrD = vec3(nGRc, nGRa, 0.); //vector to Icosahedron Edge D //Icosahedron Distance from Center float IcoDist(vec3 p) { p = abs(p); float pAB = max(dot(p, hrA),dot(p, hrB)); float pCD = max(dot(p, hrC),dot(p, hrD)); float dist = max(pAB,pCD); // optional makes it 0-1 inside, and negative outside return (.5-dist)*2.; } // makes Cool colormap with polynimal 6 vec3 Cool(float t) { const vec3 c0 = vec3(-0.000941,1.000941,1.000000); const vec3 c1 = vec3(1.001170,-1.001170,-0.000000); const vec3 c2 = vec3(0.004744,-0.004748,0.000001); const vec3 c3 = vec3(-0.011841,0.011841,-0.000005); const vec3 c4 = vec3(0.012964,-0.012943,0.000009); const vec3 c5 = vec3(-0.005110,0.005073,-0.000008); const vec3 c6 = vec3(-0.000046,0.000064,0.000003); return c0+t*(c1+t*(c2+t*(c3+t*(c4+t*(c5+t*c6))))); } // rotates a vetor from SirBelfer4 (https://www.shadertoy.com/view/ssc3z4) vec3 rotate(vec3 v, vec3 a) { // https://math.stackexchange.com/questions/2975109/how-to-convert-euler-angles-to-quaternions-and-get-the-same-euler-angles-back-fr vec4 q; vec3 c = cos(a * 0.5), s = sin(a * 0.5); q.x = s.x * c.y * c.z - c.x * s.y * s.z; q.y = c.x * s.y * c.z + s.x * c.y * s.z; q.z = c.x * c.y * s.z - s.x * s.y * c.z; q.w = c.x * c.y * c.z + s.x * s.y * s.z; // https://blog.molecular-matters.com/2013/05/24/a-faster-quaternion-vector-multiplication/ vec3 qt = 2.0 * cross(q.xyz, v); return v + q.w * qt + cross(q.xyz, qt); } void mainImage( out vec4 fragColor, in vec2 fragCoord ) { vec2 uv = (fragCoord - iResolution.xy*.5)/iResolution.y; //centered square UVs float time = fract(0.2*iTime-0.5)-0.5; // used as z dimension float size = 0.9; //size of Ico vec3 point = vec3(uv, time)/size; //animated uv cords // controls rotates around the center vec3 camRot = vec3(0.5 - iMouse.yx / iResolution.yx, 0) * 2.0 * pi; camRot.y = -camRot.y; point = rotate(point, camRot); float ico = IcoDist(point); ico = clamp(ico, 0.,1.); //saturate so the cmap doesn't break vec3 col = Cool(ico); // applying cosmetic colormap fragColor = vec4(col,0); }
mit
[ 2677, 2752, 2781, 2918, 3339 ]
[ [ 1880, 1915, 1938, 1938, 2168 ], [ 2170, 2210, 2230, 2230, 2675 ], [ 2677, 2752, 2781, 2918, 3339 ], [ 3341, 3341, 3398, 3398, 4035 ] ]
// rotates a vetor from SirBelfer4 (https://www.shadertoy.com/view/ssc3z4)
vec3 rotate(vec3 v, vec3 a) {
vec4 q; vec3 c = cos(a * 0.5), s = sin(a * 0.5); q.x = s.x * c.y * c.z - c.x * s.y * s.z; q.y = c.x * s.y * c.z + s.x * c.y * s.z; q.z = c.x * c.y * s.z - s.x * s.y * c.z; q.w = c.x * c.y * c.z + s.x * s.y * s.z; // https://blog.molecular-matters.com/2013/05/24/a-faster-quaternion-vector-multiplication/ vec3 qt = 2.0 * cross(q.xyz, v); return v + q.w * qt + cross(q.xyz, qt); }
// rotates a vetor from SirBelfer4 (https://www.shadertoy.com/view/ssc3z4) vec3 rotate(vec3 v, vec3 a) {
4
4
sdVyWt
mrange
2022-06-21T21:32:43
// License CC0: Mandelbrot variation // Tinkered with julia mapping. Not amazing but different enough to share. #define RESOLUTION iResolution #define TIME iTime // License: Unknown, author: Unknown, found: don't remember float hash(vec2 co) { return fract(sin(dot(co.xy ,vec2(12.9898,58.233))) * 13758.5453); } float cell_df(vec2 np, vec2 mp, vec2 off) { const vec2 n0 = normalize(vec2(1.0, 1.0)); const vec2 n1 = normalize(vec2(-1.0, 1.0)); np += off; mp -= off; float hh = hash(np); vec2 n = hh > 0.5 ? n0 : n1; vec2 t = vec2(n.y, -n.x); vec2 p0 = mp; p0 = abs(p0); p0 -= 0.5; float d0 = length(p0)-0.0; vec2 p1 = mp; float d1 = dot(n, p1); float px = dot(t, p1); d1 = abs(px) > sqrt(0.5) ? d0 : abs(d1); float d = d0; d = min(d, d1); return d; } float truchet_df(vec2 p) { vec2 np = floor(p+0.5); vec2 mp = fract(p+0.5) - 0.5; float d = 1E6; const float off = 1.0; for (float x=-off;x<=off;++x) { for (float y=-off;y<=off;++y) { vec2 o = vec2(x,y); d = min(d,cell_df(np, mp, o)); } } return d; } void julia_map(inout vec2 p, vec2 c) { for (int i = 0; i < 89; ++i) { vec2 p2 = p*p; p = vec2(p2.x-p2.y, 2.0*p.x*p.y); p += c; } } vec2 transform(vec2 p) { p *= 0.0125; p.x -= 0.5; p += vec2(0.59, 0.62); julia_map(p, p); p *= 30.0; p += 0.2*TIME; return p; } vec3 effect(vec3 col, vec2 p_, vec2 np_) { vec2 p = transform(p_); vec2 np = transform(np_); float aa = distance(p, np)*sqrt(0.5); float d = truchet_df(p)-aa; col = mix(col, vec3(0.1), smoothstep(aa, -aa, d)); return col; } void mainImage(out vec4 fragColor, in vec2 fragCoord) { vec2 q = fragCoord/RESOLUTION.xy; vec2 p = -1.0 + 2.0*q; p.x *= RESOLUTION.x/RESOLUTION.y; vec2 np = p+2.0/RESOLUTION.y; vec3 col = vec3(1.0); col = effect(col, p, np); col = sqrt(col); fragColor = vec4(col, 1.0); }
cc0-1.0
[ 172, 232, 253, 253, 323 ]
[ [ 172, 232, 253, 253, 323 ], [ 325, 325, 368, 368, 814 ], [ 816, 816, 842, 842, 1099 ], [ 1101, 1101, 1139, 1139, 1247 ], [ 1249, 1249, 1273, 1273, 1390 ], [ 1392, 1392, 1434, 1434, 1633 ], [ 1636, 1636, 1691, 1691, 1932 ] ]
// License: Unknown, author: Unknown, found: don't remember
float hash(vec2 co) {
return fract(sin(dot(co.xy ,vec2(12.9898,58.233))) * 13758.5453); }
// License: Unknown, author: Unknown, found: don't remember float hash(vec2 co) {
37
45
7dycDV
gehtsiegarnixan
2022-06-21T17:26:17
// The MIT License // Copyright © 2022 Gehtsiegarnixan // Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. /* Update: I made a faster version using my Square Directional Flow (https://www.shadertoy.com/view/7ddBWl). This is using my Hex Directional Flow algorithm (https://www.shadertoy.com/view/fsGyDG) with Sine waves instead of a texture. I also made a flowmap that is an aproximation of a tropical cyclone flowmap (https://www.shadertoy.com/view/fdKcWd). I wanted to aproximate the water wave height. I looked up the forumlas for the relationship between windspeed and waves, but the math is very complicated and I gave up. So I went for what looks alright (https://www.desmos.com/calculator/lewikf6y0f). The easy water wave math can be found here (https://en.wikipedia.org/wiki/Dispersion_(water_waves)). Wikipeda explains the relationship between water depth, wavelength and wave velocity (https://www.desmos.com/calculator/2nlmht2mmy). The amplitude and windspeed don't have such linear interaction, but there are formuals for observed wave spectra on the ocean after long periods of steady wind (https://wikiwaves.org/Ocean-Wave_Spectra). I just can not figure out how to solve for the wavespeed/wavelength for a give depth and windspeed. A single wave can be described by the gerstner formula (https://catlikecoding.com/unity/tutorials/flow/waves/), but I couldn't find how the wind affects the wave steepness and when exactly they break on the open sea. I found some hints here (http://hyperphysics.phy-astr.gsu.edu/hbase/Waves/watwav2.html) when they break. I played around with circular and straight waves, but the circular ones don't look that different for how much more work they are. So I kept the straight waves, but see dD and cD to test for yourself. Animating the flowmap also turned out to have some significant drawbacks. Since im sampling a lower res hexagonal version leads to flickering waves, so you can only do it VERY slowly. */ #define pi 3.1415926536 #define sqrtG 3.1320919527 #define twoPi 6.2831853072 #define sqrt3 1.7320508076 //sqrt(3) #define half_sqrt3 0.8660254038 //sqrt(3)/2 #define inv_sqrt3 0.5773502693 // 1/sqrt(3) #define inv_twice_sqrt3 0.2886751346 // 1/(2 sqrt(3)) // if you want flat tops (hex rotated by 30deg) swap xy in hr and the p.x to p.y in hexDist const vec2 r = vec2(1, sqrt3); // 1, sqrt(3) const vec2 h = vec2(0.5,half_sqrt3); // 1/2, sqrt(3) /2 // Hexagonal Distanstance from the 0,0 coords float hexDist(vec2 p) { p = abs(p); return max(dot(p, h), p.x); } // struct to fill with needed HexTile Parametes struct hexParams { vec2 gv; vec2 id; float edist; }; // From BigWIngs "Hexagonal Tiling" https://www.shadertoy.com/view/3sSGWt hexParams hexTile(vec2 uv) { vec2 a = mod(uv, r)-h; vec2 b = mod(uv-h, r)-h; vec2 gv = dot(a, a) < dot(b,b) ? a : b; //center hex UV coords // float edist = .5-hexDist(gv); // Edge distance. float edist = (.5-hexDist(gv))*2.; // Edge distance with range 0-1 // float cdist = dot(gv, gv); // squared distance from the center. // float cdist = dot(gv, gv)*3.; // squared distance with range 0-1 vec2 id = uv-gv; // simple ID calculation return hexParams(gv,id,edist); // xy hex coords + z distance to edge } // makes viridis colormap with polynimal 6 https://www.shadertoy.com/view/Nd3fR2 vec3 viridis(float t) { const vec3 c0 = vec3(0.274344,0.004462,0.331359); const vec3 c1 = vec3(0.108915,1.397291,1.388110); const vec3 c2 = vec3(-0.319631,0.243490,0.156419); const vec3 c3 = vec3(-4.629188,-5.882803,-19.646115); const vec3 c4 = vec3(6.181719,14.388598,57.442181); const vec3 c5 = vec3(4.876952,-13.955112,-66.125783); const vec3 c6 = vec3(-5.513165,4.709245,26.582180); return c0+t*(c1+t*(c2+t*(c3+t*(c4+t*(c5+t*c6))))); } //shifts value range from -1-1 to 0-1 float make0to1(float x) { return (1.0 + x) / 2.0; } //shifts value range from 0-1 to -1-1 vec2 makeM1to1(vec2 x) { return (x - 0.5) * 2.0; } // makes a simple flowmap of a cyclone vec2 cycloneFlow(vec2 point, float radius, float time) { float size = 1./(1.4 * sqrt(radius)); // of the entire cyclone float curl = 2.5; // kind of arbitrary but between 1-3.5 looks good float hole = 1./(4.*size); // also kind of arbitrary //point += vec2(cos(time),sin(time))*0.1*hole; //rotating center float angle = atan(point.y, point.x); //angle around center float dist = length(point); // distance to point float spiral = fract(dist/radius + (angle-time)/twoPi); //right slanted donut https://www.desmos.com/calculator/ocm71awnym spiral -= 1.212; spiral = 1.+ (pow(1.57*(spiral)+0.8,2.)/spiral); float flowAngle = pi + angle -(dist*curl) -(spiral*0.8); // left slanted donut https://www.desmos.com/calculator/uxyefly7fi float spiralStrength = 0.05; float mask = (1. - spiralStrength)-(pow(dist*size-hole, 2.0)/dist); mask += spiral*spiralStrength; mask = clamp(mask, 0.0, 1.0); // saturate vec2 flow = normalize(vec2(cos(flowAngle),sin(flowAngle))); flow *= mask; // apply strength mask //flow = (flow+1.0)/2.0; // to save as texture flow += vec2(0.0001,0.0001); //adding tiny offset so it isnt 0 return flow; } // generates pixelated directional waves float flowHexCell(vec2 uv, vec2 offset, float gridRes, float time, float len) { hexParams hexValues = hexTile(uv * gridRes + offset); hexValues.gv = hexValues.gv / gridRes; hexValues.id = (hexValues.id - offset)/ gridRes; float radius = 0.3; // of the first spiral //cyclone like flowmap vec2 flowMap = cycloneFlow(hexValues.id - vec2(0.885, 0.5), radius, time*0.2); float speed = length(flowMap); // Wind Speed vec2 dir = normalize(flowMap); // Wind Direction len *= pow(speed,0.5); // make slower waves smaller float k = twoPi / len; //Wave Number float a = pow(speed,1.5); //Amplitude float s = speed; //Steepness time *= sqrtG * sqrt(len); // deep water speed float dD = dot(uv,dir); //Directional/Straight Wave //float cD = length(hexValues.gv + (dir/(gridRes))); //Circular Wave //add random phase offsets for even FlowMaps or you get interference //time += texture( iChannel0, hexValues.id).x; float wave = make0to1(sin(k * (dD - time))); // make sin wave //wave = (1.- pow(wave, (1.-s/2.))); //cheap gerstner height wave aprox wave *= a * hexValues.edist; // apply amplitue and alpha mask return wave; } // 3 hex pixaled flowing sin thier edges get hidden by each other float triDirectionalFlow(vec2 uv, float gridRes, float time, float len) { float a = flowHexCell(uv, vec2(0.,0.), gridRes, time, len); float b = flowHexCell(uv, vec2(0,inv_sqrt3), gridRes, time, len); float c = flowHexCell(uv, vec2(0.5,inv_twice_sqrt3), gridRes, time, len); return a + b + c; } void mainImage( out vec4 fragColor, in vec2 fragCoord ) { float gridRes = 32.0; //Hex Grid Resolution float waveLen = 1./ (gridRes * 3.0); // Maximum Sin Wave Length float time = iTime * 0.05; // flow speed multiplier vec2 uv = fragCoord/iResolution.y; //square UVs float wave = triDirectionalFlow(uv,gridRes,time, waveLen); vec3 col = vec3(viridis(wave)); fragColor = vec4(col,1); }
mit
[ 3438, 3484, 3507, 3507, 3557 ]
[ [ 3438, 3484, 3507, 3507, 3557 ], [ 3667, 3741, 3769, 3769, 4301 ], [ 4303, 4384, 4407, 4407, 4855 ], [ 4857, 4895, 4920, 4920, 4950 ], [ 4952, 4990, 5014, 5014, 5044 ], [ 5046, 5085, 5141, 5141, 6331 ], [ 6333, 6374, 6453, 6453, 7631 ], [ 7633, 7699, 7772, 7772, 8009 ], [ 8011, 8011, 8068, 8068, 8434 ] ]
// Hexagonal Distanstance from the 0,0 coords
float hexDist(vec2 p) {
p = abs(p); return max(dot(p, h), p.x); }
// Hexagonal Distanstance from the 0,0 coords float hexDist(vec2 p) {
3
10
7dycDV
gehtsiegarnixan
2022-06-21T17:26:17
// The MIT License // Copyright © 2022 Gehtsiegarnixan // Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. /* Update: I made a faster version using my Square Directional Flow (https://www.shadertoy.com/view/7ddBWl). This is using my Hex Directional Flow algorithm (https://www.shadertoy.com/view/fsGyDG) with Sine waves instead of a texture. I also made a flowmap that is an aproximation of a tropical cyclone flowmap (https://www.shadertoy.com/view/fdKcWd). I wanted to aproximate the water wave height. I looked up the forumlas for the relationship between windspeed and waves, but the math is very complicated and I gave up. So I went for what looks alright (https://www.desmos.com/calculator/lewikf6y0f). The easy water wave math can be found here (https://en.wikipedia.org/wiki/Dispersion_(water_waves)). Wikipeda explains the relationship between water depth, wavelength and wave velocity (https://www.desmos.com/calculator/2nlmht2mmy). The amplitude and windspeed don't have such linear interaction, but there are formuals for observed wave spectra on the ocean after long periods of steady wind (https://wikiwaves.org/Ocean-Wave_Spectra). I just can not figure out how to solve for the wavespeed/wavelength for a give depth and windspeed. A single wave can be described by the gerstner formula (https://catlikecoding.com/unity/tutorials/flow/waves/), but I couldn't find how the wind affects the wave steepness and when exactly they break on the open sea. I found some hints here (http://hyperphysics.phy-astr.gsu.edu/hbase/Waves/watwav2.html) when they break. I played around with circular and straight waves, but the circular ones don't look that different for how much more work they are. So I kept the straight waves, but see dD and cD to test for yourself. Animating the flowmap also turned out to have some significant drawbacks. Since im sampling a lower res hexagonal version leads to flickering waves, so you can only do it VERY slowly. */ #define pi 3.1415926536 #define sqrtG 3.1320919527 #define twoPi 6.2831853072 #define sqrt3 1.7320508076 //sqrt(3) #define half_sqrt3 0.8660254038 //sqrt(3)/2 #define inv_sqrt3 0.5773502693 // 1/sqrt(3) #define inv_twice_sqrt3 0.2886751346 // 1/(2 sqrt(3)) // if you want flat tops (hex rotated by 30deg) swap xy in hr and the p.x to p.y in hexDist const vec2 r = vec2(1, sqrt3); // 1, sqrt(3) const vec2 h = vec2(0.5,half_sqrt3); // 1/2, sqrt(3) /2 // Hexagonal Distanstance from the 0,0 coords float hexDist(vec2 p) { p = abs(p); return max(dot(p, h), p.x); } // struct to fill with needed HexTile Parametes struct hexParams { vec2 gv; vec2 id; float edist; }; // From BigWIngs "Hexagonal Tiling" https://www.shadertoy.com/view/3sSGWt hexParams hexTile(vec2 uv) { vec2 a = mod(uv, r)-h; vec2 b = mod(uv-h, r)-h; vec2 gv = dot(a, a) < dot(b,b) ? a : b; //center hex UV coords // float edist = .5-hexDist(gv); // Edge distance. float edist = (.5-hexDist(gv))*2.; // Edge distance with range 0-1 // float cdist = dot(gv, gv); // squared distance from the center. // float cdist = dot(gv, gv)*3.; // squared distance with range 0-1 vec2 id = uv-gv; // simple ID calculation return hexParams(gv,id,edist); // xy hex coords + z distance to edge } // makes viridis colormap with polynimal 6 https://www.shadertoy.com/view/Nd3fR2 vec3 viridis(float t) { const vec3 c0 = vec3(0.274344,0.004462,0.331359); const vec3 c1 = vec3(0.108915,1.397291,1.388110); const vec3 c2 = vec3(-0.319631,0.243490,0.156419); const vec3 c3 = vec3(-4.629188,-5.882803,-19.646115); const vec3 c4 = vec3(6.181719,14.388598,57.442181); const vec3 c5 = vec3(4.876952,-13.955112,-66.125783); const vec3 c6 = vec3(-5.513165,4.709245,26.582180); return c0+t*(c1+t*(c2+t*(c3+t*(c4+t*(c5+t*c6))))); } //shifts value range from -1-1 to 0-1 float make0to1(float x) { return (1.0 + x) / 2.0; } //shifts value range from 0-1 to -1-1 vec2 makeM1to1(vec2 x) { return (x - 0.5) * 2.0; } // makes a simple flowmap of a cyclone vec2 cycloneFlow(vec2 point, float radius, float time) { float size = 1./(1.4 * sqrt(radius)); // of the entire cyclone float curl = 2.5; // kind of arbitrary but between 1-3.5 looks good float hole = 1./(4.*size); // also kind of arbitrary //point += vec2(cos(time),sin(time))*0.1*hole; //rotating center float angle = atan(point.y, point.x); //angle around center float dist = length(point); // distance to point float spiral = fract(dist/radius + (angle-time)/twoPi); //right slanted donut https://www.desmos.com/calculator/ocm71awnym spiral -= 1.212; spiral = 1.+ (pow(1.57*(spiral)+0.8,2.)/spiral); float flowAngle = pi + angle -(dist*curl) -(spiral*0.8); // left slanted donut https://www.desmos.com/calculator/uxyefly7fi float spiralStrength = 0.05; float mask = (1. - spiralStrength)-(pow(dist*size-hole, 2.0)/dist); mask += spiral*spiralStrength; mask = clamp(mask, 0.0, 1.0); // saturate vec2 flow = normalize(vec2(cos(flowAngle),sin(flowAngle))); flow *= mask; // apply strength mask //flow = (flow+1.0)/2.0; // to save as texture flow += vec2(0.0001,0.0001); //adding tiny offset so it isnt 0 return flow; } // generates pixelated directional waves float flowHexCell(vec2 uv, vec2 offset, float gridRes, float time, float len) { hexParams hexValues = hexTile(uv * gridRes + offset); hexValues.gv = hexValues.gv / gridRes; hexValues.id = (hexValues.id - offset)/ gridRes; float radius = 0.3; // of the first spiral //cyclone like flowmap vec2 flowMap = cycloneFlow(hexValues.id - vec2(0.885, 0.5), radius, time*0.2); float speed = length(flowMap); // Wind Speed vec2 dir = normalize(flowMap); // Wind Direction len *= pow(speed,0.5); // make slower waves smaller float k = twoPi / len; //Wave Number float a = pow(speed,1.5); //Amplitude float s = speed; //Steepness time *= sqrtG * sqrt(len); // deep water speed float dD = dot(uv,dir); //Directional/Straight Wave //float cD = length(hexValues.gv + (dir/(gridRes))); //Circular Wave //add random phase offsets for even FlowMaps or you get interference //time += texture( iChannel0, hexValues.id).x; float wave = make0to1(sin(k * (dD - time))); // make sin wave //wave = (1.- pow(wave, (1.-s/2.))); //cheap gerstner height wave aprox wave *= a * hexValues.edist; // apply amplitue and alpha mask return wave; } // 3 hex pixaled flowing sin thier edges get hidden by each other float triDirectionalFlow(vec2 uv, float gridRes, float time, float len) { float a = flowHexCell(uv, vec2(0.,0.), gridRes, time, len); float b = flowHexCell(uv, vec2(0,inv_sqrt3), gridRes, time, len); float c = flowHexCell(uv, vec2(0.5,inv_twice_sqrt3), gridRes, time, len); return a + b + c; } void mainImage( out vec4 fragColor, in vec2 fragCoord ) { float gridRes = 32.0; //Hex Grid Resolution float waveLen = 1./ (gridRes * 3.0); // Maximum Sin Wave Length float time = iTime * 0.05; // flow speed multiplier vec2 uv = fragCoord/iResolution.y; //square UVs float wave = triDirectionalFlow(uv,gridRes,time, waveLen); vec3 col = vec3(viridis(wave)); fragColor = vec4(col,1); }
mit
[ 3667, 3741, 3769, 3769, 4301 ]
[ [ 3438, 3484, 3507, 3507, 3557 ], [ 3667, 3741, 3769, 3769, 4301 ], [ 4303, 4384, 4407, 4407, 4855 ], [ 4857, 4895, 4920, 4920, 4950 ], [ 4952, 4990, 5014, 5014, 5044 ], [ 5046, 5085, 5141, 5141, 6331 ], [ 6333, 6374, 6453, 6453, 7631 ], [ 7633, 7699, 7772, 7772, 8009 ], [ 8011, 8011, 8068, 8068, 8434 ] ]
// From BigWIngs "Hexagonal Tiling" https://www.shadertoy.com/view/3sSGWt
hexParams hexTile(vec2 uv) {
vec2 a = mod(uv, r)-h; vec2 b = mod(uv-h, r)-h; vec2 gv = dot(a, a) < dot(b,b) ? a : b; //center hex UV coords // float edist = .5-hexDist(gv); // Edge distance. float edist = (.5-hexDist(gv))*2.; // Edge distance with range 0-1 // float cdist = dot(gv, gv); // squared distance from the center. // float cdist = dot(gv, gv)*3.; // squared distance with range 0-1 vec2 id = uv-gv; // simple ID calculation return hexParams(gv,id,edist); // xy hex coords + z distance to edge }
// From BigWIngs "Hexagonal Tiling" https://www.shadertoy.com/view/3sSGWt hexParams hexTile(vec2 uv) {
1
1
7dycDV
gehtsiegarnixan
2022-06-21T17:26:17
// The MIT License // Copyright © 2022 Gehtsiegarnixan // Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. /* Update: I made a faster version using my Square Directional Flow (https://www.shadertoy.com/view/7ddBWl). This is using my Hex Directional Flow algorithm (https://www.shadertoy.com/view/fsGyDG) with Sine waves instead of a texture. I also made a flowmap that is an aproximation of a tropical cyclone flowmap (https://www.shadertoy.com/view/fdKcWd). I wanted to aproximate the water wave height. I looked up the forumlas for the relationship between windspeed and waves, but the math is very complicated and I gave up. So I went for what looks alright (https://www.desmos.com/calculator/lewikf6y0f). The easy water wave math can be found here (https://en.wikipedia.org/wiki/Dispersion_(water_waves)). Wikipeda explains the relationship between water depth, wavelength and wave velocity (https://www.desmos.com/calculator/2nlmht2mmy). The amplitude and windspeed don't have such linear interaction, but there are formuals for observed wave spectra on the ocean after long periods of steady wind (https://wikiwaves.org/Ocean-Wave_Spectra). I just can not figure out how to solve for the wavespeed/wavelength for a give depth and windspeed. A single wave can be described by the gerstner formula (https://catlikecoding.com/unity/tutorials/flow/waves/), but I couldn't find how the wind affects the wave steepness and when exactly they break on the open sea. I found some hints here (http://hyperphysics.phy-astr.gsu.edu/hbase/Waves/watwav2.html) when they break. I played around with circular and straight waves, but the circular ones don't look that different for how much more work they are. So I kept the straight waves, but see dD and cD to test for yourself. Animating the flowmap also turned out to have some significant drawbacks. Since im sampling a lower res hexagonal version leads to flickering waves, so you can only do it VERY slowly. */ #define pi 3.1415926536 #define sqrtG 3.1320919527 #define twoPi 6.2831853072 #define sqrt3 1.7320508076 //sqrt(3) #define half_sqrt3 0.8660254038 //sqrt(3)/2 #define inv_sqrt3 0.5773502693 // 1/sqrt(3) #define inv_twice_sqrt3 0.2886751346 // 1/(2 sqrt(3)) // if you want flat tops (hex rotated by 30deg) swap xy in hr and the p.x to p.y in hexDist const vec2 r = vec2(1, sqrt3); // 1, sqrt(3) const vec2 h = vec2(0.5,half_sqrt3); // 1/2, sqrt(3) /2 // Hexagonal Distanstance from the 0,0 coords float hexDist(vec2 p) { p = abs(p); return max(dot(p, h), p.x); } // struct to fill with needed HexTile Parametes struct hexParams { vec2 gv; vec2 id; float edist; }; // From BigWIngs "Hexagonal Tiling" https://www.shadertoy.com/view/3sSGWt hexParams hexTile(vec2 uv) { vec2 a = mod(uv, r)-h; vec2 b = mod(uv-h, r)-h; vec2 gv = dot(a, a) < dot(b,b) ? a : b; //center hex UV coords // float edist = .5-hexDist(gv); // Edge distance. float edist = (.5-hexDist(gv))*2.; // Edge distance with range 0-1 // float cdist = dot(gv, gv); // squared distance from the center. // float cdist = dot(gv, gv)*3.; // squared distance with range 0-1 vec2 id = uv-gv; // simple ID calculation return hexParams(gv,id,edist); // xy hex coords + z distance to edge } // makes viridis colormap with polynimal 6 https://www.shadertoy.com/view/Nd3fR2 vec3 viridis(float t) { const vec3 c0 = vec3(0.274344,0.004462,0.331359); const vec3 c1 = vec3(0.108915,1.397291,1.388110); const vec3 c2 = vec3(-0.319631,0.243490,0.156419); const vec3 c3 = vec3(-4.629188,-5.882803,-19.646115); const vec3 c4 = vec3(6.181719,14.388598,57.442181); const vec3 c5 = vec3(4.876952,-13.955112,-66.125783); const vec3 c6 = vec3(-5.513165,4.709245,26.582180); return c0+t*(c1+t*(c2+t*(c3+t*(c4+t*(c5+t*c6))))); } //shifts value range from -1-1 to 0-1 float make0to1(float x) { return (1.0 + x) / 2.0; } //shifts value range from 0-1 to -1-1 vec2 makeM1to1(vec2 x) { return (x - 0.5) * 2.0; } // makes a simple flowmap of a cyclone vec2 cycloneFlow(vec2 point, float radius, float time) { float size = 1./(1.4 * sqrt(radius)); // of the entire cyclone float curl = 2.5; // kind of arbitrary but between 1-3.5 looks good float hole = 1./(4.*size); // also kind of arbitrary //point += vec2(cos(time),sin(time))*0.1*hole; //rotating center float angle = atan(point.y, point.x); //angle around center float dist = length(point); // distance to point float spiral = fract(dist/radius + (angle-time)/twoPi); //right slanted donut https://www.desmos.com/calculator/ocm71awnym spiral -= 1.212; spiral = 1.+ (pow(1.57*(spiral)+0.8,2.)/spiral); float flowAngle = pi + angle -(dist*curl) -(spiral*0.8); // left slanted donut https://www.desmos.com/calculator/uxyefly7fi float spiralStrength = 0.05; float mask = (1. - spiralStrength)-(pow(dist*size-hole, 2.0)/dist); mask += spiral*spiralStrength; mask = clamp(mask, 0.0, 1.0); // saturate vec2 flow = normalize(vec2(cos(flowAngle),sin(flowAngle))); flow *= mask; // apply strength mask //flow = (flow+1.0)/2.0; // to save as texture flow += vec2(0.0001,0.0001); //adding tiny offset so it isnt 0 return flow; } // generates pixelated directional waves float flowHexCell(vec2 uv, vec2 offset, float gridRes, float time, float len) { hexParams hexValues = hexTile(uv * gridRes + offset); hexValues.gv = hexValues.gv / gridRes; hexValues.id = (hexValues.id - offset)/ gridRes; float radius = 0.3; // of the first spiral //cyclone like flowmap vec2 flowMap = cycloneFlow(hexValues.id - vec2(0.885, 0.5), radius, time*0.2); float speed = length(flowMap); // Wind Speed vec2 dir = normalize(flowMap); // Wind Direction len *= pow(speed,0.5); // make slower waves smaller float k = twoPi / len; //Wave Number float a = pow(speed,1.5); //Amplitude float s = speed; //Steepness time *= sqrtG * sqrt(len); // deep water speed float dD = dot(uv,dir); //Directional/Straight Wave //float cD = length(hexValues.gv + (dir/(gridRes))); //Circular Wave //add random phase offsets for even FlowMaps or you get interference //time += texture( iChannel0, hexValues.id).x; float wave = make0to1(sin(k * (dD - time))); // make sin wave //wave = (1.- pow(wave, (1.-s/2.))); //cheap gerstner height wave aprox wave *= a * hexValues.edist; // apply amplitue and alpha mask return wave; } // 3 hex pixaled flowing sin thier edges get hidden by each other float triDirectionalFlow(vec2 uv, float gridRes, float time, float len) { float a = flowHexCell(uv, vec2(0.,0.), gridRes, time, len); float b = flowHexCell(uv, vec2(0,inv_sqrt3), gridRes, time, len); float c = flowHexCell(uv, vec2(0.5,inv_twice_sqrt3), gridRes, time, len); return a + b + c; } void mainImage( out vec4 fragColor, in vec2 fragCoord ) { float gridRes = 32.0; //Hex Grid Resolution float waveLen = 1./ (gridRes * 3.0); // Maximum Sin Wave Length float time = iTime * 0.05; // flow speed multiplier vec2 uv = fragCoord/iResolution.y; //square UVs float wave = triDirectionalFlow(uv,gridRes,time, waveLen); vec3 col = vec3(viridis(wave)); fragColor = vec4(col,1); }
mit
[ 4303, 4384, 4407, 4407, 4855 ]
[ [ 3438, 3484, 3507, 3507, 3557 ], [ 3667, 3741, 3769, 3769, 4301 ], [ 4303, 4384, 4407, 4407, 4855 ], [ 4857, 4895, 4920, 4920, 4950 ], [ 4952, 4990, 5014, 5014, 5044 ], [ 5046, 5085, 5141, 5141, 6331 ], [ 6333, 6374, 6453, 6453, 7631 ], [ 7633, 7699, 7772, 7772, 8009 ], [ 8011, 8011, 8068, 8068, 8434 ] ]
// makes viridis colormap with polynimal 6 https://www.shadertoy.com/view/Nd3fR2
vec3 viridis(float t) {
const vec3 c0 = vec3(0.274344,0.004462,0.331359); const vec3 c1 = vec3(0.108915,1.397291,1.388110); const vec3 c2 = vec3(-0.319631,0.243490,0.156419); const vec3 c3 = vec3(-4.629188,-5.882803,-19.646115); const vec3 c4 = vec3(6.181719,14.388598,57.442181); const vec3 c5 = vec3(4.876952,-13.955112,-66.125783); const vec3 c6 = vec3(-5.513165,4.709245,26.582180); return c0+t*(c1+t*(c2+t*(c3+t*(c4+t*(c5+t*c6))))); }
// makes viridis colormap with polynimal 6 https://www.shadertoy.com/view/Nd3fR2 vec3 viridis(float t) {
3
8
7dycDV
gehtsiegarnixan
2022-06-21T17:26:17
// The MIT License // Copyright © 2022 Gehtsiegarnixan // Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. /* Update: I made a faster version using my Square Directional Flow (https://www.shadertoy.com/view/7ddBWl). This is using my Hex Directional Flow algorithm (https://www.shadertoy.com/view/fsGyDG) with Sine waves instead of a texture. I also made a flowmap that is an aproximation of a tropical cyclone flowmap (https://www.shadertoy.com/view/fdKcWd). I wanted to aproximate the water wave height. I looked up the forumlas for the relationship between windspeed and waves, but the math is very complicated and I gave up. So I went for what looks alright (https://www.desmos.com/calculator/lewikf6y0f). The easy water wave math can be found here (https://en.wikipedia.org/wiki/Dispersion_(water_waves)). Wikipeda explains the relationship between water depth, wavelength and wave velocity (https://www.desmos.com/calculator/2nlmht2mmy). The amplitude and windspeed don't have such linear interaction, but there are formuals for observed wave spectra on the ocean after long periods of steady wind (https://wikiwaves.org/Ocean-Wave_Spectra). I just can not figure out how to solve for the wavespeed/wavelength for a give depth and windspeed. A single wave can be described by the gerstner formula (https://catlikecoding.com/unity/tutorials/flow/waves/), but I couldn't find how the wind affects the wave steepness and when exactly they break on the open sea. I found some hints here (http://hyperphysics.phy-astr.gsu.edu/hbase/Waves/watwav2.html) when they break. I played around with circular and straight waves, but the circular ones don't look that different for how much more work they are. So I kept the straight waves, but see dD and cD to test for yourself. Animating the flowmap also turned out to have some significant drawbacks. Since im sampling a lower res hexagonal version leads to flickering waves, so you can only do it VERY slowly. */ #define pi 3.1415926536 #define sqrtG 3.1320919527 #define twoPi 6.2831853072 #define sqrt3 1.7320508076 //sqrt(3) #define half_sqrt3 0.8660254038 //sqrt(3)/2 #define inv_sqrt3 0.5773502693 // 1/sqrt(3) #define inv_twice_sqrt3 0.2886751346 // 1/(2 sqrt(3)) // if you want flat tops (hex rotated by 30deg) swap xy in hr and the p.x to p.y in hexDist const vec2 r = vec2(1, sqrt3); // 1, sqrt(3) const vec2 h = vec2(0.5,half_sqrt3); // 1/2, sqrt(3) /2 // Hexagonal Distanstance from the 0,0 coords float hexDist(vec2 p) { p = abs(p); return max(dot(p, h), p.x); } // struct to fill with needed HexTile Parametes struct hexParams { vec2 gv; vec2 id; float edist; }; // From BigWIngs "Hexagonal Tiling" https://www.shadertoy.com/view/3sSGWt hexParams hexTile(vec2 uv) { vec2 a = mod(uv, r)-h; vec2 b = mod(uv-h, r)-h; vec2 gv = dot(a, a) < dot(b,b) ? a : b; //center hex UV coords // float edist = .5-hexDist(gv); // Edge distance. float edist = (.5-hexDist(gv))*2.; // Edge distance with range 0-1 // float cdist = dot(gv, gv); // squared distance from the center. // float cdist = dot(gv, gv)*3.; // squared distance with range 0-1 vec2 id = uv-gv; // simple ID calculation return hexParams(gv,id,edist); // xy hex coords + z distance to edge } // makes viridis colormap with polynimal 6 https://www.shadertoy.com/view/Nd3fR2 vec3 viridis(float t) { const vec3 c0 = vec3(0.274344,0.004462,0.331359); const vec3 c1 = vec3(0.108915,1.397291,1.388110); const vec3 c2 = vec3(-0.319631,0.243490,0.156419); const vec3 c3 = vec3(-4.629188,-5.882803,-19.646115); const vec3 c4 = vec3(6.181719,14.388598,57.442181); const vec3 c5 = vec3(4.876952,-13.955112,-66.125783); const vec3 c6 = vec3(-5.513165,4.709245,26.582180); return c0+t*(c1+t*(c2+t*(c3+t*(c4+t*(c5+t*c6))))); } //shifts value range from -1-1 to 0-1 float make0to1(float x) { return (1.0 + x) / 2.0; } //shifts value range from 0-1 to -1-1 vec2 makeM1to1(vec2 x) { return (x - 0.5) * 2.0; } // makes a simple flowmap of a cyclone vec2 cycloneFlow(vec2 point, float radius, float time) { float size = 1./(1.4 * sqrt(radius)); // of the entire cyclone float curl = 2.5; // kind of arbitrary but between 1-3.5 looks good float hole = 1./(4.*size); // also kind of arbitrary //point += vec2(cos(time),sin(time))*0.1*hole; //rotating center float angle = atan(point.y, point.x); //angle around center float dist = length(point); // distance to point float spiral = fract(dist/radius + (angle-time)/twoPi); //right slanted donut https://www.desmos.com/calculator/ocm71awnym spiral -= 1.212; spiral = 1.+ (pow(1.57*(spiral)+0.8,2.)/spiral); float flowAngle = pi + angle -(dist*curl) -(spiral*0.8); // left slanted donut https://www.desmos.com/calculator/uxyefly7fi float spiralStrength = 0.05; float mask = (1. - spiralStrength)-(pow(dist*size-hole, 2.0)/dist); mask += spiral*spiralStrength; mask = clamp(mask, 0.0, 1.0); // saturate vec2 flow = normalize(vec2(cos(flowAngle),sin(flowAngle))); flow *= mask; // apply strength mask //flow = (flow+1.0)/2.0; // to save as texture flow += vec2(0.0001,0.0001); //adding tiny offset so it isnt 0 return flow; } // generates pixelated directional waves float flowHexCell(vec2 uv, vec2 offset, float gridRes, float time, float len) { hexParams hexValues = hexTile(uv * gridRes + offset); hexValues.gv = hexValues.gv / gridRes; hexValues.id = (hexValues.id - offset)/ gridRes; float radius = 0.3; // of the first spiral //cyclone like flowmap vec2 flowMap = cycloneFlow(hexValues.id - vec2(0.885, 0.5), radius, time*0.2); float speed = length(flowMap); // Wind Speed vec2 dir = normalize(flowMap); // Wind Direction len *= pow(speed,0.5); // make slower waves smaller float k = twoPi / len; //Wave Number float a = pow(speed,1.5); //Amplitude float s = speed; //Steepness time *= sqrtG * sqrt(len); // deep water speed float dD = dot(uv,dir); //Directional/Straight Wave //float cD = length(hexValues.gv + (dir/(gridRes))); //Circular Wave //add random phase offsets for even FlowMaps or you get interference //time += texture( iChannel0, hexValues.id).x; float wave = make0to1(sin(k * (dD - time))); // make sin wave //wave = (1.- pow(wave, (1.-s/2.))); //cheap gerstner height wave aprox wave *= a * hexValues.edist; // apply amplitue and alpha mask return wave; } // 3 hex pixaled flowing sin thier edges get hidden by each other float triDirectionalFlow(vec2 uv, float gridRes, float time, float len) { float a = flowHexCell(uv, vec2(0.,0.), gridRes, time, len); float b = flowHexCell(uv, vec2(0,inv_sqrt3), gridRes, time, len); float c = flowHexCell(uv, vec2(0.5,inv_twice_sqrt3), gridRes, time, len); return a + b + c; } void mainImage( out vec4 fragColor, in vec2 fragCoord ) { float gridRes = 32.0; //Hex Grid Resolution float waveLen = 1./ (gridRes * 3.0); // Maximum Sin Wave Length float time = iTime * 0.05; // flow speed multiplier vec2 uv = fragCoord/iResolution.y; //square UVs float wave = triDirectionalFlow(uv,gridRes,time, waveLen); vec3 col = vec3(viridis(wave)); fragColor = vec4(col,1); }
mit
[ 4857, 4895, 4920, 4920, 4950 ]
[ [ 3438, 3484, 3507, 3507, 3557 ], [ 3667, 3741, 3769, 3769, 4301 ], [ 4303, 4384, 4407, 4407, 4855 ], [ 4857, 4895, 4920, 4920, 4950 ], [ 4952, 4990, 5014, 5014, 5044 ], [ 5046, 5085, 5141, 5141, 6331 ], [ 6333, 6374, 6453, 6453, 7631 ], [ 7633, 7699, 7772, 7772, 8009 ], [ 8011, 8011, 8068, 8068, 8434 ] ]
//shifts value range from -1-1 to 0-1
float make0to1(float x) {
return (1.0 + x) / 2.0; }
//shifts value range from -1-1 to 0-1 float make0to1(float x) {
2
2
7dycDV
gehtsiegarnixan
2022-06-21T17:26:17
// The MIT License // Copyright © 2022 Gehtsiegarnixan // Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. /* Update: I made a faster version using my Square Directional Flow (https://www.shadertoy.com/view/7ddBWl). This is using my Hex Directional Flow algorithm (https://www.shadertoy.com/view/fsGyDG) with Sine waves instead of a texture. I also made a flowmap that is an aproximation of a tropical cyclone flowmap (https://www.shadertoy.com/view/fdKcWd). I wanted to aproximate the water wave height. I looked up the forumlas for the relationship between windspeed and waves, but the math is very complicated and I gave up. So I went for what looks alright (https://www.desmos.com/calculator/lewikf6y0f). The easy water wave math can be found here (https://en.wikipedia.org/wiki/Dispersion_(water_waves)). Wikipeda explains the relationship between water depth, wavelength and wave velocity (https://www.desmos.com/calculator/2nlmht2mmy). The amplitude and windspeed don't have such linear interaction, but there are formuals for observed wave spectra on the ocean after long periods of steady wind (https://wikiwaves.org/Ocean-Wave_Spectra). I just can not figure out how to solve for the wavespeed/wavelength for a give depth and windspeed. A single wave can be described by the gerstner formula (https://catlikecoding.com/unity/tutorials/flow/waves/), but I couldn't find how the wind affects the wave steepness and when exactly they break on the open sea. I found some hints here (http://hyperphysics.phy-astr.gsu.edu/hbase/Waves/watwav2.html) when they break. I played around with circular and straight waves, but the circular ones don't look that different for how much more work they are. So I kept the straight waves, but see dD and cD to test for yourself. Animating the flowmap also turned out to have some significant drawbacks. Since im sampling a lower res hexagonal version leads to flickering waves, so you can only do it VERY slowly. */ #define pi 3.1415926536 #define sqrtG 3.1320919527 #define twoPi 6.2831853072 #define sqrt3 1.7320508076 //sqrt(3) #define half_sqrt3 0.8660254038 //sqrt(3)/2 #define inv_sqrt3 0.5773502693 // 1/sqrt(3) #define inv_twice_sqrt3 0.2886751346 // 1/(2 sqrt(3)) // if you want flat tops (hex rotated by 30deg) swap xy in hr and the p.x to p.y in hexDist const vec2 r = vec2(1, sqrt3); // 1, sqrt(3) const vec2 h = vec2(0.5,half_sqrt3); // 1/2, sqrt(3) /2 // Hexagonal Distanstance from the 0,0 coords float hexDist(vec2 p) { p = abs(p); return max(dot(p, h), p.x); } // struct to fill with needed HexTile Parametes struct hexParams { vec2 gv; vec2 id; float edist; }; // From BigWIngs "Hexagonal Tiling" https://www.shadertoy.com/view/3sSGWt hexParams hexTile(vec2 uv) { vec2 a = mod(uv, r)-h; vec2 b = mod(uv-h, r)-h; vec2 gv = dot(a, a) < dot(b,b) ? a : b; //center hex UV coords // float edist = .5-hexDist(gv); // Edge distance. float edist = (.5-hexDist(gv))*2.; // Edge distance with range 0-1 // float cdist = dot(gv, gv); // squared distance from the center. // float cdist = dot(gv, gv)*3.; // squared distance with range 0-1 vec2 id = uv-gv; // simple ID calculation return hexParams(gv,id,edist); // xy hex coords + z distance to edge } // makes viridis colormap with polynimal 6 https://www.shadertoy.com/view/Nd3fR2 vec3 viridis(float t) { const vec3 c0 = vec3(0.274344,0.004462,0.331359); const vec3 c1 = vec3(0.108915,1.397291,1.388110); const vec3 c2 = vec3(-0.319631,0.243490,0.156419); const vec3 c3 = vec3(-4.629188,-5.882803,-19.646115); const vec3 c4 = vec3(6.181719,14.388598,57.442181); const vec3 c5 = vec3(4.876952,-13.955112,-66.125783); const vec3 c6 = vec3(-5.513165,4.709245,26.582180); return c0+t*(c1+t*(c2+t*(c3+t*(c4+t*(c5+t*c6))))); } //shifts value range from -1-1 to 0-1 float make0to1(float x) { return (1.0 + x) / 2.0; } //shifts value range from 0-1 to -1-1 vec2 makeM1to1(vec2 x) { return (x - 0.5) * 2.0; } // makes a simple flowmap of a cyclone vec2 cycloneFlow(vec2 point, float radius, float time) { float size = 1./(1.4 * sqrt(radius)); // of the entire cyclone float curl = 2.5; // kind of arbitrary but between 1-3.5 looks good float hole = 1./(4.*size); // also kind of arbitrary //point += vec2(cos(time),sin(time))*0.1*hole; //rotating center float angle = atan(point.y, point.x); //angle around center float dist = length(point); // distance to point float spiral = fract(dist/radius + (angle-time)/twoPi); //right slanted donut https://www.desmos.com/calculator/ocm71awnym spiral -= 1.212; spiral = 1.+ (pow(1.57*(spiral)+0.8,2.)/spiral); float flowAngle = pi + angle -(dist*curl) -(spiral*0.8); // left slanted donut https://www.desmos.com/calculator/uxyefly7fi float spiralStrength = 0.05; float mask = (1. - spiralStrength)-(pow(dist*size-hole, 2.0)/dist); mask += spiral*spiralStrength; mask = clamp(mask, 0.0, 1.0); // saturate vec2 flow = normalize(vec2(cos(flowAngle),sin(flowAngle))); flow *= mask; // apply strength mask //flow = (flow+1.0)/2.0; // to save as texture flow += vec2(0.0001,0.0001); //adding tiny offset so it isnt 0 return flow; } // generates pixelated directional waves float flowHexCell(vec2 uv, vec2 offset, float gridRes, float time, float len) { hexParams hexValues = hexTile(uv * gridRes + offset); hexValues.gv = hexValues.gv / gridRes; hexValues.id = (hexValues.id - offset)/ gridRes; float radius = 0.3; // of the first spiral //cyclone like flowmap vec2 flowMap = cycloneFlow(hexValues.id - vec2(0.885, 0.5), radius, time*0.2); float speed = length(flowMap); // Wind Speed vec2 dir = normalize(flowMap); // Wind Direction len *= pow(speed,0.5); // make slower waves smaller float k = twoPi / len; //Wave Number float a = pow(speed,1.5); //Amplitude float s = speed; //Steepness time *= sqrtG * sqrt(len); // deep water speed float dD = dot(uv,dir); //Directional/Straight Wave //float cD = length(hexValues.gv + (dir/(gridRes))); //Circular Wave //add random phase offsets for even FlowMaps or you get interference //time += texture( iChannel0, hexValues.id).x; float wave = make0to1(sin(k * (dD - time))); // make sin wave //wave = (1.- pow(wave, (1.-s/2.))); //cheap gerstner height wave aprox wave *= a * hexValues.edist; // apply amplitue and alpha mask return wave; } // 3 hex pixaled flowing sin thier edges get hidden by each other float triDirectionalFlow(vec2 uv, float gridRes, float time, float len) { float a = flowHexCell(uv, vec2(0.,0.), gridRes, time, len); float b = flowHexCell(uv, vec2(0,inv_sqrt3), gridRes, time, len); float c = flowHexCell(uv, vec2(0.5,inv_twice_sqrt3), gridRes, time, len); return a + b + c; } void mainImage( out vec4 fragColor, in vec2 fragCoord ) { float gridRes = 32.0; //Hex Grid Resolution float waveLen = 1./ (gridRes * 3.0); // Maximum Sin Wave Length float time = iTime * 0.05; // flow speed multiplier vec2 uv = fragCoord/iResolution.y; //square UVs float wave = triDirectionalFlow(uv,gridRes,time, waveLen); vec3 col = vec3(viridis(wave)); fragColor = vec4(col,1); }
mit
[ 6333, 6374, 6453, 6453, 7631 ]
[ [ 3438, 3484, 3507, 3507, 3557 ], [ 3667, 3741, 3769, 3769, 4301 ], [ 4303, 4384, 4407, 4407, 4855 ], [ 4857, 4895, 4920, 4920, 4950 ], [ 4952, 4990, 5014, 5014, 5044 ], [ 5046, 5085, 5141, 5141, 6331 ], [ 6333, 6374, 6453, 6453, 7631 ], [ 7633, 7699, 7772, 7772, 8009 ], [ 8011, 8011, 8068, 8068, 8434 ] ]
// generates pixelated directional waves
float flowHexCell(vec2 uv, vec2 offset, float gridRes, float time, float len) {
hexParams hexValues = hexTile(uv * gridRes + offset); hexValues.gv = hexValues.gv / gridRes; hexValues.id = (hexValues.id - offset)/ gridRes; float radius = 0.3; // of the first spiral //cyclone like flowmap vec2 flowMap = cycloneFlow(hexValues.id - vec2(0.885, 0.5), radius, time*0.2); float speed = length(flowMap); // Wind Speed vec2 dir = normalize(flowMap); // Wind Direction len *= pow(speed,0.5); // make slower waves smaller float k = twoPi / len; //Wave Number float a = pow(speed,1.5); //Amplitude float s = speed; //Steepness time *= sqrtG * sqrt(len); // deep water speed float dD = dot(uv,dir); //Directional/Straight Wave //float cD = length(hexValues.gv + (dir/(gridRes))); //Circular Wave //add random phase offsets for even FlowMaps or you get interference //time += texture( iChannel0, hexValues.id).x; float wave = make0to1(sin(k * (dD - time))); // make sin wave //wave = (1.- pow(wave, (1.-s/2.))); //cheap gerstner height wave aprox wave *= a * hexValues.edist; // apply amplitue and alpha mask return wave; }
// generates pixelated directional waves float flowHexCell(vec2 uv, vec2 offset, float gridRes, float time, float len) {
1
1
7dycDV
gehtsiegarnixan
2022-06-21T17:26:17
// The MIT License // Copyright © 2022 Gehtsiegarnixan // Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. /* Update: I made a faster version using my Square Directional Flow (https://www.shadertoy.com/view/7ddBWl). This is using my Hex Directional Flow algorithm (https://www.shadertoy.com/view/fsGyDG) with Sine waves instead of a texture. I also made a flowmap that is an aproximation of a tropical cyclone flowmap (https://www.shadertoy.com/view/fdKcWd). I wanted to aproximate the water wave height. I looked up the forumlas for the relationship between windspeed and waves, but the math is very complicated and I gave up. So I went for what looks alright (https://www.desmos.com/calculator/lewikf6y0f). The easy water wave math can be found here (https://en.wikipedia.org/wiki/Dispersion_(water_waves)). Wikipeda explains the relationship between water depth, wavelength and wave velocity (https://www.desmos.com/calculator/2nlmht2mmy). The amplitude and windspeed don't have such linear interaction, but there are formuals for observed wave spectra on the ocean after long periods of steady wind (https://wikiwaves.org/Ocean-Wave_Spectra). I just can not figure out how to solve for the wavespeed/wavelength for a give depth and windspeed. A single wave can be described by the gerstner formula (https://catlikecoding.com/unity/tutorials/flow/waves/), but I couldn't find how the wind affects the wave steepness and when exactly they break on the open sea. I found some hints here (http://hyperphysics.phy-astr.gsu.edu/hbase/Waves/watwav2.html) when they break. I played around with circular and straight waves, but the circular ones don't look that different for how much more work they are. So I kept the straight waves, but see dD and cD to test for yourself. Animating the flowmap also turned out to have some significant drawbacks. Since im sampling a lower res hexagonal version leads to flickering waves, so you can only do it VERY slowly. */ #define pi 3.1415926536 #define sqrtG 3.1320919527 #define twoPi 6.2831853072 #define sqrt3 1.7320508076 //sqrt(3) #define half_sqrt3 0.8660254038 //sqrt(3)/2 #define inv_sqrt3 0.5773502693 // 1/sqrt(3) #define inv_twice_sqrt3 0.2886751346 // 1/(2 sqrt(3)) // if you want flat tops (hex rotated by 30deg) swap xy in hr and the p.x to p.y in hexDist const vec2 r = vec2(1, sqrt3); // 1, sqrt(3) const vec2 h = vec2(0.5,half_sqrt3); // 1/2, sqrt(3) /2 // Hexagonal Distanstance from the 0,0 coords float hexDist(vec2 p) { p = abs(p); return max(dot(p, h), p.x); } // struct to fill with needed HexTile Parametes struct hexParams { vec2 gv; vec2 id; float edist; }; // From BigWIngs "Hexagonal Tiling" https://www.shadertoy.com/view/3sSGWt hexParams hexTile(vec2 uv) { vec2 a = mod(uv, r)-h; vec2 b = mod(uv-h, r)-h; vec2 gv = dot(a, a) < dot(b,b) ? a : b; //center hex UV coords // float edist = .5-hexDist(gv); // Edge distance. float edist = (.5-hexDist(gv))*2.; // Edge distance with range 0-1 // float cdist = dot(gv, gv); // squared distance from the center. // float cdist = dot(gv, gv)*3.; // squared distance with range 0-1 vec2 id = uv-gv; // simple ID calculation return hexParams(gv,id,edist); // xy hex coords + z distance to edge } // makes viridis colormap with polynimal 6 https://www.shadertoy.com/view/Nd3fR2 vec3 viridis(float t) { const vec3 c0 = vec3(0.274344,0.004462,0.331359); const vec3 c1 = vec3(0.108915,1.397291,1.388110); const vec3 c2 = vec3(-0.319631,0.243490,0.156419); const vec3 c3 = vec3(-4.629188,-5.882803,-19.646115); const vec3 c4 = vec3(6.181719,14.388598,57.442181); const vec3 c5 = vec3(4.876952,-13.955112,-66.125783); const vec3 c6 = vec3(-5.513165,4.709245,26.582180); return c0+t*(c1+t*(c2+t*(c3+t*(c4+t*(c5+t*c6))))); } //shifts value range from -1-1 to 0-1 float make0to1(float x) { return (1.0 + x) / 2.0; } //shifts value range from 0-1 to -1-1 vec2 makeM1to1(vec2 x) { return (x - 0.5) * 2.0; } // makes a simple flowmap of a cyclone vec2 cycloneFlow(vec2 point, float radius, float time) { float size = 1./(1.4 * sqrt(radius)); // of the entire cyclone float curl = 2.5; // kind of arbitrary but between 1-3.5 looks good float hole = 1./(4.*size); // also kind of arbitrary //point += vec2(cos(time),sin(time))*0.1*hole; //rotating center float angle = atan(point.y, point.x); //angle around center float dist = length(point); // distance to point float spiral = fract(dist/radius + (angle-time)/twoPi); //right slanted donut https://www.desmos.com/calculator/ocm71awnym spiral -= 1.212; spiral = 1.+ (pow(1.57*(spiral)+0.8,2.)/spiral); float flowAngle = pi + angle -(dist*curl) -(spiral*0.8); // left slanted donut https://www.desmos.com/calculator/uxyefly7fi float spiralStrength = 0.05; float mask = (1. - spiralStrength)-(pow(dist*size-hole, 2.0)/dist); mask += spiral*spiralStrength; mask = clamp(mask, 0.0, 1.0); // saturate vec2 flow = normalize(vec2(cos(flowAngle),sin(flowAngle))); flow *= mask; // apply strength mask //flow = (flow+1.0)/2.0; // to save as texture flow += vec2(0.0001,0.0001); //adding tiny offset so it isnt 0 return flow; } // generates pixelated directional waves float flowHexCell(vec2 uv, vec2 offset, float gridRes, float time, float len) { hexParams hexValues = hexTile(uv * gridRes + offset); hexValues.gv = hexValues.gv / gridRes; hexValues.id = (hexValues.id - offset)/ gridRes; float radius = 0.3; // of the first spiral //cyclone like flowmap vec2 flowMap = cycloneFlow(hexValues.id - vec2(0.885, 0.5), radius, time*0.2); float speed = length(flowMap); // Wind Speed vec2 dir = normalize(flowMap); // Wind Direction len *= pow(speed,0.5); // make slower waves smaller float k = twoPi / len; //Wave Number float a = pow(speed,1.5); //Amplitude float s = speed; //Steepness time *= sqrtG * sqrt(len); // deep water speed float dD = dot(uv,dir); //Directional/Straight Wave //float cD = length(hexValues.gv + (dir/(gridRes))); //Circular Wave //add random phase offsets for even FlowMaps or you get interference //time += texture( iChannel0, hexValues.id).x; float wave = make0to1(sin(k * (dD - time))); // make sin wave //wave = (1.- pow(wave, (1.-s/2.))); //cheap gerstner height wave aprox wave *= a * hexValues.edist; // apply amplitue and alpha mask return wave; } // 3 hex pixaled flowing sin thier edges get hidden by each other float triDirectionalFlow(vec2 uv, float gridRes, float time, float len) { float a = flowHexCell(uv, vec2(0.,0.), gridRes, time, len); float b = flowHexCell(uv, vec2(0,inv_sqrt3), gridRes, time, len); float c = flowHexCell(uv, vec2(0.5,inv_twice_sqrt3), gridRes, time, len); return a + b + c; } void mainImage( out vec4 fragColor, in vec2 fragCoord ) { float gridRes = 32.0; //Hex Grid Resolution float waveLen = 1./ (gridRes * 3.0); // Maximum Sin Wave Length float time = iTime * 0.05; // flow speed multiplier vec2 uv = fragCoord/iResolution.y; //square UVs float wave = triDirectionalFlow(uv,gridRes,time, waveLen); vec3 col = vec3(viridis(wave)); fragColor = vec4(col,1); }
mit
[ 7633, 7699, 7772, 7772, 8009 ]
[ [ 3438, 3484, 3507, 3507, 3557 ], [ 3667, 3741, 3769, 3769, 4301 ], [ 4303, 4384, 4407, 4407, 4855 ], [ 4857, 4895, 4920, 4920, 4950 ], [ 4952, 4990, 5014, 5014, 5044 ], [ 5046, 5085, 5141, 5141, 6331 ], [ 6333, 6374, 6453, 6453, 7631 ], [ 7633, 7699, 7772, 7772, 8009 ], [ 8011, 8011, 8068, 8068, 8434 ] ]
// 3 hex pixaled flowing sin thier edges get hidden by each other
float triDirectionalFlow(vec2 uv, float gridRes, float time, float len) {
float a = flowHexCell(uv, vec2(0.,0.), gridRes, time, len); float b = flowHexCell(uv, vec2(0,inv_sqrt3), gridRes, time, len); float c = flowHexCell(uv, vec2(0.5,inv_twice_sqrt3), gridRes, time, len); return a + b + c; }
// 3 hex pixaled flowing sin thier edges get hidden by each other float triDirectionalFlow(vec2 uv, float gridRes, float time, float len) {
1
2
fdKcWd
gehtsiegarnixan
2022-06-21T17:26:10
// The MIT License // Copyright © 2022 Gehtsiegarnixan // Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. /* This is an approximation of a tropical cyclone flowmap at sea level. The reference cyclone had a diamter of 300km. The maximum velocity was 53m/s. It was generated using the CM1 weather model in a super computer. The flowmap is just a vector field that can be used for other stuff like this (https://www.shadertoy.com/view/7dycDV) The quiver plot is from Reima (https://www.shadertoy.com/view/ls2GWG) */ #define twoPi 6.2831853072 #define pi 3.1415926536 #define ARROW_TILE_SIZE 32.0 // Computes the center pixel of the tile containing pixel pos vec2 arrowTileCenterCoord(vec2 pos) { return (floor(pos / ARROW_TILE_SIZE) + 0.5) * ARROW_TILE_SIZE; } // Computes the signed distance from a line segment float line(vec2 p, vec2 p1, vec2 p2) { vec2 center = (p1 + p2) * 0.5; float len = length(p2 - p1); vec2 dir = (p2 - p1) / len; vec2 rel_p = p - center; float dist1 = abs(dot(rel_p, vec2(dir.y, -dir.x))); float dist2 = abs(dot(rel_p, dir)) - 0.5*len; return max(dist1, dist2); } // v = field sampled at arrowTileCenterCoord(p), scaled by the length // desired in pixels for arrows // Returns a signed distance from the arrow float arrow(vec2 p, vec2 v) { // Make everything relative to the center, which may be fractional p -= arrowTileCenterCoord(p); float mag_v = length(v), mag_p = length(p); if (mag_v > 0.0) { // Non-zero velocity case vec2 dir_v = v / mag_v; // We can't draw arrows larger than the tile radius, so clamp magnitude. // Enforce a minimum length to help see direction mag_v = clamp(mag_v, 5.0, ARROW_TILE_SIZE * 0.5); // Arrow tip location v = dir_v * mag_v; // Signed distance from shaft float shaft = line(p, v, -v); // Signed distance from head float head = min(line(p, v, 0.4*v + 0.2*vec2(-v.y, v.x)), line(p, v, 0.4*v + 0.2*vec2(v.y, -v.x))); return min(shaft, head); } else { // Signed distance from the center point return mag_p; } } //shifts value range from 0-1 to -1-1 vec2 makeM1to1(vec2 x) { return (x - 0.5) * 2.0; } //shifts value range from -1-1 to 0-1 vec2 make0to1(vec2 x) { return (1.0 + x) / 2.0; } // makes a simple flowmap of a cyclone vec2 cycloneFlow(vec2 point, float radius, float time) { float size = 1./(1.4 * sqrt(radius)); // of the entire cyclone float curl = 2.5; // kind of arbitrary but between 1-3.5 looks good float hole = 1./(4.*size); // also kind of arbitrary //point += vec2(cos(time),sin(time))*0.1*hole; //rotating center float angle = atan(point.y, point.x); //angle around center float dist = length(point); // distance to point float spiral = fract(dist/radius + (angle-time)/twoPi); //right slanted donut https://www.desmos.com/calculator/ocm71awnym spiral -= 1.212; // spiral = 1.+ (pow(1.57*(spiral)+0.8,2.)/spiral); float flowAngle = pi + angle -(dist*curl) -(spiral*0.8); // left slanted donut https://www.desmos.com/calculator/uxyefly7fi float spiralStrength = 0.05; // makes sure mask is 0-1 range float mask = (1. - spiralStrength)-(pow(dist*size-hole, 2.0)/dist); mask += spiral*spiralStrength; mask = clamp(mask, 0.0, 1.0); // saturate vec2 flow = normalize(vec2(cos(flowAngle),sin(flowAngle))); flow *= mask; // apply strength mask //flow = (flow+1.0)/2.0; // to save as texture //flow += vec2(0.00001,0.00001); //adding tiny offset so it isnt 0 return flow; } void mainImage( out vec4 fragColor, in vec2 fragCoord ) { float radius = 0.3; // of the first spiral float time = iTime * 1.0; // rotation speed vec2 uv = (fragCoord.xy- (0.5*iResolution.xy))/iResolution.y; // center screen coords vec2 flowMap = cycloneFlow(uv, radius, time); float arrow_dist = arrow(fragCoord.xy, flowMap* ARROW_TILE_SIZE * 0.4); vec4 arrow_col = vec4(0, 0, 0, clamp(arrow_dist, 0.0, 1.0)); fragColor = mix(arrow_col, vec4(make0to1(flowMap),0.5,1.0), arrow_col.a); }
mit
[ 3237, 3276, 3332, 3332, 4561 ]
[ [ 1598, 1660, 1697, 1697, 1763 ], [ 1765, 1817, 1855, 1855, 2101 ], [ 2103, 2249, 2278, 2346, 3048 ], [ 3050, 3088, 3112, 3112, 3142 ], [ 3144, 3182, 3205, 3205, 3235 ], [ 3237, 3276, 3332, 3332, 4561 ], [ 4563, 4563, 4620, 4620, 5095 ] ]
// makes a simple flowmap of a cyclone
vec2 cycloneFlow(vec2 point, float radius, float time) {
float size = 1./(1.4 * sqrt(radius)); // of the entire cyclone float curl = 2.5; // kind of arbitrary but between 1-3.5 looks good float hole = 1./(4.*size); // also kind of arbitrary //point += vec2(cos(time),sin(time))*0.1*hole; //rotating center float angle = atan(point.y, point.x); //angle around center float dist = length(point); // distance to point float spiral = fract(dist/radius + (angle-time)/twoPi); //right slanted donut https://www.desmos.com/calculator/ocm71awnym spiral -= 1.212; // spiral = 1.+ (pow(1.57*(spiral)+0.8,2.)/spiral); float flowAngle = pi + angle -(dist*curl) -(spiral*0.8); // left slanted donut https://www.desmos.com/calculator/uxyefly7fi float spiralStrength = 0.05; // makes sure mask is 0-1 range float mask = (1. - spiralStrength)-(pow(dist*size-hole, 2.0)/dist); mask += spiral*spiralStrength; mask = clamp(mask, 0.0, 1.0); // saturate vec2 flow = normalize(vec2(cos(flowAngle),sin(flowAngle))); flow *= mask; // apply strength mask //flow = (flow+1.0)/2.0; // to save as texture //flow += vec2(0.00001,0.00001); //adding tiny offset so it isnt 0 return flow; }
// makes a simple flowmap of a cyclone vec2 cycloneFlow(vec2 point, float radius, float time) {
1
3
NdyyWy
gehtsiegarnixan
2022-06-21T17:26:05
// The MIT License // Copyright © 2022 Gehtsiegarnixan // Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. /* This is a donut shaped flowmap I did for testing. The quiver plot is from Reima (https://www.shadertoy.com/view/ls2GWG) */ #define ARROW_TILE_SIZE 32.0 // Computes the center pixel of the tile containing pixel pos vec2 arrowTileCenterCoord(vec2 pos) { return (floor(pos / ARROW_TILE_SIZE) + 0.5) * ARROW_TILE_SIZE; } // Computes the signed distance from a line segment float line(vec2 p, vec2 p1, vec2 p2) { vec2 center = (p1 + p2) * 0.5; float len = length(p2 - p1); vec2 dir = (p2 - p1) / len; vec2 rel_p = p - center; float dist1 = abs(dot(rel_p, vec2(dir.y, -dir.x))); float dist2 = abs(dot(rel_p, dir)) - 0.5*len; return max(dist1, dist2); } // v = field sampled at arrowTileCenterCoord(p), scaled by the length // desired in pixels for arrows // Returns a signed distance from the arrow float arrow(vec2 p, vec2 v) { // Make everything relative to the center, which may be fractional p -= arrowTileCenterCoord(p); float mag_v = length(v), mag_p = length(p); if (mag_v > 0.0) { // Non-zero velocity case vec2 dir_v = v / mag_v; // We can't draw arrows larger than the tile radius, so clamp magnitude. // Enforce a minimum length to help see direction mag_v = clamp(mag_v, 5.0, ARROW_TILE_SIZE * 0.5); // Arrow tip location v = dir_v * mag_v; // Signed distance from shaft float shaft = line(p, v, -v); // Signed distance from head float head = min(line(p, v, 0.4*v + 0.2*vec2(-v.y, v.x)), line(p, v, 0.4*v + 0.2*vec2(v.y, -v.x))); return min(shaft, head); } else { // Signed distance from the center point return mag_p; } } //shifts value range from -1-1 to 0-1 vec2 make0to1(vec2 x) { return (1.0 + x) / 2.0; } // makes a simple flowmap in the shape a donut swirl centered on point vec2 donutFlow(vec2 point, float spread, float offset) { float cenderDistance = length(point); // distance to center // simple inverted x^2 https://www.desmos.com/calculator/ibidozowyh float donut = 1.0-pow(2.0*(cenderDistance-offset)/spread, 2.0); donut = clamp(donut, 0.0, 1.0); // saturate vec2 flow = normalize(vec2(-point.y, point.x)); // flow vectors flow *= donut; // masked by donut //flow = (flow+1.0)/2.0; // generates a flowmap texture //flow += vec2(0.0001,0.0001); //adding tiny offset so it isnt 0 return flow; } void mainImage( out vec4 fragColor, in vec2 fragCoord ) { vec2 uv = (fragCoord.xy- (0.5*iResolution.xy))/iResolution.y; // center screen coords uv += vec2(cos(iTime),sin(iTime))*0.1; //rotating center float spread = mix(0.4, 0.3, sin(0.9*iTime)*0.5+0.5); //changing donut size // making flowmap vec2 flowMap = donutFlow(uv, spread, 0.33); //adding arrows float arrow_dist = arrow(fragCoord.xy, flowMap* ARROW_TILE_SIZE * 0.4); vec4 arrow_col = vec4(0, 0, 0, clamp(arrow_dist, 0.0, 1.0)); fragColor = mix(arrow_col, vec4(make0to1(flowMap),0.5,1.0), arrow_col.a); }
mit
[ 1239, 1301, 1338, 1338, 1404 ]
[ [ 1239, 1301, 1338, 1338, 1404 ], [ 1406, 1458, 1496, 1496, 1742 ], [ 1744, 1890, 1919, 1987, 2689 ], [ 2691, 2729, 2752, 2752, 2782 ], [ 2784, 2855, 2911, 2911, 3438 ], [ 3440, 3440, 3497, 3497, 4053 ] ]
// Computes the center pixel of the tile containing pixel pos
vec2 arrowTileCenterCoord(vec2 pos) {
return (floor(pos / ARROW_TILE_SIZE) + 0.5) * ARROW_TILE_SIZE; }
// Computes the center pixel of the tile containing pixel pos vec2 arrowTileCenterCoord(vec2 pos) {
4
4
NdyyWy
gehtsiegarnixan
2022-06-21T17:26:05
// The MIT License // Copyright © 2022 Gehtsiegarnixan // Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. /* This is a donut shaped flowmap I did for testing. The quiver plot is from Reima (https://www.shadertoy.com/view/ls2GWG) */ #define ARROW_TILE_SIZE 32.0 // Computes the center pixel of the tile containing pixel pos vec2 arrowTileCenterCoord(vec2 pos) { return (floor(pos / ARROW_TILE_SIZE) + 0.5) * ARROW_TILE_SIZE; } // Computes the signed distance from a line segment float line(vec2 p, vec2 p1, vec2 p2) { vec2 center = (p1 + p2) * 0.5; float len = length(p2 - p1); vec2 dir = (p2 - p1) / len; vec2 rel_p = p - center; float dist1 = abs(dot(rel_p, vec2(dir.y, -dir.x))); float dist2 = abs(dot(rel_p, dir)) - 0.5*len; return max(dist1, dist2); } // v = field sampled at arrowTileCenterCoord(p), scaled by the length // desired in pixels for arrows // Returns a signed distance from the arrow float arrow(vec2 p, vec2 v) { // Make everything relative to the center, which may be fractional p -= arrowTileCenterCoord(p); float mag_v = length(v), mag_p = length(p); if (mag_v > 0.0) { // Non-zero velocity case vec2 dir_v = v / mag_v; // We can't draw arrows larger than the tile radius, so clamp magnitude. // Enforce a minimum length to help see direction mag_v = clamp(mag_v, 5.0, ARROW_TILE_SIZE * 0.5); // Arrow tip location v = dir_v * mag_v; // Signed distance from shaft float shaft = line(p, v, -v); // Signed distance from head float head = min(line(p, v, 0.4*v + 0.2*vec2(-v.y, v.x)), line(p, v, 0.4*v + 0.2*vec2(v.y, -v.x))); return min(shaft, head); } else { // Signed distance from the center point return mag_p; } } //shifts value range from -1-1 to 0-1 vec2 make0to1(vec2 x) { return (1.0 + x) / 2.0; } // makes a simple flowmap in the shape a donut swirl centered on point vec2 donutFlow(vec2 point, float spread, float offset) { float cenderDistance = length(point); // distance to center // simple inverted x^2 https://www.desmos.com/calculator/ibidozowyh float donut = 1.0-pow(2.0*(cenderDistance-offset)/spread, 2.0); donut = clamp(donut, 0.0, 1.0); // saturate vec2 flow = normalize(vec2(-point.y, point.x)); // flow vectors flow *= donut; // masked by donut //flow = (flow+1.0)/2.0; // generates a flowmap texture //flow += vec2(0.0001,0.0001); //adding tiny offset so it isnt 0 return flow; } void mainImage( out vec4 fragColor, in vec2 fragCoord ) { vec2 uv = (fragCoord.xy- (0.5*iResolution.xy))/iResolution.y; // center screen coords uv += vec2(cos(iTime),sin(iTime))*0.1; //rotating center float spread = mix(0.4, 0.3, sin(0.9*iTime)*0.5+0.5); //changing donut size // making flowmap vec2 flowMap = donutFlow(uv, spread, 0.33); //adding arrows float arrow_dist = arrow(fragCoord.xy, flowMap* ARROW_TILE_SIZE * 0.4); vec4 arrow_col = vec4(0, 0, 0, clamp(arrow_dist, 0.0, 1.0)); fragColor = mix(arrow_col, vec4(make0to1(flowMap),0.5,1.0), arrow_col.a); }
mit
[ 1406, 1458, 1496, 1496, 1742 ]
[ [ 1239, 1301, 1338, 1338, 1404 ], [ 1406, 1458, 1496, 1496, 1742 ], [ 1744, 1890, 1919, 1987, 2689 ], [ 2691, 2729, 2752, 2752, 2782 ], [ 2784, 2855, 2911, 2911, 3438 ], [ 3440, 3440, 3497, 3497, 4053 ] ]
// Computes the signed distance from a line segment
float line(vec2 p, vec2 p1, vec2 p2) {
vec2 center = (p1 + p2) * 0.5; float len = length(p2 - p1); vec2 dir = (p2 - p1) / len; vec2 rel_p = p - center; float dist1 = abs(dot(rel_p, vec2(dir.y, -dir.x))); float dist2 = abs(dot(rel_p, dir)) - 0.5*len; return max(dist1, dist2); }
// Computes the signed distance from a line segment float line(vec2 p, vec2 p1, vec2 p2) {
3
3
NdyyWy
gehtsiegarnixan
2022-06-21T17:26:05
// The MIT License // Copyright © 2022 Gehtsiegarnixan // Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. /* This is a donut shaped flowmap I did for testing. The quiver plot is from Reima (https://www.shadertoy.com/view/ls2GWG) */ #define ARROW_TILE_SIZE 32.0 // Computes the center pixel of the tile containing pixel pos vec2 arrowTileCenterCoord(vec2 pos) { return (floor(pos / ARROW_TILE_SIZE) + 0.5) * ARROW_TILE_SIZE; } // Computes the signed distance from a line segment float line(vec2 p, vec2 p1, vec2 p2) { vec2 center = (p1 + p2) * 0.5; float len = length(p2 - p1); vec2 dir = (p2 - p1) / len; vec2 rel_p = p - center; float dist1 = abs(dot(rel_p, vec2(dir.y, -dir.x))); float dist2 = abs(dot(rel_p, dir)) - 0.5*len; return max(dist1, dist2); } // v = field sampled at arrowTileCenterCoord(p), scaled by the length // desired in pixels for arrows // Returns a signed distance from the arrow float arrow(vec2 p, vec2 v) { // Make everything relative to the center, which may be fractional p -= arrowTileCenterCoord(p); float mag_v = length(v), mag_p = length(p); if (mag_v > 0.0) { // Non-zero velocity case vec2 dir_v = v / mag_v; // We can't draw arrows larger than the tile radius, so clamp magnitude. // Enforce a minimum length to help see direction mag_v = clamp(mag_v, 5.0, ARROW_TILE_SIZE * 0.5); // Arrow tip location v = dir_v * mag_v; // Signed distance from shaft float shaft = line(p, v, -v); // Signed distance from head float head = min(line(p, v, 0.4*v + 0.2*vec2(-v.y, v.x)), line(p, v, 0.4*v + 0.2*vec2(v.y, -v.x))); return min(shaft, head); } else { // Signed distance from the center point return mag_p; } } //shifts value range from -1-1 to 0-1 vec2 make0to1(vec2 x) { return (1.0 + x) / 2.0; } // makes a simple flowmap in the shape a donut swirl centered on point vec2 donutFlow(vec2 point, float spread, float offset) { float cenderDistance = length(point); // distance to center // simple inverted x^2 https://www.desmos.com/calculator/ibidozowyh float donut = 1.0-pow(2.0*(cenderDistance-offset)/spread, 2.0); donut = clamp(donut, 0.0, 1.0); // saturate vec2 flow = normalize(vec2(-point.y, point.x)); // flow vectors flow *= donut; // masked by donut //flow = (flow+1.0)/2.0; // generates a flowmap texture //flow += vec2(0.0001,0.0001); //adding tiny offset so it isnt 0 return flow; } void mainImage( out vec4 fragColor, in vec2 fragCoord ) { vec2 uv = (fragCoord.xy- (0.5*iResolution.xy))/iResolution.y; // center screen coords uv += vec2(cos(iTime),sin(iTime))*0.1; //rotating center float spread = mix(0.4, 0.3, sin(0.9*iTime)*0.5+0.5); //changing donut size // making flowmap vec2 flowMap = donutFlow(uv, spread, 0.33); //adding arrows float arrow_dist = arrow(fragCoord.xy, flowMap* ARROW_TILE_SIZE * 0.4); vec4 arrow_col = vec4(0, 0, 0, clamp(arrow_dist, 0.0, 1.0)); fragColor = mix(arrow_col, vec4(make0to1(flowMap),0.5,1.0), arrow_col.a); }
mit
[ 1744, 1890, 1919, 1987, 2689 ]
[ [ 1239, 1301, 1338, 1338, 1404 ], [ 1406, 1458, 1496, 1496, 1742 ], [ 1744, 1890, 1919, 1987, 2689 ], [ 2691, 2729, 2752, 2752, 2782 ], [ 2784, 2855, 2911, 2911, 3438 ], [ 3440, 3440, 3497, 3497, 4053 ] ]
// v = field sampled at arrowTileCenterCoord(p), scaled by the length // desired in pixels for arrows // Returns a signed distance from the arrow
float arrow(vec2 p, vec2 v) {
p -= arrowTileCenterCoord(p); float mag_v = length(v), mag_p = length(p); if (mag_v > 0.0) { // Non-zero velocity case vec2 dir_v = v / mag_v; // We can't draw arrows larger than the tile radius, so clamp magnitude. // Enforce a minimum length to help see direction mag_v = clamp(mag_v, 5.0, ARROW_TILE_SIZE * 0.5); // Arrow tip location v = dir_v * mag_v; // Signed distance from shaft float shaft = line(p, v, -v); // Signed distance from head float head = min(line(p, v, 0.4*v + 0.2*vec2(-v.y, v.x)), line(p, v, 0.4*v + 0.2*vec2(v.y, -v.x))); return min(shaft, head); } else { // Signed distance from the center point return mag_p; } }
// v = field sampled at arrowTileCenterCoord(p), scaled by the length // desired in pixels for arrows // Returns a signed distance from the arrow float arrow(vec2 p, vec2 v) {
3
4
NdyyWy
gehtsiegarnixan
2022-06-21T17:26:05
// The MIT License // Copyright © 2022 Gehtsiegarnixan // Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. /* This is a donut shaped flowmap I did for testing. The quiver plot is from Reima (https://www.shadertoy.com/view/ls2GWG) */ #define ARROW_TILE_SIZE 32.0 // Computes the center pixel of the tile containing pixel pos vec2 arrowTileCenterCoord(vec2 pos) { return (floor(pos / ARROW_TILE_SIZE) + 0.5) * ARROW_TILE_SIZE; } // Computes the signed distance from a line segment float line(vec2 p, vec2 p1, vec2 p2) { vec2 center = (p1 + p2) * 0.5; float len = length(p2 - p1); vec2 dir = (p2 - p1) / len; vec2 rel_p = p - center; float dist1 = abs(dot(rel_p, vec2(dir.y, -dir.x))); float dist2 = abs(dot(rel_p, dir)) - 0.5*len; return max(dist1, dist2); } // v = field sampled at arrowTileCenterCoord(p), scaled by the length // desired in pixels for arrows // Returns a signed distance from the arrow float arrow(vec2 p, vec2 v) { // Make everything relative to the center, which may be fractional p -= arrowTileCenterCoord(p); float mag_v = length(v), mag_p = length(p); if (mag_v > 0.0) { // Non-zero velocity case vec2 dir_v = v / mag_v; // We can't draw arrows larger than the tile radius, so clamp magnitude. // Enforce a minimum length to help see direction mag_v = clamp(mag_v, 5.0, ARROW_TILE_SIZE * 0.5); // Arrow tip location v = dir_v * mag_v; // Signed distance from shaft float shaft = line(p, v, -v); // Signed distance from head float head = min(line(p, v, 0.4*v + 0.2*vec2(-v.y, v.x)), line(p, v, 0.4*v + 0.2*vec2(v.y, -v.x))); return min(shaft, head); } else { // Signed distance from the center point return mag_p; } } //shifts value range from -1-1 to 0-1 vec2 make0to1(vec2 x) { return (1.0 + x) / 2.0; } // makes a simple flowmap in the shape a donut swirl centered on point vec2 donutFlow(vec2 point, float spread, float offset) { float cenderDistance = length(point); // distance to center // simple inverted x^2 https://www.desmos.com/calculator/ibidozowyh float donut = 1.0-pow(2.0*(cenderDistance-offset)/spread, 2.0); donut = clamp(donut, 0.0, 1.0); // saturate vec2 flow = normalize(vec2(-point.y, point.x)); // flow vectors flow *= donut; // masked by donut //flow = (flow+1.0)/2.0; // generates a flowmap texture //flow += vec2(0.0001,0.0001); //adding tiny offset so it isnt 0 return flow; } void mainImage( out vec4 fragColor, in vec2 fragCoord ) { vec2 uv = (fragCoord.xy- (0.5*iResolution.xy))/iResolution.y; // center screen coords uv += vec2(cos(iTime),sin(iTime))*0.1; //rotating center float spread = mix(0.4, 0.3, sin(0.9*iTime)*0.5+0.5); //changing donut size // making flowmap vec2 flowMap = donutFlow(uv, spread, 0.33); //adding arrows float arrow_dist = arrow(fragCoord.xy, flowMap* ARROW_TILE_SIZE * 0.4); vec4 arrow_col = vec4(0, 0, 0, clamp(arrow_dist, 0.0, 1.0)); fragColor = mix(arrow_col, vec4(make0to1(flowMap),0.5,1.0), arrow_col.a); }
mit
[ 2691, 2729, 2752, 2752, 2782 ]
[ [ 1239, 1301, 1338, 1338, 1404 ], [ 1406, 1458, 1496, 1496, 1742 ], [ 1744, 1890, 1919, 1987, 2689 ], [ 2691, 2729, 2752, 2752, 2782 ], [ 2784, 2855, 2911, 2911, 3438 ], [ 3440, 3440, 3497, 3497, 4053 ] ]
//shifts value range from -1-1 to 0-1
vec2 make0to1(vec2 x) {
return (1.0 + x) / 2.0; }
//shifts value range from -1-1 to 0-1 vec2 make0to1(vec2 x) {
2
2
NdyyWy
gehtsiegarnixan
2022-06-21T17:26:05
// The MIT License // Copyright © 2022 Gehtsiegarnixan // Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. /* This is a donut shaped flowmap I did for testing. The quiver plot is from Reima (https://www.shadertoy.com/view/ls2GWG) */ #define ARROW_TILE_SIZE 32.0 // Computes the center pixel of the tile containing pixel pos vec2 arrowTileCenterCoord(vec2 pos) { return (floor(pos / ARROW_TILE_SIZE) + 0.5) * ARROW_TILE_SIZE; } // Computes the signed distance from a line segment float line(vec2 p, vec2 p1, vec2 p2) { vec2 center = (p1 + p2) * 0.5; float len = length(p2 - p1); vec2 dir = (p2 - p1) / len; vec2 rel_p = p - center; float dist1 = abs(dot(rel_p, vec2(dir.y, -dir.x))); float dist2 = abs(dot(rel_p, dir)) - 0.5*len; return max(dist1, dist2); } // v = field sampled at arrowTileCenterCoord(p), scaled by the length // desired in pixels for arrows // Returns a signed distance from the arrow float arrow(vec2 p, vec2 v) { // Make everything relative to the center, which may be fractional p -= arrowTileCenterCoord(p); float mag_v = length(v), mag_p = length(p); if (mag_v > 0.0) { // Non-zero velocity case vec2 dir_v = v / mag_v; // We can't draw arrows larger than the tile radius, so clamp magnitude. // Enforce a minimum length to help see direction mag_v = clamp(mag_v, 5.0, ARROW_TILE_SIZE * 0.5); // Arrow tip location v = dir_v * mag_v; // Signed distance from shaft float shaft = line(p, v, -v); // Signed distance from head float head = min(line(p, v, 0.4*v + 0.2*vec2(-v.y, v.x)), line(p, v, 0.4*v + 0.2*vec2(v.y, -v.x))); return min(shaft, head); } else { // Signed distance from the center point return mag_p; } } //shifts value range from -1-1 to 0-1 vec2 make0to1(vec2 x) { return (1.0 + x) / 2.0; } // makes a simple flowmap in the shape a donut swirl centered on point vec2 donutFlow(vec2 point, float spread, float offset) { float cenderDistance = length(point); // distance to center // simple inverted x^2 https://www.desmos.com/calculator/ibidozowyh float donut = 1.0-pow(2.0*(cenderDistance-offset)/spread, 2.0); donut = clamp(donut, 0.0, 1.0); // saturate vec2 flow = normalize(vec2(-point.y, point.x)); // flow vectors flow *= donut; // masked by donut //flow = (flow+1.0)/2.0; // generates a flowmap texture //flow += vec2(0.0001,0.0001); //adding tiny offset so it isnt 0 return flow; } void mainImage( out vec4 fragColor, in vec2 fragCoord ) { vec2 uv = (fragCoord.xy- (0.5*iResolution.xy))/iResolution.y; // center screen coords uv += vec2(cos(iTime),sin(iTime))*0.1; //rotating center float spread = mix(0.4, 0.3, sin(0.9*iTime)*0.5+0.5); //changing donut size // making flowmap vec2 flowMap = donutFlow(uv, spread, 0.33); //adding arrows float arrow_dist = arrow(fragCoord.xy, flowMap* ARROW_TILE_SIZE * 0.4); vec4 arrow_col = vec4(0, 0, 0, clamp(arrow_dist, 0.0, 1.0)); fragColor = mix(arrow_col, vec4(make0to1(flowMap),0.5,1.0), arrow_col.a); }
mit
[ 2784, 2855, 2911, 2911, 3438 ]
[ [ 1239, 1301, 1338, 1338, 1404 ], [ 1406, 1458, 1496, 1496, 1742 ], [ 1744, 1890, 1919, 1987, 2689 ], [ 2691, 2729, 2752, 2752, 2782 ], [ 2784, 2855, 2911, 2911, 3438 ], [ 3440, 3440, 3497, 3497, 4053 ] ]
// makes a simple flowmap in the shape a donut swirl centered on point
vec2 donutFlow(vec2 point, float spread, float offset) {
float cenderDistance = length(point); // distance to center // simple inverted x^2 https://www.desmos.com/calculator/ibidozowyh float donut = 1.0-pow(2.0*(cenderDistance-offset)/spread, 2.0); donut = clamp(donut, 0.0, 1.0); // saturate vec2 flow = normalize(vec2(-point.y, point.x)); // flow vectors flow *= donut; // masked by donut //flow = (flow+1.0)/2.0; // generates a flowmap texture //flow += vec2(0.0001,0.0001); //adding tiny offset so it isnt 0 return flow; }
// makes a simple flowmap in the shape a donut swirl centered on point vec2 donutFlow(vec2 point, float spread, float offset) {
2
2
fdVBDw
iq
2022-07-20T11:43:48
// The MIT License // Copyright © 2022 Inigo Quilez // Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. // Computing the SDF of a limited number of copies of a base // SDF object constrained to a circle. // Related techniques: // // Elongation : https://www.shadertoy.com/view/Ml3fWj // Rounding : https://www.shadertoy.com/view/Mt3BDj // Onion : https://www.shadertoy.com/view/MlcBDj // Metric : https://www.shadertoy.com/view/ltcfDj // Combination : https://www.shadertoy.com/view/lt3BW2 // Repetition : https://www.shadertoy.com/view/3syGzz // Extrusion2D : https://www.shadertoy.com/view/4lyfzw // Revolution2D: https://www.shadertoy.com/view/4lyfzw // // More information here: https://iquilezles.org/articles/distfunctions // https://iquilezles.org/articles/distfunctions float sdBox( in vec2 p, in vec2 b ) { vec2 q = abs(p) - b; return min(max(q.x,q.y),0.0) + length(max(q,0.0)); } // the SDF we want to repeat float sdBase( in vec2 p, vec2 id, float sp, in float time ) { float d; if( sin(time/2.0)>0.0 ) { d = sdBox( p, vec2(0.1,0.1)*sp ) - 0.2*sp; } else { if( mod(id.x+id.y,2.0)>0.5 ) d = sdBox( p, vec2(0.2*sp) ); else d = sdBox( p, vec2(0.2,0.02)*sp ) - 0.3*sp; } return d; } // the point of this shader float sdCircularRepetition( in vec2 p, float ra, float sp, float time ) { // make grid vec2 id0 = round(p/sp); // snap to circle if( dot(id0,id0)>ra*ra ) id0 = round(normalize(id0)*ra); // scan neighbors float d = 1e20; for( int j=-2; j<=2; j++ ) // increase this search window for( int i=-2; i<=2; i++ ) // for large values of ra { vec2 id = id0 + vec2(i,j); if( dot(id,id)<=ra*ra ) { vec2 q = p-sp*id; d = min( d, sdBase(q,id,sp,time) ); } } return d; } void mainImage( out vec4 fragColor, in vec2 fragCoord ) { vec2 p = (2.0*fragCoord-iResolution.xy)/iResolution.y; vec2 m = (2.0*iMouse.xy-iResolution.xy)/iResolution.y; float time = iTime + 0.001; // circle radius and cell size, to be tuned for your needs float ra = floor(3.0 + 8.0*(0.5-0.5*cos(time))); float sp = 0.8/ra; // sdf float d = sdCircularRepetition( p, ra, sp, time ); // colorize vec3 col = (d>0.0) ? vec3(0.9,0.6,0.3) : vec3(0.65,0.85,1.0); col *= 1.0 - exp(-32.0*abs(d)); col *= 0.8 + 0.2*cos( 120.0*d); col = mix( col, vec3(1.0), 1.0-smoothstep(0.0,0.009,abs(d)) ); if( iMouse.z>0.001 ) { d = sdCircularRepetition( m, ra, sp, time ); col = mix(col, vec3(1.0,1.0,0.0), 1.0-smoothstep(0.0, 0.005, abs(length(p-m)-abs(d))-0.0025)); col = mix(col, vec3(1.0,1.0,0.0), 1.0-smoothstep(0.0, 0.005, length(p-m)-0.015)); } fragColor = vec4(col,1.0); }
mit
[ 1721, 1770, 1808, 1808, 1890 ]
[ [ 1721, 1770, 1808, 1808, 1890 ], [ 1892, 1921, 1982, 1982, 2267 ], [ 2269, 2297, 2370, 2387, 2862 ], [ 2864, 2864, 2921, 2921, 3811 ] ]
// https://iquilezles.org/articles/distfunctions
float sdBox( in vec2 p, in vec2 b ) {
vec2 q = abs(p) - b; return min(max(q.x,q.y),0.0) + length(max(q,0.0)); }
// https://iquilezles.org/articles/distfunctions float sdBox( in vec2 p, in vec2 b ) {
5
10
fdVBDw
iq
2022-07-20T11:43:48
// The MIT License // Copyright © 2022 Inigo Quilez // Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. // Computing the SDF of a limited number of copies of a base // SDF object constrained to a circle. // Related techniques: // // Elongation : https://www.shadertoy.com/view/Ml3fWj // Rounding : https://www.shadertoy.com/view/Mt3BDj // Onion : https://www.shadertoy.com/view/MlcBDj // Metric : https://www.shadertoy.com/view/ltcfDj // Combination : https://www.shadertoy.com/view/lt3BW2 // Repetition : https://www.shadertoy.com/view/3syGzz // Extrusion2D : https://www.shadertoy.com/view/4lyfzw // Revolution2D: https://www.shadertoy.com/view/4lyfzw // // More information here: https://iquilezles.org/articles/distfunctions // https://iquilezles.org/articles/distfunctions float sdBox( in vec2 p, in vec2 b ) { vec2 q = abs(p) - b; return min(max(q.x,q.y),0.0) + length(max(q,0.0)); } // the SDF we want to repeat float sdBase( in vec2 p, vec2 id, float sp, in float time ) { float d; if( sin(time/2.0)>0.0 ) { d = sdBox( p, vec2(0.1,0.1)*sp ) - 0.2*sp; } else { if( mod(id.x+id.y,2.0)>0.5 ) d = sdBox( p, vec2(0.2*sp) ); else d = sdBox( p, vec2(0.2,0.02)*sp ) - 0.3*sp; } return d; } // the point of this shader float sdCircularRepetition( in vec2 p, float ra, float sp, float time ) { // make grid vec2 id0 = round(p/sp); // snap to circle if( dot(id0,id0)>ra*ra ) id0 = round(normalize(id0)*ra); // scan neighbors float d = 1e20; for( int j=-2; j<=2; j++ ) // increase this search window for( int i=-2; i<=2; i++ ) // for large values of ra { vec2 id = id0 + vec2(i,j); if( dot(id,id)<=ra*ra ) { vec2 q = p-sp*id; d = min( d, sdBase(q,id,sp,time) ); } } return d; } void mainImage( out vec4 fragColor, in vec2 fragCoord ) { vec2 p = (2.0*fragCoord-iResolution.xy)/iResolution.y; vec2 m = (2.0*iMouse.xy-iResolution.xy)/iResolution.y; float time = iTime + 0.001; // circle radius and cell size, to be tuned for your needs float ra = floor(3.0 + 8.0*(0.5-0.5*cos(time))); float sp = 0.8/ra; // sdf float d = sdCircularRepetition( p, ra, sp, time ); // colorize vec3 col = (d>0.0) ? vec3(0.9,0.6,0.3) : vec3(0.65,0.85,1.0); col *= 1.0 - exp(-32.0*abs(d)); col *= 0.8 + 0.2*cos( 120.0*d); col = mix( col, vec3(1.0), 1.0-smoothstep(0.0,0.009,abs(d)) ); if( iMouse.z>0.001 ) { d = sdCircularRepetition( m, ra, sp, time ); col = mix(col, vec3(1.0,1.0,0.0), 1.0-smoothstep(0.0, 0.005, abs(length(p-m)-abs(d))-0.0025)); col = mix(col, vec3(1.0,1.0,0.0), 1.0-smoothstep(0.0, 0.005, length(p-m)-0.015)); } fragColor = vec4(col,1.0); }
mit
[ 1892, 1921, 1982, 1982, 2267 ]
[ [ 1721, 1770, 1808, 1808, 1890 ], [ 1892, 1921, 1982, 1982, 2267 ], [ 2269, 2297, 2370, 2387, 2862 ], [ 2864, 2864, 2921, 2921, 3811 ] ]
// the SDF we want to repeat
float sdBase( in vec2 p, vec2 id, float sp, in float time ) {
float d; if( sin(time/2.0)>0.0 ) { d = sdBox( p, vec2(0.1,0.1)*sp ) - 0.2*sp; } else { if( mod(id.x+id.y,2.0)>0.5 ) d = sdBox( p, vec2(0.2*sp) ); else d = sdBox( p, vec2(0.2,0.02)*sp ) - 0.3*sp; } return d; }
// the SDF we want to repeat float sdBase( in vec2 p, vec2 id, float sp, in float time ) {
1
1
fdVBDw
iq
2022-07-20T11:43:48
// The MIT License // Copyright © 2022 Inigo Quilez // Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. // Computing the SDF of a limited number of copies of a base // SDF object constrained to a circle. // Related techniques: // // Elongation : https://www.shadertoy.com/view/Ml3fWj // Rounding : https://www.shadertoy.com/view/Mt3BDj // Onion : https://www.shadertoy.com/view/MlcBDj // Metric : https://www.shadertoy.com/view/ltcfDj // Combination : https://www.shadertoy.com/view/lt3BW2 // Repetition : https://www.shadertoy.com/view/3syGzz // Extrusion2D : https://www.shadertoy.com/view/4lyfzw // Revolution2D: https://www.shadertoy.com/view/4lyfzw // // More information here: https://iquilezles.org/articles/distfunctions // https://iquilezles.org/articles/distfunctions float sdBox( in vec2 p, in vec2 b ) { vec2 q = abs(p) - b; return min(max(q.x,q.y),0.0) + length(max(q,0.0)); } // the SDF we want to repeat float sdBase( in vec2 p, vec2 id, float sp, in float time ) { float d; if( sin(time/2.0)>0.0 ) { d = sdBox( p, vec2(0.1,0.1)*sp ) - 0.2*sp; } else { if( mod(id.x+id.y,2.0)>0.5 ) d = sdBox( p, vec2(0.2*sp) ); else d = sdBox( p, vec2(0.2,0.02)*sp ) - 0.3*sp; } return d; } // the point of this shader float sdCircularRepetition( in vec2 p, float ra, float sp, float time ) { // make grid vec2 id0 = round(p/sp); // snap to circle if( dot(id0,id0)>ra*ra ) id0 = round(normalize(id0)*ra); // scan neighbors float d = 1e20; for( int j=-2; j<=2; j++ ) // increase this search window for( int i=-2; i<=2; i++ ) // for large values of ra { vec2 id = id0 + vec2(i,j); if( dot(id,id)<=ra*ra ) { vec2 q = p-sp*id; d = min( d, sdBase(q,id,sp,time) ); } } return d; } void mainImage( out vec4 fragColor, in vec2 fragCoord ) { vec2 p = (2.0*fragCoord-iResolution.xy)/iResolution.y; vec2 m = (2.0*iMouse.xy-iResolution.xy)/iResolution.y; float time = iTime + 0.001; // circle radius and cell size, to be tuned for your needs float ra = floor(3.0 + 8.0*(0.5-0.5*cos(time))); float sp = 0.8/ra; // sdf float d = sdCircularRepetition( p, ra, sp, time ); // colorize vec3 col = (d>0.0) ? vec3(0.9,0.6,0.3) : vec3(0.65,0.85,1.0); col *= 1.0 - exp(-32.0*abs(d)); col *= 0.8 + 0.2*cos( 120.0*d); col = mix( col, vec3(1.0), 1.0-smoothstep(0.0,0.009,abs(d)) ); if( iMouse.z>0.001 ) { d = sdCircularRepetition( m, ra, sp, time ); col = mix(col, vec3(1.0,1.0,0.0), 1.0-smoothstep(0.0, 0.005, abs(length(p-m)-abs(d))-0.0025)); col = mix(col, vec3(1.0,1.0,0.0), 1.0-smoothstep(0.0, 0.005, length(p-m)-0.015)); } fragColor = vec4(col,1.0); }
mit
[ 2269, 2297, 2370, 2387, 2862 ]
[ [ 1721, 1770, 1808, 1808, 1890 ], [ 1892, 1921, 1982, 1982, 2267 ], [ 2269, 2297, 2370, 2387, 2862 ], [ 2864, 2864, 2921, 2921, 3811 ] ]
// the point of this shader
float sdCircularRepetition( in vec2 p, float ra, float sp, float time ) {
vec2 id0 = round(p/sp); // snap to circle if( dot(id0,id0)>ra*ra ) id0 = round(normalize(id0)*ra); // scan neighbors float d = 1e20; for( int j=-2; j<=2; j++ ) // increase this search window for( int i=-2; i<=2; i++ ) // for large values of ra { vec2 id = id0 + vec2(i,j); if( dot(id,id)<=ra*ra ) { vec2 q = p-sp*id; d = min( d, sdBase(q,id,sp,time) ); } } return d; }
// the point of this shader float sdCircularRepetition( in vec2 p, float ra, float sp, float time ) {
1
1
7sGBzw
gehtsiegarnixan
2022-07-16T16:10:01
// The MIT License // Copyright © 2022 Gehtsiegarnixan // Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. /* Simple 3D Cubic Tiling. It looks like triangles and hexagons, because I rotated it a bit. What you see is the Edge Distance. This project contains algorithms for the edge distance, center distance, ID and UVW coordinates of a cubeic honeycomb grid. The caluclation for the cube gird is very fast. I wonder, if this is faster to calculate 3D cubes and rotate them compated to making a 2D triangle grid the normal way. Maybe I'll test that later. */ #define sqrt25 0.6324555320 //sqrt(2./5.) #define sqrt35 0.7745966692 //sqrt(3./5.) //edge distance of a Cube float cubeDist(vec3 uvw) { vec3 d = abs(uvw); //mirroring along axis return max(d.x, max(d.y, d.z))*2.; //*2. for 0-1 range } // Cube Tiling vec4 cubeTile(vec3 uvw) { vec3 grid = fract(uvw)-.5; // centered UVW coords float edist = 1.-cubeDist(grid); // edge distance //float cdist = dot(grid,grid); //squared center distance //vec3 id = uvw-grid; // Cells IDs return vec4(grid, edist); } // scaled with offset cube tiling vec4 cubeCell(vec3 uvw, vec3 offset, float gridRes) { vec4 cubeTiling = cubeTile(uvw*gridRes + offset); vec3 tiledUV = (cubeTiling.xyz - offset)/gridRes; //cube pixaltion return vec4(tiledUV,cubeTiling.w); } // rotates a vetor from SirBelfer4 (https://www.shadertoy.com/view/ssc3z4) vec3 rotate(vec3 v, vec3 a) { // https://math.stackexchange.com/questions/2975109/how-to-convert-euler-angles-to-quaternions-and-get-the-same-euler-angles-back-fr vec4 q; vec3 c = cos(a * 0.5), s = sin(a * 0.5); q.x = s.x * c.y * c.z - c.x * s.y * s.z; q.y = c.x * s.y * c.z + s.x * c.y * s.z; q.z = c.x * c.y * s.z - s.x * s.y * c.z; q.w = c.x * c.y * c.z + s.x * s.y * s.z; // https://blog.molecular-matters.com/2013/05/24/a-faster-quaternion-vector-multiplication/ vec3 qt = 2.0 * cross(q.xyz, v); return v + q.w * qt + cross(q.xyz, qt); } // makes RdYlBu_r colormap with polynimal 6 https://www.shadertoy.com/view/Nd3fR2 vec3 RdYlBu_r(float t) { const vec3 c0 = vec3(0.207621,0.196195,0.618832); const vec3 c1 = vec3(-0.088125,3.196170,-0.353302); const vec3 c2 = vec3(8.261232,-8.366855,14.368787); const vec3 c3 = vec3(-2.922476,33.244294,-43.419173); const vec3 c4 = vec3(-34.085327,-74.476041,37.159352); const vec3 c5 = vec3(50.429790,67.145621,-1.750169); const vec3 c6 = vec3(-21.188828,-20.935464,-6.501427); return c0+t*(c1+t*(c2+t*(c3+t*(c4+t*(c5+t*c6))))); } void mainImage( out vec4 fragColor, in vec2 fragCoord ) { vec2 uv = fragCoord/iResolution.y; //square UV pattern float time = (0.05*iTime); // used as z dimension float gridRes = 2.5; //size of cubes vec3 point = vec3(uv, time); //uvw cords //cosmetic rotate for fun triangles otherwise it looks so square point = rotate(point, (vec3(sqrt25,sqrt35,0.))); //vec3 must be normalized vec4 a = cubeCell(point, vec3(0.), gridRes); vec3 col = RdYlBu_r(a.w); // cosmetic Colormap fragColor = vec4(col, 1.); }
mit
[ 1629, 1655, 1681, 1681, 1788 ]
[ [ 1629, 1655, 1681, 1681, 1788 ], [ 1790, 1805, 1830, 1830, 2072 ], [ 2074, 2108, 2161, 2161, 2332 ], [ 2334, 2409, 2438, 2575, 2996 ], [ 2998, 3080, 3104, 3104, 3560 ], [ 3562, 3562, 3619, 3619, 4128 ] ]
//edge distance of a Cube
float cubeDist(vec3 uvw) {
vec3 d = abs(uvw); //mirroring along axis return max(d.x, max(d.y, d.z))*2.; //*2. for 0-1 range }
//edge distance of a Cube float cubeDist(vec3 uvw) {
1
1
7sGBzw
gehtsiegarnixan
2022-07-16T16:10:01
// The MIT License // Copyright © 2022 Gehtsiegarnixan // Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. /* Simple 3D Cubic Tiling. It looks like triangles and hexagons, because I rotated it a bit. What you see is the Edge Distance. This project contains algorithms for the edge distance, center distance, ID and UVW coordinates of a cubeic honeycomb grid. The caluclation for the cube gird is very fast. I wonder, if this is faster to calculate 3D cubes and rotate them compated to making a 2D triangle grid the normal way. Maybe I'll test that later. */ #define sqrt25 0.6324555320 //sqrt(2./5.) #define sqrt35 0.7745966692 //sqrt(3./5.) //edge distance of a Cube float cubeDist(vec3 uvw) { vec3 d = abs(uvw); //mirroring along axis return max(d.x, max(d.y, d.z))*2.; //*2. for 0-1 range } // Cube Tiling vec4 cubeTile(vec3 uvw) { vec3 grid = fract(uvw)-.5; // centered UVW coords float edist = 1.-cubeDist(grid); // edge distance //float cdist = dot(grid,grid); //squared center distance //vec3 id = uvw-grid; // Cells IDs return vec4(grid, edist); } // scaled with offset cube tiling vec4 cubeCell(vec3 uvw, vec3 offset, float gridRes) { vec4 cubeTiling = cubeTile(uvw*gridRes + offset); vec3 tiledUV = (cubeTiling.xyz - offset)/gridRes; //cube pixaltion return vec4(tiledUV,cubeTiling.w); } // rotates a vetor from SirBelfer4 (https://www.shadertoy.com/view/ssc3z4) vec3 rotate(vec3 v, vec3 a) { // https://math.stackexchange.com/questions/2975109/how-to-convert-euler-angles-to-quaternions-and-get-the-same-euler-angles-back-fr vec4 q; vec3 c = cos(a * 0.5), s = sin(a * 0.5); q.x = s.x * c.y * c.z - c.x * s.y * s.z; q.y = c.x * s.y * c.z + s.x * c.y * s.z; q.z = c.x * c.y * s.z - s.x * s.y * c.z; q.w = c.x * c.y * c.z + s.x * s.y * s.z; // https://blog.molecular-matters.com/2013/05/24/a-faster-quaternion-vector-multiplication/ vec3 qt = 2.0 * cross(q.xyz, v); return v + q.w * qt + cross(q.xyz, qt); } // makes RdYlBu_r colormap with polynimal 6 https://www.shadertoy.com/view/Nd3fR2 vec3 RdYlBu_r(float t) { const vec3 c0 = vec3(0.207621,0.196195,0.618832); const vec3 c1 = vec3(-0.088125,3.196170,-0.353302); const vec3 c2 = vec3(8.261232,-8.366855,14.368787); const vec3 c3 = vec3(-2.922476,33.244294,-43.419173); const vec3 c4 = vec3(-34.085327,-74.476041,37.159352); const vec3 c5 = vec3(50.429790,67.145621,-1.750169); const vec3 c6 = vec3(-21.188828,-20.935464,-6.501427); return c0+t*(c1+t*(c2+t*(c3+t*(c4+t*(c5+t*c6))))); } void mainImage( out vec4 fragColor, in vec2 fragCoord ) { vec2 uv = fragCoord/iResolution.y; //square UV pattern float time = (0.05*iTime); // used as z dimension float gridRes = 2.5; //size of cubes vec3 point = vec3(uv, time); //uvw cords //cosmetic rotate for fun triangles otherwise it looks so square point = rotate(point, (vec3(sqrt25,sqrt35,0.))); //vec3 must be normalized vec4 a = cubeCell(point, vec3(0.), gridRes); vec3 col = RdYlBu_r(a.w); // cosmetic Colormap fragColor = vec4(col, 1.); }
mit
[ 1790, 1805, 1830, 1830, 2072 ]
[ [ 1629, 1655, 1681, 1681, 1788 ], [ 1790, 1805, 1830, 1830, 2072 ], [ 2074, 2108, 2161, 2161, 2332 ], [ 2334, 2409, 2438, 2575, 2996 ], [ 2998, 3080, 3104, 3104, 3560 ], [ 3562, 3562, 3619, 3619, 4128 ] ]
// Cube Tiling
vec4 cubeTile(vec3 uvw) {
vec3 grid = fract(uvw)-.5; // centered UVW coords float edist = 1.-cubeDist(grid); // edge distance //float cdist = dot(grid,grid); //squared center distance //vec3 id = uvw-grid; // Cells IDs return vec4(grid, edist); }
// Cube Tiling vec4 cubeTile(vec3 uvw) {
1
1
7sGBzw
gehtsiegarnixan
2022-07-16T16:10:01
// The MIT License // Copyright © 2022 Gehtsiegarnixan // Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. /* Simple 3D Cubic Tiling. It looks like triangles and hexagons, because I rotated it a bit. What you see is the Edge Distance. This project contains algorithms for the edge distance, center distance, ID and UVW coordinates of a cubeic honeycomb grid. The caluclation for the cube gird is very fast. I wonder, if this is faster to calculate 3D cubes and rotate them compated to making a 2D triangle grid the normal way. Maybe I'll test that later. */ #define sqrt25 0.6324555320 //sqrt(2./5.) #define sqrt35 0.7745966692 //sqrt(3./5.) //edge distance of a Cube float cubeDist(vec3 uvw) { vec3 d = abs(uvw); //mirroring along axis return max(d.x, max(d.y, d.z))*2.; //*2. for 0-1 range } // Cube Tiling vec4 cubeTile(vec3 uvw) { vec3 grid = fract(uvw)-.5; // centered UVW coords float edist = 1.-cubeDist(grid); // edge distance //float cdist = dot(grid,grid); //squared center distance //vec3 id = uvw-grid; // Cells IDs return vec4(grid, edist); } // scaled with offset cube tiling vec4 cubeCell(vec3 uvw, vec3 offset, float gridRes) { vec4 cubeTiling = cubeTile(uvw*gridRes + offset); vec3 tiledUV = (cubeTiling.xyz - offset)/gridRes; //cube pixaltion return vec4(tiledUV,cubeTiling.w); } // rotates a vetor from SirBelfer4 (https://www.shadertoy.com/view/ssc3z4) vec3 rotate(vec3 v, vec3 a) { // https://math.stackexchange.com/questions/2975109/how-to-convert-euler-angles-to-quaternions-and-get-the-same-euler-angles-back-fr vec4 q; vec3 c = cos(a * 0.5), s = sin(a * 0.5); q.x = s.x * c.y * c.z - c.x * s.y * s.z; q.y = c.x * s.y * c.z + s.x * c.y * s.z; q.z = c.x * c.y * s.z - s.x * s.y * c.z; q.w = c.x * c.y * c.z + s.x * s.y * s.z; // https://blog.molecular-matters.com/2013/05/24/a-faster-quaternion-vector-multiplication/ vec3 qt = 2.0 * cross(q.xyz, v); return v + q.w * qt + cross(q.xyz, qt); } // makes RdYlBu_r colormap with polynimal 6 https://www.shadertoy.com/view/Nd3fR2 vec3 RdYlBu_r(float t) { const vec3 c0 = vec3(0.207621,0.196195,0.618832); const vec3 c1 = vec3(-0.088125,3.196170,-0.353302); const vec3 c2 = vec3(8.261232,-8.366855,14.368787); const vec3 c3 = vec3(-2.922476,33.244294,-43.419173); const vec3 c4 = vec3(-34.085327,-74.476041,37.159352); const vec3 c5 = vec3(50.429790,67.145621,-1.750169); const vec3 c6 = vec3(-21.188828,-20.935464,-6.501427); return c0+t*(c1+t*(c2+t*(c3+t*(c4+t*(c5+t*c6))))); } void mainImage( out vec4 fragColor, in vec2 fragCoord ) { vec2 uv = fragCoord/iResolution.y; //square UV pattern float time = (0.05*iTime); // used as z dimension float gridRes = 2.5; //size of cubes vec3 point = vec3(uv, time); //uvw cords //cosmetic rotate for fun triangles otherwise it looks so square point = rotate(point, (vec3(sqrt25,sqrt35,0.))); //vec3 must be normalized vec4 a = cubeCell(point, vec3(0.), gridRes); vec3 col = RdYlBu_r(a.w); // cosmetic Colormap fragColor = vec4(col, 1.); }
mit
[ 2074, 2108, 2161, 2161, 2332 ]
[ [ 1629, 1655, 1681, 1681, 1788 ], [ 1790, 1805, 1830, 1830, 2072 ], [ 2074, 2108, 2161, 2161, 2332 ], [ 2334, 2409, 2438, 2575, 2996 ], [ 2998, 3080, 3104, 3104, 3560 ], [ 3562, 3562, 3619, 3619, 4128 ] ]
// scaled with offset cube tiling
vec4 cubeCell(vec3 uvw, vec3 offset, float gridRes) {
vec4 cubeTiling = cubeTile(uvw*gridRes + offset); vec3 tiledUV = (cubeTiling.xyz - offset)/gridRes; //cube pixaltion return vec4(tiledUV,cubeTiling.w); }
// scaled with offset cube tiling vec4 cubeCell(vec3 uvw, vec3 offset, float gridRes) {
1
1
7sGBzw
gehtsiegarnixan
2022-07-16T16:10:01
// The MIT License // Copyright © 2022 Gehtsiegarnixan // Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. /* Simple 3D Cubic Tiling. It looks like triangles and hexagons, because I rotated it a bit. What you see is the Edge Distance. This project contains algorithms for the edge distance, center distance, ID and UVW coordinates of a cubeic honeycomb grid. The caluclation for the cube gird is very fast. I wonder, if this is faster to calculate 3D cubes and rotate them compated to making a 2D triangle grid the normal way. Maybe I'll test that later. */ #define sqrt25 0.6324555320 //sqrt(2./5.) #define sqrt35 0.7745966692 //sqrt(3./5.) //edge distance of a Cube float cubeDist(vec3 uvw) { vec3 d = abs(uvw); //mirroring along axis return max(d.x, max(d.y, d.z))*2.; //*2. for 0-1 range } // Cube Tiling vec4 cubeTile(vec3 uvw) { vec3 grid = fract(uvw)-.5; // centered UVW coords float edist = 1.-cubeDist(grid); // edge distance //float cdist = dot(grid,grid); //squared center distance //vec3 id = uvw-grid; // Cells IDs return vec4(grid, edist); } // scaled with offset cube tiling vec4 cubeCell(vec3 uvw, vec3 offset, float gridRes) { vec4 cubeTiling = cubeTile(uvw*gridRes + offset); vec3 tiledUV = (cubeTiling.xyz - offset)/gridRes; //cube pixaltion return vec4(tiledUV,cubeTiling.w); } // rotates a vetor from SirBelfer4 (https://www.shadertoy.com/view/ssc3z4) vec3 rotate(vec3 v, vec3 a) { // https://math.stackexchange.com/questions/2975109/how-to-convert-euler-angles-to-quaternions-and-get-the-same-euler-angles-back-fr vec4 q; vec3 c = cos(a * 0.5), s = sin(a * 0.5); q.x = s.x * c.y * c.z - c.x * s.y * s.z; q.y = c.x * s.y * c.z + s.x * c.y * s.z; q.z = c.x * c.y * s.z - s.x * s.y * c.z; q.w = c.x * c.y * c.z + s.x * s.y * s.z; // https://blog.molecular-matters.com/2013/05/24/a-faster-quaternion-vector-multiplication/ vec3 qt = 2.0 * cross(q.xyz, v); return v + q.w * qt + cross(q.xyz, qt); } // makes RdYlBu_r colormap with polynimal 6 https://www.shadertoy.com/view/Nd3fR2 vec3 RdYlBu_r(float t) { const vec3 c0 = vec3(0.207621,0.196195,0.618832); const vec3 c1 = vec3(-0.088125,3.196170,-0.353302); const vec3 c2 = vec3(8.261232,-8.366855,14.368787); const vec3 c3 = vec3(-2.922476,33.244294,-43.419173); const vec3 c4 = vec3(-34.085327,-74.476041,37.159352); const vec3 c5 = vec3(50.429790,67.145621,-1.750169); const vec3 c6 = vec3(-21.188828,-20.935464,-6.501427); return c0+t*(c1+t*(c2+t*(c3+t*(c4+t*(c5+t*c6))))); } void mainImage( out vec4 fragColor, in vec2 fragCoord ) { vec2 uv = fragCoord/iResolution.y; //square UV pattern float time = (0.05*iTime); // used as z dimension float gridRes = 2.5; //size of cubes vec3 point = vec3(uv, time); //uvw cords //cosmetic rotate for fun triangles otherwise it looks so square point = rotate(point, (vec3(sqrt25,sqrt35,0.))); //vec3 must be normalized vec4 a = cubeCell(point, vec3(0.), gridRes); vec3 col = RdYlBu_r(a.w); // cosmetic Colormap fragColor = vec4(col, 1.); }
mit
[ 2998, 3080, 3104, 3104, 3560 ]
[ [ 1629, 1655, 1681, 1681, 1788 ], [ 1790, 1805, 1830, 1830, 2072 ], [ 2074, 2108, 2161, 2161, 2332 ], [ 2334, 2409, 2438, 2575, 2996 ], [ 2998, 3080, 3104, 3104, 3560 ], [ 3562, 3562, 3619, 3619, 4128 ] ]
// makes RdYlBu_r colormap with polynimal 6 https://www.shadertoy.com/view/Nd3fR2
vec3 RdYlBu_r(float t) {
const vec3 c0 = vec3(0.207621,0.196195,0.618832); const vec3 c1 = vec3(-0.088125,3.196170,-0.353302); const vec3 c2 = vec3(8.261232,-8.366855,14.368787); const vec3 c3 = vec3(-2.922476,33.244294,-43.419173); const vec3 c4 = vec3(-34.085327,-74.476041,37.159352); const vec3 c5 = vec3(50.429790,67.145621,-1.750169); const vec3 c6 = vec3(-21.188828,-20.935464,-6.501427); return c0+t*(c1+t*(c2+t*(c3+t*(c4+t*(c5+t*c6))))); }
// makes RdYlBu_r colormap with polynimal 6 https://www.shadertoy.com/view/Nd3fR2 vec3 RdYlBu_r(float t) {
2
2
ssKfRw
gehtsiegarnixan
2022-07-15T14:57:00
// The MIT License // Copyright © 2022 Gehtsiegarnixan // Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. /* I made this simple edge distance function for the Cuboctahedron. It's basically a cube with cut of corners. It has mouse controls to rotated around the center. This shape is one of the two shapes best for close packing of spheres (FCC). This shape is not part of the Honeycomb group, so it doesn't tile seamlessly. */ #define pi 3.1415926536 //Distance from the Edge of Cuboctahedron float cubocDist(vec3 p) { vec3 hra = vec3(0.5); //vector to Diagonal Edge p = abs(p); float pAB = max(p.x,p.y); //rigt and left edge float pCD = max(dot(p, hra),p.z); //diagonal and top edge float pABCD = max(pAB, pCD); //optional 0-1 range return (.5-pABCD)*2.; } // makes winter colormap with polynimal 6 vec3 winter(float t) { const vec3 c0 = vec3(-0.000000,-0.000941,1.000471); const vec3 c1 = vec3(0.000000,1.001170,-0.500585); const vec3 c2 = vec3(-0.000000,0.004744,-0.002369); const vec3 c3 = vec3(0.000000,-0.011841,0.005901); const vec3 c4 = vec3(-0.000000,0.012964,-0.006433); const vec3 c5 = vec3(0.000000,-0.005110,0.002500); const vec3 c6 = vec3(-0.000000,-0.000046,0.000045); return c0+t*(c1+t*(c2+t*(c3+t*(c4+t*(c5+t*c6))))); } // rotates a vetor from SirBelfer4 (https://www.shadertoy.com/view/ssc3z4) vec3 rotate(vec3 v, vec3 a) { // https://math.stackexchange.com/questions/2975109/how-to-convert-euler-angles-to-quaternions-and-get-the-same-euler-angles-back-fr vec4 q; vec3 c = cos(a * 0.5), s = sin(a * 0.5); q.x = s.x * c.y * c.z - c.x * s.y * s.z; q.y = c.x * s.y * c.z + s.x * c.y * s.z; q.z = c.x * c.y * s.z - s.x * s.y * c.z; q.w = c.x * c.y * c.z + s.x * s.y * s.z; // https://blog.molecular-matters.com/2013/05/24/a-faster-quaternion-vector-multiplication/ vec3 qt = 2.0 * cross(q.xyz, v); return v + q.w * qt + cross(q.xyz, qt); } void mainImage( out vec4 fragColor, in vec2 fragCoord ) { vec2 uv = (fragCoord - iResolution.xy*.5)/iResolution.y; //centered square UVs float time = fract(0.2*iTime-0.5)-0.5; // used as z dimension float size = 0.9; //size of Ico vec3 point = vec3(uv, time)/size; //animated uv cords // controls rotates around the center vec3 camRot = vec3(0.5 - iMouse.yx / iResolution.yx, 0) * 2.0 * pi; camRot.y = -camRot.y; point = rotate(point, camRot); float ico = cubocDist(point); ico = clamp(ico, 0.,1.); //saturate so the cmap doesn't break vec3 col = winter(1.-ico); // applying cosmetic colormap fragColor = vec4(col,0); }
mit
[ 1445, 1487, 1512, 1512, 1796 ]
[ [ 1445, 1487, 1512, 1512, 1796 ], [ 1798, 1840, 1862, 1862, 2308 ], [ 2310, 2385, 2414, 2551, 2972 ], [ 2974, 2974, 3031, 3031, 3675 ] ]
//Distance from the Edge of Cuboctahedron
float cubocDist(vec3 p) {
vec3 hra = vec3(0.5); //vector to Diagonal Edge p = abs(p); float pAB = max(p.x,p.y); //rigt and left edge float pCD = max(dot(p, hra),p.z); //diagonal and top edge float pABCD = max(pAB, pCD); //optional 0-1 range return (.5-pABCD)*2.; }
//Distance from the Edge of Cuboctahedron float cubocDist(vec3 p) {
1
1
ssKfRw
gehtsiegarnixan
2022-07-15T14:57:00
// The MIT License // Copyright © 2022 Gehtsiegarnixan // Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. /* I made this simple edge distance function for the Cuboctahedron. It's basically a cube with cut of corners. It has mouse controls to rotated around the center. This shape is one of the two shapes best for close packing of spheres (FCC). This shape is not part of the Honeycomb group, so it doesn't tile seamlessly. */ #define pi 3.1415926536 //Distance from the Edge of Cuboctahedron float cubocDist(vec3 p) { vec3 hra = vec3(0.5); //vector to Diagonal Edge p = abs(p); float pAB = max(p.x,p.y); //rigt and left edge float pCD = max(dot(p, hra),p.z); //diagonal and top edge float pABCD = max(pAB, pCD); //optional 0-1 range return (.5-pABCD)*2.; } // makes winter colormap with polynimal 6 vec3 winter(float t) { const vec3 c0 = vec3(-0.000000,-0.000941,1.000471); const vec3 c1 = vec3(0.000000,1.001170,-0.500585); const vec3 c2 = vec3(-0.000000,0.004744,-0.002369); const vec3 c3 = vec3(0.000000,-0.011841,0.005901); const vec3 c4 = vec3(-0.000000,0.012964,-0.006433); const vec3 c5 = vec3(0.000000,-0.005110,0.002500); const vec3 c6 = vec3(-0.000000,-0.000046,0.000045); return c0+t*(c1+t*(c2+t*(c3+t*(c4+t*(c5+t*c6))))); } // rotates a vetor from SirBelfer4 (https://www.shadertoy.com/view/ssc3z4) vec3 rotate(vec3 v, vec3 a) { // https://math.stackexchange.com/questions/2975109/how-to-convert-euler-angles-to-quaternions-and-get-the-same-euler-angles-back-fr vec4 q; vec3 c = cos(a * 0.5), s = sin(a * 0.5); q.x = s.x * c.y * c.z - c.x * s.y * s.z; q.y = c.x * s.y * c.z + s.x * c.y * s.z; q.z = c.x * c.y * s.z - s.x * s.y * c.z; q.w = c.x * c.y * c.z + s.x * s.y * s.z; // https://blog.molecular-matters.com/2013/05/24/a-faster-quaternion-vector-multiplication/ vec3 qt = 2.0 * cross(q.xyz, v); return v + q.w * qt + cross(q.xyz, qt); } void mainImage( out vec4 fragColor, in vec2 fragCoord ) { vec2 uv = (fragCoord - iResolution.xy*.5)/iResolution.y; //centered square UVs float time = fract(0.2*iTime-0.5)-0.5; // used as z dimension float size = 0.9; //size of Ico vec3 point = vec3(uv, time)/size; //animated uv cords // controls rotates around the center vec3 camRot = vec3(0.5 - iMouse.yx / iResolution.yx, 0) * 2.0 * pi; camRot.y = -camRot.y; point = rotate(point, camRot); float ico = cubocDist(point); ico = clamp(ico, 0.,1.); //saturate so the cmap doesn't break vec3 col = winter(1.-ico); // applying cosmetic colormap fragColor = vec4(col,0); }
mit
[ 1798, 1840, 1862, 1862, 2308 ]
[ [ 1445, 1487, 1512, 1512, 1796 ], [ 1798, 1840, 1862, 1862, 2308 ], [ 2310, 2385, 2414, 2551, 2972 ], [ 2974, 2974, 3031, 3031, 3675 ] ]
// makes winter colormap with polynimal 6
vec3 winter(float t) {
const vec3 c0 = vec3(-0.000000,-0.000941,1.000471); const vec3 c1 = vec3(0.000000,1.001170,-0.500585); const vec3 c2 = vec3(-0.000000,0.004744,-0.002369); const vec3 c3 = vec3(0.000000,-0.011841,0.005901); const vec3 c4 = vec3(-0.000000,0.012964,-0.006433); const vec3 c5 = vec3(0.000000,-0.005110,0.002500); const vec3 c6 = vec3(-0.000000,-0.000046,0.000045); return c0+t*(c1+t*(c2+t*(c3+t*(c4+t*(c5+t*c6))))); }
// makes winter colormap with polynimal 6 vec3 winter(float t) {
1
1
7ddBWl
gehtsiegarnixan
2022-07-10T18:45:29
// The MIT License // Copyright © 2022 Gehtsiegarnixan // Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. /* This is using my Square Directional Flow algorithm (https://www.shadertoy.com/view/7dtBWl) with Sine waves instead of a texture. I also made a flowmap that is an aproximation of a tropical cyclone flowmap (https://www.shadertoy.com/view/fdKcWd). I wanted to aproximate the water wave height. I looked up the forumlas for the relationship between windspeed and waves, but the math is very complicated and I gave up. So I went for what looks alright (https://www.desmos.com/calculator/lewikf6y0f). The easy water wave math can be found here (https://en.wikipedia.org/wiki/Dispersion_(water_waves)). Wikipeda explains the relationship between water depth, wavelength and wave velocity (https://www.desmos.com/calculator/2nlmht2mmy). The amplitude and windspeed don't have such linear interaction, but there are formuals for observed wave spectra on the ocean after long periods of steady wind (https://wikiwaves.org/Ocean-Wave_Spectra). I just can not figure out how to solve for the wavespeed/wavelength for a give depth and windspeed. A single wave can be described by the gerstner formula (https://catlikecoding.com/unity/tutorials/flow/waves/), but I couldn't find how the wind affects the wave steepness and when exactly they break on the open sea. I found some hints here (http://hyperphysics.phy-astr.gsu.edu/hbase/Waves/watwav2.html) when they break. Animating the flowmap also turned out to have some significant drawbacks. Since im sampling a lower res hexagonal version leads to flickering waves, so you can only do it VERY slowly. */ #define pi 3.1415926536 #define sqrtG 3.1320919527 #define twoPi 6.2831853072 // makes viridis colormap with polynimal 6 https://www.shadertoy.com/view/Nd3fR2 vec3 viridis(float t) { const vec3 c0 = vec3(0.274344,0.004462,0.331359); const vec3 c1 = vec3(0.108915,1.397291,1.388110); const vec3 c2 = vec3(-0.319631,0.243490,0.156419); const vec3 c3 = vec3(-4.629188,-5.882803,-19.646115); const vec3 c4 = vec3(6.181719,14.388598,57.442181); const vec3 c5 = vec3(4.876952,-13.955112,-66.125783); const vec3 c6 = vec3(-5.513165,4.709245,26.582180); return c0+t*(c1+t*(c2+t*(c3+t*(c4+t*(c5+t*c6))))); } //shifts value range from -1-1 to 0-1 float make0to1(float x) { return (1.0 + x) / 2.0; } //shifts value range from 0-1 to -1-1 vec2 makeM1to1(vec2 x) { return (x - 0.5) * 2.0; } // makes a simple flowmap of a cyclone vec2 cycloneFlow(vec2 point, float radius, float time) { float size = 1./(1.4 * sqrt(radius)); // of the entire cyclone float curl = 2.5; // kind of arbitrary but between 1-3.5 looks good float hole = 1./(4.*size); // also kind of arbitrary //point += vec2(cos(time),sin(time))*0.1*hole; //rotating center float angle = atan(point.y, point.x); //angle around center float dist = length(point); // distance to point float spiral = fract(dist/radius + (angle-time)/twoPi); //right slanted donut https://www.desmos.com/calculator/ocm71awnym spiral -= 1.212; spiral = 1.+ (pow(1.57*(spiral)+0.8,2.)/spiral); float flowAngle = pi + angle -(dist*curl) -(spiral*0.8); // left slanted donut https://www.desmos.com/calculator/uxyefly7fi float spiralStrength = 0.05; float mask = (1. - spiralStrength)-(pow(dist*size-hole, 2.0)/dist); mask += spiral*spiralStrength; mask = clamp(mask, 0.0, 1.0); // saturate vec2 flow = normalize(vec2(cos(flowAngle),sin(flowAngle))); flow *= mask; // apply strength mask //flow = (flow+1.0)/2.0; // to save as texture flow += vec2(0.0001,0.0001); //adding tiny offset so it isnt 0 return flow; } // simple square Tiling vec3 squareTile(vec2 uv) { vec2 grid = fract(uv)-.5; //UV centered on cell vec2 d = abs(grid); float eDist = (0.5-max(d.x, d.y))*2.; //Edge Distance vec2 id = uv - grid; //ID values return vec3(id, eDist); } //rhombic shape form Manhattan distance vec3 rhomTile(vec2 uv) { vec2 a = fract(uv- vec2(.0, .5))-.5; vec2 b = fract(uv- vec2(.5, .0))-.5; vec2 aa = abs(a); float mDist = (aa.x + aa.y -.5); vec2 grid = mDist < 0. ? a : b; //UV coords float eDist = abs(mDist)*2.; //Edge Distance vec2 id = uv - grid; //ID values return vec3(id, eDist); } // nakes a square pixelized pattern vec3 squarePixelizor(vec2 uv, float gridRes, vec2 offset) { vec3 sTiling = squareTile(uv*gridRes + offset); vec2 tiledUV = (sTiling.xy - offset)/gridRes; //pixaltion return vec3(tiledUV, sTiling.z); } // nakes a rhombic pixelized pattern vec3 rhomPixelizor(vec2 uv, float gridRes) { vec3 rTiling = rhomTile(uv*gridRes); vec2 tiledUV = (rTiling.xy)/gridRes; //pixaltion return vec3(tiledUV, rTiling.z); } float sinWave(vec2 uv, vec2 tiledUV, float time, float alpha, float len) { float radius = 0.3; // of the first spiral //cyclone like flowmap vec2 flowMap = cycloneFlow(tiledUV - vec2(0.885, 0.5), radius, time*0.2); float speed = length(flowMap); // Wind Speed vec2 dir = normalize(flowMap); // Wind Direction len *= pow(speed,0.5); // make slower waves smaller float k = twoPi / len; //Wave Number float a = pow(speed,1.5); //Amplitude float s = speed; //Steepness time *= sqrtG * sqrt(len); // deep water speed float dD = dot(uv,dir); //Directional/Straight Wave //add random phase offsets for even FlowMaps or you get interference //time += texture( iChannel0, tiledUV).x; float wave = make0to1(sin(k * (dD - time))); // make sin wave //wave = (1.- pow(wave, (1.-s/2.))); //cheap gerstner height wave aprox wave *= a * alpha; // apply amplitue and alpha mask return wave; } // generates pixelated directional waves float flowSquareCell(vec2 uv, vec2 offset, float gridRes, float time, float len) { vec3 pix = squarePixelizor(uv, gridRes, offset); return sinWave(uv, pix.xy, time, pix.z, len); } // generates pixelated directional waves float flowRhomCell(vec2 uv, float gridRes, float time, float len) { vec3 pix = rhomPixelizor(uv, gridRes); return sinWave(uv, pix.xy, time, pix.z, len); } // 3 hex pixaled flowing sin thier edges get hidden by each other float triDirectionalFlow(vec2 uv, float gridRes, float time, float len) { float a = flowSquareCell(uv, vec2(0.,0.), gridRes, time, len); float b = flowSquareCell(uv, vec2(0.5), gridRes, time, len); float c = flowRhomCell(uv, gridRes, time, len); return a + b + c; } void mainImage( out vec4 fragColor, in vec2 fragCoord ) { float gridRes = 32.0; //Hex Grid Resolution float waveLen = 1./ (gridRes * 3.0); // Maximum Sin Wave Length float time = iTime * 0.05; // flow speed multiplier vec2 uv = fragCoord/iResolution.y; //centered square UVs float wave = triDirectionalFlow(uv,gridRes,time, waveLen); vec3 col = vec3(viridis(wave)); fragColor = vec4(col,1); }
mit
[ 4782, 4806, 4832, 4832, 5052 ]
[ [ 2752, 2833, 2856, 2856, 3304 ], [ 3306, 3344, 3369, 3369, 3399 ], [ 3401, 3439, 3463, 3463, 3493 ], [ 3495, 3534, 3590, 3590, 4780 ], [ 4782, 4806, 4832, 4832, 5052 ], [ 5054, 5094, 5118, 5118, 5446 ], [ 5448, 5484, 5543, 5543, 5700 ], [ 5702, 5739, 5783, 5783, 5920 ], [ 5922, 5922, 5996, 5996, 6909 ], [ 6911, 6952, 7034, 7034, 7147 ], [ 7149, 7190, 7257, 7257, 7360 ], [ 7362, 7428, 7501, 7501, 7710 ], [ 7712, 7712, 7769, 7769, 8144 ] ]
// simple square Tiling
vec3 squareTile(vec2 uv) {
vec2 grid = fract(uv)-.5; //UV centered on cell vec2 d = abs(grid); float eDist = (0.5-max(d.x, d.y))*2.; //Edge Distance vec2 id = uv - grid; //ID values return vec3(id, eDist); }
// simple square Tiling vec3 squareTile(vec2 uv) {
1
1
7ddBWl
gehtsiegarnixan
2022-07-10T18:45:29
// The MIT License // Copyright © 2022 Gehtsiegarnixan // Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. /* This is using my Square Directional Flow algorithm (https://www.shadertoy.com/view/7dtBWl) with Sine waves instead of a texture. I also made a flowmap that is an aproximation of a tropical cyclone flowmap (https://www.shadertoy.com/view/fdKcWd). I wanted to aproximate the water wave height. I looked up the forumlas for the relationship between windspeed and waves, but the math is very complicated and I gave up. So I went for what looks alright (https://www.desmos.com/calculator/lewikf6y0f). The easy water wave math can be found here (https://en.wikipedia.org/wiki/Dispersion_(water_waves)). Wikipeda explains the relationship between water depth, wavelength and wave velocity (https://www.desmos.com/calculator/2nlmht2mmy). The amplitude and windspeed don't have such linear interaction, but there are formuals for observed wave spectra on the ocean after long periods of steady wind (https://wikiwaves.org/Ocean-Wave_Spectra). I just can not figure out how to solve for the wavespeed/wavelength for a give depth and windspeed. A single wave can be described by the gerstner formula (https://catlikecoding.com/unity/tutorials/flow/waves/), but I couldn't find how the wind affects the wave steepness and when exactly they break on the open sea. I found some hints here (http://hyperphysics.phy-astr.gsu.edu/hbase/Waves/watwav2.html) when they break. Animating the flowmap also turned out to have some significant drawbacks. Since im sampling a lower res hexagonal version leads to flickering waves, so you can only do it VERY slowly. */ #define pi 3.1415926536 #define sqrtG 3.1320919527 #define twoPi 6.2831853072 // makes viridis colormap with polynimal 6 https://www.shadertoy.com/view/Nd3fR2 vec3 viridis(float t) { const vec3 c0 = vec3(0.274344,0.004462,0.331359); const vec3 c1 = vec3(0.108915,1.397291,1.388110); const vec3 c2 = vec3(-0.319631,0.243490,0.156419); const vec3 c3 = vec3(-4.629188,-5.882803,-19.646115); const vec3 c4 = vec3(6.181719,14.388598,57.442181); const vec3 c5 = vec3(4.876952,-13.955112,-66.125783); const vec3 c6 = vec3(-5.513165,4.709245,26.582180); return c0+t*(c1+t*(c2+t*(c3+t*(c4+t*(c5+t*c6))))); } //shifts value range from -1-1 to 0-1 float make0to1(float x) { return (1.0 + x) / 2.0; } //shifts value range from 0-1 to -1-1 vec2 makeM1to1(vec2 x) { return (x - 0.5) * 2.0; } // makes a simple flowmap of a cyclone vec2 cycloneFlow(vec2 point, float radius, float time) { float size = 1./(1.4 * sqrt(radius)); // of the entire cyclone float curl = 2.5; // kind of arbitrary but between 1-3.5 looks good float hole = 1./(4.*size); // also kind of arbitrary //point += vec2(cos(time),sin(time))*0.1*hole; //rotating center float angle = atan(point.y, point.x); //angle around center float dist = length(point); // distance to point float spiral = fract(dist/radius + (angle-time)/twoPi); //right slanted donut https://www.desmos.com/calculator/ocm71awnym spiral -= 1.212; spiral = 1.+ (pow(1.57*(spiral)+0.8,2.)/spiral); float flowAngle = pi + angle -(dist*curl) -(spiral*0.8); // left slanted donut https://www.desmos.com/calculator/uxyefly7fi float spiralStrength = 0.05; float mask = (1. - spiralStrength)-(pow(dist*size-hole, 2.0)/dist); mask += spiral*spiralStrength; mask = clamp(mask, 0.0, 1.0); // saturate vec2 flow = normalize(vec2(cos(flowAngle),sin(flowAngle))); flow *= mask; // apply strength mask //flow = (flow+1.0)/2.0; // to save as texture flow += vec2(0.0001,0.0001); //adding tiny offset so it isnt 0 return flow; } // simple square Tiling vec3 squareTile(vec2 uv) { vec2 grid = fract(uv)-.5; //UV centered on cell vec2 d = abs(grid); float eDist = (0.5-max(d.x, d.y))*2.; //Edge Distance vec2 id = uv - grid; //ID values return vec3(id, eDist); } //rhombic shape form Manhattan distance vec3 rhomTile(vec2 uv) { vec2 a = fract(uv- vec2(.0, .5))-.5; vec2 b = fract(uv- vec2(.5, .0))-.5; vec2 aa = abs(a); float mDist = (aa.x + aa.y -.5); vec2 grid = mDist < 0. ? a : b; //UV coords float eDist = abs(mDist)*2.; //Edge Distance vec2 id = uv - grid; //ID values return vec3(id, eDist); } // nakes a square pixelized pattern vec3 squarePixelizor(vec2 uv, float gridRes, vec2 offset) { vec3 sTiling = squareTile(uv*gridRes + offset); vec2 tiledUV = (sTiling.xy - offset)/gridRes; //pixaltion return vec3(tiledUV, sTiling.z); } // nakes a rhombic pixelized pattern vec3 rhomPixelizor(vec2 uv, float gridRes) { vec3 rTiling = rhomTile(uv*gridRes); vec2 tiledUV = (rTiling.xy)/gridRes; //pixaltion return vec3(tiledUV, rTiling.z); } float sinWave(vec2 uv, vec2 tiledUV, float time, float alpha, float len) { float radius = 0.3; // of the first spiral //cyclone like flowmap vec2 flowMap = cycloneFlow(tiledUV - vec2(0.885, 0.5), radius, time*0.2); float speed = length(flowMap); // Wind Speed vec2 dir = normalize(flowMap); // Wind Direction len *= pow(speed,0.5); // make slower waves smaller float k = twoPi / len; //Wave Number float a = pow(speed,1.5); //Amplitude float s = speed; //Steepness time *= sqrtG * sqrt(len); // deep water speed float dD = dot(uv,dir); //Directional/Straight Wave //add random phase offsets for even FlowMaps or you get interference //time += texture( iChannel0, tiledUV).x; float wave = make0to1(sin(k * (dD - time))); // make sin wave //wave = (1.- pow(wave, (1.-s/2.))); //cheap gerstner height wave aprox wave *= a * alpha; // apply amplitue and alpha mask return wave; } // generates pixelated directional waves float flowSquareCell(vec2 uv, vec2 offset, float gridRes, float time, float len) { vec3 pix = squarePixelizor(uv, gridRes, offset); return sinWave(uv, pix.xy, time, pix.z, len); } // generates pixelated directional waves float flowRhomCell(vec2 uv, float gridRes, float time, float len) { vec3 pix = rhomPixelizor(uv, gridRes); return sinWave(uv, pix.xy, time, pix.z, len); } // 3 hex pixaled flowing sin thier edges get hidden by each other float triDirectionalFlow(vec2 uv, float gridRes, float time, float len) { float a = flowSquareCell(uv, vec2(0.,0.), gridRes, time, len); float b = flowSquareCell(uv, vec2(0.5), gridRes, time, len); float c = flowRhomCell(uv, gridRes, time, len); return a + b + c; } void mainImage( out vec4 fragColor, in vec2 fragCoord ) { float gridRes = 32.0; //Hex Grid Resolution float waveLen = 1./ (gridRes * 3.0); // Maximum Sin Wave Length float time = iTime * 0.05; // flow speed multiplier vec2 uv = fragCoord/iResolution.y; //centered square UVs float wave = triDirectionalFlow(uv,gridRes,time, waveLen); vec3 col = vec3(viridis(wave)); fragColor = vec4(col,1); }
mit
[ 5054, 5094, 5118, 5118, 5446 ]
[ [ 2752, 2833, 2856, 2856, 3304 ], [ 3306, 3344, 3369, 3369, 3399 ], [ 3401, 3439, 3463, 3463, 3493 ], [ 3495, 3534, 3590, 3590, 4780 ], [ 4782, 4806, 4832, 4832, 5052 ], [ 5054, 5094, 5118, 5118, 5446 ], [ 5448, 5484, 5543, 5543, 5700 ], [ 5702, 5739, 5783, 5783, 5920 ], [ 5922, 5922, 5996, 5996, 6909 ], [ 6911, 6952, 7034, 7034, 7147 ], [ 7149, 7190, 7257, 7257, 7360 ], [ 7362, 7428, 7501, 7501, 7710 ], [ 7712, 7712, 7769, 7769, 8144 ] ]
//rhombic shape form Manhattan distance
vec3 rhomTile(vec2 uv) {
vec2 a = fract(uv- vec2(.0, .5))-.5; vec2 b = fract(uv- vec2(.5, .0))-.5; vec2 aa = abs(a); float mDist = (aa.x + aa.y -.5); vec2 grid = mDist < 0. ? a : b; //UV coords float eDist = abs(mDist)*2.; //Edge Distance vec2 id = uv - grid; //ID values return vec3(id, eDist); }
//rhombic shape form Manhattan distance vec3 rhomTile(vec2 uv) {
1
1
7ddBWl
gehtsiegarnixan
2022-07-10T18:45:29
// The MIT License // Copyright © 2022 Gehtsiegarnixan // Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. /* This is using my Square Directional Flow algorithm (https://www.shadertoy.com/view/7dtBWl) with Sine waves instead of a texture. I also made a flowmap that is an aproximation of a tropical cyclone flowmap (https://www.shadertoy.com/view/fdKcWd). I wanted to aproximate the water wave height. I looked up the forumlas for the relationship between windspeed and waves, but the math is very complicated and I gave up. So I went for what looks alright (https://www.desmos.com/calculator/lewikf6y0f). The easy water wave math can be found here (https://en.wikipedia.org/wiki/Dispersion_(water_waves)). Wikipeda explains the relationship between water depth, wavelength and wave velocity (https://www.desmos.com/calculator/2nlmht2mmy). The amplitude and windspeed don't have such linear interaction, but there are formuals for observed wave spectra on the ocean after long periods of steady wind (https://wikiwaves.org/Ocean-Wave_Spectra). I just can not figure out how to solve for the wavespeed/wavelength for a give depth and windspeed. A single wave can be described by the gerstner formula (https://catlikecoding.com/unity/tutorials/flow/waves/), but I couldn't find how the wind affects the wave steepness and when exactly they break on the open sea. I found some hints here (http://hyperphysics.phy-astr.gsu.edu/hbase/Waves/watwav2.html) when they break. Animating the flowmap also turned out to have some significant drawbacks. Since im sampling a lower res hexagonal version leads to flickering waves, so you can only do it VERY slowly. */ #define pi 3.1415926536 #define sqrtG 3.1320919527 #define twoPi 6.2831853072 // makes viridis colormap with polynimal 6 https://www.shadertoy.com/view/Nd3fR2 vec3 viridis(float t) { const vec3 c0 = vec3(0.274344,0.004462,0.331359); const vec3 c1 = vec3(0.108915,1.397291,1.388110); const vec3 c2 = vec3(-0.319631,0.243490,0.156419); const vec3 c3 = vec3(-4.629188,-5.882803,-19.646115); const vec3 c4 = vec3(6.181719,14.388598,57.442181); const vec3 c5 = vec3(4.876952,-13.955112,-66.125783); const vec3 c6 = vec3(-5.513165,4.709245,26.582180); return c0+t*(c1+t*(c2+t*(c3+t*(c4+t*(c5+t*c6))))); } //shifts value range from -1-1 to 0-1 float make0to1(float x) { return (1.0 + x) / 2.0; } //shifts value range from 0-1 to -1-1 vec2 makeM1to1(vec2 x) { return (x - 0.5) * 2.0; } // makes a simple flowmap of a cyclone vec2 cycloneFlow(vec2 point, float radius, float time) { float size = 1./(1.4 * sqrt(radius)); // of the entire cyclone float curl = 2.5; // kind of arbitrary but between 1-3.5 looks good float hole = 1./(4.*size); // also kind of arbitrary //point += vec2(cos(time),sin(time))*0.1*hole; //rotating center float angle = atan(point.y, point.x); //angle around center float dist = length(point); // distance to point float spiral = fract(dist/radius + (angle-time)/twoPi); //right slanted donut https://www.desmos.com/calculator/ocm71awnym spiral -= 1.212; spiral = 1.+ (pow(1.57*(spiral)+0.8,2.)/spiral); float flowAngle = pi + angle -(dist*curl) -(spiral*0.8); // left slanted donut https://www.desmos.com/calculator/uxyefly7fi float spiralStrength = 0.05; float mask = (1. - spiralStrength)-(pow(dist*size-hole, 2.0)/dist); mask += spiral*spiralStrength; mask = clamp(mask, 0.0, 1.0); // saturate vec2 flow = normalize(vec2(cos(flowAngle),sin(flowAngle))); flow *= mask; // apply strength mask //flow = (flow+1.0)/2.0; // to save as texture flow += vec2(0.0001,0.0001); //adding tiny offset so it isnt 0 return flow; } // simple square Tiling vec3 squareTile(vec2 uv) { vec2 grid = fract(uv)-.5; //UV centered on cell vec2 d = abs(grid); float eDist = (0.5-max(d.x, d.y))*2.; //Edge Distance vec2 id = uv - grid; //ID values return vec3(id, eDist); } //rhombic shape form Manhattan distance vec3 rhomTile(vec2 uv) { vec2 a = fract(uv- vec2(.0, .5))-.5; vec2 b = fract(uv- vec2(.5, .0))-.5; vec2 aa = abs(a); float mDist = (aa.x + aa.y -.5); vec2 grid = mDist < 0. ? a : b; //UV coords float eDist = abs(mDist)*2.; //Edge Distance vec2 id = uv - grid; //ID values return vec3(id, eDist); } // nakes a square pixelized pattern vec3 squarePixelizor(vec2 uv, float gridRes, vec2 offset) { vec3 sTiling = squareTile(uv*gridRes + offset); vec2 tiledUV = (sTiling.xy - offset)/gridRes; //pixaltion return vec3(tiledUV, sTiling.z); } // nakes a rhombic pixelized pattern vec3 rhomPixelizor(vec2 uv, float gridRes) { vec3 rTiling = rhomTile(uv*gridRes); vec2 tiledUV = (rTiling.xy)/gridRes; //pixaltion return vec3(tiledUV, rTiling.z); } float sinWave(vec2 uv, vec2 tiledUV, float time, float alpha, float len) { float radius = 0.3; // of the first spiral //cyclone like flowmap vec2 flowMap = cycloneFlow(tiledUV - vec2(0.885, 0.5), radius, time*0.2); float speed = length(flowMap); // Wind Speed vec2 dir = normalize(flowMap); // Wind Direction len *= pow(speed,0.5); // make slower waves smaller float k = twoPi / len; //Wave Number float a = pow(speed,1.5); //Amplitude float s = speed; //Steepness time *= sqrtG * sqrt(len); // deep water speed float dD = dot(uv,dir); //Directional/Straight Wave //add random phase offsets for even FlowMaps or you get interference //time += texture( iChannel0, tiledUV).x; float wave = make0to1(sin(k * (dD - time))); // make sin wave //wave = (1.- pow(wave, (1.-s/2.))); //cheap gerstner height wave aprox wave *= a * alpha; // apply amplitue and alpha mask return wave; } // generates pixelated directional waves float flowSquareCell(vec2 uv, vec2 offset, float gridRes, float time, float len) { vec3 pix = squarePixelizor(uv, gridRes, offset); return sinWave(uv, pix.xy, time, pix.z, len); } // generates pixelated directional waves float flowRhomCell(vec2 uv, float gridRes, float time, float len) { vec3 pix = rhomPixelizor(uv, gridRes); return sinWave(uv, pix.xy, time, pix.z, len); } // 3 hex pixaled flowing sin thier edges get hidden by each other float triDirectionalFlow(vec2 uv, float gridRes, float time, float len) { float a = flowSquareCell(uv, vec2(0.,0.), gridRes, time, len); float b = flowSquareCell(uv, vec2(0.5), gridRes, time, len); float c = flowRhomCell(uv, gridRes, time, len); return a + b + c; } void mainImage( out vec4 fragColor, in vec2 fragCoord ) { float gridRes = 32.0; //Hex Grid Resolution float waveLen = 1./ (gridRes * 3.0); // Maximum Sin Wave Length float time = iTime * 0.05; // flow speed multiplier vec2 uv = fragCoord/iResolution.y; //centered square UVs float wave = triDirectionalFlow(uv,gridRes,time, waveLen); vec3 col = vec3(viridis(wave)); fragColor = vec4(col,1); }
mit
[ 5448, 5484, 5543, 5543, 5700 ]
[ [ 2752, 2833, 2856, 2856, 3304 ], [ 3306, 3344, 3369, 3369, 3399 ], [ 3401, 3439, 3463, 3463, 3493 ], [ 3495, 3534, 3590, 3590, 4780 ], [ 4782, 4806, 4832, 4832, 5052 ], [ 5054, 5094, 5118, 5118, 5446 ], [ 5448, 5484, 5543, 5543, 5700 ], [ 5702, 5739, 5783, 5783, 5920 ], [ 5922, 5922, 5996, 5996, 6909 ], [ 6911, 6952, 7034, 7034, 7147 ], [ 7149, 7190, 7257, 7257, 7360 ], [ 7362, 7428, 7501, 7501, 7710 ], [ 7712, 7712, 7769, 7769, 8144 ] ]
// nakes a square pixelized pattern
vec3 squarePixelizor(vec2 uv, float gridRes, vec2 offset) {
vec3 sTiling = squareTile(uv*gridRes + offset); vec2 tiledUV = (sTiling.xy - offset)/gridRes; //pixaltion return vec3(tiledUV, sTiling.z); }
// nakes a square pixelized pattern vec3 squarePixelizor(vec2 uv, float gridRes, vec2 offset) {
1
1
7ddBWl
gehtsiegarnixan
2022-07-10T18:45:29
// The MIT License // Copyright © 2022 Gehtsiegarnixan // Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. /* This is using my Square Directional Flow algorithm (https://www.shadertoy.com/view/7dtBWl) with Sine waves instead of a texture. I also made a flowmap that is an aproximation of a tropical cyclone flowmap (https://www.shadertoy.com/view/fdKcWd). I wanted to aproximate the water wave height. I looked up the forumlas for the relationship between windspeed and waves, but the math is very complicated and I gave up. So I went for what looks alright (https://www.desmos.com/calculator/lewikf6y0f). The easy water wave math can be found here (https://en.wikipedia.org/wiki/Dispersion_(water_waves)). Wikipeda explains the relationship between water depth, wavelength and wave velocity (https://www.desmos.com/calculator/2nlmht2mmy). The amplitude and windspeed don't have such linear interaction, but there are formuals for observed wave spectra on the ocean after long periods of steady wind (https://wikiwaves.org/Ocean-Wave_Spectra). I just can not figure out how to solve for the wavespeed/wavelength for a give depth and windspeed. A single wave can be described by the gerstner formula (https://catlikecoding.com/unity/tutorials/flow/waves/), but I couldn't find how the wind affects the wave steepness and when exactly they break on the open sea. I found some hints here (http://hyperphysics.phy-astr.gsu.edu/hbase/Waves/watwav2.html) when they break. Animating the flowmap also turned out to have some significant drawbacks. Since im sampling a lower res hexagonal version leads to flickering waves, so you can only do it VERY slowly. */ #define pi 3.1415926536 #define sqrtG 3.1320919527 #define twoPi 6.2831853072 // makes viridis colormap with polynimal 6 https://www.shadertoy.com/view/Nd3fR2 vec3 viridis(float t) { const vec3 c0 = vec3(0.274344,0.004462,0.331359); const vec3 c1 = vec3(0.108915,1.397291,1.388110); const vec3 c2 = vec3(-0.319631,0.243490,0.156419); const vec3 c3 = vec3(-4.629188,-5.882803,-19.646115); const vec3 c4 = vec3(6.181719,14.388598,57.442181); const vec3 c5 = vec3(4.876952,-13.955112,-66.125783); const vec3 c6 = vec3(-5.513165,4.709245,26.582180); return c0+t*(c1+t*(c2+t*(c3+t*(c4+t*(c5+t*c6))))); } //shifts value range from -1-1 to 0-1 float make0to1(float x) { return (1.0 + x) / 2.0; } //shifts value range from 0-1 to -1-1 vec2 makeM1to1(vec2 x) { return (x - 0.5) * 2.0; } // makes a simple flowmap of a cyclone vec2 cycloneFlow(vec2 point, float radius, float time) { float size = 1./(1.4 * sqrt(radius)); // of the entire cyclone float curl = 2.5; // kind of arbitrary but between 1-3.5 looks good float hole = 1./(4.*size); // also kind of arbitrary //point += vec2(cos(time),sin(time))*0.1*hole; //rotating center float angle = atan(point.y, point.x); //angle around center float dist = length(point); // distance to point float spiral = fract(dist/radius + (angle-time)/twoPi); //right slanted donut https://www.desmos.com/calculator/ocm71awnym spiral -= 1.212; spiral = 1.+ (pow(1.57*(spiral)+0.8,2.)/spiral); float flowAngle = pi + angle -(dist*curl) -(spiral*0.8); // left slanted donut https://www.desmos.com/calculator/uxyefly7fi float spiralStrength = 0.05; float mask = (1. - spiralStrength)-(pow(dist*size-hole, 2.0)/dist); mask += spiral*spiralStrength; mask = clamp(mask, 0.0, 1.0); // saturate vec2 flow = normalize(vec2(cos(flowAngle),sin(flowAngle))); flow *= mask; // apply strength mask //flow = (flow+1.0)/2.0; // to save as texture flow += vec2(0.0001,0.0001); //adding tiny offset so it isnt 0 return flow; } // simple square Tiling vec3 squareTile(vec2 uv) { vec2 grid = fract(uv)-.5; //UV centered on cell vec2 d = abs(grid); float eDist = (0.5-max(d.x, d.y))*2.; //Edge Distance vec2 id = uv - grid; //ID values return vec3(id, eDist); } //rhombic shape form Manhattan distance vec3 rhomTile(vec2 uv) { vec2 a = fract(uv- vec2(.0, .5))-.5; vec2 b = fract(uv- vec2(.5, .0))-.5; vec2 aa = abs(a); float mDist = (aa.x + aa.y -.5); vec2 grid = mDist < 0. ? a : b; //UV coords float eDist = abs(mDist)*2.; //Edge Distance vec2 id = uv - grid; //ID values return vec3(id, eDist); } // nakes a square pixelized pattern vec3 squarePixelizor(vec2 uv, float gridRes, vec2 offset) { vec3 sTiling = squareTile(uv*gridRes + offset); vec2 tiledUV = (sTiling.xy - offset)/gridRes; //pixaltion return vec3(tiledUV, sTiling.z); } // nakes a rhombic pixelized pattern vec3 rhomPixelizor(vec2 uv, float gridRes) { vec3 rTiling = rhomTile(uv*gridRes); vec2 tiledUV = (rTiling.xy)/gridRes; //pixaltion return vec3(tiledUV, rTiling.z); } float sinWave(vec2 uv, vec2 tiledUV, float time, float alpha, float len) { float radius = 0.3; // of the first spiral //cyclone like flowmap vec2 flowMap = cycloneFlow(tiledUV - vec2(0.885, 0.5), radius, time*0.2); float speed = length(flowMap); // Wind Speed vec2 dir = normalize(flowMap); // Wind Direction len *= pow(speed,0.5); // make slower waves smaller float k = twoPi / len; //Wave Number float a = pow(speed,1.5); //Amplitude float s = speed; //Steepness time *= sqrtG * sqrt(len); // deep water speed float dD = dot(uv,dir); //Directional/Straight Wave //add random phase offsets for even FlowMaps or you get interference //time += texture( iChannel0, tiledUV).x; float wave = make0to1(sin(k * (dD - time))); // make sin wave //wave = (1.- pow(wave, (1.-s/2.))); //cheap gerstner height wave aprox wave *= a * alpha; // apply amplitue and alpha mask return wave; } // generates pixelated directional waves float flowSquareCell(vec2 uv, vec2 offset, float gridRes, float time, float len) { vec3 pix = squarePixelizor(uv, gridRes, offset); return sinWave(uv, pix.xy, time, pix.z, len); } // generates pixelated directional waves float flowRhomCell(vec2 uv, float gridRes, float time, float len) { vec3 pix = rhomPixelizor(uv, gridRes); return sinWave(uv, pix.xy, time, pix.z, len); } // 3 hex pixaled flowing sin thier edges get hidden by each other float triDirectionalFlow(vec2 uv, float gridRes, float time, float len) { float a = flowSquareCell(uv, vec2(0.,0.), gridRes, time, len); float b = flowSquareCell(uv, vec2(0.5), gridRes, time, len); float c = flowRhomCell(uv, gridRes, time, len); return a + b + c; } void mainImage( out vec4 fragColor, in vec2 fragCoord ) { float gridRes = 32.0; //Hex Grid Resolution float waveLen = 1./ (gridRes * 3.0); // Maximum Sin Wave Length float time = iTime * 0.05; // flow speed multiplier vec2 uv = fragCoord/iResolution.y; //centered square UVs float wave = triDirectionalFlow(uv,gridRes,time, waveLen); vec3 col = vec3(viridis(wave)); fragColor = vec4(col,1); }
mit
[ 5702, 5739, 5783, 5783, 5920 ]
[ [ 2752, 2833, 2856, 2856, 3304 ], [ 3306, 3344, 3369, 3369, 3399 ], [ 3401, 3439, 3463, 3463, 3493 ], [ 3495, 3534, 3590, 3590, 4780 ], [ 4782, 4806, 4832, 4832, 5052 ], [ 5054, 5094, 5118, 5118, 5446 ], [ 5448, 5484, 5543, 5543, 5700 ], [ 5702, 5739, 5783, 5783, 5920 ], [ 5922, 5922, 5996, 5996, 6909 ], [ 6911, 6952, 7034, 7034, 7147 ], [ 7149, 7190, 7257, 7257, 7360 ], [ 7362, 7428, 7501, 7501, 7710 ], [ 7712, 7712, 7769, 7769, 8144 ] ]
// nakes a rhombic pixelized pattern
vec3 rhomPixelizor(vec2 uv, float gridRes) {
vec3 rTiling = rhomTile(uv*gridRes); vec2 tiledUV = (rTiling.xy)/gridRes; //pixaltion return vec3(tiledUV, rTiling.z); }
// nakes a rhombic pixelized pattern vec3 rhomPixelizor(vec2 uv, float gridRes) {
1
1
7ddBWl
gehtsiegarnixan
2022-07-10T18:45:29
// The MIT License // Copyright © 2022 Gehtsiegarnixan // Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. /* This is using my Square Directional Flow algorithm (https://www.shadertoy.com/view/7dtBWl) with Sine waves instead of a texture. I also made a flowmap that is an aproximation of a tropical cyclone flowmap (https://www.shadertoy.com/view/fdKcWd). I wanted to aproximate the water wave height. I looked up the forumlas for the relationship between windspeed and waves, but the math is very complicated and I gave up. So I went for what looks alright (https://www.desmos.com/calculator/lewikf6y0f). The easy water wave math can be found here (https://en.wikipedia.org/wiki/Dispersion_(water_waves)). Wikipeda explains the relationship between water depth, wavelength and wave velocity (https://www.desmos.com/calculator/2nlmht2mmy). The amplitude and windspeed don't have such linear interaction, but there are formuals for observed wave spectra on the ocean after long periods of steady wind (https://wikiwaves.org/Ocean-Wave_Spectra). I just can not figure out how to solve for the wavespeed/wavelength for a give depth and windspeed. A single wave can be described by the gerstner formula (https://catlikecoding.com/unity/tutorials/flow/waves/), but I couldn't find how the wind affects the wave steepness and when exactly they break on the open sea. I found some hints here (http://hyperphysics.phy-astr.gsu.edu/hbase/Waves/watwav2.html) when they break. Animating the flowmap also turned out to have some significant drawbacks. Since im sampling a lower res hexagonal version leads to flickering waves, so you can only do it VERY slowly. */ #define pi 3.1415926536 #define sqrtG 3.1320919527 #define twoPi 6.2831853072 // makes viridis colormap with polynimal 6 https://www.shadertoy.com/view/Nd3fR2 vec3 viridis(float t) { const vec3 c0 = vec3(0.274344,0.004462,0.331359); const vec3 c1 = vec3(0.108915,1.397291,1.388110); const vec3 c2 = vec3(-0.319631,0.243490,0.156419); const vec3 c3 = vec3(-4.629188,-5.882803,-19.646115); const vec3 c4 = vec3(6.181719,14.388598,57.442181); const vec3 c5 = vec3(4.876952,-13.955112,-66.125783); const vec3 c6 = vec3(-5.513165,4.709245,26.582180); return c0+t*(c1+t*(c2+t*(c3+t*(c4+t*(c5+t*c6))))); } //shifts value range from -1-1 to 0-1 float make0to1(float x) { return (1.0 + x) / 2.0; } //shifts value range from 0-1 to -1-1 vec2 makeM1to1(vec2 x) { return (x - 0.5) * 2.0; } // makes a simple flowmap of a cyclone vec2 cycloneFlow(vec2 point, float radius, float time) { float size = 1./(1.4 * sqrt(radius)); // of the entire cyclone float curl = 2.5; // kind of arbitrary but between 1-3.5 looks good float hole = 1./(4.*size); // also kind of arbitrary //point += vec2(cos(time),sin(time))*0.1*hole; //rotating center float angle = atan(point.y, point.x); //angle around center float dist = length(point); // distance to point float spiral = fract(dist/radius + (angle-time)/twoPi); //right slanted donut https://www.desmos.com/calculator/ocm71awnym spiral -= 1.212; spiral = 1.+ (pow(1.57*(spiral)+0.8,2.)/spiral); float flowAngle = pi + angle -(dist*curl) -(spiral*0.8); // left slanted donut https://www.desmos.com/calculator/uxyefly7fi float spiralStrength = 0.05; float mask = (1. - spiralStrength)-(pow(dist*size-hole, 2.0)/dist); mask += spiral*spiralStrength; mask = clamp(mask, 0.0, 1.0); // saturate vec2 flow = normalize(vec2(cos(flowAngle),sin(flowAngle))); flow *= mask; // apply strength mask //flow = (flow+1.0)/2.0; // to save as texture flow += vec2(0.0001,0.0001); //adding tiny offset so it isnt 0 return flow; } // simple square Tiling vec3 squareTile(vec2 uv) { vec2 grid = fract(uv)-.5; //UV centered on cell vec2 d = abs(grid); float eDist = (0.5-max(d.x, d.y))*2.; //Edge Distance vec2 id = uv - grid; //ID values return vec3(id, eDist); } //rhombic shape form Manhattan distance vec3 rhomTile(vec2 uv) { vec2 a = fract(uv- vec2(.0, .5))-.5; vec2 b = fract(uv- vec2(.5, .0))-.5; vec2 aa = abs(a); float mDist = (aa.x + aa.y -.5); vec2 grid = mDist < 0. ? a : b; //UV coords float eDist = abs(mDist)*2.; //Edge Distance vec2 id = uv - grid; //ID values return vec3(id, eDist); } // nakes a square pixelized pattern vec3 squarePixelizor(vec2 uv, float gridRes, vec2 offset) { vec3 sTiling = squareTile(uv*gridRes + offset); vec2 tiledUV = (sTiling.xy - offset)/gridRes; //pixaltion return vec3(tiledUV, sTiling.z); } // nakes a rhombic pixelized pattern vec3 rhomPixelizor(vec2 uv, float gridRes) { vec3 rTiling = rhomTile(uv*gridRes); vec2 tiledUV = (rTiling.xy)/gridRes; //pixaltion return vec3(tiledUV, rTiling.z); } float sinWave(vec2 uv, vec2 tiledUV, float time, float alpha, float len) { float radius = 0.3; // of the first spiral //cyclone like flowmap vec2 flowMap = cycloneFlow(tiledUV - vec2(0.885, 0.5), radius, time*0.2); float speed = length(flowMap); // Wind Speed vec2 dir = normalize(flowMap); // Wind Direction len *= pow(speed,0.5); // make slower waves smaller float k = twoPi / len; //Wave Number float a = pow(speed,1.5); //Amplitude float s = speed; //Steepness time *= sqrtG * sqrt(len); // deep water speed float dD = dot(uv,dir); //Directional/Straight Wave //add random phase offsets for even FlowMaps or you get interference //time += texture( iChannel0, tiledUV).x; float wave = make0to1(sin(k * (dD - time))); // make sin wave //wave = (1.- pow(wave, (1.-s/2.))); //cheap gerstner height wave aprox wave *= a * alpha; // apply amplitue and alpha mask return wave; } // generates pixelated directional waves float flowSquareCell(vec2 uv, vec2 offset, float gridRes, float time, float len) { vec3 pix = squarePixelizor(uv, gridRes, offset); return sinWave(uv, pix.xy, time, pix.z, len); } // generates pixelated directional waves float flowRhomCell(vec2 uv, float gridRes, float time, float len) { vec3 pix = rhomPixelizor(uv, gridRes); return sinWave(uv, pix.xy, time, pix.z, len); } // 3 hex pixaled flowing sin thier edges get hidden by each other float triDirectionalFlow(vec2 uv, float gridRes, float time, float len) { float a = flowSquareCell(uv, vec2(0.,0.), gridRes, time, len); float b = flowSquareCell(uv, vec2(0.5), gridRes, time, len); float c = flowRhomCell(uv, gridRes, time, len); return a + b + c; } void mainImage( out vec4 fragColor, in vec2 fragCoord ) { float gridRes = 32.0; //Hex Grid Resolution float waveLen = 1./ (gridRes * 3.0); // Maximum Sin Wave Length float time = iTime * 0.05; // flow speed multiplier vec2 uv = fragCoord/iResolution.y; //centered square UVs float wave = triDirectionalFlow(uv,gridRes,time, waveLen); vec3 col = vec3(viridis(wave)); fragColor = vec4(col,1); }
mit
[ 6911, 6952, 7034, 7034, 7147 ]
[ [ 2752, 2833, 2856, 2856, 3304 ], [ 3306, 3344, 3369, 3369, 3399 ], [ 3401, 3439, 3463, 3463, 3493 ], [ 3495, 3534, 3590, 3590, 4780 ], [ 4782, 4806, 4832, 4832, 5052 ], [ 5054, 5094, 5118, 5118, 5446 ], [ 5448, 5484, 5543, 5543, 5700 ], [ 5702, 5739, 5783, 5783, 5920 ], [ 5922, 5922, 5996, 5996, 6909 ], [ 6911, 6952, 7034, 7034, 7147 ], [ 7149, 7190, 7257, 7257, 7360 ], [ 7362, 7428, 7501, 7501, 7710 ], [ 7712, 7712, 7769, 7769, 8144 ] ]
// generates pixelated directional waves
float flowSquareCell(vec2 uv, vec2 offset, float gridRes, float time, float len) {
vec3 pix = squarePixelizor(uv, gridRes, offset); return sinWave(uv, pix.xy, time, pix.z, len); }
// generates pixelated directional waves float flowSquareCell(vec2 uv, vec2 offset, float gridRes, float time, float len) {
1
1
7ddBWl
gehtsiegarnixan
2022-07-10T18:45:29
// The MIT License // Copyright © 2022 Gehtsiegarnixan // Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. /* This is using my Square Directional Flow algorithm (https://www.shadertoy.com/view/7dtBWl) with Sine waves instead of a texture. I also made a flowmap that is an aproximation of a tropical cyclone flowmap (https://www.shadertoy.com/view/fdKcWd). I wanted to aproximate the water wave height. I looked up the forumlas for the relationship between windspeed and waves, but the math is very complicated and I gave up. So I went for what looks alright (https://www.desmos.com/calculator/lewikf6y0f). The easy water wave math can be found here (https://en.wikipedia.org/wiki/Dispersion_(water_waves)). Wikipeda explains the relationship between water depth, wavelength and wave velocity (https://www.desmos.com/calculator/2nlmht2mmy). The amplitude and windspeed don't have such linear interaction, but there are formuals for observed wave spectra on the ocean after long periods of steady wind (https://wikiwaves.org/Ocean-Wave_Spectra). I just can not figure out how to solve for the wavespeed/wavelength for a give depth and windspeed. A single wave can be described by the gerstner formula (https://catlikecoding.com/unity/tutorials/flow/waves/), but I couldn't find how the wind affects the wave steepness and when exactly they break on the open sea. I found some hints here (http://hyperphysics.phy-astr.gsu.edu/hbase/Waves/watwav2.html) when they break. Animating the flowmap also turned out to have some significant drawbacks. Since im sampling a lower res hexagonal version leads to flickering waves, so you can only do it VERY slowly. */ #define pi 3.1415926536 #define sqrtG 3.1320919527 #define twoPi 6.2831853072 // makes viridis colormap with polynimal 6 https://www.shadertoy.com/view/Nd3fR2 vec3 viridis(float t) { const vec3 c0 = vec3(0.274344,0.004462,0.331359); const vec3 c1 = vec3(0.108915,1.397291,1.388110); const vec3 c2 = vec3(-0.319631,0.243490,0.156419); const vec3 c3 = vec3(-4.629188,-5.882803,-19.646115); const vec3 c4 = vec3(6.181719,14.388598,57.442181); const vec3 c5 = vec3(4.876952,-13.955112,-66.125783); const vec3 c6 = vec3(-5.513165,4.709245,26.582180); return c0+t*(c1+t*(c2+t*(c3+t*(c4+t*(c5+t*c6))))); } //shifts value range from -1-1 to 0-1 float make0to1(float x) { return (1.0 + x) / 2.0; } //shifts value range from 0-1 to -1-1 vec2 makeM1to1(vec2 x) { return (x - 0.5) * 2.0; } // makes a simple flowmap of a cyclone vec2 cycloneFlow(vec2 point, float radius, float time) { float size = 1./(1.4 * sqrt(radius)); // of the entire cyclone float curl = 2.5; // kind of arbitrary but between 1-3.5 looks good float hole = 1./(4.*size); // also kind of arbitrary //point += vec2(cos(time),sin(time))*0.1*hole; //rotating center float angle = atan(point.y, point.x); //angle around center float dist = length(point); // distance to point float spiral = fract(dist/radius + (angle-time)/twoPi); //right slanted donut https://www.desmos.com/calculator/ocm71awnym spiral -= 1.212; spiral = 1.+ (pow(1.57*(spiral)+0.8,2.)/spiral); float flowAngle = pi + angle -(dist*curl) -(spiral*0.8); // left slanted donut https://www.desmos.com/calculator/uxyefly7fi float spiralStrength = 0.05; float mask = (1. - spiralStrength)-(pow(dist*size-hole, 2.0)/dist); mask += spiral*spiralStrength; mask = clamp(mask, 0.0, 1.0); // saturate vec2 flow = normalize(vec2(cos(flowAngle),sin(flowAngle))); flow *= mask; // apply strength mask //flow = (flow+1.0)/2.0; // to save as texture flow += vec2(0.0001,0.0001); //adding tiny offset so it isnt 0 return flow; } // simple square Tiling vec3 squareTile(vec2 uv) { vec2 grid = fract(uv)-.5; //UV centered on cell vec2 d = abs(grid); float eDist = (0.5-max(d.x, d.y))*2.; //Edge Distance vec2 id = uv - grid; //ID values return vec3(id, eDist); } //rhombic shape form Manhattan distance vec3 rhomTile(vec2 uv) { vec2 a = fract(uv- vec2(.0, .5))-.5; vec2 b = fract(uv- vec2(.5, .0))-.5; vec2 aa = abs(a); float mDist = (aa.x + aa.y -.5); vec2 grid = mDist < 0. ? a : b; //UV coords float eDist = abs(mDist)*2.; //Edge Distance vec2 id = uv - grid; //ID values return vec3(id, eDist); } // nakes a square pixelized pattern vec3 squarePixelizor(vec2 uv, float gridRes, vec2 offset) { vec3 sTiling = squareTile(uv*gridRes + offset); vec2 tiledUV = (sTiling.xy - offset)/gridRes; //pixaltion return vec3(tiledUV, sTiling.z); } // nakes a rhombic pixelized pattern vec3 rhomPixelizor(vec2 uv, float gridRes) { vec3 rTiling = rhomTile(uv*gridRes); vec2 tiledUV = (rTiling.xy)/gridRes; //pixaltion return vec3(tiledUV, rTiling.z); } float sinWave(vec2 uv, vec2 tiledUV, float time, float alpha, float len) { float radius = 0.3; // of the first spiral //cyclone like flowmap vec2 flowMap = cycloneFlow(tiledUV - vec2(0.885, 0.5), radius, time*0.2); float speed = length(flowMap); // Wind Speed vec2 dir = normalize(flowMap); // Wind Direction len *= pow(speed,0.5); // make slower waves smaller float k = twoPi / len; //Wave Number float a = pow(speed,1.5); //Amplitude float s = speed; //Steepness time *= sqrtG * sqrt(len); // deep water speed float dD = dot(uv,dir); //Directional/Straight Wave //add random phase offsets for even FlowMaps or you get interference //time += texture( iChannel0, tiledUV).x; float wave = make0to1(sin(k * (dD - time))); // make sin wave //wave = (1.- pow(wave, (1.-s/2.))); //cheap gerstner height wave aprox wave *= a * alpha; // apply amplitue and alpha mask return wave; } // generates pixelated directional waves float flowSquareCell(vec2 uv, vec2 offset, float gridRes, float time, float len) { vec3 pix = squarePixelizor(uv, gridRes, offset); return sinWave(uv, pix.xy, time, pix.z, len); } // generates pixelated directional waves float flowRhomCell(vec2 uv, float gridRes, float time, float len) { vec3 pix = rhomPixelizor(uv, gridRes); return sinWave(uv, pix.xy, time, pix.z, len); } // 3 hex pixaled flowing sin thier edges get hidden by each other float triDirectionalFlow(vec2 uv, float gridRes, float time, float len) { float a = flowSquareCell(uv, vec2(0.,0.), gridRes, time, len); float b = flowSquareCell(uv, vec2(0.5), gridRes, time, len); float c = flowRhomCell(uv, gridRes, time, len); return a + b + c; } void mainImage( out vec4 fragColor, in vec2 fragCoord ) { float gridRes = 32.0; //Hex Grid Resolution float waveLen = 1./ (gridRes * 3.0); // Maximum Sin Wave Length float time = iTime * 0.05; // flow speed multiplier vec2 uv = fragCoord/iResolution.y; //centered square UVs float wave = triDirectionalFlow(uv,gridRes,time, waveLen); vec3 col = vec3(viridis(wave)); fragColor = vec4(col,1); }
mit
[ 7149, 7190, 7257, 7257, 7360 ]
[ [ 2752, 2833, 2856, 2856, 3304 ], [ 3306, 3344, 3369, 3369, 3399 ], [ 3401, 3439, 3463, 3463, 3493 ], [ 3495, 3534, 3590, 3590, 4780 ], [ 4782, 4806, 4832, 4832, 5052 ], [ 5054, 5094, 5118, 5118, 5446 ], [ 5448, 5484, 5543, 5543, 5700 ], [ 5702, 5739, 5783, 5783, 5920 ], [ 5922, 5922, 5996, 5996, 6909 ], [ 6911, 6952, 7034, 7034, 7147 ], [ 7149, 7190, 7257, 7257, 7360 ], [ 7362, 7428, 7501, 7501, 7710 ], [ 7712, 7712, 7769, 7769, 8144 ] ]
// generates pixelated directional waves
float flowRhomCell(vec2 uv, float gridRes, float time, float len) {
vec3 pix = rhomPixelizor(uv, gridRes); return sinWave(uv, pix.xy, time, pix.z, len); }
// generates pixelated directional waves float flowRhomCell(vec2 uv, float gridRes, float time, float len) {
1
1
fddBD2
iq
2022-07-07T22:16:10
// The MIT License // Copyright © 2022 Inigo Quilez // Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. // Ray intersection for quadrics of this particular shape: // // f(x,y,z) = ± a²x² ± b²y² ± c²z² - {-1,0,1} = 0 // // Note this is NOT a general quadric, it does not handle // paraboloids. It does however handle hyperboloids, cones and // ellipsods optimally (as opposed to a general quadric solver), // and also spheres, cylinders, slabs and so on, in a non-optimal // way as a bonus (you should use specialized code paths for // those shapes, do NOT use this). See this shader for paraboloids: // // https://www.shadertoy.com/view/sdyfDR // // a,b,c,d are the parameters of the shape. a,b,c are inverse // radii and d is either -1, 0 or 1. See lines 91 to 100. // // Sphere : a>0, b=a, c=a, d= 1 // Ellipsoid : a>0, b>0, c>0, d= 1 // Cone : a>0, b<0, c>0, d= 0 // Hyperboloid of 1 sheets : a>0, b<0, c>0, d= 1 // Hyperboloid of 2 sheets : a>0, b<0, c>0, d=-1 // Cylinder : a>0, b=0, c>0, d= 1 // Slab : a>0, b=0, c=0, d= 1 // Hyperbolic Cylinder : a>0, b=0, c<0, d=-1 // // Note I'm showing symmetric cones and hyperboloids, but // you can just specify different radii for each axis. // // // List of ray-surface intersectors at // https://www.shadertoy.com/playlist/l3dXRf // and // https://iquilezles.org/articles/intersectors bool clipped( in vec3 pos, float clipY, float clipZ ); float iQuadricTypeA( // intersection distance. -1 if no intersection in vec3 ro, in vec3 rd, // ray origin and direction in vec4 abcd, // the quadric (see above) in float clipY, // height of clipping volume in float clipZ, // depth of clipping volume out vec3 oNor, // normal at intersection out bool oInside ) // inside/outside identifier { vec3 r2 = abcd.xyz*abs(abcd.xyz); // squared WITH sign float k2 = dot(rd,rd*r2); float k1 = dot(rd,ro*r2); float k0 = dot(ro,ro*r2) - abcd.w; float h = k1*k1 - k2*k0; if( h<0.0 ) return -1.0; h = sqrt(h) * sign(k2); // entry point float t = (-k1-h)/k2; vec3 pos = ro + t*rd; if( t>0.0 && clipped(pos,clipY,clipZ) ) { oInside = k2<0.0; oNor = normalize(pos*r2); return t; } // exit point t = (-k1+h)/k2; pos = ro + t*rd; if( t>0.0 && clipped(pos,clipY,clipZ) ) { oInside = k2>0.0; oNor = normalize(pos*r2); return t; } return -1.0; } bool clipped( in vec3 pos, float y, float z ) { return abs(pos.y)<y && abs(pos.z)<z; } //-------------------------------------------------------- // shapes const vec4 kShape[10] = vec4[10]( vec4(1.0/1.6, 1.0/1.6,1.0/1.6, 1.0), // sphere vec4(1.0/1.7, 1.0/3.0,1.0/0.9, 1.0), // ellipsoid vec4(1.0/1.0, 0.0, 0.0, 1.0), // slab vec4(1.0/0.8, 0.0, -1.0/0.8, 0.0), // cross vec4(1.0/0.8, 0.0, -1.0/0.8,-1.0), // hyperbolic cylinder vec4(1.0/1.6, 0.0, 1.0/1.6, 1.0), // cylinder vec4(1.0/1.6, 0.0, 1.0/0.9, 1.0), // cylinder vec4(1.0/0.6,-1.0/1.2,1.0/0.6, 0.0), // cone vec4(1.0/0.3,-1.0/0.7,1.0/0.3, 1.0), // hyperboloid of one sheet vec4(1.0/0.3,-1.0/0.6,1.0/0.3,-1.0)); // hyperboloid of two sheets // https://iquilezles.org/articles/filterableprocedurals/ float gridTextureGradBox( in vec2 p, in vec2 ddx, in vec2 ddy ) { // filter kernel vec2 w = max(abs(ddx), abs(ddy)) + 0.01; // analytic (box) filtering vec2 a = p + 0.5*w; vec2 b = p - 0.5*w; const float N = 18.0; // grid thickness vec2 i = (floor(a)+min(fract(a)*N,1.0)- floor(b)-min(fract(b)*N,1.0))/(N*w); //pattern return (1.0-i.x)*(1.0-i.y); } vec2 getUV( in vec3 pos, ivec2 id ) { if( id.y==0 && id.x>=2 ) return 11.0*pos.zy; return vec2(12.0,11.0)*vec2(atan(pos.x,pos.z),pos.y); } vec3 getRay( in vec2 p, in vec3 uu, in vec3 vv, in vec3 ww ) { return normalize( p.x*uu + p.y*vv + 3.0*ww ); } #define AA 2 void mainImage( out vec4 fragColor, in vec2 fragCoord ) { // clip height float clipY = 1.0 + 2.0*smoothstep(-1.0,-0.8,-cos(iTime*6.283185/12.0)); // camera movement float an1 = 0.4 + 0.9*smoothstep(0.7,0.9,-cos(iTime*6.283185/12.0)); float an2 = 6.283185*iTime/6.0; vec3 ro = 12.0*vec3( cos(an1)*sin(an2), sin(an1), cos(an1)*cos(an2) ); vec3 ta = vec3( 0.0, 0.0, 0.0 ); // camera matrix vec3 ww = normalize( ta - ro ); vec3 uu = normalize( cross(ww,vec3(0.0,1.0,0.0) ) ); vec3 vv = normalize( cross(uu,ww)); // global normalize coordinates vec2 gp = (2.0*fragCoord-iResolution.xy)/iResolution.y; // viewport ivec2 id = ivec2(vec2(5.0,2.0)*fragCoord/iResolution.xy ); vec2 res = iResolution.xy/vec2(5.0,2.0); vec2 q = mod(fragCoord,res); float clipZ = (id.x>=2 && id.y==0) ? 1.4 : 2.0; // render vec3 tot = vec3(0.0); #if AA>1 for( int m=0; m<AA; m++ ) for( int n=0; n<AA; n++ ) { // pixel coordinates vec2 o = vec2(float(m),float(n)) / float(AA) - 0.5; vec2 p = (2.0*(q+o)-res)/res.y; #else vec2 p = (2.0*q-res)/res.y; #endif // create view ray vec3 rd = getRay( p, uu, vv, ww ); // background vec3 col = vec3(0.08) * (1.0-0.3*length(gp)); //col += 0.1*cos( float(5*id.y+id.x)+vec3(0,2,4)); // raytrace bool isInside = false; vec3 nor = vec3(0.0); float t = iQuadricTypeA( ro, rd, kShape[5*id.y+id.x], clipY, clipZ, nor, isInside ); if( t>0.0 ) { vec3 pos = ro + t*rd; // material vec2 uv = getUV( pos, id ); // checkerboard pattern { col = vec3(0.6); col += 0.4*smoothstep(-0.01,0.01,cos(uv.x*0.5)*cos(uv.y*0.5)); if( isInside ) col = vec3(1.5,0.6,0.0); } // grid lines { #if 0 // no filtering col *= smoothstep(-1.0,-0.98,cos(uv.x))*smoothstep(-1.0,-0.98,cos(uv.y)); #endif #if 0 // hardware filtering uv = 0.5 + uv/6.283185; col *= gridTextureGradBox( uv, dFdx(uv), dFdy(uv) ); #endif #if 1 // software filtering // https://iquilezles.org/articles/filteringrm vec2 px = vec2(p.x+2.0/res.y,p.y); vec2 py = vec2(p.x,p.y+2.0/res.y); vec3 rdx = getRay( px, uu, vv, ww ); vec3 rdy = getRay( py, uu, vv, ww ); vec3 posx = ro + t*rdx*dot(rd,nor)/dot(rdx,nor); vec3 posy = ro + t*rdy*dot(rd,nor)/dot(rdy,nor); vec2 uvx = getUV(posx, id); vec2 uvy = getUV(posy, id); uv = 0.5 + uv /6.283185; uvx = 0.5 + uvx/6.283185; uvy = 0.5 + uvy/6.283185; col *= gridTextureGradBox( uv, uvx-uv, uvy-uv ); #endif } // lighting vec3 lig = normalize(vec3(0.7,0.6,0.3)); vec3 hal = normalize(-rd+lig); float dif = clamp( dot(nor,lig), 0.0, 1.0 ); float amb = clamp( 0.5 + 0.5*dot(nor,vec3(0.0,1.0,0.0)), 0.0, 1.0 ); col *= vec3(0.2,0.3,0.4)*amb*2.0 + 0.7*vec3(1.0,0.9,0.7)*dif; col += 0.3*pow(clamp(dot(hal,nor),0.0,1.0),32.0)*dif; } // gamma col = sqrt( col ); tot += col; #if AA>1 } tot /= float(AA*AA); #endif // dither to remove banding in the background tot += fract(sin(fragCoord.x*vec3(13,1,11)+fragCoord.y*vec3(1,7,5))*158.391832)/255.0; fragColor = vec4( tot, 1.0 ); }
mit
[ 4334, 4392, 4457, 4475, 4820 ]
[ [ 2473, 2473, 2893, 2893, 3577 ], [ 3579, 3579, 3626, 3626, 3669 ], [ 4334, 4392, 4457, 4475, 4820 ], [ 4822, 4822, 4859, 4859, 4973 ], [ 4975, 4975, 5037, 5037, 5089 ] ]
// https://iquilezles.org/articles/filterableprocedurals/
float gridTextureGradBox( in vec2 p, in vec2 ddx, in vec2 ddy ) {
vec2 w = max(abs(ddx), abs(ddy)) + 0.01; // analytic (box) filtering vec2 a = p + 0.5*w; vec2 b = p - 0.5*w; const float N = 18.0; // grid thickness vec2 i = (floor(a)+min(fract(a)*N,1.0)- floor(b)-min(fract(b)*N,1.0))/(N*w); //pattern return (1.0-i.x)*(1.0-i.y); }
// https://iquilezles.org/articles/filterableprocedurals/ float gridTextureGradBox( in vec2 p, in vec2 ddx, in vec2 ddy ) {
2
6
ssdBWS
mrange
2022-07-06T19:50:42
// License CC0: Rainbow boxes // Wednesday hack to reproduce a commonly seen effect #define TIME iTime #define RESOLUTION iResolution // License: WTFPL, author: sam hocevar, found: https://stackoverflow.com/a/17897228/418488 const vec4 hsv2rgb_K = vec4(1.0, 2.0 / 3.0, 1.0 / 3.0, 3.0); vec3 hsv2rgb(vec3 c) { vec3 p = abs(fract(c.xxx + hsv2rgb_K.xyz) * 6.0 - hsv2rgb_K.www); return c.z * mix(hsv2rgb_K.xxx, clamp(p - hsv2rgb_K.xxx, 0.0, 1.0), 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)) // License: MIT, author: Inigo Quilez, found: https://iquilezles.org/www/articles/distfunctions2d/distfunctions2d.htm float hexagon(vec2 p, float r) { // const vec3 k = vec3(-0.866025404,0.5,0.577350269); const vec3 k = 0.5*vec3(-sqrt(3.0),1.0,sqrt(4.0/3.0)); p = abs(p); p -= 2.0*min(dot(k.xy,p),0.0)*k.xy; p -= vec2(clamp(p.x, -k.z*r, k.z*r), r); return length(p)*sign(p.y); } // License: Unknown, author: Martijn Steinrucken, found: https://www.youtube.com/watch?v=VmrIDyYiJBA vec2 hextile(inout vec2 p) { // See Art of Code: Hexagonal Tiling Explained! // https://www.youtube.com/watch?v=VmrIDyYiJBA const vec2 sz = vec2(1.0, sqrt(3.0)); const vec2 hsz = 0.5*sz; vec2 p1 = mod(p, sz)-hsz; vec2 p2 = mod(p - hsz, sz)-hsz; vec2 p3 = dot(p1, p1) < dot(p2, p2) ? p1 : p2; vec2 n = ((p3 - p + hsz)/sz); p = p3; n -= vec2(0.5); // Rounding to make hextile 0,0 well behaved return round(n*2.0)*0.5; } float cellf(vec2 p, vec2 n) { const float lw = 0.01; return -hexagon(p.yx, 0.5-lw); } vec2 df(vec2 p, out vec2 hn0, out vec2 hn1) { const float sz = 0.25; p /= sz; vec2 hp0 = p; vec2 hp1 = p+vec2(1.0, sqrt(1.0/3.0)); hn0 = hextile(hp0); hn1 = hextile(hp1); float d0 = cellf(hp0, hn0); float d1 = cellf(hp1, hn1); float d2 = length(hp0); float d = d0; d = min(d0, d1); return vec2(d, d2)*sz; } // License: Unknown, author: Unknown, found: don't remember float hash(vec2 co) { return fract(sin(dot(co.xy ,vec2(12.9898,58.233))) * 13758.5453); } vec3 effect(vec2 p) { float aa = 2.0/RESOLUTION.y; vec2 hn0; vec2 hn1; p .x+= 0.05*TIME; vec2 d2 = df(p, hn0, hn1); vec3 col = vec3(0.01); float h0 = hash(hn1); float h = fract(-0.025*hn1.x+0.1*hn1.y-0.2*TIME); float l = mix(0.25, 0.75, h0); if (hn0.x <= hn1.x+0.5) { l *= 0.5; } if (hn0.y <= hn1.y) { l *= 0.75; } col += hsv2rgb(vec3(h, 0.5, l)); col = mix(col, vec3(0.), smoothstep(aa, -aa, d2.x)); col *= mix(0.75, 1.0, smoothstep(0.01, 0.2, d2.y)); return col; } void mainImage(out vec4 fragColor, in vec2 fragCoord) { vec2 q = fragCoord/iResolution.xy; vec2 p = -1. + 2. * q; p.x *= RESOLUTION.x/RESOLUTION.y; vec3 col = effect(p); col *= smoothstep(0.0, 4.0, TIME-0.5*length(p)); col = clamp(col, 0.0, 1.0); col = sqrt(col); fragColor = vec4(col, 1.0); }
cc0-1.0
[ 761, 879, 911, 966, 1150 ]
[ [ 297, 297, 319, 319, 465 ], [ 761, 879, 911, 966, 1150 ], [ 1152, 1253, 1281, 1380, 1707 ], [ 1709, 1709, 1738, 1738, 1798 ], [ 1800, 1800, 1845, 1845, 2134 ], [ 2136, 2196, 2217, 2217, 2287 ], [ 2289, 2289, 2310, 2310, 2810 ], [ 2812, 2812, 2867, 2867, 3127 ] ]
// License: MIT, author: Inigo Quilez, found: https://iquilezles.org/www/articles/distfunctions2d/distfunctions2d.htm
float hexagon(vec2 p, float r) {
const vec3 k = 0.5*vec3(-sqrt(3.0),1.0,sqrt(4.0/3.0)); p = abs(p); p -= 2.0*min(dot(k.xy,p),0.0)*k.xy; p -= vec2(clamp(p.x, -k.z*r, k.z*r), r); return length(p)*sign(p.y); }
// License: MIT, author: Inigo Quilez, found: https://iquilezles.org/www/articles/distfunctions2d/distfunctions2d.htm float hexagon(vec2 p, float r) {
2
11
ssdBWS
mrange
2022-07-06T19:50:42
// License CC0: Rainbow boxes // Wednesday hack to reproduce a commonly seen effect #define TIME iTime #define RESOLUTION iResolution // License: WTFPL, author: sam hocevar, found: https://stackoverflow.com/a/17897228/418488 const vec4 hsv2rgb_K = vec4(1.0, 2.0 / 3.0, 1.0 / 3.0, 3.0); vec3 hsv2rgb(vec3 c) { vec3 p = abs(fract(c.xxx + hsv2rgb_K.xyz) * 6.0 - hsv2rgb_K.www); return c.z * mix(hsv2rgb_K.xxx, clamp(p - hsv2rgb_K.xxx, 0.0, 1.0), 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)) // License: MIT, author: Inigo Quilez, found: https://iquilezles.org/www/articles/distfunctions2d/distfunctions2d.htm float hexagon(vec2 p, float r) { // const vec3 k = vec3(-0.866025404,0.5,0.577350269); const vec3 k = 0.5*vec3(-sqrt(3.0),1.0,sqrt(4.0/3.0)); p = abs(p); p -= 2.0*min(dot(k.xy,p),0.0)*k.xy; p -= vec2(clamp(p.x, -k.z*r, k.z*r), r); return length(p)*sign(p.y); } // License: Unknown, author: Martijn Steinrucken, found: https://www.youtube.com/watch?v=VmrIDyYiJBA vec2 hextile(inout vec2 p) { // See Art of Code: Hexagonal Tiling Explained! // https://www.youtube.com/watch?v=VmrIDyYiJBA const vec2 sz = vec2(1.0, sqrt(3.0)); const vec2 hsz = 0.5*sz; vec2 p1 = mod(p, sz)-hsz; vec2 p2 = mod(p - hsz, sz)-hsz; vec2 p3 = dot(p1, p1) < dot(p2, p2) ? p1 : p2; vec2 n = ((p3 - p + hsz)/sz); p = p3; n -= vec2(0.5); // Rounding to make hextile 0,0 well behaved return round(n*2.0)*0.5; } float cellf(vec2 p, vec2 n) { const float lw = 0.01; return -hexagon(p.yx, 0.5-lw); } vec2 df(vec2 p, out vec2 hn0, out vec2 hn1) { const float sz = 0.25; p /= sz; vec2 hp0 = p; vec2 hp1 = p+vec2(1.0, sqrt(1.0/3.0)); hn0 = hextile(hp0); hn1 = hextile(hp1); float d0 = cellf(hp0, hn0); float d1 = cellf(hp1, hn1); float d2 = length(hp0); float d = d0; d = min(d0, d1); return vec2(d, d2)*sz; } // License: Unknown, author: Unknown, found: don't remember float hash(vec2 co) { return fract(sin(dot(co.xy ,vec2(12.9898,58.233))) * 13758.5453); } vec3 effect(vec2 p) { float aa = 2.0/RESOLUTION.y; vec2 hn0; vec2 hn1; p .x+= 0.05*TIME; vec2 d2 = df(p, hn0, hn1); vec3 col = vec3(0.01); float h0 = hash(hn1); float h = fract(-0.025*hn1.x+0.1*hn1.y-0.2*TIME); float l = mix(0.25, 0.75, h0); if (hn0.x <= hn1.x+0.5) { l *= 0.5; } if (hn0.y <= hn1.y) { l *= 0.75; } col += hsv2rgb(vec3(h, 0.5, l)); col = mix(col, vec3(0.), smoothstep(aa, -aa, d2.x)); col *= mix(0.75, 1.0, smoothstep(0.01, 0.2, d2.y)); return col; } void mainImage(out vec4 fragColor, in vec2 fragCoord) { vec2 q = fragCoord/iResolution.xy; vec2 p = -1. + 2. * q; p.x *= RESOLUTION.x/RESOLUTION.y; vec3 col = effect(p); col *= smoothstep(0.0, 4.0, TIME-0.5*length(p)); col = clamp(col, 0.0, 1.0); col = sqrt(col); fragColor = vec4(col, 1.0); }
cc0-1.0
[ 1152, 1253, 1281, 1380, 1707 ]
[ [ 297, 297, 319, 319, 465 ], [ 761, 879, 911, 966, 1150 ], [ 1152, 1253, 1281, 1380, 1707 ], [ 1709, 1709, 1738, 1738, 1798 ], [ 1800, 1800, 1845, 1845, 2134 ], [ 2136, 2196, 2217, 2217, 2287 ], [ 2289, 2289, 2310, 2310, 2810 ], [ 2812, 2812, 2867, 2867, 3127 ] ]
// License: Unknown, author: Martijn Steinrucken, found: https://www.youtube.com/watch?v=VmrIDyYiJBA
vec2 hextile(inout vec2 p) {
const vec2 sz = vec2(1.0, sqrt(3.0)); const vec2 hsz = 0.5*sz; vec2 p1 = mod(p, sz)-hsz; vec2 p2 = mod(p - hsz, sz)-hsz; vec2 p3 = dot(p1, p1) < dot(p2, p2) ? p1 : p2; vec2 n = ((p3 - p + hsz)/sz); p = p3; n -= vec2(0.5); // Rounding to make hextile 0,0 well behaved return round(n*2.0)*0.5; }
// License: Unknown, author: Martijn Steinrucken, found: https://www.youtube.com/watch?v=VmrIDyYiJBA vec2 hextile(inout vec2 p) {
21
24
NstGDM
iq
2022-07-04T09:11:38
// The MIT License // Copyright © 2022 Inigo Quilez // Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. // Compressing images with noise. // // I was thinking, why not use Perlin Noise as activation function // for a classic multi-layer perceptron network? If ReLUs and sine // waves work, any non linear thing must just work. Including some // noise (ie, a differentiable, stochastic oscillating signal, not // the "noise" of signal processing). Unlike sin waves, the search // space is way larger since noise isn't periodic. Also, feel free // to call this NOREN (Noise Representation Network). // // This is the quick experiment referred here a year ago // https://twitter.com/iquilezles/status/1432429955527237632 // which I never got the time to write about. // // I trained the network with a little C program I wrote, so I am // confident you can beat it by a lot with a proper ML framework. // // As said, the network is a regular multi-layer perceptron, with // { 2, 64, 32, 16, 8, 1 } layers and a total of 2945 parameters. // The activation noise function is this one I developed here: // https://www.shadertoy.com/view/3sd3Rs // noise, https://www.shadertoy.com/view/3sd3Rs float fun( in float x ) { float i = floor(x); float f = fract(x); float k = fract(i*0.1731)*16.0-4.0; f *= f-1.0; f *= k*f-1.0; f *= sign(fract(x/2.0)-0.5); return f; } // network void mainImage(out vec4 fragColor, in vec2 fragCoord) { // --- layer 0 : input --------------- float v_0_0 = fragCoord.x/iResolution.x; float v_0_1 = fragCoord.y/iResolution.y; // --- layer 1 ----------------------- float v_1_00 = fun( 12.651764*v_0_0 +1.339055*v_0_1-23.754999); float v_1_01 = fun( -0.532269*v_0_0 -8.396215*v_0_1+23.099752); float v_1_02 = fun(-12.253928*v_0_0+22.502775*v_0_1-24.686695); float v_1_03 = fun( 17.924093*v_0_0-18.237402*v_0_1-14.419626); float v_1_04 = fun(-22.862108*v_0_0-15.147194*v_0_1-15.151608); float v_1_05 = fun( -9.650509*v_0_0-14.831182*v_0_1+20.137722); float v_1_06 = fun( -8.004325*v_0_0 -0.475607*v_0_1+20.921373); float v_1_07 = fun( 7.464520*v_0_0 +1.960937*v_0_1+4.899765); float v_1_08 = fun(-10.973597*v_0_0+18.677485*v_0_1-6.463108); float v_1_09 = fun(-23.755060*v_0_0+19.067633*v_0_1-13.359839); float v_1_10 = fun( 9.192753*v_0_0+20.252661*v_0_1+16.834564); float v_1_11 = fun( 7.906412*v_0_0+14.221536*v_0_1+7.045158); float v_1_12 = fun(-10.764951*v_0_0 +1.050687*v_0_1-12.406633); float v_1_13 = fun( 14.603448*v_0_0+24.272823*v_0_1+4.524347); float v_1_14 = fun( 5.894300*v_0_0 -2.107377*v_0_1-1.927901); float v_1_15 = fun( 3.901146*v_0_0 +1.269753*v_0_1+23.912832); float v_1_16 = fun( -7.028045*v_0_0+19.630928*v_0_1+5.540376); float v_1_17 = fun( -0.534545*v_0_0+14.446243*v_0_1-17.512001); float v_1_18 = fun( -2.202332*v_0_0+10.817842*v_0_1-19.685925); float v_1_19 = fun( -5.548895*v_0_0 -0.556134*v_0_1+12.383915); float v_1_20 = fun( 4.818054*v_0_0 +3.885520*v_0_1-18.928185); float v_1_21 = fun(-19.688728*v_0_0 -6.919561*v_0_1+19.978441); float v_1_22 = fun( -9.321958*v_0_0-20.376427*v_0_1+8.881976); float v_1_23 = fun(-20.164150*v_0_0-13.801070*v_0_1+1.050954); float v_1_24 = fun(-11.437829*v_0_0 +6.469597*v_0_1+13.477356); float v_1_25 = fun( 11.655347*v_0_0 +8.145976*v_0_1+8.415142); float v_1_26 = fun(-10.880453*v_0_0 +0.682798*v_0_1+17.531200); float v_1_27 = fun(-13.601298*v_0_0-21.871817*v_0_1-0.502928); float v_1_28 = fun(-14.981379*v_0_0+21.467344*v_0_1-3.321391); float v_1_29 = fun(-20.798067*v_0_0+17.810989*v_0_1-6.143041); float v_1_30 = fun( -8.127576*v_0_0-20.133320*v_0_1+3.440520); float v_1_31 = fun( 0.758812*v_0_0+10.336716*v_0_1-18.378170); float v_1_32 = fun( 13.717178*v_0_0 +4.189069*v_0_1-10.929428); float v_1_33 = fun( 20.781424*v_0_0+13.521489*v_0_1-20.092876); float v_1_34 = fun( 12.257710*v_0_0 -3.714963*v_0_1-17.730146); float v_1_35 = fun(-15.930890*v_0_0-11.382194*v_0_1+18.150429); float v_1_36 = fun( 7.444907*v_0_0+10.940384*v_0_1+1.030603); float v_1_37 = fun( 17.040625*v_0_0+15.649309*v_0_1+5.114138); float v_1_38 = fun( 9.930554*v_0_0-16.405514*v_0_1+20.695515); float v_1_39 = fun( 6.665332*v_0_0+18.455132*v_0_1+12.971514); float v_1_40 = fun( 23.615326*v_0_0+10.625115*v_0_1-10.179976); float v_1_41 = fun(-20.110067*v_0_0 +2.001038*v_0_1+8.840239); float v_1_42 = fun(-18.800917*v_0_0+23.278751*v_0_1+23.994085); float v_1_43 = fun( 22.557316*v_0_0-20.167139*v_0_1-6.057110); float v_1_44 = fun(-20.584620*v_0_0 -8.592924*v_0_1+9.116179); float v_1_45 = fun( 23.096958*v_0_0+20.168434*v_0_1-21.596998); float v_1_46 = fun( -7.976181*v_0_0+20.527336*v_0_1-18.099480); float v_1_47 = fun( -5.720318*v_0_0-12.690313*v_0_1-8.031078); float v_1_48 = fun( 17.160139*v_0_0 +2.665666*v_0_1-18.810461); float v_1_49 = fun(-11.865465*v_0_0-16.981085*v_0_1-19.168430); float v_1_50 = fun( -2.159684*v_0_0 +4.667675*v_0_1+3.735635); float v_1_51 = fun( -8.529593*v_0_0 -8.495744*v_0_1+19.751242); float v_1_52 = fun( 18.633884*v_0_0 +9.868877*v_0_1-1.110809); float v_1_53 = fun( -7.546693*v_0_0 -0.406618*v_0_1-7.886292); float v_1_54 = fun( 13.809946*v_0_0 +7.604858*v_0_1-23.396351); float v_1_55 = fun(-16.146168*v_0_0 +6.536390*v_0_1-7.000743); float v_1_56 = fun(-14.457527*v_0_0 -0.539393*v_0_1-3.365755); float v_1_57 = fun(-19.274729*v_0_0 +2.786475*v_0_1-10.144519); float v_1_58 = fun(-15.128548*v_0_0-21.821358*v_0_1+17.020514); float v_1_59 = fun( 20.561825*v_0_0 -8.012662*v_0_1+3.237656); float v_1_60 = fun(-22.853487*v_0_0 +0.398873*v_0_1+15.676755); float v_1_61 = fun( 18.068533*v_0_0-17.750360*v_0_1-3.100729); float v_1_62 = fun( 23.743105*v_0_0 -7.714730*v_0_1-15.557582); float v_1_63 = fun( 6.675613*v_0_0+11.700735*v_0_1-2.029474); // --- layer 2 ----------------------- float v_2_00 = fun(-0.044525*v_1_00+0.115868*v_1_01-0.035576*v_1_02+0.027339*v_1_03+0.015867*v_1_04+0.022896*v_1_05+0.039554*v_1_06-0.169480*v_1_07+0.031006*v_1_08+0.044222*v_1_09-0.004297*v_1_10+0.025188*v_1_11-0.437089*v_1_12-0.038434*v_1_13-0.082501*v_1_14-0.169753*v_1_15+0.020257*v_1_16+0.111858*v_1_17-0.051250*v_1_18+0.119436*v_1_19+0.203302*v_1_20+0.170197*v_1_21+0.068203*v_1_22-0.015849*v_1_23-0.195028*v_1_24+0.038735*v_1_25-0.087068*v_1_26+0.030674*v_1_27+0.027934*v_1_28+0.036769*v_1_29-0.029686*v_1_30-0.099598*v_1_31+0.185609*v_1_32+0.077544*v_1_33-0.001495*v_1_34-0.096777*v_1_35-0.077638*v_1_36+0.006687*v_1_37+0.025782*v_1_38+0.045049*v_1_39+0.011980*v_1_40-0.067470*v_1_41+0.005923*v_1_42-0.031544*v_1_43+0.002367*v_1_44-0.017811*v_1_45-0.044148*v_1_46-0.001016*v_1_47+0.333579*v_1_48+0.035056*v_1_49-0.033190*v_1_50-0.078993*v_1_51+0.069724*v_1_52+0.014914*v_1_53+0.067980*v_1_54+0.003039*v_1_55-0.208939*v_1_56+0.097293*v_1_57-0.000224*v_1_58+0.144430*v_1_59+0.032889*v_1_60-0.085943*v_1_61+0.029325*v_1_62-0.019159*v_1_63+0.064850); float v_2_01 = fun( 0.085992*v_1_00+0.205653*v_1_01-0.053559*v_1_02-0.075332*v_1_03+0.037484*v_1_04-0.082075*v_1_05-0.000862*v_1_06+0.081010*v_1_07-0.015090*v_1_08+0.010667*v_1_09-0.025403*v_1_10-0.133320*v_1_11-0.053244*v_1_12+0.041927*v_1_13+0.498567*v_1_14+0.243247*v_1_15+0.020366*v_1_16+0.035310*v_1_17+0.003063*v_1_18-0.169640*v_1_19+0.108635*v_1_20+0.021393*v_1_21+0.104203*v_1_22+0.016613*v_1_23-0.106106*v_1_24+0.076009*v_1_25+0.084641*v_1_26-0.092887*v_1_27-0.032172*v_1_28+0.001252*v_1_29+0.004446*v_1_30+0.041510*v_1_31-0.068689*v_1_32-0.075427*v_1_33-0.053876*v_1_34-0.117501*v_1_35+0.034715*v_1_36+0.038847*v_1_37-0.086056*v_1_38-0.075281*v_1_39-0.004249*v_1_40-0.096576*v_1_41-0.023905*v_1_42+0.079087*v_1_43+0.034240*v_1_44+0.034465*v_1_45-0.031142*v_1_46+0.044658*v_1_47-0.147024*v_1_48-0.053687*v_1_49-0.135732*v_1_50-0.049481*v_1_51-0.034369*v_1_52-0.027767*v_1_53+0.066915*v_1_54-0.193987*v_1_55+0.022023*v_1_56+0.100757*v_1_57+0.022187*v_1_58-0.139774*v_1_59+0.058295*v_1_60+0.036765*v_1_61-0.082648*v_1_62-0.136839*v_1_63+0.092278); float v_2_02 = fun(-0.127209*v_1_00+0.065225*v_1_01-0.056975*v_1_02+0.052557*v_1_03-0.074556*v_1_04-0.052306*v_1_05-0.324635*v_1_06-0.090682*v_1_07-0.103687*v_1_08-0.022151*v_1_09-0.041096*v_1_10-0.075392*v_1_11-0.270524*v_1_12+0.014113*v_1_13-0.070891*v_1_14-0.172151*v_1_15+0.025130*v_1_16-0.049420*v_1_17+0.053585*v_1_18-0.202775*v_1_19-0.056114*v_1_20-0.238883*v_1_21+0.129495*v_1_22+0.001273*v_1_23-0.126285*v_1_24-0.012618*v_1_25+0.173209*v_1_26-0.011349*v_1_27+0.050094*v_1_28-0.011544*v_1_29+0.083887*v_1_30+0.017274*v_1_31-0.113601*v_1_32-0.040849*v_1_33+0.097738*v_1_34-0.148567*v_1_35+0.098479*v_1_36-0.068012*v_1_37-0.026094*v_1_38-0.040769*v_1_39-0.037829*v_1_40-0.193376*v_1_41+0.044405*v_1_42-0.068566*v_1_43+0.029461*v_1_44-0.001436*v_1_45+0.000594*v_1_46+0.141620*v_1_47-0.087259*v_1_48-0.028868*v_1_49-0.016243*v_1_50+0.457991*v_1_51+0.150156*v_1_52-0.194628*v_1_53-0.022515*v_1_54+0.029254*v_1_55-0.059812*v_1_56-0.101218*v_1_57-0.030081*v_1_58-0.082407*v_1_59+0.003820*v_1_60+0.024786*v_1_61+0.075422*v_1_62+0.085187*v_1_63-0.007961); float v_2_03 = fun( 0.043561*v_1_00+0.103728*v_1_01-0.014765*v_1_02-0.007922*v_1_03-0.021944*v_1_04+0.004805*v_1_05+0.203720*v_1_06-0.198465*v_1_07-0.011335*v_1_08+0.024568*v_1_09+0.014230*v_1_10+0.016075*v_1_11-0.128696*v_1_12-0.044283*v_1_13-0.039055*v_1_14+0.133844*v_1_15-0.054472*v_1_16+0.104392*v_1_17-0.105933*v_1_18-0.276674*v_1_19-0.001262*v_1_20+0.012153*v_1_21-0.000153*v_1_22+0.115850*v_1_23-0.058406*v_1_24-0.009838*v_1_25-0.271043*v_1_26-0.047843*v_1_27-0.006785*v_1_28+0.020373*v_1_29-0.002165*v_1_30+0.177880*v_1_31+0.096860*v_1_32-0.030319*v_1_33-0.048030*v_1_34+0.053012*v_1_35+0.093970*v_1_36+0.006791*v_1_37-0.127931*v_1_38-0.025170*v_1_39-0.056277*v_1_40-0.090330*v_1_41-0.063819*v_1_42-0.042224*v_1_43-0.111293*v_1_44+0.002892*v_1_45-0.057016*v_1_46+0.098001*v_1_47-0.024162*v_1_48+0.028837*v_1_49+0.065524*v_1_50+0.011087*v_1_51+0.065933*v_1_52-0.024707*v_1_53-0.229571*v_1_54-0.006999*v_1_55+0.117027*v_1_56+0.024293*v_1_57-0.026667*v_1_58-0.040759*v_1_59-0.011486*v_1_60+0.009570*v_1_61-0.044660*v_1_62-0.021106*v_1_63-0.131698); float v_2_04 = fun( 0.068916*v_1_00-0.056187*v_1_01-0.083925*v_1_02-0.030404*v_1_03+0.074165*v_1_04-0.013949*v_1_05-0.114450*v_1_06+0.038914*v_1_07+0.000601*v_1_08-0.028590*v_1_09-0.036830*v_1_10+0.009743*v_1_11+0.270937*v_1_12-0.016449*v_1_13-0.066408*v_1_14+0.151630*v_1_15-0.061993*v_1_16-0.033557*v_1_17-0.014451*v_1_18-0.199938*v_1_19-0.107729*v_1_20-0.168311*v_1_21-0.072904*v_1_22-0.029236*v_1_23+0.062262*v_1_24+0.018318*v_1_25-0.056614*v_1_26-0.035537*v_1_27-0.005170*v_1_28-0.024719*v_1_29-0.071641*v_1_30+0.196137*v_1_31-0.145898*v_1_32+0.024779*v_1_33+0.181902*v_1_34+0.029270*v_1_35-0.048335*v_1_36-0.050959*v_1_37-0.007753*v_1_38-0.029827*v_1_39-0.037985*v_1_40+0.028145*v_1_41+0.066963*v_1_42+0.011681*v_1_43+0.053097*v_1_44-0.098342*v_1_45+0.081099*v_1_46-0.099549*v_1_47+0.152579*v_1_48-0.106578*v_1_49+0.011003*v_1_50+0.113793*v_1_51-0.122793*v_1_52+0.085224*v_1_53-0.079507*v_1_54-0.054002*v_1_55+0.149172*v_1_56-0.012336*v_1_57+0.012771*v_1_58-0.117302*v_1_59+0.095892*v_1_60-0.038606*v_1_61-0.021617*v_1_62+0.076835*v_1_63-0.040366); float v_2_05 = fun( 0.116964*v_1_00-0.041162*v_1_01+0.014651*v_1_02-0.056107*v_1_03-0.059145*v_1_04-0.077622*v_1_05-0.268724*v_1_06-0.134324*v_1_07-0.055725*v_1_08-0.025782*v_1_09-0.010396*v_1_10-0.049224*v_1_11-0.217466*v_1_12+0.008592*v_1_13-0.058990*v_1_14+0.029188*v_1_15+0.072704*v_1_16-0.037670*v_1_17+0.005817*v_1_18+0.109588*v_1_19-0.115937*v_1_20+0.149483*v_1_21+0.048569*v_1_22-0.038552*v_1_23+0.073754*v_1_24-0.050677*v_1_25+0.035677*v_1_26-0.011170*v_1_27+0.033516*v_1_28-0.014033*v_1_29-0.000624*v_1_30-0.090845*v_1_31+0.020498*v_1_32+0.000211*v_1_33+0.070077*v_1_34-0.025147*v_1_35-0.186809*v_1_36+0.067344*v_1_37-0.035309*v_1_38-0.022144*v_1_39-0.019433*v_1_40+0.003882*v_1_41-0.029886*v_1_42-0.008913*v_1_43-0.016018*v_1_44+0.007118*v_1_45+0.026850*v_1_46-0.015412*v_1_47-0.145883*v_1_48-0.008495*v_1_49-0.215282*v_1_50-0.108235*v_1_51+0.039193*v_1_52-0.471203*v_1_53-0.030101*v_1_54-0.085238*v_1_55-0.114731*v_1_56-0.060247*v_1_57+0.056936*v_1_58-0.060115*v_1_59-0.128227*v_1_60+0.016342*v_1_61+0.036467*v_1_62-0.106037*v_1_63+0.279289); float v_2_06 = fun( 0.109230*v_1_00+0.078372*v_1_01-0.018636*v_1_02-0.029131*v_1_03+0.027303*v_1_04-0.044817*v_1_05+0.129715*v_1_06+0.343596*v_1_07-0.007394*v_1_08+0.036945*v_1_09-0.028737*v_1_10+0.006490*v_1_11+0.160583*v_1_12-0.022513*v_1_13-0.220929*v_1_14+0.129579*v_1_15+0.013360*v_1_16+0.020161*v_1_17-0.058713*v_1_18-0.237086*v_1_19+0.242633*v_1_20+0.022790*v_1_21-0.057628*v_1_22-0.045872*v_1_23-0.066223*v_1_24+0.006318*v_1_25-0.147093*v_1_26-0.024223*v_1_27-0.040515*v_1_28-0.025714*v_1_29-0.011629*v_1_30+0.042925*v_1_31+0.077983*v_1_32+0.022331*v_1_33+0.103722*v_1_34-0.054089*v_1_35-0.019024*v_1_36+0.057139*v_1_37-0.111831*v_1_38+0.067253*v_1_39+0.099102*v_1_40+0.135182*v_1_41+0.010571*v_1_42-0.017970*v_1_43+0.032068*v_1_44-0.033492*v_1_45-0.028049*v_1_46-0.037449*v_1_47+0.172682*v_1_48+0.016097*v_1_49+0.049245*v_1_50-0.096760*v_1_51-0.088336*v_1_52+0.231941*v_1_53+0.066014*v_1_54-0.042505*v_1_55+0.108459*v_1_56-0.137289*v_1_57-0.020837*v_1_58+0.000274*v_1_59-0.012707*v_1_60+0.023851*v_1_61-0.001153*v_1_62-0.083715*v_1_63-0.045738); float v_2_07 = fun(-0.049054*v_1_00-0.064092*v_1_01-0.009303*v_1_02+0.091048*v_1_03+0.041963*v_1_04+0.071571*v_1_05-0.116161*v_1_06-0.009199*v_1_07-0.028050*v_1_08+0.109007*v_1_09+0.035222*v_1_10+0.052942*v_1_11-0.256152*v_1_12-0.015888*v_1_13+0.032352*v_1_14+0.215416*v_1_15-0.113211*v_1_16-0.038637*v_1_17+0.160005*v_1_18+0.204943*v_1_19-0.084699*v_1_20+0.169729*v_1_21-0.070630*v_1_22-0.155203*v_1_23+0.099114*v_1_24-0.082160*v_1_25+0.348775*v_1_26+0.075367*v_1_27+0.065602*v_1_28-0.059847*v_1_29-0.070868*v_1_30+0.102799*v_1_31+0.103740*v_1_32-0.008684*v_1_33-0.038303*v_1_34+0.028744*v_1_35+0.046329*v_1_36+0.035560*v_1_37-0.026201*v_1_38-0.031817*v_1_39-0.008845*v_1_40+0.045956*v_1_41-0.004966*v_1_42-0.040434*v_1_43-0.025753*v_1_44+0.012081*v_1_45+0.141337*v_1_46+0.077079*v_1_47+0.219484*v_1_48+0.087629*v_1_49-0.016214*v_1_50+0.045452*v_1_51-0.088374*v_1_52-0.003001*v_1_53+0.021538*v_1_54+0.116217*v_1_55+0.194081*v_1_56+0.064589*v_1_57+0.008192*v_1_58+0.026659*v_1_59+0.087408*v_1_60+0.034451*v_1_61+0.088239*v_1_62+0.063672*v_1_63-0.011650); float v_2_08 = fun(-0.000891*v_1_00+0.037174*v_1_01+0.035635*v_1_02+0.013455*v_1_03-0.069656*v_1_04-0.026386*v_1_05+0.154870*v_1_06-0.124133*v_1_07-0.060302*v_1_08+0.075157*v_1_09+0.064238*v_1_10+0.033930*v_1_11+0.142169*v_1_12-0.034823*v_1_13-0.141791*v_1_14+0.308062*v_1_15+0.071166*v_1_16-0.101051*v_1_17+0.148833*v_1_18-0.237508*v_1_19-0.007577*v_1_20+0.058586*v_1_21-0.008530*v_1_22+0.119090*v_1_23+0.109259*v_1_24-0.074080*v_1_25-0.173627*v_1_26-0.001551*v_1_27+0.045630*v_1_28-0.154267*v_1_29-0.071145*v_1_30+0.028686*v_1_31+0.138934*v_1_32-0.046134*v_1_33-0.205212*v_1_34-0.005224*v_1_35-0.066314*v_1_36-0.004673*v_1_37-0.046198*v_1_38+0.033970*v_1_39-0.076263*v_1_40-0.067474*v_1_41-0.053773*v_1_42-0.030688*v_1_43+0.000307*v_1_44+0.053086*v_1_45-0.038117*v_1_46+0.279037*v_1_47-0.013427*v_1_48+0.112147*v_1_49-0.138102*v_1_50+0.070978*v_1_51-0.069293*v_1_52+0.065393*v_1_53+0.126960*v_1_54+0.005318*v_1_55-0.069379*v_1_56-0.077873*v_1_57-0.064549*v_1_58-0.034743*v_1_59-0.075528*v_1_60+0.069086*v_1_61-0.125627*v_1_62+0.086342*v_1_63-0.046347); float v_2_09 = fun(-0.032540*v_1_00-0.137541*v_1_01+0.101021*v_1_02+0.040863*v_1_03+0.121088*v_1_04+0.031102*v_1_05-0.040727*v_1_06+0.130902*v_1_07+0.081037*v_1_08+0.073079*v_1_09-0.065653*v_1_10-0.083753*v_1_11-0.137497*v_1_12-0.076455*v_1_13+0.177779*v_1_14-0.196471*v_1_15+0.014860*v_1_16+0.021566*v_1_17+0.151096*v_1_18-0.113111*v_1_19-0.032137*v_1_20+0.078012*v_1_21-0.091503*v_1_22-0.098476*v_1_23+0.130862*v_1_24+0.095748*v_1_25+0.018123*v_1_26+0.030106*v_1_27-0.048689*v_1_28+0.015594*v_1_29+0.072637*v_1_30-0.135748*v_1_31+0.245782*v_1_32+0.051858*v_1_33-0.113820*v_1_34+0.048778*v_1_35-0.077600*v_1_36-0.043569*v_1_37-0.009787*v_1_38-0.058587*v_1_39+0.003101*v_1_40+0.138477*v_1_41-0.030714*v_1_42+0.007233*v_1_43+0.021504*v_1_44+0.017412*v_1_45-0.043149*v_1_46+0.064261*v_1_47-0.030618*v_1_48+0.018059*v_1_49-0.092716*v_1_50-0.037081*v_1_51-0.039639*v_1_52-0.244125*v_1_53-0.137004*v_1_54-0.023565*v_1_55-0.113035*v_1_56-0.157926*v_1_57+0.042674*v_1_58-0.053496*v_1_59-0.069275*v_1_60-0.002082*v_1_61+0.141601*v_1_62+0.124829*v_1_63-0.061572); float v_2_10 = fun( 0.290386*v_1_00-0.055151*v_1_01-0.012646*v_1_02-0.039341*v_1_03-0.025366*v_1_04-0.034720*v_1_05-0.057582*v_1_06-0.224825*v_1_07-0.061306*v_1_08+0.003922*v_1_09+0.033667*v_1_10-0.050187*v_1_11-0.055425*v_1_12+0.010525*v_1_13-0.107164*v_1_14+0.020638*v_1_15+0.031683*v_1_16+0.047446*v_1_17+0.103024*v_1_18-0.122056*v_1_19-0.058516*v_1_20+0.048436*v_1_21-0.000058*v_1_22+0.045718*v_1_23-0.009659*v_1_24-0.037452*v_1_25-0.117138*v_1_26-0.042320*v_1_27+0.021043*v_1_28-0.020780*v_1_29+0.010015*v_1_30-0.043874*v_1_31-0.062205*v_1_32-0.086181*v_1_33+0.120951*v_1_34-0.018674*v_1_35-0.051633*v_1_36+0.016197*v_1_37-0.064681*v_1_38-0.005301*v_1_39-0.024871*v_1_40-0.049132*v_1_41+0.020755*v_1_42-0.005837*v_1_43+0.074336*v_1_44-0.057820*v_1_45-0.060769*v_1_46+0.072127*v_1_47-0.255633*v_1_48-0.073757*v_1_49+0.159994*v_1_50+0.031299*v_1_51-0.076716*v_1_52+0.231272*v_1_53-0.039419*v_1_54+0.006703*v_1_55+0.051666*v_1_56+0.022057*v_1_57-0.074899*v_1_58-0.063821*v_1_59+0.002305*v_1_60-0.036243*v_1_61-0.016563*v_1_62+0.002557*v_1_63-0.031302); float v_2_11 = fun( 0.026524*v_1_00-0.045045*v_1_01+0.002808*v_1_02-0.037124*v_1_03+0.013424*v_1_04-0.019687*v_1_05+0.103888*v_1_06-0.035798*v_1_07+0.003701*v_1_08-0.011704*v_1_09+0.004628*v_1_10-0.071057*v_1_11-0.008859*v_1_12+0.000584*v_1_13+0.190465*v_1_14+0.209680*v_1_15-0.036645*v_1_16-0.095986*v_1_17+0.071253*v_1_18+0.039880*v_1_19-0.082014*v_1_20+0.046031*v_1_21-0.017396*v_1_22-0.037866*v_1_23-0.020641*v_1_24+0.021218*v_1_25+0.121622*v_1_26+0.030982*v_1_27-0.003318*v_1_28+0.018139*v_1_29+0.053375*v_1_30+0.101832*v_1_31-0.146065*v_1_32-0.061475*v_1_33-0.038460*v_1_34+0.010538*v_1_35-0.001573*v_1_36-0.077988*v_1_37+0.151403*v_1_38+0.024668*v_1_39+0.014445*v_1_40+0.037147*v_1_41+0.048779*v_1_42+0.034143*v_1_43+0.059742*v_1_44-0.011403*v_1_45+0.084758*v_1_46+0.012009*v_1_47+0.007174*v_1_48-0.004666*v_1_49+0.059770*v_1_50+0.115192*v_1_51+0.030357*v_1_52-0.207609*v_1_53-0.027997*v_1_54+0.021363*v_1_55+0.099245*v_1_56+0.080460*v_1_57+0.065775*v_1_58+0.033129*v_1_59+0.044693*v_1_60-0.048957*v_1_61-0.077817*v_1_62+0.036288*v_1_63-0.066653); float v_2_12 = fun(-0.070386*v_1_00+0.052948*v_1_01-0.042500*v_1_02+0.047282*v_1_03+0.025260*v_1_04+0.131321*v_1_05-0.257915*v_1_06+0.099309*v_1_07-0.089104*v_1_08-0.028367*v_1_09+0.079093*v_1_10-0.078358*v_1_11-0.036319*v_1_12+0.130834*v_1_13-0.359926*v_1_14+0.039374*v_1_15-0.004614*v_1_16+0.082259*v_1_17-0.123608*v_1_18-0.110275*v_1_19+0.001329*v_1_20+0.002514*v_1_21+0.023275*v_1_22+0.073062*v_1_23-0.213277*v_1_24+0.014087*v_1_25-0.067947*v_1_26+0.031123*v_1_27-0.008709*v_1_28-0.101559*v_1_29+0.054124*v_1_30-0.024036*v_1_31+0.005426*v_1_32-0.176637*v_1_33-0.239188*v_1_34-0.027527*v_1_35+0.106400*v_1_36+0.205420*v_1_37-0.013339*v_1_38+0.043838*v_1_39-0.055377*v_1_40+0.113929*v_1_41+0.052142*v_1_42-0.032742*v_1_43+0.096733*v_1_44-0.067038*v_1_45+0.024640*v_1_46+0.029677*v_1_47-0.057010*v_1_48-0.077632*v_1_49+0.255702*v_1_50-0.213174*v_1_51-0.141738*v_1_52-0.031315*v_1_53+0.150495*v_1_54+0.122954*v_1_55-0.062877*v_1_56-0.202118*v_1_57-0.026556*v_1_58+0.135034*v_1_59-0.154258*v_1_60+0.004900*v_1_61-0.093458*v_1_62+0.145635*v_1_63+0.188409); float v_2_13 = fun( 0.102896*v_1_00+0.132588*v_1_01-0.026726*v_1_02+0.026576*v_1_03+0.008145*v_1_04+0.092777*v_1_05+0.001342*v_1_06-0.227200*v_1_07-0.006547*v_1_08+0.028998*v_1_09-0.009280*v_1_10-0.027162*v_1_11-0.105840*v_1_12-0.014192*v_1_13+0.097730*v_1_14-0.265727*v_1_15-0.046303*v_1_16-0.083002*v_1_17+0.094294*v_1_18+0.172596*v_1_19+0.036173*v_1_20+0.058732*v_1_21-0.035230*v_1_22-0.021967*v_1_23-0.046883*v_1_24-0.079157*v_1_25-0.070754*v_1_26-0.013511*v_1_27+0.005162*v_1_28+0.003202*v_1_29-0.054908*v_1_30-0.048946*v_1_31-0.080689*v_1_32-0.002217*v_1_33-0.053794*v_1_34-0.057295*v_1_35+0.043063*v_1_36-0.015499*v_1_37+0.041203*v_1_38-0.024652*v_1_39+0.015546*v_1_40+0.068395*v_1_41-0.072654*v_1_42-0.015718*v_1_43+0.099289*v_1_44-0.030368*v_1_45-0.017012*v_1_46-0.068940*v_1_47+0.103993*v_1_48+0.033860*v_1_49+0.018307*v_1_50-0.067980*v_1_51-0.038447*v_1_52+0.007678*v_1_53-0.049110*v_1_54+0.075390*v_1_55-0.128384*v_1_56-0.031055*v_1_57+0.093045*v_1_58+0.039915*v_1_59+0.010956*v_1_60-0.047911*v_1_61-0.071262*v_1_62-0.054446*v_1_63-0.194175); float v_2_14 = fun( 0.097249*v_1_00-0.107658*v_1_01+0.047073*v_1_02-0.028581*v_1_03-0.036623*v_1_04-0.129108*v_1_05-0.070894*v_1_06-0.123021*v_1_07-0.037279*v_1_08-0.012234*v_1_09-0.078434*v_1_10-0.007059*v_1_11-0.257766*v_1_12-0.014171*v_1_13-0.133103*v_1_14-0.208169*v_1_15+0.048927*v_1_16-0.087562*v_1_17-0.089354*v_1_18-0.050608*v_1_19+0.112024*v_1_20+0.001560*v_1_21+0.019680*v_1_22-0.200185*v_1_23+0.000350*v_1_24+0.130224*v_1_25-0.044145*v_1_26+0.030221*v_1_27+0.079815*v_1_28+0.022414*v_1_29+0.062566*v_1_30-0.071945*v_1_31-0.051269*v_1_32+0.102051*v_1_33+0.024576*v_1_34-0.015681*v_1_35-0.023085*v_1_36-0.055362*v_1_37-0.056835*v_1_38+0.054811*v_1_39-0.033753*v_1_40-0.040839*v_1_41+0.061439*v_1_42+0.009153*v_1_43-0.114843*v_1_44+0.072661*v_1_45+0.009317*v_1_46+0.040278*v_1_47+0.068560*v_1_48-0.101806*v_1_49+0.003109*v_1_50-0.034983*v_1_51-0.028217*v_1_52-0.074423*v_1_53-0.147630*v_1_54-0.107716*v_1_55+0.164659*v_1_56+0.035496*v_1_57-0.003968*v_1_58+0.068453*v_1_59+0.019834*v_1_60-0.028257*v_1_61+0.030428*v_1_62+0.021704*v_1_63-0.153423); float v_2_15 = fun( 0.318060*v_1_00-0.097002*v_1_01-0.017498*v_1_02-0.016142*v_1_03+0.018641*v_1_04-0.007036*v_1_05-0.134782*v_1_06+0.035184*v_1_07-0.063777*v_1_08-0.119002*v_1_09+0.143757*v_1_10-0.020829*v_1_11-0.070806*v_1_12+0.021214*v_1_13+0.067304*v_1_14-0.136263*v_1_15+0.048198*v_1_16+0.130174*v_1_17-0.162235*v_1_18-0.310550*v_1_19+0.047101*v_1_20+0.000390*v_1_21+0.036958*v_1_22+0.044357*v_1_23+0.150679*v_1_24-0.086537*v_1_25+0.061050*v_1_26+0.026752*v_1_27+0.033871*v_1_28+0.096044*v_1_29-0.062106*v_1_30-0.001273*v_1_31+0.141453*v_1_32-0.174016*v_1_33+0.089377*v_1_34+0.116798*v_1_35-0.089918*v_1_36+0.123172*v_1_37+0.128447*v_1_38-0.007015*v_1_39+0.018107*v_1_40+0.180308*v_1_41-0.085415*v_1_42-0.030752*v_1_43-0.131683*v_1_44-0.003770*v_1_45+0.015266*v_1_46+0.056423*v_1_47+0.029254*v_1_48+0.041463*v_1_49+0.106484*v_1_50+0.244691*v_1_51+0.097298*v_1_52-0.061043*v_1_53+0.070898*v_1_54-0.079493*v_1_55+0.202869*v_1_56+0.073435*v_1_57+0.037280*v_1_58-0.094291*v_1_59+0.049520*v_1_60-0.048514*v_1_61-0.161530*v_1_62+0.159415*v_1_63+0.024619); float v_2_16 = fun( 0.147201*v_1_00+0.034769*v_1_01-0.031108*v_1_02-0.030289*v_1_03+0.032987*v_1_04+0.035047*v_1_05+0.156383*v_1_06+0.053084*v_1_07-0.007473*v_1_08-0.004496*v_1_09+0.123424*v_1_10-0.005311*v_1_11+0.075165*v_1_12-0.025234*v_1_13+0.048587*v_1_14-0.070836*v_1_15-0.053717*v_1_16-0.060380*v_1_17-0.077900*v_1_18+0.533767*v_1_19-0.009047*v_1_20-0.021228*v_1_21-0.032255*v_1_22-0.016347*v_1_23-0.097184*v_1_24+0.016580*v_1_25-0.030301*v_1_26-0.009585*v_1_27-0.011768*v_1_28-0.043063*v_1_29-0.058895*v_1_30-0.001107*v_1_31-0.058639*v_1_32-0.031642*v_1_33+0.264479*v_1_34+0.113643*v_1_35-0.037472*v_1_36+0.006160*v_1_37+0.027431*v_1_38+0.044727*v_1_39-0.042013*v_1_40-0.086714*v_1_41+0.011766*v_1_42-0.011616*v_1_43+0.064697*v_1_44+0.031223*v_1_45-0.003964*v_1_46+0.020819*v_1_47+0.001451*v_1_48-0.059511*v_1_49-0.064650*v_1_50-0.141412*v_1_51-0.077150*v_1_52-0.135488*v_1_53+0.054462*v_1_54-0.037431*v_1_55-0.010287*v_1_56+0.026739*v_1_57+0.019533*v_1_58-0.115860*v_1_59+0.001498*v_1_60+0.019573*v_1_61-0.128926*v_1_62-0.021824*v_1_63-0.118782); float v_2_17 = fun( 0.095144*v_1_00-0.034258*v_1_01+0.015414*v_1_02+0.093834*v_1_03+0.009984*v_1_04-0.196997*v_1_05+0.078619*v_1_06-0.057782*v_1_07-0.076626*v_1_08-0.029486*v_1_09-0.055051*v_1_10-0.056482*v_1_11-0.116257*v_1_12-0.042562*v_1_13+0.095955*v_1_14+0.254019*v_1_15+0.125456*v_1_16+0.024856*v_1_17+0.072307*v_1_18+0.434768*v_1_19+0.286832*v_1_20+0.119274*v_1_21-0.059628*v_1_22-0.115188*v_1_23-0.102288*v_1_24-0.115091*v_1_25-0.024814*v_1_26-0.002879*v_1_27-0.108488*v_1_28+0.072857*v_1_29+0.023908*v_1_30-0.014248*v_1_31-0.095894*v_1_32-0.032524*v_1_33-0.130427*v_1_34+0.043149*v_1_35-0.038313*v_1_36-0.076181*v_1_37+0.150665*v_1_38+0.096981*v_1_39-0.091956*v_1_40+0.012699*v_1_41+0.046980*v_1_42+0.073128*v_1_43+0.084351*v_1_44-0.024285*v_1_45+0.057245*v_1_46+0.077333*v_1_47+0.050003*v_1_48-0.026704*v_1_49-0.053772*v_1_50+0.231248*v_1_51-0.046740*v_1_52-0.195443*v_1_53-0.178476*v_1_54-0.096862*v_1_55-0.084065*v_1_56-0.026103*v_1_57+0.131859*v_1_58-0.043820*v_1_59+0.059325*v_1_60-0.135251*v_1_61+0.075508*v_1_62+0.213230*v_1_63+0.112285); float v_2_18 = fun(-0.074823*v_1_00-0.008639*v_1_01-0.037473*v_1_02+0.020968*v_1_03+0.016166*v_1_04+0.051208*v_1_05+0.030274*v_1_06+0.151686*v_1_07+0.006597*v_1_08+0.040258*v_1_09+0.039151*v_1_10+0.089726*v_1_11+0.043513*v_1_12-0.000917*v_1_13-0.247656*v_1_14+0.659646*v_1_15-0.005295*v_1_16+0.072994*v_1_17-0.044763*v_1_18+0.062800*v_1_19-0.178046*v_1_20+0.095272*v_1_21+0.044849*v_1_22+0.020821*v_1_23-0.024507*v_1_24+0.115631*v_1_25-0.040357*v_1_26+0.030084*v_1_27-0.000434*v_1_28-0.000875*v_1_29+0.041111*v_1_30+0.004606*v_1_31-0.034878*v_1_32-0.016758*v_1_33+0.043220*v_1_34-0.072036*v_1_35+0.031581*v_1_36-0.029288*v_1_37-0.023722*v_1_38+0.080657*v_1_39-0.046068*v_1_40-0.005445*v_1_41+0.032326*v_1_42-0.037803*v_1_43+0.014747*v_1_44+0.017115*v_1_45-0.014810*v_1_46-0.023985*v_1_47-0.021938*v_1_48+0.007481*v_1_49+0.020594*v_1_50+0.142448*v_1_51+0.037638*v_1_52-0.048612*v_1_53-0.057975*v_1_54+0.053047*v_1_55+0.065897*v_1_56+0.036405*v_1_57-0.065867*v_1_58+0.027132*v_1_59-0.004833*v_1_60+0.047071*v_1_61-0.031596*v_1_62+0.076818*v_1_63-0.022958); float v_2_19 = fun( 0.095679*v_1_00-0.036472*v_1_01+0.052574*v_1_02+0.028556*v_1_03+0.026815*v_1_04-0.127829*v_1_05+0.060295*v_1_06+0.106021*v_1_07+0.048702*v_1_08-0.003575*v_1_09-0.029194*v_1_10+0.038937*v_1_11-0.053299*v_1_12-0.007953*v_1_13+0.170006*v_1_14+0.049977*v_1_15+0.012446*v_1_16+0.064353*v_1_17+0.131522*v_1_18-0.053832*v_1_19-0.145525*v_1_20-0.067829*v_1_21-0.078829*v_1_22+0.044281*v_1_23-0.016499*v_1_24+0.017302*v_1_25+0.125538*v_1_26+0.093448*v_1_27+0.024834*v_1_28+0.040568*v_1_29+0.153339*v_1_30+0.027570*v_1_31+0.120489*v_1_32-0.003057*v_1_33+0.020171*v_1_34-0.032555*v_1_35+0.039928*v_1_36+0.050188*v_1_37-0.114904*v_1_38+0.011750*v_1_39+0.036389*v_1_40+0.184682*v_1_41+0.022356*v_1_42+0.022414*v_1_43-0.087043*v_1_44-0.043563*v_1_45+0.039863*v_1_46-0.171541*v_1_47+0.082198*v_1_48+0.044386*v_1_49+0.113120*v_1_50+0.069231*v_1_51+0.090735*v_1_52+0.093352*v_1_53-0.083231*v_1_54-0.162849*v_1_55+0.092392*v_1_56-0.109702*v_1_57-0.013519*v_1_58+0.169150*v_1_59+0.035072*v_1_60+0.032225*v_1_61+0.013814*v_1_62-0.090252*v_1_63-0.129754); float v_2_20 = fun( 0.035495*v_1_00-0.034746*v_1_01-0.057071*v_1_02+0.077991*v_1_03+0.013007*v_1_04-0.130168*v_1_05+0.199667*v_1_06-0.048282*v_1_07-0.069962*v_1_08+0.004368*v_1_09+0.005981*v_1_10+0.077606*v_1_11+0.056434*v_1_12+0.027429*v_1_13-0.280157*v_1_14-0.200260*v_1_15-0.007444*v_1_16-0.168778*v_1_17-0.161652*v_1_18-0.172109*v_1_19+0.118138*v_1_20+0.080745*v_1_21+0.125826*v_1_22+0.056150*v_1_23-0.260738*v_1_24-0.083704*v_1_25+0.077948*v_1_26-0.029848*v_1_27-0.012768*v_1_28+0.093701*v_1_29+0.019933*v_1_30+0.066294*v_1_31+0.125842*v_1_32-0.079273*v_1_33+0.283108*v_1_34+0.033387*v_1_35+0.071962*v_1_36+0.006211*v_1_37-0.005184*v_1_38-0.139697*v_1_39-0.115251*v_1_40-0.084687*v_1_41-0.003867*v_1_42-0.024396*v_1_43-0.109638*v_1_44+0.131472*v_1_45-0.040307*v_1_46-0.049689*v_1_47-0.047194*v_1_48-0.037479*v_1_49+0.018213*v_1_50+0.127044*v_1_51-0.035110*v_1_52+0.046599*v_1_53+0.099048*v_1_54+0.036148*v_1_55-0.333003*v_1_56+0.115531*v_1_57-0.027569*v_1_58-0.141175*v_1_59-0.107419*v_1_60-0.046728*v_1_61-0.084667*v_1_62-0.039256*v_1_63-0.077893); float v_2_21 = fun(-0.145870*v_1_00-0.179397*v_1_01-0.001598*v_1_02+0.078662*v_1_03-0.017292*v_1_04-0.106816*v_1_05-0.082902*v_1_06+0.026821*v_1_07+0.109633*v_1_08+0.051771*v_1_09-0.066174*v_1_10-0.042033*v_1_11+0.017372*v_1_12-0.057279*v_1_13-0.487842*v_1_14+0.215429*v_1_15+0.046850*v_1_16+0.132580*v_1_17-0.032096*v_1_18+0.067209*v_1_19+0.051961*v_1_20-0.232110*v_1_21-0.026262*v_1_22-0.033424*v_1_23+0.086529*v_1_24+0.001596*v_1_25-0.041739*v_1_26+0.032346*v_1_27+0.010403*v_1_28+0.124268*v_1_29+0.038135*v_1_30-0.095907*v_1_31+0.077675*v_1_32+0.053996*v_1_33+0.106597*v_1_34+0.048009*v_1_35-0.003231*v_1_36+0.079841*v_1_37+0.020884*v_1_38+0.052181*v_1_39+0.033267*v_1_40+0.107384*v_1_41-0.064603*v_1_42+0.013943*v_1_43+0.012131*v_1_44-0.016179*v_1_45-0.070350*v_1_46-0.032281*v_1_47-0.166642*v_1_48+0.008364*v_1_49+0.177071*v_1_50-0.158398*v_1_51+0.173566*v_1_52-0.038086*v_1_53+0.028295*v_1_54-0.106559*v_1_55+0.131552*v_1_56-0.167748*v_1_57-0.044889*v_1_58+0.089807*v_1_59+0.013079*v_1_60-0.033965*v_1_61+0.058036*v_1_62+0.024121*v_1_63-0.129454); float v_2_22 = fun( 0.163506*v_1_00+0.116730*v_1_01+0.017614*v_1_02+0.079399*v_1_03-0.036294*v_1_04-0.017938*v_1_05+0.055932*v_1_06+0.219972*v_1_07+0.005499*v_1_08+0.034809*v_1_09+0.021454*v_1_10-0.007493*v_1_11-0.181407*v_1_12-0.044627*v_1_13+0.174083*v_1_14+0.105369*v_1_15-0.037037*v_1_16+0.058805*v_1_17+0.131395*v_1_18+0.000066*v_1_19-0.258702*v_1_20-0.052686*v_1_21-0.002926*v_1_22-0.000698*v_1_23+0.063669*v_1_24-0.041365*v_1_25+0.031462*v_1_26+0.003424*v_1_27+0.024556*v_1_28-0.005972*v_1_29+0.058226*v_1_30-0.008921*v_1_31-0.051907*v_1_32-0.011668*v_1_33-0.048709*v_1_34-0.012438*v_1_35-0.157490*v_1_36+0.065145*v_1_37+0.024894*v_1_38+0.074607*v_1_39+0.030731*v_1_40+0.056638*v_1_41-0.024184*v_1_42-0.045461*v_1_43+0.024914*v_1_44-0.096972*v_1_45+0.013692*v_1_46+0.053290*v_1_47-0.168386*v_1_48-0.004690*v_1_49-0.117601*v_1_50-0.067415*v_1_51+0.043451*v_1_52+0.183752*v_1_53-0.118766*v_1_54+0.024181*v_1_55+0.221312*v_1_56-0.031017*v_1_57+0.031752*v_1_58+0.012803*v_1_59+0.018574*v_1_60-0.107304*v_1_61-0.036710*v_1_62-0.076097*v_1_63+0.017912); float v_2_23 = fun( 0.021726*v_1_00+0.024698*v_1_01+0.051796*v_1_02-0.045750*v_1_03-0.039828*v_1_04+0.069389*v_1_05+0.038318*v_1_06-0.086662*v_1_07+0.053999*v_1_08+0.050428*v_1_09+0.016212*v_1_10+0.017871*v_1_11+0.060622*v_1_12-0.103163*v_1_13+0.156376*v_1_14-0.382265*v_1_15-0.064779*v_1_16-0.129881*v_1_17+0.179816*v_1_18-0.054466*v_1_19+0.167942*v_1_20+0.036257*v_1_21-0.052102*v_1_22+0.160203*v_1_23-0.030206*v_1_24+0.037662*v_1_25-0.227760*v_1_26+0.046208*v_1_27-0.013000*v_1_28-0.027015*v_1_29+0.021135*v_1_30+0.088139*v_1_31+0.057885*v_1_32-0.023003*v_1_33+0.063294*v_1_34-0.014417*v_1_35+0.033509*v_1_36-0.124639*v_1_37+0.030170*v_1_38-0.014527*v_1_39-0.087254*v_1_40-0.093705*v_1_41-0.059968*v_1_42-0.072205*v_1_43-0.226725*v_1_44+0.011781*v_1_45+0.033925*v_1_46+0.205980*v_1_47+0.074133*v_1_48-0.046433*v_1_49-0.147946*v_1_50+0.213612*v_1_51-0.012681*v_1_52-0.059909*v_1_53-0.091516*v_1_54+0.063973*v_1_55+0.243457*v_1_56+0.121418*v_1_57+0.050073*v_1_58+0.050494*v_1_59+0.068534*v_1_60-0.059785*v_1_61+0.033478*v_1_62-0.112038*v_1_63-0.128393); float v_2_24 = fun(-0.050544*v_1_00-0.180363*v_1_01+0.061462*v_1_02-0.071600*v_1_03+0.006621*v_1_04+0.179442*v_1_05+0.021326*v_1_06+0.050782*v_1_07-0.012582*v_1_08+0.042399*v_1_09+0.030369*v_1_10-0.043486*v_1_11-0.044804*v_1_12-0.071367*v_1_13-0.045773*v_1_14-0.001165*v_1_15-0.120713*v_1_16-0.024949*v_1_17+0.195363*v_1_18-0.193877*v_1_19+0.121901*v_1_20-0.147307*v_1_21+0.146943*v_1_22-0.128370*v_1_23+0.124716*v_1_24+0.176166*v_1_25+0.193454*v_1_26-0.057714*v_1_27-0.053509*v_1_28+0.022527*v_1_29+0.064206*v_1_30-0.131882*v_1_31-0.155334*v_1_32-0.097740*v_1_33+0.007541*v_1_34+0.033374*v_1_35-0.140058*v_1_36-0.065524*v_1_37+0.060766*v_1_38+0.018226*v_1_39-0.071659*v_1_40+0.006323*v_1_41+0.058930*v_1_42-0.083008*v_1_43+0.035524*v_1_44+0.036348*v_1_45-0.005736*v_1_46+0.058605*v_1_47-0.152259*v_1_48-0.096653*v_1_49-0.070626*v_1_50-0.018521*v_1_51-0.024582*v_1_52+0.027870*v_1_53+0.105787*v_1_54-0.052791*v_1_55-0.155543*v_1_56+0.042659*v_1_57-0.056554*v_1_58+0.103733*v_1_59-0.104800*v_1_60+0.065039*v_1_61+0.096187*v_1_62+0.044322*v_1_63+0.043559); float v_2_25 = fun(-0.143788*v_1_00-0.124667*v_1_01-0.126120*v_1_02+0.056341*v_1_03+0.071410*v_1_04-0.093629*v_1_05+0.162966*v_1_06-0.172463*v_1_07+0.100926*v_1_08+0.020944*v_1_09-0.004375*v_1_10+0.085489*v_1_11+0.202547*v_1_12+0.038963*v_1_13-0.014876*v_1_14+0.243997*v_1_15+0.012334*v_1_16-0.032969*v_1_17+0.031341*v_1_18+0.160123*v_1_19+0.122372*v_1_20-0.142253*v_1_21+0.044832*v_1_22-0.116035*v_1_23+0.001555*v_1_24+0.051855*v_1_25-0.068999*v_1_26-0.044933*v_1_27+0.029653*v_1_28+0.002120*v_1_29-0.003572*v_1_30-0.029879*v_1_31+0.180541*v_1_32-0.114006*v_1_33+0.064833*v_1_34-0.007295*v_1_35+0.011442*v_1_36-0.139765*v_1_37+0.024904*v_1_38-0.088994*v_1_39+0.077624*v_1_40-0.013598*v_1_41+0.013260*v_1_42+0.025051*v_1_43-0.096173*v_1_44+0.010820*v_1_45-0.032819*v_1_46-0.109230*v_1_47-0.208038*v_1_48+0.055067*v_1_49+0.130348*v_1_50-0.062290*v_1_51+0.149416*v_1_52-0.181755*v_1_53-0.042960*v_1_54-0.109323*v_1_55+0.010075*v_1_56-0.012195*v_1_57-0.027754*v_1_58+0.022066*v_1_59-0.018877*v_1_60+0.020224*v_1_61-0.060787*v_1_62-0.084639*v_1_63+0.167064); float v_2_26 = fun(-0.250008*v_1_00-0.133694*v_1_01+0.049802*v_1_02+0.020565*v_1_03-0.061965*v_1_04+0.004078*v_1_05-0.247580*v_1_06-0.172765*v_1_07+0.031031*v_1_08+0.029313*v_1_09+0.075740*v_1_10+0.015441*v_1_11+0.050413*v_1_12-0.017299*v_1_13+0.469505*v_1_14-0.488017*v_1_15-0.008758*v_1_16+0.019012*v_1_17-0.028467*v_1_18+0.002662*v_1_19+0.196276*v_1_20+0.026125*v_1_21-0.071135*v_1_22+0.103115*v_1_23-0.123745*v_1_24+0.135102*v_1_25-0.000806*v_1_26+0.021510*v_1_27+0.001487*v_1_28+0.035961*v_1_29-0.065339*v_1_30-0.029646*v_1_31+0.167113*v_1_32-0.028877*v_1_33-0.091073*v_1_34-0.039901*v_1_35-0.059825*v_1_36+0.061069*v_1_37+0.038106*v_1_38+0.103084*v_1_39+0.096507*v_1_40+0.078328*v_1_41-0.016708*v_1_42-0.007555*v_1_43-0.016339*v_1_44+0.000596*v_1_45+0.021349*v_1_46-0.101175*v_1_47-0.101273*v_1_48-0.057021*v_1_49-0.015717*v_1_50+0.199943*v_1_51-0.033852*v_1_52-0.245972*v_1_53-0.030291*v_1_54+0.190247*v_1_55+0.133671*v_1_56+0.077213*v_1_57+0.056085*v_1_58+0.064699*v_1_59-0.043193*v_1_60-0.023179*v_1_61-0.171582*v_1_62+0.043448*v_1_63-0.139438); float v_2_27 = fun( 0.042914*v_1_00-0.056391*v_1_01+0.042633*v_1_02+0.058883*v_1_03+0.049711*v_1_04+0.046266*v_1_05+0.397336*v_1_06-0.056700*v_1_07-0.016119*v_1_08+0.024251*v_1_09+0.059287*v_1_10-0.025932*v_1_11+0.128445*v_1_12-0.015435*v_1_13-0.061154*v_1_14+0.446170*v_1_15-0.040126*v_1_16-0.107514*v_1_17-0.075646*v_1_18+0.216301*v_1_19+0.120494*v_1_20-0.082604*v_1_21-0.018787*v_1_22+0.005329*v_1_23+0.044530*v_1_24+0.079088*v_1_25-0.025080*v_1_26-0.065861*v_1_27-0.018091*v_1_28-0.008258*v_1_29-0.088934*v_1_30-0.065546*v_1_31+0.016943*v_1_32-0.053246*v_1_33-0.093756*v_1_34+0.088500*v_1_35+0.030016*v_1_36+0.017786*v_1_37-0.040298*v_1_38-0.123512*v_1_39+0.001288*v_1_40+0.064996*v_1_41+0.004272*v_1_42-0.036213*v_1_43-0.171982*v_1_44+0.047645*v_1_45-0.053825*v_1_46-0.060183*v_1_47+0.183344*v_1_48+0.007293*v_1_49+0.087602*v_1_50-0.043304*v_1_51+0.022211*v_1_52+0.129382*v_1_53+0.006573*v_1_54+0.119095*v_1_55-0.040031*v_1_56+0.001212*v_1_57-0.011027*v_1_58+0.031518*v_1_59-0.018907*v_1_60+0.042672*v_1_61+0.042982*v_1_62+0.047723*v_1_63+0.015713); float v_2_28 = fun(-0.247434*v_1_00+0.087006*v_1_01-0.001838*v_1_02+0.103970*v_1_03+0.044078*v_1_04-0.035469*v_1_05+0.096247*v_1_06-0.221772*v_1_07+0.027120*v_1_08-0.013663*v_1_09+0.041071*v_1_10-0.096205*v_1_11+0.378040*v_1_12-0.040731*v_1_13-0.146890*v_1_14+0.057755*v_1_15+0.072481*v_1_16-0.025617*v_1_17+0.116804*v_1_18-0.012006*v_1_19+0.118558*v_1_20+0.099509*v_1_21-0.054052*v_1_22-0.029560*v_1_23+0.015257*v_1_24-0.018572*v_1_25+0.006983*v_1_26-0.023485*v_1_27-0.014802*v_1_28+0.033256*v_1_29+0.026986*v_1_30-0.046895*v_1_31+0.099273*v_1_32+0.132610*v_1_33+0.089164*v_1_34-0.012252*v_1_35-0.001675*v_1_36-0.022203*v_1_37+0.022235*v_1_38-0.090554*v_1_39-0.014280*v_1_40-0.233611*v_1_41-0.031846*v_1_42-0.034070*v_1_43-0.009919*v_1_44+0.010189*v_1_45-0.050531*v_1_46+0.049227*v_1_47-0.012636*v_1_48-0.024750*v_1_49-0.019146*v_1_50+0.097287*v_1_51+0.037336*v_1_52+0.164855*v_1_53+0.035434*v_1_54+0.145338*v_1_55-0.168737*v_1_56-0.028701*v_1_57-0.042239*v_1_58+0.038589*v_1_59+0.000372*v_1_60-0.013494*v_1_61-0.128969*v_1_62+0.048280*v_1_63-0.030141); float v_2_29 = fun( 0.015752*v_1_00-0.095414*v_1_01-0.025556*v_1_02-0.046414*v_1_03-0.020304*v_1_04+0.022741*v_1_05-0.044633*v_1_06-0.072512*v_1_07-0.082407*v_1_08+0.001178*v_1_09-0.056977*v_1_10+0.128317*v_1_11-0.142663*v_1_12+0.026767*v_1_13+0.118596*v_1_14+0.047216*v_1_15-0.000868*v_1_16+0.127119*v_1_17-0.008348*v_1_18-0.079873*v_1_19-0.053913*v_1_20-0.012249*v_1_21-0.018671*v_1_22-0.093717*v_1_23+0.057636*v_1_24+0.020238*v_1_25-0.045780*v_1_26-0.020037*v_1_27+0.011733*v_1_28-0.024091*v_1_29+0.059316*v_1_30+0.025354*v_1_31+0.019169*v_1_32-0.015251*v_1_33-0.029542*v_1_34-0.017117*v_1_35+0.032121*v_1_36+0.015890*v_1_37-0.149591*v_1_38+0.029245*v_1_39+0.036584*v_1_40+0.020786*v_1_41-0.008920*v_1_42+0.034699*v_1_43-0.075346*v_1_44-0.007095*v_1_45+0.047784*v_1_46-0.001412*v_1_47-0.033727*v_1_48+0.062673*v_1_49-0.020166*v_1_50-0.063980*v_1_51-0.077553*v_1_52-0.202349*v_1_53-0.144119*v_1_54-0.041573*v_1_55+0.122908*v_1_56+0.050519*v_1_57-0.128274*v_1_58-0.029806*v_1_59+0.044142*v_1_60+0.020201*v_1_61+0.099513*v_1_62-0.054130*v_1_63+0.006593); float v_2_30 = fun( 0.048807*v_1_00+0.026975*v_1_01-0.019485*v_1_02+0.004008*v_1_03+0.016719*v_1_04+0.047581*v_1_05+0.502410*v_1_06+0.160158*v_1_07+0.027909*v_1_08+0.046359*v_1_09-0.079433*v_1_10-0.053918*v_1_11-0.103968*v_1_12-0.003395*v_1_13+0.014385*v_1_14-0.173457*v_1_15-0.001820*v_1_16+0.012140*v_1_17+0.003838*v_1_18-0.226680*v_1_19+0.069451*v_1_20-0.034824*v_1_21+0.000264*v_1_22-0.086546*v_1_23-0.097731*v_1_24-0.065381*v_1_25+0.054259*v_1_26+0.025402*v_1_27-0.020453*v_1_28+0.002425*v_1_29-0.001751*v_1_30-0.092841*v_1_31+0.211274*v_1_32+0.005983*v_1_33+0.042153*v_1_34-0.097111*v_1_35+0.047695*v_1_36+0.077482*v_1_37-0.024398*v_1_38+0.054729*v_1_39-0.019457*v_1_40+0.088513*v_1_41-0.018716*v_1_42+0.055683*v_1_43+0.029142*v_1_44+0.024234*v_1_45-0.006112*v_1_46-0.028955*v_1_47+0.206247*v_1_48+0.074527*v_1_49-0.240541*v_1_50-0.090128*v_1_51-0.086299*v_1_52+0.026007*v_1_53+0.041443*v_1_54-0.044002*v_1_55+0.012283*v_1_56-0.002342*v_1_57+0.074317*v_1_58+0.014854*v_1_59-0.031060*v_1_60-0.031747*v_1_61+0.078449*v_1_62-0.009373*v_1_63-0.035445); float v_2_31 = fun(-0.222115*v_1_00+0.040301*v_1_01-0.016525*v_1_02+0.046240*v_1_03+0.100368*v_1_04+0.137614*v_1_05+0.160493*v_1_06-0.150416*v_1_07+0.005644*v_1_08-0.026327*v_1_09+0.079841*v_1_10+0.125470*v_1_11-0.021651*v_1_12-0.003291*v_1_13-0.111326*v_1_14-0.016486*v_1_15+0.029922*v_1_16-0.052471*v_1_17+0.058107*v_1_18+0.060459*v_1_19+0.089466*v_1_20+0.168591*v_1_21-0.091046*v_1_22+0.048474*v_1_23-0.005327*v_1_24-0.168475*v_1_25-0.629512*v_1_26+0.012670*v_1_27-0.122494*v_1_28-0.131098*v_1_29+0.002919*v_1_30-0.073231*v_1_31-0.085928*v_1_32-0.124500*v_1_33+0.056340*v_1_34-0.068095*v_1_35+0.176562*v_1_36-0.100797*v_1_37+0.044769*v_1_38-0.001113*v_1_39-0.106552*v_1_40-0.091171*v_1_41+0.042360*v_1_42+0.004133*v_1_43+0.100468*v_1_44-0.033907*v_1_45-0.091305*v_1_46-0.014356*v_1_47-0.027684*v_1_48+0.041259*v_1_49+0.025353*v_1_50-0.070525*v_1_51+0.035754*v_1_52+0.128852*v_1_53-0.080721*v_1_54+0.013834*v_1_55-0.213721*v_1_56+0.020273*v_1_57+0.054897*v_1_58+0.019326*v_1_59+0.085586*v_1_60+0.039246*v_1_61-0.043885*v_1_62-0.065694*v_1_63+0.200177); // --- layer 3 ----------------------- float v_3_00 = fun(-0.072429*v_2_00-0.052117*v_2_01-0.023910*v_2_02+0.203479*v_2_03-0.132919*v_2_04-0.349307*v_2_05+0.089661*v_2_06-0.078603*v_2_07+0.196552*v_2_08-0.067238*v_2_09+0.169480*v_2_10+0.155241*v_2_11-0.198106*v_2_12-0.085792*v_2_13-0.238174*v_2_14-0.163969*v_2_15-0.071988*v_2_16+0.027705*v_2_17-0.020056*v_2_18+0.246110*v_2_19+0.084463*v_2_20-0.094323*v_2_21-0.105242*v_2_22+0.044057*v_2_23+0.207527*v_2_24+0.282902*v_2_25+0.114393*v_2_26+0.173069*v_2_27+0.069312*v_2_28-0.001658*v_2_29+0.183876*v_2_30+0.038688*v_2_31-0.067231); float v_3_01 = fun( 0.279215*v_2_00+0.280494*v_2_01+0.321873*v_2_02-0.145595*v_2_03-0.034021*v_2_04+0.195307*v_2_05-0.234471*v_2_06+0.135093*v_2_07+0.035883*v_2_08+0.081551*v_2_09-0.219987*v_2_10+0.054182*v_2_11-0.238160*v_2_12+0.011234*v_2_13-0.085822*v_2_14-0.259100*v_2_15+0.366847*v_2_16+0.132563*v_2_17-0.228914*v_2_18+0.130180*v_2_19+0.149006*v_2_20+0.023534*v_2_21-0.103975*v_2_22-0.081088*v_2_23-0.025780*v_2_24-0.200678*v_2_25+0.378662*v_2_26-0.204158*v_2_27-0.024252*v_2_28+0.413405*v_2_29-0.157246*v_2_30-0.044508*v_2_31+0.158127); float v_3_02 = fun( 0.160732*v_2_00+0.256011*v_2_01-0.110751*v_2_02-0.125313*v_2_03-0.065373*v_2_04-0.110848*v_2_05-0.114430*v_2_06-0.082431*v_2_07-0.068293*v_2_08+0.050474*v_2_09-0.211380*v_2_10+0.008279*v_2_11+0.208713*v_2_12-0.032765*v_2_13+0.189141*v_2_14-0.086992*v_2_15+0.124879*v_2_16+0.033473*v_2_17-0.208384*v_2_18+0.037765*v_2_19+0.119528*v_2_20+0.101169*v_2_21+0.222705*v_2_22+0.245765*v_2_23-0.176616*v_2_24+0.017667*v_2_25+0.078378*v_2_26+0.284788*v_2_27-0.028020*v_2_28+0.033615*v_2_29+0.062638*v_2_30+0.094317*v_2_31+0.102371); float v_3_03 = fun( 0.141703*v_2_00+0.018339*v_2_01-0.049143*v_2_02+0.017668*v_2_03-0.153063*v_2_04+0.058508*v_2_05+0.111957*v_2_06+0.082174*v_2_07-0.212974*v_2_08+0.009967*v_2_09+0.041689*v_2_10-0.231775*v_2_11-0.145673*v_2_12-0.269081*v_2_13-0.201231*v_2_14-0.146360*v_2_15+0.069768*v_2_16+0.174144*v_2_17+0.102493*v_2_18-0.158220*v_2_19-0.023848*v_2_20-0.044683*v_2_21+0.194084*v_2_22+0.012289*v_2_23-0.108902*v_2_24+0.157053*v_2_25-0.101255*v_2_26-0.138732*v_2_27-0.064813*v_2_28-0.168581*v_2_29-0.179403*v_2_30-0.098669*v_2_31+0.060956); float v_3_04 = fun( 0.055462*v_2_00+0.012236*v_2_01+0.137857*v_2_02-0.007873*v_2_03-0.255538*v_2_04-0.004729*v_2_05-0.009306*v_2_06+0.177762*v_2_07+0.167626*v_2_08+0.179370*v_2_09+0.156887*v_2_10-0.026025*v_2_11+0.195465*v_2_12-0.169990*v_2_13-0.110219*v_2_14+0.171137*v_2_15+0.041942*v_2_16+0.056661*v_2_17-0.047715*v_2_18-0.097023*v_2_19-0.076487*v_2_20+0.102538*v_2_21+0.070541*v_2_22+0.289628*v_2_23-0.054302*v_2_24+0.262871*v_2_25-0.115504*v_2_26-0.038528*v_2_27-0.005957*v_2_28+0.024039*v_2_29+0.116935*v_2_30-0.136978*v_2_31+0.290137); float v_3_05 = fun( 0.094135*v_2_00+0.151499*v_2_01+0.142469*v_2_02+0.473716*v_2_03-0.003120*v_2_04-0.096686*v_2_05-0.211224*v_2_06+0.289545*v_2_07-0.017378*v_2_08-0.219641*v_2_09-0.105904*v_2_10+0.159131*v_2_11-0.232989*v_2_12+0.093633*v_2_13+0.203833*v_2_14-0.182458*v_2_15-0.181173*v_2_16-0.151925*v_2_17-0.137024*v_2_18-0.030933*v_2_19-0.269800*v_2_20-0.005893*v_2_21+0.204376*v_2_22-0.451209*v_2_23+0.172122*v_2_24-0.080869*v_2_25+0.097873*v_2_26-0.113800*v_2_27+0.222237*v_2_28-0.011652*v_2_29-0.006933*v_2_30+0.135856*v_2_31+0.229496); float v_3_06 = fun( 0.114590*v_2_00-0.050509*v_2_01-0.177848*v_2_02-0.075297*v_2_03+0.166118*v_2_04-0.151201*v_2_05+0.083566*v_2_06+0.325173*v_2_07-0.109660*v_2_08-0.026054*v_2_09+0.067388*v_2_10-0.113322*v_2_11-0.028444*v_2_12-0.227439*v_2_13+0.138387*v_2_14-0.042116*v_2_15-0.142887*v_2_16-0.253878*v_2_17-0.019159*v_2_18+0.154164*v_2_19+0.186702*v_2_20-0.031668*v_2_21+0.023003*v_2_22+0.012250*v_2_23+0.089520*v_2_24+0.060231*v_2_25+0.000937*v_2_26-0.298728*v_2_27+0.267446*v_2_28-0.292538*v_2_29+0.064285*v_2_30-0.072182*v_2_31+0.172897); float v_3_07 = fun(-0.110691*v_2_00-0.261372*v_2_01+0.078001*v_2_02+0.213953*v_2_03+0.090914*v_2_04-0.291401*v_2_05+0.085209*v_2_06+0.217021*v_2_07-0.114512*v_2_08+0.133875*v_2_09+0.270512*v_2_10-0.064528*v_2_11+0.065763*v_2_12+0.108031*v_2_13+0.130548*v_2_14-0.132751*v_2_15-0.248279*v_2_16-0.075339*v_2_17+0.176982*v_2_18-0.039952*v_2_19+0.095405*v_2_20+0.213864*v_2_21+0.074618*v_2_22+0.016896*v_2_23+0.095186*v_2_24-0.004186*v_2_25+0.011728*v_2_26+0.149403*v_2_27-0.101422*v_2_28-0.006989*v_2_29+0.119510*v_2_30+0.138768*v_2_31+0.083989); float v_3_08 = fun( 0.114491*v_2_00+0.168758*v_2_01+0.264733*v_2_02+0.025732*v_2_03-0.138357*v_2_04-0.636609*v_2_05-0.179637*v_2_06+0.069689*v_2_07-0.169867*v_2_08+0.055848*v_2_09-0.149956*v_2_10-0.215913*v_2_11-0.005772*v_2_12-0.077164*v_2_13+0.061990*v_2_14+0.018299*v_2_15+0.284049*v_2_16+0.163867*v_2_17-0.339084*v_2_18-0.009155*v_2_19-0.205331*v_2_20-0.233561*v_2_21-0.065324*v_2_22-0.098747*v_2_23+0.010475*v_2_24+0.031747*v_2_25+0.313526*v_2_26-0.017686*v_2_27+0.036675*v_2_28+0.168762*v_2_29-0.062879*v_2_30+0.074452*v_2_31+0.253199); float v_3_09 = fun(-0.056692*v_2_00-0.238749*v_2_01+0.076381*v_2_02+0.114606*v_2_03+0.089212*v_2_04-0.080897*v_2_05+0.270516*v_2_06+0.059891*v_2_07-0.002170*v_2_08+0.231490*v_2_09-0.242035*v_2_10+0.191429*v_2_11+0.006937*v_2_12-0.056038*v_2_13-0.204798*v_2_14-0.008964*v_2_15+0.037935*v_2_16-0.290974*v_2_17-0.159624*v_2_18+0.059585*v_2_19+0.199148*v_2_20+0.186739*v_2_21-0.170407*v_2_22+0.027352*v_2_23+0.150852*v_2_24+0.148215*v_2_25+0.054201*v_2_26-0.518585*v_2_27+0.289968*v_2_28+0.037875*v_2_29-0.052819*v_2_30+0.033675*v_2_31+0.029864); float v_3_10 = fun( 0.326542*v_2_00+0.040399*v_2_01+0.201698*v_2_02+0.290997*v_2_03+0.199064*v_2_04+0.006128*v_2_05-0.124135*v_2_06+0.057628*v_2_07+0.124545*v_2_08+0.109343*v_2_09+0.048072*v_2_10+0.330426*v_2_11-0.036181*v_2_12-0.260121*v_2_13+0.071318*v_2_14-0.135288*v_2_15-0.117472*v_2_16-0.148146*v_2_17-0.688773*v_2_18+0.072893*v_2_19+0.024796*v_2_20-0.076462*v_2_21+0.109759*v_2_22-0.280305*v_2_23-0.023174*v_2_24-0.242890*v_2_25+0.171241*v_2_26+0.099887*v_2_27+0.202405*v_2_28-0.218115*v_2_29+0.035058*v_2_30+0.411294*v_2_31-0.131805); float v_3_11 = fun( 0.205495*v_2_00+0.131622*v_2_01-0.200618*v_2_02-0.126344*v_2_03+0.137103*v_2_04-0.203709*v_2_05-0.179754*v_2_06+0.008463*v_2_07+0.047206*v_2_08-0.174325*v_2_09-0.310894*v_2_10-0.374026*v_2_11-0.065052*v_2_12-0.041360*v_2_13-0.227356*v_2_14-0.049431*v_2_15+0.047929*v_2_16+0.244925*v_2_17+0.321526*v_2_18+0.089854*v_2_19+0.043593*v_2_20-0.040902*v_2_21+0.375603*v_2_22-0.023301*v_2_23+0.229255*v_2_24+0.077241*v_2_25-0.023149*v_2_26-0.170729*v_2_27-0.068468*v_2_28+0.249025*v_2_29-0.085374*v_2_30+0.125159*v_2_31-0.172228); float v_3_12 = fun( 0.039226*v_2_00+0.034918*v_2_01-0.048377*v_2_02+0.090690*v_2_03+0.176874*v_2_04-0.118805*v_2_05-0.010681*v_2_06+0.153826*v_2_07+0.055955*v_2_08+0.009882*v_2_09-0.223976*v_2_10+0.085491*v_2_11+0.059156*v_2_12-0.046569*v_2_13-0.222009*v_2_14-0.012478*v_2_15-0.205995*v_2_16+0.202204*v_2_17+0.137789*v_2_18-0.111004*v_2_19+0.149519*v_2_20+0.034712*v_2_21+0.272577*v_2_22+0.014841*v_2_23+0.075070*v_2_24-0.403323*v_2_25+0.075140*v_2_26+0.270352*v_2_27-0.155054*v_2_28+0.096580*v_2_29+0.104740*v_2_30-0.007412*v_2_31+0.047696); float v_3_13 = fun(-0.048225*v_2_00+0.058702*v_2_01-0.105006*v_2_02+0.131665*v_2_03+0.088907*v_2_04-0.147617*v_2_05+0.070276*v_2_06+0.078152*v_2_07-0.106617*v_2_08-0.140748*v_2_09-0.127722*v_2_10-0.011950*v_2_11+0.134040*v_2_12-0.071629*v_2_13-0.051022*v_2_14-0.250510*v_2_15-0.142103*v_2_16-0.135902*v_2_17-0.063278*v_2_18-0.172445*v_2_19+0.307059*v_2_20+0.034731*v_2_21-0.102078*v_2_22-0.148489*v_2_23-0.024020*v_2_24-0.366180*v_2_25+0.174037*v_2_26+0.118328*v_2_27+0.186542*v_2_28+0.103307*v_2_29+0.023335*v_2_30-0.088635*v_2_31+0.359868); float v_3_14 = fun(-0.159407*v_2_00+0.048035*v_2_01-0.235352*v_2_02+0.196105*v_2_03+0.049172*v_2_04-0.048163*v_2_05-0.132879*v_2_06+0.151793*v_2_07-0.208038*v_2_08-0.155564*v_2_09+0.130196*v_2_10+0.216088*v_2_11-0.024750*v_2_12-0.364631*v_2_13-0.075135*v_2_14-0.087908*v_2_15-0.212368*v_2_16-0.005580*v_2_17+0.004953*v_2_18-0.284964*v_2_19-0.136990*v_2_20+0.082654*v_2_21+0.089684*v_2_22+0.014834*v_2_23-0.064100*v_2_24-0.106852*v_2_25-0.023190*v_2_26+0.021252*v_2_27+0.373946*v_2_28-0.054027*v_2_29+0.656903*v_2_30+0.147754*v_2_31+0.308907); float v_3_15 = fun( 0.225937*v_2_00-0.224250*v_2_01-0.242018*v_2_02+0.105097*v_2_03-0.082519*v_2_04-0.138594*v_2_05-0.153288*v_2_06-0.109048*v_2_07-0.059405*v_2_08-0.047025*v_2_09+0.048504*v_2_10+0.030623*v_2_11-0.001060*v_2_12+0.071544*v_2_13-0.135603*v_2_14-0.178962*v_2_15-0.104012*v_2_16-0.041296*v_2_17+0.105765*v_2_18+0.040479*v_2_19-0.013607*v_2_20-0.092112*v_2_21-0.032040*v_2_22+0.042604*v_2_23-0.173923*v_2_24-0.014723*v_2_25-0.206968*v_2_26-0.095554*v_2_27-0.015923*v_2_28-0.145868*v_2_29-0.284663*v_2_30-0.215003*v_2_31+0.205751); // --- layer 4 ----------------------- float v_4_0 = fun(-0.074770*v_3_00+0.153457*v_3_01-0.081600*v_3_02+0.806365*v_3_03+0.319611*v_3_04-0.421145*v_3_05+0.262921*v_3_06+0.414504*v_3_07+0.182466*v_3_08-0.204948*v_3_09-0.278227*v_3_10-0.267526*v_3_11-0.482732*v_3_12+0.016222*v_3_13-0.163100*v_3_14-0.230546*v_3_15+0.239487); float v_4_1 = fun(-0.177743*v_3_00+0.225562*v_3_01-0.453886*v_3_02+0.049631*v_3_03-0.075604*v_3_04+0.043647*v_3_05-0.399492*v_3_06+0.247270*v_3_07+0.142535*v_3_08+0.207551*v_3_09-0.285785*v_3_10+0.103653*v_3_11+0.173852*v_3_12-0.448810*v_3_13+0.348173*v_3_14-0.034657*v_3_15+0.146180); float v_4_2 = fun( 0.007303*v_3_00-0.020625*v_3_01+0.083740*v_3_02+0.352550*v_3_03+0.240649*v_3_04-0.228324*v_3_05+0.194696*v_3_06-0.296093*v_3_07-0.187802*v_3_08-0.277522*v_3_09+0.138169*v_3_10+0.089463*v_3_11-0.271476*v_3_12+0.172629*v_3_13-0.294718*v_3_14-0.250925*v_3_15+0.358876); float v_4_3 = fun(-0.265278*v_3_00-0.038249*v_3_01+0.333545*v_3_02-0.297062*v_3_03-0.615192*v_3_04-0.249223*v_3_05+0.212743*v_3_06-0.604752*v_3_07-0.367048*v_3_08-0.042192*v_3_09+0.173391*v_3_10+0.114303*v_3_11+0.426310*v_3_12-0.139203*v_3_13-0.123320*v_3_14+0.058854*v_3_15+0.155411); float v_4_4 = fun( 0.240330*v_3_00-0.381828*v_3_01+0.046630*v_3_02-0.166178*v_3_03-0.399996*v_3_04-0.082567*v_3_05+0.133546*v_3_06-0.302975*v_3_07+0.572987*v_3_08+0.104452*v_3_09-0.106836*v_3_10-0.224661*v_3_11+0.276150*v_3_12+0.192883*v_3_13-0.242290*v_3_14+0.385779*v_3_15+0.468982); float v_4_5 = fun( 0.110387*v_3_00+0.526222*v_3_01+0.281856*v_3_02-0.270505*v_3_03-0.084157*v_3_04-0.022643*v_3_05+0.262157*v_3_06+0.263482*v_3_07+0.012487*v_3_08-0.286433*v_3_09+0.246836*v_3_10+0.379451*v_3_11-0.071842*v_3_12-0.334393*v_3_13+0.305813*v_3_14-0.101473*v_3_15-0.389199); float v_4_6 = fun(-0.254180*v_3_00+0.230147*v_3_01+0.149039*v_3_02+0.492671*v_3_03+0.093311*v_3_04-0.255843*v_3_05-0.106917*v_3_06-0.123294*v_3_07+0.267801*v_3_08+0.014941*v_3_09-0.434856*v_3_10-0.066969*v_3_11-0.263687*v_3_12-0.005927*v_3_13+0.241499*v_3_14+0.033405*v_3_15+0.188735); float v_4_7 = fun(-0.151883*v_3_00-0.453696*v_3_01-0.408301*v_3_02+0.007573*v_3_03-0.007660*v_3_04-0.544588*v_3_05-0.594500*v_3_06-0.579255*v_3_07-0.301253*v_3_08+0.662012*v_3_09-0.429279*v_3_10-0.396704*v_3_11-0.088744*v_3_12-0.262998*v_3_13-0.595673*v_3_14-0.016370*v_3_15+0.526708); // --- layer 5 : output -------------- float v_5_0 = 0.5 + ( 0.274124*v_4_0+0.153013*v_4_1 -1.233798*v_4_2+0.299297*v_4_3+0.879313*v_4_4-0.199257*v_4_5-0.248584*v_4_6+0.411614*v_4_7-0.153534); fragColor = vec4(v_5_0, v_5_0, v_5_0, 1.0); }
mit
[ 2114, 2162, 2187, 2187, 2346 ]
[ [ 2114, 2162, 2187, 2187, 2346 ], [ 2348, 2359, 2414, 2457, 52260 ] ]
// noise, https://www.shadertoy.com/view/3sd3Rs
float fun( in float x ) {
float i = floor(x); float f = fract(x); float k = fract(i*0.1731)*16.0-4.0; f *= f-1.0; f *= k*f-1.0; f *= sign(fract(x/2.0)-0.5); return f; }
// noise, https://www.shadertoy.com/view/3sd3Rs float fun( in float x ) {
1
1
fddfRj
mrange
2022-07-02T20:47:13
// License CC0: 2nd attempt multiscale truchet // Everyone loves truchet tiles. Shane did an amazing one: https://www.shadertoy.com/view/4t3BW4 // Been tinkering a bit more with multiscale truchet inspired by Shane's. // Made a height field and applied lighting to it. Kind of neat #define TIME iTime #define RESOLUTION iResolution #define PI 3.141592654 #define TAU (2.0*PI) #define ROT(a) mat2(cos(a), sin(a), -sin(a), cos(a)) #define DOT2(x) dot(x,x) // License: Unknown, author: nmz (twitter: @stormoid), found: https://www.shadertoy.com/view/NdfyRM vec3 sRGB(vec3 t) { return mix(1.055*pow(t, vec3(1./2.4)) - 0.055, 12.92*t, step(t, vec3(0.0031308))); } // License: Unknown, author: Matt Taylor (https://github.com/64), found: https://64.github.io/tonemapping/ vec3 aces_approx(vec3 v) { v = max(v, 0.0); 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); } // License: WTFPL, author: sam hocevar, found: https://stackoverflow.com/a/17897228/418488 const vec4 hsv2rgb_K = vec4(1.0, 2.0 / 3.0, 1.0 / 3.0, 3.0); vec3 hsv2rgb(vec3 c) { vec3 p = abs(fract(c.xxx + hsv2rgb_K.xyz) * 6.0 - hsv2rgb_K.www); return c.z * mix(hsv2rgb_K.xxx, clamp(p - hsv2rgb_K.xxx, 0.0, 1.0), 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)) // License: Unknown, author: Unknown, found: don't remember float hash(vec2 co) { return fract(sin(dot(co.xy ,vec2(12.9898,58.233))) * 13758.5453); } float tanh_approx(float x) { // return tanh(x); float x2 = x*x; return clamp(x*(27.0 + x2)/(27.0+9.0*x2), -1.0, 1.0); } float circle(vec2 p, float r) { return length(p) - r; } float df0(vec2 p) { p -= 0.5; vec2 n = round(p); p -= n; float h0 = hash(n+100.0); if (h0 > 0.5) { p = vec2(p.y, -p.x);; } float d0 = circle(p-0.5, 0.5); float d1 = circle(p+0.5, 0.5); float d = d0; d = min(d, d1); d = abs(d) - 0.125; return d; } float df1(vec2 p) { vec2 op = p; p -= 0.5; vec2 n = round(p); p -= n; float h0 = hash(n+200.0); float h1 = fract(8667.0*h0); if (h1 < 0.5) { return -(df0(2.0*op))*0.5; } if (h0 > 0.5) { p = vec2(p.y, -p.x);; } float d0 = circle(p-0.5, 0.5); float d1 = circle(p+0.5, 0.5); p = abs(p); float d2 = circle(p-0.5, 0.125*1.5); float d = d0; d = min(d, d1); d = abs(d)-0.125*1.5; d = min(d, d2); return d; } float df2(vec2 p) { vec2 op = p; p -= 0.5; vec2 n = round(p); p -= n; float h0 = hash(n+300.0); float h1 = fract(8667.0*h0); if (h1 < 0.5) { return -(df1(2.0*op))*0.5; } if (h0 > 0.666) { p = vec2(p.y, -p.x);; } float d0 = circle(p-0.5, 0.5); float d1 = circle(p+0.5, 0.5); p = abs(p); float d2 = circle(p-0.5, 0.125); float d = d0; d = min(d, d1); d = abs(d)-0.125; d = min(d, d2); d = abs(d)-0.0125*2.5; return d; } float df(vec2 p) { return df2(p); } float hf(vec2 p) { float aa = 0.0275; float d = df(p); return -0.033*smoothstep(aa, -aa, -d); } float g_h3 = 0.0; float height(vec2 p) { p *= 0.3333; float h = hf(p); p *= 3.0; h += 0.5*hf(p); p *= 3.0; float h3 = hf(p); h += 0.25*h3; g_h3 = h3; return h; } vec3 normal(vec2 p) { vec2 e = vec2(4.0/RESOLUTION.y, 0); vec3 n; n.x = height(p + e.xy) - height(p - e.xy); n.y = 2.0*e.x; n.z = height(p + e.yx) - height(p - e.yx); return normalize(n); } vec3 effect(vec2 p) { const float s = 1.0; const float amp = 10.0; vec2 off = amp*sin(vec2(1.0, sqrt(0.5))*TIME*TAU/(30.0*amp)); const vec3 lp1 = vec3(1.0, 1.25, 1.0)*vec3(s, 1.0, s); const vec3 lp2 = vec3(-1.0, 1.25, 1.0)*vec3(s, 1.0, s); vec2 p0 = p; p0 += off; float h = height(p0); float h3= g_h3; vec3 n = normal(p0); vec3 ro = vec3(0.0, -10.0, 0.0); vec3 pp = vec3(p.x, 0.0, p.y); vec3 po = vec3(p.x, h, p.y); vec3 rd = normalize(ro - po); vec3 ld1 = normalize(lp1 - po); vec3 ld2 = normalize(lp2 - po); float diff1 = max(dot(n, ld1), 0.0); float diff2 = max(dot(n, ld2), 0.0); vec3 rn = n; vec3 ref = reflect(rd, rn); float ref1 = max(dot(ref, ld1), 0.0); float ref2 = max(dot(ref, ld2), 0.0); float fre = 1.0+dot(n,rd); float mh3 = smoothstep(-0.033, -0.015, h3); vec3 mat = HSV2RGB(vec3(0.66, 0.55, mix(0.75, 0.05, mh3))); const vec3 lcol1 = HSV2RGB(vec3(0.60, 0.66, 6.0)); const vec3 lcol2 = HSV2RGB(vec3(0.05, 0.66, 2.0)); vec3 col = vec3(0.); float dm = tanh_approx(-h*10.0+0.05); float dist1 = DOT2(lp1 - po); float dist2 = DOT2(lp2 - po); col += (lcol1*mat)*(diff1*diff1/dist1); col += (lcol2*mat)*(diff2*diff2/dist2); col *= dm; float rm = mix(0.125, 0.5, fre); float spread = mix(80.0, 40.0, mh3); col += (rm/dist1)*(pow(ref1, spread)*lcol1); col += (rm/dist2)*(pow(ref2, spread)*lcol2); return col; } void mainImage(out vec4 fragColor, in vec2 fragCoord) { vec2 q = fragCoord/iResolution.xy; vec2 p = -1. + 2. * q; p.x *= RESOLUTION.x/RESOLUTION.y; vec3 col = effect(p); col *= smoothstep(0.0, 4.0, TIME); col = aces_approx(col); col = sRGB(col); fragColor = vec4(col, 1.0); }
cc0-1.0
[ 490, 590, 609, 609, 696 ]
[ [ 490, 590, 609, 609, 696 ], [ 698, 805, 831, 831, 1015 ], [ 1169, 1169, 1191, 1191, 1337 ], [ 1632, 1692, 1713, 1713, 1783 ], [ 1785, 1785, 1813, 1833, 1909 ], [ 1911, 1911, 1942, 1942, 1968 ], [ 1970, 1970, 1989, 1989, 2246 ], [ 2248, 2248, 2267, 2267, 2697 ], [ 2699, 2699, 2718, 2718, 3167 ], [ 3169, 3169, 3187, 3187, 3206 ], [ 3208, 3208, 3226, 3226, 3309 ], [ 3330, 3330, 3352, 3352, 3491 ], [ 3493, 3493, 3514, 3514, 3700 ], [ 3702, 3702, 3723, 3723, 5123 ], [ 5125, 5125, 5180, 5180, 5416 ] ]
// License: Unknown, author: nmz (twitter: @stormoid), found: https://www.shadertoy.com/view/NdfyRM
vec3 sRGB(vec3 t) {
return mix(1.055*pow(t, vec3(1./2.4)) - 0.055, 12.92*t, step(t, vec3(0.0031308))); }
// License: Unknown, author: nmz (twitter: @stormoid), found: https://www.shadertoy.com/view/NdfyRM vec3 sRGB(vec3 t) {
59
59
sscBRj
mrange
2022-07-02T12:46:36
// License CC0: 1st attempt multiscale truchet // Everyone loves truchet tiles. Shane did an amazing one: https://www.shadertoy.com/view/4t3BW4 // I was trying to understand what was going and my brain hurt. // Anyway after some tinkering I think I got the gist of it. The idea is brilliant! // Compared to Shane's this looks awful but I have a low barrier to what I chose to share :) #define TIME iTime #define RESOLUTION iResolution #define PI 3.141592654 #define TAU (2.0*PI) // License: Unknown, author: Unknown, found: don't remember float hash(vec2 co) { return fract(sin(dot(co.xy ,vec2(12.9898,58.233))) * 13758.5453); } float circle(vec2 p, float r) { return length(p) - r; } // Classic truchet pattern float df0(vec2 p) { p -= 0.5; vec2 n = round(p); p -= n; float h0 = hash(n+100.0); if (h0 > 0.5) { p = vec2(p.y, -p.x);; } float d0 = circle(p-0.5, 0.5); float d1 = circle(p+0.5, 0.5); float d = d0; d = min(d, d1); d = abs(d) - 0.125; return d; } // Multiscale truchet float df1(vec2 p) { vec2 op = p; p -= 0.5; vec2 n = round(p); p -= n; float h0 = hash(n+100.0); float h1 = fract(8667.0*h0); // Recurse to df0 for 50% of the tiles if (h1 < 0.5) { // Invert the distance to make inside into outside return -(df0(2.0*op))*0.5; } if (h0 > 0.5) { p = vec2(p.y, -p.x);; } // Classic truchet with an added circle // so that the outside areas matches up with the nested truchet float d0 = circle(p-0.5, 0.5); float d1 = circle(p+0.5, 0.5); p = abs(p); float d2 = circle(p-0.5, 0.125*1.5); float d = d0; d = min(d, d1); d = abs(d)-0.125*1.5; d = min(d, d2); return d; } float df(vec2 p) { return df1(p); } vec3 effect(vec2 p) { float aa = 2.0/RESOLUTION.y; const float amp = 10.0; p += amp*sin(vec2(1.0, sqrt(0.5))*TIME*TAU/(10.0*amp)); const float sz = 0.25; float d = df(p/sz)*sz; vec3 col = vec3(0.01); col = mix(col, vec3(0.5), smoothstep(aa, -aa, d)); return col; } void mainImage(out vec4 fragColor, vec2 fragCoord) { vec2 q = fragCoord/iResolution.xy; vec2 p = -1. + 2. * q; p.x *= RESOLUTION.x/RESOLUTION.y; vec3 col = effect(p); col = sqrt(col); fragColor = vec4(col, 1.0); }
cc0-1.0
[ 718, 745, 764, 764, 1021 ]
[ [ 506, 566, 587, 587, 657 ], [ 659, 659, 690, 690, 716 ], [ 718, 745, 764, 764, 1021 ], [ 1023, 1045, 1064, 1064, 1699 ], [ 1701, 1701, 1719, 1719, 1738 ], [ 1740, 1740, 1761, 1761, 2020 ], [ 2022, 2022, 2074, 2074, 2249 ] ]
// Classic truchet pattern
float df0(vec2 p) {
p -= 0.5; vec2 n = round(p); p -= n; float h0 = hash(n+100.0); if (h0 > 0.5) { p = vec2(p.y, -p.x);; } float d0 = circle(p-0.5, 0.5); float d1 = circle(p+0.5, 0.5); float d = d0; d = min(d, d1); d = abs(d) - 0.125; return d; }
// Classic truchet pattern float df0(vec2 p) {
2
3
sscBRj
mrange
2022-07-02T12:46:36
// License CC0: 1st attempt multiscale truchet // Everyone loves truchet tiles. Shane did an amazing one: https://www.shadertoy.com/view/4t3BW4 // I was trying to understand what was going and my brain hurt. // Anyway after some tinkering I think I got the gist of it. The idea is brilliant! // Compared to Shane's this looks awful but I have a low barrier to what I chose to share :) #define TIME iTime #define RESOLUTION iResolution #define PI 3.141592654 #define TAU (2.0*PI) // License: Unknown, author: Unknown, found: don't remember float hash(vec2 co) { return fract(sin(dot(co.xy ,vec2(12.9898,58.233))) * 13758.5453); } float circle(vec2 p, float r) { return length(p) - r; } // Classic truchet pattern float df0(vec2 p) { p -= 0.5; vec2 n = round(p); p -= n; float h0 = hash(n+100.0); if (h0 > 0.5) { p = vec2(p.y, -p.x);; } float d0 = circle(p-0.5, 0.5); float d1 = circle(p+0.5, 0.5); float d = d0; d = min(d, d1); d = abs(d) - 0.125; return d; } // Multiscale truchet float df1(vec2 p) { vec2 op = p; p -= 0.5; vec2 n = round(p); p -= n; float h0 = hash(n+100.0); float h1 = fract(8667.0*h0); // Recurse to df0 for 50% of the tiles if (h1 < 0.5) { // Invert the distance to make inside into outside return -(df0(2.0*op))*0.5; } if (h0 > 0.5) { p = vec2(p.y, -p.x);; } // Classic truchet with an added circle // so that the outside areas matches up with the nested truchet float d0 = circle(p-0.5, 0.5); float d1 = circle(p+0.5, 0.5); p = abs(p); float d2 = circle(p-0.5, 0.125*1.5); float d = d0; d = min(d, d1); d = abs(d)-0.125*1.5; d = min(d, d2); return d; } float df(vec2 p) { return df1(p); } vec3 effect(vec2 p) { float aa = 2.0/RESOLUTION.y; const float amp = 10.0; p += amp*sin(vec2(1.0, sqrt(0.5))*TIME*TAU/(10.0*amp)); const float sz = 0.25; float d = df(p/sz)*sz; vec3 col = vec3(0.01); col = mix(col, vec3(0.5), smoothstep(aa, -aa, d)); return col; } void mainImage(out vec4 fragColor, vec2 fragCoord) { vec2 q = fragCoord/iResolution.xy; vec2 p = -1. + 2. * q; p.x *= RESOLUTION.x/RESOLUTION.y; vec3 col = effect(p); col = sqrt(col); fragColor = vec4(col, 1.0); }
cc0-1.0
[ 1023, 1045, 1064, 1064, 1699 ]
[ [ 506, 566, 587, 587, 657 ], [ 659, 659, 690, 690, 716 ], [ 718, 745, 764, 764, 1021 ], [ 1023, 1045, 1064, 1064, 1699 ], [ 1701, 1701, 1719, 1719, 1738 ], [ 1740, 1740, 1761, 1761, 2020 ], [ 2022, 2022, 2074, 2074, 2249 ] ]
// Multiscale truchet
float df1(vec2 p) {
vec2 op = p; p -= 0.5; vec2 n = round(p); p -= n; float h0 = hash(n+100.0); float h1 = fract(8667.0*h0); // Recurse to df0 for 50% of the tiles if (h1 < 0.5) { // Invert the distance to make inside into outside return -(df0(2.0*op))*0.5; } if (h0 > 0.5) { p = vec2(p.y, -p.x);; } // Classic truchet with an added circle // so that the outside areas matches up with the nested truchet float d0 = circle(p-0.5, 0.5); float d1 = circle(p+0.5, 0.5); p = abs(p); float d2 = circle(p-0.5, 0.125*1.5); float d = d0; d = min(d, d1); d = abs(d)-0.125*1.5; d = min(d, d2); return d; }
// Multiscale truchet float df1(vec2 p) {
1
2
7lVcDw
Behzod
2022-08-27T17:48:11
// The MIT License // Copyright © 2014 Inigo Quilez // Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. // Signed distance to a triangle. Negative in the inside, positive in the outside. // Note there's only one square root involved. The clamp(x,a,b) is really just // max(a,min(b,x)). The sign(x) function is |x|/x. // List of other 2D distances: https://www.shadertoy.com/playlist/MXdSRf // // and iquilezles.org/articles/distfunctions2d // Other triangle functions: // // Distance: https://www.shadertoy.com/view/XsXSz4 // Gradient: https://www.shadertoy.com/view/tlVyWh // Boundaries: https://www.shadertoy.com/view/tlKcDz // signed distance to a 2D triangle float sdTriangle( in vec2 p, in vec2 p0, in vec2 p1, in vec2 p2 ) { vec2 e0 = p1 - p0; vec2 e1 = p2 - p1; vec2 e2 = p0 - p2; vec2 v0 = p - p0; vec2 v1 = p - p1; vec2 v2 = p - p2; vec2 pq0 = v0 - e0*clamp( dot(v0,e0)/dot(e0,e0), 0.0, 1.0 ); vec2 pq1 = v1 - e1*clamp( dot(v1,e1)/dot(e1,e1), 0.0, 1.0 ); vec2 pq2 = v2 + e2*clamp( dot(v2,e2)/dot(e2,e2), 0.0, 1.0 ); float s = e0.x*e2.y - e0.y*e2.x; vec2 d = min( min( vec2( dot( pq0, pq0 ), s*(v0.x*e0.y-v0.y*e0.x) ), vec2( dot( pq1, pq1 ), s*(v1.x*e1.y-v1.y*e1.x) )), vec2( dot( pq2, pq2 ), s*(v2.x*e2.y-v2.y*e2.x) )); return -sqrt(d.x)*sign(d.y); } float drawQuad(in vec2 p, vec2 v1, float w1, vec2 v2, float w2){ float t1 = sdTriangle(p, v1+vec2(-w1/2.,0.0),v1+vec2(w1/2.,0.0),v2+vec2(w2/2.,0)); return min(t1, sdTriangle( p,v1+vec2(-w1/2.,0.0),v2-vec2(w2/2.,0),v2+vec2(w2/2.,0))); } void mainImage( out vec4 fragColor, in vec2 fragCoord ) { vec2 p = (2.0*fragCoord.xy-iResolution.xy)/iResolution.y; vec2 m = (2.0*iMouse.xy-iResolution.xy)/iResolution.y; p *= 1.5; m *= 1.5; // animate vec2 v1 = vec2(1.4,1.0)*cos( iTime*vec2(0.0,2.00) + 0.0 ); vec2 v2 = vec2(1.4,1.0)*cos( iTime*vec2(0.0,1.50) + 1.5 ); vec2 v3 = vec2(1.4,1.0)*cos( iTime*vec2(0.0,3.00) + 4.0 ); v3 = abs(v3); // distance float d = sdTriangle( p, v1, v2, v3 ); d = drawQuad(p, v1, v3.x, v2, v3.y); // color vec3 col = vec3(1.0) - sign(d)*vec3(0.1,0.4,0.7); col *= 1.0 - exp(-2.0*abs(d)); col *= 0.8 + 0.2*cos(120.0*d); col = mix( col, vec3(1.0), 1.0-smoothstep(0.0,0.02,abs(d)) ); fragColor = vec4(col,1.0); }
mit
[ 1612, 1648, 1715, 1715, 2316 ]
[ [ 1612, 1648, 1715, 1715, 2316 ], [ 2318, 2318, 2382, 2382, 2561 ], [ 2563, 2563, 2620, 2620, 3299 ] ]
// signed distance to a 2D triangle
float sdTriangle( in vec2 p, in vec2 p0, in vec2 p1, in vec2 p2 ) {
vec2 e0 = p1 - p0; vec2 e1 = p2 - p1; vec2 e2 = p0 - p2; vec2 v0 = p - p0; vec2 v1 = p - p1; vec2 v2 = p - p2; vec2 pq0 = v0 - e0*clamp( dot(v0,e0)/dot(e0,e0), 0.0, 1.0 ); vec2 pq1 = v1 - e1*clamp( dot(v1,e1)/dot(e1,e1), 0.0, 1.0 ); vec2 pq2 = v2 + e2*clamp( dot(v2,e2)/dot(e2,e2), 0.0, 1.0 ); float s = e0.x*e2.y - e0.y*e2.x; vec2 d = min( min( vec2( dot( pq0, pq0 ), s*(v0.x*e0.y-v0.y*e0.x) ), vec2( dot( pq1, pq1 ), s*(v1.x*e1.y-v1.y*e1.x) )), vec2( dot( pq2, pq2 ), s*(v2.x*e2.y-v2.y*e2.x) )); return -sqrt(d.x)*sign(d.y); }
// signed distance to a 2D triangle float sdTriangle( in vec2 p, in vec2 p0, in vec2 p1, in vec2 p2 ) {
1
14
7ttcDj
mrange
2022-08-15T19:39:08
// License CC0: Cable nest v2 // Revisited the old Cable nest shader and recoloured + tweaked distance field // Thought it turned out nice enough to share again // --- // Some parameters to play with. #define BPM 120.0 // Controls camera "fisheye" //#define RDD0 //#define RDD1 // cable shapes #define ROUNDEDX //#define BOX // Colour themes //#define THEME0 #define THEME1 //#define THEME2 // If using aces approx #define HDR // Another distance field, slightly different //#define DF0 // Number of iterations used for distance field #define MAX_ITER 3 // --- #define TOLERANCE 0.0001 #define NORMTOL 0.00125 #define MAX_RAY_LENGTH 20.0 #define MAX_RAY_MARCHES 90 #define TIME iTime #define RESOLUTION iResolution #define ROT(a) mat2(cos(a), sin(a), -sin(a), cos(a)) #define PI 3.141592654 #define TAU (2.0*PI) #define PATHA vec2(0.1147, 0.2093) #define PATHB vec2(13.0, 3.0) // License: WTFPL, author: sam hocevar, found: https://stackoverflow.com/a/17897228/418488 const vec4 hsv2rgb_K = vec4(1.0, 2.0 / 3.0, 1.0 / 3.0, 3.0); vec3 hsv2rgb(vec3 c) { vec3 p = abs(fract(c.xxx + hsv2rgb_K.xyz) * 6.0 - hsv2rgb_K.www); return c.z * mix(hsv2rgb_K.xxx, clamp(p - hsv2rgb_K.xxx, 0.0, 1.0), 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)) const float cam_amp = 1.0; mat2 g_rot = ROT(0.0); float g_quad = 0.0; int g_hit = 0; // License: Unknown, author: nmz (twitter: @stormoid), found: https://www.shadertoy.com/view/NdfyRM vec3 sRGB(vec3 t) { return mix(1.055*pow(t, vec3(1./2.4)) - 0.055, 12.92*t, step(t, vec3(0.0031308))); } // License: Unknown, author: Matt Taylor (https://github.com/64), found: https://64.github.io/tonemapping/ vec3 aces_approx(vec3 v) { v = max(v, 0.0); 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); } // License: Unknown, author: Unknown, found: don't remember float tanh_approx(float x) { // return tanh(x); float x2 = x*x; return clamp(x*(27.0 + x2)/(27.0+9.0*x2), -1.0, 1.0); } // License: MIT, author: Inigo Quilez, found: https://www.iquilezles.org/www/articles/spherefunctions/spherefunctions.htm float sphered(vec3 ro, vec3 rd, vec4 sph, float dbuffer) { float ndbuffer = dbuffer/sph.w; vec3 rc = (ro - sph.xyz)/sph.w; float b = dot(rd,rc); float c = dot(rc,rc) - 1.0; float h = b*b - c; if( h<0.0 ) return 0.0; h = sqrt( h ); float t1 = -b - h; float t2 = -b + h; if( t2<0.0 || t1>ndbuffer ) return 0.0; t1 = max( t1, 0.0 ); t2 = min( t2, ndbuffer ); float i1 = -(c*t1 + b*t1*t1 + t1*t1*t1/3.0); float i2 = -(c*t2 + b*t2*t2 + t2*t2*t2/3.0); return (i2-i1)*(3.0/4.0); } // License: Unknown, author: Unknown, found: don't remember float hash(float co) { return fract(sin(co*12.9898) * 13758.5453); } vec3 cam_path(float z) { return vec3(cam_amp*sin(z*PATHA)*PATHB, z); } vec3 dcam_path(float z) { return vec3(cam_amp*PATHA*PATHB*cos(PATHA*z), 1.0); } vec3 ddcam_path(float z) { return cam_amp*vec3(cam_amp*-PATHA*PATHA*PATHB*sin(PATHA*z), 0.0); } // License: MIT, author: Inigo Quilez, found: https://iquilezles.org/www/articles/distfunctions2d/distfunctions2d.htm float box(vec2 p, vec2 b, float r) { b -= r; vec2 d = abs(p)-b; return length(max(d,0.0)) + min(max(d.x,d.y),0.0)-r; } // License: MIT, author: Inigo Quilez, found: https://iquilezles.org/www/articles/distfunctions2d/distfunctions2d.htm float roundedX(vec2 p, float w, float r) { p = abs(p); return length(p-min(p.x+p.y,w)*0.5) - r; } float cables(vec3 p3) { const float cylr = 0.2; vec2 p = p3.xy; float t = p3.z; const float ss = 1.5; mat2 pp = ss*ROT(1.0+0.5*p3.z); p *= g_rot; float s = 1.0; float d = 1E6; float quad = 1.0; int hit = 0; for (int i = 0; i < MAX_ITER; ++i) { p *= pp; p = abs(p); #if defined(DF0) const float scaling = 3.0; p -= 0.5*s*scaling; s *= 1.0/ss; float sz = scaling*s; #else p -= 1.35*s; s *= 1.0/ss; const float sz = 1.0; #endif #if defined(ROUNDEDX) float dd = roundedX(p, sz*1.5*cylr, sz*0.25*cylr)*s; #elif defined(BOX) float dd = box(p, vec2(sz*cylr), sz*cylr*0.1)*s; #else float dd = (length(p)-sz*cylr)*s; #endif vec2 s = sign(p); float q = s.x*s.y; if (dd < d) { d = dd; quad = q; hit = i; } } g_quad = quad; g_hit = hit; return d; } float df(vec3 p) { // Found this world warping technique somewhere but forgot which shader :( vec3 cam = cam_path(p.z); vec3 dcam = normalize(dcam_path(p.z)); p.xy -= cam.xy; p -= dcam*dot(vec3(p.xy, 0), dcam)*0.5*vec3(1,1,-1); float d = cables(p); return d; } float rayMarch(in vec3 ro, in vec3 rd, out int iter) { float t = 0.1; int i = 0; for (i = 0; i < MAX_RAY_MARCHES; i++) { float d = df(ro + rd*t); if (d < TOLERANCE || t > MAX_RAY_LENGTH) break; t += d; } iter = i; return t; } vec3 normal(in vec3 pos) { vec3 eps = vec3(NORMTOL,0.0,0.0); vec3 nor; nor.x = df(pos+eps.xyy) - df(pos-eps.xyy); nor.y = df(pos+eps.yxy) - df(pos-eps.yxy); nor.z = df(pos+eps.yyx) - df(pos-eps.yyx); return normalize(nor); } float softShadow(in vec3 pos, in vec3 ld, in float ll, float mint, float k) { const float minShadow = 0.25; float res = 1.0; float t = mint; for (int i=0; i<25; ++i) { float distance = df(pos + ld*t); res = min(res, k*distance/t); if (ll <= t) break; if(res <= minShadow) break; t += max(mint*0.2, distance); } return clamp(res,minShadow,1.0); } vec3 render(vec3 ro, vec3 rd) { vec3 lightPos0 = cam_path(TIME-0.5); vec3 lightPos1 = cam_path(TIME+6.5); vec3 skyCol = vec3(0.0); int iter = 0; float t = rayMarch(ro, rd, iter); float quad = g_quad; float hit = float(g_hit); float tt = float(iter)/float(MAX_RAY_MARCHES); float bs = 1.0-tt*tt*tt*tt; vec3 pos = ro + t*rd; float lsd1 = sphered(ro, rd, vec4(lightPos1, 2.5), t); float beat = smoothstep(0.25, 1.0, sin(TAU*TIME*BPM/60.0)); vec3 bcol = mix(HSV2RGB(vec3(0.6, 0.6, 3.0)), HSV2RGB(vec3(0.55, 0.8, 7.0)), beat); vec3 gcol = lsd1*bcol; if (t >= MAX_RAY_LENGTH) { return skyCol+gcol; } vec3 nor = normal(pos); vec3 lv0 = lightPos0 - pos; float ll20 = dot(lv0, lv0); float ll0 = sqrt(ll20); vec3 ld0 = lv0 / ll0; float dm0 = 8.0/ll20; float sha0 = softShadow(pos, ld0, ll0, 0.125, 32.0); float dif0 = max(dot(nor,ld0),0.0)*dm0; vec3 lv1 = lightPos1 - pos; float ll21 = dot(lv1, lv1); float ll1 = sqrt(ll21); vec3 ld1 = lv1 / ll1; float spe1 = pow(max(dot(reflect(ld1, nor), rd), 0.), 100.)*tanh_approx(3.0/ll21); vec3 col = vec3(0.0); const vec3 black = vec3(0.0); #if defined(THEME0) const vec3 dcol0 = HSV2RGB(vec3(0.6, 0.5, 1.0)); const vec3 dcol1 = dcol0; #elif defined(THEME1) const vec3 dcol0 = black; const vec3 dcol1 = HSV2RGB(vec3(0.08, 1.0, 1.0)); #elif defined(THEME2) vec3 dcol0 = hsv2rgb(vec3(0.6-0.05*hit, 0.75, 1.0)); const vec3 dcol1 = HSV2RGB(vec3(0.8, 1.0, 0.)); #else const vec3 dcol0 = black; const vec3 dcol1 = dcol0; #endif col += dif0*sha0*mix(dcol0, dcol1, 0.5+0.5*quad); col += spe1*bcol*bs; col += gcol; return col; } vec3 effect(vec2 p) { float tm = TIME; g_rot = ROT(-0.2*tm); vec3 cam = cam_path(tm); vec3 dcam = dcam_path(tm); vec3 ddcam= ddcam_path(tm); vec3 ro = cam; vec3 ww = normalize(dcam); vec3 uu = normalize(cross(vec3(0.0,1.0,0.0)+ddcam*2.0, ww )); vec3 vv = normalize(cross(ww,uu)); #if defined(RDD0) float rdd = (2.0-0.5*tanh_approx(dot(p, p))); #elif defined(RDD1) float rdd = (2.0+0.75*tanh_approx(dot(p, p))); #else const float rdd = 2.5; #endif vec3 rd = normalize(p.x*uu + p.y*vv + rdd*ww); vec3 col = render(ro, rd); return col; } void mainImage(out vec4 fragColor, in vec2 fragCoord) { vec2 q = fragCoord/RESOLUTION.xy; vec2 p = -1.0 + 2.0*q; p.x *= RESOLUTION.x/RESOLUTION.y; vec3 col = effect(p); #if defined(HDR) col = aces_approx(col); col = sRGB(col); #else col = sqrt(col); #endif fragColor = vec4(col, 1.0); }
cc0-1.0
[ 2379, 2501, 2559, 2559, 3040 ]
[ [ 1115, 1115, 1137, 1137, 1283 ], [ 1666, 1766, 1785, 1785, 1872 ], [ 1874, 1981, 2007, 2007, 2191 ], [ 2193, 2253, 2281, 2301, 2377 ], [ 2379, 2501, 2559, 2559, 3040 ], [ 3042, 3102, 3124, 3124, 3172 ], [ 3174, 3174, 3198, 3198, 3246 ], [ 3248, 3248, 3273, 3273, 3329 ], [ 3331, 3331, 3357, 3357, 3428 ], [ 3430, 3548, 3584, 3584, 3672 ], [ 3674, 3792, 3834, 3834, 3893 ], [ 3895, 3895, 3918, 3918, 4776 ], [ 4778, 4778, 4796, 4873, 5056 ], [ 5059, 5059, 5113, 5113, 5308 ], [ 5310, 5310, 5336, 5336, 5547 ], [ 5549, 5549, 5626, 5626, 5926 ], [ 5928, 5928, 5959, 5959, 7624 ], [ 7626, 7626, 7647, 7647, 8195 ], [ 8197, 8197, 8252, 8252, 8507 ] ]
// License: MIT, author: Inigo Quilez, found: https://www.iquilezles.org/www/articles/spherefunctions/spherefunctions.htm
float sphered(vec3 ro, vec3 rd, vec4 sph, float dbuffer) {
float ndbuffer = dbuffer/sph.w; vec3 rc = (ro - sph.xyz)/sph.w; float b = dot(rd,rc); float c = dot(rc,rc) - 1.0; float h = b*b - c; if( h<0.0 ) return 0.0; h = sqrt( h ); float t1 = -b - h; float t2 = -b + h; if( t2<0.0 || t1>ndbuffer ) return 0.0; t1 = max( t1, 0.0 ); t2 = min( t2, ndbuffer ); float i1 = -(c*t1 + b*t1*t1 + t1*t1*t1/3.0); float i2 = -(c*t2 + b*t2*t2 + t2*t2*t2/3.0); return (i2-i1)*(3.0/4.0); }
// License: MIT, author: Inigo Quilez, found: https://www.iquilezles.org/www/articles/spherefunctions/spherefunctions.htm float sphered(vec3 ro, vec3 rd, vec4 sph, float dbuffer) {
8
11
7ttcDj
mrange
2022-08-15T19:39:08
// License CC0: Cable nest v2 // Revisited the old Cable nest shader and recoloured + tweaked distance field // Thought it turned out nice enough to share again // --- // Some parameters to play with. #define BPM 120.0 // Controls camera "fisheye" //#define RDD0 //#define RDD1 // cable shapes #define ROUNDEDX //#define BOX // Colour themes //#define THEME0 #define THEME1 //#define THEME2 // If using aces approx #define HDR // Another distance field, slightly different //#define DF0 // Number of iterations used for distance field #define MAX_ITER 3 // --- #define TOLERANCE 0.0001 #define NORMTOL 0.00125 #define MAX_RAY_LENGTH 20.0 #define MAX_RAY_MARCHES 90 #define TIME iTime #define RESOLUTION iResolution #define ROT(a) mat2(cos(a), sin(a), -sin(a), cos(a)) #define PI 3.141592654 #define TAU (2.0*PI) #define PATHA vec2(0.1147, 0.2093) #define PATHB vec2(13.0, 3.0) // License: WTFPL, author: sam hocevar, found: https://stackoverflow.com/a/17897228/418488 const vec4 hsv2rgb_K = vec4(1.0, 2.0 / 3.0, 1.0 / 3.0, 3.0); vec3 hsv2rgb(vec3 c) { vec3 p = abs(fract(c.xxx + hsv2rgb_K.xyz) * 6.0 - hsv2rgb_K.www); return c.z * mix(hsv2rgb_K.xxx, clamp(p - hsv2rgb_K.xxx, 0.0, 1.0), 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)) const float cam_amp = 1.0; mat2 g_rot = ROT(0.0); float g_quad = 0.0; int g_hit = 0; // License: Unknown, author: nmz (twitter: @stormoid), found: https://www.shadertoy.com/view/NdfyRM vec3 sRGB(vec3 t) { return mix(1.055*pow(t, vec3(1./2.4)) - 0.055, 12.92*t, step(t, vec3(0.0031308))); } // License: Unknown, author: Matt Taylor (https://github.com/64), found: https://64.github.io/tonemapping/ vec3 aces_approx(vec3 v) { v = max(v, 0.0); 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); } // License: Unknown, author: Unknown, found: don't remember float tanh_approx(float x) { // return tanh(x); float x2 = x*x; return clamp(x*(27.0 + x2)/(27.0+9.0*x2), -1.0, 1.0); } // License: MIT, author: Inigo Quilez, found: https://www.iquilezles.org/www/articles/spherefunctions/spherefunctions.htm float sphered(vec3 ro, vec3 rd, vec4 sph, float dbuffer) { float ndbuffer = dbuffer/sph.w; vec3 rc = (ro - sph.xyz)/sph.w; float b = dot(rd,rc); float c = dot(rc,rc) - 1.0; float h = b*b - c; if( h<0.0 ) return 0.0; h = sqrt( h ); float t1 = -b - h; float t2 = -b + h; if( t2<0.0 || t1>ndbuffer ) return 0.0; t1 = max( t1, 0.0 ); t2 = min( t2, ndbuffer ); float i1 = -(c*t1 + b*t1*t1 + t1*t1*t1/3.0); float i2 = -(c*t2 + b*t2*t2 + t2*t2*t2/3.0); return (i2-i1)*(3.0/4.0); } // License: Unknown, author: Unknown, found: don't remember float hash(float co) { return fract(sin(co*12.9898) * 13758.5453); } vec3 cam_path(float z) { return vec3(cam_amp*sin(z*PATHA)*PATHB, z); } vec3 dcam_path(float z) { return vec3(cam_amp*PATHA*PATHB*cos(PATHA*z), 1.0); } vec3 ddcam_path(float z) { return cam_amp*vec3(cam_amp*-PATHA*PATHA*PATHB*sin(PATHA*z), 0.0); } // License: MIT, author: Inigo Quilez, found: https://iquilezles.org/www/articles/distfunctions2d/distfunctions2d.htm float box(vec2 p, vec2 b, float r) { b -= r; vec2 d = abs(p)-b; return length(max(d,0.0)) + min(max(d.x,d.y),0.0)-r; } // License: MIT, author: Inigo Quilez, found: https://iquilezles.org/www/articles/distfunctions2d/distfunctions2d.htm float roundedX(vec2 p, float w, float r) { p = abs(p); return length(p-min(p.x+p.y,w)*0.5) - r; } float cables(vec3 p3) { const float cylr = 0.2; vec2 p = p3.xy; float t = p3.z; const float ss = 1.5; mat2 pp = ss*ROT(1.0+0.5*p3.z); p *= g_rot; float s = 1.0; float d = 1E6; float quad = 1.0; int hit = 0; for (int i = 0; i < MAX_ITER; ++i) { p *= pp; p = abs(p); #if defined(DF0) const float scaling = 3.0; p -= 0.5*s*scaling; s *= 1.0/ss; float sz = scaling*s; #else p -= 1.35*s; s *= 1.0/ss; const float sz = 1.0; #endif #if defined(ROUNDEDX) float dd = roundedX(p, sz*1.5*cylr, sz*0.25*cylr)*s; #elif defined(BOX) float dd = box(p, vec2(sz*cylr), sz*cylr*0.1)*s; #else float dd = (length(p)-sz*cylr)*s; #endif vec2 s = sign(p); float q = s.x*s.y; if (dd < d) { d = dd; quad = q; hit = i; } } g_quad = quad; g_hit = hit; return d; } float df(vec3 p) { // Found this world warping technique somewhere but forgot which shader :( vec3 cam = cam_path(p.z); vec3 dcam = normalize(dcam_path(p.z)); p.xy -= cam.xy; p -= dcam*dot(vec3(p.xy, 0), dcam)*0.5*vec3(1,1,-1); float d = cables(p); return d; } float rayMarch(in vec3 ro, in vec3 rd, out int iter) { float t = 0.1; int i = 0; for (i = 0; i < MAX_RAY_MARCHES; i++) { float d = df(ro + rd*t); if (d < TOLERANCE || t > MAX_RAY_LENGTH) break; t += d; } iter = i; return t; } vec3 normal(in vec3 pos) { vec3 eps = vec3(NORMTOL,0.0,0.0); vec3 nor; nor.x = df(pos+eps.xyy) - df(pos-eps.xyy); nor.y = df(pos+eps.yxy) - df(pos-eps.yxy); nor.z = df(pos+eps.yyx) - df(pos-eps.yyx); return normalize(nor); } float softShadow(in vec3 pos, in vec3 ld, in float ll, float mint, float k) { const float minShadow = 0.25; float res = 1.0; float t = mint; for (int i=0; i<25; ++i) { float distance = df(pos + ld*t); res = min(res, k*distance/t); if (ll <= t) break; if(res <= minShadow) break; t += max(mint*0.2, distance); } return clamp(res,minShadow,1.0); } vec3 render(vec3 ro, vec3 rd) { vec3 lightPos0 = cam_path(TIME-0.5); vec3 lightPos1 = cam_path(TIME+6.5); vec3 skyCol = vec3(0.0); int iter = 0; float t = rayMarch(ro, rd, iter); float quad = g_quad; float hit = float(g_hit); float tt = float(iter)/float(MAX_RAY_MARCHES); float bs = 1.0-tt*tt*tt*tt; vec3 pos = ro + t*rd; float lsd1 = sphered(ro, rd, vec4(lightPos1, 2.5), t); float beat = smoothstep(0.25, 1.0, sin(TAU*TIME*BPM/60.0)); vec3 bcol = mix(HSV2RGB(vec3(0.6, 0.6, 3.0)), HSV2RGB(vec3(0.55, 0.8, 7.0)), beat); vec3 gcol = lsd1*bcol; if (t >= MAX_RAY_LENGTH) { return skyCol+gcol; } vec3 nor = normal(pos); vec3 lv0 = lightPos0 - pos; float ll20 = dot(lv0, lv0); float ll0 = sqrt(ll20); vec3 ld0 = lv0 / ll0; float dm0 = 8.0/ll20; float sha0 = softShadow(pos, ld0, ll0, 0.125, 32.0); float dif0 = max(dot(nor,ld0),0.0)*dm0; vec3 lv1 = lightPos1 - pos; float ll21 = dot(lv1, lv1); float ll1 = sqrt(ll21); vec3 ld1 = lv1 / ll1; float spe1 = pow(max(dot(reflect(ld1, nor), rd), 0.), 100.)*tanh_approx(3.0/ll21); vec3 col = vec3(0.0); const vec3 black = vec3(0.0); #if defined(THEME0) const vec3 dcol0 = HSV2RGB(vec3(0.6, 0.5, 1.0)); const vec3 dcol1 = dcol0; #elif defined(THEME1) const vec3 dcol0 = black; const vec3 dcol1 = HSV2RGB(vec3(0.08, 1.0, 1.0)); #elif defined(THEME2) vec3 dcol0 = hsv2rgb(vec3(0.6-0.05*hit, 0.75, 1.0)); const vec3 dcol1 = HSV2RGB(vec3(0.8, 1.0, 0.)); #else const vec3 dcol0 = black; const vec3 dcol1 = dcol0; #endif col += dif0*sha0*mix(dcol0, dcol1, 0.5+0.5*quad); col += spe1*bcol*bs; col += gcol; return col; } vec3 effect(vec2 p) { float tm = TIME; g_rot = ROT(-0.2*tm); vec3 cam = cam_path(tm); vec3 dcam = dcam_path(tm); vec3 ddcam= ddcam_path(tm); vec3 ro = cam; vec3 ww = normalize(dcam); vec3 uu = normalize(cross(vec3(0.0,1.0,0.0)+ddcam*2.0, ww )); vec3 vv = normalize(cross(ww,uu)); #if defined(RDD0) float rdd = (2.0-0.5*tanh_approx(dot(p, p))); #elif defined(RDD1) float rdd = (2.0+0.75*tanh_approx(dot(p, p))); #else const float rdd = 2.5; #endif vec3 rd = normalize(p.x*uu + p.y*vv + rdd*ww); vec3 col = render(ro, rd); return col; } void mainImage(out vec4 fragColor, in vec2 fragCoord) { vec2 q = fragCoord/RESOLUTION.xy; vec2 p = -1.0 + 2.0*q; p.x *= RESOLUTION.x/RESOLUTION.y; vec3 col = effect(p); #if defined(HDR) col = aces_approx(col); col = sRGB(col); #else col = sqrt(col); #endif fragColor = vec4(col, 1.0); }
cc0-1.0
[ 3674, 3792, 3834, 3834, 3893 ]
[ [ 1115, 1115, 1137, 1137, 1283 ], [ 1666, 1766, 1785, 1785, 1872 ], [ 1874, 1981, 2007, 2007, 2191 ], [ 2193, 2253, 2281, 2301, 2377 ], [ 2379, 2501, 2559, 2559, 3040 ], [ 3042, 3102, 3124, 3124, 3172 ], [ 3174, 3174, 3198, 3198, 3246 ], [ 3248, 3248, 3273, 3273, 3329 ], [ 3331, 3331, 3357, 3357, 3428 ], [ 3430, 3548, 3584, 3584, 3672 ], [ 3674, 3792, 3834, 3834, 3893 ], [ 3895, 3895, 3918, 3918, 4776 ], [ 4778, 4778, 4796, 4873, 5056 ], [ 5059, 5059, 5113, 5113, 5308 ], [ 5310, 5310, 5336, 5336, 5547 ], [ 5549, 5549, 5626, 5626, 5926 ], [ 5928, 5928, 5959, 5959, 7624 ], [ 7626, 7626, 7647, 7647, 8195 ], [ 8197, 8197, 8252, 8252, 8507 ] ]
// License: MIT, author: Inigo Quilez, found: https://iquilezles.org/www/articles/distfunctions2d/distfunctions2d.htm
float roundedX(vec2 p, float w, float r) {
p = abs(p); return length(p-min(p.x+p.y,w)*0.5) - r; }
// License: MIT, author: Inigo Quilez, found: https://iquilezles.org/www/articles/distfunctions2d/distfunctions2d.htm float roundedX(vec2 p, float w, float r) {
5
5
Nt3yDH
iq
2022-08-04T22:30:28
// The MIT License // Copyright © 2022 Inigo Quilez // Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. // Distance to the a cross made of four y(x) = 1/x curves. Minimizing the // distance squared d²(x,y) = (x-t)²+(y-1/t)² produces a 4th degree // polyonomial in t, which I'm solving with Ferrari's Method as described // here: https://en.wikipedia.org/wiki/Quartic_equation // // I added a paramter k in the open range (0,1) to control its shape. // Compare to negative squircle here: https://www.shadertoy.com/view/7stcR4 // List of some other 2D distances: https://www.shadertoy.com/playlist/MXdSRf // // and iquilezles.org/articles/distfunctions2d // k in (0,1) range float sdHyperbolicCross( in vec2 p, float k ) { // scale float s = 1.0/k - k; p = p*s; // symmetry p = abs(p); p = (p.x>p.y) ? p.yx : p.xy; // offset p += k; // solve quartic (for details see https://www.shadertoy.com/view/ftcyW8) float x2 = p.x*p.x/16.0; float y2 = p.y*p.y/16.0; float r = (p.x*p.y-4.0)/12.0; float q = y2-x2; float h = q*q-r*r*r; float u; if( h<0.0 ) { float m = sqrt(r); u = m*cos( acos(q/(r*m) )/3.0 ); } else { float m = pow(sqrt(h)+q,1.0/3.0); u = (m+r/m)/2.0; } float w = sqrt(u+x2); float x = p.x/4.0-w+sqrt(2.0*x2-u+(p.y-x2*p.x*2.0)/w/4.0); // clamp arm x = max(x,k); // compute distance to closest point float d = length( p-vec2(x,1.0/x) ) / s; // sign return p.x*p.y < 1.0 ? -d : d; } void mainImage( out vec4 fragColor, in vec2 fragCoord ) { const float scale = 1.5; vec2 p = scale*(2.0*fragCoord-iResolution.xy)/iResolution.y; vec2 m = scale*(2.0*iMouse.xy-iResolution.xy)/iResolution.y; float px = scale*2.0/iResolution.y; float k = 0.5 + 0.45*sin(3.14159*iTime); float d = sdHyperbolicCross(p, k); // colorize vec3 col = (d>0.0) ? vec3(0.9,0.6,0.3) : vec3(0.65,0.85,1.0); col *= 1.0 - exp2(-10.0*abs(d)); col *= 0.7 + 0.2*cos(70.0*d); col = mix( col, vec3(1.0), 1.0-smoothstep(0.0,4.0*px,abs(d)) ); // mouse if( iMouse.z>0.001 ) { float d = sdHyperbolicCross(m, k); float l = length(p-m); col = mix(col, vec3(1.0,1.0,0.0), 1.0-smoothstep(0.0, 2.0*px, abs(l-abs(d)))); col = mix(col, vec3(1.0,1.0,0.0), 1.0-smoothstep(0.0, 2.0*px, l-px*3.0)); } fragColor = vec4(col,1.0); }
mit
[ 1633, 1653, 1700, 1713, 2529 ]
[ [ 1633, 1653, 1700, 1713, 2529 ], [ 2531, 2531, 2588, 2588, 3435 ] ]
// k in (0,1) range
float sdHyperbolicCross( in vec2 p, float k ) {
float s = 1.0/k - k; p = p*s; // symmetry p = abs(p); p = (p.x>p.y) ? p.yx : p.xy; // offset p += k; // solve quartic (for details see https://www.shadertoy.com/view/ftcyW8) float x2 = p.x*p.x/16.0; float y2 = p.y*p.y/16.0; float r = (p.x*p.y-4.0)/12.0; float q = y2-x2; float h = q*q-r*r*r; float u; if( h<0.0 ) { float m = sqrt(r); u = m*cos( acos(q/(r*m) )/3.0 ); } else { float m = pow(sqrt(h)+q,1.0/3.0); u = (m+r/m)/2.0; } float w = sqrt(u+x2); float x = p.x/4.0-w+sqrt(2.0*x2-u+(p.y-x2*p.x*2.0)/w/4.0); // clamp arm x = max(x,k); // compute distance to closest point float d = length( p-vec2(x,1.0/x) ) / s; // sign return p.x*p.y < 1.0 ? -d : d; }
// k in (0,1) range float sdHyperbolicCross( in vec2 p, float k ) {
1
1
ftcyW8
iq
2022-08-04T19:35:57
// The MIT License // Copyright © 2022 Inigo Quilez // Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. // Distance to the y(x)=1/x curve. // Minimizing the distance squared D² = (x-t)²+(y-1/t)² produces // // t⁴ - xt³ + yt - 1 = 0 // // which can be solved with the quartic formula, as described in Wikipedia: // https://en.wikipedia.org/wiki/Quartic_equation. I followed the // section "Summary of Ferrari's method" and simplified a lot of things // (complex branches to reals, trigonometrics, constant unfolding, etc) // until I got this expression. // // I wrote the shader for comparison with the numerically computed version // of the SDF implemented here: https://www.shadertoy.com/view/sttyWr // List of some other 2D distances: https://www.shadertoy.com/playlist/MXdSRf // // and iquilezles.org/articles/distfunctions2d // distance to y=1/x float sdOOX( in vec2 p ) { p = (p.x>p.y) ? p.yx : p.xy; float x2 = p.x*p.x/16.0; float y2 = p.y*p.y/16.0; float r = (4.0-p.x*p.y)/12.0; float q = x2 - y2; float h = q*q + r*r*r; float u; if( h<0.0 ) { float m = sqrt(-r); u = m*cos( acos(q/(r*m))/3.0 ); } else { float m = pow(sqrt(h)-q,1.0/3.0); u = (m - r/m)/2.0; } float w = sqrt( u + x2 ); float b = p.y - x2*p.x*2.0; float t = p.x/4.0 - w + sqrt( 2.0*x2 - u + b/w/4.0 ); float d = length( p-vec2(t,1.0/t) ); return p.x*p.y < 1.0 ? d : -d; } void mainImage(out vec4 fragColor, in vec2 fragCoord) { const float scale = 3.0; vec2 p = scale*fragCoord/iResolution.y; vec2 m = scale*iMouse.xy/iResolution.y; float px = scale/iResolution.y; float d = sdOOX(p); // colorize vec3 col = (d>0.0) ? vec3(0.9,0.6,0.3) : vec3(0.65,0.85,1.0); col *= 1.0 - exp(-6.0*abs(d)); col *= 0.7 + 0.2*cos(73.33*d); col = mix( col, vec3(1.0), 1.0-smoothstep(0.0,3.0*px,abs(d)) ); // mouse if( iMouse.z>0.001 ) { float d = sdOOX(m); float l = length(p-m); col = mix(col, vec3(1.0,1.0,0.0), 1.0-smoothstep(0.0, 2.0*px, abs(l-abs(d)))); col = mix(col, vec3(1.0,1.0,0.0), 1.0-smoothstep(0.0, 2.0*px, l-px*3.0)); } fragColor = vec4(col,1.0); }
mit
[ 1817, 1838, 1864, 1864, 2451 ]
[ [ 1817, 1838, 1864, 1864, 2451 ], [ 2453, 2453, 2508, 2508, 3228 ] ]
// distance to y=1/x
float sdOOX( in vec2 p ) {
p = (p.x>p.y) ? p.yx : p.xy; float x2 = p.x*p.x/16.0; float y2 = p.y*p.y/16.0; float r = (4.0-p.x*p.y)/12.0; float q = x2 - y2; float h = q*q + r*r*r; float u; if( h<0.0 ) { float m = sqrt(-r); u = m*cos( acos(q/(r*m))/3.0 ); } else { float m = pow(sqrt(h)-q,1.0/3.0); u = (m - r/m)/2.0; } float w = sqrt( u + x2 ); float b = p.y - x2*p.x*2.0; float t = p.x/4.0 - w + sqrt( 2.0*x2 - u + b/w/4.0 ); float d = length( p-vec2(t,1.0/t) ); return p.x*p.y < 1.0 ? d : -d; }
// distance to y=1/x float sdOOX( in vec2 p ) {
1
1
NtKBWh
mrange
2022-09-29T05:45:01
// License CC0: Dark chocolate FBM // Working on a cake related shader and created kind of dark chocolate // background. Nothing unique but different colors than what I usually // do so sharing. #define TIME iTime #define RESOLUTION iResolution #define PI 3.141592654 #define TAU (2.0*PI) #define ROT(a) mat2(cos(a), sin(a), -sin(a), cos(a)) #define TTIME (TAU*TIME) #define DOT2(p) dot(p, p) // License: WTFPL, author: sam hocevar, found: https://stackoverflow.com/a/17897228/418488 const vec4 hsv2rgb_K = vec4(1.0, 2.0 / 3.0, 1.0 / 3.0, 3.0); vec3 hsv2rgb(vec3 c) { vec3 p = abs(fract(c.xxx + hsv2rgb_K.xyz) * 6.0 - hsv2rgb_K.www); return c.z * mix(hsv2rgb_K.xxx, clamp(p - hsv2rgb_K.xxx, 0.0, 1.0), 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)) // License: Unknown, author: nmz (twitter: @stormoid), found: https://www.shadertoy.com/view/NdfyRM vec3 sRGB(vec3 t) { return mix(1.055*pow(t, vec3(1./2.4)) - 0.055, 12.92*t, step(t, vec3(0.0031308))); } // License: Unknown, author: Matt Taylor (https://github.com/64), found: https://64.github.io/tonemapping/ vec3 aces_approx(vec3 v) { v = max(v, 0.0); 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); } // License: Unknown, author: Unknown, found: don't remember float tanh_approx(float x) { // return tanh(x); float x2 = x*x; return clamp(x*(27.0 + x2)/(27.0+9.0*x2), -1.0, 1.0); } // License: MIT, author: Inigo Quilez, found: https://www.iquilezles.org/www/articles/smin/smin.htm float pmin(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); } // License: CC0, author: Mårten Rånge, found: https://github.com/mrange/glsl-snippets float pabs(float a, float k) { return -pmin(a, -a, k); } // License: MIT, author: Inigo Quilez, found: https://iquilezles.org/www/articles/distfunctions2d/distfunctions2d.htm float heart(vec2 p) { p.y -= -0.6; p.x = pabs(p.x, 0.125); if( p.y+p.x>1.0 ) return sqrt(DOT2(p-vec2(0.25,0.75))) - sqrt(2.0)/4.0; return sqrt(min(DOT2(p-vec2(0.00,1.00)), DOT2(p-0.5*max(p.x+p.y,0.0)))) * sign(p.x-p.y); } vec2 mod2_1(inout vec2 p) { vec2 n = floor(p + 0.5); p = fract(p+0.5)-0.5; return n; } float hf(vec2 p) { p *= 0.25; vec2 p0 = p; vec2 n0 = mod2_1(p0); vec2 p1 = p*vec2(1.0, -1.0)+vec2(0.5, 0.66); vec2 n1 = mod2_1(p1); const float ss = 0.60; float d0 = heart(p0/ss)*ss; float d1 = heart(p1/ss)*ss; float d = min(d0, d1); return tanh_approx(smoothstep(0.0, -0.1,d)*exp(8.0*-d)); } float height(vec2 p) { const mat2 rot1 = ROT(1.0); float tm = 123.0+TTIME/240.0; p += 5.0*vec2(cos(tm), sin(tm*sqrt(0.5))); const float aa = -0.45; const mat2 pp = (1.0/aa)*rot1; float h = 0.0; float a = 1.0; float d = 0.0; for (int i = 0; i < 4; ++i) { h += a*hf(p); d += a; a *= aa; p *= pp; } const float hf = -0.125; return hf*(h/d)+hf; } vec3 normal(vec2 p) { vec2 v; vec2 w; vec2 e = vec2(4.0/RESOLUTION.y, 0); vec3 n; n.x = height(p + e.xy) - height(p - e.xy); n.y = 2.0*e.x; n.z = height(p + e.yx) - height(p - e.yx); return normalize(n); } vec3 effect(vec2 p, vec2 q) { vec2 ppp = p; const float s = 1.0; const vec3 lp1 = vec3(1.0, 1.25, 1.0)*vec3(s, 1.0, s); const vec3 lp2 = vec3(-1.0, 1.25, 1.0)*vec3(s, 1.0, s); const vec3 lcol1 = HSV2RGB(vec3(0.06, 0.9 , .5)); const vec3 lcol2 = HSV2RGB(vec3(0.05, 0.25, 1.0)); const vec3 mcol = HSV2RGB(vec3(0.1 , 0.95, 0.2)); const float spe1 = 20.0; const float spe2 = 40.0; float aa = 2.0/RESOLUTION.y; float h = height(p); vec3 n = normal(p); vec3 ro = vec3(0.0, -10.0, 0.0); vec3 pp = vec3(p.x, 0.0, p.y); vec3 po = vec3(p.x, h, p.y); vec3 rd = normalize(ro - po); vec3 ld1 = normalize(lp1 - po); vec3 ld2 = normalize(lp2 - po); float diff1 = max(dot(n, ld1), 0.0); float diff2 = max(dot(n, ld2), 0.0); vec3 rn = n; vec3 ref = reflect(rd, rn); float ref1 = max(dot(ref, ld1), 0.0); float ref2 = max(dot(ref, ld2), 0.0); vec3 lpow1 = 0.15*lcol1/DOT2(ld1); vec3 lpow2 = 0.25*lcol2/DOT2(ld2); vec3 dm = mcol*tanh_approx(-h*5.0+0.125); vec3 col = vec3(0.0); col += dm*diff1*lpow1; col += dm*diff2*lpow2; vec3 rm = vec3(1.0)*mix(0.25, 1.0, tanh_approx(-h*1000.0)); col += rm*pow(ref1, spe1)*lcol1; col += rm*pow(ref2, spe2)*lcol2; const float top = 10.0; col = aces_approx(col); col = sRGB(col); return col; } void mainImage( out vec4 fragColor, in vec2 fragCoord ) { vec2 q = fragCoord/RESOLUTION.xy;; vec2 p = -1. + 2. * q; p.x *= RESOLUTION.x/RESOLUTION.y; vec3 col = effect(p, q); fragColor = vec4(col, 1.0); }
cc0-1.0
[ 1768, 1868, 1907, 1907, 1992 ]
[ [ 592, 592, 614, 614, 760 ], [ 1055, 1155, 1174, 1174, 1261 ], [ 1263, 1370, 1396, 1396, 1580 ], [ 1582, 1642, 1670, 1690, 1766 ], [ 1768, 1868, 1907, 1907, 1992 ], [ 1994, 2082, 2112, 2112, 2140 ], [ 2142, 2260, 2281, 2281, 2514 ], [ 2516, 2516, 2543, 2543, 2608 ], [ 2610, 2610, 2628, 2628, 2924 ], [ 2926, 2926, 2948, 2948, 3311 ], [ 3313, 3313, 3334, 3334, 3540 ], [ 3542, 3542, 3571, 3571, 4863 ], [ 4865, 4865, 4922, 4922, 5084 ] ]
// License: MIT, author: Inigo Quilez, found: https://www.iquilezles.org/www/articles/smin/smin.htm
float pmin(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); }
// License: MIT, author: Inigo Quilez, found: https://www.iquilezles.org/www/articles/smin/smin.htm float pmin(float a, float b, float k) {
63
107
NtKBWh
mrange
2022-09-29T05:45:01
// License CC0: Dark chocolate FBM // Working on a cake related shader and created kind of dark chocolate // background. Nothing unique but different colors than what I usually // do so sharing. #define TIME iTime #define RESOLUTION iResolution #define PI 3.141592654 #define TAU (2.0*PI) #define ROT(a) mat2(cos(a), sin(a), -sin(a), cos(a)) #define TTIME (TAU*TIME) #define DOT2(p) dot(p, p) // License: WTFPL, author: sam hocevar, found: https://stackoverflow.com/a/17897228/418488 const vec4 hsv2rgb_K = vec4(1.0, 2.0 / 3.0, 1.0 / 3.0, 3.0); vec3 hsv2rgb(vec3 c) { vec3 p = abs(fract(c.xxx + hsv2rgb_K.xyz) * 6.0 - hsv2rgb_K.www); return c.z * mix(hsv2rgb_K.xxx, clamp(p - hsv2rgb_K.xxx, 0.0, 1.0), 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)) // License: Unknown, author: nmz (twitter: @stormoid), found: https://www.shadertoy.com/view/NdfyRM vec3 sRGB(vec3 t) { return mix(1.055*pow(t, vec3(1./2.4)) - 0.055, 12.92*t, step(t, vec3(0.0031308))); } // License: Unknown, author: Matt Taylor (https://github.com/64), found: https://64.github.io/tonemapping/ vec3 aces_approx(vec3 v) { v = max(v, 0.0); 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); } // License: Unknown, author: Unknown, found: don't remember float tanh_approx(float x) { // return tanh(x); float x2 = x*x; return clamp(x*(27.0 + x2)/(27.0+9.0*x2), -1.0, 1.0); } // License: MIT, author: Inigo Quilez, found: https://www.iquilezles.org/www/articles/smin/smin.htm float pmin(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); } // License: CC0, author: Mårten Rånge, found: https://github.com/mrange/glsl-snippets float pabs(float a, float k) { return -pmin(a, -a, k); } // License: MIT, author: Inigo Quilez, found: https://iquilezles.org/www/articles/distfunctions2d/distfunctions2d.htm float heart(vec2 p) { p.y -= -0.6; p.x = pabs(p.x, 0.125); if( p.y+p.x>1.0 ) return sqrt(DOT2(p-vec2(0.25,0.75))) - sqrt(2.0)/4.0; return sqrt(min(DOT2(p-vec2(0.00,1.00)), DOT2(p-0.5*max(p.x+p.y,0.0)))) * sign(p.x-p.y); } vec2 mod2_1(inout vec2 p) { vec2 n = floor(p + 0.5); p = fract(p+0.5)-0.5; return n; } float hf(vec2 p) { p *= 0.25; vec2 p0 = p; vec2 n0 = mod2_1(p0); vec2 p1 = p*vec2(1.0, -1.0)+vec2(0.5, 0.66); vec2 n1 = mod2_1(p1); const float ss = 0.60; float d0 = heart(p0/ss)*ss; float d1 = heart(p1/ss)*ss; float d = min(d0, d1); return tanh_approx(smoothstep(0.0, -0.1,d)*exp(8.0*-d)); } float height(vec2 p) { const mat2 rot1 = ROT(1.0); float tm = 123.0+TTIME/240.0; p += 5.0*vec2(cos(tm), sin(tm*sqrt(0.5))); const float aa = -0.45; const mat2 pp = (1.0/aa)*rot1; float h = 0.0; float a = 1.0; float d = 0.0; for (int i = 0; i < 4; ++i) { h += a*hf(p); d += a; a *= aa; p *= pp; } const float hf = -0.125; return hf*(h/d)+hf; } vec3 normal(vec2 p) { vec2 v; vec2 w; vec2 e = vec2(4.0/RESOLUTION.y, 0); vec3 n; n.x = height(p + e.xy) - height(p - e.xy); n.y = 2.0*e.x; n.z = height(p + e.yx) - height(p - e.yx); return normalize(n); } vec3 effect(vec2 p, vec2 q) { vec2 ppp = p; const float s = 1.0; const vec3 lp1 = vec3(1.0, 1.25, 1.0)*vec3(s, 1.0, s); const vec3 lp2 = vec3(-1.0, 1.25, 1.0)*vec3(s, 1.0, s); const vec3 lcol1 = HSV2RGB(vec3(0.06, 0.9 , .5)); const vec3 lcol2 = HSV2RGB(vec3(0.05, 0.25, 1.0)); const vec3 mcol = HSV2RGB(vec3(0.1 , 0.95, 0.2)); const float spe1 = 20.0; const float spe2 = 40.0; float aa = 2.0/RESOLUTION.y; float h = height(p); vec3 n = normal(p); vec3 ro = vec3(0.0, -10.0, 0.0); vec3 pp = vec3(p.x, 0.0, p.y); vec3 po = vec3(p.x, h, p.y); vec3 rd = normalize(ro - po); vec3 ld1 = normalize(lp1 - po); vec3 ld2 = normalize(lp2 - po); float diff1 = max(dot(n, ld1), 0.0); float diff2 = max(dot(n, ld2), 0.0); vec3 rn = n; vec3 ref = reflect(rd, rn); float ref1 = max(dot(ref, ld1), 0.0); float ref2 = max(dot(ref, ld2), 0.0); vec3 lpow1 = 0.15*lcol1/DOT2(ld1); vec3 lpow2 = 0.25*lcol2/DOT2(ld2); vec3 dm = mcol*tanh_approx(-h*5.0+0.125); vec3 col = vec3(0.0); col += dm*diff1*lpow1; col += dm*diff2*lpow2; vec3 rm = vec3(1.0)*mix(0.25, 1.0, tanh_approx(-h*1000.0)); col += rm*pow(ref1, spe1)*lcol1; col += rm*pow(ref2, spe2)*lcol2; const float top = 10.0; col = aces_approx(col); col = sRGB(col); return col; } void mainImage( out vec4 fragColor, in vec2 fragCoord ) { vec2 q = fragCoord/RESOLUTION.xy;; vec2 p = -1. + 2. * q; p.x *= RESOLUTION.x/RESOLUTION.y; vec3 col = effect(p, q); fragColor = vec4(col, 1.0); }
cc0-1.0
[ 1994, 2082, 2112, 2112, 2140 ]
[ [ 592, 592, 614, 614, 760 ], [ 1055, 1155, 1174, 1174, 1261 ], [ 1263, 1370, 1396, 1396, 1580 ], [ 1582, 1642, 1670, 1690, 1766 ], [ 1768, 1868, 1907, 1907, 1992 ], [ 1994, 2082, 2112, 2112, 2140 ], [ 2142, 2260, 2281, 2281, 2514 ], [ 2516, 2516, 2543, 2543, 2608 ], [ 2610, 2610, 2628, 2628, 2924 ], [ 2926, 2926, 2948, 2948, 3311 ], [ 3313, 3313, 3334, 3334, 3540 ], [ 3542, 3542, 3571, 3571, 4863 ], [ 4865, 4865, 4922, 4922, 5084 ] ]
// License: CC0, author: Mårten Rånge, found: https://github.com/mrange/glsl-snippets
float pabs(float a, float k) {
return -pmin(a, -a, k); }
// License: CC0, author: Mårten Rånge, found: https://github.com/mrange/glsl-snippets float pabs(float a, float k) {
24
44
7tKfzh
IWBTShyGuy
2022-09-25T06:37:05
// Copyright © 2022 IWBTShyGuy // Attribution 4.0 International (CC BY 4.0) // Hash without Sine https://www.shadertoy.com/view/4djSRW 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); } float noise12(vec2 p) { vec2 t = fract(p); p = floor(p) + vec2(1.365, -0.593); vec2 e = vec2(0, 1); return mix( mix(hash12(p + e.xx), hash12(p + e.yx), t.x), mix(hash12(p + e.yx), hash12(p + e.yy), t.x), t.y ); } void mainImage(out vec4 O, in vec2 U) { O = vec4(0.95, 0.95, 0.9, 1); vec2 r = iResolution.xy, m = vec2(0), M = r, p = m, k, l, e = vec2(0, 1); float a; for (int i = 0; i < int(log2(length(r))/1.2); i++) { a = noise12(p + iTime * 0.1); if (a > 0.1 * dot(r, e) / dot(r, e.yx)) e = 1.0 - e; a = 0.35 + 0.3 * hash12(p + r * sign(U - p)); p += (m * (1.0 - a) + M * a - p) * e; if (abs(dot(p - U, e)) < 2.0) { O.xyz *= 0.0; return; } k = clamp(sign(U - p), 0.0, 1.0); l = clamp(sign(p - U), 0.0, 1.0); m += (max(k * p, m) - m) * e; M += (min(k * r + l * p, M) - M) * e; } a = noise12(p + sign(U - p) * r + iTime * 0.25); if (0.3 <= a && a < 0.4) O = vec4(0.9, 0, 0.2, 1); else if (0.4 <= a && a < 0.5) O = vec4(0.9, 0.9, 0, 1); else if (0.5 <= a && a < 0.6) O = vec4(0, 0.2, 1, 1); }
cc-by-4.0
[ 78, 137, 159, 159, 276 ]
[ [ 78, 137, 159, 159, 276 ], [ 278, 278, 301, 301, 534 ], [ 536, 536, 575, 575, 1454 ] ]
// Hash without Sine https://www.shadertoy.com/view/4djSRW
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); }
// Hash without Sine https://www.shadertoy.com/view/4djSRW float hash12(vec2 p) {
2
53
DdlGD8
iq
2022-10-18T02:38:00
// The MIT License // Copyright © 2022 Inigo Quilez // Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. // Signed distance and gradient to a quadratic bezier segment. // Faster than central differences or automatic differentiation/duals. // List of other 2D distances+gradients: // // https://iquilezles.org/articles/distgradfunctions2d // // and // // https://www.shadertoy.com/playlist/M3dSRf // .x = f(p) // .y = ∂f(p)/∂x // .z = ∂f(p)/∂y // .yz = ∇f(p) with ‖∇f(p)‖ =☺ 1 vec3 sdBezier( in vec2 pos, in vec2 A, in vec2 B, in vec2 C ) { vec2 a = B - A; vec2 b = A - 2.0*B + C; vec2 c = a * 2.0; vec2 d = A - pos; float kk = 1.0/dot(b,b); float kx = kk * dot(a,b); float ky = kk * (2.0*dot(a,a)+dot(d,b))/3.0; float kz = kk * dot(d,a); vec3 res; float p = ky - kx*kx; float q = kx*(2.0*kx*kx - 3.0*ky) + kz; float p3 = p*p*p; float q2 = q*q; float h = q2 + 4.0*p3; if( h>=0.0 ) // 1 root { h = sqrt(h); vec2 x = (vec2(h,-h)-q)/2.0; #if 0 // When p≈0 and p<0, h-q has catastrophic cancelation. So, we do // h=√(q²+4p³)=q·√(1+4p³/q²)=q·√(1+w) instead. Now we approximate // √ by a linear Taylor expansion into h≈q(1+½w) so that the q's // cancel each other in h-q. Expanding and simplifying further we // get x=vec2(p³/q,-p³/q-q). And using a second degree Taylor // expansion instead: x=vec2(k,-k-q) with k=(1-p³/q²)·p³/q if( abs(p)<0.001 ) { //float k = p3/q; // linear approx float k = (1.0-p3/q2)*p3/q; // quadratic approx x = vec2(k,-k-q); } #endif vec2 uv = sign(x)*pow(abs(x), vec2(1.0/3.0)); float t = clamp( uv.x+uv.y-kx, 0.0, 1.0 ); vec2 q = d+(c+b*t)*t; res = vec3(dot(q,q),q); } else // 3 roots { float z = sqrt(-p); float v = acos(q/(p*z*2.0))/3.0; float m = cos(v); float n = sin(v)*1.732050808; vec3 t = clamp( vec3(m+m,-n-m,n-m)*z-kx, 0.0, 1.0 ); vec2 qx = d+(c+b*t.x)*t.x; float dx=dot(qx,qx); vec2 qy = d+(c+b*t.y)*t.y; float dy=dot(qy,qy); res = (dx<dy) ? vec3(dx,qx) : vec3(dy,qy); } res.x = sqrt(res.x); res.yz /= -res.x; return res; } void mainImage(out vec4 fragColor, in vec2 fragCoord) { vec2 p = (2.0*fragCoord-iResolution.xy)/iResolution.y; vec2 m = (2.0*iMouse.xy-iResolution.xy)/iResolution.y; // animate vec2 v0 = vec2(1.3,0.9)*cos(iTime*0.5 + vec2(0.0,5.0) ); vec2 v1 = vec2(1.3,0.9)*cos(iTime*0.6 + vec2(3.0,4.0) ); vec2 v2 = vec2(1.3,0.9)*cos(iTime*0.7 + vec2(2.0,0.0) ); // sdf vec3 dg = sdBezier( p, v0, v1, v2 ); float d = dg.x; vec2 g = dg.yz; // central differenes based gradient, for comparison //g = vec2(dFdx(d),dFdy(d))/(2.0/iResolution.y); // coloring vec3 col = (d>0.0) ? vec3(0.9,0.6,0.3) : vec3(0.4,0.7,0.85); col *= 1.0 + vec3(0.5*g,0.0); col *= 1.0 - 0.5*exp(-16.0*abs(d)); col *= 0.9 + 0.1*cos(150.0*d); col = mix( col, vec3(1.0), 1.0-smoothstep(0.0,0.01,abs(d)) ); if( iMouse.z>0.001 ) { d = sdBezier( m, v0, v1, v2 ).x; col = mix(col, vec3(1.0,1.0,0.0), 1.0-smoothstep(0.0, 0.005, abs(length(p-m)-abs(d))-0.0025)); col = mix(col, vec3(1.0,1.0,0.0), 1.0-smoothstep(0.0, 0.005, length(p-m)-0.015)); } fragColor = vec4(col,1.0); }
mit
[ 1372, 1470, 1533, 1533, 3367 ]
[ [ 1372, 1470, 1533, 1533, 3367 ], [ 3369, 3369, 3424, 3424, 4507 ] ]
// .x = f(p) // .y = ∂f(p)/∂x // .z = ∂f(p)/∂y // .yz = ∇f(p) with ‖∇f(p)‖ =☺ 1
vec3 sdBezier( in vec2 pos, in vec2 A, in vec2 B, in vec2 C ) {
vec2 a = B - A; vec2 b = A - 2.0*B + C; vec2 c = a * 2.0; vec2 d = A - pos; float kk = 1.0/dot(b,b); float kx = kk * dot(a,b); float ky = kk * (2.0*dot(a,a)+dot(d,b))/3.0; float kz = kk * dot(d,a); vec3 res; float p = ky - kx*kx; float q = kx*(2.0*kx*kx - 3.0*ky) + kz; float p3 = p*p*p; float q2 = q*q; float h = q2 + 4.0*p3; if( h>=0.0 ) // 1 root { h = sqrt(h); vec2 x = (vec2(h,-h)-q)/2.0; #if 0 // When p≈0 and p<0, h-q has catastrophic cancelation. So, we do // h=√(q²+4p³)=q·√(1+4p³/q²)=q·√(1+w) instead. Now we approximate // √ by a linear Taylor expansion into h≈q(1+½w) so that the q's // cancel each other in h-q. Expanding and simplifying further we // get x=vec2(p³/q,-p³/q-q). And using a second degree Taylor // expansion instead: x=vec2(k,-k-q) with k=(1-p³/q²)·p³/q if( abs(p)<0.001 ) { //float k = p3/q; // linear approx float k = (1.0-p3/q2)*p3/q; // quadratic approx x = vec2(k,-k-q); } #endif vec2 uv = sign(x)*pow(abs(x), vec2(1.0/3.0)); float t = clamp( uv.x+uv.y-kx, 0.0, 1.0 ); vec2 q = d+(c+b*t)*t; res = vec3(dot(q,q),q); } else // 3 roots { float z = sqrt(-p); float v = acos(q/(p*z*2.0))/3.0; float m = cos(v); float n = sin(v)*1.732050808; vec3 t = clamp( vec3(m+m,-n-m,n-m)*z-kx, 0.0, 1.0 ); vec2 qx = d+(c+b*t.x)*t.x; float dx=dot(qx,qx); vec2 qy = d+(c+b*t.y)*t.y; float dy=dot(qy,qy); res = (dx<dy) ? vec3(dx,qx) : vec3(dy,qy); } res.x = sqrt(res.x); res.yz /= -res.x; return res; }
// .x = f(p) // .y = ∂f(p)/∂x // .z = ∂f(p)/∂y // .yz = ∇f(p) with ‖∇f(p)‖ =☺ 1 vec3 sdBezier( in vec2 pos, in vec2 A, in vec2 B, in vec2 C ) {
1
1
Dss3W8
iq
2022-10-18T02:29:22
// The MIT License // Copyright © 2022 Inigo Quilez // Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. // Signed distance and gradient to a parabolic segment. // Faster than central differences or automatic // differentiation/dual numbers. // List of other 2D distances+gradients: // // https://iquilezles.org/articles/distgradfunctions2d // // and // // https://www.shadertoy.com/playlist/M3dSRf // .x = f(p) // .y = ∂f(p)/∂x // .z = ∂f(p)/∂y // .yz = ∇f(p) with ‖∇f(p)‖ = 1 vec3 sdParabola( in vec2 pos, in float wi, in float he ) { float s = sign(pos.x); pos.x = abs(pos.x); float ik = wi*wi/he; float p = ik*(he-pos.y-0.5*ik)/3.0; float q = pos.x*ik*ik*0.25; float h = q*q - p*p*p; float x; if( h>0.0 ) // 1 root { float r = sqrt(h); x = pow(q+r,1.0/3.0) + pow(abs(q-r),1.0/3.0)*sign(p); } else // 3 roots { float r = sqrt(p); x = 2.0*r*cos(acos(q/(p*r))/3.0); // see https://www.shadertoy.com/view/WltSD7 for an implementation of cos(acos(x)/3) without trigonometrics } x = min(x,wi); vec2 w = pos - vec2(x,he-x*x/ik); float d = length(w); w.x *= s; return vec3(d,w/d); } void mainImage(out vec4 fragColor, in vec2 fragCoord) { vec2 p = (2.0*fragCoord-iResolution.xy)/iResolution.y; vec2 m = (2.0*iMouse.xy-iResolution.xy)/iResolution.y; // animate float t = iTime/2.0; float w = 0.7+0.69*sin(iTime*0.61+0.0); float h = 0.4+0.35*sin(iTime*0.53+2.0); // sdf vec3 dg = sdParabola( p, w, h ); float d = dg.x; vec2 g = dg.yz; // central differenes based gradient, for comparison //g = vec2(dFdx(d),dFdy(d))/(2.0/iResolution.y); // coloring vec3 col = (d>0.0) ? vec3(0.9,0.6,0.3) : vec3(0.4,0.7,0.85); col *= 1.0 + vec3(0.5*g,0.0); col *= 1.0 - 0.5*exp(-16.0*abs(d)); col *= 0.9 + 0.1*cos(150.0*d); col = mix( col, vec3(1.0), 1.0-smoothstep(0.0,0.01,abs(d)) ); if( iMouse.z>0.001 ) { d = sdParabola(m, w, h ).x; col = mix(col, vec3(1.0,1.0,0.0), 1.0-smoothstep(0.0, 0.005, abs(length(p-m)-abs(d))-0.0025)); col = mix(col, vec3(1.0,1.0,0.0), 1.0-smoothstep(0.0, 0.005, length(p-m)-0.015)); } fragColor = vec4(col,1.0); }
mit
[ 1376, 1471, 1529, 1529, 2198 ]
[ [ 1376, 1471, 1529, 1529, 2198 ], [ 2200, 2200, 2255, 2255, 3259 ] ]
// .x = f(p) // .y = ∂f(p)/∂x // .z = ∂f(p)/∂y // .yz = ∇f(p) with ‖∇f(p)‖ = 1
vec3 sdParabola( in vec2 pos, in float wi, in float he ) {
float s = sign(pos.x); pos.x = abs(pos.x); float ik = wi*wi/he; float p = ik*(he-pos.y-0.5*ik)/3.0; float q = pos.x*ik*ik*0.25; float h = q*q - p*p*p; float x; if( h>0.0 ) // 1 root { float r = sqrt(h); x = pow(q+r,1.0/3.0) + pow(abs(q-r),1.0/3.0)*sign(p); } else // 3 roots { float r = sqrt(p); x = 2.0*r*cos(acos(q/(p*r))/3.0); // see https://www.shadertoy.com/view/WltSD7 for an implementation of cos(acos(x)/3) without trigonometrics } x = min(x,wi); vec2 w = pos - vec2(x,he-x*x/ik); float d = length(w); w.x *= s; return vec3(d,w/d); }
// .x = f(p) // .y = ∂f(p)/∂x // .z = ∂f(p)/∂y // .yz = ∇f(p) with ‖∇f(p)‖ = 1 vec3 sdParabola( in vec2 pos, in float wi, in float he ) {
1
1
mdX3WH
iq
2022-10-17T23:16:05
// The MIT License // Copyright © 2022 Inigo Quilez // Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. // Signed distance and gradient to a parabola. // Probably faster than central differences or // automatic differentiation/dual numbers. // List of other 2D distances+gradients: // // https://iquilezles.org/articles/distgradfunctions2d // // and // // https://www.shadertoy.com/playlist/M3dSRf // .x = f(p) // .y = ∂f(p)/∂x // .z = ∂f(p)/∂y // .yz = ∇f(p) with ‖∇f(p)‖ = 1 vec3 sdParabola( in vec2 pos, in float k ) { float s = sign(pos.x); pos.x = abs(pos.x); float ik = 1.0/k; float p = ik*(pos.y - 0.5*ik)/3.0; float q = 0.25*ik*ik*pos.x; float h = q*q - p*p*p; float r = sqrt(abs(h)); float x = (h>0.0) ? // 1 root pow(q+r,1.0/3.0) - pow(abs(q-r),1.0/3.0)*sign(r-q) : // 3 roots 2.0*cos(atan(r,q)/3.0)*sqrt(p); float z = (pos.x-x<0.0)?-1.0:1.0; vec2 w = pos-vec2(x,k*x*x); float l = length(w); w.x*=s; return z*vec3(l, w/l ); } void mainImage(out vec4 fragColor, in vec2 fragCoord) { vec2 p = (2.0*fragCoord-iResolution.xy)/iResolution.y; vec2 m = (2.0*iMouse.xy-iResolution.xy)/iResolution.y; // animate float t = iTime/2.0; float px = 0.0 + 0.4*cos(t*1.1+5.5); // x position float py = -0.4 + 0.2*cos(t*1.2+3.0); // y position float pk = 8.0 + 7.5*cos(t*1.3+3.5); // width // sdf vec3 dg = sdParabola( p-vec2(px,py), pk ); float d = dg.x; vec2 g = dg.yz; // central differenes based gradient, for comparison //g = vec2(dFdx(d),dFdy(d))/(2.0/iResolution.y); // coloring vec3 col = (d>0.0) ? vec3(0.9,0.6,0.3) : vec3(0.4,0.7,0.85); col *= 1.0 + vec3(0.5*g,0.0); //col = vec3(0.5+0.5*g,1.0); col *= 1.0 - 0.5*exp(-16.0*abs(d)); col *= 0.9 + 0.1*cos(150.0*d); col = mix( col, vec3(1.0), 1.0-smoothstep(0.0,0.01,abs(d)) ); if( iMouse.z>0.001 ) { d = sdParabola(m-vec2(px,py), pk ).x; col = mix(col, vec3(1.0,1.0,0.0), 1.0-smoothstep(0.0, 0.005, abs(length(p-m)-abs(d))-0.0025)); col = mix(col, vec3(1.0,1.0,0.0), 1.0-smoothstep(0.0, 0.005, length(p-m)-0.015)); } fragColor = vec4(col,1.0); }
mit
[ 1375, 1470, 1514, 1514, 2026 ]
[ [ 1375, 1470, 1514, 1514, 2026 ], [ 2028, 2028, 2083, 2083, 3217 ] ]
// .x = f(p) // .y = ∂f(p)/∂x // .z = ∂f(p)/∂y // .yz = ∇f(p) with ‖∇f(p)‖ = 1
vec3 sdParabola( in vec2 pos, in float k ) {
float s = sign(pos.x); pos.x = abs(pos.x); float ik = 1.0/k; float p = ik*(pos.y - 0.5*ik)/3.0; float q = 0.25*ik*ik*pos.x; float h = q*q - p*p*p; float r = sqrt(abs(h)); float x = (h>0.0) ? // 1 root pow(q+r,1.0/3.0) - pow(abs(q-r),1.0/3.0)*sign(r-q) : // 3 roots 2.0*cos(atan(r,q)/3.0)*sqrt(p); float z = (pos.x-x<0.0)?-1.0:1.0; vec2 w = pos-vec2(x,k*x*x); float l = length(w); w.x*=s; return z*vec3(l, w/l ); }
// .x = f(p) // .y = ∂f(p)/∂x // .z = ∂f(p)/∂y // .yz = ∇f(p) with ‖∇f(p)‖ = 1 vec3 sdParabola( in vec2 pos, in float k ) {
1
1
ddX3WH
iq
2022-10-17T23:14:56
// The MIT License // Copyright © 2022 Inigo Quilez // Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. // Signed distance and gradient to a moon shape. Faster than // central differences or automatic differentiation/duals. // List of other 2D distances+gradients: // // https://iquilezles.org/articles/distgradfunctions2d // // and // // https://www.shadertoy.com/playlist/M3dSRf // .x = f(p) // .y = ∂f(p)/∂x // .z = ∂f(p)/∂y // .yz = ∇f(p) with ‖∇f(p)‖ = 1 vec3 sdMoon(vec2 p, float d, float ra, float rb ) { float s = sign(p.y); p.y = abs(p.y); float a = (ra*ra - rb*rb + d*d)/(2.0*d); float b = sqrt(max(ra*ra-a*a,0.0)); if( d*(p.x*b-p.y*a) > d*d*max(b-p.y,0.0) ) { vec2 w = p-vec2(a,b); float d = length(w); w.y *= s; return vec3(d,w/d); } vec2 w1 = p; ; float l1 = length(w1); float d1 = l1-ra; w1.y *= s; vec2 w2 = p-vec2(d,0); float l2 = length(w2); float d2 = rb-l2; w2.y *= s; return (d1>d2) ? vec3(d1,w1/l1) : vec3(d2,-w2/l2); } void mainImage(out vec4 fragColor, in vec2 fragCoord) { vec2 p = (2.0*fragCoord-iResolution.xy)/iResolution.y; vec2 m = (2.0*iMouse.xy-iResolution.xy)/iResolution.y; // animate float ra = 0.9; float rb = 0.7; float di = 1.2*cos(iTime+3.9); // sdf vec3 dg = sdMoon( p, di, ra, rb ); float d = dg.x; vec2 g = dg.yz; // central differenes based gradient, for comparison //g = vec2(dFdx(d),dFdy(d))/(2.0/iResolution.y); // coloring vec3 col = (d>0.0) ? vec3(0.9,0.6,0.3) : vec3(0.4,0.7,0.85); col *= 1.0 + vec3(0.5*g,0.0); col *= 1.0 - 0.5*exp(-16.0*abs(d)); col *= 0.9 + 0.1*cos(150.0*d); col = mix( col, vec3(1.0), 1.0-smoothstep(0.0,0.01,abs(d)) ); if( iMouse.z>0.001 ) { d = sdMoon(m, di, ra, rb ).x; col = mix(col, vec3(1.0,1.0,0.0), 1.0-smoothstep(0.0, 0.005, abs(length(p-m)-abs(d))-0.0025)); col = mix(col, vec3(1.0,1.0,0.0), 1.0-smoothstep(0.0, 0.005, length(p-m)-0.015)); } fragColor = vec4(col,1.0); }
mit
[ 1358, 1453, 1504, 1504, 2004 ]
[ [ 1358, 1453, 1504, 1504, 2004 ], [ 2006, 2006, 2061, 2061, 3035 ] ]
// .x = f(p) // .y = ∂f(p)/∂x // .z = ∂f(p)/∂y // .yz = ∇f(p) with ‖∇f(p)‖ = 1
vec3 sdMoon(vec2 p, float d, float ra, float rb ) {
float s = sign(p.y); p.y = abs(p.y); float a = (ra*ra - rb*rb + d*d)/(2.0*d); float b = sqrt(max(ra*ra-a*a,0.0)); if( d*(p.x*b-p.y*a) > d*d*max(b-p.y,0.0) ) { vec2 w = p-vec2(a,b); float d = length(w); w.y *= s; return vec3(d,w/d); } vec2 w1 = p; ; float l1 = length(w1); float d1 = l1-ra; w1.y *= s; vec2 w2 = p-vec2(d,0); float l2 = length(w2); float d2 = rb-l2; w2.y *= s; return (d1>d2) ? vec3(d1,w1/l1) : vec3(d2,-w2/l2); }
// .x = f(p) // .y = ∂f(p)/∂x // .z = ∂f(p)/∂y // .yz = ∇f(p) with ‖∇f(p)‖ = 1 vec3 sdMoon(vec2 p, float d, float ra, float rb ) {
1
1
slyfDc
kara0xfb
2022-10-10T00:32:31
// The MIT License // Copyright © 2013 Inigo Quilez // Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. // https://www.youtube.com/c/InigoQuilez // https://iquilezles.org // Gradient Noise (http://en.wikipedia.org/wiki/Gradient_noise), not to be confused with // Value Noise, and neither with Perlin's Noise (which is one form of Gradient Noise) // is probably the most convenient way to generate noise (a random smooth signal with // mostly all its energy in the low frequencies) suitable for procedural texturing/shading, // modeling and animation. // // It produces smoother and higher quality than Value Noise, but it's of course slighty more // expensive. // // The princpiple is to create a virtual grid/latice all over the plane, and assign one // random vector to every vertex in the grid. When querying/requesting a noise value at // an arbitrary point in the plane, the grid cell in which the query is performed is // determined, the four vertices of the grid are determined and their random vectors // fetched. Then, the position of the current point under evaluation relative to each // vertex is doted (projected) with that vertex' random vector, and the result is // bilinearly interpolated with a smooth interpolant. // Value Noise 2D, Derivatives: https://www.shadertoy.com/view/4dXBRH // Gradient Noise 2D, Derivatives: https://www.shadertoy.com/view/XdXBRH // Value Noise 3D, Derivatives: https://www.shadertoy.com/view/XsXfRH // Gradient Noise 3D, Derivatives: https://www.shadertoy.com/view/4dffRH // Value Noise 2D : https://www.shadertoy.com/view/lsf3WH // Value Noise 3D : https://www.shadertoy.com/view/4sfGzS // Gradient Noise 2D : https://www.shadertoy.com/view/XdXGW8 // Gradient Noise 3D : https://www.shadertoy.com/view/Xsl3Dl // Simplex Noise 2D : https://www.shadertoy.com/view/Msf3WH // Wave Noise 2D : https://www.shadertoy.com/view/tldSRj // Hash Functions for GPU Rendering - Jarzynski, Olano // https://www.jcgt.org/published/0009/03/02/ ivec2 Pcg2(ivec2 v) { uint x = uint(v.x); uint y = uint(v.y); x = x * 1664525u + 1013904223u; y = y * 1664525u + 1013904223u; x += y * 1664525u; y += x * 1664525u; x ^= x >> 16; y ^= y >> 16; x += y * 1664525u; y += x * 1664525u; return ivec2(x, y); } // Hash Functions for GPU Rendering - Jarzynski, Olano // https://www.jcgt.org/published/0009/03/02/ ivec3 Pcg3(ivec3 v) { uint x = uint(v.x); uint y = uint(v.y); uint z = uint(v.z); x = x * 1664525u + 1013904223u; y = y * 1664525u + 1013904223u; z = z * 1664525u + 1013904223u; x += y * z; y += z * x; z += x * y; x ^= x >> 16; y ^= y >> 16; z ^= z >> 16; x += y * z; y += z * x; z += x * y; return ivec3(x, y, z); } // Hash Functions for GPU Rendering - Jarzynski, Olano // https://www.jcgt.org/published/0009/03/02/ ivec4 Pcg4(ivec4 v) { uint x = uint(v.x); uint y = uint(v.y); uint z = uint(v.z); uint w = uint(v.w); x = x * 1664525u + 1013904223u; y = y * 1664525u + 1013904223u; z = z * 1664525u + 1013904223u; w = w * 1664525u + 1013904223u; x += y * w; y += z * x; z += x * y; w += y * z; x ^= x >> 16; y ^= y >> 16; z ^= z >> 16; w ^= w >> 16; x += y * w; y += z * x; z += x * y; w += y * z; return ivec4(x, y, z, w); } vec2 grad2( ivec2 v ) { int n = Pcg2(v).x; // higher quality rng in high bits float x = (n & (1<<30)) != 0 ? 1.0 : -1.0; float y = (n & (1<<29)) != 0 ? 1.0 : -1.0; float z = (n & (1<<28)) != 0 ? 1.0 : -1.0; vec3 gr = vec3(x, y, z); return vec2(gr.x, gr.y); } vec3 grad3( ivec3 v) { v = Pcg3(v); // higher quality rng in high bits float x = (v.x & (1<<30)) != 0 ? 1.0 : -1.0; float y = (v.y & (1<<29)) != 0 ? 1.0 : -1.0; float z = (v.z & (1<<28)) != 0 ? 1.0 : -1.0; return vec3(x, y, z); } float noise2( in vec2 p ) { ivec2 i = ivec2(floor( p )); vec2 f = fract( p ); vec2 u = f * f * ((f * -2.0f) + 3.0f); float c00 = dot(grad2(i + ivec2(0,0)), f - vec2(0.0, 0.0)); float c01 = dot(grad2(i + ivec2(1,0)), f - vec2(1.0, 0.0)); float c10 = dot(grad2(i + ivec2(0,1)), f - vec2(0.0, 1.0)); float c11 = dot(grad2(i + ivec2(1,1)), f - vec2(1.0, 1.0)); float c = mix(mix(c00, c01, u.x), mix(c10, c11, u.x), u.y); return c; } float noise3(in vec3 p) { ivec3 i = ivec3(floor( p )); vec3 f = fract( p ); vec3 u = f * f * ((f * -2.0f) + 3.0f); float c000 = dot(grad3(i + ivec3(0,0,0)), f - vec3(0.0,0.0,0.0)); float c001 = dot(grad3(i + ivec3(0,0,1)), f - vec3(0.0,0.0,1.0)); float c010 = dot(grad3(i + ivec3(0,1,0)), f - vec3(0.0,1.0,0.0)); float c011 = dot(grad3(i + ivec3(0,1,1)), f - vec3(0.0,1.0,1.0)); float c100 = dot(grad3(i + ivec3(1,0,0)), f - vec3(1.0,0.0,0.0)); float c101 = dot(grad3(i + ivec3(1,0,1)), f - vec3(1.0,0.0,1.0)); float c110 = dot(grad3(i + ivec3(1,1,0)), f - vec3(1.0,1.0,0.0)); float c111 = dot(grad3(i + ivec3(1,1,1)), f - vec3(1.0,1.0,1.0)); float c00z = mix(c000, c001, u.z); float c01z = mix(c010, c011, u.z); float c10z = mix(c100, c101, u.z); float c11z = mix(c110, c111, u.z); float c0yz = mix(c00z, c01z, u.y); float c1yz = mix(c10z, c11z, u.y); float cxyz = mix(c0yz, c1yz, u.x); return cxyz; } // ----------------------------------------------- void mainImage( out vec4 fragColor, in vec2 fragCoord ) { vec2 p = fragCoord / iResolution.xy; float f = 0.0; vec2 uv2 = p*vec2(iResolution.x/iResolution.y,1.0); vec3 uv3 = vec3(uv2.x, uv2.y,iTime); uv3.xy = 32.0 * uv3.xy; float freq = 1.0; float scale = 1.0; float peak = 0.0; float u = min(p.x, 1.0); float octaves = 1.0 + u * 3.0; octaves = min(octaves, 4.0); for (float i = 0.0; i < ceil(octaves); i += 1.0) { float amt = min(max(octaves - i, 0.0), 1.0); scale *= amt; peak += scale; f += scale * noise3(uv3 * freq); scale *= 0.55; freq *= 2.0136; } f = f / peak; f = 0.5 + 0.5*f; fragColor = vec4( f, f, f, 1.0 ); }
mit
[ 2942, 3043, 3064, 3064, 3338 ]
[ [ 2942, 3043, 3064, 3064, 3338 ], [ 3340, 3441, 3462, 3462, 3821 ], [ 3823, 3924, 3945, 3945, 4417 ], [ 4419, 4419, 4442, 4442, 4705 ], [ 4707, 4707, 4729, 4729, 4960 ], [ 4962, 4962, 4989, 4989, 5438 ], [ 5440, 5440, 5465, 5465, 6460 ], [ 6514, 6514, 6571, 6571, 7249 ] ]
// Hash Functions for GPU Rendering - Jarzynski, Olano // https://www.jcgt.org/published/0009/03/02/
ivec2 Pcg2(ivec2 v) {
uint x = uint(v.x); uint y = uint(v.y); x = x * 1664525u + 1013904223u; y = y * 1664525u + 1013904223u; x += y * 1664525u; y += x * 1664525u; x ^= x >> 16; y ^= y >> 16; x += y * 1664525u; y += x * 1664525u; return ivec2(x, y); }
// Hash Functions for GPU Rendering - Jarzynski, Olano // https://www.jcgt.org/published/0009/03/02/ ivec2 Pcg2(ivec2 v) {
1
1
slyfDc
kara0xfb
2022-10-10T00:32:31
// The MIT License // Copyright © 2013 Inigo Quilez // Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. // https://www.youtube.com/c/InigoQuilez // https://iquilezles.org // Gradient Noise (http://en.wikipedia.org/wiki/Gradient_noise), not to be confused with // Value Noise, and neither with Perlin's Noise (which is one form of Gradient Noise) // is probably the most convenient way to generate noise (a random smooth signal with // mostly all its energy in the low frequencies) suitable for procedural texturing/shading, // modeling and animation. // // It produces smoother and higher quality than Value Noise, but it's of course slighty more // expensive. // // The princpiple is to create a virtual grid/latice all over the plane, and assign one // random vector to every vertex in the grid. When querying/requesting a noise value at // an arbitrary point in the plane, the grid cell in which the query is performed is // determined, the four vertices of the grid are determined and their random vectors // fetched. Then, the position of the current point under evaluation relative to each // vertex is doted (projected) with that vertex' random vector, and the result is // bilinearly interpolated with a smooth interpolant. // Value Noise 2D, Derivatives: https://www.shadertoy.com/view/4dXBRH // Gradient Noise 2D, Derivatives: https://www.shadertoy.com/view/XdXBRH // Value Noise 3D, Derivatives: https://www.shadertoy.com/view/XsXfRH // Gradient Noise 3D, Derivatives: https://www.shadertoy.com/view/4dffRH // Value Noise 2D : https://www.shadertoy.com/view/lsf3WH // Value Noise 3D : https://www.shadertoy.com/view/4sfGzS // Gradient Noise 2D : https://www.shadertoy.com/view/XdXGW8 // Gradient Noise 3D : https://www.shadertoy.com/view/Xsl3Dl // Simplex Noise 2D : https://www.shadertoy.com/view/Msf3WH // Wave Noise 2D : https://www.shadertoy.com/view/tldSRj // Hash Functions for GPU Rendering - Jarzynski, Olano // https://www.jcgt.org/published/0009/03/02/ ivec2 Pcg2(ivec2 v) { uint x = uint(v.x); uint y = uint(v.y); x = x * 1664525u + 1013904223u; y = y * 1664525u + 1013904223u; x += y * 1664525u; y += x * 1664525u; x ^= x >> 16; y ^= y >> 16; x += y * 1664525u; y += x * 1664525u; return ivec2(x, y); } // Hash Functions for GPU Rendering - Jarzynski, Olano // https://www.jcgt.org/published/0009/03/02/ ivec3 Pcg3(ivec3 v) { uint x = uint(v.x); uint y = uint(v.y); uint z = uint(v.z); x = x * 1664525u + 1013904223u; y = y * 1664525u + 1013904223u; z = z * 1664525u + 1013904223u; x += y * z; y += z * x; z += x * y; x ^= x >> 16; y ^= y >> 16; z ^= z >> 16; x += y * z; y += z * x; z += x * y; return ivec3(x, y, z); } // Hash Functions for GPU Rendering - Jarzynski, Olano // https://www.jcgt.org/published/0009/03/02/ ivec4 Pcg4(ivec4 v) { uint x = uint(v.x); uint y = uint(v.y); uint z = uint(v.z); uint w = uint(v.w); x = x * 1664525u + 1013904223u; y = y * 1664525u + 1013904223u; z = z * 1664525u + 1013904223u; w = w * 1664525u + 1013904223u; x += y * w; y += z * x; z += x * y; w += y * z; x ^= x >> 16; y ^= y >> 16; z ^= z >> 16; w ^= w >> 16; x += y * w; y += z * x; z += x * y; w += y * z; return ivec4(x, y, z, w); } vec2 grad2( ivec2 v ) { int n = Pcg2(v).x; // higher quality rng in high bits float x = (n & (1<<30)) != 0 ? 1.0 : -1.0; float y = (n & (1<<29)) != 0 ? 1.0 : -1.0; float z = (n & (1<<28)) != 0 ? 1.0 : -1.0; vec3 gr = vec3(x, y, z); return vec2(gr.x, gr.y); } vec3 grad3( ivec3 v) { v = Pcg3(v); // higher quality rng in high bits float x = (v.x & (1<<30)) != 0 ? 1.0 : -1.0; float y = (v.y & (1<<29)) != 0 ? 1.0 : -1.0; float z = (v.z & (1<<28)) != 0 ? 1.0 : -1.0; return vec3(x, y, z); } float noise2( in vec2 p ) { ivec2 i = ivec2(floor( p )); vec2 f = fract( p ); vec2 u = f * f * ((f * -2.0f) + 3.0f); float c00 = dot(grad2(i + ivec2(0,0)), f - vec2(0.0, 0.0)); float c01 = dot(grad2(i + ivec2(1,0)), f - vec2(1.0, 0.0)); float c10 = dot(grad2(i + ivec2(0,1)), f - vec2(0.0, 1.0)); float c11 = dot(grad2(i + ivec2(1,1)), f - vec2(1.0, 1.0)); float c = mix(mix(c00, c01, u.x), mix(c10, c11, u.x), u.y); return c; } float noise3(in vec3 p) { ivec3 i = ivec3(floor( p )); vec3 f = fract( p ); vec3 u = f * f * ((f * -2.0f) + 3.0f); float c000 = dot(grad3(i + ivec3(0,0,0)), f - vec3(0.0,0.0,0.0)); float c001 = dot(grad3(i + ivec3(0,0,1)), f - vec3(0.0,0.0,1.0)); float c010 = dot(grad3(i + ivec3(0,1,0)), f - vec3(0.0,1.0,0.0)); float c011 = dot(grad3(i + ivec3(0,1,1)), f - vec3(0.0,1.0,1.0)); float c100 = dot(grad3(i + ivec3(1,0,0)), f - vec3(1.0,0.0,0.0)); float c101 = dot(grad3(i + ivec3(1,0,1)), f - vec3(1.0,0.0,1.0)); float c110 = dot(grad3(i + ivec3(1,1,0)), f - vec3(1.0,1.0,0.0)); float c111 = dot(grad3(i + ivec3(1,1,1)), f - vec3(1.0,1.0,1.0)); float c00z = mix(c000, c001, u.z); float c01z = mix(c010, c011, u.z); float c10z = mix(c100, c101, u.z); float c11z = mix(c110, c111, u.z); float c0yz = mix(c00z, c01z, u.y); float c1yz = mix(c10z, c11z, u.y); float cxyz = mix(c0yz, c1yz, u.x); return cxyz; } // ----------------------------------------------- void mainImage( out vec4 fragColor, in vec2 fragCoord ) { vec2 p = fragCoord / iResolution.xy; float f = 0.0; vec2 uv2 = p*vec2(iResolution.x/iResolution.y,1.0); vec3 uv3 = vec3(uv2.x, uv2.y,iTime); uv3.xy = 32.0 * uv3.xy; float freq = 1.0; float scale = 1.0; float peak = 0.0; float u = min(p.x, 1.0); float octaves = 1.0 + u * 3.0; octaves = min(octaves, 4.0); for (float i = 0.0; i < ceil(octaves); i += 1.0) { float amt = min(max(octaves - i, 0.0), 1.0); scale *= amt; peak += scale; f += scale * noise3(uv3 * freq); scale *= 0.55; freq *= 2.0136; } f = f / peak; f = 0.5 + 0.5*f; fragColor = vec4( f, f, f, 1.0 ); }
mit
[ 3340, 3441, 3462, 3462, 3821 ]
[ [ 2942, 3043, 3064, 3064, 3338 ], [ 3340, 3441, 3462, 3462, 3821 ], [ 3823, 3924, 3945, 3945, 4417 ], [ 4419, 4419, 4442, 4442, 4705 ], [ 4707, 4707, 4729, 4729, 4960 ], [ 4962, 4962, 4989, 4989, 5438 ], [ 5440, 5440, 5465, 5465, 6460 ], [ 6514, 6514, 6571, 6571, 7249 ] ]
// Hash Functions for GPU Rendering - Jarzynski, Olano // https://www.jcgt.org/published/0009/03/02/
ivec3 Pcg3(ivec3 v) {
uint x = uint(v.x); uint y = uint(v.y); uint z = uint(v.z); x = x * 1664525u + 1013904223u; y = y * 1664525u + 1013904223u; z = z * 1664525u + 1013904223u; x += y * z; y += z * x; z += x * y; x ^= x >> 16; y ^= y >> 16; z ^= z >> 16; x += y * z; y += z * x; z += x * y; return ivec3(x, y, z); }
// Hash Functions for GPU Rendering - Jarzynski, Olano // https://www.jcgt.org/published/0009/03/02/ ivec3 Pcg3(ivec3 v) {
1
1
dls3Wr
mkeeter
2022-12-21T17:04:32
// Using distance-to-quadratic and winding number to generate a closed-form // distance field of a font outline, which is specified as lines + quadratic // Bézier curves. // // Quadratic solver is based on https://www.shadertoy.com/view/MlKcDD, which // includes the following copyright notice: // // Copyright © 2018 Inigo Quilez // Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. // Curves are baked by an external tool #define QUAD_COUNT 38 const vec2 QUADS[QUAD_COUNT * 3] = vec2[QUAD_COUNT * 3]( vec2(0.5758487, -4.5724106), vec2(0.5758487, -4.9204984), vec2(0.7176622, -5.221315), vec2(0.7176622, -5.221315), vec2(0.8594757, -5.5221314), vec2(1.1216158, -5.758487), vec2(0.7520412, -2.0842285), vec2(0.8594757, -1.6974645), vec2(1.0034379, -1.3859046), vec2(0.86162436, -3.5904598), vec2(0.5758487, -3.9664803), vec2(0.5758487, -4.5724106), vec2(1.0034379, -1.3859046), vec2(1.1474, -1.0743446), vec2(1.3837559, -0.8036098), vec2(1.1216158, -5.758487), vec2(1.3708637, -5.9819508), vec2(1.7103566, -6.1087236), vec2(1.3794585, -4.9591746), vec2(1.3794585, -4.563816), vec2(1.5642458, -4.3038244), vec2(1.3837559, -0.8036098), vec2(1.6072196, -0.55006444), vec2(1.9058874, -0.3996562), vec2(1.5642458, -4.3038244), vec2(1.7490331, -4.0438333), vec2(2.101418, -3.8762355), vec2(1.6630855, -2.9823806), vec2(1.1474, -3.2144392), vec2(0.86162436, -3.5904598), vec2(1.6673828, -5.599484), vec2(1.3794585, -5.337344), vec2(1.3794585, -4.9591746), vec2(1.6974645, -0.0021486892), vec2(1.2892135, -0.12892136), vec2(0.99269444, -0.30941126), vec2(1.7103566, -6.1087236), vec2(2.0498495, -6.235496), vec2(2.419424, -6.235496), vec2(1.9058874, -0.3996562), vec2(2.2045553, -0.24924795), vec2(2.599914, -0.24924795), vec2(2.101418, -3.8762355), vec2(2.4151268, -3.7258272), vec2(2.718092, -3.616244), vec2(2.2862053, -2.7266867), vec2(1.9252255, -2.862054), vec2(1.6630855, -2.9823806), vec2(2.363558, -5.8616242), vec2(1.9553072, -5.8616242), vec2(1.6673828, -5.599484), vec2(2.419424, -6.235496), vec2(2.840567, -6.235496), vec2(3.173614, -6.106575), vec2(2.5139663, 0.12462398), vec2(2.1057155, 0.12462398), vec2(1.6974645, -0.0021486892), vec2(2.599914, -0.24924795), vec2(2.896433, -0.24924795), vec2(3.117748, -0.32660076), vec2(2.718092, -3.616244), vec2(3.0210571, -3.506661), vec2(3.3046842, -3.382037), vec2(2.9265146, -2.4795873), vec2(2.647185, -2.5913193), vec2(2.2862053, -2.7266867), vec2(3.0167596, -5.7133646), vec2(2.7503223, -5.8616242), vec2(2.363558, -5.8616242), vec2(3.117748, -0.32660076), vec2(3.3390632, -0.40395358), vec2(3.4765792, -0.54576707), vec2(3.173614, -6.106575), vec2(3.506661, -5.9776535), vec2(3.781693, -5.8057585), vec2(3.3046842, -3.382037), vec2(3.5625267, -3.270305), vec2(3.8010314, -3.1284916), vec2(3.4679844, -5.315857), vec2(3.2831972, -5.565105), vec2(3.0167596, -5.7133646), vec2(3.4765792, -0.54576707), vec2(3.6140952, -0.6875806), vec2(3.6807046, -0.8788139), vec2(3.54104, -2.0004296), vec2(3.3347657, -2.316287), vec2(2.9265146, -2.4795873), vec2(3.6807046, -0.8788139), vec2(3.747314, -1.0700473), vec2(3.747314, -1.3192952), vec2(3.747314, -1.3192952), vec2(3.747314, -1.6845723), vec2(3.54104, -2.0004296), vec2(3.775247, -4.7400084), vec2(3.657069, -5.0580144), vec2(3.4679844, -5.315857), vec2(3.8010314, -3.1284916), vec2(4.039536, -2.9866781), vec2(4.2157283, -2.7975934), vec2(3.9879673, -4.073915), vec2(3.893425, -4.4220023), vec2(3.775247, -4.7400084), vec2(3.996562, -0.3996562), vec2(3.3992264, 0.12462398), vec2(2.5139663, 0.12462398), vec2(4.2157283, -2.7975934), vec2(4.4091105, -2.5827246), vec2(4.501504, -2.3270304), vec2(4.501504, -2.3270304), vec2(4.593898, -2.0713365), vec2(4.593898, -1.7318435), vec2(4.593898, -1.7318435), vec2(4.593898, -0.92393637), vec2(3.996562, -0.3996562) ); #define LINE_COUNT 8 const vec2 LINES[LINE_COUNT * 2] = vec2[LINE_COUNT * 2]( vec2(0.40395358, -2.0842285), vec2(0.7520412, -2.0842285), vec2(0.46411687, 0.0042973785), vec2(0.40395358, -2.0842285), vec2(0.80790716, 0.0042973785), vec2(0.46411687, 0.0042973785), vec2(0.99269444, -0.30941126), vec2(0.80790716, 0.0042973785), vec2(3.781693, -5.8057585), vec2(3.9578855, -6.09798), vec2(3.9578855, -6.09798), vec2(4.301676, -6.09798), vec2(4.301676, -6.09798), vec2(4.336055, -4.073915), vec2(4.336055, -4.073915), vec2(3.9879673, -4.073915) ); float dot2(in vec2 v) { return dot(v, v); } float cro(in vec2 a, in vec2 b) { return a.x * b.y - a.y * b.x; } // signed distance to a quadratic bezier float sdBezier(in vec2 pos, in vec2 A, in vec2 B, in vec2 C) { vec2 a = B - A; vec2 b = A - 2.0 * B + C; vec2 c = a * 2.0; vec2 d = A - pos; float kk = 1.0 / dot(b, b); float kx = kk * dot(a, b); float ky = kk * (2.0 * dot(a, a) + dot(d, b)) / 3.0; float kz = kk * dot(d, a); float res = 0.0; float sgn = 0.0; float p = ky - kx * kx; float q = kx * (2.0 * kx * kx - 3.0 * ky) + kz; float p3 = p * p * p; float q2 = q * q; float h = q2 + 4.0 * p3; if(h >= 0.0) { // 1 root h = sqrt(h); vec2 x = (vec2(h, -h) - q) / 2.0; // When p≈0 and p<0, h - q has catastrophic cancelation. So, we do // h=√(q² + 4p³)=q·√(1 + 4p³/q²)=q·√(1 + w) instead. Now we approximate // √ by a linear Taylor expansion into h≈q(1 + ½w) so that the q's // cancel each other in h - q. Expanding and simplifying further we // get x=vec2(p³/q, -p³/q - q). And using a second degree Taylor // expansion instead: x=vec2(k, -k - q) with k=(1 - p³/q²)·p³/q if(abs(abs(h/q) - 1.0) < 0.0001) { float k = (1.0 - p3 / q2) * p3 / q; // quadratic approx x = vec2(k, -k - q); } vec2 uv = sign(x) * pow(abs(x), vec2(1.0/3.0)); float t = clamp(uv.x + uv.y - kx, 0.0, 1.0); vec2 q = d + (c + b * t) * t; res = dot2(q); sgn = cro(c + 2.0 * b * t, q); } else { // 3 roots float z = sqrt(-p); float v = acos(q / (p * z * 2.0)) / 3.0; float m = cos(v); float n = sin(v) * 1.732050808; vec3 t = clamp(vec3(m + m, -n - m, n - m) * z - kx, 0.0, 1.0); vec2 qx=d + (c + b * t.x) * t.x; float dx = dot2(qx), sx = cro(c + 2.0 * b * t.x, qx); vec2 qy=d + (c + b * t.y) * t.y; float dy = dot2(qy); float sy = cro(c + 2.0 * b * t.y, qy); if (dx<dy) { res=dx; sgn=sx; } else { res=dy; sgn=sy; } } return sqrt(res) * sign(sgn); } // Source: https://www.shadertoy.com/view/wdBXRW float winding_sign(in vec2 p, in vec2 a, in vec2 b) { vec2 e = b - a; vec2 w = p - a; // winding number from http://geomalgorithms.com/a03-_inclusion.html bvec3 cond = bvec3(p.y >= a.y, p.y < b.y, e.x*w.y > e.y*w.x); if( all(cond) || all(not(cond))) { return -1.0; } else { return 1.0; } } float winding_angle(in vec2 p, in vec2 a, in vec2 b) { float pa = dot2(a - p); float pb = dot2(b - p); float ab = dot2(a - b); float ang = acos((pa + pb - ab) / (2.0 * sqrt(pa * pb))); return sign(cro(a - p, b - p)) * ang; } float udSegment(in vec2 p, in vec2 a, in vec2 b) { vec2 pa = p - a; vec2 ba = b - a; float h = clamp(dot(pa, ba)/dot(ba, ba), 0.0, 1.0); return length(pa - ba * h); } void mainImage(out vec4 fragColor, in vec2 fragCoord) { vec2 p = (2.0 * fragCoord - iResolution.xy) / iResolution.y; p = (p + vec2(0.5, 0.75)) * vec2(4.0, -4.0); vec2 m = (2.0 * iMouse.xy - iResolution.xy) / iResolution.y; m = (m + vec2(0.5, 0.75)) * vec2(4.0, -4.0); float d = 1e10; float winding = 1.0; for (int i=0; i < QUAD_COUNT; i++) { vec2 v0 = QUADS[i * 3]; vec2 v1 = QUADS[i * 3 + 1]; vec2 v2 = QUADS[i * 3 + 2]; float sd = sdBezier(p, v0, v1, v2); d = min(d, abs(sd)); if (sd > 0.0 == cro(v1 - v2, v1 - v0) < 0.0) { winding *= winding_sign(p, v0, v1); winding *= winding_sign(p, v1, v2); } else { winding *= winding_sign(p, v0, v2); } } for (int i=0; i < LINE_COUNT; i++) { vec2 v0 = LINES[i * 2]; vec2 v1 = LINES[i * 2 + 1]; d = min(d, udSegment(p, v0, v1)); winding *= winding_sign(p, v0, v1); } d *= winding; // Apply a color based on signed distance vec3 col = vec3(1.0) - vec3(0.1, 0.4, 0.7) * sign(d); col *= 1.0 - exp(-4.0 * abs(d)); col *= 0.8 + 0.2 * cos(60.0 * d); col = mix(col, vec3(1.0), 1.0 - smoothstep(0.0, 0.015, abs(d))); // Draw the mouse stuff if(iMouse.z > 0.001) { float d = 1e10; for (int i=0; i < QUAD_COUNT; i++) { vec2 v0 = QUADS[i * 3]; vec2 v1 = QUADS[i * 3 + 1]; vec2 v2 = QUADS[i * 3 + 2]; d = min(d, abs(sdBezier(m, v0, v1, v2))); } for (int i=0; i < LINE_COUNT; i++) { vec2 v0 = LINES[i * 2]; vec2 v1 = LINES[i * 2 + 1]; d = min(d, udSegment(m, v0, v1)); } col = mix(col, vec3(1.0, 1.0, 0.0), 1.0 - smoothstep(0.0, 0.005, abs(length(p - m) - abs(d)) - 0.01)); col = mix(col, vec3(1.0, 1.0, 0.0), 1.0 - smoothstep(0.0, 0.005, length(p - m) - 0.05)); } { // Draw the skeleton of the Bezier curves float d = 1e10; for (int i=0; i < QUAD_COUNT; i++) { vec2 v0 = QUADS[i * 3]; vec2 v1 = QUADS[i * 3 + 1]; vec2 v2 = QUADS[i * 3 + 2]; d = min(d, min(udSegment(p, v0, v1), udSegment(p, v1, v2))); d = min(d, length(p - v0) - 0.05); d = min(d, length(p - v1) - 0.05); d = min(d, length(p - v2) - 0.05); } for (int i=0; i < LINE_COUNT; i++) { vec2 v0 = LINES[i * 2]; vec2 v1 = LINES[i * 2 + 1]; d = min(d, udSegment(p, v0, v1)); d = min(d, length(p - v0) - 0.05); d = min(d, length(p - v1) - 0.05); } col = mix(col, vec3(1, 0, 0), 1.0 - smoothstep(0.0, 0.014, d)); } fragColor = vec4(col, 1.0); }
mit
[ 5586, 5627, 5689, 5689, 7707 ]
[ [ 5475, 5475, 5498, 5498, 5518 ], [ 5519, 5519, 5552, 5552, 5584 ], [ 5586, 5627, 5689, 5689, 7707 ], [ 7709, 7758, 7811, 7811, 8140 ], [ 8142, 8142, 8196, 8196, 8386 ], [ 8388, 8388, 8438, 8438, 8570 ], [ 8572, 8572, 8627, 8627, 11360 ] ]
// signed distance to a quadratic bezier
float sdBezier(in vec2 pos, in vec2 A, in vec2 B, in vec2 C) {
vec2 a = B - A; vec2 b = A - 2.0 * B + C; vec2 c = a * 2.0; vec2 d = A - pos; float kk = 1.0 / dot(b, b); float kx = kk * dot(a, b); float ky = kk * (2.0 * dot(a, a) + dot(d, b)) / 3.0; float kz = kk * dot(d, a); float res = 0.0; float sgn = 0.0; float p = ky - kx * kx; float q = kx * (2.0 * kx * kx - 3.0 * ky) + kz; float p3 = p * p * p; float q2 = q * q; float h = q2 + 4.0 * p3; if(h >= 0.0) { // 1 root h = sqrt(h); vec2 x = (vec2(h, -h) - q) / 2.0; // When p≈0 and p<0, h - q has catastrophic cancelation. So, we do // h=√(q² + 4p³)=q·√(1 + 4p³/q²)=q·√(1 + w) instead. Now we approximate // √ by a linear Taylor expansion into h≈q(1 + ½w) so that the q's // cancel each other in h - q. Expanding and simplifying further we // get x=vec2(p³/q, -p³/q - q). And using a second degree Taylor // expansion instead: x=vec2(k, -k - q) with k=(1 - p³/q²)·p³/q if(abs(abs(h/q) - 1.0) < 0.0001) { float k = (1.0 - p3 / q2) * p3 / q; // quadratic approx x = vec2(k, -k - q); } vec2 uv = sign(x) * pow(abs(x), vec2(1.0/3.0)); float t = clamp(uv.x + uv.y - kx, 0.0, 1.0); vec2 q = d + (c + b * t) * t; res = dot2(q); sgn = cro(c + 2.0 * b * t, q); } else { // 3 roots float z = sqrt(-p); float v = acos(q / (p * z * 2.0)) / 3.0; float m = cos(v); float n = sin(v) * 1.732050808; vec3 t = clamp(vec3(m + m, -n - m, n - m) * z - kx, 0.0, 1.0); vec2 qx=d + (c + b * t.x) * t.x; float dx = dot2(qx), sx = cro(c + 2.0 * b * t.x, qx); vec2 qy=d + (c + b * t.y) * t.y; float dy = dot2(qy); float sy = cro(c + 2.0 * b * t.y, qy); if (dx<dy) { res=dx; sgn=sx; } else { res=dy; sgn=sy; } } return sqrt(res) * sign(sgn); }
// signed distance to a quadratic bezier float sdBezier(in vec2 pos, in vec2 A, in vec2 B, in vec2 C) {
1
1