Presentation is loading. Please wait.

Presentation is loading. Please wait.

Game Programming 09 OGRE3D Lighting/shadow in Action

Similar presentations

Presentation on theme: "Game Programming 09 OGRE3D Lighting/shadow in Action"— Presentation transcript:

1 Game Programming 09 OGRE3D Lighting/shadow in Action
2010년 2학기 디지털콘텐츠전공

2 Rendering in Video Games
Depth-Buffered Triangle Rasterization Virtual Scene Virtual Camera Various Light Sources Visual Properties Solving the Rendering Equation (Shading Equation)

3 Rendering in OGRE3D Depth-Buffered Triangle Rasterization
Virtual Scene  createScene() Virtual Camera  createCamera()/ createViewport() Various Light Sources  createScene() Visual Properties  material Solving the Rendering Equation (OGRE3D engine)

4 What does make a scene look real?
Material Lighting (shade + shadow)

5 OGRE3D Lighting Three types of lighting in OGRE3D
Point (Ogre::Light::LT_POINT) Point light sources emit light from them in every direction. Spotlight (Ogre::Light::LT_SPOTLIGHT) A spotlight works exactly like a flashlight does. Directional (Ogre::Light::LT_DIRECTIONAL) Directional light simulates far-away light that hits everything in the scene from a direction.

6 Creating a Light Creating a Light Setting a type Setting a position
SceneManager::createLight(“name”) Setting a type Ogre::Light::setType( … ) LT_POINT, LT_DIRECTIONAL, LT_SPOTLIGHT Setting a position Ogre::Light::setPosition( Ogre::Vector3(x,y,z) ) Ogre::Light* pointLight = mSceneMgr->createLight("pointLight"); pointLight->setType(Ogre::Light::LT_POINT); pointLight->setPosition(Ogre::Vector3(0, 150, 250));

7 Setting a Light Setting the color Setting the direction
Ogre::Light::setDiffuseColour (Ogre::ColourValue(r,g,b)) Ogre::Light::setSpecularColour (Ogre::ColourValue(r,g,b)) Setting the direction Ogre::Light::setDirection( Ogre::Vector3(x,y,z)) Setting the spot light property Ogre::Light::setSpotlightRange (inner_angle, outer_angle) angle: Ogre::Degree(angle) Ogre::Light* directionalLight = mSceneMgr->createLight("directionalLight"); directionalLight->setType(Ogre::Light::LT_DIRECTIONAL); directionalLight->setDiffuseColour(Ogre::ColourValue(.25, .25, 0)); directionalLight->setSpecularColour(Ogre::ColourValue(.25, .25, 0)); directionalLight->setDirection(Ogre::Vector3( 0, -1, 1 ));

8 Shadow Shadows are: There are many techniques to render shadows.
one of the most challenging aspects of 3D rendering still very much an active area of research. There are many techniques to render shadows. None is perfect and they all come with advantages and disadvantages

9 How to draw a shadow? Off-line algorithm Real-time algorithm
Ray tracing shadow Real-time algorithm Projected planar shadows Shadow mapping (texture-based shadow) Stencil Shadow Volume

10 Ray Tracing Shadow

11 Projected Planar Shadows
The simplest technique to create shadows from an object. Two-pass algorithm Draw the object Draw the shadow Problem: Only on a planar surface

12 Shadow Mapping Testing whether a pixel is visible from the light source by comparing it to a depth image of the light source's view Depth image is stored as a texture  Texture-based shadow Visualization of the depth map projected onto the scene Scene rendered from the light view Scene from the light view, depth map. Depth map test failures Scene with shadow mapping

13 Shadow Mapping A problem of the shadow mapping:
Aliasing How to solve the problem: Increasing the resolution of the texture Projective shadow map single shadow map pixel

14 Stencil Shadow Volume Stencil + Shadow Volume

15 Stencil buffer Stencil buffer is like a mask.

16 Typical use of a stencil buffer
Drawing a reflection effect Drawing a planar shadow 참고자료:

17 Shadow volume concept Shadow volume is constructed from occluders
Although we can create volumes for every triangle in the occluders, we only need the silhouette. Different types of volume for different types of lights

18 Shadow Volume concept All the objects positioned within a shadow volume are hidden from the light source and are thus in either full or partial shadow. A silhouette edge can more generally be considered as an outline or edge separating a front- and back-facing surface.

19 Shadow Volume concept A point light source and the shadow Volume

20 Stencil Shadow Volume Render the Scene without lights and keep the z-buffer. Fragments with non-zero stencil values are considered to be in shadow. The generation of the values in the stencil buffer : Render front face of shadow volume. If depth test passes, increment stencil value Render back face of shadow volume. If depth test passes, decrement stencil value Render the lit area where the stencil buffer value is 0

21 Stencil Shadow Volume Stencil Shadow Volume in Action Shadow volume
in wireframe Rendered with the shadow Shadow volume

22 Stencil Shadow Pros Very accurate and robust Nearly artifact-free
Faceting near the silhouette edges is the only problem Work for point lights and directional lights equally well Low memory usage

23 Stencil Shadow Cons Too accurate — hard edges Very fill-intensive
Need a way to soften Very fill-intensive Scissor and depth bounds test help Significant CPU work required Silhouette determination Building shadow volumes Hard shadow Soft shadow

24 Shadow in OGRE3D Multiple implementations about shadow
How to know where shadows are: Stencil Shadow Texture-based shadow How to draw the shadows Modulative shadows : darkening Additive Light Masking : brightening

25 Enabling shadows Disabled by default Enabling a shadow technique
This should be the first thing of the scene setup. Type can be stencil shadow or texture-based shadow Create Lights. By default, they will cast shadows To turn off the shadow: Create Objects. By default, they will cast shadows mSceneMgr->setShadowTechnique(ShadowType) Calling Light::setCastsShadows(false) Calling Entity::setCastsShadows(false)

26 Stencil Shadow Shadow Type either: Good thing: Bad thing:
Modulative Shadow SHADOWTYPE_STENCIL_MODULATIVE Additive Light Masking SHADOWTYPE_STENCIL_ADDITIVE Good thing: Self-Shadow on low-end hardware Bad thing: Hard-shadow only Slow because of a higher polygon count mSceneMgr->setShadowTechnique(SHADOWTYPE_STENCIL_MODULATIVE)

27 Stencil Shadow Issues CPU overhead for shadow volume computation
Avoid any long shadows (e.g. a very low sun position) Culling distant objects beforehand Shadow volume accuracy Don’t put any object too close to a light source Mesh edge list Edge list is necessary for constructing the shadow volume Official exporter and tools will generate it automatically If you use your own mesh, you can generate it by calling Mesh::buildEdgeList Visible silhouette edge Silhouette edge can be very marked. Especially, the mudulative method is more vulnerable with 2 or more light sources Additive lights do not suffer from this as badly because each light is masked individually

28 Texture-based shadow Rendering shadow casters for the point of view of the light into a texture. Then, projected onto shadow receiver. Type Name: SHADOWTYPE_TEXTURE_MODULATIVE SHADOWTYPE_TEXTURE_ADDITIVE Good things: Lower overhead Hardware acceleration Customisable (e.g. easy to make soft shadows) Bad things: Aliasing effect depending on the resolution Only supports direction lights and spotlights

29 Texture-based shadow Configurations Maximum number of shadow textures
Shadow texture size Shadow far distance Shadow texture offset (Directional Lights) Shadow fade settings

30 Modulative Shadow Drawing a scene without shadows
Darkening(modulating) the shadow area

31 Additive Shadow Drawing a scene with ambient light
Adding each light one by one For this reason, rendering should be divided into several passes: Ambient pass Diffuse/specular pass Decal pass

32 Additive shadow Pass spliting example material TestIllumination {
technique pass ambient diffuse 1 0 0 specular texture_unit texture grass.png }

33 Additive shadow Pass dividing example // Ambient pass pass {
diffuse 0 0 0 specular 0 0 0 } // Diffuse / specular pass pass { scene_blend add iteration once_per_light diffuse 1 0 0 specular } // Decal pass pass { scene_blend modulate lighting off texture_unit texture grass.png }

Download ppt "Game Programming 09 OGRE3D Lighting/shadow in Action"

Similar presentations

Ads by Google