Archive for January, 2018

CG programming for non-programmers, lesson 28

Wednesday, January 31st, 2018

In lesson 28 we go for a more painterly effect.

Fractal textures are very evocative. Once you start using them to mix different colors, you can get some really cool effects.

Here we are creating a more painterly sky, by using the cloud texture as a kind of procedural paint brush to evoke a sense of sunlight and shadow on a cloud covered day.

You can see this lesson by CLICKING HERE.

CG programming for non-programmers, lesson 27

Tuesday, January 30th, 2018

In lesson 27 we show a way to turn static clouds in to roiling clouds.

The trick is to drag the noise function through z over time, so that all of the levels of the fractal sum of noise end up animating over time. The effect is surprisingly convincing.

You can see this lesson by CLICKING HERE.

CG programming for non-programmers, lesson 26

Monday, January 29th, 2018

Once again, small changes to evoke nature can produce a very large impact on the visual result. In lesson 26 we make just a slight modification to our fractal texture: We use it to mix together a sky blue and a white cloud cover.

Just as in painting, the choice of color palette is very important. But why take my word for it? Try playing with various values of vec3(RED,GREEN,BLUE) to explore the possibilities.

You can see this lesson by CLICKING HERE.

CG programming for non-programmers, lesson 25

Sunday, January 28th, 2018

The noise function doesn’t really do all that much by itself. It’s when you use it in creative ways that things really start happening. And that is just what we do in lesson 25.

For example, a single frequency of noise looks kind of boring: It creates textures of just one size. But if you scale the argument to the noise function, that will change the frequency of the resulting texture. The more you scale up the argument, the higher frequency will be the result, and the finer will be the resulting texture.

Just like mixing musical notes of different frequencies to create chords, we can mix different frequencies of noise to create more interesting textures. For example, by summing together octaves** of noise we can create fractal-like textures.

You can see this lesson by CLICKING HERE.

** An “octave” in music is a power of two in frequency. For example, the A below middle C on a piano keyboard is a sound that vibrates 440 times per second. The next higher A on the piano — one octave higher — is a sound that vibrates 880 times per second. So for every successive octave, frequency doubles. We use the word “octave” in exactly the same way, except that we apply it to visual texture. For example, if we vary a wiggly texture so that it wiggles twice as many times across the screen, we say that the frequency of the new texture is one octave higher.

CG programming for non-programmers, lesson 24

Saturday, January 27th, 2018

Sometimes values only make sense within a certain range. For example, in an election it doesn’t make sense, when talking about voters, to speak of fewer than zero percent, or more than one hundred percent.

Similarly, when we mix two things, it often doesn’t make sense to talk about a mix parameter of less than zero, or greater than one.

For such reasons, it is often useful to clamp a value to some useful range. In lesson 24 we introduce the clamp(value,lo,hi) function, which makes sure that value can’t be lower than lo or higher than hi.

In this case, we are applying the clamp function to control the gradation in fog thickness from the top to the bottom of our image. We want to have lighter fog at the top of the image, and heavier fog at the bottom.

But we still want to mix in a sensible quantity of fog. And in this case, “sensible” means the mixing parameter needs to be between 0.0 and 1.0.

You can see this lesson by CLICKING HERE.

CG programming for non-programmers, lesson 23

Friday, January 26th, 2018

For lesson 23 we learn how to mix colors. Actually, we can use it to mix pretty much anything. We are just using color as an example.

The mix(a,b,t) function uses its third argument t to create a mixture of a and b. When t is 0.0 the result is a. When t is 1.0 the result is b. When t is anything in between we get a mixture of a and b.

Here we are using it to create a mysterious fog cover over our moon at night. The shape of the fog cover is created by a noise texture, and the value of that noise texture is controlled by x, y, z and uTime. The use of uTime in defining the noise texture is what makes the fog animate.

You can see this lesson by CLICKING HERE.


Thursday, January 25th, 2018

After 22 straight posts about computer graphics for non-programmers, it seems like a good idea to take a deep breath before plunging back in. Consider this an intermission.

Coincidentally, this is my first week of the semester teaching undergraduate computer graphics, and I am about to cover much the same material — albeit for students who have already been programming for at least a few years. Their prior programming experience will allow me to cover a lot more ground, so it’s not quite the same thing.

Meanwhile, I’ve been grappling with the question of how to write a really great story for immersive virtual reality. I have seen quite a few VR pieces by now, but to my mind none of them has been completely successful on the fundamental level of narrative storytelling.

I guess I’m taking that as a challenge. Wish me luck! :-)

CG programming for non-programmers, lesson 22

Wednesday, January 24th, 2018

For lesson 22 we make just a few small changes from lesson 20, but the resulting visual difference is dramatic.

We throw some of our handy noise function onto the sphere, tint our sphere ever so slightly yellow, and place it all over a deep blue background.

Suddenly we see not a mathematical sphere, but a moon in the night sky.

You can see this lesson by CLICKING HERE.

CG programming for non-programmers, lesson 21

Tuesday, January 23rd, 2018

Sometimes other people come up with cool shader ideas and all I can say is “wow, totally awesome.”

In his comment on yesterday’s lesson, Sam Umbach came up with such an idea, and posted the code in his comment.

So for lesson 21 I am just going to stand back and share his work with the rest of you. Hopefully others will be inspired to create their own interesting shader ideas.

You can see this lesson by CLICKING HERE.

CG programming for non-programmers, lesson 20

Monday, January 22nd, 2018

In lesson 20 we finally move from 2D graphics to 3D graphics. Specifically we go from flat disks to spheres.

To do this we just use some high school math. For a sphere of radius r, you probably learned in high school that for any point (x,y,z) on the sphere surface the following is true:

      x2 + y2 + z2 = r2

From there it is pretty easy to show that if you already know x,y and r, you can find z by:

      z = sqrt(r2 - x2 - y2)

We use this formula to create a sphere, which we will do cool things with in coming lessons.

You can see this lesson by CLICKING HERE.