OUTLINE. Hierarchical Models Z-Fighting Primitives Besides Triangles Back Face Culling

Similar documents
Introduction to OpenGL

SFU CMPT 361 Computer Graphics Fall 2017 Assignment 2. Assignment due Thursday, October 19, 11:59pm

Geometry Primitives. Computer Science Department University of Malta. Sandro Spina Computer Graphics and Simulation Group. CGSG Geometry Primitives

Hierarchical Models. Roadmap. Importance of shadows. Importance of shadows. Importance of shadows. Importance of shadows

WebGL A quick introduction. J. Madeira V. 0.2 September 2017

Geometry Shaders. And how to use them

HIERARCHICAL TRANSFORMATIONS A Practical Introduction

Modeling Objects. Modeling. Symbol-Instance Table. Instance Transformation. Each appearance of the object in the model is an instance

2D Drawing Primitives

API for creating a display window and using keyboard/mouse interations. See RayWindow.cpp to see how these are used for Assignment3

Today s Agenda. Basic design of a graphics system. Introduction to OpenGL

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

HIERARCHICAL TRANSFORMATIONS A Practical Introduction

PROFESSIONAL. WebGL Programming DEVELOPING 3D GRAPHICS FOR THE WEB. Andreas Anyuru WILEY. John Wiley & Sons, Ltd.

CMSC427 Final Practice v2 Fall 2017

Computer graphic -- Programming with OpenGL I

Describe the Orthographic and Perspective projections. How do we combine together transform matrices?

Comp 410/510 Computer Graphics Spring Programming with OpenGL Part 2: First Program

OpenGL: Open Graphics Library. Introduction to OpenGL Part II. How do I render a geometric primitive? What is OpenGL

Sung-Eui Yoon ( 윤성의 )

Topics and things to know about them:

CSE 167: Introduction to Computer Graphics Lecture #5: Visibility, OpenGL

Ciril Bohak. - INTRODUCTION TO WEBGL

CHAPTER 1 Graphics Systems and Models 3

OPENGL AND GLSL. Computer Graphics

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

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

Graphics Programming. Computer Graphics, VT 2016 Lecture 2, Chapter 2. Fredrik Nysjö Centre for Image analysis Uppsala University

CS 4620 Program 3: Pipeline

CS451Real-time Rendering Pipeline

Programming with OpenGL Part 2: Complete Programs Computer Graphics I, Fall

Rasterization Overview

CMSC427 Fall 2017 OpenGL Notes A: Starting with JOGL and OpenGL Objectives of notes Readings Computer Graphics Programming in OpenGL with Java

EECE 478. Learning Objectives. Learning Objectives. Rasterization & Scenes. Rasterization. Compositing

Transforms 1 Christian Miller CS Fall 2011

RASTERISED RENDERING

The Rendering Pipeline (1)

Hierarchical Modeling

CSC Graphics Programming. Budditha Hettige Department of Statistics and Computer Science

Advanced Lighting Techniques Due: Monday November 2 at 10pm

Outline. Introduction Surface of Revolution Hierarchical Modeling Blinn-Phong Shader Custom Shader(s)

Game Architecture. 2/19/16: Rasterization

HIERARCHICAL TRANSFORMATIONS A Practical Introduction

Clipping & Culling. Lecture 11 Spring Trivial Rejection Outcode Clipping Plane-at-a-time Clipping Backface Culling

1 Preview. Dr. Scott Gordon Computer Science Dept. CSUS. Virtual Cameras, Viewing Transformations: CSc-155 Advanced Computer Graphics

Projection Matrix Tricks. Eric Lengyel

CS488. Visible-Surface Determination. Luc RENAMBOT

Shadows in the graphics pipeline

Lecture 5: Transforms II. Computer Graphics and Imaging UC Berkeley CS184/284A

How shapes are represented in 3D Graphics. Aims and objectives By the end of the lecture you will be able to describe

TDA362/DIT223 Computer Graphics EXAM (Same exam for both CTH- and GU students)

Advanced Graphics. OpenGL and Shaders I. Alex Benton, University of Cambridge Supported in part by Google UK, Ltd

Due: Thursday, February 6 th, 11:59 pm TA: Mason Remy

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

Computer Graphics (CS 543) Lecture 6a: Hierarchical 3D Models. Prof Emmanuel Agu. Computer Science Dept. Worcester Polytechnic Institute (WPI)

Viewing with Computers (OpenGL)

VISIBILITY & CULLING. Don t draw what you can t see. Thomas Larsson, Afshin Ameri DVA338, Spring 2018, MDH

2D/3D Geometric Transformations and Scene Graphs

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

CS 4620 Midterm 1. Tuesday 22 October minutes

Filled Area Primitives. CEng 477 Introduction to Computer Graphics METU, 2007

Perspective matrix, OpenGL style

Notes on Assignment. Notes on Assignment. Notes on Assignment. Notes on Assignment

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

Today. Parity. General Polygons? Non-Zero Winding Rule. Winding Numbers. CS559 Lecture 11 Polygons, Transformations

Computer Graphics Shadow Algorithms

Building Models. Prof. George Wolberg Dept. of Computer Science City College of New York

Precept 2 Aleksey Boyko February 18, 2011

Culling. Computer Graphics CSE 167 Lecture 12

Hierarchical Modeling. University of Texas at Austin CS384G - Computer Graphics Fall 2010 Don Fussell

Institutionen för systemteknik

Lecture 3 Sections 2.2, 4.4. Mon, Aug 31, 2009

Shadow Algorithms. CSE 781 Winter Han-Wei Shen

Transformations. Rotation and Scaling

CS 432 Interactive Computer Graphics

CS Simple Raytracer for students new to Rendering

Motivation. Culling Don t draw what you can t see! What can t we see? Low-level Culling

Pipeline Operations. CS 4620 Lecture 14

The exam begins at 2:40pm and ends at 4:00pm. You must turn your exam in when time is announced or risk not having it accepted.

3D Graphics and OpenGl. First Steps

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

Programming using OpenGL: A first Introduction

The original image. Let s get started! The final result.

THE VIEWING TRANSFORMATION

Computer Graphics Hands-on

Lab 2-3D Transformations and Vertex Shaders

CS 4620 Midterm, March 21, 2017

C O M P U T E R G R A P H I C S. Computer Graphics. Three-Dimensional Graphics I. Guoying Zhao 1 / 52

TSBK03 Screen-Space Ambient Occlusion

Luiz Fernando Martha André Pereira

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

4: Polygons and pixels

CSE 167: Introduction to Computer Graphics Lecture 11: Scene Graph 2. Jürgen P. Schulze, Ph.D. University of California, San Diego Fall Quarter 2013

Wed, October 12, 2011

Queen s University CISC 454 Final Exam. April 19, :00pm Duration: 3 hours. One two sided aid sheet allowed. Initial of Family Name:

Transformations. Write three rules based on what you figured out above: To reflect across the y-axis. (x,y) To reflect across y=x.

2D ANIMATION & INTERACTION COURSE WEEK 5 QUICK REFERENCE

Graphics Pipeline & APIs

Models and Architectures

Maya Lesson 3 Temple Base & Columns

Transcription:

MATRIX STACKS

OUTLINE Hierarchical Models Z-Fighting Primitives Besides Triangles Back Face Culling

HIERARCHICAL MODELS Building scenes where objects move in relation to each other rather than independently Building complex objects from simpler shapes

MATRIX STACKS Stack of transformation matrices OpenGL built in matrix stack deprecated (of course) But graphicslib3d library contains MatrixStack with methods: pushmatrix() make a copy of top matrix and push on stack popmatrix() return and remove top matrix on stack multmatrix(m) multiply top matrix on stack by m peek() return top matrix, but don t remove rotate(d, x, y, z) apply to top matrix on stack translate(x, y, z) apply to top matrix on stack scale(x, y, z) apply to top matrix on stack Instead of wrangling multiple model and view matrices in code, can manage them all on a single stack

USING A STACK Let s say we want to view our scene from a particular position and watch the objects move Strategy: Set our camera location Push a matrix (identity) onto the stack and multiply it by the view matrix Create the first object and its model matrix Do a push (duplicates the previous matrix) and multiply it by the model matrix Create the next object and model matrix Do a push and multiply it by the model matrix You probably see the pattern here

USING A STACK Now, when we draw each object: Call gldrawarrays to draw the object Pop the appropriate matrices off the stack Call gldrawarrays to draw the next object Pop the appropriate matrices off the stack Another pattern

JAVA JOGL CODE IN DISPLAY() (1/4) // push view matrix onto the stack mvstack.pushmatrix(); mvstack.translate(-camerax, -cameray, -cameraz); double amt = (double)(system.currenttimemillis())/1000.0; // Assuming we have the location of proj_loc already gl.gluniformmatrix4fv(proj_loc, 1, false, pmat.getfloatvalues(), 0);

JAVA JOGL CODE IN DISPLAY() (2/4) // ---------------------- pyramid == sun mvstack.pushmatrix(); mvstack.translate(pyrlocx, pyrlocy, pyrlocz); mvstack.pushmatrix(); mvstack.rotate((system.currenttimemillis())/10.0,1.0,0.0,0.0); gl.gluniformmatrix4fv(mv_loc, 1, false, mvstack.peek().getfloatvalues(), 0); gl.glbindbuffer(gl_array_buffer, vbo[1]); gl.glvertexattribpointer(0, 3, GL_FLOAT, false, 0, 0); gl.glenablevertexattribarray(0); gl.glenable(gl_depth_test); gl.gldrawarrays(gl_triangles, 0, 18); mvstack.popmatrix(); // Note: we only pop the rotation matrix, not translation

JAVA JOGL CODE IN DISPLAY() (3/4) //----------------------- cube == planet mvstack.pushmatrix(); mvstack.translate(math.sin(amt)*4.0f, 0.0f, Math.cos(amt)*4.0f); mvstack.pushmatrix(); mvstack.rotate((system.currenttimemillis())/10.0,0.0,1.0,0.0); gl.gluniformmatrix4fv(mv_loc, 1, false, mvstack.peek().getfloatvalues(), 0); gl.glbindbuffer(gl_array_buffer, vbo[0]); gl.glvertexattribpointer(0, 3, GL_FLOAT, false, 0, 0); gl.glenablevertexattribarray(0); gl.gldrawarrays(gl_triangles, 0, 36); mvstack.popmatrix(); // Again, only pop the rotation matrix

JAVA JOGL CODE IN DISPLAY() (4/4) //----------------------- smaller cube == moon mvstack.pushmatrix(); mvstack.translate(0.0f, Math.sin(amt)*2.0f, Math.cos(amt)*2.0f); mvstack.rotate((system.currenttimemillis())/10.0,0.0,0.0,1.0); mvstack.scale(0.25, 0.25, 0.25); gl.gluniformmatrix4fv(mv_loc, 1, false, mvstack.peek().getfloatvalues(), 0); gl.glbindbuffer(gl_array_buffer, vbo[0]); gl.glvertexattribpointer(0, 3, GL_FLOAT, false, 0, 0); gl.glenablevertexattribarray(0); gl.gldrawarrays(gl_triangles, 0, 36); // Here s where we clean up the stack by popping all mvstack.popmatrix(); mvstack.popmatrix(); mvstack.popmatrix(); mvstack.popmatrix();

USING A STACK Since the stack code is all in display(), it gets called each time the frame changes So these matrices are different for each new change

SO.. WHY AREN T WE DOING THIS WITH SPHERES? Well we haven t looked at how do create sphere objects yet First, sphere vertices are more elegantly defined by a mathematical function than by listing vertices Second, we need to worry about curved surfaces Otherwise our sphere will look faceted, not smooth We will get to all of that soon

Z-FIGHTING When the depth (z axis) of two objects is similar, the display can get confused Often seen in terrain and shadows Caused by floating point rounding error and limited precision in the of z-buffer values

Z-FIGHTING Some solutions: Move objects apart slightly Don t make the near clipping plane too close to the camera

OPENGL PRIMITIVES AND THEIR INTERPRETATIONS GL_TRIANGLES GL_TRIANGLE_STRIP GL_TRIANGLE_FAN

OPENGL PRIMITIVES AND THEIR INTERPRETATIONS GL_LINES GL_LINE_STRIP

BACK FACE CULLING Affects rendering efficiency in a good way Every primitive we draw has a front face and a back face When we construct a cube out of triangles, only the front face of each triangle shows The cube is a closed object But OpenGL is still interpolating colors, etc. for the back face We can enable back face culling by: glenable(gl_cullface); We may also need to tell OpenGL how to tell what is a back face: gl_frontface(gl_ccw); Default is CCW counter clockwise that is, if the vertices progress in a counter clockwise order Called the winding order

BACK FACE CULLING If using back face culling, want to make your objects so that triangles defining the exterior are the same winding order Usually counter-clockwise May use culling in interesting ways With transparent objects, may want to see inside, not outside Probably don t want to use back face culling in objects that are not closed

SUMMARY Hierarchical Models Z-Fighting Primitives Besides Triangles Back Face Culling 19