1 / 30

CS361

Week 1 - Friday. CS361. Last time. What did we talk about last time? C# XNA. Questions?. More XNA Examples. Review of the bouncing cat. Program creates a Game1 (or similar) object and starts it running Game1 has: Initialize() LoadContent () UnloadContent () Update() Draw()

Download Presentation

CS361

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Week 1 - Friday CS361

  2. Last time • What did we talk about last time? • C# • XNA

  3. Questions?

  4. More XNA Examples

  5. Review of the bouncing cat • Program creates a Game1 (or similar) object and starts it running • Game1 has: • Initialize() • LoadContent() • UnloadContent() • Update() • Draw() • It runs an update-draw loop continuously until told to exit

  6. 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 • XNA 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

  7. Drawing text continued • In an XNA solution • Right-click on your content project and select Add and New Item… • Select the Sprite Font template • Call it what you want • Edit the XML to pick the font, size, and spacing • You will need multiple Sprite Fonts even for different sizes of the same font • Note: fonts have complex licensing and distribution requirements

  8. Drawing a font continued • Load the font similar to texture content • Add a DrawString() call in the Draw() method: font = Content.Load<SpriteFont>("GameFont"); spriteBatch.Begin(); spriteBatch.DrawString(font, "Hello, World!", new Vector2(100, 100), Color.Black); spriteBatch.End();

  9. 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

  10. 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);

  11. 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.NoneNo effects • 1 Float level

  12. Student Lecture: Graphics Rendering Pipeline

  13. Graphics Rendering Pipeline

  14. Rendering • What do we have? • Virtual camera (viewpoint) • 3D objects • Light sources • Shading • Textures • What do we want? • 2D image

  15. 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: • Instruction fetch • Decode • Execute • Memory Access • Writeback

  16. Pipeline performance • If you have an n stage pipeline, what's the maximum speedup you can get? • Consider a TV show with the following pipeline • Write • Rewrite • Film • 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

  17. 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:

  18. 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

  19. 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

  20. 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

  21. Application Stage

  22. 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

  23. 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

  24. 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

  25. 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

  26. 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

  27. 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

  28. Upcoming

  29. Next time… • Rendering pipeline • Geometry stage

  30. Reminders • Send me teams by today! • Keep reading Chapter 2 • Focus on 2.3 • No class on Monday

More Related