├── .gitignore ├── README.md ├── Lava Lamp (Unlit).shader └── Some Overwatch Shader.shader /.gitignore: -------------------------------------------------------------------------------- 1 | *.meta 2 | testing/ -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Fun Fragment Shaders 2 | > 🎨 Fun fragment shaders that you can use in Unity. 3 | 4 | ### [Download all shaders](https://github.com/makitsune/fun-frag-shaders/archive/master.zip) 5 | 6 | ## Lava Lamp 7 | 8 | 9 | 10 | ### Download [Lava Lamp (Unlit).shader](https://raw.githubusercontent.com/makitsune/fun-frag-shaders/master/Lava%20Lamp%20%28Unlit%29.shader) 11 | 12 | Fun shader to stick on your VRChat avatar. Things you can customize: 13 | 14 | - **Blob:** Scale, Depth, Saturation, Value 15 | - **Hue:** Speed, Scale 16 | - Background 17 | -------------------------------------------------------------------------------- /Lava Lamp (Unlit).shader: -------------------------------------------------------------------------------- 1 | Shader "Maki/Lava Lamp (Unlit)" { 2 | Properties { 3 | _BlobScale ("Blob Scale", Range (0.1, 8)) = 1 4 | _BlobDepth ("Blob Depth", Range (2, 16)) = 4 5 | _BlobSaturation ("Blob Saturation", Range(0,1)) = 0.8 6 | _BlobValue ("Blob Value", Range(0,1)) = 0.4 7 | _BlobMoveSpeed ("Blob Movement Speed", Float) = 4 8 | 9 | _HueSpeed ("Hue Speed", Float) = 1 10 | _HueScale ("Hue Scale", Float) = 2 11 | [HDR]_Background ("Background", Color) = (0,0,0,1) 12 | } 13 | SubShader { 14 | Pass { 15 | Cull Back 16 | CGPROGRAM 17 | #pragma vertex vert 18 | #pragma fragment frag 19 | #pragma multi_compile_fog 20 | 21 | #include "UnityCG.cginc" 22 | 23 | uniform float _BlobScale; 24 | uniform float _BlobDepth; 25 | uniform float _BlobSaturation; 26 | uniform float _BlobValue; 27 | uniform float _BlobMoveSpeed; 28 | 29 | uniform float _HueSpeed; 30 | uniform float _HueScale; 31 | uniform float4 _Background; 32 | 33 | struct appdata { 34 | float4 vertex: POSITION; 35 | float2 uv: TEXCOORD0; 36 | }; 37 | 38 | struct v2f { 39 | float4 vertex: SV_POSITION; 40 | float4 posWorld: TEXCOORD0; 41 | UNITY_VERTEX_INPUT_INSTANCE_ID 42 | }; 43 | 44 | struct fragOut { 45 | float4 color: SV_Target; 46 | //float depth: SV_Blobdepth; 47 | UNITY_FOG_COORDS(1) 48 | UNITY_VERTEX_OUTPUT_STEREO 49 | }; 50 | 51 | v2f vert (appdata v) { 52 | v2f o; 53 | UNITY_SETUP_INSTANCE_ID(v); 54 | UNITY_INITIALIZE_OUTPUT(v2f, o) 55 | UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o); 56 | o.vertex = UnityObjectToClipPos(v.vertex); 57 | o.posWorld = mul(unity_ObjectToWorld, v.vertex); 58 | UNITY_TRANSFER_FOG(o,o.vertex); 59 | return o; 60 | } 61 | 62 | float3 HSVtoRGB(float3 hsv) { 63 | // thx shaderforge <3~ 64 | return (lerp(float3(1,1,1),saturate(3.0*abs(1.0-2.0*frac(hsv.r+float3(0.0,-1.0/3.0,1.0/3.0)))-1),hsv.g)*hsv.b); 65 | } 66 | 67 | // https://forum.unity.com/threads/2d-3d-4d-optimised-perlin-noise-cg-hlsl-library-cginc.218372 68 | // http://ctrl-alt-test.fr/minifier/index 69 | #define NOISE_SIMPLEX_1_DIV_289 0.00346020761245674740484429065744f 70 | float3 mod289(float3 x){return x-floor(x*NOISE_SIMPLEX_1_DIV_289)*289.;}float4 mod289(float4 x){return x-floor(x*NOISE_SIMPLEX_1_DIV_289)*289.;}float4 taylorInvSqrt(float4 r){return 1.79284-.853735*r;}float4 permute(float4 x){return mod289(x*x*34.+x);}float snoise(float3 v){const float2 C=float2(.166667,.333333);const float4 D=float4(0.,.5,1.,2.);float3 i=floor(v+dot(v,C.ggg)),x0=v-i+dot(i,C.rrr),g=step(x0.gbr,x0.rgb),l=1-g,i1=min(g.rgb,l.brg),i2=max(g.rgb,l.brg),x1=x0-i1+C.rrr,x2=x0-i2+C.ggg,x3=x0-D.ggg;i=mod289(i);float4 p=permute(permute(permute(i.b+float4(0.,i1.b,i2.b,1.))+i.g+float4(0.,i1.g,i2.g,1.))+i.r+float4(0.,i1.r,i2.r,1.));float n_=.142857;float3 ns=n_*D.agb-D.rbr;float4 j=p-49.*floor(p*ns.b*ns.b),x_=floor(j*ns.b),y_=floor(j-7.*x_),x=x_*ns.r+ns.gggg,y=y_*ns.r+ns.gggg,h=1.-abs(x)-abs(y),b0=float4(x.rg,y.rg),b1=float4(x.ba,y.ba),s0=floor(b0)*2.+1.,s1=floor(b1)*2.+1.,sh=-step(h,0.),a0=b0.rbga+s0.rbga*sh.rrgg,a1=b1.rbga+s1.rbga*sh.bbaa;float3 p0=float3(a0.rg,h.r),p1=float3(a0.ba,h.g),p2=float3(a1.rg,h.b),p3=float3(a1.ba,h.a);float4 norm=taylorInvSqrt(float4(dot(p0,p0),dot(p1,p1),dot(p2,p2),dot(p3,p3)));p0*=norm.r;p1*=norm.g;p2*=norm.b;p3*=norm.a;float4 m=max(.6-float4(dot(x0,x0),dot(x1,x1),dot(x2,x2),dot(x3,x3)),0.);m=m*m;return 42.*dot(m*m,float4(dot(p0,x0),dot(p1,x1),dot(p2,x2),dot(p3,x3)));} 71 | 72 | void raymarch (float3 rayOrigin, float3 rayDir, out float4 color) { 73 | color = _Background; 74 | 75 | float3 position = float3(0,_Time.x*_BlobMoveSpeed,0)-(mul(unity_ObjectToWorld, float4(0,0,0,1)).xyz); 76 | 77 | float rayStep = 0.04*_BlobScale; 78 | float3 rayPos = rayOrigin+position; 79 | for (float i=0; i<_BlobDepth; i+=rayStep) { 80 | rayPos += rayDir*rayStep; 81 | 82 | float dist = snoise(rayPos*_BlobScale); 83 | float c = length((rayOrigin-rayPos)+position); 84 | 85 | //if (dist>0.5 && c>1) { 86 | if (dist>0.5) { 87 | float3 col = HSVtoRGB(float3( ( 88 | (-rayPos.y*_HueScale*0.1) + ((0.2+_Time.x)*_HueSpeed*3) 89 | )%1, 90 | _BlobSaturation, _BlobValue 91 | )); 92 | 93 | c = _BlobDepth-c; 94 | color = float4(lerp(_Background, col, c), 1); 95 | break; 96 | } 97 | } 98 | 99 | //float4 clipPos = mul(UNITY_MATRIX_VP, float4(rayPos, 1.0)); 100 | //clipDepth = clipPos.z / clipPos.w; 101 | } 102 | 103 | fragOut frag(v2f i) { 104 | float3 rayOrigin = i.posWorld.xyz; 105 | float3 rayDir = normalize(rayOrigin-_WorldSpaceCameraPos); 106 | float4 color; 107 | //float clipDepth; 108 | raymarch(rayOrigin, rayDir, color); 109 | 110 | fragOut f; 111 | //f.depth = clipDepth; 112 | UNITY_APPLY_FOG(i.fogCoord, color); 113 | f.color = color; 114 | return f; 115 | } 116 | ENDCG 117 | } 118 | } 119 | } 120 | -------------------------------------------------------------------------------- /Some Overwatch Shader.shader: -------------------------------------------------------------------------------- 1 | Shader "Maki/Some Overwatch Shader" 2 | { 3 | Properties 4 | { 5 | _MainTex ("Texture", 2D) = "white" {} 6 | } 7 | SubShader 8 | { 9 | Tags 10 | { 11 | "RenderType"="Opaque" 12 | } 13 | LOD 100 14 | 15 | Pass 16 | { 17 | CGPROGRAM 18 | #pragma vertex vert 19 | #pragma fragment frag 20 | // make fog work 21 | #pragma multi_compile_fog 22 | 23 | #include "UnityCG.cginc" 24 | 25 | struct appdata 26 | { 27 | float4 vertex : POSITION; 28 | float2 uv : TEXCOORD0; 29 | }; 30 | 31 | struct v2f 32 | { 33 | float2 uv : TEXCOORD0; 34 | UNITY_FOG_COORDS(1) 35 | float4 vertex : SV_POSITION; 36 | }; 37 | 38 | sampler2D _MainTex; 39 | float4 _MainTex_ST; 40 | 41 | v2f vert(appdata v) 42 | { 43 | v2f o; 44 | o.vertex = UnityObjectToClipPos(v.vertex); 45 | o.uv = TRANSFORM_TEX(v.uv, _MainTex); 46 | UNITY_TRANSFER_FOG(o, o.vertex); 47 | return o; 48 | } 49 | 50 | // https://forum.unity.com/threads/2d-3d-4d-optimised-perlin-noise-cg-hlsl-library-cginc.218372 51 | // http://ctrl-alt-test.fr/minifier/index 52 | #define NOISE_SIMPLEX_1_DIV_289 0.00346020761245674740484429065744f 53 | float3 mod289(float3 x) { return x - floor(x * NOISE_SIMPLEX_1_DIV_289) * 289.; } 54 | float4 mod289(float4 x) { return x - floor(x * NOISE_SIMPLEX_1_DIV_289) * 289.; } 55 | float4 taylorInvSqrt(float4 r) { return 1.79284 - .853735 * r; } 56 | float4 permute(float4 x) { return mod289(x * x * 34. + x); } 57 | 58 | float snoise(float3 v) 59 | { 60 | const float2 C = float2(.166667, .333333); 61 | const float4 D = float4(0., .5, 1., 2.); 62 | float3 i = floor(v + dot(v, C.ggg)), x0 = v - i + dot(i, C.rrr), g = step(x0.gbr, x0.rgb), l = 1 - g, i1 63 | = min(g.rgb, l.brg), i2 = max(g.rgb, l.brg), x1 = x0 - i1 + C.rrr, x2 = x0 - i2 + C.ggg, x3 = 64 | x0 - D.ggg; 65 | i = mod289(i); 66 | float4 p = permute( 67 | permute(permute(i.b + float4(0., i1.b, i2.b, 1.)) + i.g + float4(0., i1.g, i2.g, 1.)) + i.r + 68 | float4(0., i1.r, i2.r, 1.)); 69 | float n_ = .142857; 70 | float3 ns = n_ * D.agb - D.rbr; 71 | float4 j = p - 49. * floor(p * ns.b * ns.b), x_ = floor(j * ns.b), y_ = floor(j - 7. * x_), x = x_ * ns. 72 | r + ns.gggg, y = y_ * ns.r + ns.gggg, h = 1. - abs(x) - abs(y), b0 = float4(x.rg, y.rg), b1 = 73 | float4(x.ba, y.ba), s0 = floor(b0) * 2. + 1., s1 = floor(b1) * 2. + 1., sh = -step(h, 0.), a0 74 | = b0.rbga + s0.rbga * sh.rrgg, a1 = b1.rbga + s1.rbga * sh.bbaa; 75 | float3 p0 = float3(a0.rg, h.r), p1 = float3(a0.ba, h.g), p2 = float3(a1.rg, h.b), p3 = float3( 76 | a1.ba, h.a); 77 | float4 norm = taylorInvSqrt(float4(dot(p0, p0), dot(p1, p1), dot(p2, p2), dot(p3, p3))); 78 | p0 *= norm.r; 79 | p1 *= norm.g; 80 | p2 *= norm.b; 81 | p3 *= norm.a; 82 | float4 m = max(.6 - float4(dot(x0, x0), dot(x1, x1), dot(x2, x2), dot(x3, x3)), 0.); 83 | m = m * m; 84 | return 42. * dot(m * m, float4(dot(p0, x0), dot(p1, x1), dot(p2, x2), dot(p3, x3))); 85 | } 86 | 87 | #define mod(x,y) (x-y*floor(x/y)) 88 | 89 | float3 HSVtoRGB(float3 hsv) 90 | { 91 | // thx shaderforge <3~ 92 | return (lerp(float3(1, 1, 1), 93 | saturate(3.0 * abs(1.0 - 2.0 * frac(hsv.r + float3(0.0, -1.0 / 3.0, 1.0 / 3.0))) - 1), 94 | hsv.g) * hsv.b); 95 | } 96 | 97 | fixed4 frag(v2f i) : SV_Target 98 | { 99 | float2 uv = i.uv * float2(2, 1); 100 | 101 | float2 bigCirclesUv = uv; 102 | bigCirclesUv *= 8; 103 | bigCirclesUv = mod(bigCirclesUv, 1.0); 104 | bigCirclesUv -= 0.5; 105 | 106 | float2 smallCirclesUv = uv; 107 | smallCirclesUv *= 48; 108 | smallCirclesUv.y -= _Time.y * 4; 109 | smallCirclesUv = mod(smallCirclesUv, 1.0); 110 | smallCirclesUv -= 0.5; 111 | 112 | float bigCircles = abs(distance(bigCirclesUv, 0)); 113 | bigCircles = bigCircles > 0.46 ? 0 : 1; 114 | 115 | float smallCircles = abs(distance(smallCirclesUv, 0)); 116 | smallCircles = smallCircles > 0.44 ? 0 : 1; 117 | 118 | float2 patternUv = uv; 119 | patternUv *= 2; 120 | 121 | float pattern = snoise(float3(patternUv, _Time.y * 0.2)) / 2 + 0.5; 122 | 123 | 124 | float3 color = float3(1, 1, 1); 125 | 126 | if (smallCircles > 0.5 && bigCircles > 0.5) 127 | { 128 | color = HSVtoRGB( 129 | float3( 130 | lerp(0.4, 10, pattern), 131 | 0.6, 132 | 1 133 | // lerp(0.6, 1, pattern) 134 | ) 135 | ); 136 | color = pow(color, 2.2); 137 | } 138 | 139 | fixed4 outputColor = fixed4(color, 1); 140 | UNITY_APPLY_FOG(i.fogCoord, outputColor); 141 | return outputColor; 142 | } 143 | ENDCG 144 | } 145 | } 146 | } 147 | --------------------------------------------------------------------------------