Skip to content

Instantly share code, notes, and snippets.

@renaudbedard
Created November 23, 2018 04:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save renaudbedard/f14c7e8bdc924c011ecaf24ccbfeb224 to your computer and use it in GitHub Desktop.
Save renaudbedard/f14c7e8bdc924c011ecaf24ccbfeb224 to your computer and use it in GitHub Desktop.
float4x4 WorldViewProj : WorldViewProjection;
texture ColorTexture;
sampler2D ColorSampler = sampler_state {
Texture = <ColorTexture>;
FILTER = MIN_MAG_MIP_LINEAR;
AddressU = Wrap;
AddressV = Wrap;
};
float2 CellCount;
float2 CellIndex;
float2 TCRepeat;
struct VertexInput
{
float4 Position : POSITION0;
float2 TextureCoordinates : TEXCOORD0;
};
struct VertexOutput {
float4 Position : POSITION0;
float2 TextureCoordinates : TEXCOORD0;
};
VertexOutput mainVS(VertexInput input)
{
VertexOutput output;
float2 cellSize = 1.0f / CellCount;
float2 cellOffset = cellSize * CellIndex;
output.TextureCoordinates = (input.TextureCoordinates * cellSize + cellOffset) * TCRepeat;
output.Position = mul(input.Position, WorldViewProj);
return output;
}
float4 mainPS(VertexOutput input) : COLOR0
{
float2 cellSize = 1.0f / CellCount;
float2 cellOffset = cellSize * CellIndex;
float2 tc = input.TextureCoordinates;
tc = frac((tc - cellOffset) / cellSize) * cellSize + cellOffset;
float4 sample = tex2D(ColorSampler, tc);
return sample;
}
technique technique0 {
pass p0 {
CullMode = None;
VertexShader = compile vs_3_0 mainVS();
PixelShader = compile ps_3_0 mainPS();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment