Saturday, 9 February 2013

Assignment 4: Files and Format

Requirements
  • Create a new "Effect" file format that specifies:
    • "Techniques", where a single technique consists of a vertex program, a fragment program, and render state
      • At this point we only have a single vertex and fragment program, so this requirement may seem a bit confusing. Imagine that each Effect may have different rendering modes (or "techniques"), and each mode has a single vertex and fragment program pair that determines what it does (and these don't have to be unique; you could, for example, only have two vertex shader programs in the game, but ten different fragment shaders).
      • For this assignment you will only have a single technique, but keep in mind that we will add others in future assignments
      • We haven't discussed render state yet, and you don't need to include any. (I just wanted you to be aware that there will be other settings that will be part of techniques in the future.)
    • Expected textures
      • You can think of this as what samplers the fragment shader(s) will use. For now, we only have a single texture, which is a diffuse map. In the future, though, we may add normal maps, environment maps, etc. In order to fulfill this requirement you need enough so that a material file can specify a specific image file which can then be assigned to the correct sampler in the fragment shader.
    • (Be aware that in the future we will also be adding expected uniform parameters, which will be similar to expected textures.)
  • Create a new "Material" file format that specifies:
    • Which Effect file it should use
      • (There will usually be many different Materials that use the same Effect)
    • Which specific Textures should be used with the Effect
    • (Be aware that in the future we will be adding specific values that should be assigned to the expected uniform parameters)
  • Create a new "Entity" file format that specifies:
    • Which Mesh file it should use
    • Which Material file it should use
      • (In a real game you will probably want to support more than one material per mesh. In this class, however, we will always have exactly one material per mesh, and so the Entity file format will not have to change after this assignment.)
  • Create a new "Scene" file format that specifies:
    • Which Entities are in the scene. Each Entity should be defined by:
      • Which Entity file it uses
      • Its initial position and rotation/orientation in world space
      • For this assignment nothing else is required, but you may consider allowing this to be expandable in the future (for example, we may want to assign a velocity to an entity)
    • The initial position and rotation/orientation of the camera
    • Which Lights are in the scene. For this assignment, there should only be a single light defined by:
      • Its initial position
      • Its color
      • Its intensity
  • Create an Effect file
    • For now, this can use the same vertex and fragment shader we've been using so far, and it should expect a diffuse texture.
  • Create three Material files
    • For now these should all use the single Entity file that we have, which means that the only difference between them all is that they should each use a different Texture for their diffuse texture
  • Create three Entity files
    • For now each of these should use the single Mesh file that we have, but each of them should use a different Material and be at a different position (it is fine if none of them are rotated)
  • Create a Scene file
    • This should contain references to the three entity files in different positions (it's fine if none of them have any rotation)
    • It should also contain the data for a point light (like from Assignment 03, but this time with color and intensity added).
  • All of the graphics data in your renderer should come from these files. The only kinds of things that are still ok to hardcode are incidental, non-graphics things like:
    • How fast the light should move when you press a key
    • How fast the camera should move when you press a key
    • Which keys control the light and camera
    • etc.
  • All of these new file formats must live in the Assets/ folder as text files that are human readable
    • In order to grade your assignments I will open some of these files and change things, then build assets and run the game to see if the changes work
  • Now that we have more than one object you will have to use a depth buffer. A box in back of another box must never draw on top of it
  • The lighting code in your pixel shader must now deal with the light's color and intensity
    • This should be stored in a single float4:
      • The first three components should be the color. You can access that in HLSL like so:
        • float3 lightColor = g_lightParameter.xyz;
      • The last component should be the intensity. You can access that in HLSL like so:
        • float lightIntensity = g_lightParameter.w;
    • You can now calculate the final color using something like the following pseudocode:
      • float3 diffuseLighting = ( lightColor * lightIntensity ) * clampedDotProduct;
      • float3 litFragment = diffuseLighting * diffuseColor;
  • The camera and the light must still be movable (remember to document your controls in the writeup)
  • Your writeup must include a screenshot from PIX of the depth buffer.
    • You can get this by going to the Render tab and changing "Channels" to "Depth"
    • You will almost certainly have to move some sliders in the histogram box next to the Channels box in order to see anything (before you do this it will probably all look black).
Details

Enabling the depth buffer
  • You will need to set the EnableAutoDepthStencil member of your presentation parameters to TRUE
  • You will also then need to set something in the AutoDepthStencilFormat member of your presentation parameters. D3DFMT_D16 is generally a good choice
    • In a real game we should query hardware to find out if it supports various formats, but I haven't covered this in class to keep things simple. If using this format fails let me know and we will find a good alternative for you.
  • When you clear the back buffer every render frame, you will now need to clear the depth in addition to the color. You can do this by using D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER. You will then also need to specify what value to clear the depth to... Can you figure out what this should be based on our discussion in class?

No comments:

Post a Comment