0% found this document useful (0 votes)
9 views

A2

The assignment involves implementing shadowing using a multipass shader with two passes: the first pass computes a shadow map from the light's viewpoint, while the second pass determines fragment illumination based on shadow presence. Students are required to edit four shader files and follow a specific sequence of tasks to visualize the scene and shadows. The final submission must include the shader files, a README, and a screenshot of the output, all organized in a designated directory.

Uploaded by

jingxue07
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views

A2

The assignment involves implementing shadowing using a multipass shader with two passes: the first pass computes a shadow map from the light's viewpoint, while the second pass determines fragment illumination based on shadow presence. Students are required to edit four shader files and follow a specific sequence of tasks to visualize the scene and shadows. The final submission must include the shader files, a README, and a screenshot of the output, all organized in a designated directory.

Uploaded by

jingxue07
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 3

CISC/CMPE 454 Assignment 2

Due March 3 before class

Your task is to do shadowing using a multipass shader. The first pass


computes the shadow map. The second pass determines whether a
fragment is in shadow and renders it accordingly.

- In pass 1, the objects are rendered from the point of view of the
light source and a 'shadowTexture' is used to store the depth (in
the light's CCS transformed to the range [0,1]) of each fragment.

- In pass 2, the objects are rendered from the viewpoint. Each


fragment is provided with its coordinates in the WCS. The fragment
shader transforms those WCS coordinates into the light's CCS using
a WCS-to-lightCCS transformation (provided). Then the depth of the
transformed fragment is compared to the depth in the shadow texture
corresponding to that point in the light's CCS.

The fragment is given reduced illumination if it is in shadow.

The shadow depth is stored in a 'shadowTexture' texture. The texture


has the same dimensions as the window, so there's a one-to-one
correspondence between texels in the texture map and pixels in the
window.

You do not need to edit or compile any C++ code. You need only to
edit four shader files: a vertex shader and a fragment shader for each
of the two passes.

Step 0

This is best done on the CasLab Linux machines. Compile the code,
then run it as

./shader data/carpet.obj data/triceratops.obj data/apple.obj

The program should show an empty window with a coordinate system and
a rotating line (which points to the light source).

If working on Windows, go in to the a2_windows folder and run


shader.exe from there.

Important Note

You should NOT do the following in the order given. Rather, get some
output on the screen first, then incrementally change the code and
test each change by drawing the intermediate results to the screen.

For example, first get the objects drawn. You can ignore the Pass 1
shaders and get the Pass 2 vertex shader to compute *only*
gl_Position. Then get the Pass 2 fragment shader to *only* output
an arbitrary colour. Once this is done, you'll see an approximation
of the scene.

You might then, for example, add diffuse illumination by computing


the normals in the vertex shader and using it in the fragment
shader. Once this is done, you'll see pretty good approximation of
the scene.
Then you might add texturing. Once things are working and you're
more familiar with the operation of your shaders, you could consider
generating the Pass 1 shadow texture.

Note that much of the work (e.g. Phong illumination and texture
colour lookup) can be done independently of the shadowing.

Pass 1

The pass 1 shaders are used when the scene is rendered from the
light's viewpoint, using orthographic projection because the light
is directional. (A point light source would use perspective
projection.) See 'render' in renderer.cpp for the details.

[1 mark] Edit pass1.vert to compute the vertex's position in the


light's CCS.

[1 mark] Then compute the vertex's depth in the light's CCS, and
convert this to the range [0,1] and pass that value to the fragment
shader.

You do not have to modify pass1.frag, as it simply copies the


(interpolated) depth value into the shadow texture.

After this step, you should be able to press 'd' (for debug) and see
the red shadow map. Press 'd' again to see the normal view.

Pass 2 vertex shader

The pass 2 shaders are used when the scene is rendered from the
eye's viewpoint, using perspective projection.

Edit pass2.vert:

[1 mark] Compute the vertex's position in the eye's CCS.

[1 mark] Set the vertex colour based on the object's diffuse


illumination coefficient. You'll have to see how this is done in
'setMaterial' in wavefront.cpp and use the 'uniform' value that is
defined there.

[1 mark] Compute the vertex's normal in the WCS.

[1 mark] Compute the vertex's position in the WCS.

Pass 2 fragment shader

Edit pass2.frag:

[1 mark] Compute the fragment position in the light's CCS.

[1 mark] Using the above result, compute the fragment's depth


(in [0,1]).

[2 marks] Compute the fragment's xy position in the light's CCS


(in [0,1]x[0,1]) and use this to look up the depth from the shadow
buffer.

[1 mark] If the fragment is in shadow, attenuate its intensity.


Reduce the streaky artifacts if any appear.

[1 mark] Use the texture colour (if texturing) or the colour from
the vertex shader (if not texturing).

[1 mark] Apply Phong illumination (but get it working with diffuse


first).

To Hand In

Make a directory called 'a2'. In that directory, put

- your FOUR shader files

- a README file with your name(s), student number(s) again, and


email address(es)

- one screen captured image of your program output, showing shadows.

- DO NOT INCLUDE ANY OTHER FILES. YOUR a2 DIRECTORY SHOULD


CONTAIN EXACTLY 6 FILES. YOU WILL LOSE MARKS OTHERWISE.

Create a ZIP archive of the a2 directory and email it to [email protected].

You might also like