This page was last updated: January 19, 2024
A glman .glib file might look like this:
##OpenGL GLIB
Perspective 90
LookAt 0 0 2 0 0 0 0 1 0
Vertex oval.vert
Fragment oval.frag
Program Oval \
uAd <.001 .1 .5> \
uBd <.001 .1 .5> \
uTol <0. 0. 1.>
Color 1. .9 0
Sphere 1 50 50
This will produce sliders for
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 |
// a defined value: const int MSEC = 10000; // 10000 milliseconds = 10 seconds // a global: Keytimes Ad; // in InitGraphics( ): Ad.Init( ); Ad.AddTimeValue( 0.0, ????? ); Ad.AddTimeValue( 2.0, ????? ); Ad.AddTimeValue( 5.0, ????? ); Ad.AddTimeValue( 8.0, ????? ); Ad.AddTimeValue( 10.0, ????? ); // in Animate( ): glutSetWindow( MainWindow ); glutPostRedisplay( ); // in Display( ): // turn # msec into the cycle ( 0 - MSEC-1 ): int msec = glutGet( GLUT_ELAPSED_TIME ) % MSEC; // turn that into a time in seconds: float nowTime = (float)msec / 1000.; . . . Pattern.SetUniformVariable( "uAd", Ad.GetValue( nowTime ) ); . . .
#version 330 compatibility out vec2 vST; // texture coords out vec3 vN; // normal vector out vec3 vL; // vector from point to light out vec3 vE; // vector from point to eye out vec3 vMCposition; const vec3 LIGHTPOSITION = vec3( 5., 5., 0. ); void main( ) { vST = gl_MultiTexCoord0.st; vMCposition = gl_Vertex.xyz; vec4 ECposition = gl_ModelViewMatrix * gl_Vertex; // eye coordinate position vN = normalize( gl_NormalMatrix * gl_Normal ); // normal vector vL = LIGHTPOSITION - ECposition.xyz; // vector from the point to the light position vE = vec3( 0., 0., 0. ) - ECposition.xyz; // vector from the point to the eye position gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex; }
In the fragment shader do this:
#version 330 compatibility
// you can set these uniform variables dynamically or hardwire them:
uniform float uKa, uKd, uKs; // coefficients of each type of lighting
uniform float uShininess; // specular exponent
// these have to be set dynamically from glman sliders or keytime animations:
uniform float uAd, uBd;
uniform float uTol;
// in variables from the vertex shader:
in vec2 vST; // texture cords
in vec3 vN; // normal vector
in vec3 vL; // vector from point to light
in vec3 vE; // vector from point to eye
in vec3 vMCposition;
void
main( )
{
vec3 Normal = normalize(vN);
vec3 Light = normalize(vL);
vec3 Eye = normalize(vE);
vec3 myColor = vec3( ????? ); // whatever default color you'd like
vec3 mySpecularColor = vec3( ????? ); // whatever default color you'd like
<< set myColor by using the ellipse equation to create a smooth blend between the ellipse color and the background color >>
<< now use myColor in the lighting equations >>
// here is the per-fragment lighting:
vec3 ambient = uKa * myColor;
float d = 0.;
float s = 0.;
if( dot(Normal,Light) > 0. ) // only do specular if the light can see the point
{
d = dot(Normal,Light);
vec3 ref = normalize( reflect( -Light, Normal ) ); // reflection vector
s = pow( max( dot(Eye,ref),0. ), uShininess );
}
vec3 diffuse = uKd * d * myColor;
vec3 specular = uKs * s * mySpecularColor;
gl_FragColor = vec4( ambient + diffuse + specular, 1. );
}
float t = smoothstep( 1. - uTol, 1. + uTol, results_of_ellipse_equation );Then use t in the mix function to blend the colors on the edge of the ellipse.
Obj dragon010.objor use the API and our LoadObjFile( ) function. the OBJ file needs to be in the same folder as your .cpp, .glib, .vert, and .frag files.
Your turnin will be done at http://teach.engr.oregonstate.edu and will consist of:
Submissions are due at 23:59:59 on the listed due date.
Feature | Points |
---|---|
Hard-edged elliptical dots | 10 |
Smooth-edged elliptical dots with varying uTol | 20 |
Correct elongation when varying uAd and uBd | 10 |
Correct per-fragment lighting | 20 |
Potential Total | 60 |