main-practice3

Practice Program 3 - Shaders and Textures

There was a bug in the sample code. It has been fixed. If you get the version dated 11/23, you’ll be OK.

Please put “practice 3” as the subject line in your email to the TA (don’t worry about this if you’ve already sent the email).

For the final project, you are going to need to be able to use textures and shaders.

In order to use textures or shaders, you both need to understand them, as well as be able to deal with all of the program mechanics involved in using them in an OpenGL program. We’ll make the latter part easier for you (if you want) by providing libraries that make it easy to load shaders and textures.

Before the project, we want to make sure that everyone can get shaders and textures to work. Once you understand the mechanics, you can focus on making effective use of texture and shaders in your project.

So, for this practice assignment, you need to create a program that

  1. loads in a texture from a file and displays it on a 3D object
  2. loads in a vertex and fragment shader and displays it on a 3D object

We don’t care what the texture is, what the object is, how boring things are. Just that you are able to get a program like this to compile and run.

In fact, we’ll even give you a solution. In this zip file, there’s a program that satisfies the requirements. All you need to do is download it, compile it, and run it. Its a good idea if you try to understand how the texture manager code works and how the shader manager code works - maybe even try to make a simple shader or two yourself.

All you need to do for this assignment is to send email to the TA saying “I completed Practice Assignment 3” and you’ll get credit. Its totally honor system. If you do something cooler than just run my program (like writing an interesting shader), feel free to attach a picture to the email.

This assignment is due on November 25th. Please do it before you take off for Thanksgiving.

Some advice on Shaders

You can just write shaders in a text editor and try them out with my sample program. However, we recommend that you try using a Shader IDE like RenderMonkey (see below) or ShaderDesigner since it can make shader development easier. Also, it will give you lots of example shaders to look at and learn from.

We are trying to get ShaderDesigner Installed on the CSL Windows machines. This should happen soon.

Note: if you want to write your shaders in a language other than GLSL, you’re kindof on your own. And you’ll need to figure out how to make a program use them. And the shading languages are very similar: there isn’t enough difference between GLSL and HLSL or Cg (as far as doing things for this class)

For this assignment, we don’t care too much what your shader does. A good first thing to try: make a pattern (like a checkerboard) that is properly affected by the light.

Chapter 15 of the OpenGL red book gives a good introduction to GLSL. (if you don’t have a 6th edition red book, a scan of Chapter 15 is in p:/course/cs559-gleicher/public/Readings). We’ll also provide Appendix I of the Redbook (also in the readings directory and Learn@UW) which is a reference for GLSL.

You’ll probably want to look at example programs / web tutorials. Here are some that I’ve found (if you find others that you think are good, let us know)

Here’s a note on doing anti-aliasing in shaders. Mainly recommended since its yet another example of how to write a shader.http://www.cs.wisc.edu/graphics/Courses/559-f2008/Main/ShaderAntiAliasing

Some notes on the Shader Manager

Its really simple. It prints errors to the console, so make sure you look at the console window if things go wrong.

RenderMonkey

ShaderDesigner is an open source alternative to rendermoney. I have no first hand experience with it. If you try it, let me know if its any good.

RenderMonkey is an IDE (integrated development environment) for writing shaders. It has a text editor, an integrated compiler, and a preview window. It makes it easier to experiment with shaders - all you need to do is write the shader code, and RenderMonkey lets you experiment with different geometry easily. It also lets you control the parameters of the shader (like colors) interactively.

There are other shader IDEs, many of which seem to have better features. But the reason we’re recommending RenderMonkey is that 1) its free, and 2) it supports GLSL. It also comes with a library of examples to look at.

On the down side, there have been stability problems in the past, and it doesn’t have lots of features to help you write the shaders.

RenderMonkey is installed on the CSL Windows machines. You can download a copy for your own computer from http://developer.amd.com/gpu/rendermonkey/Pages/default.aspx. Even though RenderMonkey comes from ATI (now part of AMD), it seems to work fine on NVidia hardware.

We had some advice on getting started with RenderMonkey on last spring’s course web.

Note: you don’t have to use RenderMonkey. In fact, even if you use rendermonkey, eventually you will need to copy your shader code into your own OpenGL program.

Page last modified on November 23, 2009, at 04:50 PM