3D Games Rendering - Érico de Morais Nunes
-
Upload
tchelinux-slides -
Category
Technology
-
view
969 -
download
2
description
Transcript of 3D Games Rendering - Érico de Morais Nunes
May 23, 2009 Tchelinux 2009 1
Érico de Morais Nunes - [email protected]
Universidade Federal do Pampa
3D Games Rendering
May 23, 2009 Tchelinux 2009 2
Summary● About me
● This talk is not about
● Introduction
● Definitions
● OpenGL
● 3D Pipeline Overview
● 3D Rendering Topics
● Shaders and the “future” of 3D development
● Conclusion
May 23, 2009 Tchelinux 2009 3
● About me
● This talk is not about
● Introduction
● Definitions
● OpenGL
● 3D Pipeline Overview
● 3D Rendering Topics
● Shaders and the “future” of 3D development
● Conclusion
May 23, 2009 Tchelinux 2009 4
About Me
● I am a Computer Engineering student.● 3D Rendering is not my main research
area, though I have used it in projects.● I have been into computer graphics for
around a year and a half.● I have not produced any commercial
games.● I am a (casual) gamer. :)
May 23, 2009 Tchelinux 2009 5
Summary● About me
● This talk is not about
● Introduction
● Definitions
● OpenGL
● 3D Pipeline Overview
● 3D Rendering Topics
● Shaders and the “future” of 3D development
● Conclusion
May 23, 2009 Tchelinux 2009 6
This talk is not about
● Unfortunately, this talk is not aimed at...● NVIDIA A is better than ATI B.● Card X runs game Y.● How to code a game.● How to get past level N of game X.
● It is aimed at rendering!
May 23, 2009 Tchelinux 2009 7
● About me
● This talk is not about
● Introduction
● Definitions
● OpenGL
● 3D Pipeline Overview
● 3D Rendering Topics
● Shaders and the “future” of 3D development
● Conclusion
May 23, 2009 Tchelinux 2009 8
Introduction
● Games nowadays look just damn real!● And in real time!
May 23, 2009 Tchelinux 2009 9
Introduction
● How do they do it?
May 23, 2009 Tchelinux 2009 10
Introduction
● We could also go a bit back...● How did they do it, back at the days?
Doom, 1993
System req:
80386 class CPU
(12~40 MHz)
4 MB RAM
May 23, 2009 Tchelinux 2009 11
Introduction
● In this talk, we shall see the science behind graphics.
May 23, 2009 Tchelinux 2009 12
● About me
● This talk is not about
● Introduction
● Definitions
● OpenGL
● 3D Pipeline Overview
● 3D Rendering Topics
● Shaders and the “future” of 3D development
● Conclusion
May 23, 2009 Tchelinux 2009 13
Definitions
● Rendering – Process of creating the 3D image you see on the screen.
● Modeling – Process of generating models to render. For example, designing the characters' models in software like Blender.
May 23, 2009 Tchelinux 2009 14
Definitions
● Pixel – One “dot of color” in your screen.● Vertex – It could be a coordinate in the 3D
space. Like the ones in math.● Fragment – It is all the data needed to generate
a pixel. Depth, color, texture coordinate... Do not confuse it with the pixel itself – you can have many fragments in a pixel space.
● Texture – Name given to an image attached to some geometry in your scene.
May 23, 2009 Tchelinux 2009 15
Definitions
● OpenGL – The cross platform standard API for 3D graphics.
● API – Application Programming Interface. Used to provide an interface to some device.
● GPU – Graphics Processing Unit. Same as the “Graphics card”.
→ These definitions only aim to make quick explanations so that we can go further without major problems :)
May 23, 2009 Tchelinux 2009 16
● About me
● This talk is not about
● Introduction
● Definitions
● OpenGL
● 3D Pipeline Overview
● 3D Rendering Topics
● Shaders and the “future” of 3D development
● Conclusion
May 23, 2009 Tchelinux 2009 17
OpenGL
● “The Industry's Foundation for High Performance Graphics.”
● “From games to virtual reality, mobile phones to supercomputers.”
May 23, 2009 Tchelinux 2009 18
OpenGL
OpenGL (Open Graphics Library) is a standard specification defining a cross-platform API for writing applications that produce 2D and 3D computer graphics.
May 23, 2009 Tchelinux 2009 19
OpenGL
● Some considerations:● It is a rendering API!● OpenGL is not open source.
(There is an open source implementation similar to it, Mesa).
● Maintained by the OpenGl ARB. ● OpenGL is the standard API used in Linux 3D
rendering software.
May 23, 2009 Tchelinux 2009 20
OpenGL
● As for this talk, we are mainly interested in understanding the OpenGL Rendering Pipeline.
May 23, 2009 Tchelinux 2009 21
● About me
● This talk is not about
● Introduction
● Definitions
● OpenGL
● 3D Pipeline Overview
● 3D Rendering Topics
● Shaders and the “future” of 3D development
● Conclusion
May 23, 2009 Tchelinux 2009 22
3D Pipeline
● Do not be scared!● Pipeline: “a chain of data-processing
stages”.
Ok. I want to draw a line and a triangle. What do I need to provide and what steps are performed for it to be rendered?
May 23, 2009 Tchelinux 2009 23
3D Pipeline
http://www.lighthouse3d.com/opengl/glsl/index.php?pipeline
May 23, 2009 Tchelinux 2009 24
3D Pipeline - Vertex
● Vertices are user defined (or loaded from a model). They define your geometry.
● Note that each one has an associated color.
● At games, generally, a texture is provided instead.
May 23, 2009 Tchelinux 2009 25
3D Pipeline - Transformation
● Transformation is related to changing the vertex position.
● It is important – when something needs to move/animate, its vertices need to be transformed!
● Transformation is defined by the user, performed by the pipeline.
May 23, 2009 Tchelinux 2009 26
3D Pipeline – Assembly
● So far, we only have
vertices, coordinates.
● Besides vertices, we have also provided the information on how to connect them.
May 23, 2009 Tchelinux 2009 27
3D Pipeline - Rasterization
● Very important step!
● Your eyes trick you:
Your screen is 2D.
● Rasterization: converting from the 3D space into the “plane” screen space. Fragments.
May 23, 2009 Tchelinux 2009 28
3D Pipeline - Interpolation
● Finally, we perform interpolation between the fragments.
● That is: calculate the color on each pixel, based on the colors at the vertices.
May 23, 2009 Tchelinux 2009 29
3D Pipeline
● That's it.
●
● You now have base knowledge on how it goes for rendering geometry, in a few simple steps!
May 23, 2009 Tchelinux 2009 30
3D Pipeline
● To finish with it, here is a more complete (and complex) pipeline model:
May 23, 2009 Tchelinux 2009 31
● About me
● This talk is not about
● Introduction
● Definitions
● OpenGL
● 3D Pipeline Overview
● 3D Rendering Topics
● Shaders and the “future” of 3D development
● Conclusion
May 23, 2009 Tchelinux 2009 32
3D Rendering Topics
● Now, let's touch at some interesting topics in 3D rendering that are vastly employed in games, such as:● Depth Testing● Space Partitioning● Ray Tracing● Texture Mapping● Modeling
May 23, 2009 Tchelinux 2009 33
3D Rendering Topics
● Objects can be hidden behind other objects.
● OpenGL does not do standard check to figure out which object should be in front and which should be hidden.
● You need to find a way to do it yourself. ● What if you don't?
May 23, 2009 Tchelinux 2009 34
3D Rendering Topics
● Well, this might happen:
May 23, 2009 Tchelinux 2009 35
3D Rendering Topics
● One way to do it is called Depth Testing.● Each fragment has a depth associated to
it, resulting from rasterization● Depth testing performs per fragment
check to identify which fragment is closer to the viewer.
May 23, 2009 Tchelinux 2009 36
3D Rendering Topics
● Depth testing works!
● However, you shouldn't rely on that only.● For large sceneries, checking every
fragment could be very slow. :(
May 23, 2009 Tchelinux 2009 37
3D Rendering Topics
● Ok, think on this:
Could you ever possibly see anything inside the building from here?
May 23, 2009 Tchelinux 2009 38
3D Rendering Topics
● Probably not.● In this case, wouldn't it be wise to discard
everything inside it, ahead of time?
May 23, 2009 Tchelinux 2009 39
3D Rendering Topics
● We can extend this even more:
● We can't see behind that door. We can discard that part of the map.
May 23, 2009 Tchelinux 2009 40
3D Rendering Topics
● This is a kind of Space Partitioning.● It consists in knowing which parts of the
map aren't visible and loading them as they appear.
May 23, 2009 Tchelinux 2009 41
3D Rendering Topics
Doom was only possible back then because of Space Partitioning!
May 23, 2009 Tchelinux 2009 42
3D Rendering Topics
● Out of hidden surfaces, another cool feature is Ray Tracing.
● Ray Tracing is a vector based model which is used to, for example, model light rays and achieve high lighting and shadows realism.
May 23, 2009 Tchelinux 2009 43
3D Rendering Topics
May 23, 2009 Tchelinux 2009 44
3D Rendering Topics
● Texture Mapping: consists of adding pictures to geometry to simulate extra detail.
● For long, games have been relying in texturing to achieve some degree of realism.
May 23, 2009 Tchelinux 2009 45
3D Rendering Topics
● Detailed scenery?!
● Textures are a cheap way to add realism.
May 23, 2009 Tchelinux 2009 46
3D Rendering Topics
● Modeling: how can models made in 3D modelers be added to the OpenGL Pipeline?
May 23, 2009 Tchelinux 2009 47
3D Rendering Topics
● That's no OpenGL business.● Your 3D modeler probably supports
exporting to many different model formats.
● To load it into your game, you load and parse the file yourself, and pass OpenGL the raw ready data :)
May 23, 2009 Tchelinux 2009 48
● About me
● This talk is not about
● Introduction
● Definitions
● OpenGL
● 3D Pipeline Overview
● 3D Rendering Topics
● Shaders and the “future” of 3D development
● Conclusion
May 23, 2009 Tchelinux 2009 49
Shaders and the “future”
● So far, we have only seen a hard defined 3D pipeline, with well defined functions.
● While this could be enough for many tasks, in order to achieve realism, you would need more flexibility.
May 23, 2009 Tchelinux 2009 50
Shaders and the “future”
● A Shader is a piece of code which is used primarily to calculate rendering effects on graphics hardware with a high degree of flexibility.
● GLSL, HLSL, ● In your shader, you can do many cool
things like...
May 23, 2009 Tchelinux 2009 51
Shaders and the “future”
Cell Shading
Per Pixel Lighting
May 23, 2009 Tchelinux 2009 52
Shaders and the “future”
● OpenGL currently supports Vertex Shaders and Pixel Shaders.
● Let's take a look on the new pipeline, with shaders in!
May 23, 2009 Tchelinux 2009 53
Shaders and the “future”
May 23, 2009 Tchelinux 2009 54
Shaders and the “future”
● Some sources say that Shaders are the future of 3D graphics.
● It is not the future. It is the current state of the art.
● Almost everything came down to shaders.
… everything else is on its way to become a shader.
May 23, 2009 Tchelinux 2009 55
● About me
● This talk is not about
● Introduction
● Definitions
● OpenGL
● 3D Pipeline Overview
● 3D Rendering Topics
● Shaders and the “future” of 3D development
● Conclusion
May 23, 2009 Tchelinux 2009 56
Conclusion
● The pipeline is a very important part of graphics rendering.
● Understanding the pipeline is on way to understand what goes on the GPU.
● Figuring out data to be discarded plays major part on performance and detailing level.
● Current games rely heavily in shaders and texturing for highly realistic graphics.
May 23, 2009 Tchelinux 2009 57
Just in case...
● Good reference books:● The OpenGL Superbible 4th Edition● The OpenGL Programming Guide (The Redbook)● OpenGL Shading Language (Orange Book)
● Good web resources for starters:● http://www.lighthouse3d.com● http://nehe.gamedev.net● http://www.videotutorialsrock.com ● http://www.opengl.org