This page was last updated: January 24, 2023
glEnable( GL_BLEND ); glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA ); Pattern->Use( ); << set uniform variables and draw your object >> Pattern->Use( 0 ); glDisable( GL_BLEND );
|Parameter||What It Does|
|uAd||Ellipse diameter for s|
|uBd||Ellipse diameter for t|
|uTol||Width of the blend between ellipse and non-ellipse areas|
|uAlpha||Alpha value for the areas outside the ellipses|
The .glib file, including the Extra Credit parameter, might look like this:
LookAt 0 0 3 0 0 0 0 1 0
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
float t = smoothstep( 1. - uTol, 1. + uTol, d );Then use t in the mix function.
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.
// 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 >>
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:
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:
. . .
// do this in InitLists( ):
DL = glGenLists( 1 );
glNewList( DL, GL_COMPILE );
LoadObjFile( "spaceship.obj" );
. . .
// and do this in Display( ):
. . .
glCallList( DL );
Pattern->Use( 0 );
Add uniform variable uAlpha that changes the opacity of the non-ellipse areas. When uAlpha == 0., do a discard instead of setting alpha.
Your turnin will be done at http://engr.oregonstate.edu/teach and will consist of:
Submissions are due at 23:59:59 on the listed due date.
|Show correct changes in uAd and uBd||20|
|Show correct changes in uNoiseAmp||30|
|Show correct changes in uNoiseFreq||30|
|Show correct changes in uTol||20|
|EC: Show correct changes in uAlpha||5|