Additional Examples
§ Line-Sphere Intersection:
o
Here is the source
o
Here is the accompanied diagram
Some
of the following examples are based on older versions of the libraries. In all
cases, the idea remains the same though.
1. Problem with Hardware Shading: Some examples of confusing hardware shading problems. |
2. Drawing 2D and
3D in the same window: Pay attention to DrawOnlyHandler::DrawGraphics(),
after we are done drawing 3D is where all the 2D stuff happens. (Download Source Code) |
3. Working with 2D
and 3D Windows: Check on 2D Control Window to see the 2D view of the 3D world.
In the 2D window, you can LMB click and drag either the teapot or the plane.
The 2D window is like a 2D plane for supporting UI. (Download Source Code) |
4. Shadow
Reflection and Stencil: We will discuss this in class! (Download Source Code) |
5. Interesting
Texture Effects: o
Draw textures: (here is
the source code) 1.
TdrawTexture class: now sub-class from Ttexture ….
2.
Tworld: for any
primitive that we can display textures (primitives with area: i.e. Tfillable): we have these new attributes:
o
Bubble texture: (here is
the source code): simple tiny changes in
TdrawTexture::UpdateTexture(), now instead of simply copy my 2D numbers into the
hardware … I did a little bit of a trick … floating my texture and enlighten
things a little … ok, pretty lame bubbles, but kind of interesting isn’t it?
Now .what if I can control what is in the buffer, such that … o
Fire Texture: (here is
the source code):
|
6. Fog: purely
based on distance to camera. If you have ore than
one views, the result looks strange! (here is the source code). |
7. X-Ray-light: now
we are really hacking! I will talk about this in class. (here is the
source code). |
SimpleShader: almost the simplest vertex/pixel shader. Notice:
1.
Compare and
contrast to Tutorial_A.1 on Page 490 from the textbook, see that we do not need
to program the rendering pipeline anymore!
2.
We can load
different “effects”: GrafxWindowD3D.cpp:: line 37.
3.
We can verify uv values are linearly
interpolated after vertex shader and interpolated
result is passed into the pixel shader.
4.
Effects parameter
setting (e.g., effect->SetTexture()) has almost no error
checking! We can call this function even if our effect has no support for
texture! This is pretty cool, you can do almost anything you want, this is very
annoying because compiler and/or run time is not looking for potential errors
for us (setting texture when working with the simple shader)
5.
Nomrals are set up to point away from the center of the
square (and has no y-components) We can load different
“effects”. In NdotL shader,
this would mean all pixels should be shaded to black (NdotL
will equal to zero). But, linear interpolation is occurring and we can actually
verify the results!
6.
Notice normal’s
transform is different from that of the positions (with Inverse Transpose).
PixelPhong: integrate
Vertex/Shader into our library (almost correct), and re-implement
default phong illumination pipeline with vertex and
pixel shader. Notice:
1.
UWB_LightingEffects:
a. Supports 4 light sources, notice the difference! Phong is computed for each pixel rather than once per
vertex!
b. Texture is added to the illumination effect: one
alternative would be to use the texture as replacement for diffuse material.
c. Alpha term is always set to 1: this stop blending from
working. A simple fix would be to assign material diffuse’s
alpha value to the output. Alternatively, we can retain the phong
illumination result for the alpha channel, can be cool?
2.
Effect as resources:
effect files are “just like” texture and mesh files, we can take advantage of our
“resource management” system to load/store the effect:
a. D3D_Resources folder: D3DEffectResource, just like
texture and mesh, we need to read the resource into the memory.
b. D3D_GraphicsSystem folder:
i.
D3DGraphicsSystem
class, we create a new effect resource table.
ii.
D3DGraphicsSystem_Effect.cpp:
support setting of effect parameters, notice we support a super set of most of
the parameters we need for illumination computation (e.g., always try to set material, always try to set texture, etc.)
c. Other effect parameters: Light – done in D3D_Light
class. Always set all 4 light sources.
d. Other effect parameters: Camera Position: set in WindowHandler::DrawGraphics()
e. Drawing with effect: D3D_DrawHelper gets the “current
effect” from GraphicsSystem and renders with GraphicsSystem’s current.
f. Should do: create effect as a attribute
in Primitive such that each primitive has its own effects, this will make
handling of effects identical to texture, much more general (and should get ride of the GraphicsSystem
current effect).
3.
Known bugs:
a. MeshArrow is not drawing correctly, I am not sure why yet.
b. After loading of texture, effect loading will fail. I
am not sure why.