Software Engineering. ò Look up Design Patterns. ò Code Refactoring. ò Code Documentation? ò One of the lessons to learn for good design:

Similar documents
CSE 167: Lecture #5: Rasterization. Jürgen P. Schulze, Ph.D. University of California, San Diego Fall Quarter 2012

Rendering. Converting a 3D scene to a 2D image. Camera. Light. Rendering. View Plane

Shaders (some slides taken from David M. course)

CHAPTER 1 Graphics Systems and Models 3

CS451Real-time Rendering Pipeline

The Importance of Matrices in the DirectX API. by adding support in the programming language for frequently used calculations.

CS 354R: Computer Game Technology

Advanced Lighting Techniques Due: Monday November 2 at 10pm

The Application Stage. The Game Loop, Resource Management and Renderer Design

CS 381 Computer Graphics, Fall 2008 Midterm Exam Solutions. The Midterm Exam was given in class on Thursday, October 23, 2008.

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

C P S C 314 S H A D E R S, O P E N G L, & J S RENDERING PIPELINE. Mikhail Bessmeltsev

Computer Graphics Fundamentals. Jon Macey

Core Graphics and OpenGL ES. Dr. Sarah Abraham

Rendering Objects. Need to transform all geometry then

CSE 167: Introduction to Computer Graphics Lecture #4: Vertex Transformation

Ulf Assarsson Department of Computer Engineering Chalmers University of Technology

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

Today. Rendering pipeline. Rendering pipeline. Object vs. Image order. Rendering engine Rendering engine (jtrt) Computergrafik. Rendering pipeline

Models and Architectures

3D GRAPHICS. design. animate. render

CS 130 Final. Fall 2015

Affine Transformation. Edith Law & Mike Terry

Three Main Themes of Computer Graphics

CSE 167: Introduction to Computer Graphics Lecture #5: Rasterization. Jürgen P. Schulze, Ph.D. University of California, San Diego Fall Quarter 2015

Graphics and Interaction Rendering pipeline & object modelling

Deferred Rendering Due: Wednesday November 15 at 10pm

Pipeline Operations. CS 4620 Lecture 14

1.2.3 The Graphics Hardware Pipeline

Computer Graphics 7: Viewing in 3-D

IMAGE-BASED RENDERING AND ANIMATION

Computer Graphics: Viewing in 3-D. Course Website:

COMP30019 Graphics and Interaction Scan Converting Polygons and Lines

3D Programming. 3D Programming Concepts. Outline. 3D Concepts. 3D Concepts -- Coordinate Systems. 3D Concepts Displaying 3D Models

Real-Time Rendering (Echtzeitgraphik) Michael Wimmer

Real-Time Shadows. Last Time? Textures can Alias. Schedule. Questions? Quiz 1: Tuesday October 26 th, in class (1 week from today!

Could you make the XNA functions yourself?

CMSC427 Transformations II: Viewing. Credit: some slides from Dr. Zwicker

Pipeline Operations. CS 4620 Lecture 10

Tutorial on GPU Programming #2. Joong-Youn Lee Supercomputing Center, KISTI

Computer Graphics 1. Chapter 7 (June 17th, 2010, 2-4pm): Shading and rendering. LMU München Medieninformatik Andreas Butz Computergraphik 1 SS2010

CS 381 Computer Graphics, Fall 2012 Midterm Exam Solutions. The Midterm Exam was given in class on Tuesday, October 16, 2012.

Ch 10: Game Event Management. Quiz # 4 Discussion

CSC 305 The Graphics Pipeline-1

Introduction to Computer Graphics with WebGL

Computer Graphics. Instructor: Oren Kapah. Office Hours: T.B.A.

Chapter 1 Introduction

Chapter 7 - Light, Materials, Appearance

Rasterization Overview

Computer Graphics (CS 543) Lecture 10: Soft Shadows (Maps and Volumes), Normal and Bump Mapping

Models and Architectures. Ed Angel Professor of Computer Science, Electrical and Computer Engineering, and Media Arts University of New Mexico

Advanced Shading I: Shadow Rasterization Techniques

Graphics Hardware, Graphics APIs, and Computation on GPUs. Mark Segal

CMSC427 Advanced shading getting global illumination by local methods. Credit: slides Prof. Zwicker

GEOMETRIC TRANSFORMATIONS AND VIEWING

CSE 167: Introduction to Computer Graphics Lecture #10: View Frustum Culling

Course Recap + 3D Graphics on Mobile GPUs

Lecture 2. Shaders, GLSL and GPGPU

Computer Graphics. Chapter 1 (Related to Introduction to Computer Graphics Using Java 2D and 3D)

3D Rendering Pipeline

Computer Graphics Seminar

Real-Time Shadows. Last Time? Today. Why are Shadows Important? Shadows as a Depth Cue. For Intuition about Scene Lighting

Computer Graphics. Lecture 02 Graphics Pipeline. Edirlei Soares de Lima.

CHETTINAD COLLEGE OF ENGINEERING & TECHNOLOGY CS2401 COMPUTER GRAPHICS QUESTION BANK

Introduction to Visualization and Computer Graphics

COMP30019 Graphics and Interaction Rendering pipeline & object modelling

Lecture outline. COMP30019 Graphics and Interaction Rendering pipeline & object modelling. Introduction to modelling

Computer Graphics Viewing

Graphics Hardware. Instructor Stephen J. Guy

Graphics Pipeline 2D Geometric Transformations

Real Time Reflections Han-Wei Shen

Drawing in 3D (viewing, projection, and the rest of the pipeline)

CS 130 Exam I. Fall 2015

CS 4620 Midterm, March 21, 2017

INTRODUCTION TO COMPUTER GRAPHICS. It looks like a matrix Sort of. Viewing III. Projection in Practice. Bin Sheng 10/11/ / 52

Game Architecture. 2/19/16: Rasterization

graphics pipeline computer graphics graphics pipeline 2009 fabio pellacini 1

Today. Rendering algorithms. Rendering algorithms. Images. Images. Rendering Algorithms. Course overview Organization Introduction to ray tracing

Computer Graphics and Visualization. What is computer graphics?

Object Representation Affine Transforms. Polygonal Representation. Polygonal Representation. Polygonal Representation of Objects

Rendering Algorithms: Real-time indirect illumination. Spring 2010 Matthias Zwicker

COMP3421. Introduction to 3D Graphics

graphics pipeline computer graphics graphics pipeline 2009 fabio pellacini 1

Culling. Computer Graphics CSE 167 Lecture 12

Real-Time Universal Capture Facial Animation with GPU Skin Rendering

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

CS GPU and GPGPU Programming Lecture 2: Introduction; GPU Architecture 1. Markus Hadwiger, KAUST

SRM INSTITUTE OF SCIENCE AND TECHNOLOGY

TSBK03 Screen-Space Ambient Occlusion

03 RENDERING PART TWO

Ray Tracing Basics I. Computer Graphics as Virtual Photography. camera (captures light) real scene. photo. Photographic print. Photography: processing

UNIT 2 2D TRANSFORMATIONS

Computer Graphics: Programming, Problem Solving, and Visual Communication

CIS 581 Interactive Computer Graphics

Midterm Exam Fundamentals of Computer Graphics (COMP 557) Thurs. Feb. 19, 2015 Professor Michael Langer

TDA361/DIT220 Computer Graphics, January 15 th 2016

INFOGR Computer Graphics

CS 432 Interactive Computer Graphics

S U N G - E U I YO O N, K A I S T R E N D E R I N G F R E E LY A VA I L A B L E O N T H E I N T E R N E T

Transformations. Ed Angel Professor of Computer Science, Electrical and Computer Engineering, and Media Arts University of New Mexico

Transcription:

Software Engineering ò Look up Design Patterns ò Code Refactoring ò Code Documentation? ò One of the lessons to learn for good design: ò Coupling: the amount of interconnectedness between classes ò Cohesion: a measure of how closely related the responsibilities, data, and methods for a class are ò For good code: Increase cohesion and decrease coupling

Architecture: Code Review Session Pair Review Guidelines

3D Graphics Resources: outside Materials Recommended Readings: Chapters 5 (Tom Miller) Chapter 11 (Aaron Reed)

Computer Graphics ò Modeling: math representation of a set of objects in a scene ò Rendering: drawing the images from model description to pixels on the display: combining lighting, objects, materials ò Animation: illusion of life

Some terms ò Pixel: short for Picture Element ò Raster image: image stored as an array of pixels usually with RGB values ò Raster Display: displays that show images as rectangular array of pixels

Computer Graphics ò Modeling: math representation of a set of objects in a scene ò Rendering: drawing the images from model description to pixels on the display: combining lighting, objects, materials ò Animation: illusion of life

Creating content In 2D?

Pixel Art ò Form of art whereby artists draw images by pixel using raster image software, e.g. paint or photoshop ò Advantages: ò File types can be read by any program ò Easy for photo touch ups ò Disadvantages: ò Cannot change the image too much ò Resizing problems

Vector Art ò Images represented as vectors (mathematically), lines, points, and curves ò Advantages: ò Easy to change and manipulate objects ò Can convert to pixel or raster art ò Can resize ò Disadvantage: ò Cannot use it for photos ò Not so good with a lot of color blends

2D Coordinate system 0,0 x y

Creating Content In 3D?

3D Model Representation ò Polygons and vertices ò Use triangles as simple primitive

3D Coordinate System Form: http://viz.aset.psu.edu/gho/sem_notes/3d_fundamentals/html/3d_coordinates.html Or, if you are standing facing +ive X and your up is Y

Computer Graphics ò Modeling: math representation of a set of objects in a scene ò Rendering: drawing the images from model description to pixels on the display: combining lighting, objects, materials ò Animation: illusion of life

Displays ò Example raster display ò Frame Buffer which holds color value per pixel RGB and an alpha channel for translucency

Displays (LCD and LED) ò Both displays are based on independent 3 sub-pixels per pixel, showing RGB

Color ò Subtractive: subtracting color ò Paints ò Additive: is adding color ò Lights ò Displays ò CG

Color (Representation) ò 8-bit RGB fixed range: web, email apps ò 12-/14-bit RGB fixed range: photography ò 16-bit RGB fixed range: printing and image processing and photography ò 16-bit float RGB: HDR High Dynamic Range (real-time rendering) ò 32-bit float RGB: HDR

Projective Rendering ò Used by OpenGL & DirectX ò Efficient for real-time rendering ò For each object in the scene ò Polyons are projected to 2D screen ò Order/depth is conserved ò Color is computed based on materials and light

Ray Tracing ò Shoot a ray from the eye to the scene ò Draw pixel based on color reflections from light sources and objects materials, etc. ò It is slow not usually realtime, but there are optimization techniques

Graphics Pipeline Rendering Process

Modeling Transformation Illumination (Shading) Model Transformation: Take model from local coordinates to world coordinates Viewing Transformation Clipping Projection to 2D space Rasterization Visibility/Display

Modeling Transformation Illumination (Shading) Illumination (Shading): Color per vertex or pixel is calculated based on light sources, and object materials Viewing Transformation Clipping Projection to 2D space Rasterization Visibility/Display

Modeling Transformation Illumination (Shading) Viewing Transformation: Color per vertex or pixel is calculated based on light sources, and object materials Viewing Transformation Clipping Projection to 2D space Rasterization Visibility/Display

Modeling Transformation Illumination (Shading) Clipping: Removing parts of the 3D scene that is not visible Viewing Transformation Clipping Projection to 2D space Rasterization Visibility/Display

Modeling Transformation Illumination (Shading) Projection to 2D space: Projecting the 3D object to 2D space Viewing Transformation Clipping Projection to 2D space Rasterization Visibility/Display

Modeling Transformation Illumination (Shading) Rasterization Convert objects to pixels, interpolate color and depth Viewing Transformation Clipping Projection to 2D space Rasterization Frame Buffer

Rasterization ò Rasterization is the process by which 2D or 3D objects are converted into pixels ò Each pixel is represented in RBG, depth

Graphics Pipeline

Graphics Pipelines From: Nvidia Cg Users Manual via http://blogs.vislab.usyd.edu.au/index.php/2007/03/

Graphics Pipelines XNA Backface Culling Viewport clipping From: MSDN: XNA Graphics Pipeline

3D Coordinate System Form: http://viz.aset.psu.edu/gho/sem_notes/3d_fundamentals/html/3d_coordinates.html Or, if you are standing facing +ive X and your up is Y It is important to know what coordinate system your artists used, otherwise the model will be flipped. To flip it back, multiply z coordinate by -1.

3D Graphics Drawing a model in XNA Chapters 5 (Tom Miller)

Get a Model ò Turbo Squid ò Or look for a model ò Remember to credit the person when using it

Representation of a Model ò Model ò ModelMesh (e.g., head, body, hand, etc.) ò ModelMeshPart: smallest part sent to video card (e.g., triangle strips) ò Effect: describes how the object should be rendered (world, view, projection to describe how the object is positioned, lighting, etc.)

Effect Classes in XNA ò BasicEffect (includes basic lighting: BasicEffect.EnableDefaultLighting()) ò Effect (use if you want to create your own shaders)

Adding a model in XNA

Adding a model in XNA

Adding a model in XNA

Adding a model in XNA

Matrix in XNA ò World Matrix: where the model is in relation to the world ò WorldMatrix = mesh * scale * rotate * translation matrix; ò View Matrix: where the camera sits ò CreateLookAt (camerapos, cameratarget, cameraupvector); ò Projection: how 3D space is projected into 2D screen ò CreatePrespectiveFieldOfView (fieldofview, aspectratio, nearplane, farplane) ò FieldOfView most often = MathHelper.PiOver4

Class Exercise Get a Model and add it in a 3D Scene in XNA

Moving the Model around Vector Math

Outline ò Scaling (generalized from 2D) ò Rotation (rotation about a line and not points) ò Translation

Vector Transformation: Scaling ò Vector Transformation: In 2D In 3D! # # " s x 0 0 s y $! & &# %" x y Transformation Matrix $ & %! # # # " s x 0 0 0 s y 0 0 0 s z $! &# &# %" x y z $ & & & % Transformation Matrix

Vector Transformation: Rotation ò Around origin In 2D " clockwise$ # cosθ sinθ sinθ cosθ %" ' $ &# x y % ' & In 3D Transformation Matrix " $ z axis$ $ # " $ x axis$ $ # cosθ sinθ 0 sinθ cosθ 0 1 0 0 cosθ 0 sinθ 0 0 1 0 sinθ cosθ %" ' $ ' $ ' $ &# %" ' $ ' $ ' $ &# x y z x y z % ' ' ' & % ' ' ' & " $ y axis$ $ # cosθ 0 0 1 sinθ 0 sinθ 0 cosθ %" ' $ ' $ ' $ &# x y z % ' ' ' &

Rotations ò Orientation: yaw, pitch and roll ò Yaw: around the Y ò Pitch: around the Z ò Roll: around X

2D Translation of an object Represent the point x, y by vector Thus: x y 1! " # # # $ % & & & x! y! 1 " # $ $ $ % & ' ' ' = 1 0 x t 0 1 y t 0 0 1 ( ) * * * * +, - - - - x y 1 ( ) * * * +, - - - = x + x t y + y t 1 ( ) * * * * +, - - - - Homogenous Coordinates Affine Transformation

3D Translation of an object Represent the point x, y by vector Thus: x y z 1! " # # # # $ % & & & & x! y! z! 1 " # $ $ $ $ % & ' ' ' ' = 1 0 0 x t 0 1 0 y t 0 0 1 z t 0 0 0 1 ( ) * * * * * +, - - - - - x y z 1 ( ) * * * * +, - - - - = x + x t y + y t z + z t 1 ( ) * * * * * +, - - - - - Homogenous Coordinates Affine Transformation

Vector Transformation: Translation 1 0 0 0 0 1 0 0 0 0 1 0 Tx. Ty. Tz. 1

Rotations (Affine Transformation) 1 0 0 0 0 cos( ) sin( ) 0 0 sin( ) cos( ) 0 0 0 0 1 x x X x x cos( ) 0 sin( ) 0 0 1 0 0 sin( ) 0 cos( ) 0 0 0 0 1 y y Y y y cos( ) sin( ) 0 0 sin( ) cos( ) 0 0 0 0 1 0 0 0 0 1 z z z z Z

Scaling (Affine Transformation) ò Scaling scale 0 0 0 0 scale 0 0 0 0 scale 0 0 0 0 1 When you are doing transformation on object, order is important

Vector Math: Dot Product ò Is a scalar ò Normalize vectors before use, formula is: float dotproduct = (v1.x*v2.x) + (v1.y*v2.y) + (v1.z*v2.z) ò Used to calculate angle between two vectors ab θ cos 1 = ab

Vector Math ò Dot product: ò Same vector? ò Opposite vector? ò Orthogonal vector? ò Why is the Dot product important?

Vector Math: Cross Product ò Is a vector ò Normalize vectors before use, formula is: Vector3 crossproduct; crossproduct.x = (v1.y*v2.z) (v2.y*v1.z); crossproduct.y = (v1.z*v2.x) (v2.z*v1.x); crossproduct.z = (v1.x*v2.y) (v2.x*v1.y); ò Used to calculate normal vector between two vectors

Vector Math ò Unit vector: ò vector of length of 1.0 ò To unitize or normalize your vector: Vector3 destination = new Vector3(10, 15, 10); Vector3 origin = new Vector3(2, 15, 0); Vector3 direction = destination - origin; direction.normalize();

Vector Transformation: Scaling ò Vector Transformation: In 2D In 3D! # # " s x 0 0 s y $! & &# %" x y Transformation Matrix $ & %! # # # " s x 0 0 0 s y 0 0 0 s z $! &# &# %" x y z $ & & & % Transformation Matrix In XNA: Create a scale variable Vector3, then Matrix.CreateScale (scale)

E.g., Rotate towards object Vector3 destination = new Vector3(10, 15, 10); Vector3 origin = new Vector3(2, 15, 0); Vector3 direction = destination - origin; Vector3 facingdirection = new Vector (0, 0, 10); direction.normalize(); facingdirection.normalize(); //getting the rotation angle float rotationangle; rotationangle = Math.Acos(Vector3.Dot(direction, facingdirection));

E.g., Rotate towards object Vector3 destination = new Vector3(10, 15, 10); Vector3 origin = new Vector3(2, 15, 0); Vector3 direction = destination - origin; Vector3 facingdirection = new Vector (0, 0, 10); direction.normalize(); facingdirection.normalize(); //getting the rotation angle float rotationangle; rotationangle = Math.Acos(Vector3.Dot(direction, facingdirection)); Problem, don t know which direction to rotate, need Cross Product

Matrix Class in XNA ò Matrix.CreateTranstlation(translationVector3); ò Matrix.CreateRotationX(angle); ò Matrix.CreateRotationY(angle); ò Matrix.CreateRotationZ(angle); ò Matrix.CreateScale(scale);

Matrix Class in XNA ò worldmatrix = scale * rotate * translate;

Class Assignment Try moving the model forward and backward

Assignment # 2 Online