Hello and welcome people of the internet to this blog of
well stuff, yeah stuff that’s the best way to describe this blog, since I talk
about stuff and every once in a while I rant about stuff. SO YEAH, welcome to
the blog that talks about stuff, the stuff that will be focused on in this blog
will be a little something called shaders. This blog will cover a brief
overview of what shaders are some of the types of shaders and examples of what
shaders can do and where you can use them.
So you may be wondering what shaders are, and why the hell
should you care about shaders, well I am going to answer those questions in
just one moment.
WHAT ARE SHADERS?
Now shaders, in the field of
computer graphics, are the name for a computer program that are used to produce
special effects and do post processing. Shaders can be used to create anything
from shadows to reflective glass. They are one of the most flexible ways to
calculate the rendering effects on graphics hardware, most of which are primarily
coded for the GPU (Otherwise known as the graphics processing unit).
Programmers use shaders in order to program the programmable GPU rendering
pipeline (which you can learn more about HERE) in order to get around and exceed
the fixed functionality of the pipeline.
GPU Graphics Pipeline |
By using shaders we are able to use customizable effects and
alter things such as position, hue, saturation, brightness, and contrast of all
pixels, vertices and textures at the drop of a hat.
TYPE OF SHADERS
There are a lot of different types of shaders, however I
will only be focusing on three types of shaders in this blog, which are The
Vertex Shader, Pixel Shader and the Geometry shader.
VERTEX SHADER
Vertex shaders are one of the main shaders used in computer
graphics which are run once per vertex depending on the graphics processor.
Their purpose is to transform the 3D position of each vector into the 2D
coordinate that will appear on the screen. The vertex shader is responsible for
the manipulation of position, colour and texture coordinates, and can enable
powerful control over the position, movement, lighting, and colour of any 3D
scene.
The following are just a few simple examples of some vertex shader
code:
#version 120
void main()
{
gl_Position
= gl_ModelViewProjectionMatrix * gl_Vertex;
}
}
This is a simple pass through shader
that passes the model view projection matrix and the vertex through to a
position. The next example is a draw
attribute vertex shader:
#version 120
varying vec3 passVertex;
varying vec3 passNormal;
varying vec2 passTexcoord;
void main()
{
gl_Position
= gl_ModelViewProjectionMatrix * gl_Vertex;
passVertex
= gl_Vertex.xyz;
passNormal
= gl_Normal;
passTexcoord
= gl_MultiTexCoord0.st;
}
PIXEL SHADER
The pixel shader, otherwise known as the fragment shader, computes
colour and other attributes on a per pixel bases rather than on the vertices
like the vertex shader does. The fragment shader is responsible for changing
the look and feel of colors, applying lighting value, translucency, shadows,
bump mapping, among other effects. The fragment shader also has the ability to
alter the depth of the fragment (for Z-buffering) or output for multiple target
rendering. Now while the pixel shader cannot produce very complex effects it
does have the knowledge of the screen coordinates being drawn and can sample
the screen and nearby pixels, which can enable a large variety of 2D post processing effects such as blur, edge
detection and cell shading.
The following are just a few simple examples of some Pixel
(fragment) shader code:
#version 120
void main()
{
//this sets
all targets to the same colour
gl_FragColor
= vec4(1.0, 0.5, 0.0, 1.0);
}
The is a simple fragment shader
pass through that sets all targets to the same color, while the following code
is an example of a simple fragment shader that draws the attributes:
#version 120
varying vec3 passVertex;
varying vec3 passNormal;
varying vec2 passTexcoord;
void main()
{
//vec3
colour = passVertex*0.5 + 0.5;
vec3
colour = passNormal*0.5 + 0.5;
//vec3
colour = vec3(passTexcoord, 0.0);
gl_FragColor
= vec4(colour, 1.0);
}
GEOMETRY SHADER
The last shader I will be talking briefly about in this blog
will be the Geometry shader, which is a relatively new shader in the OpenGL language
that has the ability to generate new graphics primitives, such as points, lines
and triangles, from the ones that were sent to the beginning of the GPU
pipeline. Geometry shaders are executed after the vertex shader and take the
whole primitive as well as additional information as its input. This type of
shader is an optional shader and does not have to be used.
Now I mentioned a few post processing techniques which I
will discuss more in a later blog, my next blog will focus on lighting.
The Star Grand at The Star Casino Site
ReplyDeleteThe Star Grand at The Star Casino Site. The Star Grand at The Star Casino Site. The Star Grand at The 인카지노 Star Casino Site. choegocasino The Star Grand at The 메리트 카지노 Star Casino