Created
October 9, 2012 09:45
-
-
Save distantcam/3857676 to your computer and use it in GitHub Desktop.
xkcd Shader
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
sampler2D input : register(s0); | |
/// <summary>The second input texture.</summary> | |
/// <defaultValue>c:\examplefolder\examplefile.jpg</defaultValue> | |
sampler2D RandomTexture : register(s1); | |
/// <summary>The radius of the Poisson disk (in pixels).</summary> | |
/// <minValue>1</minValue> | |
/// <maxValue>10</maxValue> | |
/// <defaultValue>5</defaultValue> | |
float DiskRadius : register(C0); | |
/// <summary>The size of the input (in pixels).</summary> | |
/// <type>Size</type> | |
/// <minValue>1,1</minValue> | |
/// <maxValue>1000,1000</maxValue> | |
/// <defaultValue>600,400</defaultValue> | |
float2 InputSize : register(C1); | |
/// <summary>Dampens the effect of the noise.</summary> | |
/// <minValue>1</minValue> | |
/// <maxValue>300</maxValue> | |
/// <defaultValue>100</defaultValue> | |
float Dampen : register(C2); | |
static const float2 poisson[12] = | |
{ | |
float2(-0.326212f, -0.40581f), | |
float2(-0.840144f, -0.07358f), | |
float2(-0.695914f, 0.457137f), | |
float2(-0.203345f, 0.620716f), | |
float2(0.96234f, -0.194983f), | |
float2(0.473434f, -0.480026f), | |
float2(0.519456f, 0.767022f), | |
float2(0.185461f, -0.893124f), | |
float2(0.507431f, 0.064425f), | |
float2(0.89642f, 0.412458f), | |
float2(-0.32194f, -0.932615f), | |
float2(-0.791559f, -0.59771f) | |
}; | |
float4 blur(float2 uv) | |
{ | |
float4 cOut; | |
// Center tap | |
cOut = tex2D(RandomTexture, uv); | |
for(int tap = 0; tap < 12; tap++) | |
{ | |
float2 coord= uv.xy + (poisson[tap] / InputSize * DiskRadius); | |
// Sample pixel | |
cOut += tex2D(RandomTexture, coord); | |
} | |
return(cOut / 13.0f); | |
} | |
float4 main(float2 uv : TEXCOORD) : COLOR | |
{ | |
float4 randomValue = blur(uv); | |
uv.x += randomValue.x / Dampen; | |
uv.y += randomValue.y / Dampen; | |
float4 color = tex2D( input, uv ); | |
return color; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment