Created
July 30, 2018 15:55
-
-
Save luluco250/9f3c57df547cc9a6d1850933d9713896 to your computer and use it in GitHub Desktop.
Screen noise generator shader written in Unity's ShaderLab
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 "Hidden/Noise" { | |
Properties { | |
_Complexity("", Float) = 1.0 | |
_TimeScale("", Float) = 0.0 | |
} | |
SubShader { Cull Off ZWrite Off ZTest Always | |
CGINCLUDE | |
#include "UnityCG.cginc" | |
//========// | |
//Uniforms// | |
//========// | |
float _Complexity; | |
float _TimeScale; | |
sampler2D _Texture; | |
//=========// | |
//Functions// | |
//=========// | |
float rand(float2 uv, float t) { | |
// Arbitrary constants. | |
static const float a = 2344.1234; | |
static const float b = 3847.5446; | |
static const float c = 643453.3452; | |
float d = dot(uv, float2(a, b)); | |
float s = sin(d) * c; | |
return frac(s + t); | |
} | |
//=======// | |
//Shaders// | |
//=======// | |
void VS_PostProcess( | |
float3 vertex : POSITION, | |
out float4 position : SV_POSITION, | |
inout float2 uv : TEXCOORD | |
) { | |
position = UnityObjectToClipPos(vertex); | |
} | |
float4 PS_Noise( | |
float4 position : SV_POSITION, | |
float2 uv : TEXCOORD | |
) : SV_TARGET { | |
float noise = rand(uv, _Time.y * _TimeScale); | |
noise = pow(noise, 2.2); | |
noise = lerp(0.5, noise, _Complexity); | |
return float4(noise.xxx, 1.0); | |
} | |
ENDCG | |
Pass { // Noise | |
CGPROGRAM | |
#pragma vertex VS_PostProcess | |
#pragma fragment PS_Noise | |
ENDCG | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment