Rest of the Pipeline, Textures




CS116b/CS216

Chris Pollett

Feb 3, 2014

Outline

Introduction

Projections

A film plane in front of the camera

More Projections

Quiz

Which of the following statements is true?

  1. A translation is an example of an affine transformation.
  2. In the example from class last week, we sent the model view matrix to the vertex shader using an in variable.
  3. In OpenGL coordinates of vertices of objects are stored in index buffer objects.

Clipping and Culling

Steps in Graphicsa Pipeline

Triangles on the Screen, z-buffering

Materials

Fragment Shader for a Material

#version 330

uniform vec3 uLight;
in vec3 vColor;
in vec3 vNormal;
in vec4 vPosition;

out fragColor;

void main()
{
    vec3 toLight = uLight - vec3(vPosition);
    vec3 toV = -normalize(vec3(vPosition));
    toLight = normalize(toLight);
    vec3 h = normalize(toV + toLight);
    vec3 normal = normalize(vNormal);

    float specular = pow(max(0.0, dot(h, normal)), 64.0);
    float diffuse = max(0.0, dot(normal, toLight));
    vec3 intensity = vec3(0.1, 0.1, 0.1) + vColor * diffuse
        + vec3(0.6, 0.6, 0.6) *specular;

    fragColor = vec4(intensity.x, intensity.y, intensity.z, 1.0);
}

Texture Mapping

Basic Texturing Vextex Shader

#version 330

uniform mat4 uProjMatrix;
uniform mat4 uModelViewMatrix;

in vec2 aTexCoord;
in vec4 aVertex;

out vec2 vTexCoord;

void main(void)
{
    vTexCoord = aTexCoord;
    gl_Position = uProjMatrix * uModelViewMatrix * aVertex;
}

Basic Texturing Fragment Shader

#version 330

uniform sampler2d uTexUnit0;

in vec2 vTexCoord;
out fragColor;

void main(void)
{
    vec4 texColor0 = texture2D(uTexUnit0, vTexCoord);
    fragColor = texColor0;
}