Zeyang Li Carnegie Mellon University

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

Shaders. Slide credit to Prof. Zwicker

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

Technical Game Development II. Reference: Rost, OpenGL Shading Language, 2nd Ed., AW, 2006 The Orange Book Also take CS 4731 Computer Graphics

Technical Game Development II. Reference: Rost, OpenGL Shading Language, 2nd Ed., AW, 2006 The Orange Book Also take CS 4731 Computer Graphics

OPENGL RENDERING PIPELINE

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

EDAF80 Introduction to Computer Graphics. Seminar 3. Shaders. Michael Doggett. Slides by Carl Johan Gribel,

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

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

Evolution of GPUs Chris Seitz

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

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

Shaders CSCI 4239/5239 Advanced Computer Graphics Spring 2014

Computergrafik. Matthias Zwicker Universität Bern Herbst 2016

The Rasterization Pipeline

Supplement to Lecture 22

Programming shaders & GPUs Christian Miller CS Fall 2011

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

Technical Game Development II. Reference: Rost, OpenGL Shading Language, 2nd Ed., AW, 2006 The Orange Book IMGD 4000 (D 10) 1

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

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

Introduction to Shaders.

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

16 - Other Topics. The Stencil Buffer. Erosion. Fragment Discarding. Multi-Texturing + +

Module Contact: Dr Stephen Laycock, CMP Copyright of the University of East Anglia Version 1

Today. Texture mapping in OpenGL. Texture mapping. Basic shaders for texturing. Today. Computergrafik

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

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

Interactive Cloth Simulation. Matthias Wloka NVIDIA Corporation

1 of 5 9/10/ :11 PM

CS 354R: Computer Game Technology

Computer graphics 2: Graduate seminar in computational aesthetics

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

Programming Graphics Hardware

CS 450: COMPUTER GRAPHICS TEXTURE MAPPING SPRING 2015 DR. MICHAEL J. REALE

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

Efficient and Scalable Shading for Many Lights

Sign up for crits! Announcments

Lecture 17: Shading in OpenGL. CITS3003 Graphics & Animation

Computer Graphics (CS 543) Lecture 10: Normal Maps, Parametrization, Tone Mapping

COMP371 COMPUTER GRAPHICS

Bump Mapping Which one of these two image has a better visual effect?

Computergrafik. Matthias Zwicker. Herbst 2010

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

GLSL 1: Basics. J.Tumblin-Modified SLIDES from:

Programming Graphics Hardware

Programmable Graphics Hardware

Surface Rendering. Surface Rendering

Direct Rendering of Trimmed NURBS Surfaces

Texture mapping. Computer Graphics CSE 167 Lecture 9

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

Lecture 5 Vertex and Fragment Shaders-1. CITS3003 Graphics & Animation

Pipeline Operations. CS 4620 Lecture 14

Introduction to Shaders for Visualization. The Basic Computer Graphics Pipeline

Graphics Programming. Computer Graphics, VT 2016 Lecture 2, Chapter 2. Fredrik Nysjö Centre for Image analysis Uppsala University

frame buffer depth buffer stencil buffer

object (say a cube) will be made up of triangles, each with three vertices, each with known object coordinates.

CS4621/5621 Fall Basics of OpenGL/GLSL Textures Basics

Shaders CSCI 4229/5229 Computer Graphics Fall 2017

Parallax Bumpmapping. Whitepaper

Lecture 2. Shaders, GLSL and GPGPU

Objectives Shading in OpenGL. Front and Back Faces. OpenGL shading. Introduce the OpenGL shading methods. Discuss polygonal shading

Programmable Graphics Hardware

OUTLINE. Tessellation in OpenGL Tessellation of Bezier Surfaces Tessellation for Terrain/Height Maps Level of Detail

More Texture Mapping. Texture Mapping 1/46

Graphics Hardware. Instructor Stephen J. Guy

WebGL and GLSL Basics. CS559 Fall 2016 Lecture 14 October

INF3320 Computer Graphics and Discrete Geometry

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

Overview. Hierarchy. Level of detail hierarchy Texture maps Procedural shading and texturing Texture synthesis and noise.

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

CS GPU and GPGPU Programming Lecture 12: GPU Texturing 1. Markus Hadwiger, KAUST

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

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

Mobile graphics API Overview

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

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

12.2 Programmable Graphics Hardware

Hardware Accelerated Volume Visualization. Leonid I. Dimitrov & Milos Sramek GMI Austrian Academy of Sciences

OUTLINE. Learn the basic design of a graphics system Introduce pipeline architecture Examine software components for a graphics system

CS GPU and GPGPU Programming Lecture 11: GPU Texturing 1. Markus Hadwiger, KAUST

CS 4620 Program 3: Pipeline

Orthogonal Projection Matrices. Angel and Shreiner: Interactive Computer Graphics 7E Addison-Wesley 2015

Rendering. Converting a 3D scene to a 2D image. Camera. Light. Rendering. View Plane

Programmable GPUS. Last Time? Reading for Today. Homework 4. Planar Shadows Projective Texture Shadows Shadow Maps Shadow Volumes

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

TSBK03 Screen-Space Ambient Occlusion

Hardware-Assisted Relief Texture Mapping

Mattan Erez. The University of Texas at Austin

SUMMARY. CS380: Introduction to Computer Graphics Texture Mapping Chapter 15. Min H. Kim KAIST School of Computing 18/05/03.

Computergrafik. Matthias Zwicker Universität Bern Herbst 2016

Texture Mapping II. Light maps Environment Maps Projective Textures Bump Maps Displacement Maps Solid Textures Mipmaps Shadows 1. 7.

Shading. Flat shading Gouraud shading Phong shading

CSE528 Computer Graphics: Theory, Algorithms, and Applications

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

Texture and other Mappings

Real-Time Rendering (Echtzeitgraphik) Michael Wimmer

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

HW-Tessellation Basics

Transcription:

Zeyang Li Carnegie Mellon University

Recap: Texture Mapping Programmable Graphics Pipeline Bump Mapping Displacement Mapping Environment Mapping GLSL Overview Perlin Noise GPGPU

Map reflectance over a piece of geometry 2D texture mapping steps: f(x, y, z) mapping function: 3D points to u, v coordinates g(u, v) sampling function: u, v coordinates to color.

The mapping function Easy for simple geometries: cubes, spheres Not so easy for human body, plant, alien So it s usually done manually

The mapping function Easy for simple geometries: cubes, spheres Not so easy for human body, plant, alien So it s usually done manually

The mapping function Easy for simple geometries: cubes, spheres Not so easy for human body, plant, alien So it s usually done manually

The mapping function Easy for simple geometries: cubes, spheres Not so easy for human body, plant, alien So it s usually done manually

The mapping function Easy for simple geometries: cubes, spheres Not so easy for human body, plant, alien So it s usually done manually

The mapping function Easy for simple geometries: cubes, spheres Not so easy for human body, plant, alien So it s usually done manually You will texture map spheres in project 2(P247)

The sampling function (P242) Nearest-neighbor Bilinear Linear interpolation on two directions Hermite Similar to bilinear interpolation, weighting neighbor points differently.

Programmable Pipeline Vertex processors Fragment processors

Programmable Pipeline Vertex processors fragment processors

Vertex shader operates on incoming vertices and associated data(normals, uv coordinates). operates on one vertex at a time replaces vertex program in the pipeline must compute the vertex position

Fragment shader/pixel shader operates on each fragment fragment: smallest unit being shaded replaces pixel program in the pipeline must compute a color

Programmable Pipeline Vertex processors Fragment processors What you can do with it? Anything you can do with fixed function pipeline And a few million more

Texture mapping by itself does not produce very satisfying result. What can we do to fix it?

Texture mapping by itself does not produce very satisfying result. What can we do to fix it? Normal mapping

Texture mapping by itself does not produce very satisfying result. What can we do to fix it? perturb the normals

How? Two textures, color map and normal map

How? Two textures, color map and normal map Normal map usually uses tangent space, while other vectors are in eye space

How? Two textures, color map and normal map Normal map usually uses tangent space, while other vectors are in eye space Eye space to tangent space transformation

Eye space to tangent space transformation Goal: find basis vectors for tangent space. We need vertices v1,v2,v3 on a plane, and their (u,v) coordinates c1,c2,c3. v2v1: 3D(x,y,z) vector from v1 to v2. c2c1: 2D(u,v) vector from c1 to c2. Write v2v1 and v3v1 as a linearly combination of the basis vectors T and B. v2v1 = c2c1.u * T + c2c1.v * B v3v1 = c3c1.u * T + c3c1.v * B Solve this linear system, we can get T and B. N is trivial to compute from T and B. I m sure you can construct a matrix from T, B and N to transform vectors from eye space to tangent space.

Bump mapping is not good enough Bumps do not cast shadow or affect sihouette(they don t officially exist ) The hard way to do it, add more geometric details. heightmap: displacement in the direction of normals. vertex displacement possible in vertex shader subvertex displacement Shadermodel 4.0(DirectX 10), supported only on epic graphics cards(geforce 8800 and above) Requires subdivison, need to generate new vertices

How? p = p + f(p)*n f(p): height value from height map p: point position n: normal

Sometimes Phongshading is not good enough A spaceship traveling in some exotic star system, light sources include 2 suns, 5 planets and a million stars. How many lights we need?

Sometimes Phongshading is not good enough A spaceship traveling in some exotic star system, light sources include 2 suns, 5 planets and a million stars. How many lights we need? Environment map is a texture used as lights. Good when lighting conditions are static, ex. all light sources are very far away

Basic Idea Convert reflected eye vector to uv coordinates(again, 3D -> 2D, except this time, for real) Different mapping schemes, depending on what environment map you use.

Basic Idea Convert reflected eye vector to uv coordinates(again, 3D -> 2D, except this time, for real) Different mapping schemes, depending on what environment map you use. Sphere mapping m = 2*sqrt(x^2 + y^2 + (z+1)^2) u = x/m + 0.5 v = y/m + 0.5

C-like shading language // vertex shader void main(void) { float shift = 2.0; gl_position = gl_modelviewprojectionmatrix*gl_vertex*shift; } // fragment shader void main(void) { gl_fragcolor = vec4(1.0, 0.0, 0.0, 1.0); }

C-like shading language // vertex shader void main(void) { float shift = 2.0; gl_position = gl_modelviewprojectionmatrix*gl_vertex*shift; } // fragment shader void main(void) { gl_fragcolor = vec4(1.0, 0.0, 0.0, 1.0); } More primitives: vec[2-4], mat[2-4], special types of variables: uniform, varying, attribute

In GLSL, you can access OpenGL states: lighting, materials, modelview matrix, projection matrix, textures, vertex data, ext. Vertex shader cannot access texture, or has to suffer a performance penalty. Neither shaders can generate new vertices. Fragment shader cannot change its screen coordinates.

Uniform Variables Read-only Accessible in both shaders Initialized externally uniform vec3 diffuse; varying vec3 normal; attribute vec3 tangent; void main(void) { } GLint diffuse_loc = glgetuniformlocationarb(program, "diffuse"); gluniform3farb(diffuse_loc, 1.0, 0.0, 0.0);

Varying Variables Interface between vertex fragment shader Interpolated automatically Read/write in vertex shader Read-only in fragment shader uniform vec3 diffuse; varying vec3 normal; attribute vec3 tangent; void main(void) { }

Attributes Values passed on a per-vertex base, like position, normal, uv Read-only GLinttangent_loc= uniform vec3 diffuse; varying vec3 normal; attribute vec3 tangent; void main(void) { } glgetattriblocationarb(program, "tangent"); For each vertex, glvertexattrib3farb(tangent_loc, t.x, t.y, t.z);

Demo Vertex shading vs. Pixel shading Useful references GLSL Quick Reference: http://www.opengl.org/sdk/libs/openscenegraph /glsl_quickref.pdf GLSL Specification http://www.opengl.org/registry/doc/glslangspe c.full.1.20.8.pdf

Invented by Ken Perlin Functions that generate noise/randomness Very useful when generate procedural textures Steps to noise Generate random numbers over a KD grid. Interpolate those numbers. Repeat this process at different scales, and add the results together.

1D example

Frequency: density of samples. Amplitude, range of samples

Composition of all the noise

2D Example

Can do a lot more: cloud, marble, wood, lava, gold Interpolation Linear, cosine, cubic, Gaussian blur A more comprehensive treatment of Perlin noise P69, Texturing & Modeling: A Procedural Approach 3 rd http://freespace.virgin.net/hugo.elias/models/m_ perlin.htm

General-Purpose compute on GPU (GPGPU) Much faster than CPU for highly parallelized computation. Hard to program have encode data as vertices/textures, feedback through write-to-texture New platforms are coming out that support more CPU-like programming style, Intel s Larrabee, nvidia s CUDA.

The textbook About Perlinnoise: http://freespace.virgin.net/hugo.elias/models/m_perlin.htm GPGPU slides: http://www.gpgpu.org/s2007/slides/01-introduction.pdf