Query 5.1. Go look on your CD and execute Ced3d/bin/Xpose.exe. Find the sphere model (it's in src/firefly) then find the Jade texture (in a folder named src/jade) and apply it to the sphere. Select flat shading, then Gouraud. That highlight is annoying, isn't it? Can you find a menu option that would turn it down, or off? HINT: It's not called highlight. But it is in a fairly obvious place.
Start playing with the JadeWin source code example. Note that the text refers to the callback function as MoveFrame but the source code refers to FrameMove. Go figure.
The text discusses the use of Resources - which are data objects that get built into the .exe file. Both the mesh named D3D (how's that for confusing us?) and the texture named jade, are treated as Resources in this example.
Query 5.2. Construct a directory called RemoteTest, somewhere far away from your D3d stuff. Make a copy of jade.exe in that directory. Also go make a copy of your sample.exe (or whatever you called it), and put it in remoteTest.
Now close down Visual Studio. Double click on Jade.exe. It should run, all by itself. Exit. Double click on Sample.exe. What's the difference in this run and the Jade run, and why? How would you fix the sample program so it would run (there are at least two ways, one easy and one troublesome.)
Query 5.3. Read Listing 5.1 and its explanations. They're pretty straightforward. Try the suggested action (page 137, toward the bottom) of commenting out the line which specifies the perspective correction for the mesh. What happens?
Well, my personal C++ system is now hosed up. I get
LINK : fatal error LNK1104: cannot open file "nafxcwd.lib"
when I try to compile anything whatsoever. The CDs I need to repair this problem are at the office and I'm at home. So the rest of these notes will be somewhat speculative since I can't try the examples.
Exploring the Perspective Correction for Textures
Consider the problem of mapping a rectangular texture onto a perspective image of the rectangle. The image is in general a trapezoid, and so one quick-and-dirty way to squash the texture would be just to bilinearly interpolate it in 2d, into the trapezoid that results from using the perspective projection on the original rectangular texture map.
Query 5.4. What visual artifact would result from this method of flat texture mapping?
I will provide for the class, the classic Edwin Catmul paper on the two-stage texture manipulation routine which is at the heart of most hardware accelerators. You won't be able to deal with the next queries until you have read the paper, so think of them as "forward reference" queries.
Query 5.5. What is the range of angles through which the Catmull technique can rotate an image without excessive sampling error? How is it generalized to overcome this problem and handle all angles?
Query 5.6. Can the Catmull technique produce a true perspective correction? If so, what is its per-pixel cost in arithmetic operations (in some approximate sense, at least?) If not, why not?
Back to the Text (Page 140)
Query 5.7. In Table 5.1, are the captions in the "Parameter" column correctly labelled?
<<I don't understand where in the source for the JadeWin application, the pulldown menus which refer to OnRenderWireframe, etc. are created. Somebody please let me know.>>
The Difference between Flat, Cylinder and Sphere Wraps
is not discussed in the text. Here are the three Apply methods, for comparison.
void WrapsWin::ApplyFlat( LPDIRECT3DRMMESHBUILDER meshbuilder )
{
D3DRMBOX box;
meshbuilder->GetBox( &box );
D3DVALUE width=box.max.x-box.min.x;
D3DVALUE height=box.max.y-box.min.y;
LPDIRECT3DRMWRAP wrap;
d3drm->CreateWrap( D3DRMWRAP_FLAT, NULL,
D3DVALUE(0.0), D3DVALUE(0.0), D3DVALUE(0.0), // wrap origin
D3DVALUE(0.0), D3DVALUE(0.0), D3DVALUE(1.0), // z axis
of wrap
D3DVALUE(0.0), D3DVALUE(1.0), D3DVALUE(0.0), // y axis
of wrap
D3DVALUE(0.5), D3DVALUE(0.5), // texture
origin
D3DDivide(1,width), D3DDivide(1,height), // texture scale
&wrap );
wrap->Apply( meshbuilder );
wrap->Release();
}
In the flat method, we specify the texture origin at the center of the box and scale the texture to cover the flat side of the cube exactly once.
void WrapsWin::ApplyCylinder( LPDIRECT3DRMMESHBUILDER meshbuilder )
{
D3DRMBOX box;
meshbuilder->GetBox( &box );
D3DVALUE width=box.max.x-box.min.x;
D3DVALUE height=box.max.y-box.min.y;
LPDIRECT3DRMWRAP wrap;
d3drm->CreateWrap( D3DRMWRAP_CYLINDER, NULL,
D3DVALUE(0.0), D3DVALUE(0.0), D3DVALUE(0.0), // wrap origin
D3DVALUE(0.0), D3DVALUE(0.0), D3DVALUE(1.0), // z axis
of wrap
D3DVALUE(0.0), D3DVALUE(1.0), D3DVALUE(0.0), // y axis
of wrap
D3DVALUE(0.5), D3DVALUE(0.5),
D3DVALUE(1.0), D3DDivide(1,height),
// texture scale
&wrap );
wrap->Apply( meshbuilder );
wrap->Release();
}
In the cylinder method we seem to be correcting for height but not for width. This tells us that the width will always be linearly interpolated across 360 degrees. We deduce that the texture is in fact projected as though on a surrounding cylinder infinitely far from the axis of the specified cylinder object. But how are the ends mapped?
I don't know. The following image is from the WRAPS demo. I would have thought that the ends would be textured in a radial pattern. Obviously a cylindrical texture really doesn't work at all well, on the cube.
Query 5.8: Where are the discontinuities in the cylindrical mapping?
void WrapsWin::ApplySphere( LPDIRECT3DRMMESHBUILDER meshbuilder )
{
D3DRMBOX box;
meshbuilder->GetBox( &box );
D3DVALUE width=box.max.x-box.min.x;
D3DVALUE height=box.max.y-box.min.y;
LPDIRECT3DRMWRAP wrap;
d3drm->CreateWrap( D3DRMWRAP_SPHERE, NULL,
D3DVALUE(0.0), D3DVALUE(0.0), D3DVALUE(0.0), // wrap origin
D3DVALUE(0.0), D3DVALUE(0.0), D3DVALUE(1.0), // z axis
of wrap
D3DVALUE(0.0), D3DVALUE(1.0), D3DVALUE(0.0), // y axis
of wrap
D3DVALUE(0.0), D3DVALUE(0.0), // texture
origin
D3DVALUE(1.0), D3DVALUE(1.0), // texture
scale
&wrap );
wrap->Apply( meshbuilder );
wrap->Release();
}
For the sphere we can see that the source map is wrapped around the sphere: 360 degrees as in a cylinder, and 180 degrees vertically.
Query 5.9: Where are the discontinuities in the spherical mapping?
The Decals ("billboards", in normal graphics-speak) demo is simple and doesn't need discussion.
The transparency demo shows that one uses a method called SetDecalTransparency, even though we're not working with a decal in that case. Black is the default transparent color, to nobody's surprise.
Texture animation is demonstrated by the TextureDrift demo (one map, moving horizontally across a static object) and Showroom (which is SUPPOSED to contain a series of maps projected animation-style onto a moving object. The demo doesn't change the texture maps on my machine. Since my C++ is messed up today I cannot experiment with the source code. I hope that you will do so, and let us know on Monday what it takes to get the texture maps to animate.