Time for action – the pixel shader
1. Examine the code of the
PixelShaderFunction
, in particular the line that readsreturn float4(1, 0, 0, 1)
.2. Modify the code for the
PixelShaderFunction
, replacing the contents with the following:float4 PixelShaderFunction(VertexShaderOutput input) : COLOR0 { return tex2D(textureSampler, input.TextureCoordinate); }
What just happened?
In step 1, we see that the default pixel shader function is quite simple. All it does is return a float4
value of (1, 0, 0, 1). But what does this mean? Note the COLOR0
at the end of the declaration for the pixel shader function. This is another semantic that indicates that this function returns the color of the pixel that will be sent to the display.
If we interpret the float4
value as a color, in the order Red, Green, Blue, Alpha, we see that the default pixel shader simply returns a non-transparent red. Ah ha! This is why our terrain is currently rendering as a large red blob!
Our replacement function uses the tex2D
HLSL...