Today. Rendering - III. Outline. Texturing: The 10,000m View. Texture Coordinates. Specifying Texture Coordinates in GL

Similar documents
Programmable GPUs. Real Time Graphics 11/13/2013. Nalu 2004 (NVIDIA Corporation) GeForce 6. Virtua Fighter 1995 (SEGA Corporation) NV1

Programming shaders & GPUs Christian Miller CS Fall 2011

Levy: Constraint Texture Mapping, SIGGRAPH, CS 148, Summer 2012 Introduction to Computer Graphics and Imaging Justin Solomon

Real-Time Rendering (Echtzeitgraphik) Michael Wimmer

Introduction to Shaders.

Shader Programs. Lecture 30 Subsections 2.8.2, Robb T. Koether. Hampden-Sydney College. Wed, Nov 16, 2011

Information Coding / Computer Graphics, ISY, LiTH GLSL. OpenGL Shading Language. Language with syntax similar to C

The Graphics Pipeline and OpenGL III: OpenGL Shading Language (GLSL 1.10)!

Lecture 2. Shaders, GLSL and GPGPU

Introduction to the OpenGL Shading Language

Information Coding / Computer Graphics, ISY, LiTH GLSL. OpenGL Shading Language. Language with syntax similar to C

The Transition from RenderMan to the OpenGL Shading Language (GLSL)

GLSL Introduction. Fu-Chung Huang. Thanks for materials from many other people

Programmable Graphics Hardware

CSE 167: Lecture #8: GLSL. Jürgen P. Schulze, Ph.D. University of California, San Diego Fall Quarter 2012

SHADER PROGRAMMING. Based on Jian Huang s lecture on Shader Programming

CSE 167: Introduction to Computer Graphics Lecture #13: GLSL. Jürgen P. Schulze, Ph.D. University of California, San Diego Fall Quarter 2015

Supplement to Lecture 22

Real - Time Rendering. Graphics pipeline. Michal Červeňanský Juraj Starinský

INF3320 Computer Graphics and Discrete Geometry

OPENGL RENDERING PIPELINE

X. GPU Programming. Jacobs University Visualization and Computer Graphics Lab : Advanced Graphics - Chapter X 1

E.Order of Operations

Some advantages come from the limited environment! No classes. Stranight ans simple code. Remarkably. Avoids most of the bad things with C/C++.

Introduction to Shaders for Visualization. The Basic Computer Graphics Pipeline

The Graphics Pipeline and OpenGL III: OpenGL Shading Language (GLSL 1.10)!

GLSL Introduction. Fu-Chung Huang. Thanks for materials from many other people

CS4621/5621 Fall Computer Graphics Practicum Intro to OpenGL/GLSL

Rendering Objects. Need to transform all geometry then

12.2 Programmable Graphics Hardware

Graphics Hardware. Computer Graphics COMP 770 (236) Spring Instructor: Brandon Lloyd 2/26/07 1

C P S C 314 S H A D E R S, O P E N G L, & J S RENDERING PIPELINE. Mikhail Bessmeltsev

The Graphics Pipeline

Sign up for crits! Announcments

Sung-Eui Yoon ( 윤성의 )

Programmable Graphics Hardware

The Graphics Pipeline

CS GPU and GPGPU Programming Lecture 2: Introduction; GPU Architecture 1. Markus Hadwiger, KAUST

CS179: GPU Programming

Shader Programming. Daniel Wesslén, Stefan Seipel, Examples

1.2.3 The Graphics Hardware Pipeline

GPU Programming EE Final Examination

The Basic Computer Graphics Pipeline, OpenGL-style. Introduction to the OpenGL Shading Language (GLSL)

Programmable shader. Hanyang University

Introduction to the OpenGL Shading Language (GLSL)

Shaders CSCI 4239/5239 Advanced Computer Graphics Spring 2014

COURSE 17: STATE-OF-THE-ART IN SHADING HARDWARE1 CHAPTER 6: THE OPENGL SHADING LANGUAGE 2. Randi J. Rost 3Dlabs, Inc.

Today s Agenda. Basic design of a graphics system. Introduction to OpenGL

CS GPU and GPGPU Programming Lecture 7: Shading and Compute APIs 1. Markus Hadwiger, KAUST

Programming with OpenGL Part 3: Shaders. Ed Angel Professor of Emeritus of Computer Science University of New Mexico

3D Graphics and OpenGl. First Steps

Graphics Pipeline & APIs

CPSC 436D Video Game Programming

GLSL v1.20. Scott MacHaffie Schrödinger, Inc.

Content. Building Geometry Appearance Lights Model Loaders

Programmable Shading. University of Texas at Austin CS354 - Computer Graphics

1 of 5 9/10/ :11 PM

Copyright Khronos Group 2012 Page 1. Teaching GL. Dave Shreiner Director, Graphics and GPU Computing, ARM 1 December 2012

WebGL and GLSL Basics. CS559 Fall 2015 Lecture 10 October 6, 2015

Shaders. Slide credit to Prof. Zwicker

Shaders CSCI 4229/5229 Computer Graphics Fall 2017

Lecture 09: Shaders (Part 1)

CMPS160 Shader-based OpenGL Programming. All slides originally from Prabath Gunawardane, et al. unless noted otherwise

Graphics Processing Units (GPUs) V1.2 (January 2010) Outline. High-Level Pipeline. 1. GPU Pipeline:

OpenGL Programmable Shaders

CS770/870 Fall 2015 Advanced GLSL

MXwendler Fragment Shader Development Reference Version 1.0

COMP371 COMPUTER GRAPHICS

Graphics Pipeline & APIs

Pipeline Operations. CS 4620 Lecture Steve Marschner. Cornell CS4620 Spring 2018 Lecture 11

Lecture 13: OpenGL Shading Language (GLSL)

Tutorial on GPU Programming #2. Joong-Youn Lee Supercomputing Center, KISTI

Programming Guide. Aaftab Munshi Dan Ginsburg Dave Shreiner. TT r^addison-wesley

Introduction to OpenGL

INF3320 Computer Graphics and Discrete Geometry

Programming Graphics Hardware

Shader Programming 1. Examples. Vertex displacement mapping. Daniel Wesslén 1. Post-processing, animated procedural textures

Graphics Processing Units (GPUs) V2.2 (January 2013) Jan Kautz, Anthony Steed, Tim Weyrich

CS 354R: Computer Game Technology

WebGL and GLSL Basics. CS559 Fall 2016 Lecture 14 October

Pipeline Operations. CS 4620 Lecture 14

Lighting and Texturing

Computer Graphics Coursework 1

Advanced Rendering Techniques

Artistic Rendering with Graphics Shaders

Stored Texture Shaders

Shadows. Prof. George Wolberg Dept. of Computer Science City College of New York

An Overview GLUT GLSL GLEW

CS452/552; EE465/505. Clipping & Scan Conversion

CS770/870 Spring 2017 Open GL Shader Language GLSL

CS770/870 Spring 2017 Open GL Shader Language GLSL

Lab 9 - Metal and Glass

The GPGPU Programming Model

Ciril Bohak. - INTRODUCTION TO WEBGL

Vertex & Fragment shaders

Dave Shreiner, ARM March 2009

Shading Language Update

Programming with OpenGL Shaders I. Adapted From: Ed Angel Professor of Emeritus of Computer Science University of New Mexico

Best practices for effective OpenGL programming. Dan Omachi OpenGL Development Engineer

To Do. Computer Graphics (Fall 2008) Course Outline. Course Outline. Methodology for Lecture. Demo: Surreal (HW 3)

Transcription:

Today Rendering - III CS148, Summer 2010 Graphics Pipeline and Programmable Shaders Artist Workflow Siddhartha Chaudhuri 1 2 Outline Texturing: The 10,000m View Intro to textures The fixed-function graphics pipeline Programmable stages shaders shaders OpenGL shading language (GLSL) A look ahead 3 (Adapted from Pat Hanrahan's slides) = + 4 (Globe and texture map courtesy James Hastings-Trew) Coordinates coordinates on surface map surface points to image pixels Specify at vertices, interpolated within primitives Specifying Coordinates in GL Most common version: gltexcoord2f(float u, float v); (0, 1) (1, 1) Used just like glcolor, glnormal etc., before a gl call (0.5, 0.5) (0, 0) (1, 0) Maps vertex to point (u, v) [0, 1] 2 on texture image This texture image is loaded with the functions glgens, glteximage2d and glbind, look up SDK docs for syntax 5 6

Basic Graphics Pipeline queue interpretation Unpacking and format conversion Maintain graphics state 7 glloadidentity( ); glmultmatrix(t); glbegin(gl_triangle_strip); glcolor3f(0.0, 0.5, 0.0); gl3f(0.0, 0.0, 0.0); glcolor3f(0.5, 0.0, 0.0); gl3f(1.0, 0.0, 0.0); glcolor3f(0.0, 0.5, 0.0); gl3f(0.0, 1.0, 0.0); glcolor3f(0.5, 0.0, 0.0); gl3f(1.0, 1.0, 0.0); glend( ); 8 transformation Normal transformation coordinate generation coordinate transformation Per-vertex lighting Combine transformed/lit vertices into primitives 1 vertex point 2 vertices line 3 vertices triangle Clipping to view volume Convert from homogenous coordinates Transform to window (viewport) coordinates Determine orientation (CW/CCW) Back-face culling Object space vertices Screen space lit vertices 9 10 Setup (per-triangle) Sampling (triangle fragments) Interpolation (coordinates, colors, normals, ) s are arrays indexed by floats Sampler interface for reading values address calculation interpolation and filtering s fragments Screen space triangles s 11 12

Combine texture sampler outputs Per-fragment lighting Special effects tests: - Ownership: screen pixel owned by current window? - Scissor: pixel inside clipping rectangle? - Alpha: fragment α satisfies some condition? - Stencil: fragment within masked area? - Depth: new depth < old depth? Blending/compositing Dithering and logical ops s d fragments 13 d fragments Framebuffer pixels 14 Gamma correction Digital to analog conversion Programmable Stages Programmable Framebuffer pixels Light 15 16 Programmable Shaders The code that processes a vertex is called a vertex shader The code that processes a fragment is called a fragment shader Shaders replace fixed-function stages Can be written in Assembly High-level languages (typically C-like) GLSL (OpenGL) Cg (OpenGL/Direct3D) Simple GLSL Shader gl_position = gl_projectionmatrix * gl_modelviewmatrix * gl_; gl_frontcolor = gl_color; gl_backcolor = gl_color; HLSL (Direct3D) 17 18

Simple GLSL Shader gl_fragcolor = gl_color; Per- Lighting vec4 color = complicatedlightingfunction(); gl_frontcolor = color; gl_backcolor = color; 19 20 Per- ( Per-Pixel ) Lighting gl_fragcolor = complicatedlightingfunction(); Shader for Texturing gl_position = ftransform(); gl_texcoord[0] = gl_multitexcoord0; gl_multitexcoord0 holds vertex's (first set of) texture coordinates ftransform() is optimized shorthand for multiplying gl_ by gl_modelviewmatrix & gl_projectionmatrix 21 22 Shader for Texturing // Handle to an attached texture uniform sampler2d my; gl_fragcolor = texture2d(my, gl_texcoord[0].xy); Passing Data to Shaders Program to shaders, per-primitive: Uniform variables Program to vertex shader, per-vertex: Attribute variables shader to fragment shader, per-fragment: Varying variables 23 24

Uniform Variables Attribute Variables Uniforms are variables set by the program that can be changed at runtime, but are constant across each execution of the shader Set at most once per primitive (glbegin/glend block) uniform mat4 gl_modelviewmatrix; uniform mat4 gl_projectionmatrix; uniform mat4 gl_normalmatrix; // User-defined Attributes are vertex properties Set at most once per vertex s to vertex shader attribute vec4 gl_color; attribute vec3 gl_normal; attribute vec4 gl_multitexcoord0; // User-defined attribute float vtxlabel; uniform float time; 25 26 Varying Variables Example Varying variables are outputs of vertex shader Interpolated across primitive for values at fragments varying vec4 gl_frontcolor, gl_backcolor (in vertex shader) gl_color (in fragment shader) varying vec4 gl_texcoord[n]; // User-defined (declare in both vertex and fragment shaders) shader.vert uniform float time; attribute float vtxlabel; gl_position = ftransform(); height = foo(vtxlabel, time); shader.frag uniform vec4 lightcolor; // Interpolated from vertices gl_fragcolor = bar(height, lightcolor); 27 28 Limitations A Look Ahead: The Direct3D 11 Pipeline Memory No access to neighboring fragments Limited stack space, instruction count Cannot bind output framebuffer (render target) as an input texture Performance Branching support is limited and slow Improving in newer hardware Graphics card will timeout if code takes too long Variable support across different graphics cards Shader Hull Shader Tessellator Domain Shader Geometry Shader Shader 29 Programmable 30