Computer Graphics: More on GLSL Language and Shader Design

 




  Shading calculation - What color should show up in a different location

Specular reflection reflects all the light that comes in at the same angle. 

Const are compile-time constants, which means you cannot control with the host program, live completely in the shader programs. Consts are drawn to uniforms. These have values that are spatially constant throughout the entire scene.

Attributes are always defined in vertex shaders. They would never, ever, EVER be defined in a fragment shader. 

Vertex shaders helps to compute the world coordinates.

Varying is the ONLY way to communicate from the vertex shader to the fragment shader. They are invisible to the host program. They are assigned on a pre-vertex basis by the vertex shader, interpolated on a per-fragment basis and interpolates using barycentric weights. 

The only way to pass down any types of information is through varying variables. 

fPosition and fNormal

Rasterization is computing a triple of weights that will reconstruct the point if used as averaging weights from the triangle vertices. This tires to figure out if there is a window of pixels that successfully encloses everything? 

One possible heuristic is the center of each one of the pixels, we check that pixel for inclusion or exclusion relative to the triangle, and if we can determine a pixel is inside.



x frag = w1x1 + w2x2 + w3x3.
Qfrag = w1Q1 + w2Q2 + w3Q3.

When you declare a varying identifier, it will be the responsibility of the vertex shader to specify the value of that property on every vertex.

These are used as "averaging" weights.

We will have information after rasterization on how many pictures a triangle will cover.

Rasterization overlays with the pixels on screen and sees if there is a window of pixels that neatly encloses the triangle to be drawn.

We first see if a pixel is actually inside of a triangle or outside of a triangle.

Both Web GL and Open GL are APIs that accesses the GPU functionality wit   hin a host program.

We are simply writing programs that will run on the GPU. OpenGL will work on a host C program of JavaScript program. 






It is always possible to write the location xfrag on any location on an entire plane as a weighted sum of the 3 locations that correspond to the corners that are on the embedded triangle.

Every plane can be as a weighted sum of the corners of the triangle. Write down the linear system that has these weights.

The labels have the sum equal to 1 and blending weights in order to get the centroid of the triangle use 1/3 of every vertex and this will give you the average of the vertices. Average 3 vertex quantities, and populate them with the same blending weights.     

Interpolate from the vertex level to the fragment level, and creates a smooth field of vertex quantities that populates each fragment. Pass on information using a varying. 
The only other way for the fragment to get some information is to access uniforms. 




 
h = 1/2 (r + e)




What we do instead is that we compare the angle between the halfway vector and the normal vector. We essentially take the dot product of h and n (h o n) and raise it to s 
Is = Ks * (h o n)^s. This is so we can we can use this computation solely and not have to compute the intended direction.

Most of the action has happened inside of the vertex shader.


The attributes are

uniform mat3 normalMatrix;
uniform mat4 modelViewMatrix 
uniform mat4 projectionMatrix;

The normal matrix is defined in object space and is a matrix 3x3 and will compute the camera space normal if multiplied with the object space normal. 

The model view matrix will take the object space to the camera. Its object to world x world to camera.

The projection matrix implements a version of prospective projection for a visualization.

Position uses a modelView matrix with an object space position. It is multiplied with a modelViewMatrix that takes it from object space to camera coordinates. Pos is in camera coordinates. 

We then multiply these camera coordinates by projection matrix, and these will take us from camera coordinates into normalized device coordinates. 

The model attempts to place something in a specific location.



l, n, e are the direction towards the light, the normal, and the direction towards the camera, respectively. 

Negative pos points towards the light, positive pos points away from the light. 

If there is a very wide angle, we want to see the real halfway bector is 0.5 * (e + l).

To compute the specular color, compute the specular reflection coefficient, and then the dot product between n and h, then raise this to the specular exponent, and multiply this by the light color.

Here fColor is the shader and having an alpha color, and writing this to the special value gl_FragColo

precision highp float;
varying vec3 fColor;

void main() {

    gl_FragColor = vec4(fColor, 1.0);

}

normalMatrix x normal will convert a matrix into camera space.  
position x modelView will convert to a homogeneous space.

The fragment shader is a lot more accurate in comparison to the vertex shader.

We get the highest intensity if the direction of the light is the same as the direction of the normal vector. 

Now imagine if you just interpolated across the normal itself.


A corner can get a situation where there will be a highlight because the normal of that corner is in the direction of the reflection. Smoothly interpolating the normal and then doing the computation helps to make things a lot more even. Fragment is an example.


Diffuse only normal vector and direction to the lights. Everything is exactly the same. Should expect to get way better results if you do the calculations on the fragment shader. We do as much as possible on the fragment shader and as little as possible of the vertex shader. 

The vertex shader

1. Set the variable gl_position to the normalized device coordinates of the vertex being processed. Also passes varying down to the fragment shader, or discards drawing the fragment altogether. 

2. The fragment shader sets up the variable gl_fragcolor wo the final coloration of every pixel being shaded. You could also ask the shader to discard the pixel from being drawn. 

We have control structures such as GLSL such as if-else statements and specify the step interpolation iteration coefficents (color, smoothstep, etc.)

User-defined functions are also very much possible for this. Can call something and return a result. 

Discard discards the drawing of the location. 

The uniform time is a variable that is created and is continuously being updated. It can make the light spin around the object and define the position of the light and use the time parameter to animate a light to circle around an object. 

Discard can do some interesting things. 





Comments

Popular Posts