61
Advanced Game Design Prof. Roger Crawfis Computer Science & Engineering The Ohio State University

Advanced Game Design Prof. Roger Crawfis Computer Science & Engineering The Ohio State University

Embed Size (px)

Citation preview

Page 1: Advanced Game Design Prof. Roger Crawfis Computer Science & Engineering The Ohio State University

Advanced Game Design

Prof. Roger CrawfisComputer Science & Engineering

The Ohio State University

Page 2: Advanced Game Design Prof. Roger Crawfis Computer Science & Engineering The Ohio State University

Course OverviewProject-based / Team-based

Little lecturing

Focus on programming for gamesSystems integration – graphics, sound, AI, networking, user-interfaces, physics, scriptingUtilize higher-level toolkits, allowing for more advanced progress while still developing programming skills.

Page 3: Advanced Game Design Prof. Roger Crawfis Computer Science & Engineering The Ohio State University

Course StructureI will lecture for about the first week and a half.Student game project groups will provide several presentations on their game ideas and progress.Student technology teams will provide an intermediate and an advanced lecture on their findings and analysis about their area.

Page 4: Advanced Game Design Prof. Roger Crawfis Computer Science & Engineering The Ohio State University

Project GoalsLarge-scale software developmentTeam-based (synergistic development)Toolkit-based (fast-start development)Learn and utilize the many non-graphical elements needed for games.Leverage and extend your software engineering, graphics, AI, …, expertise.

Page 5: Advanced Game Design Prof. Roger Crawfis Computer Science & Engineering The Ohio State University

ElementsGaming Engine

Responsible for providing primitivesHardware abstractionHandle different areas of the game

Physics, AI, etc.

GameDefined by a genreDefines the gameplay

Page 6: Advanced Game Design Prof. Roger Crawfis Computer Science & Engineering The Ohio State University

Requirements of a gaming engineStunning VisualsImmersive sound stageVaried input/output devicesScalabilitySimulationAnimationNetworking

Page 7: Advanced Game Design Prof. Roger Crawfis Computer Science & Engineering The Ohio State University

Requirements of a gameScriptingArtificial IntelligenceSupporting Tools

Optimizing game contentDeveloping game contentExtending game contentDebugging / Tuning of game performance

Page 8: Advanced Game Design Prof. Roger Crawfis Computer Science & Engineering The Ohio State University

Stunning VisualsAdding realismSmarter ModelsUse hardware

Bump-mappingDynamic water or other liquidsRich textures (Billboards, gloss-maps, light-maps, etc.)ShadowsParticle systems

Page 9: Advanced Game Design Prof. Roger Crawfis Computer Science & Engineering The Ohio State University

Immersive sound stageMulti-track sound supportPositional sound effects (3D immersion)Dynamic sounds / movement (doppler effects)

Page 10: Advanced Game Design Prof. Roger Crawfis Computer Science & Engineering The Ohio State University

Input devicesCommonly available devices are

Keyboard, mouse, gamepads and joysticks

Force feedback (haptic) devices are gaining popularitySteering wheelsJoysticksMotion tracking

Output devicesMultiple monitorsHead mounted displays

Page 11: Advanced Game Design Prof. Roger Crawfis Computer Science & Engineering The Ohio State University

ScalabilityMultiple hardware capabilitiesMulti-resolution modelsMulti-user supportLOD

Multiple model definitionsMulti-res modelsSubdivision surfaces

Page 12: Advanced Game Design Prof. Roger Crawfis Computer Science & Engineering The Ohio State University

SimulationVirtual worlds are all good to look atImmersion breaks when real world physics are not appliedSo we need

Collision detectionCollision response

Page 13: Advanced Game Design Prof. Roger Crawfis Computer Science & Engineering The Ohio State University

AnimationLinear transformationsModeled animations

Articulated motionLip syncingFacial Expressions

Blending animations

Page 14: Advanced Game Design Prof. Roger Crawfis Computer Science & Engineering The Ohio State University

NetworkingMulti-player support essentialCommon problems

LatencySynchronizationScalabilityConsistent game stateSecurity

Page 15: Advanced Game Design Prof. Roger Crawfis Computer Science & Engineering The Ohio State University

ScriptingStrict coding is tedious Support for scripting is essential for RADScripting has added a whole new fun factor for many games.

Page 16: Advanced Game Design Prof. Roger Crawfis Computer Science & Engineering The Ohio State University

Artificial IntelligenceGames need specialized AI

StrategyPath findingModeling behaviorLearning

Non-perfect!Fast!

Page 17: Advanced Game Design Prof. Roger Crawfis Computer Science & Engineering The Ohio State University

ToolsCreating varied content

models, video, images, sound

Integrating contentCommon file format support

Supporting existing popular tools via plug-ins3DS Max, Lightwave, Maya etc.Adobe premier, Adobe Photoshop

Page 18: Advanced Game Design Prof. Roger Crawfis Computer Science & Engineering The Ohio State University

Interactive ProgramsGames are interactive systems - they must respond to the userHow?

Page 19: Advanced Game Design Prof. Roger Crawfis Computer Science & Engineering The Ohio State University

Interactive Program StructureEvent driven programming

Everything happens in response to an event

Events come from two sources:

The userThe system

Events are also called messages

An event causes a message to be sent…

Initialize

User Does Somethingor

Timer Goes Off

System Updates

Page 20: Advanced Game Design Prof. Roger Crawfis Computer Science & Engineering The Ohio State University

User EventsThe OS manages user input

Interrupts at the hardware level …Get converted into events in queues at the windowing level …Are made available to your program

It is generally up to the application to make use of the event streamWindowing systems may abstract the events for you

Page 21: Advanced Game Design Prof. Roger Crawfis Computer Science & Engineering The Ohio State University

System EventsWindowing systems provide timer events

The application requests an event at a future timeThe system will provide an event sometime around the requested time. Semantics vary:

Guaranteed to come before the requested time As soon as possible after Almost never right on (real-time OS?)

Page 22: Advanced Game Design Prof. Roger Crawfis Computer Science & Engineering The Ohio State University

Polling for Events

Most windowing systems provide a non-blocking event function

Does not wait for an event, just returns NULL if one is not ready

What type of games might use this structure?Why wouldn’t you always use it?

while ( true )if ( e = checkEvent() )

switch ( e.type )…

do more work

Page 23: Advanced Game Design Prof. Roger Crawfis Computer Science & Engineering The Ohio State University

Waiting for Events

Most windowing systems provide a blocking event function

Waits (blocks) until an event is availableUsually used with timer events. Why?

On what systems is this better than the previous method? What types of games is it useful for?

e = nextEvent();switch ( e.type )

Page 24: Advanced Game Design Prof. Roger Crawfis Computer Science & Engineering The Ohio State University

The Callback AbstractionA common event abstraction is the callback mechanismApplications register functions they wish to have called in response to particular events

Translation table says which callbacks go with which eventsGenerally found in GUI (graphical user interface) toolkits

“When the button is pressed, invoke the callback”Many systems mix methods, or have a catch-all callback for unclaimed events

Why are callbacks good? Why are they bad?

Page 25: Advanced Game Design Prof. Roger Crawfis Computer Science & Engineering The Ohio State University

Upon Receiving an Event …Event responses fall into two classes:

Task events: The event sparks a specific task or results in some change of state within the current mode

eg Load, Save, Pick up a weapon, turn on the lights, … Call a function to do the job

Mode switches: The event causes the game to shift to some other mode of operation

eg Start game, quit, go to menu, … Switch event loops, because events now have different meanings

Software structure reflects this - menu system is separate from run-time game system, for example

Page 26: Advanced Game Design Prof. Roger Crawfis Computer Science & Engineering The Ohio State University

Real-Time LoopAt the core of interactive games is a real-time loop:

What else might you need to do?The number of times this loop executes per second is the frame rate

# frames per second (fps)

while ( true )process eventsupdate animation / scenerender

Page 27: Advanced Game Design Prof. Roger Crawfis Computer Science & Engineering The Ohio State University

LagLag is the time between when a user does something and when they see the result - also called latency

Too much lag and causality is distortedWith tight visual/motion coupling, too much lag makes people motion sick

Big problem with head-mounted displays for virtual reality

Too much lag makes it hard to target objects (and track them, and do all sorts of other perceptual tasks)

High variance in lag also makes interaction difficultUsers can adjust to constant lag, but not variable lag

From a psychological perspective, lag is the important variable

Page 28: Advanced Game Design Prof. Roger Crawfis Computer Science & Engineering The Ohio State University

Computing LagLag is NOT the time it takes to compute 1 frame!What is the formula for maximum lag as a function of frame rate, fr?What is the formula for average lag?

Process input

Update state

Render

Process input

Update state

Render

Process input

Frame time

Lag

frlag

frlag

average

5.1

2max

Event time

Page 29: Advanced Game Design Prof. Roger Crawfis Computer Science & Engineering The Ohio State University

Frame Rate QuestionsWhat is an acceptable frame rate for twitch games? Why?What is the maximum useful frame rate? Why?What is the frame rate for NTSC television?What is the minimum frame rate required for a sense of presence? How do we know?How can we manipulate the frame rate?

Page 30: Advanced Game Design Prof. Roger Crawfis Computer Science & Engineering The Ohio State University

Frame Rate Answers (I)Twitch games demand at least 30fs, but the higher the better (lower lag)

Users see enemy’s motions soonerHigher frame rates make targeting easier

The maximum useful frame rate is the monitor refresh rate

Time taken for the monitor to draw one screenSynchronization issues

Buffer swap in graphics is timed with vertical sweep, so ideal frame rate is monitor refresh rate

Can turn of synchronization, but get nasty artifacts on screen

Page 31: Advanced Game Design Prof. Roger Crawfis Computer Science & Engineering The Ohio State University

Frame Rate Answers (II)NTSC television draws all the odd lines of the screen, then all the even ones (interlace format)

Full screen takes 1/30th of a secondUse 60fps to improve visuals, but only half of each frame actually gets drawn by the screenDo consoles only render 1/2 screen each time?

It was once argued that 10fps was required for a sense of presence (being there)

Head mounted displays require 20fps or higher to avoid illnessMany factors influence the sense of presencePerceptual studies indicate what frame rates are acceptable

Page 32: Advanced Game Design Prof. Roger Crawfis Computer Science & Engineering The Ohio State University

Reducing LagFaster algorithms and hardware is the obvious answerDesigners choose a frame rate and put as much into the game as they can without going below the threshold

Part of design documents presented to the publisherThreshold assumes fastest hardware and all game features turned onOptions given to players to reduce game features and improve their frame rate

There is a resource budget: How much of the loop is dedicated to each aspect of the game (graphics, AI, sound, …)

Some other techniques allow for more features and less lag

Page 33: Advanced Game Design Prof. Roger Crawfis Computer Science & Engineering The Ohio State University

Decoupling ComputationIt is most important to minimize lag between the user actions and their direct consequences

So the input/rendering loop must have low latency

Lag between actions and other consequences may be less severe

Time between input and the reaction of enemy can be greaterTime to switch animations can be greater

Technique: Update different parts of the game at different rates, which requires decoupling them

For example, run graphics at 60fps, AI at 10fpsDone in Unreal engine, for instance

Page 34: Advanced Game Design Prof. Roger Crawfis Computer Science & Engineering The Ohio State University

Animation and SoundAnimation and sound need not be changed at high frequency, but they must be updated at high frequency

For example, switching from walk to run can happen at low frequency, but joint angles for walking must be updated at every frame

Solution is to package multiple frames of animation and submit them all at once to the renderer

Good idea anyway, makes animation independent of frame rate

Sound is offloaded to the sound card

Page 35: Advanced Game Design Prof. Roger Crawfis Computer Science & Engineering The Ohio State University

Overview of Ogre3DNot a full-blown gameengine.Open-sourceStrong user community.Decent Software Engineering.Cool Logo

Page 36: Advanced Game Design Prof. Roger Crawfis Computer Science & Engineering The Ohio State University

FeaturesGraphics API independent 3D implementationPlatform independenceMaterial & Shader support

Well known texture formats: png, jpeg, tga, bmp, dds, dxtMesh support: Milkshape3D, 3D Studio Max, Maya, BlenderScene features

BSP, Octree plugins, hierarchical scene graphSpecial effects

Particle systems, skyboxes, billboarding, HUD, cube mapping, bump mapping, post-processing effects

Easy integration with physics librariesODE, Tokamak, Newton, OPCODE

Open source!

Page 37: Advanced Game Design Prof. Roger Crawfis Computer Science & Engineering The Ohio State University

Core Objects

Page 38: Advanced Game Design Prof. Roger Crawfis Computer Science & Engineering The Ohio State University

Startup SequenceExampleApplication

Go() Setup()Configure()setupResources()chooseSceneManager()createCamera()createViewport()createResourceListener()loadResources()createScene()frameStarted/Ended()createFrameListener()destroyScene()

Page 39: Advanced Game Design Prof. Roger Crawfis Computer Science & Engineering The Ohio State University

Basic SceneEntity, SceneNodeCamera, lights, shadowsBSP mapIntegrated ODE physicsBSP mapFrame listeners

Page 40: Advanced Game Design Prof. Roger Crawfis Computer Science & Engineering The Ohio State University

Terrain, sky, fog

Page 41: Advanced Game Design Prof. Roger Crawfis Computer Science & Engineering The Ohio State University

CEGUIWindow, panel, scrollbar, listbox, button, static textMedia/gui/ogregui.layout

CEGUI::Window* sheet = CEGUI::WindowManager::getSingleton().loadWindowLayout( (

CEGUI::utf8*)"ogregui.layout"); mGUISystem->setGUISheet(sheet);

Page 42: Advanced Game Design Prof. Roger Crawfis Computer Science & Engineering The Ohio State University

AnimationNode animation (camera, light sources)Skeletal AnimationAnimationState *mAnimationState; mAnimationState = ent->getAnimationState("Idle");mAnimationState->setLoop(true);mAnimationState->setEnabled(true); mAnimationState->addTime(evt.timeSinceLastFrame); mNode->rotate(quat);

Page 43: Advanced Game Design Prof. Roger Crawfis Computer Science & Engineering The Ohio State University

AnimationCrowd (instancing vs single entity)

InstancedGeometry* batch = new InstancedGeometry(mCamera->getSceneManager(), "robots" );batch->addEntity(ent, Vector3::ZERO);batch->build();

Facial animationVertexPoseKeyFrame* manualKeyFrame;manualKeyFrame->addPoseReference();manualKeyFrame->updatePoseReference ( ushort poseIndex, Real

influence)

Page 44: Advanced Game Design Prof. Roger Crawfis Computer Science & Engineering The Ohio State University

Picking

Page 45: Advanced Game Design Prof. Roger Crawfis Computer Science & Engineering The Ohio State University

Picking CEGUI::Point mousePos = CEGUI::MouseCursor::getSingleton().getPosition(); Ray mouseRay = mCamera->getCameraToViewportRay(mousePos.d_x/float(arg.state.width), mousePos.d_y/float(arg.state.height)); mRaySceneQuery->setRay(mouseRay); mRaySceneQuery->setSortByDistance(false); RaySceneQueryResult &result = mRaySceneQuery->execute(); RaySceneQueryResult::iterator mouseRayItr; Vector3 nodePos; for (mouseRayItr = result.begin(); mouseRayItr != result.end(); mouseRayItr++) { if (mouseRayItr->worldFragment) { nodePos = mouseRayItr->worldFragment->singleIntersection; break; } // if }

Page 46: Advanced Game Design Prof. Roger Crawfis Computer Science & Engineering The Ohio State University

Particle Effects mSceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject(

mSceneMgr->createParticleSystem("sil", "Examples/sil"));

Examples/sil{ material Examples/Flare2 particle_width 75 particle_height 100 cull_each false quota 1000 billboard_type oriented_self // Area emitter emitter Point { angle 30 emission_rate 75 time_to_live 2 direction 0 1 0 velocity_min 250 velocity_max 300 colour_range_start 0 0 0 colour_range_end 1 1 1 }

// Gravity affector LinearForce { force_vector 0 -100 0 force_application add }

// Fader affector ColourFader { red -0.5 green -0.5 blue -0.5 }}

Page 47: Advanced Game Design Prof. Roger Crawfis Computer Science & Engineering The Ohio State University

Particle Effects

Particle system attributesquota material particle_width particle_height cull_each billboard_type billboard_origin billboard_rotation_type common_direction common_up_vector renderer sorted local_space point_rendering accurate_facing iteration_interval

nonvisible_update_timeout

Emitter attributes(point, box, clyinder, ellipsoid, hollow ellipsoid, ring)angle colour colour_range_start colour_range_end direction emission_rate position velocity velocity_min velocity_max time_to_live time_to_live_min time_to_live_max duration duration_min duration_max repeat_delay repeat_delay_min repeat_delay_max

Affectors (LinearForce, ColorFader)Linear Force Affector ColourFader Affector ColourFader2 Affector Scaler Affector Rotator Affector ColourInterpolator Affector ColourImage Affector DeflectorPlane Affector DirectionRandomiser Affector

Page 48: Advanced Game Design Prof. Roger Crawfis Computer Science & Engineering The Ohio State University

Fire and Smoke

affector Rotator { rotation_range_start 0 rotation_range_end 360 rotation_speed_range_start -60 rotation_speed_range_end 200 }

Page 49: Advanced Game Design Prof. Roger Crawfis Computer Science & Engineering The Ohio State University

Cel Shadingvertex_program Ogre/CelShadingVP cg{

source Example_CelShading.cgentry_point main_vp…

default_params{… }

}

material Examples/CelShading{…

vertex_program_ref Ogre/CelShadingVP {}fragment_program_ref Ogre/CelShadingFP {}

}

Page 50: Advanced Game Design Prof. Roger Crawfis Computer Science & Engineering The Ohio State University

Cube MappingWith Perlin noise to distort vertices

void morningcubemap_fp (float3 uv : TEXCOORD0,out float4 colour : COLOR,uniform samplerCUBE tex : register(s0) )

{colour = texCUBE(tex, uv);// blow out the light a bitcolour *= 1.7;

}

Page 51: Advanced Game Design Prof. Roger Crawfis Computer Science & Engineering The Ohio State University

Bump Mapping

+ =

Page 52: Advanced Game Design Prof. Roger Crawfis Computer Science & Engineering The Ohio State University

Reflections & Refractions// Noisetexture_unit{

// Perlin noise volumetexture waves2.dds// min / mag filtering, no mipfiltering linear linear none

}// Reflectiontexture_unit{ // Will be filled in at runtime

texture Reflectiontex_address_mode clamp// needed by ps.1.4tex_coord_set 1

}// Refractiontexture_unit{

// Will be filled in at runtimetexture Refractiontex_address_mode clamp// needed by ps.1.4tex_coord_set 2

}

Page 53: Advanced Game Design Prof. Roger Crawfis Computer Science & Engineering The Ohio State University

Reflections & Refractions

Page 54: Advanced Game Design Prof. Roger Crawfis Computer Science & Engineering The Ohio State University

Grass

Each grass section is 3 planes at 60 degrees to each otherNormals point straight up to simulate correct lighting

Page 55: Advanced Game Design Prof. Roger Crawfis Computer Science & Engineering The Ohio State University

Post-Processing Effects

Page 56: Advanced Game Design Prof. Roger Crawfis Computer Science & Engineering The Ohio State University

Supporting tools (add-ons)Blender, Autodesk 3DS, Milkshape3D, Softimage XSI importers/exportersParticle editors, mesh viewersGUI editorsPhysics bindingsScene exporters and lots more

Add-on site

Page 57: Advanced Game Design Prof. Roger Crawfis Computer Science & Engineering The Ohio State University

Referenceshttp://www.ogre3d.org/

Page 58: Advanced Game Design Prof. Roger Crawfis Computer Science & Engineering The Ohio State University

Design PatternsFirst, an aside on Design Patterns

Page 59: Advanced Game Design Prof. Roger Crawfis Computer Science & Engineering The Ohio State University

Ogre FoundationsRootRenderSystemSceneManagerResourceManager

Page 60: Advanced Game Design Prof. Roger Crawfis Computer Science & Engineering The Ohio State University

Ogre FoundationsMeshEntityMaterialOverlay – OverlayElement, OverlayContainer, OverlayManagerSkeletal Animation

Page 61: Advanced Game Design Prof. Roger Crawfis Computer Science & Engineering The Ohio State University