CS 457/557 -- Winter Quarter 2023

Project #2

Noisy Elliptical Dots

100 Points

Due: January 28

This page was last updated: January 24, 2023

If You Are Using the API and Want to Do the Extra Credit, You Need to Enable Transparency (Blending) Like This:

glEnable( GL_BLEND );
Pattern->Use( );

<< set uniform variables and draw your object >>

Pattern->Use( 0 );
glDisable( GL_BLEND );


  1. Using a GLIB file (for glman) or using the GLSL API, be able to vary the following parameters:

    ParameterWhat It Does
    uAdEllipse diameter for s
    uBdEllipse diameter for t
    uNoiseAmpNoise Amplitude
    uNoiseFreqNoise Frequency
    uTolWidth of the blend between ellipse and non-ellipse areas
    uAlphaAlpha value for the areas outside the ellipses

    The .glib file, including the Extra Credit parameter, might look like this:

    ##OpenGL GLIB
    LookAt  0 0 3  0 0 0  0 1 0
    Perspective 70
    Vertex   ovalnoise.vert
    Fragment ovalnoise.frag
    Program  OvalNoise                                              \
            uAd <.01 .05 .5>  uBd <.01 .05 .5>                      \
            uNoiseAmp <0. 0. 1.>  uNoiseFreq <0. 1. 10.>      	\
            uTol <0. 0. 1.>						\
            uAlpha <0. 1. 1.> 
    Color 1. .9 0

  2. Remember that the border of an ellipse, defined in s and t coordinates is:
    d = (s-sc)2 / Ar2 + (t-tc)2 / Br2 = 1

  3. The NoiseFreq parameter is the frequency of the noise function, i.e., it multiplies what goes into the noise function.

  4. The NoiseAmp parameter is the amplitude of the noise function, i.e., it multiplies the noise value.

  5. The effects of the NoiseAmp and NoiseFreq parameters should look something like this:
      NoiseAmp NoiseFreq

  6. The uTol parameter is the width of a smoothstep( ) blend between the ellipse and non-ellipse areas, thus smoothing the abrupt color transition.

    float t = smoothstep( 1. - uTol, 1. + uTol, d );
    Then use t in the mix function.


  7. You can have as many other uniform variables as you wish.

  8. Apply lighting. The easiest way to do this would be to just use diffuse in per-vertex lighting, looking at the cosine of the angle between the surface normal and the vector to the light source:

    out float	vLightIntensity;
    const vec3 LIGHTPOS   = vec3( -2., 0., 10. );
       . . .
    vec3 tnorm      = normalize( gl_NormalMatrix * gl_Normal );	// transformed normal
    vec3 ECposition = ( gl_ModelViewMatrix * gl_Vertex ).xyz;
    vLightIntensity  = abs(  dot( normalize(LIGHTPOS - ECposition), tnorm )  );

    Of course, you can make this as sophisticated as you want, including interpolating the transformed normal through the rasterizer and using per-fragment lighting.

  9. The ellipses must be created procedurally, i.e., with equations in the Fragment Shader program. (No texture images.)

  10. As we discussed in class, get a noise value based on the current fragment's model coordinates. Use all 4 octaves available. Then use that value to alter the ds and dt values. Then use those new ds and dt values to determine the correct color to use.
    // read the glman 2D noise texture (if using s,t or the 3D noise texture if using x,y,z:
    uniform sampler2D Noise2;
    . . .
    vec4 nv  = texture2D( Noise2, uNoiseFreq*vST );
    ------------  or  ---------------
    uniform sampler3D Noise3;
    . . .
    vec4 nv  = texture3D( Noise3, uNoiseFreq*vMCposition );
    // give the noise a range of [-1.,+1.]:
    float n = nv.r + nv.g + nv.b + nv.a;    //  1. -> 3.
    n = n - 2.;                             // -1. -> 1.
    n *= uNoiseAmp;
    // determine the color based on the noise-modified (s,t):
    float sc = float(numins) * uAd  +  Ar;
    float ds = vST.s - sc;                   // wrt ellipse center
    float tc = float(numint) * uBd  +  Br;
    float dt = vST.t - tc;                   // wrt ellipse center
    float oldDist = sqrt( ds*ds + dt*dt );
    float newDist = oldDist + n;
    float scale = newDist / oldDist;        // this could be < 1., = 1., or > 1.
    << scale ds and dt >>
    << divide them by Ar and Br, respectively >>
    << compute d by squaring those quantities and adding them together >>
    << use d in the smoothstep( ) function just like before >>

  11. The choice of geometry is up to you. You are allowed to contrive the size to make it work.

Using Objects Other Than A Sphere

You can try this with any solid objects you want. However, be aware that not all solid objects have built-in s-t (texture) coordinates. In glman, the sphere, torus, and teapot have them. The others don't. (Blame this on GLUT.) Many of the hundreds (thousands) of free .obj files available on the net have them. (You can check this by editing the .obj file and ensuring that there are lines beginning with "vt".) Also, be aware that not all .obj objects have built-in surface normals (nx,ny,nz). You can check this by editing the .obj file and ensuring that there are lines beginning with "vn".

If you want to use an OBJ object in glman, download it and include it in your GLIB file like this:
Obj spaceship.obj

Or use an OBJ file in your C/C++ file by including the file loadobjfile.cpp into your own code. Then, place the .obj object into a display list:

// a global variable:
GLuint DL;

. . .

// do this in InitLists( ):
DL = glGenLists( 1 );
glNewList( DL, GL_COMPILE );
LoadObjFile( "spaceship.obj" );
glEndList( );

. . .

// and do this in Display( ):
Pattern->Use( );
. . .
glCallList( DL );
Pattern->Use( 0 );

Extra Credit (+5 points)

Add uniform variable uAlpha that changes the opacity of the non-ellipse areas. When uAlpha == 0., do a discard instead of setting alpha.

Be sure to show the Extra Credit in your video!


The Turn-In Process:

Your turnin will be done at http://engr.oregonstate.edu/teach and will consist of:

  1. All source files (.cpp, .glib, .vert, .frag). You can zip this all together if you want.
  2. A PDF report with a title, your name, your email address, nice screen shots from your program, and the link to the Kaltura video or YouTube video demonstrating that your project does what the requirements ask for. Narrate your video so that you can tell us what it is doing.
  3. Be sure your video's protection is set to unlisted.
  4. Do not put your PDF into your zip file. Leave it out separately so my collect-all-the-PDFs script can find it.

Submissions are due at 23:59:59 on the listed due date.


Show correct changes in uAd and uBd20
Show correct changes in uNoiseAmp30
Show correct changes in uNoiseFreq30
Show correct changes in uTol20
EC: Show correct changes in uAlpha5
Potential Total105