CIS 665 GPU Programming and Architecture

Similar documents
Spring 2012 Final. CS184 - Foundations of Computer Graphics. University of California at Berkeley

CG Surfaces: Materials, Shading, and Texturing

Approximate Catmull-Clark Patches. Scott Schaefer Charles Loop

CHAPTER 1 Graphics Systems and Models 3

Information Coding / Computer Graphics, ISY, LiTH. Splines

Interactive Computer Graphics A TOP-DOWN APPROACH WITH SHADER-BASED OPENGL

CIS 665 GPU Programming and Architecture

Interpolation and Basis Fns

2D Spline Curves. CS 4620 Lecture 13

Illumination and Shading

Homework #2. Shading, Projections, Texture Mapping, Ray Tracing, and Bezier Curves

CS559 Computer Graphics Fall 2015

CS 130 Final. Fall 2015

Interpolation and Basis Fns

Shading Languages. Seminar Computer Graphics. Markus Kummerer

lecture 18 - ray tracing - environment mapping - refraction

GLOBAL EDITION. Interactive Computer Graphics. A Top-Down Approach with WebGL SEVENTH EDITION. Edward Angel Dave Shreiner

Objects 2: Curves & Splines Christian Miller CS Fall 2011

Shape modeling Modeling technique Shape representation! 3D Graphics Modeling Techniques

Splines. Parameterization of a Curve. Curve Representations. Roller coaster. What Do We Need From Curves in Computer Graphics? Modeling Complex Shapes

3D Modeling techniques

Lecture 17: Shading in OpenGL. CITS3003 Graphics & Animation

Lecture 10: Shading Languages. Kayvon Fatahalian CMU : Graphics and Imaging Architectures (Fall 2011)

2D Spline Curves. CS 4620 Lecture 18

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

Computer Graphics I Lecture 11

Chapter 7 - Light, Materials, Appearance

Light Sources. Spotlight model

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

Computer Animation. Rick Parent

Fall CSCI 420: Computer Graphics. 4.2 Splines. Hao Li.

Homework 3: Programmable Shaders

Until now we have worked with flat entities such as lines and flat polygons. Fit well with graphics hardware Mathematically simple

OpenGl Pipeline. triangles, lines, points, images. Per-vertex ops. Primitive assembly. Texturing. Rasterization. Per-fragment ops.

For each question, indicate whether the statement is true or false by circling T or F, respectively.

Chapter IV Fragment Processing and Output Merging. 3D Graphics for Game Programming

CIS 665 GPU Programming and Architecture

Methodology for Lecture. Importance of Lighting. Outline. Shading Models. Brief primer on Color. Foundations of Computer Graphics (Spring 2010)

Computer Graphics Coursework 1

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

CSE 167: Introduction to Computer Graphics Lecture 12: Bézier Curves. Jürgen P. Schulze, Ph.D. University of California, San Diego Fall Quarter 2013

CMSC 435/634: Introduction to Graphics

Rendering. Illumination Model. Wireframe rendering simple, ambiguous Color filling flat without any 3D information

Topics and things to know about them:

Central issues in modelling

Computer Graphics Introduction. Taku Komura

Approximating Catmull-Clark Subdivision Surfaces with Bicubic Patches

Kochanek-Bartels Cubic Splines (TCB Splines)

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

Lets assume each object has a defined colour. Hence our illumination model is looks unrealistic.

In this course we will need a set of techniques to represent curves and surfaces in 2-d and 3-d. Some reasons for this include

AGDC Per-Pixel Shading. Sim Dietrich

Objectives. Shading II. Distance Terms. The Phong Reflection Model

Computergrafik. Matthias Zwicker Universität Bern Herbst 2016

CPSC / Texture Mapping

(Spline, Bezier, B-Spline)

Approximating Subdivision Surfaces with Gregory Patches for Hardware Tessellation

Interactive Graphics. Lecture 9: Introduction to Spline Curves. Interactive Graphics Lecture 9: Slide 1

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

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

CS 559 Computer Graphics Midterm Exam March 22, :30-3:45 pm

Fast Third-Order Texture Filtering

CS452/552; EE465/505. Lighting & Shading

Announcements. Written Assignment 2 is out see the web page. Computer Graphics

Computer Graphics CS 543 Lecture 13a Curves, Tesselation/Geometry Shaders & Level of Detail

Final Exam CS 184: Foundations of Computer Graphics page 1 of 14 Fall 2016 Prof. James O Brien

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

The University of Calgary

CS GPU and GPGPU Programming Lecture 16+17: GPU Texturing 1+2. Markus Hadwiger, KAUST

Computer Graphics. Illumination and Shading

Rational Bezier Curves

Mathematical Tools in Computer Graphics with C# Implementations Table of Contents

Sung-Eui Yoon ( 윤성의 )

CS 464 Review. Review of Computer Graphics for Final Exam

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

Raytracing CS148 AS3. Due :59pm PDT

3D GRAPHICS. design. animate. render

Illumination and Shading

Computer Graphics (CS 543) Lecture 8a: Per-Vertex lighting, Shading and Per-Fragment lighting

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

CS 498 VR. Lecture 19-4/9/18. go.illinois.edu/vrlect19

Pipeline Operations. CS 4620 Lecture 14

Computer Graphics Curves and Surfaces. Matthias Teschner

6.837 Introduction to Computer Graphics Quiz 2 Thursday November 20, :40-4pm One hand-written sheet of notes allowed

Effective Use of Procedural Shaders in Animated Scenes

CSE 167: Introduction to Computer Graphics Lecture #11: Bezier Curves. Jürgen P. Schulze, Ph.D. University of California, San Diego Fall Quarter 2016

EECS 487, Fall 2005 Exam 2

Computergrafik. Matthias Zwicker. Herbst 2010

CS GAME PROGRAMMING Question bank

Spline Morphing. CG software practical course in the IWR. Carl Friedrich Bolz. Carl Friedrich Bolz

COMP environment mapping Mar. 12, r = 2n(n v) v

-=Bui Tuong Phong's Lighting=- University of Utah, but with shaders. Anton Gerdelan Trinity College Dublin

Technical Report. Anisotropic Lighting using HLSL

Computer Graphics (CS 4731) Lecture 18: Lighting, Shading and Materials (Part 3)

AMCS / CS 247 Scientific Visualization Lecture 10: (GPU) Texture Mapping. Markus Hadwiger, KAUST

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

Interactive Cloth Simulation. Matthias Wloka NVIDIA Corporation

Complex Shading Algorithms

Review of Tuesday. ECS 175 Chapter 3: Object Representation

Real-Time Hair Rendering on the GPU NVIDIA

Transcription:

Homework #2 Due: June 6/3/09 CIS 665 GPU Programming and Architecture 1) Bezier Curves & Color Shaping (30 points) Background: The concept of color shaping was introduced in Lecture 2 as a demonstration of shading that exceeds the capabilities of the fixed function pipeline. Recall that color shaping is a technique where lighting terms (specular, diffuse, rim, reflection, etc.) are used to mix a palette of colors. In the example presented in class, simple color shaping is achieved by passing two diffuse and specular colors to the fragment shader (Kd0, Kd1, Ks0, and Ks1), and using the specular and diffuse terms to drive a linear interpolation between the two sets of colors: // Compute the diffuse term float3 diffuse = lerp(kd0,kd1,diffuselight) *lightcolor*diffuselight; // Compute the specular term float3 specular=lerp(ks0,ks1,specularlight)*lightcolor*specularlight; Linear interpolation (lerp) is limited in that when applied to more than two colors (using several lerp s), Mach Bands can occur in the resulting image (bands of perceptually exaggerated contrast at discontinuities in color). To support more colors and eliminate Mach Bands, we can choose a higher-order interpolation function. A favorite choice in computer graphics is the cubic polynomial. In particular, Bezier curves provide a high degree of control and continuity. An efficient formulation for calculating the Bezier curve interpolation of four values (control points) is as follows: DeCasteljau s Algorithm: Given values b0, b1, b2, b3, and curve parameter t: 1. Linearly interpolate between points b0 and b1 using parameter t. 2. Linearly interpolate between points b1 and b2 using parameter t. 3. Linearly interpolate between points b2 and b3 using parameter t. 4. Linearly interpolate between the results of step 1 and 2 using parameter t. 5. Linearly interpolate between the results of step 2 and 3 using parameter t. 6. Linearly interpolate between the results of step 4 and 5 using parameter t. 7. The result of step 6 is the Bezier curve point at t.

Problem: Modify the plastic_color_shape_fragment_sphere program (available on the course website) to perform color shaping on the diffuse and specular lighting components using Bezier curves rather than lerp. This will entail modifying the demo.cpp code to pass Kd0, Kd1, Kd2, Kd3, Ks0, Ks1, Ks2, and Ks3 as uniform parameters, adding a Bezier function to the fragment program, and modifying to color shaping calls as follows: diffuse = Bezier(Kd0,Kd1,Kd2,Kd3,diffuseLight) *.. specular =Bezier(Ks0,Ks1,Ks2,Ks3,specularLight)*.. Example Images: Kd0.9.9.9 Ks0.9.9.9 Kd0.9 0 0 Ks0.9 0.9 Kd1.9.9.9 Ks1.9.9.9 Kd1.9 0 0 Ks1.9 0.9 Kd2 0 0.9 Ks2 0 0.9 Kd2 0 0.9 Ks2.9.9.9 Kd3.9 0 0 Ks3.9.9.9 Kd3 0.9 0 Ks3.9 0 0

2) Ward Shading Model (Anisotropic Highlights) (40 points) Background: Read the following excerpt from Advanced Renderman, explaining the formulation for the Ward Shading Model:

Problem: Modify the plastic_fragment_sphere program (available on the course website) to implement Ward s formulation for anisotropic specular highlights. This will involve passing uniform xroughness and y roughness parameters to the fragment program, calculating and passing the surface tangents as varying parameters to the vertex program, and coding the above equation in the fragment program (Hint: the cosine of an angle is equivalent to the dot product of unit vectors). The tangents can be calculated as follows: The demo.cpp code creates a sphere by discretely evaluating the following parametric equation: P x = sin(πu) * sin(2πv) P y = sin(πu) * cos(2πv) P z = cos(πu) The tangents can be derived by taking the partial derivates of the parametric equation with respect to u and v: U Tangent: V Tangent: dp x /du = π * cos(πu) * sin(2πv) dp x /dv = sin(πu) * 2π * cos(2πv) dp y /du = π * cos(πu) * cos(2πv) dp y /dv = sin(πu) * -2π * sin(2πv) dp z /du = -π * sin(πu) dp z /dv = 0 Using these equations, modify DrawGeometry() and ParametricEval() to calculate the U and V tangents and pass them as varying parameters to the Cg vertex program. Example Images (Spinning sphere): xroughness = 0.15, yroughness = 0.45 xroughness = 0.45, yroughness = 0.15

3. GPGPU: Simple Matrix Operations (30 points) a) Implement a GPGPU algorithm in CG to add two n x m matrices b) Implement a GPGPU algorithm in CG to subtract two n x m matrices Your program should prompt the user to input a text file containing the matrices. Your program should prompt the user the filename to save the result matrix. (Please google c++ file reading if you re unfamiliar with it) The file format is as follows: Operation #start of first matrix Dimensions Data #start of second matrix Dimensions Data #end of operation Example: + #start of first matrix 3 4 1 2 3 4 2 3 4 5 5 6 1 3 #start of second matrix 3 4 1 0 0 0 0 1 0 0 0 0 1 0 #end of operation Hint: Load the data from a file into an array. Then load that data into a texture and send it down to the GPU.

4. Extra Credit: Color Splines (25 points) While lerp and Bezier curves have provided our Cg shaders with rudimentary color shaping abilities, most production level shading uses a more power formulation: the Color Spline (A spline is a series of curves combined end to end). Conceptually, a one can think of a Color Spline as a list of colors and positions that define knots along an interpolation function. For Maya users, you may recognize Color Splines as Ramps. For Renderman Arist Tools (RAT) users, you d recognize them from the ColorSpline slim template: Renderman Artist Tools Color Spline Maya Hypershade s Ramp We will be reproducing the implementation of the Renderman Artist Tools (RAT) Color Spline (developed by Pixar Animation Studios). Their Color Spline is actually two splines, one which interpolates the positions of the color knots, and one which interpolates the actual colors of the knots. Each is implemented as a Catmull-Rom spline. Catmull-Rom Splines Catmull-Rom splines are composed of a list of input values which form the beginning and end control points of a series of Bezier curves. The inner two control points of each Bezier curve are interpolated from the surrounding input values via the following formula:

Given input points P 0 through P n, the four Bezier curve control points for each pair P i-1 and P i are computed as follows: b0 = P i-1 b1 = P i-1 + ((P i - P i-2 ) / 6 ) b2 = P i - ((P i+1 - P i-1 )/ 6 ) b3 = P i Note that this formula requires points P -1 and P n+1, which are not given. These points can be extrapolated using the following equation: P -1 = (P 1 - P 0 ) / 2 P n+1 = (P n - P n-1 ) / 2 For the purpose of a color splines, it is useful to index the Catmull-Rom spline with a parameter t that ranges from 0 to 1. Using this parameter we can decide which of the spline curves to evaluate and at what value u. If there are N input points to the Catmull- Rom spline, there will be N-1 curves. Thus, we will evaluate the max(floor((n-1)*t)+1,n- 1) th curve at value u = ((N-1)*t) - floor((n-1)*t). RAT Color Splines The user provides a Color spline with N rgb colors (C 0 through C n-1 ), N float positions (K 0 through K n-1,between 0 and 1), and a parameter t used to index the spline. A new paramter k is calculated as catmull_rom(k 0 through K n-1, t). The final color is calculated as catmull_rom(c 0 through C n-1, k). In practice, support for an arbitrary N colors and positions is cumbersome on a GPU. For simplicity we will implement Color Splines where N = 8 (Any more knots runs the risk of causing aliasing anyway). Modify your solution to problem 1 to perform color spline color shaping. You will need to pass Kd0 through Kd7, Kd0_k though Kd7_k, Ks0 through Ks7, and Ks0_k though Ks7_k to the fragment program. You will need to write a catmull_rom function (for floats and float3 s), as well as a color_spline function in the fragment program. They should be called as follows: diffuse = color_spline(kd0,kd1,kd2,kd3,kd4,kd5,kd6,kd7,kd8, Kd0_k,Kd1_k,Kd2_k,Kd3_k,Kd4_k,Kd5_k,Kd6_k,Kd7_k,Kd8_k, diffuselight) *.. specular = color_spline(ks0,ks1,ks2,ks3,ks4,ks5,ks6,ks7,ks8, Ks0_k,Ks1_k,Ks2_k,Ks3_k,Ks4_k,Ks5_k,Ks6_k,Ks7_k,Ks8_k, specularlight) *..

References 1. Apodaca A., Gritz L., Barzel R., Calahan S., Hanson C., Johnson S. Advanced Renderman Creating CGI for Motion Pictures. Morgan Kaufman Publishers, 2000. 2. Ward, G., Measuring and Modeling Anisotropic Reflection. Computer Graphics, Vol. 26, No. 2, July 1992. 3. C. Everitt. Order-Independent Transparency. http://developer.nvidia.com/object/interactive_order_transparency.html 4. Henning Mortveit, Reflections from Bumpy Surfaces. Shader X3. Charles River Media, Inc. 2005.