Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Requirements: Use GLSL and either Requirements: Use GLSL and either glman or the GLSL API to render some geometry ( your choice ) , covered
Requirements:
Use GLSL and either Requirements:
Use GLSL and either glman or the GLSL API to render some geometry your choice covered with elliptical dots.
Remember thaglman or the GLSL API to render some geometry your choice covered with elliptical dots.
Remember that the border of an ellipse, defined in s and t coordinates is:
ssc Arttc Br
Be sure you compute the ellipse centers, sc and tc correctly.
The ellipse parameters must be set as uniform variables. If you are using glman, put them on sliders. If you are using the API, animate them using KeyTime animation.
A glman glib file might look like this:
##OpenGL GLIB
Perspective
LookAt
Vertex oval.vert
Fragment oval.frag
Program Oval
uAd
uBd
uTol
Color
Sphere
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 nonellipse areas
If you are using the API, use KeyTime animation to show the effects of uAd, uBd, and uTol:
a defined value:
const int MSEC ; milliseconds seconds
a global:
Keytimes Ad;
in InitGraphics:
AdInit;
AdAddTimeValue;
AdAddTimeValue;
AdAddTimeValue;
AdAddTimeValue;
AdAddTimeValue;
in Animate:
glutSetWindow MainWindow ;
glutPostRedisplay;
in Display:
turn # msec into the cycle MSEC:
int msec glutGet GLUTELAPSEDTIME MSEC;
turn that into a time in seconds:
float nowTime floatmsec ;
Pattern.SetUniformVariable "uAd", AdGetValue nowTime ;
Apply perfragment lighting. In the vertex shader, do something like this:
#version compatibility
out vec vST; texture coords
out vec vN; normal vector
out vec vL; vector from point to light
out vec vE; vector from point to eye
out vec vMCposition;
const vec LIGHTPOSITION vec;
void
main
vST glMultiTexCoordst;
vMCposition glVertex.xyz;
vec ECposition glModelViewMatrix glVertex; eye coordinate position
vN normalize glNormalMatrix glNormal ; normal vector
vL LIGHTPOSITION ECposition.xyz; vector from the point to the light position
vE vec ECposition.xyz; vector from the point to the eye position
glPosition glModelViewProjectionMatrix glVertex;
In the fragment shader do this:
#version 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 vec vST; texture cords
in vec vN; normal vector
in vec vL; vector from point to light
in vec vE; vector from point to eye
in vec vMCposition;
void
main
vec Normal normalizevN;
vec Light normalizevL;
vec Eye normalizevE;
vec myColor vec; whatever default color you'd like
vec mySpecularColor vec; 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 perfragment lighting:
vec ambient uKa myColor;
float d ;
float s ;
if dotNormalLight only do specular if the light can see the point
d dotNormalLight;
vec ref normalize reflectLight, Normal ; reflection vector
s pow max dotEyeref uShininess ;
vec diffuse uKd d myColor;
vec specular uKs s mySpecularColor;
glFragColor vec ambient diffuse specular, ;
The uTol parameter is the width of a smoothstep blend between the ellipse and nonellipse areas, thus smoothing the abrupt color transition.
float t smoothstep uTol, uTol, resultsofellipseequation ;
Then use t in the mix function to blend the colors on the edge of the ellipse.
The choice of geometry is up to you. Keep it simple at first, then, if there is still time, feel free to get more creative. To try out one of the dragon models, use the GLIB line:
Obj dragonobj
or use the API and our LoadObjFile function. the OBJ file needs to be in the same folder as your cppglib, vert, and frag files.
Hints:
Use the ellipse equation found in the Stripes, Rings,and Dots notes.
You can key off of anything you like. st works well. xyz works well too, depending on the geometry.
For some shapes, strange things happen in st and xyz
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started