Here's an example of a shader that creates a shiney beam of light that scrolls over an object:
Code
// Define input structure for pixel shader
struct PixelInput
{
float2 texCoord : TEXCOORD0;
};
// Define variables for shine frequency, strength, and speed
float ShineFrequency : register(c0);
float ShineStrength : register(c1);
float ShineSpeed : register(c2);
float ShineWidth : register(c3); // Expose shine width directly
float time : register(c4); // Expose time directly
// Texture sampler
sampler2D itemTexture : register(s0);
// Pixel shader
float4 main(PixelInput input) : COLOR
{
// Calculate shine factor
float shineValue = sin(dot(input.texCoord, float2(ShineFrequency, ShineFrequency)) + time * ShineSpeed);
float shineFactor = 0.5 + 0.5 * ShineStrength * smoothstep(0.5 - ShineWidth * 0.5, 0.5 + ShineWidth * 0.5, shineValue);
// Sample input texture color
float4 inputColor = tex2D(itemTexture, input.texCoord);
// Add shine effect
inputColor.rgb *= shineFactor;
return inputColor;
}
// Technique for applying shine effect
technique ShineTechnique
{
pass Pass1
{
PixelShader = compile ps_2_0 main();
}
}
Display More
It works, it's pretty cool. However, if the object rotates, the shine bands rotate with it. There's fPixelWidth and fPixelHeight to get screen dimensions, but is there a way to make a shader operate in world coordinates?