CS 455 Lecture 22 – Applying Noise
Agenda
- what ?s
- last homework
- compute this
- generating noise
- wood and marble
- fog
Compute This
Suppose you’ve got three numbers. You want to weight and sum them. The 0th should be weighted half as much as the 1st. The 1st should be weighted half as much as the 2nd. What are the weights?
Suppose you’ve got n numbers. You want to weight and sum them. The 0th should be weighted half as much as the 1st. The 1st should be weighted half as much as the 2nd. And so on. What are the weights?
TODO
As a lab exercise:
- Your task is to color the plane in our scene with a moving fog texture.
- Sync with the class repository to get the
noise
project. - Switch from the
noise.*.glsl
shaders to thefog.*.glsl
shaders. - Generate a volume of noise instead of a slice. Use the
Field3
class, a 3D texture (which needs one further parameter to itsUpload
call), and asampler3D
. - Retrieve the grayscale intensity from the fog volume in the fragment shader. You’ll need 3D texture coordinates to sample a 3D texture. Where do you get them? The plane’s 2D texture coordinates provide two. For the third, let’s use a
time
uniform. As time progresses, we will draw the fog out from different planes of our 3D texture. - In
OnDraw
, upload the time uniform such that it increases as our application executes. What do you notice? - When you are satisfied with the advancement of the texture, let’s make the fog transparent. Hug your drawing of the plane with these commands:
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glEnable(GL_BLEND); ... glDisable(GL_BLEND);
In your fragment shader, set the fragment’s color opacity (it’s
a
channel) to the fog intensity. How does this look? - You might find it helpful to push the fog to the background like we did with the skybox. In the vertex shader, add:
gl_Position.z = gl_Position.w;
- What can you do to make the fog thicker? More immersive?
- Send me a screenshot of your foggy plane.