botany shader
This commit is contained in:
1 parent
0f9576a67b
commit
d36158bc48
14 files changed
+276
-223
No files matched your search
@@ -6,8 +6,8 @@ Shader "FullScreen/Botany"
|
||||
_ThemeTexture("ThemeTexture", 2D) = "white" {}
|
||||
_SpectrumSize("SpectrumSize", float) = 16
|
||||
|
||||
_Zoom("Zoom", range(-2, 2)) = 0.5
|
||||
_Wildness("Wildness", range(1, 10)) = 4.0
|
||||
_Zoom("Zoom", range(1, 10)) = 5
|
||||
_Wildness("Wildness", range(0.2, 2.0)) = 0.8
|
||||
_Brightness("Brightness", range(1, 10)) = 4.0
|
||||
}
|
||||
|
||||
@@ -30,6 +30,11 @@ Shader "FullScreen/Botany"
|
||||
float time;
|
||||
float rng;
|
||||
|
||||
float sub;
|
||||
float bass;
|
||||
float mids;
|
||||
float highs;
|
||||
|
||||
// -------------------------------------
|
||||
// https://www.shadertoy.com/view/NddSWs
|
||||
// source
|
||||
@@ -37,36 +42,39 @@ Shader "FullScreen/Botany"
|
||||
// Dave Hoskins
|
||||
// https://www.shadertoy.com/view/4djSRW
|
||||
float hash13(float3 p3) {
|
||||
p3 = frac(p3 * .1031);
|
||||
p3 += dot(p3, p3.zyx + 31.32);
|
||||
p3 = frac(p3 * .420);
|
||||
p3 += dot(p3, p3.zyx + 322.8);
|
||||
return frac((p3.x + p3.y) * p3.z);
|
||||
}
|
||||
|
||||
// Inigo Quilez
|
||||
// https://iquilezles.org/articles/distfunctions
|
||||
float smin( float d1, float d2, float k ) {
|
||||
float h = clamp( 0.5 + 0.5*(d2-d1)/k, 0.0, 1.0 );
|
||||
return lerp( d2, d1, h ) - k*h*(1.0-h); }
|
||||
float smin(float d1, float d2, float k) {
|
||||
float h = clamp(0.5 + bass * (d2-d1) / k, 0.0, 1.0);
|
||||
return lerp(d2, d1, h) - k*h*(1.0-h);
|
||||
}
|
||||
|
||||
float smoothing(float d1, float d2, float k) { return clamp( 0.5 + 0.5*(d2-d1)/k, 0.0, 1.0 ); }
|
||||
float smoothing(float d1, float d2, float k) { return clamp( 0.5 + 0.5 *(d2-d1)/k, 0.0, 1.0 ); }
|
||||
|
||||
// rotation matrix
|
||||
float2x2 rot(float a) {
|
||||
float2x2 rm = {cos(a),-sin(a),sin(a),cos(a) };
|
||||
float2x2 rm = { cos(a), -sin(a), sin(a), cos(a) };
|
||||
return rm;
|
||||
}
|
||||
|
||||
float3 repeat(float3 p, float r) {
|
||||
return (p % r) / 2.0;
|
||||
#define mod(x, y) (x - y * floor(x / y))
|
||||
|
||||
float3 repeat(float3 p, float3 r) {
|
||||
return mod(p , r) - r / 2.0;
|
||||
}
|
||||
|
||||
// sdf
|
||||
float map (float3 p) {
|
||||
// time stretched with noise
|
||||
float t = time*1. + rng*0.9;
|
||||
float t = time * 1.0 + rng * 2.9;
|
||||
|
||||
// domain repetition
|
||||
float grid = 5.0;
|
||||
float3 grid = float3(_Zoom, _Zoom, _Zoom);
|
||||
float3 cell = floor(p/grid);
|
||||
p = repeat(p, grid);
|
||||
|
||||
@@ -84,30 +92,34 @@ Shader "FullScreen/Botany"
|
||||
|
||||
// kaleidoscopic iterated function
|
||||
const int count = 4;
|
||||
float a = 1.0;
|
||||
// float a = 1.0;
|
||||
float a = 2.0;
|
||||
float scene = 1000.0;
|
||||
float shape = 1000.0;
|
||||
for (int index = 0; index < count; ++index) {
|
||||
// fold and translate
|
||||
p.xz = abs(p.xz)-(.5+wave)*a;
|
||||
p.xz = abs(p.xz) - (_Wildness + wave) * a;
|
||||
// p.xz = abs(p.xz) - (0.5 + wave) * a;
|
||||
|
||||
// rotate
|
||||
p.xz = mul(rot(angle.y/a), p.xz);
|
||||
p.yz = mul(rot(angle.x/a), p.yz);
|
||||
p.yx = mul(rot(angle.z/a), p.yx);
|
||||
// p.xz = mul(rot(angle.y/a), p.xz);
|
||||
// p.yz = mul(rot(angle.x/a), p.yz);
|
||||
// p.yx = mul(rot(angle.z/a), p.yx);
|
||||
|
||||
// p.xz = mul(p.xz, rot(angle.y/a));
|
||||
// p.yz = mul(p.yz, rot(angle.x/a));
|
||||
// p.yx = mul(p.yx, rot(angle.z/a));
|
||||
p.xz = mul(p.xz, rot(angle.y/a));
|
||||
p.yz = mul(p.yz, rot(angle.x/a));
|
||||
p.yx = mul(p.yx, rot(angle.z/a));
|
||||
|
||||
// sphere
|
||||
shape = length(p)-0.2*a*size;
|
||||
|
||||
// material blending
|
||||
material = lerp(material, float(index), smoothing(shape, scene, 0.3*a));
|
||||
// material = lerp(material, float(index), smoothing(shape, scene, 0.3*a));
|
||||
material = lerp(material, float(index), smoothing(shape, scene, mids*a));
|
||||
|
||||
// add with a blend
|
||||
scene = smin(scene, shape, 1.0 * a);
|
||||
// scene = smin(scene, shape, 1.0 * a);
|
||||
scene = smin(scene, shape, 2.0 * sub * a);
|
||||
|
||||
// falloff transformations
|
||||
a /= 1.9;
|
||||
@@ -120,40 +132,44 @@ Shader "FullScreen/Botany"
|
||||
float depth = LoadCameraDepth(varyings.positionCS.xy);
|
||||
PositionInputs posInput = GetPositionInput(varyings.positionCS.xy, _ScreenSize.zw, depth, UNITY_MATRIX_I_VP, UNITY_MATRIX_V);
|
||||
float2 ndc = posInput.positionNDC;
|
||||
|
||||
// convert to glsl mode and fix aspect ratio
|
||||
float2 guv = posInput.positionNDC - 0.5;
|
||||
guv.x *= _ScreenParams.x / _ScreenParams.y;
|
||||
|
||||
// musique
|
||||
float sub = tex2D(_SpectrumTexture, 0.0);
|
||||
float bass = tex2D(_SpectrumTexture, 0.25);
|
||||
float mids = tex2D(_SpectrumTexture, 0.50);
|
||||
float highs = tex2D(_SpectrumTexture, 0.75);
|
||||
float4 spectrum = float4(sub, bass, mids, highs);
|
||||
sub = tex2D(_SpectrumTexture, 0.0);
|
||||
bass = tex2D(_SpectrumTexture, 0.25);
|
||||
mids = tex2D(_SpectrumTexture, 0.50);
|
||||
highs = tex2D(_SpectrumTexture, 0.75);
|
||||
// float4 spectrum = float4(sub, bass, mids, highs);
|
||||
|
||||
time = _Time.y;
|
||||
|
||||
float4 colour = float4(0.0, 0.0, 0.0, 1.0);
|
||||
material = 0.0;
|
||||
|
||||
// white noise
|
||||
float3 seed = float3(guv, time);
|
||||
float rng = hash13(seed);
|
||||
|
||||
// camera coordinates
|
||||
float2 uv = guv;
|
||||
float3 eye = float3(1.0, 1.0, 1.0);
|
||||
float2 uv = guv * 2.5;
|
||||
float3 eye = float3(sin(time * 0.1) * 5.0, cos(time * 0.1) * 5.0, 1.0);
|
||||
// float3 eye = float3(5.0, 5.0, 1.0);
|
||||
float3 at = float3(0.0, 0.0, 0.0);
|
||||
float3 z = normalize(at-eye);
|
||||
float3 x = normalize(cross(z, float3(0,1,0)));
|
||||
float3 x = normalize(cross(z, float3(0.0,1.0,0.0)));
|
||||
float3 y = cross(x, z);
|
||||
float3 ray = normalize(float3(z + uv.x * x + uv.y * y));
|
||||
float3 pos = eye;
|
||||
|
||||
// // camera control
|
||||
float2 M = 6.28 * float2(1.0, 1.0);
|
||||
ray.xz = mul(ray.xz, rot(M.x));
|
||||
pos.xz = mul(pos.xz, rot(M.x));
|
||||
ray.xy = mul(ray.xy, rot(M.y));
|
||||
pos.xy = mul(pos.xy, rot(M.y));
|
||||
// float2 M = 6.28 * float2(1.0, 1.0);
|
||||
// ray.xz = mul(ray.xz, rot(M.x));
|
||||
// pos.xz = mul(pos.xz, rot(M.x));
|
||||
// ray.xy = mul(ray.xy, rot(M.y));
|
||||
// pos.xy = mul(pos.xy, rot(M.y));
|
||||
|
||||
// white noise
|
||||
float3 seed = float3(ndc, highs * 420.0);
|
||||
float rng = hash13(seed);
|
||||
|
||||
// raymarch
|
||||
float steps = 30.0;
|
||||
@@ -166,7 +182,7 @@ Shader "FullScreen/Botany"
|
||||
}
|
||||
|
||||
// dithering
|
||||
dist *= 0.9 + .1 * rng;
|
||||
// dist *= 0.9 + .1 * rng;
|
||||
|
||||
// raymarch
|
||||
pos += ray * dist;
|
||||
@@ -178,19 +194,16 @@ Shader "FullScreen/Botany"
|
||||
// compute normal by NuSan (https://www.shadertoy.com/view/3sBGzV)
|
||||
float2 off=float2(.001,0);
|
||||
float3 normal = normalize(map(pos)-float3(map(pos-off.xyy), map(pos-off.yxy), map(pos-off.yyx)));
|
||||
|
||||
// Inigo Quilez color palette (https://iquilezles.org/articles/palettes)
|
||||
float3 tint = .5+.5*cos(float3(3.0,2.0,1.0)+material*.5+length(pos)*.5);
|
||||
float3 tint = tex2D(_ThemeTexture, material);
|
||||
|
||||
// lighting
|
||||
float ld = dot(reflect(ray, normal), float3(0,1,0))*0.5+0.5;
|
||||
float ld = dot(reflect(ray, normal), float3(0.0,1.0,0.0))*0.5+0.5;
|
||||
float3 light = float3(1.000,0.502,0.502) * sqrt(ld);
|
||||
ld = dot(reflect(ray, normal), float3(0,0,-1))*0.5+0.5;
|
||||
light += float3(0.400,0.714,0.145) * sqrt(ld)*.5;
|
||||
|
||||
// pixel color
|
||||
colour = float4((tint + light) * shade, 1.0);
|
||||
colour = float4(tint * shade, 1.0);
|
||||
colour.rgb = (tint + light) * shade;
|
||||
|
||||
// temporal buffer
|
||||
// colour = max(colour, texture(iChannel0, fragCoord/iResolution.xy) - 0.01);
|
||||
|
||||
Reference in new issue
Block a user