Saturday, 9 February 2013

Assignment 3: Vertex elements, textures, and diffuse lighting

Requirements
  • Add texture coordinates to the box from Assignment 02
    • You will need to add texture coordinates to your mesh format
    • You will need to add texture coordinates to your mesh file. You should only use 0 and 1 for this assignment, so that each face of the box shows the full texture. The texture should be right side up and, as much as possible, not mirrored (in other words, if the image has text it should be readable). If you only use 8 vertices then the front and back faces should be oriented correctly, but the left and right faces can be mirrored and the top and bottom don't need to show anything.
      • If you end up using more vertices you may want to challenge yourself to show the texture oriented correctly on each face
    • You will need to add texture coordinates to your vertex declaration.
  • Load a texture and use change your fragment shader to display it on your box
    • The texture you choose must go through the normal asset build process. You should be able to use the existing TextureBuilder with no modification, but you will have to add your texture to the asset list.
    • The texture must not be symmetrical, so that it is obvious what part of it is the top, what part the bottom, what part the left, and what part the right.
  • Add normals to the box from Assignment 02
    • You will need to add normals to your mesh format
    • You will need to add normals to your mesh file. You have two options:
      • Add normals facing out from the sides of the box, so that it has hard edges. This will look like a traditional cube, but will require more than the 8 vertices from Assignment 02
      • Add normals facing out from the vertices of the box, so that it has interpolated soft edges. This will look kind of bad visually, but only requires 8 vertices and will help you gain an understanding of how curved surfaces are faked.
        • If you choose this second option, the normals in the file must be normalized
    • You will need to add normals to your vertex declaration
  • Add a point light to your scene which lights the box
    • The light shouldn't have any intensity, color, or falloff. The algorithm to light the box should be:
      • Calculate the vector L between the light's world position and the fragment's world position
        • L = light_position - fragment_position
        • Get the light's world position by using a uniform variable that is set by your renderer in C++
        • Get the fragment's world position by using an interpolator and passing it from the vertex shader to the fragment shader
      • Normalize that vector
        • L = normalize( L )
      • Compute the cosine of the angle between that vector and the fragment's normal in world space
        • cosine = dot( L, fragment_normal )
        • Remember that the dot product is the same as the cosine when both vectors are normalized
        • Get the fragment's normal in world space by:
          • In the vertex shader transform multiply its normal in model space with the rotation from the model-to-world transform
            • Remember that the rotation is the 3x3 part of the 4x4 transform
          • Use an interpolator and pass the normal in world space to the fragment shader
      • Calculate the diffuse lighting by clamping the cosine so it has no negative values
        • diffuseLighting = saturate( cosine )
      • Combine the fragment's diffuse color with the diffuse lighting
        • o_color = diffuseColor * diffuseLighting
    • The light should be movable
      • You can use any control scheme you wish. The box itself doesn't need to move for this assignment, so you can use the same keys you used for it in Assignment 02 if you wish. You may want to consider being able to move the light in all three axes.
      • It is not necessary to let the user control the light (although this can be helpful for debugging). You may also just have the light move automatically in a circle or something using seconds elapsed and a sine function. If you do this, though, make sure that you choose a good motion. Remember that I'll be grading this, and I need to be able to see the box clearly as well as be able to tell that the light is doing what it's supposed to be doing.
      • When your program starts the light should be in a good default position so that it is easy to see the box. Donot have your program start rendering black :-)
      • The camera must still be movable like it was in Assignment 02. The box no longer has to move, but the camera does!
  • Your writeup must include:
    • A screenshot of the texture resource in PIX

No comments:

Post a Comment