pretty crazy organic mandelbrot

This commit is contained in:
ntr committed 2022-05-06 17:34:46 +10:00
1 parent 986d37148a
commit 6da13bac1c
5 files changed
+66 -51

No files matched your search

@@ -7,13 +7,12 @@ Shader "Explorer/Mandelbrot"
_Area("Area", vector) = (0, 0, 4 ,4)
_Angle("Angle", range(-3.1415, 3.1415)) = 0
_MaxIter("Max Iterations", range(0, 555)) = 255
_Color("Color", range(0,1)) = 0.5
_Repeat("Repeat", float) = 1
_Speed("Speed", range(0, 1)) = 0.1
_Symmetry("Symmetry", range(0, 1)) = 0
_EscapeRadius("EscapeRadius", range(2, 200)) = 50
_SpectrumTexture("SpectrumTexture", 2D) = "white" {}
_ThemeTexture("ThemeTexture", 2D) = "white" {}
_SpectrumSize("SpectrumSize", float) = 16
}
@@ -52,14 +51,13 @@ Shader "Explorer/Mandelbrot"
float4 _Area;
float _Angle;
float _Color;
float _Repeat;
float _Speed;
float _Symmetry;
float _EscapeRadius;
int _MaxIter;
sampler2D _MainTex;
sampler2D _SpectrumTexture;
sampler2D _ThemeTexture;
float2 rot(float2 p, float2 pivot, float a) {
float s = sin(a);
@@ -78,18 +76,33 @@ Shader "Explorer/Mandelbrot"
uv = lerp(i.uv - 0.5, uv, _Symmetry);
float2 c = _Area.xy + uv * _Area.zw;
c = rot(c, _Area.xy, _Angle);
// cool modulation
float time = _Time.y;
float sub = tex2D(_SpectrumTexture, 0.0);
float bass = tex2D(_SpectrumTexture, 0.25);
float mids = tex2D(_SpectrumTexture, 0.50);
float highs = tex2D(_SpectrumTexture, 0.75);
float r = lerp(2.0, 200, bass);
// float maxIterations = lerp(2.0, 500, sub);
// float maxIterations = lerp(2.0, 500, sub);
// float speed = sub * -scale;
float maxIterations = _MaxIter;
// float r = _EscapeRadius;
float speed = _Speed;
float2 z; // track pixel jumping across screen
float2 zPrev;
// float r = _EscapeRadius;
float r = lerp(2.0f, 50.0f, tex2D(_SpectrumTexture, 1.0f));
float r2 = r*r;
float iter; // track current iteration
for (iter = 0; iter < _MaxIter; iter++) {
// update z based on previous z value and add original starting position
// zPrev = z;
zPrev = rot(z, 0, _Time.y);
// zPrev = rot(z, 0, clamp(tex2D(_SpectrumTexture, 0.1f) * 6.28, 1, 6.28));
float rotation = sin(time);
zPrev = rot(z, 0, rotation);
z = float2(z.x*z.x-z.y*z.y, 2*z.x*z.y) + c;
if (dot(z, zPrev) > r2) {
@@ -100,18 +113,20 @@ Shader "Explorer/Mandelbrot"
if (iter >= _MaxIter) {
return 0;
}
float dist = length(z); // distance from origin
float fracIter = (dist - r) / (r2 - r); // linear interpolation
fracIter = log2(log(dist) / log(r)); // double exponential interpolation
iter -= fracIter;
// iter -= fracIter;
float m = sqrt(iter / _MaxIter);
float4 col = sin(float4(.3, .45, .65, 1) * m * 20)*.5 + .5; // procedural colors
col = tex2D(_MainTex, float2(m * _Repeat + _Time.y*_Speed, _Color));
// float4 col = tex2D(_ThemeTexture, m + abs(sin(time)) * speed);
float4 col = tex2D(_ThemeTexture, m + time * speed);
col *= smoothstep(3, 0, fracIter);
// dark bands
float angle = atan2(z.x, z.y);
col *= 1 + sin(angle*2 + time*4)*.2;
col *= 1 + sin(angle*2 + _Time.y*4)*.2;
return col;
}
ENDCG