LECTURE 5. Announcements

Similar documents
LECTURE 5. Announcements

LECTURE 4. Announcements

LECTURE 6. Announcements

Minecraft Due: Mar. 1, 2015

LECTURE 7. Announcements

Minecraft Due: March. 6, 2018

Next week will be great!

These are notes for the third lecture; if statements and loops.

Sign up for crits! Announcments

Damaging, Attacking and Interaction

Operator overloading

Assignment 6: Ray Tracing

Practical 2: Ray Tracing

Session 8 Finishing Touches to the Air Raid Game

Announcements. Written Assignment2 is out, due March 8 Graded Programming Assignment2 next Tuesday

Topic #1: Rasterization (Scan Conversion)

Level Editor. Should be stable (as of Sunday) Will be updating the source code if you want to make tweaks to it for your final

CS1950U Setup Spring 2018

Topics and things to know about them:

CS488. Visible-Surface Determination. Luc RENAMBOT

Memory Management: High-Level Overview

the gamedesigninitiative at cornell university Lecture 7 C++ Overview

Software Engineering /48

EDAN30 Photorealistic Computer Graphics. Seminar 2, Bounding Volume Hierarchy. Magnus Andersson, PhD student

15 Sharing Main Memory Segmentation and Paging

Pointers and References

G52CPP C++ Programming Lecture 17

Spell Casting Motion Pack 5/5/2017

CS 563 Advanced Topics in Computer Graphics QSplat. by Matt Maziarz

16 Sharing Main Memory Segmentation and Paging

Surface Rendering. Surface Rendering

CS 216 Fall 2007 Midterm 1 Page 1 of 10 Name: ID:

Short Notes of CS201

GEA 2017, Week 4. February 21, 2017

Absolute C++ Walter Savitch

CS201 - Introduction to Programming Glossary By

MITOCW MIT6_172_F10_lec18_300k-mp4

Object-Oriented Programming for Scientific Computing

Collaboration policies!

CS179 GPU Programming Recitation 4: CUDA Particles

Spatial Data Structures

COMP30019 Graphics and Interaction Scan Converting Polygons and Lines

A Different Approach for Continuous Physics. Vincent ROBERT Physics Programmer at Ubisoft

Ray Tracing Part 1. CSC418/2504 Introduction to Computer Graphics. TA: Muhammed Anwar & Kevin Gibson

QUIZ. What are 3 differences between C and C++ const variables?

Ray Tracing. Computer Graphics CMU /15-662, Fall 2016

Point Cloud Filtering using Ray Casting by Eric Jensen 2012 The Basic Methodology

Drawing Fast The Graphics Pipeline

CE221 Programming in C++ Part 1 Introduction

Table of Contents. Questions or problems?

How to approach a computational problem

The 10 Minute Guide to Object Oriented Programming

LECTURE 3. Announcements

In the previous presentation, Erik Sintorn presented methods for practically constructing a DAG structure from a voxel data set.

Drawing Fast The Graphics Pipeline

Hidden Surface Elimination Raytracing. Pre-lecture business. Outline for today. Review Quiz. Image-Space vs. Object-Space

Who has worked on a voxel engine before? Who wants to? My goal is to give the talk I wish I would have had before I started on our procedural engine.

Ray Tracing. Cornell CS4620/5620 Fall 2012 Lecture Kavita Bala 1 (with previous instructors James/Marschner)

Ray Tracing through Viewing Portals

Photon Mapping. Due: 3/24/05, 11:59 PM

CS 465 Program 5: Ray II

Drawing Fast The Graphics Pipeline

Point based Rendering

18-642: Code Style for Compilers

Rasterization and Graphics Hardware. Not just about fancy 3D! Rendering/Rasterization. The simplest case: Points. When do we care?

Exception Namespaces C Interoperability Templates. More C++ David Chisnall. March 17, 2011

CS 31: Intro to Systems Virtual Memory. Kevin Webb Swarthmore College November 15, 2018

CMSC 201 Fall 2016 Lab 09 Advanced Debugging

C++_ MARKS 40 MIN

Announcements A2 will be posted by Monday at 9AM. Scott B. Baden / CSE 160 / Wi '16 2

Hello, Thanks for the introduction

The Traditional Graphics Pipeline

Pong in Unity a basic Intro

The feature set you are required to implement in your ray tracer is as follows (by order from easy to hard):

Testing is a very big and important topic when it comes to software development. Testing has a number of aspects that need to be considered.

CS61C : Machine Structures

+ Inheritance. Sometimes we need to create new more specialized types that are similar to types we have already created.

/INFOMOV/ Optimization & Vectorization. J. Bikker - Sep-Nov Lecture 8: Data-Oriented Design. Welcome!

Previously... contour or image rendering in 2D

5. Control Statements

Non-numeric types, boolean types, arithmetic. operators. Comp Sci 1570 Introduction to C++ Non-numeric types. const. Reserved words.

Voxels. Tech Team - Johnny Mercado, Michael Matonis, Glen Giffey, John Jackson

Game Development for

Computer Science II Lecture 1 Introduction and Background

Object-Oriented Programming in C++

COSC 2P95. Procedural Abstraction. Week 3. Brock University. Brock University (Week 3) Procedural Abstraction 1 / 26

Lecture 11: Ray tracing (cont.)

Volume Rendering. Computer Animation and Visualisation Lecture 9. Taku Komura. Institute for Perception, Action & Behaviour School of Informatics

III. Classes (Chap. 3)

Dynamic Bounding Volume Hierarchies. Erin Catto, Blizzard Entertainment

assembler Machine Code Object Files linker Executable File

C++ Support Classes (Data and Variables)

Last Time. University of British Columbia CPSC 111, Intro to Computation Alan J. Hu. Readings

Physically-Based Laser Simulation

Memory. From Chapter 3 of High Performance Computing. c R. Leduc

COMP322 - Introduction to C++ Lecture 02 - Basics of C++

Setting up A Basic Scene in Unity

CS12020 for CGVG. Practical 2. Jim Finnis

CS 248 Assignment 2 Polygon Scan Converter. CS248 Presented by Abe Davis Stanford University October 17, 2008

Programming projects. Assignment 1: Basic ray tracer. Assignment 1: Basic ray tracer. Assignment 1: Basic ray tracer. Assignment 1: Basic ray tracer

Transcription:

LECTURE 5 Announcements

Falling Behind? Talk to us Number of retries / grading policy slightly different this year You still pass the class if you hand in all projects at the end of the semester Hand in even if you think you re going to get a C or an incomplete! You ll get valuable feedback from the TAs and your peers No advantage of not handing in

Minecraft 2 Feedback Terrain generation should to be cheap this week srand() is very, very slow 1 octave is usually enough for decent terrain We ARE NOT checking your generation for correctness It just needs to look coherent Feel free to use a sin() wave if speed is an issue

Minecraft 2 Feedback Collisions have a lot of edge cases Leverage your third person camera! Common bugs we see include: Not colliding correctly at chunk boundaries Not considering the entity s dimensions properly

Minecraft 2 Feedback Goal velocity, gravity, and jumping Goal velocity: accelerate(desiredvel currentvel) Desired and current MUST be xz-only! Gravity: accelerate(-g) Jumping: currentvel.y += c Applied in one tick instantaneous change in y-vel Should the player be able to change directions in midair? How can you tell? Change goal velocity constant for air and ground

Announcements QUESTIONS?

LECTURE 5 Raycasting I (Voxel Engine)

Raycasting I (Voxel Engine) MOTIVATION

Given a ray what is the first thing it hits? Like shooting an infinite laser Used in graphics to find what to draw at each pixel Used in games for tons of things Line-of-sight AI Hit-scan weapons What is it?

The Ray A ray is a point (source) and a direction A point on ray Ԧr is given by: Ԧr = Ԧp + t መd Ԧp is the source point መd is the direction This must be normalized! t is a scalar value (length) Ԧp መd t መd

Why Raycast? Alternative: move a small trajectory object through the world very quickly obj obj obj obj obj obj Few large steps Collision detection is piecewise Many small steps Too expensive

Why do we care? Best answer to a very important question What is the camera looking at? In minecraft, this probably determines: Which block am I trying to destroy? Where am I trying to place a block? If I shoot a weapon, what does it hit?

Raycasting I (Voxel Engine) IMPLEMENTATION

Raycasting in Minecraft Cast a ray from the camera eye in the direction of the look vector The first intersection with the environment gives you: The block the player is currently looking at The face of that block the player is looking at The catch: we do this every tick So it needs to be super-fast Can t just intersect every visible block face

Voxel Ray Traversal Take advantage of the fact that we re traversing a grid! Break ray into components based on grid boundaries Compute the t value required to move the ray to the next component Continue checking grid boundaries until intersection with a solid block 6 3 4 5 1 2 p

Voxel Traversal Algorithm // +1 or -1 depending on direction const int stepx, stepy; // t delta to span an entire cell const float tdeltax, tdeltay; // integer block coordinates int X, Y; // t value to next integer boundary float tmaxx, tmaxy; loop { processvoxel(x, Y); if (tmaxx < tmaxy) { tmaxx += tdeltax; X += stepx; } else { tmaxy += tdeltay; Y += stepy; } } P = [1.1, 1.2] 3 2 1 1 2 (X, Y) tmaxy = 0.8 tmaxx (X, Y) = 0.45 (X, Y) 3 tmaxy = 1.8 tmaxx = (X, 0.95 Y) 4 V = [2, 1] tmaxx = 1.45

Voxel Traversal Algorithm Be very careful initializing step, tmax, and tdelta Sign & rounding issues will ruin your day Be sure to normalize this vector in your own code! When computing tdeltax, tdeltay, tdeltaz Be careful of rays parallel to an axis (divide by 0) Look at the paper for more details http://www.cse.yorku.ca/~amana/research/grid.pdf

Tips Add a visualization intersected block, face, and point This is actually required for Minecraft3 Get *one* direction working first For example, rays, in the (+x, +y, +z) direction Test *all* directions afterwards Shouldn t have to special case the loop!

Raycasting I (Voxel Engine) QUESTIONS?

LECTURE 5 Dynamic World Loading (Voxel Engine)

Dynamic World Loading (Voxel Engine) MEMORY MANAGEMENT

Memory troubles Assuming a block is one byte, one chunk is 32x32x32 = ~33 KB Last week we had 200 chunks = ~6.3 MB Decent size world, but not huge We want our worlds to be infinite So big that reaching the end is unreasonable during standard play But we don t have infinite memory Your RAM: 8GB Assassin s Creed Unity: 50GB

What should we forget? Solution: store only in memory what the player is likely to interact with Two parts: Load chunks only as the player approaches them Unload chunks when the player has moved significantly far away from them

Dynamic World Loading (Voxel Engine) CHUNK STREAMING

Chunk streaming Only store chunks within a distance from the player AABB or sphere around player Update when player moves between chunks Remove blocks that went out of range Add blocks that came into range

Chunk streaming What if the player transitions from chunk (x, y, z) to chunk (x+1, y+1, z+1) If view distance is 5 chunks on each side of the player, need to stream in more than 50 chunks Too much work for a single frame Simplest solution: queue of added chunks Dequeue one chunk per frame Build chunk s vertex buffer when it s dequeued In range at t1 only t1 In range at t2 only t2

More Complicated Solutions Use several worker threads Cannot access OpenGL in other threads VBO initializations still need to be spread out across frames Many functions aren t thread-safe (like srand() and frand()) Don t purge chunks in the world until they are (1+radius) away instead of (radius) away Loading chunks into memory is hard, so keep them there for a little while longer Keeps you from having to reload chunks when players jump back and forth across a chunk border ( thrashing ) We prefer flailing

Saving and loading With chunk streaming, modifications to chunks are lost when it goes out of the player s view range Could try to save all modifications in memory Danger of running out of memory for very long play sessions Doesn t provide persistence across play sessions Solution: Save chunks to disk as they stream out, load them from disk as they stream in How to efficiently save and load so much data?

Saving and loading in Minecraft Only saves visited chunks Pre-computing and storing entire world would be too much Not as bad in 2D though (Terraria does this) Uses a system of files Each 32x32 group of chunks is put in a region file Region files are named r.[x].[z].mcr, where x and z are the region indices 8KiB header with info in which chunks are present, when they were updated, and where they can be found Chunk data compressed with Zlib Not required! More information: http://www.minecraftwiki.net/wiki/beta_level_format

Dynamic World Loading (Voxel Engine) - Chunk Streaming QUESTIONS?

LECTURE 5 Tips for Minecraft 3

Adding/removing blocks Significant part of gameplay! Adding blocks: Raycast to determine intersected face Add a block in the direction of the normal Removing blocks: Directly remove the intersected block Debug visualizations are your friend! Actually required visualize the intersect block and face

Adding/removing blocks Logically changing a block is easy Change that block s ID Tell neighboring blocks to render faces if changed to a transparent block Visually changing a block isn t Have to re-build the entire VBO Happening at most once per frame

What if The block you intersect is on a chunk boundary Your algorithm shouldn t care! You try to place a block inside an entity You try to place a block inside yourself You should try to handle these as well as possible Edge cases

Interacting with Entities Gameplay requirement this week there must be some entities to interact with! Our voxel collision engine supports entityworld collisions options?

Entities and You Entities should affect you! Do a distance check Imprecise, only works well with round entities Implement AABB-AABB collisions Works, but why not just Use cylinder-cylinder collisions This is common code it should be usable by the voxel engine! Doesn t have to be touch-to-damage: feel free to get creative!

You and Entities You may want to be able to fight back! Do a distance check Decent for making throwable bombs Use cylinder-cylinder collisions Have cylinder bullets Use raycasting! Ray-AABB is just intersecting 6 planes Use CS123 code! Easy to adapt your ray-cube or ray-cylinder intersection code in your common engine

Tips for Minecraft 3 QUESTIONS?

LECTURE 5 C++ Tip of the Week

The preprocessor Happens before the compiler Basically string replacement Good uses #include Header Guards Bad uses #ifndef APPLICATION_H #define APPLICATION_H Class Application { } #endif

#defines for constants A common use of defines is for constants, but this has problems The compiler never sees it if you get an error, it may show the value not the symbol (32 not CHUNK_SIZE) It can t be scoped Prefer const variables! Seen by the compiler Only ever one instance Can be limited to class //bad #define CHUNK_SIZE 32 //good const int ChunkSize = 32; //scoped class Chunk { private: static const int ChunkSize = 32; };

#define for functions Another common (mis)use of defines is for quick function They reduce the number of function calls. So faster Lead to problems due to string replacement Parenthesis needed Bizarre behavior Scope Prefer inline functions! Scoped Type safety Predictable Just as fast #define CALL_WITH_MAX(a,b) f((a) > (b)? (a) : (b)) Int main() { int a=5;b=0; CALL_WITH_MAX(a++,b); cout << a << endl; } Int main() { int a=5;b=10; CALL_WITH_MAX(a++,b); cout << a << endl; } Inline voidcallwithmax(float a, float b) //can use templates to make { //general, but that s another topic f(a>b? A:b); }

LECTURE 5 C++ Anti-Tip of the Week

Basic Polymorphism class Dog { public: virtual void bark() { cout << "Bark!" << endl; } }; class Shiba : public Dog { public: virtual void bark() { cout << "Such woof, wow" << endl; Dog:bark(); } }; int main() { } Shiba *doge = new Shiba(); doge->bark(); delete doge; return 0; Prints Such woof, wow then Bark!? Compile error? Shiba isn t actually a subclass Missing colon Something else?! This actually compiles!

(Accidental) Labels What s happening is that the Dog: part of Dog:bark(); is being interpreted as a label definition The code after a label is simply executed as normal So we get infinite recursion, all because of a typo! Labels are usually used with goto statements Goto statements are forbidden magic that should never be used in any circumstance // Our code from earlier class Shiba { public: virtual void bark() { cout << "Such woof, wow" << endl; Dog:bark(); } }; // prints only At Test2 label. int main() { using namespace std; goto Test2; } cout << "testing" << endl; Test2: cerr << "At Test2 label." << endl;

LECTURE 5 Minecraft2 Playtesting!