Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.
O'Reilly Media, Inc. 4/5/2012 sampler2D BaseImage: register(s0); sampler2D TextureMap : register(s1); float vertScale : register(c0); float horzScale : register(c1); float translateX : register(c30); float translateY : register(c31); float4 main(float2 uv : TEXCOORD): COLOR { float hOffset = frac(uv.x / vertScale + translateX); float vOffset = frac(uv.y / horzScale + translateY); float2 offset = tex2D(TextureMap, float2(hOffset, vOffset)).xy * 4 - (1/2); float4 outputColor = tex2D(BaseImage, frac(uv + offset )); return outputColor; } In addition to the sampler2D inputs shown earlier in Example 4-15, the refactored code contains four additional input values declared at the top of the pixel shader. If you look closely, you can see that these new items are float values, which are loaded into registers c0, c1, c30 and c31 and then used inside the main function. The ShaderEffect class transmits parameter information to a HLSL constant register through a DependencyProperty. It does this by using the special PixelShaderConstantCallback method. The trip is one-way, from the effect class to the pixel shader. The parameter value never travels back to the effect class.