Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Unity Noise-Gradation Shader
Shader "Sasami/NoiseGradation"
{
Properties
{
_MainTex ("Texture", 2D) = "white" {}
_NoiseTilingOffset ("NoiseTex Tiling(x,y)/Offset(z,w)", Vector) = (0.1,0.1,0,0)
_NoiseSizeScroll ("NoiseTex Size(x,y)/Scroll(z,w)" , Vector) = (16,16,0,0)
_BaseColor ("Base Color" , Color ) = (1,1,1,1)
_GradationColor ("Gradation Color", Color ) = (0,0,0,1)
}
SubShader
{
Tags { "RenderType"="Transparent" }
LOD 100
ZWrite Off
Blend SrcAlpha OneMinusSrcAlpha
Pass
{
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "SasamiNoise.cginc"
struct appdata
{
float4 vertex : POSITION;
float2 uv : TEXCOORD0;
};
struct v2f
{
float4 vertex : SV_POSITION;
float4 uv : TEXCOORD0;
};
sampler2D _MainTex;
float4 _MainTex_ST;
fixed4 _NoiseTilingOffset;
fixed4 _NoiseSizeScroll;
fixed4 _BaseColor;
fixed4 _GradationColor;
v2f vert (appdata v)
{
v2f o;
o.vertex = UnityObjectToClipPos(v.vertex);
o.uv.xy = TRANSFORM_TEX(v.uv, _MainTex);
o.uv.zw = TRANSFORM_NOISE_TEX(v.uv, _NoiseTilingOffset, _NoiseSizeScroll);
return o;
}
fixed4 frag (v2f i) : SV_Target
{
fixed p = perlinNoise(i.uv.zw, _NoiseSizeScroll.xy);
return lerp( _GradationColor, _BaseColor, p ) * tex2D(_MainTex, i.uv.xy);
}
ENDCG
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment