30
CS361 Week 1 - Friday

Week 1 - Friday. What did we talk about last time? C# SharpDX

Embed Size (px)

Citation preview

Page 1: Week 1 - Friday.  What did we talk about last time?  C#  SharpDX

CS361Week 1 - Friday

Page 2: Week 1 - Friday.  What did we talk about last time?  C#  SharpDX

Last time

What did we talk about last time? C# SharpDX

Page 3: Week 1 - Friday.  What did we talk about last time?  C#  SharpDX

Questions?

Page 4: Week 1 - Friday.  What did we talk about last time?  C#  SharpDX

More SharpDX Examples

Page 5: Week 1 - Friday.  What did we talk about last time?  C#  SharpDX

Review of SharpDX

Program creates a MyGame (or similar) object and starts it running

MyGame has: Initialize() LoadContent() Update() Draw()

It runs an update-draw loop continuously until told to exit

Page 6: Week 1 - Friday.  What did we talk about last time?  C#  SharpDX

Drawing text

Modern TrueType and OpenType fonts are vector descriptions of the shapes of characters Vector descriptions are good for quality,

but bad for speed SharpDX allows us to take a vector-

based font and turn it into a picture of characters that can be rendered as a texture Just like everything else

Page 7: Week 1 - Friday.  What did we talk about last time?  C#  SharpDX

Drawing text continued

It's easiest to check the SpriteFont box when creating a SharpDX Toolkit project

It will create an XML file called Arial16.xml This file specifies the Arial font at size 16

Edit the XML to pick the font, size, and spacing You will need multiple Sprite Fonts even for

different sizes of the same font You can create your own XML file by copying it

Make sure you change the Build Action to ToolkitFont

Note: fonts have complex licensing and distribution requirements

Page 8: Week 1 - Friday.  What did we talk about last time?  C#  SharpDX

Drawing a font continued

Load the font similar to texture content

Add a DrawString() call in the Draw() method:spriteBatch.Begin();

spriteBatch.DrawString(font, "Hello, World!", new Vector2(100, 100), Color.Black);

spriteBatch.End();

font = Content.Load<SpriteFont>("Arial16");

Page 9: Week 1 - Friday.  What did we talk about last time?  C#  SharpDX

Why are they called sprites? They "float" above the

background like fairies… Multiple sprites are often

stored on one texture It's cheaper to store one big

image than a lot of small ones

This is an idea borrowed from old video games that rendered characters as sprites

Page 10: Week 1 - Friday.  What did we talk about last time?  C#  SharpDX

Drawing sprites with rotation

It is possible to apply all kinds of 3D transformations to a sprite A sprite can be used for billboarding or

other image-based techniques in a fully 3D environment

But, we can also simply rotate them using an overloaded call to Draw()

spriteBatch.Draw(texture, location,sourceRectangle, Color.White, angle, origin, 1.0f, SpriteEffects.None, 1);

Page 11: Week 1 - Friday.  What did we talk about last time?  C#  SharpDX

Let's unpack that

texture: Texture2D to draw location: Location to draw it sourceRectangle Portion of image Color.White Full brightness angle Angle in radians origin Origin of rotation 1.0f Scaling SpriteEffects.None No effects 1 Float level

Page 12: Week 1 - Friday.  What did we talk about last time?  C#  SharpDX

Student Lecture: Graphics Rendering Pipeline and Application Stage

Page 13: Week 1 - Friday.  What did we talk about last time?  C#  SharpDX

Graphics Rendering Pipeline

Page 14: Week 1 - Friday.  What did we talk about last time?  C#  SharpDX

Rendering

What do we have? Virtual camera (viewpoint) 3D objects Light sources Shading Textures

What do we want? 2D image

Page 15: Week 1 - Friday.  What did we talk about last time?  C#  SharpDX

Pipelines

The idea of a pipeline is to divide a task into independent steps, each of which can be performed by dedicated hardware

Example RISC pipeline:1. Instruction fetch2. Decode3. Execute4. Memory Access5. Writeback

Page 16: Week 1 - Friday.  What did we talk about last time?  C#  SharpDX

Pipeline performance

If you have an n stage pipeline, what's the maximum speedup you can get?

Consider a TV show with the following pipeline1. Write2. Rewrite3. Film4. Edit

Assume each step takes 1 week How much total time does it take to produce a 13

episode season? What if there was no pipelining? Note that a pipeline's speed is limited by its

slowest stage, the bottleneck

Page 17: Week 1 - Friday.  What did we talk about last time?  C#  SharpDX

Graphics rendering pipeline For API design, practical top-down problem

solving, and hardware design, and efficiency, rendering is described as a pipeline

This pipeline contains three conceptual stages:

Produces

material to be

rendered

Application

Decides what, how, and

where to

render

Geometry

Renders the final image

Rasterizer

Page 18: Week 1 - Friday.  What did we talk about last time?  C#  SharpDX

Architecture

These conceptual stages may or may not be running at the same time

Each conceptual stage may contain its own internal pipelines or parallel execution

Page 19: Week 1 - Friday.  What did we talk about last time?  C#  SharpDX

Speed

A critical concern of real time rendering is the rendering speed, determined by the slowest stage in the pipeline

We can measure speed in frames per second (fps), common for average performance over time

We can also measure speed in Hertz (Hz), common for hardware

Page 20: Week 1 - Friday.  What did we talk about last time?  C#  SharpDX

Rendering speed example Output device has a maximum update

frequency of 60 Hz (very common for LCD's)

The bottleneck rendering stage is 62.5 ms What's our rendering speed?

1/0.0625 = 16 fps 60/1 = 60 fps 60/2 = 30 fps 60/3 = 20 fps 60/4 = 15 fps 60/5 = 12 fps

Page 21: Week 1 - Friday.  What did we talk about last time?  C#  SharpDX

Application Stage

Page 22: Week 1 - Friday.  What did we talk about last time?  C#  SharpDX

Application stage

The application stage is the stage completely controlled by the programmer

As the application develops, many changes of implementation may be done to improve performance

The output of the application stage are rendering primitives Points Lines Triangles

Page 23: Week 1 - Friday.  What did we talk about last time?  C#  SharpDX

Important jobs of the application stage

Reading input Managing non-graphical output Texture animation Animation via transforms Collision detection Updating the state of the world in

general

Page 24: Week 1 - Friday.  What did we talk about last time?  C#  SharpDX

Acceleration

The Application Stage also handles a lot of acceleration

Most of this acceleration is telling the renderer what NOT to render

Acceleration algorithms Hierarchical view frustum culling BSP trees Quadtrees Octrees

Page 25: Week 1 - Friday.  What did we talk about last time?  C#  SharpDX

Hierarchical view frustum culling

An application can remove those objects that are not in the cone of visibility

Hierarchies of objects can be used to make these calculations easier

Page 26: Week 1 - Friday.  What did we talk about last time?  C#  SharpDX

BSP Trees

Splitting planes are made through polygons to repeatedly subdivide the polygons in a scene in half

Often, BSP Trees are calculated a single time for complex, static scenes

Page 27: Week 1 - Friday.  What did we talk about last time?  C#  SharpDX

Quadtrees and Octrees

Like BSP's, the space can be repeatedly subdivided as long as it contains a number of objects above a certain threshold

Octrees divide the space in three dimensions while quadtrees only focus on two

Page 28: Week 1 - Friday.  What did we talk about last time?  C#  SharpDX

Upcoming

Page 29: Week 1 - Friday.  What did we talk about last time?  C#  SharpDX

Next time…

Rendering pipeline Geometry stage

Page 30: Week 1 - Friday.  What did we talk about last time?  C#  SharpDX

Reminders

Send me teams by today! Keep reading Chapter 2

Focus on 2.3No class on Monday