CS148: Introduction to Computer Graphics and Imaging
Download
1 / 32

CS148: Introduction to Computer Graphics and Imaging - PowerPoint PPT Presentation


  • 585 Views
  • Updated On :

CS148: Introduction to Computer Graphics and Imaging Programmable Shaders Topics The Graphics Pipeline Fixed-function Programmable Programming Model Vertex, Geometry, Pixel Shaders Parallelism Implementation GLSL Syntax Limitations GPGPU The Graphics Pipeline

Related searches for CS148: Introduction to Computer Graphics and Imaging

loader
I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.
capcha
Download Presentation

PowerPoint Slideshow about 'CS148: Introduction to Computer Graphics and Imaging' - liam


An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript

Topics l.jpg
Topics

The Graphics Pipeline

  • Fixed-function

  • Programmable

    Programming Model

  • Vertex, Geometry, Pixel Shaders

  • Parallelism

    Implementation

  • GLSL Syntax

  • Limitations

    GPGPU



Geometry rendering stages l.jpg
Geometry Rendering Stages

Vertex

Data

Tessellation

Vertex Processing

Pixel Processing

Geometry Processing

Pixel Rendering

Primitive Data

Texture Sampler

Textured Surface


Rasterization l.jpg
Rasterization

Input: Vertices & values (ex. color, texture)

Output: Pixels & interpolated values


Fixed function pipeline l.jpg
Fixed Function Pipeline

Math

OpenGL

glLightfv(GL_LIGHT0, GL_DIFFUSE, P);

glLightfv(GL_LIGHT0, GL_POSITION, C);

glEnable(GL_LIGHT0);

glBlendFunc(GL_SRC_ALPHA, GL_ONE);

glEnable(GL_BLEND);

?


Programmable rendering l.jpg
Programmable Rendering

Code

Vector4 RenderPixel(

Vector3 Position,

Vector3 Normal)

{

...

return Vector4(0, 0, 1, 0);

}


Limitations l.jpg
Limitations

Mutable

Pixels

Geometry

Vertices

Immutable

  • Clipping

  • Triangle scanlines


Direct3d 10 pipeline l.jpg
Direct3D 10 pipeline

  • Traditional graphics pipeline

  • Three application-programmable stages operate on independent vertex, primitive, and pixel fragments

  • All stages share the same programming model and can query the same resources

Vertices

Input Assembler

Textures

Sampler

Vertex Shader

Constants

Textures

Sampler

Geometry Shader

Constants

CPU or GPU Memory

Rasterizer

Textures

Sampler

Pixel Shader

Constants

Application Programmable

Target Surface

Output Merger




Vertex shader l.jpg
Vertex Shader

Inputs

  • Program-provided vertex data

    • glVertex3d(1.0, 2.0, 3.0);

    • glNormal3d(1.0, 0.0, 0.0);

  • Constants

  • Textures

  • Outputs

    • Position

    • Array of floats used by future pipeline stages

      • Structure determined entirely by programmer


  • Example vertex shader l.jpg
    Example Vertex Shader

    Vertex Shader


    Geometry shader l.jpg
    Geometry Shader

    Inputs

    • Geometric primitive (point, line, triangle, quad)

    • Adjacent vertex information (AV0, AV1, AV2)

  • Outputs

    • More geometric primitives


  • Pixel shader l.jpg
    Pixel Shader

    Inputs

    • Array of floats from vertex/geometry shader

    • Constants

    • Textures

  • Outputs

    • 4-channel color

    • Depth


  • Example pixel shader l.jpg
    Example Pixel Shader

    Pixel Shader



    Simple vertex shader l.jpg
    Simple Vertex Shader

    void main()

    {

    gl_Position = gl_ModelViewProjectionMatrix *

    gl_Vertex;

    }

    gl_Position = output of vertex shader

    gl_Vertex = glVertex3d(x, y, z);

    or STShape::…

    gl_ModelViewProjectionMatrix =

    glLoadMatrixd(M);

    or STTransform::…


    Variables l.jpg
    Variables

    Local Variables

    { vec2 SomeVector = vec2(sin(2.0), sqrt(3.0));

    float SomeFloat = SomeVector.x * SomeVector.y;

    }

    “Varying” Variables

    Varyings are output by the vertex shader and interpolated across each primitive for the pixel shader

    varying vec2 TextureCoord0;

    void main() {

    TextureCoord0 = vec2(gl_Position.x, 2.0);

    }


    Variables20 l.jpg
    Variables

    Uniform Variables

    Uniforms are variables set by the program that can be changed at runtime, but are constant across each execution of the shader

    uniform float CurrentTime;

    void main() {

    float Displacement = cos(CurrentTime * 10);

    }

    C++ code to change this value might look like:

    STVertexShader Shader;

    Shader.SetUniformVariable(“CurrentTime”, ElapsedTimeInSeconds);


    Textures l.jpg
    Textures

    Textures are mapped from (0, 0) to (1, 1)

    Only relatively recent cards support vertex shader textures, almost all support pixel shader textures

    uniform sampler2D SomeTexture;

    void main()

    {

    vec4SomeTextureColor =

    texture2D(SomeTexture, vec2(0.5, 0.5));

    }


    Vectors l.jpg
    Vectors

    Constructors

    vec3 V3 = vec3(1.0, 2.0, 3.0);

    vec4 V4 = vec4(V3, 4.0);

    Swizzling

    vec2 V2 = V4.xy;

    vec4 V4Reverse = V4.wzyx;

    vec4 Result = V4.xyzw + V4.xxxx;

    Basic Vector Operators

    float Result = dot(V4, V4Reverse);

    vec3 Result = cross(V3, vec3(1.0, 0.0, 0.0));


    Simple pixel shader l.jpg
    Simple Pixel Shader

    varying vec2 TexCoord0;

    varying vec2 TexCoord1;

    uniform sampler2D SomeTexture0;

    uniform sampler2D SomeTexture1;

    void main()

    {

    gl_FragColor =

    texture2D(SomeTexture0, TexCoord0) * 0.5 +

    texture2D(SomeTexture1, TexCoord1) * 0.5;

    }

    gl_FragColor = output of pixel shader


    Functions l.jpg
    Functions

    Very similar to C:

    boolCompare(in vec3 a, in vec3 b)

    {return dot(a, a) > dot(b, b);

    }


    Limitations25 l.jpg
    Limitations

    Memory

    • No access to nearby pixels

    • Cannot bind render target as input texture

    • Limited stack space, instruction count

  • Performance

    • Branching support is limited and slow

    • Graphics card will timeout if code takes too long

    • Variable support across different graphics cards

    • Programmable code is much slower than dedicated hardware


  • Practical shading the bloom effect l.jpg
    Practical Shading: The Bloom Effect

    Images from Gamasutra.com & Tron 2.0


    Practical shading bump mapping l.jpg
    Practical Shading: Bump-mapping

    A fraction of the cost of increasing the initial number of polygons or using the geometry shader



    Parallelism l.jpg
    Parallelism

    CPU

    • Thread synchronization

    • Bandwidth limitations

    • Scheduling overhead

    • Small number of cores

      GPU

    • All threads independent

    • Message passing is not allowed

    • Resource allocation is done by GPU

    • Many cores available (12 to 48 typical)


    Ideal gpu problems l.jpg
    Ideal GPU Problems

    GPU’s are great if the problem:

    • Executes the same code many times on different input

    • Needs lots of math units at the same time

    • Does not share data between executing components

    • Can be expressed as a sequence of operations acting on a stream of data

    • Large data sets

    • Has lots of work to do without CPU intervention


    General purpose gpu s l.jpg
    General Purpose GPU’s

    Beyond triangle rendering

    • Collision detection

    • Fluid simulation

    • Physics

    • Raytracing

    • Video compression

  • Beyond graphics

    • [email protected]

    • Speech Recognition

    • Partial differential equation solvers

    • Fourier transform


  • Object reconstruction from images l.jpg
    Object Reconstruction from Images

    Massive non-linear optimization problem

    Output: Geometry of photographed object

    Input: 200 640x480 images

    (~250MB)


    ad