CGT521 Introduction to Bedrich Benes, Ph.D. Purdue University Department of Computer Graphics Rendering We have a virtual scene (a model in the memory of computer) and we want to display it What is the color of a pixel? Rendering Physics-based method: Ray tracing, Mote-Carlo Path Tracing, Photon maps, Metropolis light transport Use physics to calculate the light path based on ideas of Dürer and da Vinci (dated back to the early Renaissance) introduced by Whitted in 1980 Appel 1981 the first implementation today de facto standard in global illumination it is a recursive algorithm 4
real world but many rays do not reach the eye! simulation is very expensive let's trace ONLY the rays that go to eye 5 6 Principle for each pixel of the image do: trace the ray into the scene get the first hit object //visibility evaluate its illumination cast shadow rays //shadows trace the reflected ray (if any) trace the refracted ray (if any) accumulate the results also called the Whitted illumination model primary ray shadow rays 7 8
RT simulates specular to specular reflection mirrors are perfect ("quick fixies") RT is an image space algorithm i.e., it is driven by the viewport Contribution 1 k spec =0.5 1/16 RT is recursive as long as specular to specular reflection occurs tracing terminates if no specular surface is hit (specular to diffuse) contribution is too small too deep recursion ray out of the scene ½ ¼ 1/8 9 10 main CalculateRay the main procedure for (i=0;i<resx;i++) for (j=0;j<resy;j++){ ray=calculateray(); //get the primary ray color=traceray(ray,maxdepth); SetPixel(i,j)=color; //set the color of the pixel } the CalculateRay procedure camera concept (luv vectors) Given: lookat and eye (points) up vector up Gramm Schmidt u orthonormalization l=(lookat eye)/ lookateye eye v=(lxup)/ lxup l u=vxl v 11 lookat 12
CalculateRay we can put lens in front of the camera to get fish eye camera objective ShadowRay ShadowRay returns all visible lights it is easier than intersections we just need to know if there is some obstacle we do not care about intersection and normal we can exploit coherency and use the light buffer (see the next lecture) 13 14 Ray Casting Special case: Trace(ray,0) Ray Casting is called RayCasting the primary rays are cast through the pixels the local illumination is calculated for the visible lights it calculates shadows it does not calculate reflections This is NOT z buffer 15 16
MAXDEPTH=1 MAXDEPTH=3 MAXDEPTH=2 MAXDEPTH=4 17 18 MAXDEPTH=10 Intersections 80 90% of time is consumed for the intersections calculations improving efficiency focuses intersections MAXDEPTH=100 19 20
Open Graphics Library is an API (application programming interface) a software interface to graphics hardware a layer between the programmer and the graphics hardware Graphics Assembly Language Introduction to OpenGL 1980 Iris GL (Silicon Graphics), more than 2000 apps on SGI computers (Industrial Light Magic, Ford, Boeing, Alias Wavefront, etc.) 1992 OpenGL 1.0 hardware independent 15.8.2001 OpenGL 1.3 standard under Windows, X-Window (UNIX), Mac OS, Palms, etc. Introduction to OpenGL Capabilities: 1.x - Fixed pipeline 2.x - Programmable pipeline (GLSL) 3.x - Geometry shader 4.x Tesselation shader, double precission Introduction to OpenGL (contd.) September 2016 OpenGL 4.5 Today: Managed by the Khronos Group http://www.khronos.org/
Who makes OpenGL? Library definition Who makes OpenGL? Library programming Architecture Review Board (ARB) ARB is a part of Khronos Group Leading HW and SW companies OpenGL is a trademark of SGI A company develops a HW component NVIDIA, AMD, Intel They need to pass the OpenGL Performance Characterization Committee benchmarks http://www.spec.org/gwpg/gpc.static/index.html Who makes OpenGL? Application programming Whoever develops app using OpenGL App developers do not need to register OpenGL or pay fees OpenGL is for free for the users OpenGL A most widely adopted graphics standard High quality visual performance Stable, reliable, portable, and scalable Reflects latest advanced in development Easy to use Well documented Available everywhere
Hardware Requirements Must be pixel-oriented (OpenGL does not work on plotters) graphics acceleration is NOT required...but is desirable the graphics accelerators are called GPUs Full CPU implementations of OpenGL exist (http://www.mesa3d.org/) A side note OpenGL is not pixel exact Two implementations can vary in the result Speed is more important than precision OpenGL and Other Libraries API Hierarchy OpenGL is minimal Everything else is put into OpenGL Utility Library or GLU many additional libraries Some of them is Free Graphics Library Utility Toolkit GLUT (more later) OpenGL cannot open a window www.opengl.org
How does OpenGL work? Files the OpenGL API is gl.h the other libraries are glu.h and glut.h typically located in include/gl/ OpenGL drivers under Windows are in windows/system32/opengl32.dll www.opengl.org as well as glu32.dll and glut32.dll Command syntax Command syntax (contd.) type prefix example procedure call gl glfogf() constant GL_ GL_FOG_COLOR data type GL GLfloat example: prefix gluniform1f(1.f) command arguments Suffix Data type typical C OpenGL definition b 8bit integer signed char GLbyte s 16bit integer short GLshort i 32bit integer int GLint,GLsizei ub 8bit uns.int unsigned char GLubyte,GLboolean us 16bit uns.int unsigned short GLushort ui 32bit uns.int unsigned long GLuint,GLenum,GLbitfield f 32bit float float GLfloat,GLclampf d 64bit float double GLdouble,GLclampd
Command syntax (contd.) The v syntax some commands end with v the argument is a pointer to a vector GLfloat r=1.f, g=1.f, b=1.f; GLfloat x[]={1.f,1.f,1.f}; glcolor3f(r,g,b); glcolor3fv(x); Both have the same effect The wildcard agreement Commands with the same effect and different arguments, for example glvertex3i(x,y,z) glvertex4f(a,b,c,d) glvertex2ub(ub1,ub2) glvertex3dv(dv) Will be called glvertex*() Reading Jackie Neider, Tom Davis, Mason Woo OpenGL Programming Guide, Addison-Wesley Publication Company Edward Engel Interactive Computer Graphics: A Top-Down Approach with Shader-Based OpenGL (6th Edition) www.opengl.org