Skip to content

Instantly share code, notes, and snippets.

@smkplus
Last active October 13, 2024 13:15
Show Gist options
  • Save smkplus/256efe803f9a8f9342075538919fc893 to your computer and use it in GitHub Desktop.
Save smkplus/256efe803f9a8f9342075538919fc893 to your computer and use it in GitHub Desktop.
Unity ,Shader,white noise
Shader "Noise/WhiteNoise"
{
Properties
{
_MainTex ("Texture", 2D) = "white" {}
_Color("Color",Color) = (1,1,1,1)
}
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;
}
sampler2D _MainTex;
float4 _Color;
float hash( uint2 hashInput )
{
uint2 q = 1103515245U * ( (hashInput.x>>1U) ^ (hashInput.yx ) )*abs(sin(_Time.y));
uint n = 1103515245U * ( (q.x ) ^ (q.y>>3U) );
return float(n) * (1.0/float(0xffffffffU));
}
fixed4 frag (v2f i) : SV_Target
{
fixed4 col = tex2D(_MainTex, i.uv);
uint2 p = (i.uv*_ScreenParams);
float f = hash(p);
col = float4( f, f, f, 1.0 );
return col;
}
ENDCG
}
}
}
@STARasGAMES
Copy link

Excellent! Thank you so much!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment