Created
March 17, 2017 05:11
-
-
Save thelucre/a63a350afb86eaf55386d8db19129633 to your computer and use it in GitHub Desktop.
Simplex Noise Shader Unity
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Shader "Custom/SimplexNoise2D" { | |
Properties { | |
_Color ("Color", Color) = (1,1,1,1) | |
_Color2 ("Color2", Color) = (1,1,1,1) | |
_Color3 ("Color3", Color) = (1,1,1,1) | |
_Color4 ("Color4", Color) = (1,1,1,1) | |
} | |
SubShader { | |
Pass { | |
CGPROGRAM | |
#pragma vertex vert | |
#pragma fragment frag | |
#include "UnityCG.cginc" | |
// Sourced from: https://github.com/keijiro/NoiseShader/blob/master/Assets/HLSL/NoiseTest.shader | |
#include "SimplexNoise2D.cginc" | |
// vertex input: position, second UV | |
struct appdata { | |
float4 vertex : POSITION; | |
float4 texcoord1 : TEXCOORD1; | |
}; | |
struct v2f { | |
float4 pos : SV_POSITION; | |
float4 uv : TEXCOORD0; | |
}; | |
v2f vert (appdata v) { | |
v2f o; | |
o.pos = UnityObjectToClipPos(v.vertex ); | |
o.uv = float4( v.texcoord1.xy, 0, 0 ); | |
return o; | |
} | |
float4 _Color; | |
float4 _Color2; | |
float4 _Color3; | |
float4 _Color4; | |
half4 frag( v2f i ) : SV_Target { | |
float2 pos = snoise(i.uv + _Time[0])*((2.0+_SinTime[3])*0.5); | |
float l = length(pos); | |
if(l > 0.75) return _Color; | |
else if(l > 0.5) return _Color2; | |
else if(l > 0.25) return _Color3; | |
return _Color4; | |
} | |
ENDCG | |
} | |
} | |
FallBack "Diffuse" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment