CS 457/557 -- Winter Quarter 2024

Project #7A

Geometry Shaders: Turning a Polygonal Model into a Collection of Spheres

100 Points

Due: March 8


This page was last updated: February 27, 2024

There is an alternative Project #7 for the mac users who do not have access to a system capable of doing Geometry Shaders. If you are able to use Geometry Shaders, you are required to do this one.


Introduction:

The word "quantize" means to take something that is continuous, and give it discrete (fixed) locations instead. Some programs refer to this as "snapping".

In this project, we are going to take the triangles of a polygonal object, compute their centroid, quantize the location of that centroid, and then bend the triangle vertices around that centroid in a partial sphere. You will add more vertices to each triangle using the triangle interpolation (like in the sphere subdivision shader).

Requirements:

  1. Your input needs to be an OBJ file of your own choosing. This time it will be OK if the OBJ file doesn't have normals or texture coordinates.

  2. Have a uLevel uniform variable that controls the number of levels of triangle subdivision.

  3. Have a uQuantize uniform variable that controls the quantization equation (see below).

Entire Dragon Zoomed-in Detail

Hints

Extra Credit (+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 an option which turns the use of ChromaDepth on and off.

I have glasses which will use the ChromaDepth colors to make your scene look really 3D, although you (and we) will know if it is working without having the glasses. Please do not touch the plastic lenses on the glasses. Human fingerprints are nearly impossible to get off them.

uRedDepth and uBlueDepth are meant to be the Z depths in eye coordinates at which the ChromaDepth color interpolation starts and ends. You can make these variable, or you can hardcode them if you find good values for them.


// in the geometry shader:
out float	gZ;
. . .
	gZ = -ECposition.z;


// in the fragment shader:
in float                gZ;
. . .
vec3
Rainbow( float t )
{
        t = clamp( t, 0., 1. );         // 0.00 is red, 0.33 is green, 0.67 is blue

        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 );
}

. . .

        vec3 myColor = ?????
        vec3 mySpecularColor = vec3( 1.0, 1.0, 1.0 );

        if( uUseChromaDepth )
        {
                float t = (2./3.) * ( abs(gZ) - uRedDepth ) / ( uBlueDepth - uRedDepth );
                t = clamp( t, 0., 2./3. );
                myColor = Rainbow( t );
        }

If you want to see more ChromaDepth examples, click here.

The Turn-In Process:

Your turnin will be done at http://teach.engr.oregonstate.edu and will consist of:
  1. All source files (.cpp, .glib, .vert, .geom, .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 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.

Be sure that your PDF file is turned-in separately (not part of a .zip file).

Grading:

FeaturePoints
uLevel correctly subdivides each triangle20
uQuantize correctly quantizes the centroid of each triangle20
The vertices created by the triangle subdivision form a partial sphere using uDiam40
Per-fragment lighting works correctly20
Extra Credit5
Potential Total105

Be sure that your video demonstrates all the features that you want credit for.