If you wanted to do it in HLSL, here are some quicky examples.
Simple V Scroll:
// +----------------------------------------+
// Semantics
// +----------------------------------------+
float4x4 WorldViewProj : WorldViewProjection < string UIWidget="None"; >;
float Time : Time < string UIWidget="None"; >;
// +----------------------------------------+
// Parameters
// +----------------------------------------+
float Speed <
string UIName = "Speed";
> = 1.0f;
texture Tex <
string ResourceName = "scroll.tga";
string UIName = "Texture";
string ResourceType = "2D";
>;
sampler2D TexSampler = sampler_state {
Texture = <Tex>;
MinFilter = Linear;
MagFilter = Linear;
MipFilter = Linear;
AddressU = Wrap;
AddressV = Wrap;
};
// +----------------------------------------+
// Stage Interop
// +----------------------------------------+
struct AppData
{
float3 Position : POSITION;
float4 UV : TEXCOORD0;
};
struct VertData
{
float4 HPos : POSITION;
float2 UV : TEXCOORD0;
};
// +----------------------------------------+
// Vertex Shader
// +----------------------------------------+
VertData mainVS( AppData IN )
{
VertData OUT;
OUT.HPos = mul(float4(IN.Position.xyz, 1.0), WorldViewProj);
OUT.UV = float2( IN.UV.x, IN.UV.y + Time * Speed );
return OUT;
}
// +----------------------------------------+
// Pixel Shader
// +----------------------------------------+
float4 mainPS( VertData IN ) : COLOR
{
return tex2D(TexSampler, IN.UV);
}
technique technique0 {
pass p0 {
CullMode = None;
VertexShader = compile vs_3_0 mainVS();
PixelShader = compile ps_3_0 mainPS();
}
}
Atlas Walk:
// +----------------------------------------+
// Semantics
// +----------------------------------------+
float4x4 WorldViewProj : WorldViewProjection < string UIWidget="None"; >;
float Time : Time < string UIWidget="None"; >;
// +----------------------------------------+
// Parameters
// +----------------------------------------+
float Speed <
string UIName = "Speed";
> = 1.0f;
float XDim <
string UIName = "X Tiles (Multiple of 2)";
> = 2.0f;
float YDim <
string UIName = "Y Tiles (Multiple of 2)";
> = 2.0f;
texture Tex <
string ResourceName = "atlas.tga"
string UIName = "Texture";
string ResourceType = "2D";
>;
sampler2D TexSampler = sampler_state {
Texture = <Tex>;
MinFilter = Linear;
MagFilter = Linear;
MipFilter = Linear;
AddressU = Wrap;
AddressV = Wrap;
};
// +----------------------------------------+
// Stage Interop
// +----------------------------------------+
struct AppData
{
float3 Position : POSITION;
float4 UV : TEXCOORD0;
};
struct VertData
{
float4 HPos : POSITION;
float2 UV : TEXCOORD0;
};
// +----------------------------------------+
// Vertex Shader
// +----------------------------------------+
VertData mainVS( AppData IN )
{
VertData OUT;
OUT.HPos = mul(float4(IN.Position.xyz, 1.0), WorldViewProj);
// Atlas properties
float2 scale = 1 / float2( XDim, YDim ); // How much to scale the UVs to fit a tile
float index = floor(Time * Speed); // Which Item in the Atlas to pick (INT)
// NOTE:
// We traverse the atlas without manually wrapping U:
// 12
// --34
// ----56
// ------78
// --------9......
// would otherwise need: float2( index % XDim, floor( index / YDim ) );
OUT.UV = IN.UV + float2( index, floor(index / YDim) );
OUT.UV *= scale;
return OUT;
}
// +----------------------------------------+
// Pixel Shader
// +----------------------------------------+
float4 mainPS( VertData IN ) : COLOR
{
return tex2D(TexSampler, IN.UV);
}
technique technique0 {
pass p0 {
CullMode = None;
VertexShader = compile vs_3_0 mainVS();
PixelShader = compile ps_3_0 mainPS();
}
}
They don’t do much of anything except put the verts in the right place and then scroll the UVs.
I’ve attached some Textures that should read as sentences when scrolling, so you know what you should be expecting.
Good luck on your actual shader! -Lith