CS 457/557 -- Winter Quarter 2024

Project #5

An Image Manipulation "Toolbox"

100 Points

Due: February 20


This page was last updated: January 14, 2024


Requirements:

  1. Manipulation of images plays a big role in computer graphics, especially in the world of shaders. In this project, you will create an image manipulation "toolbox". The tools in your toolbox will be fisheye, whirl, blend, and mosaic.

  2. Draw a quadrilateral, wth our usual 0.-1. 2D s,t texture coordinates. If you are using glman, the QuadXY will work nicely.

  3. Bring in 2 images as textures. Exactly what these are is up to you. The only thing you aren't allowed to do is use the images shown here.

  4. If you are using glman, your glib file could look something like this:
    ##OpenGL GLIB
    
    Ortho -1. 1.  -1. 1.
    
    LookAt  0. 0. 2.  0. 0. 0.  0. 1. 0.
    
    Texture2D  5	DogC.bmp
    Texture2D  6  	DogD.bmp
    
    Vertex	 	whirlfisheye.vert
    Fragment	whirlfisheye.frag
    Program 	WhirlFisheye			\
    	TexUnitA 5				\
    	TexUnitB 6				\
    	uPower <1. 1. 10.>			\
    	uRtheta <0. 0. 50.>			\
    	uMosaic <0.001 .001 .06>		\
    	uBlend <0. 0. 1.>
    
    QuadXY  0.1  1.
    

  5. uPower is the exponent in the fisheye equation

  6. uRtheta is the radius multiplier in the whirl equation

  7. uMosaic is the size in s and t to collapse into a single color

  8. uBlend is the blending factor to use when blending the two images

Top of Your Fragment Shader


#version 330 compatibility

uniform float uPower;
uniform float uRtheta;
uniform float uMosaic;
uniform float uBlend;
uniform sampler2D TexUnitA;
uniform sampler2D TexUnitB;

in vec2 vST;

const vec4 BLACK = vec4( 0., 0., 0., 1. );

float
atan2( float y, float x )
{
        if( x == 0. )
        {
                if( y >= 0. )
                        return  PI/2.;
                else
                        return -PI/2.;
        }
        return atan(y,x);
}

Fisheye


vec2 st = vST - vec2(0.5,0.5);  // put (0,0) in the middle so that the range is -0.5 to +0.5
float r = the length of st
float r' = (2r)uPower;

Whirl


float θ  = atan2( t, s );
float θ' = θ - uRtheta * r;

Restoring (s,t)


st = r' * vec2( cosθ',sinθ' );  		// now in the range -1. to +1.
st += ?;                        		// change the range to 0. to +2.
st *= ?; 		       			// change the range to 0. to +1.

Mosaic'ing


// which block of pixels will this pixel be in?
int numins = ???	// same as with the ellipses
int numint = ???	// same as with the ellipses
float sc = ???		// same as with the ellipses
float tc = ???		// same as with the ellipses
// for this block of pixels, we are only going to sample the texture at the center:
st.s = sc;
st.t = tc;

Blacking Out Parts of the Image That Don't Reach the Borders and Blending


// if s or t end up outside the range [0.,1.], paint the pixel black:
if( any( lessThan(st, vec2(?, ?)) ) )			// if s or t is < 0.
{
	gl_FragColor = BLACK;
}
else
{
	if( any( greaterThan(st, vec2(, ?)) ) )		// if s or t is > 1.
	{
		gl_FragColor = BLACK;
	}
	else
	{
		// sample both textures at (s,t) giving back two rgb vec3's:
		// mix the two rgb's using uBlend
		vec3 rgb1 = texture( ??, ?? ).rgb;
		vec3 rgb1 = texture( ??, ?? ).rgb;
		vec3 rgb = ?????
		gl_FragColor = vec4( rgb, 1. );
	}
}

The Turn-In Process:

  1. Your turnin will be done at http://teach.engr.oregonstate.edu 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 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 shows all 4 required features
    4. Be sure your video's protection is set to unlisted.
    5. Do not put your PDF into your zip file. Leave it out by itself so my collect-all-the-PDFs script can find it.

  2. Use 2 textures of your own for this project. The images need to be a 24-bit uncompressed BMP. (Photoshop or GIMP are good ways to do any conversion. I can also help you.)

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

My Original Images (You must use something else!)

 

My Processed Images

Fisheye Whirl Mosaic Blend

Grading:

FeaturePoints
Fisheye works25
Whirl works25
Mosaic works25
Blending works25
Potential Total100