7. The interpolator next to
the rasterizer calculates
this value, by interpolating
the color value of the
corner points.
8. This means that a pixel
exactly in the middle
between a blue and a red
corner point, will get the
color that is exactly in the
middle of these colors.
13. You could also do this
in your XNA app, but
then your CPU would
have to perform those
calculations, which
would lower your
framerate!
14. Now you can have these
calculations done by the
GPU, which is A LOT faster
at it, leaving your CPU free
to perform more important
calculations
15. As you have seen,
Using the vertex shader,
you could also adjust
the color, which we’ve
done before (we made
our whole triangle
white)
16. So for this example, we will throw away
the color information provided to us by the
vertex stream, and define our own colors.
Say, we want our vertex shader make the
red color component indicate the X
coordinate of each vertex, the green
component the Y coordinate, and the blue
color component indicate the z coordinate.
19. Experimenting With Shaders
• Go to our last HLSL file “.fx”
– Replace the following line
Output.Color = inColor;
20. Experimenting With Shaders
• Go to our last HLSL file “.fx”
– Replace the following line
– With this one
Output.Color = inColor;
Output.Color.rgb = inPos.xyz;
21. Experimenting With Shaders
• Go to our last HLSL file “.fx”
– Replace the following line
– With this one
Output.Color = inColor;
Output.Color.rgb = inPos.xyz;
22. Experimenting With Shaders
• Go to our last HLSL file “.fx”
– Replace the following line
– With this one
Output.Color = inColor;
Output.Color.rgb = inPos.xyz;
23. Experimenting With Shaders
• Go to our last HLSL file “.fx”
– Replace the following line
– With this one
Output.Color = inColor;
Output.Color.rgb = inPos.xyz;
24. Experimenting With Shaders
• Go to our last HLSL file “.fx”
– Replace the following line
– With this one
Output.Color = inColor;
Output.Color.rgb = inPos.xyz;
29. Experimenting With Shaders
• So what is happening?
• Before the colors are passed to the interpolator, the
3 color values of the 3 vertices are being clipped to
the [0,1] region. For example, the (-2,-2,2) vertex
should have -2, -2 and 2 as rgb color values, but it
gets 0, 0 and 1 as color values
30. Experimenting With Shaders
• So what is happening?
• The (0,0,0) point gets a color value that is an
interpolation of color values between the [0,1]
region, and thus will never be completely 0,0,0
(=black).
42. Shaders - Samples
• Texturing our triangle using the Pixel Shader
• Read more
– http://www.riemers.net/eng/Tutorials/XNA/Csharp/Series3/Textured_triangle.php
43. Shaders - Samples
• A logical next step would be to load a texture from within our XNA app, and have our
pixel shader sample the correct color for each pixel.
54. Shaders - Samples
• Creating your first light
• Read more
– http://www.riemers.net/eng/Tutorials/XNA/Csharp/Series3/Per-pixel_lighting.php
55. Shaders - Samples
• Every object is lit by an amount of light, which depends on the angle between the normal
and the direction of the light.
56. Shaders - Samples
• Every object is lit by an amount of light, which depends on the angle between the normal
and the direction of the light.
• This is found by taking the dot product between that object’s normal and the direction of
the incoming light.
65. Shaders - Samples
• Transforming vertices to texture space using Projective Texturing
• Reading more
– http://www.riemers.net/eng/Tutorials/XNA/Csharp/Series3/Projective_texturing.php