A simple OpenGL animation Due: Wednesday, January 27 at 4pm

Similar documents
Deferred Rendering Due: Wednesday November 15 at 10pm

Shading and Texturing Due: Friday, Feb 17 at 6:00pm

CSE Intro to Computer Graphics. ANSWER KEY: Midterm Examination. November 18, Instructor: Sam Buss, UC San Diego

CS 184: Assignment 2 Scene Viewer

ECS 175 COMPUTER GRAPHICS. Ken Joy.! Winter 2014

Homework 3: Programmable Shaders

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

Orthogonal Projection Matrices. Angel and Shreiner: Interactive Computer Graphics 7E Addison-Wesley 2015

Assignment 2 Ray Tracing

Raytracing CS148 AS3. Due :59pm PDT

Homework #2. Shading, Projections, Texture Mapping, Ray Tracing, and Bezier Curves

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

Assignment 6: Ray Tracing

TSBK03 Screen-Space Ambient Occlusion

TDA361/DIT220 Computer Graphics, January 15 th 2016

CS 130 Exam I. Fall 2015

Topics and things to know about them:

Terrain rendering (part 1) Due: Monday, March 10, 10pm

Advanced Lighting Techniques Due: Monday November 2 at 10pm

Problem Set 4 Part 1 CMSC 427 Distributed: Thursday, November 1, 2007 Due: Tuesday, November 20, 2007

Computer Graphics Coursework 1

Shading. Why we need shading. Scattering. Shading. Objectives

Objectives. Shading II. Distance Terms. The Phong Reflection Model

Pipeline Operations. CS 4620 Lecture 14

CSE 167: Lecture #8: Lighting. Jürgen P. Schulze, Ph.D. University of California, San Diego Fall Quarter 2011

Computer Graphics: Programming, Problem Solving, and Visual Communication

Shading I Computer Graphics I, Fall 2008

Graphics Hardware and OpenGL

Rendering: Reality. Eye acts as pinhole camera. Photons from light hit objects

Introduction Ray tracing basics Advanced topics (shading) Advanced topics (geometry) Graphics 2010/2011, 4th quarter. Lecture 11: Ray tracing

Today. Global illumination. Shading. Interactive applications. Rendering pipeline. Computergrafik. Shading Introduction Local shading models

CHAPTER 1 Graphics Systems and Models 3

CS 130 Exam I. Fall 2015

By: Tyler Spears Mentor: Dr. Bijaya Karki. Visualizing Time- Dependent Atomic Data in OpenGL

Comp 410/510 Computer Graphics. Spring Shading

CSE 167: Lecture #8: GLSL. Jürgen P. Schulze, Ph.D. University of California, San Diego Fall Quarter 2012

Lecture 17: Shading in OpenGL. CITS3003 Graphics & Animation

Lecture 15: Shading-I. CITS3003 Graphics & Animation

Assignment #2. (Due date: 11/6/2012)

CCSI 3161 Project Flight Simulator

Interactive Real-Time Raycasting

CS 4620 Program 3: Pipeline

Computer Graphics I Lecture 11

GPU Programming EE Midterm Examination

Methodology for Lecture. Importance of Lighting. Outline. Shading Models. Brief primer on Color. Foundations of Computer Graphics (Spring 2010)

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

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

COS 116 The Computational Universe Laboratory 10: Computer Graphics

Documentation for Lindsay s OpenGL Lighting Demonstration. Lindsay s OpenGL Light Demo

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

Homework 1: Getting Started with WebGL and Transformations EE267 Virtual Reality 2018

CS 184: Assignment 3 Real-Time Graphics: OpenGL Scene

Glass Gambit: Chess set and shader presets for DAZ Studio

Terrain Rendering (Part 1) Due: Thursday November 30 at 10pm

Chapter 17: The Truth about Normals

Computer Graphics. Illumination and Shading

Recollection. Models Pixels. Model transformation Viewport transformation Clipping Rasterization Texturing + Lights & shadows

CS 559 Computer Graphics Midterm Exam March 22, :30-3:45 pm

Objectives Shading in OpenGL. Front and Back Faces. OpenGL shading. Introduce the OpenGL shading methods. Discuss polygonal shading

CS 184: Assignment 4 Simple Raytracer

light light light B E

Computer Graphics Lecture 11

Today. Global illumination. Shading. Interactive applications. Rendering pipeline. Computergrafik. Shading Introduction Local shading models

Homework #2 Posted: February 8 Due: February 15

Virtual Reality for Human Computer Interaction

A Quick Introduction to POV-Ray

Lessons Learned from HW4. Shading. Objectives. Why we need shading. Shading. Scattering

Rendering. Illumination Model. Wireframe rendering simple, ambiguous Color filling flat without any 3D information

Reflection of Light. 1)Students will discover how light interacts with certain types of surfaces

[175 points] The purpose of this assignment is to give you practice with shaders in OpenGL.

CS452/552; EE465/505. Intro to Lighting

Spring 2012 Final. CS184 - Foundations of Computer Graphics. University of California at Berkeley

CS Simple Raytracer for students new to Rendering

CS5620 Intro to Computer Graphics

Interactive OpenGL Animation

Photorealism: Ray Tracing

CSE 167: Lecture #7: Color and Shading. Jürgen P. Schulze, Ph.D. University of California, San Diego Fall Quarter 2011

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

THE AUSTRALIAN NATIONAL UNIVERSITY Final Examinations(Semester 2) COMP4610/COMP6461 (Computer Graphics) Final Exam

CSC 471 midterm 2 Winter Name:

Computer Graphics Tick 1

Ø Sampling Theory" Ø Fourier Analysis Ø Anti-aliasing Ø Supersampling Strategies" Ø The Hall illumination model. Ø Original ray tracing paper

Homework #2. Shading, Ray Tracing, and Texture Mapping

Shading, Advanced Rendering. Week 7, Wed Feb 28

Interactive Computer Graphics A TOP-DOWN APPROACH WITH SHADER-BASED OPENGL

Particle systems, collision detection, and ray tracing. Computer Graphics CSE 167 Lecture 17

COS 116 The Computational Universe Laboratory 10: Computer Graphics

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

Creating the Tilt Game with Blender 2.49b

Lighting and Shading II. Angel and Shreiner: Interactive Computer Graphics 7E Addison-Wesley 2015

Chapter 4- Blender Render Engines

Models and Architectures

CMSC427 Final Practice v2 Fall 2017

Reflection and Shading

Easy Decal Version Easy Decal. Operation Manual. &u - Assets

CMSC427: Computer Graphics Lecture Notes Last update: November 21, 2014

CS 4300/5310 Computer Graphics

Full Screen Layout. Main Menu Property-specific Options. Object Tools ( t ) Outliner. Object Properties ( n ) Properties Buttons

Introduction to Computer Graphics 7. Shading

4) Finish the spline here. To complete the spline, double click the last point or select the spline tool again.

Transcription:

CMSC 23700 Winter 2010 Introduction to Computer Graphics Project 1 January 12 A simple OpenGL animation Due: Wednesday, January 27 at 4pm 1 Summary This project is the first part of a three-part project. In it, you will have to implement a simple viewer in C using OpenGL and the GLUT library. The goals of this project are to get your feet wet with simple graphics programming and to give you some quick feedback on the course submission and grading policies. In this part of the project, you will implement a simple shader that corresponds to the smooth shading of the traditional fixed pipeline. Chapters 1 6 and 10 of the OpenGL Primer cover the aspects of the OpenGL and GLUT that are relevant to this project. 2 Description Your task in this project is to implement an interactive viewer of a simple 3D animation. The animation is of a 2 2 2 box centered at the origin, which contains one or more bouncing spheres. The viewer is located at (0, 0, 3) (this is called the camera or eye position) and is looking in the direction of the positive Z-axis. We recommend a field of view of around 65 degrees. Your program is responsible for displaying the animation and for allowing the user to vary change its state using the keyboard. 2.1 The graphics There are three components to the rendering: The box. The box is 2 2 2 units in size and is centered at (0, 0, 0). You should render five sides: back (z = 1), left (x = 1), right (x = 1), bottom (y = 1), and top (y = 1). You should render the sides as a 5 5 grid of quads. 1 We recommend giving the walls different colors. The user will be able to select between flat and smooth shading for the walls. The balls. The balls have radius r = 0.05. Use the function glutsolidsphere to render them. When adding a ball to the mix, pick a random location, initial velocity, and color. The initial speed (length the the velocity vector) should be in the range 0.5 to 2.5. Use smooth shading to render the balls. 1 Note that this does not produce the best lighting effects, but it will help illustrate some aspects of OpenGL lighting.

The lights. You should implement multiple lighting modes (ambient only, directional light, positional light, and a spot light). The space key is used to switch between lighting modes. Experiment with the placement of the lights. Shading. While this assignment could be implemented using the fixed pipeline, we will use GLSL shaders. The gl_lightsource[] uniform variable holds the state of the lights, which your shader program can use to determine the lighting mode. Your shader should support ambient and diffuse lighting. We will provide sample code for the simulation and utility code for loading and compiling shaders. 2.2 User interface Your viewer should support the following keyboard commands: l toggle the lighting mode between none, directional, point, and spotlight. + add a ball to the simulation - remove a ball from the simulation q quit the viewer You can limit the number of balls to 100. Your application should also handle resizing the viewport. 3 Hints Review the demo code to understand how to structure an animation using Glut and OpenGL. We recommend the staging your implementation effort in the following steps: 1. Start by getting the box to display with directional lighting and getting features such as resizing and quiting to work. 2. Add the lighting modes. 3. Animate a single bouncing ball and handle ball-wall collisions. 4. Finally, add multiple balls and ball-to-ball collisions. 3.1 Representing the balls The position of a ball can be represented by three pieces of information: a time t 0, an initial position q, and a velocity vector v. Given these vlaues, the ball s position can be defined as a function of time p(t) = q + (t t 0 )v for t t 0 In addition, you will want to record the ball s color information and the time of its next collision. 2

3.2 Event queue To manage the simulation, you will need to maintain a priority queue of events ordered by time. There are two types of events: ball-wall collisions and ball-ball collisions. A given ball will continue moving in its current direction until it hits something, so the only time you need to update the state of the system is when an event occurs. Because the objects and their motions are simple, it is possible to accurately predict what the next event to affect a given ball is likely to be. If we are going to render the scene at time t, then we should first process all of the events that occur at or before t. To process a wall collision, we compute the ball s new velocity (v), set its initial time value (t 0 ) to the collision time, and set its initial position (q) to the collision position. We then compute the ball s next collision by testing it against the walls and other balls. Note that if the ball is going to collide with some other ball, you may have to recompute other collisions. For example, say that ball B was scheduled to hit ball C, but we now discover that ball A will hit B first. This means that we must recompute C s next collision (and so on). For simplicity, we will assume that a ball is involved in only one kind of collision at a time (i.e., no ball-ball-wall or three-ball collisions). 3.3 Ball-wall collisions Given a ball with position p(t) = q + tv the time of intersection with the plane defining a given wall can be determined by projecting out the appropriate component of the velocity vector v. For example, if v x > 0, 2 then the ball will hit the right side of the box (x = 1) at time t satisfying (1 r) = p(t) x thus the time of intersection with the right wall is = q x + tv x t = 1 r q x v x If v x < 0, then we check it against the left wall (x = 1 plane). For each ball, we must test it against at most three planes and then take the minimum time as the time of collision. When a ball hits a wall, its new velocity vector will be a reflection of its current vector off the plane of the wall. 3 Figure 1 illustrates this situation. 3.4 Ball-ball collisions Consider two balls, whose positions are specified as p 1 (t) = q 1 + tv 1 p 2 (t) = q 2 + tv 2 2 In practice, we need to test for v x > ɛ, where ɛ is a small positive number (e.g., 10 6 ). 3 Question 1 of Homework 1 addresses the computation of the reflection vector. 3

β β Figure 1: Ball-to-wall collision The distance between the centers of these two balls is d(t) = (p 1 (t) p 2 (t)) 2 d(t) 2 = (p 1 (t) p 2 (t)) 2 = ((q 1 + tv 1 ) (q 2 + tv 2 )) 2 = ((q 1 q 2 ) + t(v 1 v 2 )) 2 = (q + tv) 2 = q 2 + 2(q v)t + v 2 t 2 where q = (q 1 q 2 ) and v = (v 1 v 2 ). When d(t) 2r, then the balls have collided, so we can detect the point of collision by finding the roots of v 2 t 2 + 2(q v)t + (q 2 4r 2 ) If there are no real roots or both roots are negative, then there is no collision, if both roots are positive, then the smaller one is the time of collision, and if one root is positive and the other negative, then the balls are currently overlapping (which should not happen in your simulation). When two balls collide, their direction vector should change as follows. First compute the plane at the point of contact that is tangent to both balls. Then, the new velocity vector is the reflection of the old vector off of the tangent plane. Figure 2 illustrates this situation. If a ball is moving away from the tangent plane, then its velocity vector should not change. 4 Submission We will set up a gforge repository for each student on the Computer Science server (see the Lab notes (Handout 2) for more information on gforge). We will collect the projects at 4:00pm on Wednesday January 27th from the repositories, so make sure that you have committed your final version before then. 4

β β α α Figure 2: Ball-to-ball collision 4.1 Extra credit For extra credit, make the balls shiny and implement specular lighting. History 2009-01-12 Original version. 5