CO2409-12 Lab Worksheet PDF

Title CO2409-12 Lab Worksheet
Course Computer Graphics
Institution University of Central Lancashire
Pages 4
File Size 154.6 KB
File Type PDF
Total Downloads 10
Total Views 164

Summary

Lab 12 - Texture Mapping, Lab 12 - Texture Mapping...


Description

Direct3D 10 Texture Mapping This exercise does not count towards the Lab Assignments This worksheet looks at textures, texture mapping and texture coordinates UV Exercises Given this texture:

1. Draw the texture as it would be mapped onto polygons with these texture coordinates:

2. Draw the texture as it would be mapped onto this polygon. Draw two pictures, one for the “wrap” texture addressing mode and another for the “clamp” mode.

Wrap:

Clamp:

Practical: Getting Started   

Download the Texturing zip file from the CO2409 webpage Unzip it to your work folder and open the ‘Texturing’ project Open the project, but note that the program does not work at first

CO2409 - Computer Graphics, Week 12

Lab Worksheet 1-1

Practical Exercises As usual, the project is derived from last week's lab, with some minor changes, mostly to add two different models in the scene. However, the program doesn’t initially work…  



Open the Effect (“.fx”) file. There is missing line of code in both the vertex and pixel shader. Fill it in referring to your previous lab work and the comments. Run the program, you now should see a cube hovering over a floor. They should be textured if you completed the previous step correctly o The camera can be zoomed in and out with the up and down cursor keys. o The cube can be rotated with the ‘W’, ‘S’, ‘A’, & ‘D’, keys – notice that each side is a different colour – the cube mesh is coloured differently on each face, then the texture is blended into that colour There is no filtering so the texels on the floor are clearly visible and also on the cube when very close – use the up and down cursor keys to zoom

Texture Addressing Mode We’ll look at UV coordinates first and leave the filtering until later  Open “Texturing.cpp” and scroll down into the geometry data. Find the floor vertex array (read the variable names).  Update UVs in floor data to range from 0.0 to 5.0 rather than 0.0 to 1.0. o Check the BasicVertex structure further up (or use your common sense) to work out which data is the UVs  Run the app and see how the floor texture is now repeated several times rather than just once. o Also note the aliasing (pixel flicker / shimmer) especially when you zoom out.  Open the Effect file (“Texturing.fx”) and find the “Textures” section near the top  Read the comments We’ll sample the texture differently using texture addressing modes:  Look in the Sampler in that section. Change the addressing mode to Clamp mode. o Notice that this mode is set independently for the U and V texture directions. o Set them both the same.  Run the app and work out what happened. o Zoom out quite a lot, and look at the lecture notes.  Try Border mode too  Switch back to Wrap mode before continuing Bilinear Filtering We need to fix the aliasing - we’ll start with bilinear filtering  Again in the sampler, look at the ‘Filter’ line. o Note how the constant refers to minification, magnification and mip-map filtering. We can set each differently.  We want to change the filter to use linear for minification and magnification, but point sampling for mip-mapping. This is done with: MIN_MAG_LINEAR_MIP_POINT  Run the program, the texels will have been smoothed out now. However, zooming out you may still see some aliasing on the floor. CO2409 - Computer Graphics, Week 12

Lab Worksheet 1-2

We can show aliasing problems more clearly:  Open the ‘Texturing.cpp’ file. o Note, there have been several changes to allow multiple independent models to be rendered and to use different textures  Go to end of the InitGeometry function to find the code that loads the texture files. o Change ‘Wood2.jpg’ to ‘Lines.png’ (note that’s PNG not JPG)  Run the app again. This is an extremely difficult texture to filter effectively. Zooming out should show very bad aliasing

Mip-Mapping   

Go back to the Sampler in the Effect file. Comment out or remove the MaxLOD line. This line was preventing the app from using mip-maps. With this line removed, point sampled mip-maps will be used (together with the bilinear filtering from before) Run the app. You can see it use more blurry versions of the floor texture in the distance to try and reduce aliasing. o However, the horizontal lines between the mip-map levels are clearly visible. Zoom away then zoom in and out to see them very easily

Trilinear Filtering  

Change the Filter to MIN_MAG_MIP_LINEAR to add linear mip-map filtering to the bilinear filtering. This makes trilinear filtering. Run the app. You can see the mip-map boundaries and now blended, making a somewhat better result

Anisotropic Filtering 

Change the Filter to just ANISOTROPIC to enable anisotropic filtering for all sampling. Also add a new line to the sampler: MaxAnisotropy = 2; o This controls the quality of the anisotropic filter. Different machines can support different levels (from 1 to 16). Experiment.

Final Details We’ve seen most parts of the code relating to textures, just a couple of notes remain:  You’ll have noticed that the texture variables have been called diffuse maps. This relates to lighting. The diffuse texture is the basic look of a surface and is affected by diffuse light. We will see more kinds of texture later: for example specular maps and normal maps. Get used to the words texture and map being interchangeable.  Go to the Render function in Texturing.cpp. Notice how it has been broken up into sections to aid in rendering multiple models.  Look for the lines: g_pDiffuseMapVar->SetResource(...), each setting the texture variable in the shader with one of the C++ texture variables. This is the final link in the texturing code you’ve worked with in this lab

CO2409 - Computer Graphics, Week 12

Lab Worksheet 1-3

Multiple Models Here are some exercises to try over Christmas. This is not part of the assignment labs, but it will prepare you very well for the work ahead. You are strongly recommended to try it, get as far as you can: 

Try to create another model in the scene o Start by making changes to the Render function to draw a second cube (in a different place than the first) o Try to add code to control this separately from the other cube  Another Update function may help o Now try to use a different texture from the floor and first cube  There are a few textures in the project folder o Can you make this model use different geometry?  You will need more arrays of vertices and indices, as well as a new vertex buffer / index buffer. This is a decent challenge.

CO2409 - Computer Graphics, Week 12

Lab Worksheet 1-4...


Similar Free PDFs