Skip to content

Instantly share code, notes, and snippets.

@neildanson
Created August 31, 2013 20:11
Show Gist options
  • Save neildanson/6400324 to your computer and use it in GitHub Desktop.
Save neildanson/6400324 to your computer and use it in GitHub Desktop.
Example fx file that compiles and runs fine on Windows, iOS & Android.
float fTimer;
float fPixellateFactor = 1.0f;
sampler ColorMapSampler : register(s0);
float4 NormalShader(float2 Tex:TEXCOORD0) : COLOR
{
float4 color = tex2D(ColorMapSampler, Tex);
return color;
}
technique Normal
{
pass P0
{
PixelShader = compile ps_2_0 NormalShader();
}
}
float4 WobbleShader(float2 Tex:TEXCOORD0) : COLOR
{
Tex.x += sin(fTimer+Tex.x*10)*0.02f;
Tex.y += sin(fTimer+Tex.y*10)*0.02f;
float4 color = tex2D(ColorMapSampler, Tex);
return color;
}
technique Wobble
{
pass P0
{
PixelShader = compile ps_2_0 WobbleShader();
}
}
float4 DiscoShader(float2 Tex:TEXCOORD0) : COLOR
{
float4 color = tex2D(ColorMapSampler, Tex);
color.r = color.r - sin (fTimer/3+color.r * Tex.y) * 0.5f;
color.g = color.g - sin (fTimer/3+color.g * Tex.x) * 0.5f;
color.b = color.b - cos (fTimer/3+color.b * Tex.y) * 0.5f;
return color;
}
technique Disco
{
pass P0
{
PixelShader = compile ps_2_0 DiscoShader();
}
}
float4 PixellateShader(float2 Tex:TEXCOORD0) : COLOR
{
float2 brickCounts = { 640, 480 };
//2.0 is a distortion factor - larger the # the larger the distortion
float2 brickSize = fPixellateFactor / brickCounts;
// Offset every other row of bricks
float2 offsetuv = Tex;
float2 brickNum = floor(offsetuv / brickSize);
float2 centerOfBrick = brickNum * brickSize + brickSize / 0.5f;
float4 color = tex2D(ColorMapSampler, centerOfBrick);
return color;
}
technique Pixellate
{
pass P0
{
PixelShader = compile ps_2_0 PixellateShader();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment