CS 457/557 -- Winter Quarter 2017

Project #3

Interactive Noisy Elliptical Polka-dots

100 Points

Due: February 7


This page was last updated: January 30, 2017


Requirements:

  1. The goal of this project is to beat the elliptical shader thing to death, but this time make it interactive using the OpenGL Shading Language and glman.

  2. Create a GLIB file that produces parameter sliders for:

    ParameterWhat It Does
    uAdEllipse diameter #1
    uBdEllipse diameter #2
    uNoiseAmpNoise Amplitude
    uNoiseFreqNoise Frequency
    uTolWidth of the blend between ellipse and non-ellipse areas

    The .glib file, including the Extra Credit parameters, 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.>      	 \
            uAlpha <0. 1. 1.>                                        \
            uTol <0. 0. 1.>
    
    
    Color 1. .9 0
    Sphere
    

  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.

    uTol

  7. You can have as many other slider-based 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 a Fragment Shader program. (No texture images.)

  10. 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 of .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 the signature object, get the salmon file, salmon_low.obj, here. Include it in your GLIB file like this:
Obj salmon_low.obj

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.

ParameterWhat It Does
uAlphaOpacity of non-ellipse areas

uAlpha

Extra Credit #2 (+5 points)

Add a ChromaDepth feature that colors the scene by eye coordinate depth: Red in the front, Blue in the back, and Green in the middle. Include a checkbox called uUseChromaDepth which turns ChromaDepth on and off.

Glasses are on the front table in the CGEL. Feel free to keep a pair.

uChromaRed and uChromaBlue are meant to be the Z depths in eye coordinates at which the ChromaDepth color interpolation starts and ends.

I'd recommend putting them both on sliders, so that you can play with the values. Remember that, in eye coordinates, the eye is at the origin looking in -Z. Thus, uChromaRed and uChromaBlue need to be negative.

Checkboxes are added to the glman user interface like this:

. . . uUseChromaDepth <false> . . .

and are used in the shader program as:

uniform bool uUseChromaDepth;

. . .

	if( uUseChromaDepth )
	{
		float t = (2./3.) * ( Z - uChromaRed ) / ( uChromaBlue - uChromaRed );
		t = clamp( t, 0., 2./3. );
		TheColor = ChromaDepth( t );
	}
	else
	{
		. . .
	}

ChromaDepth

If you normalize a distance t so that it is t=0. in the front of the object and t=.667 in the back, here is code to assign the colors. (It is actually just the hue-only part of the rainbow color scale.)


vec3
Rainbow( float t )
{
	t = clamp( t, 0., 1. );

	float r = 1.;
	float g = 0.0;
	float b = 1.  -  6. * ( t - (5./6.) );

        if( t <= (5./6.) )
        {
                r = 6. * ( t - (4./6.) );
                g = 0.;
                b = 1.;
        }

        if( t <= (4./6.) )
        {
                r = 0.;
                g = 1.  -  6. * ( t - (3./6.) );
                b = 1.;
        }

        if( t <= (3./6.) )
        {
                r = 0.;
                g = 1.;
                b = 6. * ( t - (2./6.) );
        }

        if( t <= (2./6.) )
        {
                r = 1.  -  6. * ( t - (1./6.) );
                g = 1.;
                b = 0.;
        }

        if( t <= (1./6.) )
        {
                r = 1.;
                g = 6. * t;
        }

	return vec3( r, g, b );
}

Note that this code implements the full (H,S=1.,V=1.) to (R,G,B) conversion. You need to keep t between 0. and (2./3.) because you are only interested in the Red-Green-Blue color range. This code is good to keep around. There are lots of good visualization uses for it too.

Letting Me Know to Test the Extra Credit(s)

It would be a big help to me if you would use the GLIB MessageBox command to let me know if you have implemented an Extra Credit. For example:

MessageBox This implements the Alpha extra credit

Hints:

The Turn-In Process:

  1. Your turnin will be done at http://engr.oregonstate.edu/teach and will consist of:
    1. All source files (.glib, .vert, .frag)
    2. Your PDF report describing what you did, why it works, and all of your images.
    3. If you did the Extra Credit, then also include images exhibiting changes in uAlpha.

    Do not zip up any of these files. Leave them all out separately.

    Also, name your .vert and .frag files with some variation of your name or login.

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

  2. Your PDF turnin will consist of:
    1. A cover page (name, Project #3)
    2. Source listings (.glib, .vert, .frag)
    3. A prose explanation of what you did and why it worked. (Your submission will not be considered valid unless you can explain why it works.)
    4. One or more color images showing what your results were

    Grading:

    FeaturePoints
    Correct changes in uAd and uBd20
    Correct changes in uNoiseAmp30
    Correct changes in uNoiseFreq30
    Correct changes in uTol20
    EC #1: Correct changes in uAlpha5
    EC #2: Correct ChromaDepth5
    Potential Total110