Shadow Maps and Projective Texturing In X3D · in shadow looks the same as object outside of...

25
Motivation and Previous Work Shadow Maps Algorithm High-level Shadows Extensions Low-level Shadows Extensions For Shadow Maps Summary Shadow Maps and Projective Texturing In X3D Michalis Kamburelis [email protected] Institute of Computer Science University of Wroclaw, Poland Web3D 2010 Michalis Kamburelis Shadow Maps and Projective Texturing In X3D

Transcript of Shadow Maps and Projective Texturing In X3D · in shadow looks the same as object outside of...

Page 1: Shadow Maps and Projective Texturing In X3D · in shadow looks the same as object outside of light’s radius, so things look OK. Michalis Kamburelis Shadow Maps and Projective Texturing

Motivation and Previous WorkShadow Maps Algorithm

High-level Shadows ExtensionsLow-level Shadows Extensions For Shadow Maps

Summary

Shadow Maps and Projective TexturingIn X3D

Michalis [email protected]

Institute of Computer ScienceUniversity of Wrocław, Poland

Web3D 2010

Michalis Kamburelis Shadow Maps and Projective Texturing In X3D

Page 2: Shadow Maps and Projective Texturing In X3D · in shadow looks the same as object outside of light’s radius, so things look OK. Michalis Kamburelis Shadow Maps and Projective Texturing

Motivation and Previous WorkShadow Maps Algorithm

High-level Shadows ExtensionsLow-level Shadows Extensions For Shadow Maps

Summary

Outline1 Motivation and Previous Work

MotivationPrevious Work

2 Shadow Maps Algorithm3 High-level Shadows Extensions

Shadow ReceiversShadow CastersLights Configuration

4 Low-level Shadows Extensions For Shadow MapsOverview and ExamplesGenerated Shadow MapProjected Texture Coordinate

5 Summary

Michalis Kamburelis Shadow Maps and Projective Texturing In X3D

Page 3: Shadow Maps and Projective Texturing In X3D · in shadow looks the same as object outside of light’s radius, so things look OK. Michalis Kamburelis Shadow Maps and Projective Texturing

Motivation and Previous WorkShadow Maps Algorithm

High-level Shadows ExtensionsLow-level Shadows Extensions For Shadow Maps

Summary

MotivationPrevious Work

Outline1 Motivation and Previous Work

MotivationPrevious Work

2 Shadow Maps Algorithm3 High-level Shadows Extensions

Shadow ReceiversShadow CastersLights Configuration

4 Low-level Shadows Extensions For Shadow MapsOverview and ExamplesGenerated Shadow MapProjected Texture Coordinate

5 Summary

Michalis Kamburelis Shadow Maps and Projective Texturing In X3D

Page 4: Shadow Maps and Projective Texturing In X3D · in shadow looks the same as object outside of light’s radius, so things look OK. Michalis Kamburelis Shadow Maps and Projective Texturing

Motivation and Previous WorkShadow Maps Algorithm

High-level Shadows ExtensionsLow-level Shadows Extensions For Shadow Maps

Summary

MotivationPrevious Work

We Want The Scenes To Look Pretty

Shadows make the scene lookrealistic.Shadows automatically makethe impression that „more stuff ishappening” on the screen.This is even more true fordynamic scenes, whereshadows also changedynamically.

Michalis Kamburelis Shadow Maps and Projective Texturing In X3D

Page 5: Shadow Maps and Projective Texturing In X3D · in shadow looks the same as object outside of light’s radius, so things look OK. Michalis Kamburelis Shadow Maps and Projective Texturing

Motivation and Previous WorkShadow Maps Algorithm

High-level Shadows ExtensionsLow-level Shadows Extensions For Shadow Maps

Summary

MotivationPrevious Work

We Want The User To Understand What IsDisplayed

Shadows help the mind to determine the positions of the 3Dobjects.Is this spider hovering or standing on the ground?

Michalis Kamburelis Shadow Maps and Projective Texturing In X3D

Page 6: Shadow Maps and Projective Texturing In X3D · in shadow looks the same as object outside of light’s radius, so things look OK. Michalis Kamburelis Shadow Maps and Projective Texturing

Motivation and Previous WorkShadow Maps Algorithm

High-level Shadows ExtensionsLow-level Shadows Extensions For Shadow Maps

Summary

MotivationPrevious Work

Previous Work

Both Bitmanagement and Octaga proposed their own shadowsextensions. We argue that our extensions are a little better :)

Easier for non-technical authorsFlexible for advanced authorsNice for implementors

Of course, we would like to see the shadows extensionsincluded in the X3D specification.

Michalis Kamburelis Shadow Maps and Projective Texturing In X3D

Page 7: Shadow Maps and Projective Texturing In X3D · in shadow looks the same as object outside of light’s radius, so things look OK. Michalis Kamburelis Shadow Maps and Projective Texturing

Motivation and Previous WorkShadow Maps Algorithm

High-level Shadows ExtensionsLow-level Shadows Extensions For Shadow Maps

Summary

Outline1 Motivation and Previous Work

MotivationPrevious Work

2 Shadow Maps Algorithm3 High-level Shadows Extensions

Shadow ReceiversShadow CastersLights Configuration

4 Low-level Shadows Extensions For Shadow MapsOverview and ExamplesGenerated Shadow MapProjected Texture Coordinate

5 Summary

Michalis Kamburelis Shadow Maps and Projective Texturing In X3D

Page 8: Shadow Maps and Projective Texturing In X3D · in shadow looks the same as object outside of light’s radius, so things look OK. Michalis Kamburelis Shadow Maps and Projective Texturing

Motivation and Previous WorkShadow Maps Algorithm

High-level Shadows ExtensionsLow-level Shadows Extensions For Shadow Maps

Summary

Shadow Maps Algorithm Overview

1 Render a shadow map from a lightsource.

2 Project a shadow map when renderingthe actual view for the screen. Thismeans using a shadow map texture,and calculating a texture coordinatessuch that you know the distance fromthe light at each screen pixel.

3 Compare depth value from the shadowmap with the actual depth.Object in the shadow must be behindan object obscuring the light.

Michalis Kamburelis Shadow Maps and Projective Texturing In X3D

Page 9: Shadow Maps and Projective Texturing In X3D · in shadow looks the same as object outside of light’s radius, so things look OK. Michalis Kamburelis Shadow Maps and Projective Texturing

Motivation and Previous WorkShadow Maps Algorithm

High-level Shadows ExtensionsLow-level Shadows Extensions For Shadow Maps

Summary

Shadow Maps Terms

Michalis Kamburelis Shadow Maps and Projective Texturing In X3D

Page 10: Shadow Maps and Projective Texturing In X3D · in shadow looks the same as object outside of light’s radius, so things look OK. Michalis Kamburelis Shadow Maps and Projective Texturing

Motivation and Previous WorkShadow Maps Algorithm

High-level Shadows ExtensionsLow-level Shadows Extensions For Shadow Maps

Summary

Shadow ReceiversShadow CastersLights Configuration

Outline1 Motivation and Previous Work

MotivationPrevious Work

2 Shadow Maps Algorithm3 High-level Shadows Extensions

Shadow ReceiversShadow CastersLights Configuration

4 Low-level Shadows Extensions For Shadow MapsOverview and ExamplesGenerated Shadow MapProjected Texture Coordinate

5 Summary

Michalis Kamburelis Shadow Maps and Projective Texturing In X3D

Page 11: Shadow Maps and Projective Texturing In X3D · in shadow looks the same as object outside of light’s radius, so things look OK. Michalis Kamburelis Shadow Maps and Projective Texturing

Motivation and Previous WorkShadow Maps Algorithm

High-level Shadows ExtensionsLow-level Shadows Extensions For Shadow Maps

Summary

Shadow ReceiversShadow CastersLights Configuration

Define Shadow Receivers

New field for the Appearance nodeMFNode [] receiveShadows []# [X3DLightNode] list

Very easy to use.Ideally, the only thing really needed by authors for simplestpurposes.So simple, it’s suitable for any shadow algorithm.Light contribution (whole, including ambient) is scaledto zero where the light is in the shadow. This way objectin shadow looks the same as object outside of light’sradius, so things look OK.

Michalis Kamburelis Shadow Maps and Projective Texturing In X3D

Page 12: Shadow Maps and Projective Texturing In X3D · in shadow looks the same as object outside of light’s radius, so things look OK. Michalis Kamburelis Shadow Maps and Projective Texturing

Motivation and Previous WorkShadow Maps Algorithm

High-level Shadows ExtensionsLow-level Shadows Extensions For Shadow Maps

Summary

Shadow ReceiversShadow CastersLights Configuration

Reasoning: Where To Place Shadow Information?Separate node: not natural. We want to make shadowscommonly used in the scenes, so activating shadows mustbe easy. Also, separate node is not really needed forflexibility.Casters: there’s not much you want to configure onshadow casters. You just want to „treat everything asshadow caster by default”.Lights: yes, put some information there, but not flexibleenough.Shadow receivers seem like the best choice:

Natural for authors: shadows change the look of theshadow receiver.Natural for implementors: shadow receivers must berendered in a special way.

Michalis Kamburelis Shadow Maps and Projective Texturing In X3D

Page 13: Shadow Maps and Projective Texturing In X3D · in shadow looks the same as object outside of light’s radius, so things look OK. Michalis Kamburelis Shadow Maps and Projective Texturing

Motivation and Previous WorkShadow Maps Algorithm

High-level Shadows ExtensionsLow-level Shadows Extensions For Shadow Maps

Summary

Shadow ReceiversShadow CastersLights Configuration

Shadow Casters

By default, everything casts a shadow. Simple globalconfiguration: you can disable casting any shadows from thisshape.

New field for the Appearance nodeSFBool [in,out] shadowCaster TRUE

What if this is too simple? For complicated cases, another fieldlike doNotCastShadows can be added, to disable castingshadows for some chosen lights and/or some chosenreceivers. In practice, this wasn’t needed on our scenes.

Michalis Kamburelis Shadow Maps and Projective Texturing In X3D

Page 14: Shadow Maps and Projective Texturing In X3D · in shadow looks the same as object outside of light’s radius, so things look OK. Michalis Kamburelis Shadow Maps and Projective Texturing

Motivation and Previous WorkShadow Maps Algorithm

High-level Shadows ExtensionsLow-level Shadows Extensions For Shadow Maps

Summary

Shadow ReceiversShadow CastersLights Configuration

Shadow Map ParametersIn principle, every light by default is capable of castingshadows. So you don’t have to do anything. However, you cantweak some shadow maps stuff:

New field for the X3DLightNodeSFNode [] defaultShadowMap NULL# [GeneratedShadowMap]

The way this works will be clear later, when we describeGeneratedShadowMap node. For now, we just note that thisallows you to:

manually control when the shadow map is updated,change shadow map size,indicate that you want to visualize shadow maps.

Michalis Kamburelis Shadow Maps and Projective Texturing In X3D

Page 15: Shadow Maps and Projective Texturing In X3D · in shadow looks the same as object outside of light’s radius, so things look OK. Michalis Kamburelis Shadow Maps and Projective Texturing

Motivation and Previous WorkShadow Maps Algorithm

High-level Shadows ExtensionsLow-level Shadows Extensions For Shadow Maps

Summary

Shadow ReceiversShadow CastersLights Configuration

Lights Projection ParametersFor shadow maps, we have to be able to treat lights ascameras. So we need some projection parameters. When youuse receiveShadows, the browser should be able tocalculate suitable values for fields below automatically.But you can tweak them, for complicated cases and low-levelusage.

New fields for X3DLightNodeSFFloat [in,out] projectionNear 0SFFloat [in,out] projectionFar 0SFVec3f [in,out] up 0 0 0

...and some additional fields for the DirectionalLight andSpotLight, see the paper for details.

Michalis Kamburelis Shadow Maps and Projective Texturing In X3D

Page 16: Shadow Maps and Projective Texturing In X3D · in shadow looks the same as object outside of light’s radius, so things look OK. Michalis Kamburelis Shadow Maps and Projective Texturing

Motivation and Previous WorkShadow Maps Algorithm

High-level Shadows ExtensionsLow-level Shadows Extensions For Shadow Maps

Summary

Overview and ExamplesGenerated Shadow MapProjected Texture Coordinate

Outline1 Motivation and Previous Work

MotivationPrevious Work

2 Shadow Maps Algorithm3 High-level Shadows Extensions

Shadow ReceiversShadow CastersLights Configuration

4 Low-level Shadows Extensions For Shadow MapsOverview and ExamplesGenerated Shadow MapProjected Texture Coordinate

5 Summary

Michalis Kamburelis Shadow Maps and Projective Texturing In X3D

Page 17: Shadow Maps and Projective Texturing In X3D · in shadow looks the same as object outside of light’s radius, so things look OK. Michalis Kamburelis Shadow Maps and Projective Texturing

Motivation and Previous WorkShadow Maps Algorithm

High-level Shadows ExtensionsLow-level Shadows Extensions For Shadow Maps

Summary

Overview and ExamplesGenerated Shadow MapProjected Texture Coordinate

Why Low-level Extensions?

A couple of cooperating extensions to achieve shadow maps.Implementors:

Very easy to handle in the renderer.Open a way to handle high-level extensions by transformingto low-level.

Authors:Not easy for authors: you need to understand how shadowmaps work.But: you can use own shaders (GLSL etc.)But: you can use projective texturing for other purposes.

Michalis Kamburelis Shadow Maps and Projective Texturing In X3D

Page 18: Shadow Maps and Projective Texturing In X3D · in shadow looks the same as object outside of light’s radius, so things look OK. Michalis Kamburelis Shadow Maps and Projective Texturing

Motivation and Previous WorkShadow Maps Algorithm

High-level Shadows ExtensionsLow-level Shadows Extensions For Shadow Maps

Summary

Overview and ExamplesGenerated Shadow MapProjected Texture Coordinate

Example of Low-level Extensions Usage

DEF MySpot SpotLight {location 0 0 10 direction 0 0 -1projectionNear 1 projectionFar 20 }

Shape {appearance Appearance {texture GeneratedShadowMap {light USE MySpot update "ALWAYS" } }

geometry IndexedFaceSet {texCoord ProjectedTextureCoordinate {projector USE MySpot }

# ... other IndexedFaceSet fields} }

Michalis Kamburelis Shadow Maps and Projective Texturing In X3D

Page 19: Shadow Maps and Projective Texturing In X3D · in shadow looks the same as object outside of light’s radius, so things look OK. Michalis Kamburelis Shadow Maps and Projective Texturing

Motivation and Previous WorkShadow Maps Algorithm

High-level Shadows ExtensionsLow-level Shadows Extensions For Shadow Maps

Summary

Overview and ExamplesGenerated Shadow MapProjected Texture Coordinate

How Is This Related To High-level Extensions?

The low-level extensions cooperate very nicely with high-levelextensions described previously:

receiveShadows and defaultShadowMap may beimplemented by transforming the scene to use low-levelextensions.How to transform: For each shape withreceiveShadows, add to it’s textures aGeneratedShadowMap node and add to it’s tex coords aProjectedTextureCoordinate. Details in the paper.Rest (light’s projection, shadow casters) is simply usedas-is.

Michalis Kamburelis Shadow Maps and Projective Texturing In X3D

Page 20: Shadow Maps and Projective Texturing In X3D · in shadow looks the same as object outside of light’s radius, so things look OK. Michalis Kamburelis Shadow Maps and Projective Texturing

Motivation and Previous WorkShadow Maps Algorithm

High-level Shadows ExtensionsLow-level Shadows Extensions For Shadow Maps

Summary

Overview and ExamplesGenerated Shadow MapProjected Texture Coordinate

New X3D Node: Generated Shadow MapYou can place this inside e.g. a texture field, or as a textureinside shader node (like ComposedShader for GLSL):

GeneratedShadowMap : X3DTextureNodeSFString [in,out] update "NONE"# ["NONE" | "ALWAYS" | "NEXT_FRAME_ONLY"]

SFInt32 [] size 128SFNode [] light NULL # [X3DLightNode]SFFloat [in,out] scale 1.1SFFloat [in,out] bias 4.0SFString [] compareMode"COMPARE_R_LEQUAL" # ["COMPARE_R_LEQUAL"# | "COMPARE_R_GEQUAL" | "NONE"]

Michalis Kamburelis Shadow Maps and Projective Texturing In X3D

Page 21: Shadow Maps and Projective Texturing In X3D · in shadow looks the same as object outside of light’s radius, so things look OK. Michalis Kamburelis Shadow Maps and Projective Texturing

Motivation and Previous WorkShadow Maps Algorithm

High-level Shadows ExtensionsLow-level Shadows Extensions For Shadow Maps

Summary

Overview and ExamplesGenerated Shadow MapProjected Texture Coordinate

Projecting Textures ExplainedUntextured scene Texture to project

Final scenewith projected texture

+ =

Final scene,as seen fromthe projector:

Michalis Kamburelis Shadow Maps and Projective Texturing In X3D

Page 22: Shadow Maps and Projective Texturing In X3D · in shadow looks the same as object outside of light’s radius, so things look OK. Michalis Kamburelis Shadow Maps and Projective Texturing

Motivation and Previous WorkShadow Maps Algorithm

High-level Shadows ExtensionsLow-level Shadows Extensions For Shadow Maps

Summary

Overview and ExamplesGenerated Shadow MapProjected Texture Coordinate

New X3D Node: Projected Texture CoordinateYou can place this inside e.g. texCoord fields:

ProjectedTextureCoordinate : X3DTextureCoordinateNodeSFNode [in,out] projector NULL# [SpotLight, DirectionalLight,# X3DViewpointNode]

Generates texture coordinates that project (cast) a texture.For shadow maps: project your shadow map from a lightsource.You can also project a normal texture (e.g. colorMovieTexture).You can also project from a viewpoint (e.g. to cast aheadlight texture).

Michalis Kamburelis Shadow Maps and Projective Texturing In X3D

Page 23: Shadow Maps and Projective Texturing In X3D · in shadow looks the same as object outside of light’s radius, so things look OK. Michalis Kamburelis Shadow Maps and Projective Texturing

Motivation and Previous WorkShadow Maps Algorithm

High-level Shadows ExtensionsLow-level Shadows Extensions For Shadow Maps

Summary

Outline1 Motivation and Previous Work

MotivationPrevious Work

2 Shadow Maps Algorithm3 High-level Shadows Extensions

Shadow ReceiversShadow CastersLights Configuration

4 Low-level Shadows Extensions For Shadow MapsOverview and ExamplesGenerated Shadow MapProjected Texture Coordinate

5 Summary

Michalis Kamburelis Shadow Maps and Projective Texturing In X3D

Page 24: Shadow Maps and Projective Texturing In X3D · in shadow looks the same as object outside of light’s radius, so things look OK. Michalis Kamburelis Shadow Maps and Projective Texturing

Motivation and Previous WorkShadow Maps Algorithm

High-level Shadows ExtensionsLow-level Shadows Extensions For Shadow Maps

Summary

SummaryHigh-level extensions to easily get shadows

Define shadow receivers by the receiveShadows field.Easy to use, easy to implement basing on low-levelextensions.

Low-level extensions to fully control shadow mapsDefine shadow receivers by explicitly addingGeneratedShadowMap andProjectedTextureCoordinate to textures and texcoords.Easy to implement.Projective texturing available also independently.Usable with custom shaders.

Michalis Kamburelis Shadow Maps and Projective Texturing In X3D

Page 25: Shadow Maps and Projective Texturing In X3D · in shadow looks the same as object outside of light’s radius, so things look OK. Michalis Kamburelis Shadow Maps and Projective Texturing

Motivation and Previous WorkShadow Maps Algorithm

High-level Shadows ExtensionsLow-level Shadows Extensions For Shadow Maps

Summary

Thank you for your attention!

Questions?

Visit our VRML engine onhttp://vrmlengine.sourceforge.net/

Michalis Kamburelis Shadow Maps and Projective Texturing In X3D