Praseed Pai

53
3D Computer Graphics - a Technical Introduction AKA 3D Graphics Programming ! By Praseed Pai K.T. http://praseedp.blogspot.com [email protected]

description

 

Transcript of Praseed Pai

Page 1: Praseed Pai

3D Computer Graphics - a Technical Introduction

AKA 3D Graphics Programming !

ByPraseed Pai K.T.

http://[email protected]

Page 2: Praseed Pai

Background

UT Game Engine Release Discussion in the BarCamp user Group Volunteered to take a session on Graphics

Programming Aspects Has in the past consulted for companies in the

CAD/CAM space. Lack of Graphics Programmers in Kerala

( INDIA)

Page 3: Praseed Pai

Computer Graphics – What the heck is it ?

William Fetter in 1960 coined the term Ivan Sutherland's Sketch Pad Thesis @ MIT

Page 4: Praseed Pai

Part - 1

PIXELS !

Page 5: Praseed Pai

What is a Pixel ?

Pixel or Picture Element is a 32 bit integer value

RGBA – Red Green Blue Alpha One can use an array of unsigned integers to

store the pixel data. Once the data is populated , we can transfer

the stuff into a Windows Device Independent Bitmap.

Page 6: Praseed Pai

After Pixels , what else ?

Bresenham's Line Algorithm

Midpoint Circle Algorithm

Triangle , Rectangle , Polygon Filling

Copy the Stuff into the Device

Page 7: Praseed Pai

Demo

Clear the Screen Background Plotting Arbitary data at a point Rectangle,Triangle , Circle , Arc Rasterization

demo Image Point Processing ( Color to Grey Scale

and Image Negative ) Procedural Image

Page 8: Praseed Pai

Part 2

Transformation and Matrices

Page 9: Praseed Pai

2D Physical Co-ordinate System

Page 10: Praseed Pai

Transformation

Translation Rotation Scale

Page 11: Praseed Pai

Logical Co-ordinates

Page 12: Praseed Pai

Demo

A Clock Program using MFC Manual co-ordinate Transformation. Clock Geometry

Page 13: Praseed Pai

Part 3

Finally it's 3D Time

Page 14: Praseed Pai

3D Co-ordinate System – Are you on the Left or Right ?

Page 15: Praseed Pai

3D Transformation - Translation

Page 16: Praseed Pai

3D Transformation - Rotate

Page 17: Praseed Pai

3D Transform - Scale

Page 18: Praseed Pai

3D Viewing - Perspective

Page 19: Praseed Pai

3D viewing – Perspective Matrix

Page 20: Praseed Pai

3D viewing - Ortho

Page 21: Praseed Pai

3D viewing – Ortho Matrix

Page 22: Praseed Pai

Primitives

Page 23: Praseed Pai

Primitives ( contd.. )

Page 24: Praseed Pai

Jim Kajiya and his Rendering Equation

Page 25: Praseed Pai

Lights Please

Page 26: Praseed Pai

Rendering A scene using Global illumination

Page 27: Praseed Pai

Numerical Evaluation of Rendering Equation

Computationally Very Expensive Monte Carlo Rendering Global Illumination Algorithm Radiosity , Photon Rendering , Bidirectional

Path Tracing , MetroPolis Light Transport Algorithms solve the Rendering Equation to determine the Pixel Color

AQSIS – A RenderMan Compliant Renderer

Page 28: Praseed Pai

How do i Light in a feasible manner?

Page 29: Praseed Pai

Local Illumination Models

Global Illumination by solving Rendering Equation is not suitable for Real Time Graphics

We go for Approximation algorithms to create illumination models which are close to the physically based models

Phong Lighting Model with Gourord Shading ( more about it later ) was the only feasible thing for real time work.

Thanks to GPU we can have per pixel lighting like Phong Shading.

Page 30: Praseed Pai

Phong Lighting Model

Page 31: Praseed Pai

Phong Lighting Model

Page 32: Praseed Pai

Shading – Flat Shading

Every Polygonal face will have same color Fastest Shading Method Visual Fidelity is not good

Page 33: Praseed Pai

Shading – Gourord Shading

Calculation is done per vertex The Colors are interpolated

Page 34: Praseed Pai

Shading – Phong Shading

Per Pixel Lighting Calculation Most Expensive Feasible only on a GPU

Page 35: Praseed Pai

Lights – Directional Light

Page 36: Praseed Pai

Lights – Point Lights

Page 37: Praseed Pai

Light – Spot Light

Page 38: Praseed Pai

Images , so far ar synthetic .how do i add details ?

Page 39: Praseed Pai

Texture Mapping - Adding Detail to the surface

Page 40: Praseed Pai

Texture co-ordinates

Page 41: Praseed Pai

Demos

Texture Mapping an Image on to a Quad Environment Mapping Demo Terrain MultiTexturing Fog Demos from Ultimate Game Programming book

Page 42: Praseed Pai

Duo Who made PC a graphics Platform

Page 43: Praseed Pai

Part 4

Procedural Techniques

Page 44: Praseed Pai

GPU

Aka Graphics Cards Became Programmable from 1999 Now one can write code using High Level

Languages Cg from Nvidia GLSL from OpenGL ARB/Khronos HLSL from Microsoft Modern day GPU

Page 45: Praseed Pai

Graphics Pipeline

Page 46: Praseed Pai

Demo – Ambient Light Vertex Program

//////////////////////////// Vertex Program to Demonstrate Ambient Light//

varying vec3 normal, lightDir;

void main(){

gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;

}

Page 47: Praseed Pai

Demo – Ambient Light Fragment Processor

//////////////////// Fragment Program for Ambient Light////

varying vec3 normal, lightDir;

void main(){float intensity=0.2;vec4 color= vec4(1.0,1.0,0.0,0.0);gl_FragColor = color*intensity;

}

Page 48: Praseed Pai

Rasterizing Triangle using ShadersVertex Shader

void main() { gl_Position = ftransform();}

Page 49: Praseed Pai

Triangle – Fragment Shaderuniform vec2 v0, v1, v2;

///////////////////////////////////////// 2D cross product;//float crs(const vec2 u, const vec2 v){ return u.x * v.y - u.y * v.x; }

/////////////////////////////////////// Main routine test whether screen pixel is // within the triangle// void main() { vec2 p = gl_FragCoord.xy; if (crs(v1 - v0, p - v0) >= 0 && crs(v2 - v1, p - v1) >= 0 && crs(v0 - v2, p - v2) >= 0) gl_FragColor = vec4(1.0,0.0,0.0,0.0); else gl_FragColor = vec4(0.5); // gl_FragColor = vec4(1.0,0.0,0.0,0.0); }

Page 50: Praseed Pai

More Demos

GLSL Code snippets for doing various Lighting Models

GLSL demo from now defunct 3D Labs inc..

Page 51: Praseed Pai

Turner Whitted and his Rendering Technique

Page 52: Praseed Pai

Ray Tracing

Shooting a Ray from Eye into the scene ( for every pixel we need to do this )

It reverses the actual vision process to reduce the computational time..

We require robust computational primitives Ray Casting Demo Ray Tracing Demo A Discussion on POV Ray

Page 53: Praseed Pai

Q & A

THANK YOU