Files
kaiju/Assets/Scenes/GFLPC_GradientBrot/NtrJulia.shader
T
2022-05-06 13:33:26 +10:00

134 lines
4.4 KiB
Plaintext

Shader "Kaiju/Julia"
{
Properties
{
_MainTex ("Texture", 2D) = "white" {}
_MaxIterations("Max Iterations", range(0, 555)) = 255
_Pan("Pan", vector) = (0.5, 0.0, 0.0, 0.0)
_Zoom("Zoom", range(0, 4)) = 3
_Aspect("Aspect", range(0, 4)) = 1
_JuliaSeed("JuliaSeed", vector) = (0.39, -0.2, 0.0, 0.0)
_Colors("Colors", vector) = (3.0, 3.0, 3.0, 0.0)
}
SubShader
{
// No culling or depth
Cull Off ZWrite Off ZTest Always
Pass
{
CGPROGRAM
// #pragma enable_d3d11_debug_symbols
#pragma target 3.0
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"
struct appdata
{
float4 vertex : POSITION;
float2 uv : TEXCOORD0;
};
struct v2f
{
float2 uv : TEXCOORD0;
float4 vertex : SV_POSITION;
};
v2f vert (appdata v)
{
v2f o;
o.vertex = UnityObjectToClipPos(v.vertex);
o.uv = v.uv;
return o;
}
float _MaxIterations;
float2 _Pan;
float _Zoom;
float _Aspect;
float2 _JuliaSeed;
float3 _Colors;
float ComputeValue(float2 v, float2 offset) {
float vxsquare = 0;
float vysquare = 0;
float iteration;
for (iteration = 0; iteration < _MaxIterations; iter++) {
}
// do {
// vxsquare = v.x * v.x;
// vysquare = v.y * v.y;
// v = float2(vxsquare - vysquare, v.x * v.y * 2) + offset;
// iteration++;
// if ((lastIteration == _MaxIterations) && (vxsquare + vysquare) > 4.0) {
// lastIteration = iteration + 1;
// }
// } while (iteration < lastIteration);
// return (float(iteration) - (log(log(sqrt(vxsquare + vysquare))) / log(2.0))) / float(_MaxIterations);
}
// for each pixel (Px, Py) on the screen do
// x0 := scaled x coordinate of pixel (scaled to lie in the Mandelbrot X scale (-2.5, 1))
// y0 := scaled y coordinate of pixel (scaled to lie in the Mandelbrot Y scale (-1, 1))
// x := 0.0
// y := 0.0
// iteration := 0
// max_iteration := 1000
// // Here N = 2^8 is chosen as a reasonable bailout radius.
// while x*x + y*y ≤ (1 << 16) and iteration < max_iteration do
// xtemp := x*x - y*y + x0
// y := 2*x*y + y0
// x := xtemp
// iteration := iteration + 1
// // Used to avoid floating point issues with points inside the set.
// if iteration < max_iteration then
// // sqrt of inner term removed using log simplification rules.
// log_zn := log(x*x + y*y) / 2
// nu := log(log_zn / log(2)) / log(2)
// // Rearranging the potential function.
// // Dividing log_zn by log(2) instead of log(N = 1<<8)
// // because we want the entire palette to range from the
// // center to radius 2, NOT our bailout radius.
// iteration := iteration + 1 - nu
// color1 := palette[floor(iteration)]
// color2 := palette[floor(iteration) + 1]
// // iteration % 1 = fractional part of iteration.
// color := linear_interpolate(color1, color2, iteration % 1)
// plot(Px, Py, color)
float4 Mandelbrot_PixelShader(float2 texCoord : TEXCOORD0) : COLOR0 {
float2 v = (texCoord - 0.5) * _Zoom * float2(1, _Aspect) - _Pan;
float val = ComputeValue(v, v);
return float4(sin(val * _Colors.x), sin(val * _Colors.y), sin(val * _Colors.z), 1);
}
float4 Julia_PixelShader(float2 texCoord : TEXCOORD0) : COLOR0 {
_JuliaSeed = float2(sin(_Time.y), cos(_Time.y));
float2 v = (texCoord - 0.5) * _Zoom * float2(1, _Aspect) - _Pan;
float val = ComputeValue(v, _JuliaSeed);
return float4(sin(val * _Colors.x), sin(val * _Colors.y), sin(val * _Colors.z), 1);
}
float4 frag (v2f i) : SV_Target {
// return Julia_PixelShader(i.uv);
return Mandelbrot_PixelShader(i.uv);
}
ENDCG
}
}
}