Chapter 13: HLSL Basics

Quiz Answers

  1. In HLSL, how can you access the first element in a float4 object?

    • If you want to access the first element in a float4 object called color, you can use array notation (color[0]), or you can use the namespaces for color and position (color.r or color.x).

  2. What is swizzling?

    • The term swizzling refers to accessing multiple elements of a float4 or similar dataype at the same time by using two or more elements from the color or position namespaces (e.g., color.rb or color.xyz).

  3. In HLSL, how do you specify which vertex and pixel shader versions to use?

    • In the pass block of the technique for an HLSL effect file, you specify a VertexShader and/or a PixelShader by providing the compile keyword followed by a shader version. For vertex shaders, you use vs_1_1 syntax, and for pixel shaders, you use ps_1_1 syntax.

  4. What does HLSL do for you that you can't accomplish without it?

    • HLSL allows developers to access hardware functions that aren't available via the XNA Framework. The reason: graphics hardware has become more and more complex, and if the XNA Framework were expanded to handle all capabilities of graphics cards, the framework would be enormous. Instead, HLSL works with XNA and allows you to write code for the graphics card itself.

  5. How do you multiply two matrices together in HLSL?

    • The mul function in HLSL will multiply together two matrices.

  6. What is the role of a semantic in HLSL?

    • A semantic marks a variable as being used for a certain purpose. For input parameters, ...

Get Learning XNA 3.0 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.