show some love to hyper

This commit is contained in:
ntr committed 2022-05-12 17:08:35 +10:00
1 parent 6da13bac1c
commit 15c8fce77c
52 files changed
+4091 -2008

No files matched your search

@@ -0,0 +1,74 @@
using UnityEngine;
public class Explorer : MonoBehaviour {
[SerializeField] private Material mat;
[SerializeField] private Vector2 pos;
[SerializeField] private float scale;
[SerializeField] private float angle;
private Vector2 smoothPos;
private float smoothScale;
private float smoothAngle;
void FixedUpdate() {
HandleUserInput();
UpdateShader();
}
void Start() {
scale = 4.0f;
}
private void HandleUserInput() {
float scroll = Input.GetAxis("Mouse ScrollWheel");
if (scroll > 0f) {
scale = Mathf.Max(scale *= 0.9f, 0.0002f);
} else if (scroll < 0f) {
scale *= 1.1f;
scale = Mathf.Min(scale *= 1.1f, 5.0f);
}
if (Input.GetKey(KeyCode.Q)) {
angle -= 0.01f;
} else if (Input.GetKey(KeyCode.E)) {
angle += 0.01f;
}
Vector2 dir = new Vector2(0.01f * scale, 0);
float s = Mathf.Sin(angle);
float c = Mathf.Cos(angle);
dir = new Vector2(dir.x * c, dir.x * s);
if (Input.GetKey(KeyCode.A)) {
pos -= dir;
} else if (Input.GetKey(KeyCode.D)) {
pos += dir;
}
dir = new Vector2(-dir.y, dir.x);
if (Input.GetKey(KeyCode.W)) {
pos += dir;
} else if (Input.GetKey(KeyCode.S)) {
pos -= dir;
}
}
private void UpdateShader() {
smoothPos = Vector2.Lerp(smoothPos, pos, 0.03f);
smoothScale = Mathf.Lerp(smoothScale, scale, 0.03f);
smoothAngle = Mathf.Lerp(smoothAngle, angle, 0.03f);
float aspect = (float) Screen.width / Screen.height;
float scaleX = smoothScale;
float scaleY = smoothScale;
if (aspect > 1f) {
scaleY /= aspect;
} else {
scaleX *= aspect;
}
mat.SetVector("_Area", new Vector4(smoothPos.x, smoothPos.y, scaleX, scaleY));
mat.SetFloat("_Angle", smoothAngle);
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: e63c937d62a0d0246bb017eae3cf6cf1
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,103 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!114 &-6103144385684529463
MonoBehaviour:
m_ObjectHideFlags: 3
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 0}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 24f077503be6ae942a1e1245dbd53ea9, type: 3}
m_Name: Bloom
m_EditorClassIdentifier:
active: 1
quality:
m_OverrideState: 1
m_Value: 1
threshold:
m_OverrideState: 1
m_Value: 37.34
intensity:
m_OverrideState: 1
m_Value: 0.633
scatter:
m_OverrideState: 0
m_Value: 0.7
tint:
m_OverrideState: 1
m_Value: {r: 0.8773585, g: 0, b: 0, a: 1}
dirtTexture:
m_OverrideState: 0
m_Value: {fileID: 0}
dirtIntensity:
m_OverrideState: 0
m_Value: 0
anamorphic:
m_OverrideState: 0
m_Value: 1
m_Resolution:
m_OverrideState: 1
m_Value: 2
m_HighQualityPrefiltering:
m_OverrideState: 1
m_Value: 0
m_HighQualityFiltering:
m_OverrideState: 1
m_Value: 1
--- !u!114 &-2506743561836662026
MonoBehaviour:
m_ObjectHideFlags: 3
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 0}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 2c1be1b6c95cd2e41b27903b9270817f, type: 3}
m_Name: Vignette
m_EditorClassIdentifier:
active: 1
mode:
m_OverrideState: 1
m_Value: 0
color:
m_OverrideState: 1
m_Value: {r: 0, g: 0, b: 0, a: 1}
center:
m_OverrideState: 1
m_Value: {x: 0.5, y: 0.5}
intensity:
m_OverrideState: 1
m_Value: 0.464
smoothness:
m_OverrideState: 0
m_Value: 0.2
roundness:
m_OverrideState: 0
m_Value: 1
rounded:
m_OverrideState: 0
m_Value: 0
mask:
m_OverrideState: 0
m_Value: {fileID: 0}
opacity:
m_OverrideState: 0
m_Value: 1
--- !u!114 &11400000
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 0}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: d7fd9488000d3734a9e00ee676215985, type: 3}
m_Name: Global Volume Profile
m_EditorClassIdentifier:
components:
- {fileID: -6103144385684529463}
- {fileID: -2506743561836662026}
@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: c4f2a74607ecb1242bcb520877df1bee
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 11400000
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,131 @@
Shader "Explorer/Mandelbrot"
{
Properties
{
_MainTex ("Texture", 2D) = "white" {}
// first two numbers are center of area, second two - size of area
_Area("Area", vector) = (0, 0, 4 ,4)
_Angle("Angle", range(-3.1415, 3.1415)) = 0
_MaxIter("Max Iterations", range(0, 555)) = 255
_Speed("Speed", range(0, 1)) = 0.1
_EscapeRadius("EscapeRadius", range(2, 2000)) = 255
_SpectrumTexture("SpectrumTexture", 2D) = "white" {}
_SpectrumSize("SpectrumSize", float) = 16
_ThemeTexture("ThemeTexture", 2D) = "white" {}
_ThemeSize("ThemeSize", float) = 16
}
SubShader
{
// No culling or depth
Cull Off ZWrite Off ZTest Always
Pass
{
CGPROGRAM
#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;
}
float4 _Area;
int _MaxIter;
float _EscapeRadius;
float _Speed;
sampler2D _SpectrumTexture;
int _SpectrumSize;
sampler2D _ThemeTexture;
int _ThemeSize;
sampler2D _MainTex;
fixed4 frag (v2f i) : SV_Target {
// drawing stuff
float2 uv = i.uv - 0.5;
float2 offset = _Area.xy + uv * _Area.zw;
// cool modulation
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);
// fractal bits
float r2 = r*r;
float2 c = _Area.xy + uv * _Area.zw;
float2 z = 0;
float2 zNext;
int iter;
for (iter = 0; iter < maxIterations; iter ++)
{
// f(z) = z^2 + c
zNext.x = z.x * z.x - z.y * z.y + c.x;
zNext.y = 2 * z.x * z.y + c.y;
z = zNext;
// unbounded
if (length(zNext) > r)
break;
}
// in the set
// make it white
if (iter >= maxIterations) {
return 0;
return 1;
}
float val = iter / float(maxIterations);
float4 col = tex2D(_ThemeTexture, float2(sub, 1.0));
return col * val;
// return float4(val, val, val, 1.0);
// return tex2D(_ThemeTexture, highs);
// float col = tex2D(_ThemeTexture, float2(highs * val, 1.0));
// return col;
// from spinny curvy brot
// 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;
// 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));
// col *= smoothstep(3, 0, fracIter);
// float angle = atan2(z.x, z.y);
// col *= 1 + sin(angle*2 + _Time.y*4)*.2;
// return col;
}
ENDCG
}
}
}
@@ -0,0 +1,10 @@
fileFormatVersion: 2
guid: 227040abb40a96245b6b6fc40b161460
ShaderImporter:
externalObjects: {}
defaultTextures: []
nonModifiableTextures: []
preprocessorOverride: 0
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,298 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!114 &-8084887043848020213
MonoBehaviour:
m_ObjectHideFlags: 11
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 0}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: da692e001514ec24dbc4cca1949ff7e8, type: 3}
m_Name:
m_EditorClassIdentifier:
version: 12
hdPluginSubTargetMaterialVersions:
m_Keys: []
m_Values:
--- !u!21 &2100000
Material:
serializedVersion: 6
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_Name: Mandelbrot
m_Shader: {fileID: 4800000, guid: e1072418ddacefc438fd474f86c5fead, type: 3}
m_ShaderKeywords: _DISABLE_SSR_TRANSPARENT _NORMALMAP_TANGENT_SPACE
m_LightmapFlags: 4
m_EnableInstancingVariants: 0
m_DoubleSidedGI: 0
m_CustomRenderQueue: -1
stringTagMap: {}
disabledShaderPasses:
- TransparentDepthPrepass
- TransparentDepthPostpass
- TransparentBackface
- RayTracingPrepass
- MOTIONVECTORS
m_SavedProperties:
serializedVersion: 3
m_TexEnvs:
- _AnisotropyMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _BaseColorMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _BentNormalMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _BentNormalMapOS:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _CoatMaskMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _DetailMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _EmissiveColorMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _HeightMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _IridescenceMaskMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _IridescenceThicknessMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _MainTex:
m_Texture: {fileID: 2800000, guid: f39e2e35cb2de674bbba32a578a4253f, type: 3}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _MaskMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _NormalMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _NormalMapOS:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _Spectrum:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _SpectrumDataTexture:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _SpectrumTexture:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _SpecularColorMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _SubsurfaceMaskMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _TangentMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _TangentMapOS:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _ThemeTexture:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _ThicknessMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _TransmittanceColorMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- unity_Lightmaps:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- unity_LightmapsInd:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- unity_ShadowMasks:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
m_Ints: []
m_Floats:
- _AORemapMax: 1
- _AORemapMin: 0
- _ATDistance: 1
- _AddPrecomputedVelocity: 0
- _AlbedoAffectEmissive: 0
- _AlphaCutoff: 0.5
- _AlphaCutoffEnable: 0
- _AlphaCutoffPostpass: 0.5
- _AlphaCutoffPrepass: 0.5
- _AlphaCutoffShadow: 0.5
- _AlphaDstBlend: 0
- _AlphaSrcBlend: 1
- _AlphaToMask: 0
- _AlphaToMaskInspectorValue: 0
- _Angle: 0
- _Anisotropy: 0
- _Aspect: 1
- _BlendMode: 0
- _CoatMask: 0
- _Color: 0
- _CullMode: 2
- _CullModeForward: 2
- _Cutoff: 0.5
- _DepthOffsetEnable: 0
- _DetailAlbedoScale: 1
- _DetailNormalScale: 1
- _DetailSmoothnessScale: 1
- _DiffusionProfile: 0
- _DiffusionProfileHash: 0
- _DisplacementLockObjectScale: 1
- _DisplacementLockTilingScale: 1
- _DisplacementMode: 0
- _DoubleSidedEnable: 0
- _DoubleSidedGIMode: 0
- _DoubleSidedNormalMode: 1
- _DstBlend: 0
- _EmissiveColorMode: 1
- _EmissiveExposureWeight: 1
- _EmissiveIntensity: 1
- _EmissiveIntensityUnit: 0
- _EnableBlendModePreserveSpecularLighting: 1
- _EnableFogOnTransparent: 1
- _EnableGeometricSpecularAA: 0
- _EnergyConservingSpecularColor: 1
- _EscapeRadius: 83.2
- _HeightAmplitude: 0.02
- _HeightCenter: 0.5
- _HeightMapParametrization: 0
- _HeightMax: 1
- _HeightMin: -1
- _HeightOffset: 0
- _HeightPoMAmplitude: 2
- _HeightTessAmplitude: 2
- _HeightTessCenter: 0.5
- _Intensity: 134.54797
- _InvTilingScale: 1
- _Ior: 1.5
- _IridescenceMask: 1
- _IridescenceThickness: 1
- _Iterations: 255
- _LinkDetailsWithBase: 1
- _MaterialID: 1
- _MaxIter: 555
- _Metallic: 0
- _MetallicRemapMax: 1
- _MetallicRemapMin: 0
- _Movement: 0
- _NormalMapSpace: 0
- _NormalScale: 1
- _OpaqueCullMode: 2
- _PPDLodThreshold: 5
- _PPDMaxSamples: 15
- _PPDMinSamples: 5
- _PPDPrimitiveLength: 1
- _PPDPrimitiveWidth: 1
- _Radius: 21.6
- _RayTracing: 0
- _ReceivesSSR: 1
- _ReceivesSSRTransparent: 0
- _RefractionModel: 0
- _Repeat: 34.44
- _Smoothness: 0.5
- _SmoothnessRemapMax: 1
- _SmoothnessRemapMin: 0
- _SpectrumSize: 4
- _SpecularAAScreenSpaceVariance: 0.1
- _SpecularAAThreshold: 0.2
- _SpecularOcclusionMode: 1
- _Speed: 1
- _SrcBlend: 1
- _StencilRef: 0
- _StencilRefDepth: 8
- _StencilRefGBuffer: 10
- _StencilRefMV: 40
- _StencilWriteMask: 6
- _StencilWriteMaskDepth: 8
- _StencilWriteMaskGBuffer: 14
- _StencilWriteMaskMV: 40
- _SubsurfaceMask: 1
- _SupportDecals: 1
- _SurfaceType: 0
- _Symmetry: 0
- _TexWorldScale: 1
- _TexWorldScaleEmissive: 1
- _ThemeSize: 128
- _Thickness: 1
- _TransmissionEnable: 1
- _TransparentBackfaceEnable: 0
- _TransparentCullMode: 2
- _TransparentDepthPostpassEnable: 0
- _TransparentDepthPrepassEnable: 0
- _TransparentSortPriority: 0
- _TransparentWritingMotionVec: 0
- _TransparentZWrite: 0
- _UVBase: 0
- _UVDetail: 0
- _UVEmissive: 0
- _UseEmissiveIntensity: 0
- _UseShadowThreshold: 0
- _ZTestDepthEqualForOpaque: 3
- _ZTestGBuffer: 4
- _ZTestTransparent: 4
- _ZWrite: 1
- _Zoom: 3
m_Colors:
- _Area: {r: 0.5375612, g: 0, b: 3.9999962, a: 2.1153827}
- _BaseColor: {r: 1, g: 1, b: 1, a: 1}
- _BaseColorMap_MipInfo: {r: 0, g: 0, b: 0, a: 0}
- _Color: {r: 1, g: 1, b: 1, a: 1}
- _Colors: {r: 6.7, g: 4, b: 5, a: 0}
- _DiffusionProfileAsset: {r: 0, g: 0, b: 0, a: 0}
- _DoubleSidedConstants: {r: 1, g: 1, b: -1, a: 0}
- _EmissionColor: {r: 1, g: 1, b: 1, a: 1}
- _EmissiveColor: {r: 0, g: 0, b: 0, a: 1}
- _EmissiveColorLDR: {r: 0, g: 0, b: 0, a: 1}
- _InvPrimScale: {r: 1, g: 1, b: 0, a: 0}
- _IridescenceThicknessRemap: {r: 0, g: 1, b: 0, a: 0}
- _JuliaSeed: {r: 0.39, g: -0.2, b: 0, a: 0}
- _Pan: {r: 0.5, g: 0, b: 0, a: 0}
- _SpecularColor: {r: 1, g: 1, b: 1, a: 1}
- _ThicknessRemap: {r: 0, g: 1, b: 0, a: 0}
- _TransmittanceColor: {r: 1, g: 1, b: 1, a: 1}
- _UVDetailsMappingMask: {r: 1, g: 0, b: 0, a: 0}
- _UVMappingMask: {r: 1, g: 0, b: 0, a: 0}
- _UVMappingMaskEmissive: {r: 1, g: 0, b: 0, a: 0}
m_BuildTextureStacks: []
@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: a80b1774bdbb2664d9a520c89563020e
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 2100000
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,136 @@
Shader "Explorer/Mandelbrot"
{
Properties
{
_MainTex ("Texture", 2D) = "white" {}
// first two numbers are center of area, second two - size of area
_Area("Area", vector) = (0, 0, 4 ,4)
_Angle("Angle", range(-3.1415, 3.1415)) = 0
_MaxIter("Max Iterations", range(0, 555)) = 255
_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
}
SubShader
{
// No culling or depth
Cull Off ZWrite Off ZTest Always
Pass
{
CGPROGRAM
#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;
}
float4 _Area;
float _Angle;
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);
float c = cos(a);
p -= pivot;
p = float2(p.x*c-p.y*s, p.x*s+p.y*c);
p += pivot;
return p;
}
fixed4 frag (v2f i) : SV_Target
{
float2 uv = i.uv - 0.5;
uv = abs(uv);
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 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;
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) {
break;
}
}
if (iter >= _MaxIter) {
return 0;
}
float val = iter / float(_MaxIter);
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;
float m = sqrt(iter / _MaxIter);
float4 col = tex2D(_ThemeTexture, abs(sin(time)));
// float4 col = tex2D(_ThemeTexture, val + abs(time);
col *= smoothstep(3, 0, fracIter);
// dark bands
float angle = atan2(z.x, z.y);
col *= 1 + sin(angle*2 + mids*4)*.2;
return col;
}
ENDCG
}
}
}
@@ -0,0 +1,10 @@
fileFormatVersion: 2
guid: e1072418ddacefc438fd474f86c5fead
ShaderImporter:
externalObjects: {}
defaultTextures: []
nonModifiableTextures: []
preprocessorOverride: 0
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,98 @@
Shader "Explorer/Mandelbrot"
{
Properties
{
_MainTex ("Texture", 2D) = "white" {}
// first two numbers are center of area, second two - size of area
_Area("Area", vector) = (0, 0, 4 ,4)
_Angle("Angle", range(-3.1415, 3.1415)) = 0
_MaxIter("Max Iterations", range(0, 555)) = 255
// _Speed("Speed", range(0, 1)) = 0.1
_Colors("Colors", vector) = (0.5, 0.5, 0.5, 0.0)
_EscapeRadius("EscapeRadius", range(2, 2000)) = 255
}
SubShader
{
// No culling or depth
Cull Off ZWrite Off ZTest Always
Pass
{
CGPROGRAM
#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;
}
float4 _Area;
float _Angle;
float3 _Colors;
// float _Speed;
int _MaxIter;
float _EscapeRadius;
sampler2D _MainTex;
fixed4 frag (v2f i) : SV_Target {
float2 uv = i.uv - 0.5;
float2 offset = _Area.xy + uv * _Area.zw;
float r = _EscapeRadius;
float r2 = r*r;
float2 c = _Area.xy + uv * _Area.zw;
float2 z = 0;
float2 zNext;
int iter;
for (iter = 0; iter < _MaxIter; iter ++)
{
// f(z) = z^2 + c
zNext.x = z.x * z.x - z.y * z.y + c.x;
zNext.y = 2 * z.x * z.y + c.y;
z = zNext;
// Bounded?
if (distance(z, float2(0,0)) > r)
break;
}
float val = iter / float(_MaxIter);
return float4(val, val, val, 1);
return float4(sin(val), sin(val), sin(val), 1);
// 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;
// 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));
// col *= smoothstep(3, 0, fracIter);
// float angle = atan2(z.x, z.y);
// col *= 1 + sin(angle*2 + _Time.y*4)*.2;
// return col;
}
ENDCG
}
}
}
@@ -0,0 +1,10 @@
fileFormatVersion: 2
guid: ac37e4ae67210ed48bd3bb15fca8b2b2
ShaderImporter:
externalObjects: {}
defaultTextures: []
nonModifiableTextures: []
preprocessorOverride: 0
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,112 @@
Shader "Explorer/Mandelbrot"
{
Properties
{
_MainTex ("Texture", 2D) = "white" {}
// first two numbers are center of area, second two - size of area
_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
_Colors("Colors", vector) = (3.0, 4.0, 5.0, 0.0)
}
SubShader
{
// No culling or depth
Cull Off ZWrite Off ZTest Always
Pass
{
CGPROGRAM
#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;
}
float4 _Area;
float _Angle;
float _Color;
float3 _Colors;
float _Repeat;
float _Speed;
int _MaxIter;
sampler2D _MainTex;
float2 rot(float2 p, float2 pivot, float a) {
float s = sin(a);
float c = cos(a);
p -= pivot;
p = float2(p.x*c-p.y*s, p.x*s+p.y*c);
p += pivot;
return p;
}
fixed4 frag (v2f i) : SV_Target {
float2 uv = i.uv - 0.5;
float2 offset = _Area.xy + uv * _Area.zw;
float2 z; // track pixel jumping across screen
float2 zPrev;
float r = 2; // escape radius
float r2 = r*r;
float vxsquare = 0;
float vysquare = 0;
float iteration = 0;
float lastIteration = _MaxIter;
do {
vxsquare = uv.x * uv.x;
vysquare = uv.y * uv.y;
uv = float2(vxsquare - vysquare, uv.x * uv.y * 2) + offset;
iteration++;
if ((lastIteration == _MaxIter) && (vxsquare + vysquare) > 4.0) {
lastIteration = iteration + 1;
}
} while (iteration < lastIteration);
float val = (float(iteration) - (log(log(sqrt(vxsquare + vysquare))) / log(2.0))) / float(_MaxIter);
return float4(sin(val * _Colors.x), sin(val * _Colors.y), sin(val * _Colors.z), 1);
// 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;
// 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));
// col *= smoothstep(3, 0, fracIter);
// float angle = atan2(z.x, z.y);
// col *= 1 + sin(angle*2 + _Time.y*4)*.2;
// return col;
}
ENDCG
}
}
}
@@ -0,0 +1,10 @@
fileFormatVersion: 2
guid: 4af1c27d2ef17f74a8690709b6a0970a
ShaderImporter:
externalObjects: {}
defaultTextures: []
nonModifiableTextures: []
preprocessorOverride: 0
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,80 @@
using Assets.WasapiAudio.Scripts.Unity;
using UnityEngine;
public class SpectrumMandlebrotBinder : MonoBehaviour {
[SerializeField] private Material mat;
[SerializeField] private WasapiAudioSource source;
[SerializeField] private Vector2 pos;
[SerializeField] private float scale;
[SerializeField] private float angle;
[SerializeField] private float speed;
private Vector2 smoothPos;
private float smoothScale;
private float smoothAngle;
void Awake() {
scale = 4.0f;
}
private void HandleUserInput() {
float scroll = Input.GetAxis("Mouse ScrollWheel");
if (scroll > 0f) {
scale *= 0.9f;
} else if (scroll < 0f) {
scale *= 1.1f;
}
if (Input.GetKey(KeyCode.Q)) {
angle -= 0.01f;
} else if (Input.GetKey(KeyCode.E)) {
angle += 0.01f;
}
Vector2 dir = new Vector2(0.01f * scale, 0);
float s = Mathf.Sin(angle);
float c = Mathf.Cos(angle);
dir = new Vector2(dir.x * c, dir.x * s);
if (Input.GetKey(KeyCode.A)) {
pos -= dir;
} else if (Input.GetKey(KeyCode.D)) {
pos += dir;
}
dir = new Vector2(-dir.y, dir.x);
if (Input.GetKey(KeyCode.W)) {
pos += dir;
} else if (Input.GetKey(KeyCode.S)) {
pos -= dir;
}
}
private void UpdateShader() {
smoothPos = Vector2.Lerp(smoothPos, pos, 0.03f);
smoothScale = Mathf.Lerp(smoothScale, scale, 0.03f);
smoothAngle = Mathf.Lerp(smoothAngle, angle, 0.03f);
float aspect = (float) Screen.width / Screen.height;
float scaleX = smoothScale;
float scaleY = smoothScale;
if (aspect > 1f) {
scaleY /= aspect;
} else {
scaleX *= aspect;
}
mat.SetVector("_Area", new Vector4(smoothPos.x, smoothPos.y, scaleX, scaleY));
mat.SetFloat("_Angle", smoothAngle);
mat.SetFloat("_Speed", speed);
}
void Update() {
var spectrumData = source.GetSpectrumData();
// speed = spectrumData[1];
mat.SetFloat("_Movement", Mathf.PI * 2 * spectrumData[0]);
mat.SetFloat("_EscapeRadius", Mathf.Clamp(50.0f * spectrumData[0], 2.1f, 50.0f));
UpdateShader();
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 251f0c72f0fac5945bf694fa5660f6c6
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: