Lab: Vertex Shading Chris Wynn Ken Hurley. Objective Hands-On vertex shader programming Start with simple programs … Part 1: Textured-Lit Teapot.

Slides:



Advertisements
Similar presentations
Normal Map Compression with ATI 3Dc™ Jonathan Zarge ATI Research Inc.
Advertisements

Michael I. Gold NVIDIA Corporation
Topics in Computer Graphics Spring Application.
Bump Mapping CSE 781 Roger Crawfis.
Graphics Pipeline.
3D Graphics Rendering and Terrain Modeling
CS-378: Game Technology Lecture #9: More Mapping Prof. Okan Arikan University of Texas, Austin Thanks to James O’Brien, Steve Chenney, Zoran Popovic, Jessica.
9/25/2001CS 638, Fall 2001 Today Shadow Volume Algorithms Vertex and Pixel Shaders.
(conventional Cartesian reference system)
Status – Week 277 Victor Moya.
Compilation, Architectural Support, and Evaluation of SIMD Graphics Pipeline Programs on a General-Purpose CPU Mauricio Breternitz Jr, Herbert Hum, Sanjeev.
University of British Columbia CPSC 414 Computer Graphics © Tamara Munzner 1 Shading Week 5, Wed 1 Oct 2003 recap: lighting shading.
Computer Graphics Inf4/MSc Computer Graphics Lecture 11 Texture Mapping.
Lighting for Games Kenneth L. Hurley.
Polygon Shading. Assigning color to a shape to make graphical scenes look realistic, or artistic, or whatever effect we’re attempting to achieve But first.
REAL-TIME VOLUME GRAPHICS Christof Rezk Salama Computer Graphics and Multimedia Group, University of Siegen, Germany Eurographics 2006 Real-Time Volume.
COMP 175: Computer Graphics March 24, 2015
Computer Graphics 3 Lecture 4: GPU Programming Benjamin Mora 1 University of Wales Swansea Dr. Benjamin Mora.
Technology and Historical Overview. Introduction to 3d Computer Graphics  3D computer graphics is the science, study, and method of projecting a mathematical.
Programmable Pipelines. Objectives Introduce programmable pipelines ­Vertex shaders ­Fragment shaders Introduce shading languages ­Needed to describe.
CS 638, Fall 2001 Admin Grad student TAs may have had their accounts disabled –Please check and the lab if there is a problem If you plan on graduating.
Environment Mapping. Examples Fall Motivation Silver candlestick No appropriate texture for it “ environment ” map Simulates the results of ray-tracing.
Graphics Graphics Korea University cgvr.korea.ac.kr 1 Using Vertex Shader in DirectX 8.1 강 신 진
Programmable Pipelines. 2 Objectives Introduce programmable pipelines ­Vertex shaders ­Fragment shaders Introduce shading languages ­Needed to describe.
1 SIC / CoC / Georgia Tech MAGIC Lab Rossignac Textures and shadows  Generation  Mipmap  Texture coordinates,
COLLEGE OF ENGINEERING UNIVERSITY OF PORTO COMPUTER GRAPHICS AND INTERFACES / GRAPHICS SYSTEMS JGB / AAS 1 Shading (Shading) & Smooth Shading Graphics.
09/09/03CS679 - Fall Copyright Univ. of Wisconsin Last Time Event management Lag Group assignment has happened, like it or not.
09/11/03CS679 - Fall Copyright Univ. of Wisconsin Last Time Graphics Pipeline Texturing Overview Cubic Environment Mapping.
CS 450: COMPUTER GRAPHICS REVIEW: INTRODUCTION TO COMPUTER GRAPHICS – PART 2 SPRING 2015 DR. MICHAEL J. REALE.
University of British Columbia CPSC 314 Computer Graphics Jan-Apr 2007 Tamara Munzner Blending, Modern Hardware.
MIT EECS 6.837, Durand and Teller 1 The Rendering Pipeline Local Illumination Models MIT EECS Lecture 4, September 17 th 2002.
Rendering Overview CSE 3541 Matt Boggus. Rendering Algorithmically generating a 2D image from 3D models Raster graphics.
Computer Graphics The Rendering Pipeline - Review CO2409 Computer Graphics Week 15.
CS 445 / 645: Introductory Computer Graphics Light.
Advanced Computer Graphics Advanced Shaders CO2409 Computer Graphics Week 16.
Eighty-color-channel lighting Zoltán Márton Cecília Sik Lányi University of Pannonia Egyetem u. 10.
Programming 3D Applications CE Displaying Computer Graphics Week 3 Lecture 5 Bob Hobbs Faculty of Computing, Engineering and Technology Staffordshire.
Programmable Pipelines Ed Angel Professor of Computer Science, Electrical and Computer Engineering, and Media Arts Director, Arts Technology Center University.
1 Perception and VR MONT 104S, Fall 2008 Lecture 21 More Graphics for VR.
A Few Things about Graphics Jian Huang Computer Science University of Tennessee.
Advanced Computer Graphics Spring 2014 K. H. Ko School of Mechatronics Gwangju Institute of Science and Technology.
A User-Programmable Vertex Engine Erik Lindholm Mark Kilgard Henry Moreton NVIDIA Corporation Presented by Han-Wei Shen.
CS 325 Introduction to Computer Graphics 03 / 29 / 2010 Instructor: Michael Eckmann.
Review on Graphics Basics. Outline Polygon rendering pipeline Affine transformations Projective transformations Lighting and shading From vertices to.
11/5/2002 (c) University of Wisconsin, CS 559 Last Time Local Shading –Diffuse term –Specular term –All together –OpenGL brief overview.
11/24/ :45 Graphics II Shadow Maps Reflections Session 5.
COMPUTER GRAPHICS CS 482 – FALL 2015 SEPTEMBER 29, 2015 RENDERING RASTERIZATION RAY CASTING PROGRAMMABLE SHADERS.
09/25/03CS679 - Fall Copyright Univ. of Wisconsin Last Time Shadows Stage 2 outline.
Where We Stand So far we know how to: –Transform between spaces –Rasterize –Decide what’s in front Next –Deciding its intensity and color.
Module 06 –environment mapping Module 06 – environment mapping Module 06 Advanced mapping techniques: Environment mapping.
Mesh Skinning Sébastien Dominé. Agenda Introduction to Mesh Skinning 2 matrix skinning 4 matrix skinning with lighting Complex skinning for character.
Render methods. Contents Levels of rendering Wireframe Plain shadow Gouraud Phong Comparison Gouraud-Phong.
Schedule Update GP 4 – Tesselation/Cg GDS 4 – Subdiv Surf. GP 5 – Object Modeling Lab: Mini-proj Setup GDS 5 – Maya Modeling MCG 6 – Intersections GP 6.
Module 05 –Bump mapping Module 05 – Bump mapping Module 05 Advanced mapping techniques: Bump mapping.
GLSL Review Monday, Nov OpenGL pipeline Command Stream Vertex Processing Geometry processing Rasterization Fragment processing Fragment Ops/Blending.
Texturing Tomas Akenine-Möller Department of Computer Engineering Chalmers University of Technology.
Shaders, part 2 alexandri zavodny.
Programmable Pipelines
Hardware-Based Cell Projection
3D Graphics Rendering PPT By Ricardo Veguilla.
The Graphics Rendering Pipeline
Chapter 14 Shading Models.
© University of Wisconsin, CS559 Fall 2004
Introduction to Programmable Hardware
Where does the Vertex Engine fit?
Chapter XIV Normal Mapping
Texture Mapping 고려대학교 컴퓨터 그래픽스 연구실.
Chapter 14 Shading Models.
Adding Surface Detail 고려대학교 컴퓨터 그래픽스 연구실.
Adding Surface Detail 고려대학교 컴퓨터 그래픽스 연구실.
Presentation transcript:

Lab: Vertex Shading Chris Wynn Ken Hurley

Objective Hands-On vertex shader programming Start with simple programs … Part 1: Textured-Lit Teapot

What you will learn: Exposure to register/instruction set. How to do matrix transformations in a vertex program. How texture coordinates are assigned. How to do simple vertex lighting. OpenGL\src\labs\vertexlab_part1_exercise main.cpp vertex_programs.h …\Effects\TeapotExercise TeapotExercise.cpp TeapotExercise.nvv

The Sample Application Provides Initialization Create and set vertex shader Create vertices, normals, texture coords Create and bind texture Set-up render states and texture combining Every frame Update viewing parameters Render teapot

Textured-Lit Teapot Shader Inputs Constant memory contains c[0]…c[3] contains composite transform matrix. c[4]...c[7] contains the object-to-view matrix. c[8]...c[11] contains the inverse transpose of the. object-to-view matrix. c[12] contains the eye-space light position. c[13] contains the material color. c[14] contains some useful constants.

Textured-Lit Teapot Shader Inputs (cont.) Per-Vertex inputs Position (v0, v[OPOS]) Normal (v1, v[NRML]) Texture coordinates (v2, v[TEX0]) *For OpenGL, v[OPOS] = v[0] v[NRML] = v[2] v[TEX0] = v[8]

Textured-Lit Teapot Shader Program (OpenGL) // Transform position to clip space DP4 o[HPOS].x, c[0], v[OPOS] ; DP4 o[HPOS].y, c[1], v[OPOS] ; DP4 o[HPOS].z, c[2], v[OPOS] ; DP4 o[HPOS].w, c[3], v[OPOS] ; // Set the primary color MOV o[COL0], c[13];

Textured-Lit Teapot Shader Program (DX8) ; Transform position to clip space DP4 oPos.x, v0, c0 DP4 oPos.y, v0, c1 DP4 oPos.z, v0, c2 DP4 oPos.w, v0, c3 ; Set the primary color Mov oD0, c13

Extension: Texturing Add texturing Copy texture coordinates

Texturing Solution MOV oT0, v2 MOV o[TEX0], v[TEX0]; OR MOV o[8], v[8];

Extension: Diffuse Lighting Compute vertex normal dot light direction Multiply result with material color

Diffuse Lighting Solution // 1. Get the position of the vertex in eye-space. (OpenGL) DP4 R0.x, c[4], v[OPOS]; DP4 R0.y, c[5], v[OPOS]; DP4 R0.z, c[6], v[OPOS]; DP4 R0.w, c[7], v[OPOS]; (D3D) DP4 r0.x, c[4], v0 DP4 r0.y, c[5], v0 DP4 r0.z, c[6], v0 DP4 r0.w, c[7], v0

Diffuse Lighting Solution (cont.) // 2. Compute normalized L = light position - vertex position. (OpenGL) ADD R1, c[12], -R0; DP3 R1.w, R1, R1; RSQ R1.w, R1.w; MUL R1.xyz, R1, R1.w; (D3D) ADD r1, c[12], -r0 DP3 r1.w, r1, r1 RSQ r1.w, r1.w MUL r1.xyz, r1, r1.w

Diffuse Lighting Solution (cont.) // 3. Transform the normal to eye-space. (OpenGL) DP4 R2.x, c[8], v[NRML]; DP4 R2.y, c[9], v[NRML]; DP4 R2.z, c[10], v[NRML]; (D3D) DP4 r2.x, c[8], v1 DP4 r2.y, c[9], v1 DP4 r2.z, c[10], v1

Diffuse Lighting Solution (cont.) // 4. Compute N dot L and clamp the result. (OpenGL) DP3 R3, R1, R2; MAX R3, R3, c[14].w; (D3D) DP3 r3, r1, r2 MAX r3, r3, c[14].w

Diffuse Lighting Solution (cont.) // 5. Modulate the material color by NdotL. (OpenGL) MUL o[COL0], c[13], R3; (D3D) MUL oD0, c[13], r3

Part 2: Reflective Teapot What you will learn: Custom texture coordinate generation.

Part 2: Reflective Teapot (cont.) OpenGL\src\labs\vertexlab_part2_exercise main.cpp vertex_programs.h …\Effects\TeapotExercisePart2 TeapotExercise2.cpp TeapotExercise2.nvv

Reflective Teapot Shader Inputs Constant memory contains c[0]…c[3] contains composite transform matrix. c[4]...c[7] contains the object-to-view matrix. c[8]...c[11] contains the inverse transpose of the. object-to-view matrix. c[12] contains the eye-space light position. c[13] contains the material color. c[14] contains some useful constants.

Reflective Teapot Shader Inputs (cont.) Per-Vertex inputs Position (v0, v[OPOS]) Normal (v1, v[NRML]) *For OpenGL, v[OPOS] = v[0] v[NRML] = v[2]

Extension: Reflection vector Start with basic program and compute reflection vector. R = 2 ( N E ) N - E Hints in the code…

Reflection Vector Solution // A1. Get the position of the vertex in eye-space. (OpenGL) DP4 R0.x, c[4], v[OPOS]; DP4 R0.y, c[5], v[OPOS]; DP4 R0.z, c[6], v[OPOS]; DP4 R0.w, c[7], v[OPOS]; (D3D) DP4 r0.x, c[4], v0 DP4 r0.y, c[5], v0 DP4 r0.z, c[6], v0 DP4 r0.w, c[7], v0

Reflection Vector Solution (cont.) // A2. Compute the vector from the eye-space vertex to the camera origin (0,0,0) // A3. Normalize (OpenGL) DP3 R0.w, R0, R0; RSQ R0.w, R0.w; MUL R1.xyz, -R0, R0.w; (D3D) DP3 r0.w, r0, r0 RSQ r0.w, r0.w MUL r1.xyz, -r0, r0.w

Reflection Vector Solution (cont.) // B. Determine the normal vector N (in eye-space). (OpenGL) DP4 R2.x, c[8], v[NRML]; DP4 R2.y, c[9], v[NRML]; DP4 R2.z, c[10], v[NRML]; (D3D) DP4 r2.x, c[8], v1 DP4 r2.y, c[9], v1 DP4 r2.z, c[10], v1

Reflection Vector Solution (cont.) // C. Calculate the reflected vector R = 2*(N dot E)*N - E // R = 2 * ( N dot E )N - E // R1 = E, R2 = N // R4 = 2 * (R2 dot R1)R2 - R1 (OpenGL)(D3D) DP3 R3, R2, R1;DP3 r3, r2, r1 MUL R3, R3.x, R2;MUL r3.xyz, r3.x, r2 MUL R3, c[14].z, R3;MUL r3.xyz, c[14].z, r3.xyz ADD R4, R3, -R1;ADD r4.xyz, r3, -r1 MOV o[TEX0].xyz, R4;MOV oT0.xyz, r4.xyz

Part 3: Diffuse Bump-mapping setup What you will learn: Basics of per-pixel bump-mapping. How to implement “tangent space” computations in a vertex shader program.

Part 3: Diffuse Bump-mapping setup

Basics of per-pixel bump-mapping Basic idea: Provide a normal per-pixel. Provide other lighting parameters on a per-pixel basis (light vector, halfangle-vector, etc.) Compute a lighting equation using operations performed on a per-pixel basis Typically compute Phong diffuse and specular lighting: intensity = (NL) + (NH) m

Basics of per-pixel bump-mapping How this is done in real-time: Encode normals into an RGB texture. Map the “normal map” texture onto a model using standard 2D texture mapping. Additionally, compute L and/or H vectors on a per- vertex basis and interpolate these across a triangle. Compute the necessary dot-products using texture combining hardware (ex. Texture combiners) Phong diffuse and specular lighting: intensity = (NL) + (NH) m

Basics of per-pixel bump-mapping Computing Dot Products in a Common Space: When computing dot products, L, H, and N must be in the same coordinate space World, Eye, other. One convenient space for per-pixel lighting operations is called Texture Space Z axis of Texture Space is roughly parallel to the surface normal at a vertex X and Y axes are perpendicular to the Z axis and can be arbitrarily oriented around the Z axis

Basics of per-pixel bump-mapping Texture Space gives us a way to redefine the lighting coordinate system on a per-vertex basis SxT S T T S S T T

Basics of per-pixel bump-mapping It also allows us to define our normal maps in texture space. If we didn’t use texture space as for computing the per-pixel dot products, we’d either: 1. Have to define the normal map in some other space (and recompute the normal map each frame) 2. Define the normal map in texture space, but perform a per-pixel transformation to take the normal into the correct space.

Basics of per-pixel bump-mapping Texture space is convenient (so we use it). To compute N L or N H on a per-pixel basis, L and H must be provided in texture space for each pixel This means we must rotate the L and H vectors into texture space at each vertex (and use an appropriate form of linear interpolation to generate texture L and H vectors per-pixel)

Part 3: Diffuse Bump-mapping setup In this lab you will do the per-vertex math necessary for performing simple N L per-pixel lighting. Specifically you will: Pass through (s,t) texture coordinates for the normal map. Compute a light position in world space. Derive a world-space L vector. Rotate the L vector from world-space to texture space and provide this as texture coords for a normalization cube-map

Part 3: Diffuse Bump-mapping setup The per-vertex basis is given as T, B, N. The matrix for rotating a vector into this space is: Given an L vector in world-space, can transform to local-space using 3 dot products.

Part 3: Bump-mapping setup OpenGL\src\labs\vertexlab_part3_exercise main.cpp vertex_programs.h …\Effects\TeapotExercisePart3 TeapotExercise3.cpp TeapotExercise3.nvv

Questions, comments, feedback Chris Wynn Matthias Wloka