window mode and botany wip

This commit is contained in:
ntr committed 2022-05-31 15:39:24 +10:00
1 parent f0aa6495c7
commit 0f9576a67b
68 files changed
+8224 -1311

No files matched your search

+304
View File
@@ -0,0 +1,304 @@
Shader "FullScreen/Nebula"
{
Properties
{
_SpectrumTexture("SpectrumTexture", 2D) = "white" {}
_ThemeTexture("ThemeTexture", 2D) = "white" {}
_SpectrumSize("SpectrumSize", float) = 16
_Zoom("Zoom", range(-2, 2)) = 0.5
_Wildness("Wildness", range(1, 10)) = 4.0
_Brightness("Brightness", range(1, 10)) = 4.0
}
HLSLINCLUDE
// HDRP stuff
#pragma vertex Vert
#pragma target 4.5
#pragma only_renderers d3d11 playstation xboxone xboxseries vulkan metal switch
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/RenderPass/CustomPass/CustomPassCommon.hlsl"
// here we go...
sampler2D _SpectrumTexture;
sampler2D _ThemeTexture;
float _Zoom;
float _Wildness;
float _Brightness;
// matrix fn
float2x2 m(float a) {
float c=cos(a), s=sin(a);
float2x2 mat = { c, -s, s, c };
return mat;
}
#define iterations 12
#define formuparam 0.430
// #define time cos(time*0.2)
#define volsteps 6
#define stepsize 0.4
#define zoom 0.800
#define tile 0.850
#define speed 0.05
#define brightness 0.00015
#define darkmatter 0.4 // 0.4
#define distfading 0.960
#define saturation -14.1
#define PI = 3.1415926535897932384626433832795;
float3 mod289(float3 x) {
return x - floor(x * (1.0 / 289.0)) * 289.0;
}
float4 mod289(float4 x) {
return x - floor(x * (1.0 / 289.0)) * 289.0;
}
float4 permute(float4 x) {
return mod289(((x*34.0)+1.0)*x);
}
float4 taylorInvSqrt(float4 r) {
return 1.79284291400159 - 0.85373472095314 * r;
}
float snoise(float3 v)
{
const float2 C = float2(1.0/6.0, 1.0/3.0) ;
const float4 D = float4(0.0, 0.5, 1.0, 2.0);
// First corner
float3 i = floor(v + dot(v, C.yyy) );
float3 x0 = v - i + dot(i, C.xxx) ;
// Other corners
float3 g = step(x0.yzx, x0.xyz);
float3 l = 1.0 - g;
float3 i1 = min( g.xyz, l.zxy );
float3 i2 = max( g.xyz, l.zxy );
float3 x1 = x0 - i1 + C.xxx;
float3 x2 = x0 - i2 + C.yyy; // 2.0*C.x = 1/3 = C.y
float3 x3 = x0 - D.yyy; // -1.0+3.0*C.x = -0.5 = -D.y
// Permutations
i = mod289(i);
float4 p = permute( permute( permute(
i.z + float4(0.0, i1.z, i2.z, 1.0 ))
+ i.y + float4(0.0, i1.y, i2.y, 1.0 ))
+ i.x + float4(0.0, i1.x, i2.x, 1.0 ));
// Gradients: 7x7 points over a square, mapped onto an octahedron.
// The ring size 17*17 = 289 is close to a multiple of 49 (49*6 = 294)
float n_ = 0.142857142857; // 1.0/7.0
float3 ns = n_ * D.wyz - D.xzx;
float4 j = p - 49.0 * floor(p * ns.z * ns.z); // mod(p,7*7)
float4 x_ = floor(j * ns.z);
float4 y_ = floor(j - 7.0 * x_ ); // mod(j,N)
float4 x = x_ *ns.x + ns.yyyy;
float4 y = y_ *ns.x + ns.yyyy;
float4 h = 1.0 - abs(x) - abs(y);
float4 b0 = float4( x.xy, y.xy );
float4 b1 = float4( x.zw, y.zw );
float4 s0 = floor(b0)*2.0 + 1.0;
float4 s1 = floor(b1)*2.0 + 1.0;
float4 sh = -step(h, float4(0.0, 0.0, 0.0, 0.0));
float4 a0 = b0.xzyw + s0.xzyw*sh.xxyy ;
float4 a1 = b1.xzyw + s1.xzyw*sh.zzww ;
float3 p0 = float3(a0.xy,h.x);
float3 p1 = float3(a0.zw,h.y);
float3 p2 = float3(a1.xy,h.z);
float3 p3 = float3(a1.zw,h.w);
//Normalise gradients
//float4 norm = taylorInvSqrt(float4(dot(p0,p0), dot(p1,p1), dot(p2, p2), dot(p3,p3)));
float4 norm = rsqrt(float4(dot(p0,p0), dot(p1,p1), dot(p2, p2), dot(p3,p3)));
p0 *= norm.x;
p1 *= norm.y;
p2 *= norm.z;
p3 *= norm.w;
// Mix final noise value
float4 m = max(0.6 - float4(dot(x0,x0), dot(x1,x1), dot(x2,x2), dot(x3,x3)), 0.0);
m = m * m;
return 42.0 * dot( m*m, float4( dot(p0,x0), dot(p1,x1),
dot(p2,x2), dot(p3,x3) ) );
}
//////////////////////////////////////////////////////////////
// PRNG
// From https://www.shadertoy.com/view/4djSRW
float prng(in float2 seed) {
seed = frac(seed * float2 (5.3983, 5.4427));
seed += dot (seed.yx, seed.xy + float2 (21.5351, 14.3137));
return frac(seed.x * seed.y * 95.4337);
}
//////////////////////////////////////////////////////////////
float noiseStack(float3 pos,int octaves,float falloff){
float noise = snoise(float3(pos));
float off = 1.0;
if (octaves>1) {
pos *= 2.0;
off *= falloff;
noise = (1.0-off)*noise + off*snoise(float3(pos));
}
if (octaves>2) {
pos *= 2.0;
off *= falloff;
noise = (1.0-off)*noise + off*snoise(float3(pos));
}
if (octaves>3) {
pos *= 2.0;
off *= falloff;
noise = (1.0-off)*noise + off*snoise(float3(pos));
}
return (1.0+noise)/2.0;
}
float2 noiseStackUV(float3 pos,int octaves,float falloff,float diff){
float displaceA = noiseStack(pos,octaves,falloff);
float displaceB = noiseStack(pos+float3(3984.293,423.21,5235.19),octaves,falloff);
return float2(displaceA,displaceB);
}
float rand(float2 co){
return frac(sin(dot(co.xy ,float2(12.9898,78.233))) * 43758.5453);
}
float circle(in float2 _st, in float _radius){
float2 dist = _st-float2(0.5, 0.5);
return 1.-smoothstep(_radius-(_radius*0.01),
_radius+(_radius*0.01),
dot(dist,dist)*4.0);
}
float4 FullScreenPass(Varyings varyings) : SV_Target {
float depth = LoadCameraDepth(varyings.positionCS.xy);
PositionInputs posInput = GetPositionInput(varyings.positionCS.xy, _ScreenSize.zw, depth, UNITY_MATRIX_I_VP, UNITY_MATRIX_V);
float4 fragColor = float4(0.0, 0.0, 0.0, 0.0);
float time = _Time.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);
// screen
float zoomFactor = 0.5; // .01 + iMouse.x / iResolution.x;
float2 uv = float2(posInput.positionNDC.x, 1 - posInput.positionNDC.y) * zoomFactor;
// float2 uv = (posInput.positionNDC - .5) * zoomFactor;
float aspect = _ScreenParams.y / _ScreenParams.x;
uv.y *= aspect;
// float2 uv= fragCoord.xy/iResolution.xy*zoomFactor-.65;
// float aspect = iResolution.y/iResolution.x;
// uv.y*=aspect;
// p.x *= _ScreenParams.x / _ScreenParams.y;
//get coords and direction
float zoom2 = 0.0 * sin(time);
float2 c = uv-float2(-0.75*aspect, -0.5*aspect);
float3 dir=float3(uv-c*zoom2,tan(.3)*1000.0);
float a2=speed+.5;
float a1=0.0;
float2x2 rot1 = { cos(a1), tan(a1), -sin(a1), cos(a1) };
float2x2 rot2=rot1; //mat2(cos(a2),sin(a2),-sin(a2),cos(a2));
dir.xz = mul(rot1, dir.xz);
dir.xy = mul(rot2, dir.xy);
float3 from = float3(0.,0.,0.);
float thing = (tan(.15),.152,-2.);
from += float3(thing, thing, thing);
from.x -= time * 0.01;
from.x -= sin(time) * 0.001;
from.y -= cos(time) * 0.001;
from.xz = mul(rot1, from.xz);
from.xy = mul(rot2, from.xy);
//volumetric rendering
float s=.4;
float fade=.2;
float3 v = float3(0.8, 0.8, 0.8);
float2 u = float2(0., 0.);
int r;
for (r=0; r<volsteps; r++) {
float3 p=from+s*dir*.5;
// u = noiseStackUV(float3(0.5),1,0.4,0.1);
// u = noiseStackUV(0.01*float3(float2(p.x,p.y),30.0*time),1,0.4,0.1);
p = abs(float3(tile, tile, tile)- (p % float3(tile*2., tile*2., tile*2.))); // tiling fold
float pa = 0.0;
float a = 0.0;
for (int i=0; i<iterations; i++) {
p=abs(p)/dot(p,p)-formuparam; // the magic formula
a+=abs(length(p)-pa); // absolute sum of average change
pa=length(p);
}
float dm=max(0.,darkmatter-a*a*tan(.001)); //dark matter
a*=a*a*2.; // add contrast
if (r>3) fade*=1.-dm; // dark matter, don't render near
//v+=float3(dm,dm*.5,0.);
v+=fade;
v+=float3(s,s*s,s*s*s*s)*a*brightness*fade; // coloring based on distance
fade*=distfading; // distance fading
s+=stepsize;
}
v=lerp(length(v), v ,saturation); //color adjust
float2 vp = uv - 0.5;
float vl = length(vp)*0.4;
fragColor = float4(v*.01,1.);
fragColor.r = 0.0;
fragColor.g = 0.0;
fragColor.b *= 1.5;
fragColor.b = min(0.9, fragColor.b);
fragColor.b = max(0.3, fragColor.b);
fragColor += float4(v*.001, 1.);
fragColor -= float4(float3(vl, vl, vl), 1.0);
return fragColor;
}
ENDHLSL
SubShader
{
Tags{ "RenderPipeline" = "HDRenderPipeline" }
Pass
{
Name "Custom Pass 0"
ZWrite Off
ZTest Always
// Blend SrcAlpha OneMinusSrcAlpha
Cull Off
HLSLPROGRAM
#pragma fragment FullScreenPass
ENDHLSL
}
}
Fallback Off
}