Blog 1
After much delay,
here is my first blog of INFR2350 – Intermediate Graphics.
This entry
will cover an overview of material of the past three weeks; namely VBOs,
shaders and lighting.
VBO
In modern
OpenGL, with shaders, we gain the ability to program directly to the gpu how
our data is to be computed. Prior to touching on shaders, we need to know the
difference in how to pass our data to begin with. Unlike old opengl where we
interate through draws of glVertex, glNormal and glTexCoords, we only need to
pass the data once and simple call draw when the object needs to be rendered.
To achieve this, there are many ways to pass the data to the gpu as a VBO, the gist of it is either pass arrays
of vertices, normals and texCoords or to organize the data in a single array
and pass that instead.
Shaders
Shaders are
essentially small programs (like functions) run on the GPU. They are fed a
number of inputs, performs calculations and then the output is passed further
along the pipeline. What is important to note is that very small iterative
pieces are passed one by one, not the entire object itself; for instance the properties
of vertex location, normal, and texCoord of a pixel. The changes to the vertex
are never returned as this would be both costly and unnecessary. As the
vertices are processed individually (in parallel on the gpu), previous results
are not to be relied on.
Lighting
Though we covered lighting models in intro to graphics, a brief review is needed to refresh dormant knowledge.
Though we covered lighting models in intro to graphics, a brief review is needed to refresh dormant knowledge.
OpenGL uses
the Blinn-Phong Lighting model to simulate realistic lighting. Under the Phong
model, three color components are calculated and then added together to
determine the color (specular, diffuse, and ambient)
Ambient is a
global ambience where all light is of the same color, it can be thought of indirect
light with no source.
where k is
come coefficient for the intensity
L is the
color of the light
Diffuse is
lighting where color is scattered by the material in accordance to normal of
the object
where k is
come coefficient (representing material properties such as absorbed, non-reflected
light)
l.n is the
dot product between the incident ray and the normal,
also the cosine of the angle of normal to l
L is the
color of the light
Specular is
the shiny reflection of objects and light to viewer
Where k is
come coefficient
Cosa φ is a shininess coefficient and φ is the angle of viewer and reflected ray
Also the dot product of the
reflected ray and the viewer r.v
L is the
color of the light
In the
Blinn-Phong model that OpenGl uses, a halfway vector is computed for
optimization purposes. Instead of needing to determine the reflected ray, we
use the halfway vector of l and v and sub in n.h in place of r.v.
Hogue, A.
(2014, January 13). Intro to Shaders
[PowerPoint slides].
Retrieved from UOIT College
Blackboard site: https://uoit.blackboard.com/
Pazzi, W. R.
(2013, December 2). Intro to Computer
Graphics Review & Questions [PowerPoint slides]. Retrieved from UOIT
College Blackboard site: https://uoit.blackboard.com/