Programmable Shading May 15, 2006.

Slides:



Advertisements
Similar presentations
COMPUTER GRAPHICS SOFTWARE.
Advertisements

Bump Mapping CSE 781 Roger Crawfis.
Graphics Pipeline.
Shading CMSC 435/634. RenderMan Light Displacement Surface Volume Imager.
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.
The Programmable Graphics Hardware Pipeline Doug James Asst. Professor CS & Robotics.
CS5500 Computer Graphics © Chun-Fa Chang, Spring 2007 CS5500 Computer Graphics April 19, 2007.
GLSL I May 28, 2007 (Adapted from Ed Angel’s lecture slides)
Shading Languages Yung-feng Chiu. 2 Agenda Introduction Pixar’s RenderMan, MS’s HLSL, NV’s CgFX, ATI’s RenderMonkey Demos.fx file Comparsion.
Status – Week 277 Victor Moya.
Mohan Sridharan Based on slides created by Edward Angel GLSL I 1 CS4395: Computer Graphics.
Shading Languages By Markus Kummerer. Markus Kummerer 2 / 19 State of the Art Shading.
CS6500 Adv. Computer Graphics © Chun-Fa Chang, Spring 2003 RenderMan & Its Shading Language.
1cs426-winter-2008 Notes  RenderMan resources up on the website  We will be using Pixie this term Check on the website soon (installed on CS linux.
Programmable Shading May 21, Motivation Recall what are done in the graphics pipeline: –Front End: Transformations (Modeling, Viewing, and Projection)
GPU Graphics Processing Unit. Graphics Pipeline Scene Transformations Lighting & Shading ViewingTransformations Rasterization GPUs evolved as hardware.
Under the Hood: 3D Pipeline. Motherboard & Chipset PCI Express x16.
REAL-TIME VOLUME GRAPHICS Christof Rezk Salama Computer Graphics and Multimedia Group, University of Siegen, Germany Eurographics 2006 Real-Time Volume.
RenderMan (Shading Language: Concepts)
What is ? Open Graphics Library A cross-language, multi-platform API for rendering 2D and 3D computer graphics. The API is used to interact with a Graphics.
Under the Hood: 3D Pipeline. Motherboard & Chipset PCI Express x16.
Programmable Pipelines. Objectives Introduce programmable pipelines ­Vertex shaders ­Fragment shaders Introduce shading languages ­Needed to describe.
Programmable Pipelines. 2 Objectives Introduce programmable pipelines ­Vertex shaders ­Fragment shaders Introduce shading languages ­Needed to describe.
Shading. What is Shading? Assigning of a color to a pixel in the final image. So, everything in shading is about how to select and combine colors to get.
Computer Graphics. Requirements Prerequisites Prerequisites CS 255 : Data Structures CS 255 : Data Structures Math 253 Math 253 Experience with C Programming.
CSE 690: GPGPU Lecture 6: Cg Tutorial Klaus Mueller Computer Science, Stony Brook University.
Kansas State University Department of Computing and Information Sciences CIS 736: Advanced Computer Graphics Monday, 24 April 2006 Shaun Budhram (Slides.
RenderMan Introduction CS 551/645 Fall Evaluate Me! Please visit the SEAS main website and use the ‘Course Evaluations’ button to rate this class.
Shadow Mapping Chun-Fa Chang National Taiwan Normal University.
Programmable Pipelines Ed Angel Professor of Computer Science, Electrical and Computer Engineering, and Media Arts Director, Arts Technology Center University.
CSE 381 – Advanced Game Programming GLSL. Rendering Revisited.
Review on Graphics Basics. Outline Polygon rendering pipeline Affine transformations Projective transformations Lighting and shading From vertices to.
OpenGL Shading Language (GLSL)
Computing & Information Sciences Kansas State University Lecture 12 of 42CIS 636/736: (Introduction to) Computer Graphics CIS 636/736 Computer Graphics.
COMPUTER GRAPHICS CS 482 – FALL 2015 SEPTEMBER 29, 2015 RENDERING RASTERIZATION RAY CASTING PROGRAMMABLE SHADERS.
Advanced rendering techniques 4/2/02. Rendering for animation The big difference: real time vs. off-line Real time: sacrifice quality for performance.
09/25/03CS679 - Fall Copyright Univ. of Wisconsin Last Time Shadows Stage 2 outline.
Ray Tracing using Programmable Graphics Hardware
What are shaders? In the field of computer graphics, a shader is a computer program that runs on the graphics processing unit(GPU) and is used to do shading.
GLSL I.  Fixed vs. Programmable  HW fixed function pipeline ▪ Faster ▪ Limited  New programmable hardware ▪ Many effects become possible. ▪ Global.
GLSL Review Monday, Nov OpenGL pipeline Command Stream Vertex Processing Geometry processing Rasterization Fragment processing Fragment Ops/Blending.
Graphics Pipeline Bringing it all together. Implementation The goal of computer graphics is to take the data out of computer memory and put it up on the.
Shader.
Computer Graphics.
Photorealistic Rendering vs. Interactive 3D Graphics
Visualization Shading
Programmable Pipelines
Graphics Processing Unit
Chapter 6 GPU, Shaders, and Shading Languages
The Graphics Rendering Pipeline
Understanding Theory and application of 3D
Real-time Computer Graphics Overview
Models and Architectures
Models and Architectures
Models and Architectures
Introduction to Computer Graphics with WebGL
GLSL I Ed Angel Professor of Computer Science, Electrical and Computer Engineering, and Media Arts Director, Arts Technology Center University of New Mexico.
Chapter VI OpenGL ES and Shader
Graphics Processing Unit
Joshua Barczak* CMSC 435 UMBC
Models and Architectures
CS5500 Computer Graphics April 17, 2006 CS5500 Computer Graphics
ICG 2018 Fall Homework1 Guidance
Models and Architectures
Programming with OpenGL Part 3: Shaders
CIS 441/541: Introduction to Computer Graphics Lecture 15: shaders
CS 480/680 Computer Graphics GLSL Overview.
Computer Graphics Shading in OpenGL
OpenGL-Rendering Pipeline
CS 480/680 Fall 2011 Dr. Frederick C Harris, Jr. Computer Graphics
Presentation transcript:

Programmable Shading May 15, 2006

Motivation Recall what are done in the graphics pipeline: Front End: Transformations (Modeling, Viewing, and Projection) and Lighting. Back End: Rasterization and Interpolations (of Colors, Depth, and Texture Coordinates) What are their input/output parameters?

OpenGL Fixed Function Vertex Vertex (object) Vertex (clip) Transform [MVP],[MV],[MV]-T Normal Vertex (eye) Color SecondaryColor Front&Back Color [0,1] Lighting Front&Back SecondaryColor [0,1] Texgen Texture Matrixn TexCoordn TexCoordn EdgeFlag EdgeFlag

OpenGL Fixed Function Fragment Color SecondaryColor Tex n TEn Sum Fog TexCoord[n] Color [0,1] z (|ze|,f ) Depth Depth Coord Coord FrontFacing FrontFacing

Programmable Shading Why not doing something different with those input? Case in focus: bump mapping Bump mapping simulates detail with a surface normal that varies across a surface.

RenderMan & Its Shading Language

Key Idea of a Shading Language Image synthesis can be divided into two basic concerns Shape: Geometric Objects, Coordinates, Transformations, Hidden-Surface Methods… Shading: Light, Surface, Material, Texture, … Control shading not only by adjusting parameters and options, but by telling the shader what you want it to do directly in the form of a procedure

Pixar’s RenderMan Separation of Modeling and Rendering RenderMan serves as the interface. Scene = Shape + Shading The power of RenderMan is in the shading part.

Example #1 #include <ri.h> RtPoint Square[4]={{.5,.5,.5},{.5,-.5,.5}, {-.5,-.5,.5},{-.5,.5,.5}}; Main(){ RiBegin(RI_NULL); RiWorldBegin(); RiSurface(“constant”, RI_NULL); RiPolygon(4, RI_P, (RtPointer)Square, RI_NULL); RiWorldEnd(); RiEnd(); }

Example #2 Colorspheres.c in the BMRT/examples folder.

Building and Running Must have the following: Header file: ri.h Link library A renderer The program generates a “RenderMan Interface” file, but doesn’t render it So that you may pick a renderer that matches the graphics power of your machine.

Pixar’s RenderMan RIB File .rib Rman cc Geom Program Code render Shader .sl (slc) Byte-code .slc RIB File .rib render (rendrib) TIFF image texture Image txmake

RenderMan’s RIB File Structure Options global to the entire animation Frame Block Image options Camera options World Block Attributes, lights, primitives Changed Options Another world block Next frame block

Comparison to OpenGL It doesn’t do the actual rendering. Separation of modeling and rendering. It’s the task of the renderer. RiSurface() changes the graphics state Similar to glColor() RiPolygon() to describe the models Similar to glBegin(GL_POLYGON)

Why C? Binding to other programming language is also possible. (My guess) Maybe just to avoid writing a compiler for its own scripting language…

RenderMan Interface Spec Where do you find the meaning of the arguments to those Ri…() functions? Check the spec! (available directly from Pixar). Appendix G contains a quick reference. http://www.pixar.com/renderman/developers_corner/rispec/rispec_pdf/RISpec3_2.pdf

BMRT A public-domain implementation of Pixar Photorealistic RenderMan (PRMan). Three main components: Rendrib: the renderer Rgl: quick rendering for preview Slc: shading language compiler

Shading Language Many types of shaders are possible: Light source shaders Surface shaders Atmosphere shaders Volume shaders…etc. We will discuss only the surface shaders.

Shader Writing Global variables: (from Table 14.2 of The RenderMan Companion book) Camera position, surface color/opacity, surface position/normal, texture coordinates…etc. Must output: color of light from surface, opacity of surface. Many built-in operators (Table 14.4) and functions (Ch.15, Tables 15.1-15.2).

Example: Plastic Surface plastic (float Ka = 1, Kd = 0.5, Ks = 0.5, roughness = 0.1; color specularcolor = 1) { normal Nf = faceforward (normalize(N),I); Ci = Cs * (Ka*ambient() + Kd*diffuse(Nf)) + specularcolor * Ks*specular(Nf,-normalize(I),roughness); Oi = Os; Ci *= Oi; }

RenderMan’s Shader Phong shader surface phong( float Ka = 1, Kd =1, Ks = 0.5; float roughness = 0.1; color specularcolor = 1; ) { normal Nf = faceforward( normalize(N), I ); vector V = -normalize(I); color C = 0; illuminance( P ) { vector R = 2*normalize(N)* (normalize(N) . normalize( L )) - normalize( L ); C += Ka*Cs + Kd*Cs*( normalize(N) . normalize(L) ) + Ks*specularcolor* pow(( R . V ), 10); } Ci = C*Cs;

Gallery of Shaders Procedural textures: e.g., wood Bump mapping and displacement mapping. For more, see Ch. 16 of The RenderMan Companion See also the shaders and examples folders of BMRT.

Shading Languages for Graphics Hardware

Bump Map Example Bump mapping simulates detail with a surface normal that varies across a surface

RenderMan Example displacement lumpy ( float Km = 1, frequency = 1, maxoctaves = 6; string shadingspace = "shader"; float truedisp = 1;) { point Pshad = transform (shadingspace, frequency*P); float dPshad = filterwidthp(Pshad); float magnitude = fBm (Pshad, dPshad, maxoctaves, 2, 0.5); N = Displace (normalize(N), shadingspace, Km*magnitude, truedisp); }

Cg Example f2fb DiffuseBumpPS(v2f IN, uniform sampler2D DiffuseMap, uniform sampler2D NormalMap, uniform float4 bumpHeight) { f2fb OUT; float4 color = tex2D(DiffuseMap); //fetch base color //fetch bump normal float4 bumpNormal = expand(tex2D(NormalMap)) * bumpHeight; //expand iterated light vector to [-1,1] float4 lightVector = expand(passthrough(IN.LightVector)); //compute final color (diffuse + ambient) float4 bump = uclamp(dot3_rgba(bumpNormal.xyz, lightVector.xyz)); OUT.col = color * bump; return OUT; }

GL2 Logical Diagram

OpenGL Fixed Function Vertex Vertex (object) Vertex (clip) Transform [MVP],[MV],[MV]-T Normal Vertex (eye) Color SecondaryColor Front&Back Color [0,1] Lighting Front&Back SecondaryColor [0,1] Texgen Texture Matrixn TexCoordn TexCoordn EdgeFlag EdgeFlag

GL2 Vertex Processor Uniform Vertex Shader Temporaries Vertex (object) Vertex (clip) Uniform Normal Vertex (eye) Color SecondaryColor Vertex Shader Front&Back Color Front&Back SecondaryColor TexCoordn Temporaries TexCoordn EdgeFlag EdgeFlag

OpenGL Fixed Function Fragment Color SecondaryColor Tex n TEn Sum Fog TexCoord[n] Color [0,1] z (|ze|,f ) Depth Depth Coord Coord FrontFacing FrontFacing

GL2 Fragment Processor Uniform Texture Fragment Shader Temporaries Color Uniform Texture SecondaryColor Fragment Shader TexCoord[n] Color z (|ze|,f ) Depth Depth Temporaries Coord Coord FrontFacing FrontFacing

Comparison RenderMan OpenGL 2.0 D3D VS (2.0/3.0) D3D PS (2.0/3.0) Program Size No limit 256/256 >=16 16/16 >= 40 interpolators 10/10 12/16 Yes Yes/Yes No/Yes No/No Vertex Attributes VS:>=512 floats PS: >= 64 floats 128/256 32/128 Constants Varying Parameters Texture Samplers Temp Registers Constant-Based Flow Control Variable-Based Flow Control