Docsity

Introduction to Computer Graphics Assignment 11: Shader Manipulation - Prof. Christopher W, Assignments of Computer Graphics

Toggle sidebar
bg1
Fall 2007
22C:151 Introduction to Computer Graphics
Assignment 11
Due: Friday December 14th at 11:59pm
Goal: Experiment with OpenGL’s GLSL vertex and fragment shaders.
Download a copy of my shader “template” programs. Hopefully you should be able to compile it out of the box
using the README instructions. However as long as the included executable works, you can finish this assignment.
You do not need a compiler for this assignment, simply a text editor!
For Problem 1, you will be modifying the two shaders “test.vert.glsl” and “test.frag.glsl” that come with the shader
template #1. For Problem 2, you will be modifying the shaders (with the same names) that come with shader template
#2. Since the precompiled executables load these files, your shaders for this assignment must have the same filename
(unless you change the C++ code to look in a different location)!
Note: These programs “intelligently” select the GL window resolution, so your program may either run at 5122
or 10242, depending on your screen resolution. All images were captured at 5122– Moir´
e patterns will take longer to
appear at 10242.
The two problems (each worth 10 points) are separated out on the following two pages.
Make sure you read the README that comes with the program (and/or source) if you have problems running the
program!
(Also, if the shaders included with the template include the line “#version 120” you may remove that line – that
was why my shaders did not work on my laptop in class. These shaders only need GLSL v1.0, not GLSL v1.2.)
pf3
pf4

Partial preview of the text

Download Introduction to Computer Graphics Assignment 11: Shader Manipulation - Prof. Christopher W and more Assignments Computer Graphics in PDF only on Docsity!

Fall 2007

22C:151 Introduction to Computer Graphics

Assignment 11

Due: Friday December 14th at 11:59pm

Goal: Experiment with OpenGL’s GLSL vertex and fragment shaders.

Download a copy of my shader “template” programs. Hopefully you should be able to compile it out of the box

using the README instructions. However as long as the included executable works, you can finish this assignment.

You do not need a compiler for this assignment, simply a text editor!

For Problem 1, you will be modifying the two shaders “test.vert.glsl” and “test.frag.glsl” that come with the shader

template #1. For Problem 2, you will be modifying the shaders (with the same names) that come with shader template

#2. Since the precompiled executables load these files, your shaders for this assignment must have the same filename

(unless you change the C++ code to look in a different location)!

Note: These programs “intelligently” select the GL window resolution, so your program may either run at 5122

or 10242 , depending on your screen resolution. All images were captured at 5122 – Moir´e patterns will take longer to

appear at 10242.

The two problems (each worth 10 points) are separated out on the following two pages.

Make sure you read the README that comes with the program (and/or source) if you have problems running the

program!

(Also, if the shaders included with the template include the line “#version 120” you may remove that line – that

was why my shaders did not work on my laptop in class. These shaders only need GLSL v1.0, not GLSL v1.2.)

Problem 1 (10 points): Modify Shader Template #1 to exhibit the following behavior.

Part A (5 points): Compute the color in a fragment shader using the sinusoidal function:

outputcolor = 0. 5 ∗ (1 + sin(val ∗ x^2 + val ∗ y^2 )). (1)

Use the fragment’s texture coordinate (“gl TexCoord[0].xy”) for the x and y values and val is passed in as the uniform parameter “scaleValue” (i.e. you can access it via “scaleValue.x”), which can change via the ’+’ and ’-’ keys when running the program. This should look like the following two examples (for val = 20 and 300.5, respectively).

Part B (5 points): Now that you can see some cool Moir´e effects on your quadrilateral, lets move the vertices around a bit in the vertex shader. Notice in the OpenGL program, that the one big quad in this program is actually made up of 400 smaller quads. For this problem, we’re going to use the vertex shader to manipulate the location of these quad vertices before the quads are rasterized !! This means, you’ll be changing the displayed geometry without recompiling the program. Based on the uniform parameter “theTime” passed to the vertex shader, change the location of the vertex as follows:

newObjSpaceP osx = oldObjSpaceP osx (2) newObjSpaceP osy = oldObjSpaceP osy (3) newObjSpaceP osz = oldObjSpaceP osz + 5 ∗ theT ime^2 ∗ (oldObjSpaceP os^2 x + oldObjSpaceP os^2 y ) (4)

  • Remember, two things you must do in your vertex shader are: (1) Transform your new object space position into clip coordinates (using the combined modelview/projection matrix) and (2) Pass down your input texture coordinates so your new fragment shader for Part A will have access to them.
  • The results of this change are subtle – in fact you will not notice a difference when you first run your program. To see these changing vertex locations, you need to rotate your quad (using the left mouse button), and should see something that changes over time similar to this:

Extra Credit (Up To 5 points): Modify either the Shader Template #1 or #2 to create an “interesting” result. This

result should change as a light moves around the scene. You may with to modify the OpenGL program to pass

additional information down to the shader to facilitate increased “coolness.” The number of points received will

depend on the coolness of your result. Note that this is probably harder than the rest of the entire assignment,

but is here to reward those people who think shaders are neat and want to put more time into understanding them.

(Alternatively, you can modify your existing OpenGL program instead of modifying my template.)

Make sure to update your web page with images of this assignment!!