Animation and Games Development
description
Transcript of Animation and Games Development
242-515 AGD: 11. Textures 11
• Objectiveo introduce texturing and its use in environment
mapping, lightmapping, bump mapping and shadows
Animation and Games
Development242-515, Semester 1, 2014-2015
11. Textures and Maps
242-515 AGD: 11. Textures 22
1. Why Textures?2. Textures in jME3. Wrap Modes4. Texture Resizing5. jME Transparency6. Texture Mapping
onto Surfaces
Overview
7. Multitexturing8. Environment
Mapping9. Light Mapping10.Bump Mapping11.Multi-pass
Rendering12.Shadow Mapping
242-515 AGD: 11. Textures 33
• A texture makes a shape look better without increasing its number of vertices.
• A texture is an image wrapped around a shape.• Textures are usually 2D images. There are also 1D
and 3D textures.
1. Why Textures?
242-515 AGD: 11. Textures 44
• The color of a pixel is determined by mapping from (s,t) texture space to the pixel's (x,y,z) world space• sometimes (u,v) axis labels are used instead of (s,t)
Texture mapping
t(1, 1)
(0, 1)(s, t) = (0.2, 0.8)
(0.4, 0.2)
(0.8, 0.4)
A
B C
a
bc
Texture Space World Space
s(1, 0)(0, 0)
242-515 AGD: 11. Textures 55
Mapping Examples
• mapping all of a texture to one face of a shape
242-515 AGD: 11. Textures 66
Texture mappings involving parts of atexture are most commonly used bytexture atlases (see later).
242-515 AGD: 11. Textures 77
• Textures are made of texels• just as images are made from pixels
• Texels have R,G,B,A componentso usually means red, green, blue, alpha o but can be used to store other data
Texture Formats
242-515 AGD: 11. Textures 88
• Specify how texture colors modify pixel colors• Common modes:
o DECAL: replace pixel color with texture color
o BLEND: combine texture and pixel colors using weighted addition
o MODULATE: combine texture and pixel colors using multiplication of their components
Texture Functions
242-515 AGD: 11. Textures 99
• A 1D texture is a 2D texture with height == 1o often used for drawing colored stripes/lines
• A 3D texture is like a stack of 2D textureso often used in visualization
• e.g. medical imaging
1D and 3D Textures
242-515 AGD: 11. Textures 1010
• Add a texture to an unshaded (unlit) material:o mat.setTexture("ColorMap",
assetManager.loadTexture("Textures/monkey.png")); // with Unshaded.j3md
• Add a texture to a lit material:o mat.setTexture("DiffuseMap",
assetManager.loadTexture("Textures/wood.png")); // with Lighting.j3md
2. Textures in jME
242-515 AGD: 11. Textures 1111
Unlit Texture ExampleUnlitTexture.java
242-515 AGD: 11. Textures 1212
public void simpleInitApp() { flyCam.setMoveSpeed(20); Box mesh = new Box(2,2,2); Geometry geom = new Geometry("mesh", mesh);
Material mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md"); mat.setTexture("ColorMap", assetManager.loadTexture("Textures/R.png")); geom.setMaterial(mat); rootNode.attachChild(geom); }
Partial Code
R.png
242-515 AGD: 11. Textures 1313
Lit Texture ExampleLitTexture.java
242-515 AGD: 11. Textures 1414
public void simpleInitApp() { flyCam.setMoveSpeed(20); Box mesh = new Box(2,2,2); Geometry geom = new Geometry("mesh", mesh); Material mat = new Material(assetManager, "Common/MatDefs/Light/Lighting.j3md"); mat.setTexture("DiffuseMap", assetManager.loadTexture("Textures/R.png")); :
Partial Code
242-515 AGD: 11. Textures 1515
mat.setBoolean("UseMaterialColors", true); mat.setColor("Diffuse",ColorRGBA.White); mat.setColor("Specular",ColorRGBA.White); mat.setFloat("Shininess", 8f); // [0,128] geom.setMaterial(mat); rootNode.attachChild(geom);
// add a light to make the lit object visible DirectionalLight sun = new DirectionalLight(); sun.setDirection(new Vector3f(1,-1, -2).normalizeLocal()); sun.setColor(ColorRGBA.White); rootNode.addLight(sun); } // end of simpleInitApp()
242-515 AGD: 11. Textures 1616
How to deal with (s,t) values outside 0-1
3. Wrap Modes
Mirror once (mirror+clamp)
Clamp
Border color
Wrap (Repeat)
Mirror
Original
Black edges
shown for illustration
only
242-515 AGD: 11. Textures 1717
• Wrapping is also known as tiling or repeating.
Wrapping and Clamping
242-515 AGD: 11. Textures 1818
Texture tex = mat.getTextureParam("DiffuseMap"). getTextureValue(); System.out.println("texture: " + tex); System.out.println("Texture type: " + tex.getType()); System.out.println("Mag/Min filtering: " + tex.getMagFilter() + "/" + tex.getMinFilter()); System.out.println("Anisotropic filtering level: " + tex.getAnisotropicFilter());
Texture.WrapMode horizWrapMode = tex.getWrap(Texture.WrapAxis.S); // horizontal wrap Texture.WrapMode vertWrapMode = tex.getWrap(Texture.WrapAxis.T); // vertical wrap System.out.println("(S,T) wrap modes: (" + horizWrapMode + ", " + vertWrapMode + ")");
Accessing jME Texture InfoLitTexture.java
242-515 AGD: 11. Textures 1919
texture: Texture2D [name=Textures/R.png, image=Image[size=256x256, format=BGR8]]
Texture type: TwoDimensional
Mag/Min filtering: Bilinear/TrilinearAnisotropic filtering level: 1
(S,T) wrap modes: (EdgeClamp, EdgeClamp)
Output
242-515 AGD: 11. Textures 2020
• In LitTexture.java:
• mesh.scaleTextureCoordinates(new Vector2f(2,1)); // times to repeat on X and Y axes
• tex.setWrap(Texture.WrapAxis.S, Texture.WrapMode.Repeat);
Adjusting the Wrap Mode in jME
242-515 AGD: 11. Textures 2121
Result
4. Texture Resizing• Magnification: when a pixel is mapped to a part of
one texel
• Minification: when a pixel is mapped to many texels
242-515 AGD: 11. Textures 2323
• Texture magnification/minification without filtering produces ugly visual effects:o When magnified, the texels become very obviouso When minified, the texture becomes “sparkly”
Texture Filtering
242-515 AGD: 11. Textures 2424
• Bilinear filtering is used to smooth a texture when it is displayed larger or smaller than its normal size. • blends edges of texel neighbours
• Magnification looks better, but minification may still sparkle.
Bilinear Filtering
242-515 AGD: 11. Textures 2525
Bilinear Filtering Effect
No filtering Bilinear Filtering
magnified
minified
242-515 AGD: 11. Textures 2626
• Mipmaps reduce problems with minification.
• A mipmap is a pre-calculated, optimized collection of bitmap images for a texture
• Each bitmap image is a version of the texture at a reduced level of detail (LOD).
• The rendering engine uses a different bitmap for wrapping the object depending on its distance from the viewer.
Mipmaps
242-515 AGD: 11. Textures 2727
Examples
242-515 AGD: 11. Textures 2828
• Mipmapping of the road texture:
242-515 AGD: 11. Textures 2929
texture
mipmap for the texture
a singleimagefile
242-515 AGD: 11. Textures 3030
+
viewer
242-515 AGD: 11. Textures 3131
• Common mipmap minification filterso NEAREST: uses the nearest mipmap closest to the
polygon resolution, and applies bilinear filtering
o LINEAR: uses linear interpolation between the two mipmaps closest to the polygon resolution, and applies bilinear filtering
Mipmap Filters
242-515 AGD: 11. Textures 3232
• Transitions between one mipmap size and the next may be obviouso the change is visible as a moving/flickering line
• Use trilinear filteringo blends between mipmap sizes smoothly
Trilinear Filtering
bilinear/trilinear- the difference
is only apparentwhen the user moves
242-515 AGD: 11. Textures 3333
• Improves on bilinear and trilinear filtering by reducing blur and preserving more detail at extreme viewing angles.
Anisotropic Filtering
trilinear filtering(blurry)
anisotropicfiltering(less blurry)
242-515 AGD: 11. Textures 3434
Filtering and Mipmapping
Using textures without filtering and mipmapping.
With filteringand mipmapping
242-515 AGD: 11. Textures 3535
• jME creates a mipmap automatically for a texture (unless disabled).
• It is possible to import models with pre-calculated mipmap textureso e.g. using the dds plugin for gimp
http://code.google.com/p/gimp-dds/
Mipmapping in jME
242-515 AGD: 11. Textures 3636
• For colored Materials, the last float of an RGBA color is the Alpha channel. o Alpha = 1.0f makes the color opaque (the default)o Alpha = 0.0f make the color transparento Alpha between 0f and 1f makes the color more or less
translucent
• A translucent red:mat.setColor("Color", new ColorRGBA(1,0,0, 0.5f));
5. jME Transparency
242-515 AGD: 11. Textures 3737
• For textured Materials, either supply an AlphaMap that specifies which areas are transparent.setTexture("AlphaMap", assetManager.loadTexture("Textures/window_alpha.png"));
• or add an alpha channel to the ColorMap/DiffuseMap
• Enable alpha rendering:mat.setBoolean("UseAlpha",true);
242-515 AGD: 11. Textures 3838
• Specify alpha blending for the Material:mat.getAdditionalRenderState().setBlendMode( BlendMode.Alpha);
• Put the Geometry (not the Material!) in the appropriate render queue:geom.setQueueBucket(Bucket.Translucent);
orgeom.setQueueBucket(Bucket.Transparent);
242-515 AGD: 11. Textures 3939
Alpha Map ExampleGlassSphere.java
Spinning see-through sphere in front of a brick wall
242-515 AGD: 11. Textures 4040
// cyan sphere Sphere sphere = new Sphere(32,32, 2f); Geometry geom = new Geometry("sphere", sphere); Material mat = new Material(assetManager, "Common/MatDefs/Light/Lighting.j3md");
mat.setBoolean("UseMaterialColors",true); mat.setColor("Ambient", ColorRGBA.Cyan); mat.setColor("Diffuse", ColorRGBA.Cyan); mat.setColor("Specular", ColorRGBA.White); mat.setFloat("Shininess", 16f); // [0,128] :
Partial Code
242-515 AGD: 11. Textures 4141
// transparent texture mat.setTexture("AlphaMap", assetManager.loadTexture( "Textures/R_bw.png")); mat.setBoolean("UseAlpha",true); mat.getAdditionalRenderState().setBlendMode(BlendMode.Alpha); geom.setQueueBucket(Bucket.Transparent);
geom.setMaterial(mat);
R_bw.jpg
242-515 AGD: 11. Textures 4242
Using a rock Alpha Map
rock.png
mat.setTexture("AlphaMap", assetManager.loadTexture("Textures/rock.png"));
242-515 AGD: 11. Textures 4343
• In planar mapping, one of the (x,y,z) components of the shape (usually the z-axis) is ignored when mapping from the (s,t) texture space to the pixel's (x,y,z) world space• leaves us with a simple (s,t) ↔ (x,y) mapping
6. Texture Mapping onto Surfaces
43
ignore z-axis of shape whenmapping
242-515 AGD: 11. Textures 4444
ignore z-axis of shapeswhen mapping
Planar Surface Mapping
242-515 AGD: 11. Textures 4545
Cylindrical Surface Mapping
texture cylinder’s long axis is the y-axis
The default mapping for most shapes in jME
242-515 AGD: 11. Textures 4646
Cylinder mesh = new Cylinder(100, 100, 2, 3, true); :geom.rotate(-FastMath.HALF_PI, 0, 0); // rotate up
Cylinder in LitTexture.java
242-515 AGD: 11. Textures 4747
• Using a cylinderical surface for the texture:
Rotating SphereSphereTex.java
242-515 AGD: 11. Textures 4848
Sphere mesh = new Sphere(16,16,2);mesh.scaleTextureCoordinates(new Vector2f(5,1)); // times to repeat on X and y axes
Geometry geom = new Geometry("mesh", mesh);Material mat = new Material(assetManager, "Common/MatDefs/Light/Lighting.j3md");mat.setTexture("DiffuseMap", assetManager.loadTexture("Textures/R.png"));geom.setMaterial(mat);
geom.rotate(-FastMath.HALF_PI, 0, 0); // rotate upright
Partial Code
242-515 AGD: 11. Textures 4949
Spherical Surface Mapping
uses latitude andlongitude for thetexture mapping
stretches the squares in the map near the equator, and squeezes the squares as the longitude reaches a pole
242-515 AGD: 11. Textures 5050
• Switched to a spherical surface mapping for the texture:
Rotating Sphere (Remapped)
mesh.setTextureMode(Sphere.TextureMode.Projected);
242-515 AGD: 11. Textures 5151
• A texture atlas is a texture image which contains several sub-images, each of which is a texture for a part of the 3D object.
Texture Atlases
+ =
242-515 AGD: 11. Textures 5252
• Texture atlases reduce the amount of texture state switching by the underlying graphics engineo makes rendering faster
atlas with 100 sub-images,for decorating a 2D world
242-515 AGD: 11. Textures 5353
The HoverTank ModelTestHoverTank.java
242-515 AGD: 11. Textures 5454
• The model is loaded with:o Node tank = (Node) assetManager.loadModel(
"Models/HoverTank/Tank2.mesh.xml");
• The mesh, and various texture maps, are located inside jmonkeyplatform\libs\jME3-testdata.jar
242-515 AGD: 11. Textures 5555
tank_diffuse.jpg
242-515 AGD: 11. Textures 5656
• Multitexturing is applying several textures to the same surface.
• Multitexturing hardware supports texture units, each of which applies a standard texture map operation.
7. Multitexturing
242-515 AGD: 11. Textures 5757
• Multitexturing for layering detail onto a terrain.
we'll do this later in jME
242-515 AGD: 11. Textures 5858
• A texture matrix can be used to “transform” the textureo e.g. translation the texture over the shape
• If the texture matrix changes over time, the texture will appear to move on the objecto Useful for implementing flames, water, clouds, etc.
Animating Texture
242-515 AGD: 11. Textures 5959
• An environment map (a texture) is used to approximate mirrored surfaces
8. Environment Mapping
242-515 AGD: 11. Textures 6060
242-515 AGD: 11. Textures 6161
• The texture color is transferred from the environment map onto the object in the direction of the reflected ray sent from the viewer.
Theory
Object
viewer
Reflected ray
Environment Map(a texture)
242-515 AGD: 11. Textures 6262
• A cube map texture is made from six 2D texture maps that correspond to the sides of a boxo one kind of environment map
Cube Mapping
242-515 AGD: 11. Textures 6363
Cube Map Format
242-515 AGD: 11. Textures 6464
• An environment map can be statico often used for sky + hills + ground in a 3D
sceneo hard to notice that it’s not correcto very fast and effectiveo called a skybox
Static Environment Maps
242-515 AGD: 11. Textures 6565
A Skybox in jME
rotate thecamera inthe scene
SkyBox.java
242-515 AGD: 11. Textures 6666
public void simpleInitApp() { Texture west = assetManager.loadTexture("Textures/Sky/ Lagoon/lagoon_west.jpg"); Texture east = assetManager.loadTexture("Textures/Sky/ Lagoon/lagoon_east.jpg"); Texture north = assetManager.loadTexture("Textures/Sky/ Lagoon/lagoon_north.jpg"); Texture south = assetManager.loadTexture("Textures/Sky/ Lagoon/lagoon_south.jpg"); Texture up = assetManager.loadTexture("Textures/Sky/ Lagoon/lagoon_up.jpg"); Texture down = assetManager.loadTexture("Textures/Sky/ Lagoon/lagoon_down.jpg");
Spatial sky = SkyFactory.createSky(assetManager, west, east, north, south, up, down); rootNode.attachChild(sky); }
Partial Code
242-515 AGD: 11. Textures 6767
Six Skybox Images\jmonkeyplatform\libs\jME3-testdata.jar
242-515 AGD: 11. Textures 6868
• When the object using the environment map moves, then the map should change.
• Can be done using multi-pass rendering• six rendering passes needed to build the sides of a
new cube map• another pass to apply the map to the object
Dynamic Environment Mapping
Sphere Mapping
• Problems:o non-uniform samplingo non-linear mapping
Another kind of environment mapping.
9. Light Mapping• A light map is used to simulate
light effects on a surface. o It’s often a gray scale image,
which is blended with another texture to produce lighting effects
• This approach speeds up run-time lighting since the lighting effects have been pre-computed and stored in a mapo complex (slow) illumination
techniques can be used to create the map (e.g. shadows)when the game is being coded
Example
No light maps With light maps
Specular Mapping
• Not all objects are uniformly shiny all over their surface, e.g.:o tile floors are worn in placeso metal with corrosion spotso partially wet surfaces
• Specular mapping is a way tovary the amount of specularlight over a shape.
242-515 AGD: 11. Textures 7373
Example
the specular mapspecular reflection
242-515 AGD: 11. Textures 7474
Specular Map for the Hover Tank
tank_specular.jpg
242-515 AGD: 11. Textures 7575
• Add a BloomFilter PostProcessor to simpleInitApp()
• Specify a Glow color. mat.setColor("GlowColor",ColorRGBA.White);
• Optionally specify a GlowMap texture. mat.setTexture("GlowMap", assetManager.loadTexture("Textures/alien_glow.png"));
o says where the DiffuseMap texture glows;o If you don't supply a GlowMap, then the whole material
glows
jME Glowing
242-515 AGD: 11. Textures 7676
Glowing ColorsGlowSpheres.java
no glow
red glow
white glow
242-515 AGD: 11. Textures 7777
// needed by all glowing objectsFilterPostProcessor fpp = new FilterPostProcessor(assetManager);BloomFilter bloom = new BloomFilter(BloomFilter.GlowMode.Objects);fpp.addFilter(bloom);viewPort.addProcessor(fpp);
:
Partial Code
242-515 AGD: 11. Textures 7878
// the glowing red sphere Geometry sph2 = new Geometry("chequered", sphere); Material mat2 = new Material(assetManager, "Common/MatDefs/Light/Lighting.j3md");
mat2.setBoolean("UseMaterialColors",true); mat2.setColor("Diffuse", ColorRGBA.Cyan); mat2.setColor("Ambient", ColorRGBA.Cyan); mat2.setColor("GlowColor", ColorRGBA.Red); :
242-515 AGD: 11. Textures 7979
Glowing Maps VersionGlowSpheres.java (with maps)
no glow
chequered map
random map
242-515 AGD: 11. Textures 8080
// glowing using a chequered patternGeometry sph2 = new Geometry("chequered", sphere);Material mat2 = new Material(assetManager, "Common/MatDefs/Light/Lighting.j3md");mat2.setBoolean("UseMaterialColors",true);mat2.setColor("Diffuse", ColorRGBA.Cyan);mat2.setColor("Ambient", ColorRGBA.Cyan);mat2.setTexture("GlowMap", assetManager.loadTexture("Textures/bloom-glow2.png"));
Partial Code
bloom-glow2.png
10. Bump Mapping
• Makes a shape's surface look bumpy without changing the shape's geometry.
• The bump map changes the surface normal values by small amounts.o also called normal
mapping
242-515 AGD: 11. Textures 8282
• Normal vectors are stored with the shape's vertices.
• Rough surfaces require lots of variation in the surface normalso this would require lots more vertices
• Use a bump map instead to change the shape's normals at each pixel.
242-515 AGD: 11. Textures 8383
Bump
242-515 AGD: 11. Textures 8484
• Object Surface(with normals)
• Bump map
• Object Surface(with changed normals)
Bump Map Example
242-515 AGD: 11. Textures 8585
• The bump map stores a series of heightso the heights are turned into surface normals by
calculating the differences between neighbors in the s and t directions
Bump Mapping Uses Heights
bump map heights bump map surface normals
242-515 AGD: 11. Textures 8686
Varying the Bumps
242-515 AGD: 11. Textures 8787
• Generate normal vectors information for the mesh:TangentBinormalGenerator.generate(mesh);
• Specify a normal map texture for the Material:mat.setTexture("NormalMap", assetManager.loadTexture( "Textures/wood_normal.png")); // with Lighting.j3md
Bump Maps in jME
242-515 AGD: 11. Textures 8888
Example Bumps.java
242-515 AGD: 11. Textures 8989
Sphere rock = new Sphere(32, 32, 2); // A rocky ball Geometry rockGeom = new Geometry("rock", rock); rock.setTextureMode(Sphere.TextureMode.Projected); TangentBinormalGenerator.generate(rock); Material rMat = new Material(assetManager, "Common/MatDefs/Light/Lighting.j3md"); rMat.setTexture("DiffuseMap", assetManager.loadTexture( "Textures/Pebbles/Pebbles_diffuse.png")); rMat.setTexture("NormalMap", assetManager.loadTexture( "Textures/Pebbles/Pebbles_normal.png"));
rMat.setBoolean("UseMaterialColors", true); rMat.setColor("Diffuse",ColorRGBA.White); rMat.setColor("Specular",ColorRGBA.White); rMat.setFloat("Shininess", 4f); // [0,128]
rockGeom.setMaterial(rMat); rockGeom.setLocalTranslation(0,1,0); // Move it a bit rockGeom.rotate(1.6f, 0, 0); // Rotate it a bit rootNode.attachChild(rockGeom);
:
Partial Code
242-515 AGD: 11. Textures 9090
// A wall with a rough bricky surface Box box = new Box(2, 2, 2); Geometry wall = new Geometry("wall", box); TangentBinormalGenerator.generate(wall); Material wMat = new Material(assetManager, "Common/MatDefs/Light/Lighting.j3md"); wMat.setTexture("DiffuseMap", assetManager.loadTexture( "Textures/BrickWall/BrickWall_diffuse.jpg")); wMat.setTexture("NormalMap", assetManager.loadTexture( "Textures/BrickWall/BrickWall_normal.jpg")); wall.setMaterial(wMat); wall.setLocalTranslation(0,-3,0); // Move it a bit rootNode.attachChild(wall);
242-515 AGD: 11. Textures 9191
Bumps.java Maps
242-515 AGD: 11. Textures 9292
• If the normal maps are commented out:
Without Bumps
242-515 AGD: 11. Textures 9393
Bump Mapping Atlas
242-515 AGD: 11. Textures 9494
Normal Map for the Hover Tank
tank_normals.png
242-515 AGD: 11. Textures 9595
• Bump mapping adjusts surface normals (but there's no change to the vertices)
• Displacement mapping uses a map to change the shape's vertices.
Displacement Mapping
242-515 AGD: 11. Textures 9696
• The outline of the shape gives away whether bump mapping or displacement mapping was used.
242-515 AGD: 11. Textures 9797
• Draw the scene, or parts of the scene, multiple times to achieve certain effects. o Used for mirrors, shadows, etc.o It can be used to approximate multi-texturing when
multi-texturing is not supported by the hardwareo Disadvantage: rendering a frame takes longer
11. Multi-pass Rendering
242-515 AGD: 11. Textures 9898
• Shadows are created by testing whether a pixel is visible from the light sourceo comparing pixel to a z-buffer or depth image of the light
source's view
12. Shadow Mapping
add shadowmapping
242-515 AGD: 11. Textures 9999
• jME offers two forms of shadow:o BasicShadowRenderer: basic drop shadows onto a flat
surface
o Parallel-Split Shadow Map (PSSM): for shadows that fall on complex (curved) surfaces; more resource intensive
jME Shadows
242-515 AGD: 11. Textures 100100
• Shadow calculations (casting and receiving) slow down performance.
• So switch off shadow processing for the scene graph, and specify the shadow behaviour for each node that needs it: o specifiy whether a node casts shadows, receives
shadows, or does both
Reducing Shadow Calculations
242-515 AGD: 11. Textures 101101
rootNode.setShadowMode(ShadowMode.Off); // graph nodes will not process shadows
wall.setShadowMode(ShadowMode.CastAndReceive); // switch on cast/receive processing for this node
floor.setShadowMode(ShadowMode.Receive); // only receive; this node doesn't make shadows
airplane.setShadowMode(ShadowMode.Cast); // only cast; no shadows fall onto this node
242-515 AGD: 11. Textures 102102
The Basic Shadow RendererTeapotShadow.java
the flooronlyreceivesshadows
the teapotcasts andreceivesshadows
242-515 AGD: 11. Textures 103103
cam.setLocation(new Vector3f(0, 3, 5));cam.lookAt(Vector3f.ZERO, Vector3f.UNIT_Y); // look at the origin with +y-axis being up
cam.setFrustumFar(10); // or shadows go 'funny'
rootNode.setShadowMode(ShadowMode.Off); :
Partial Code
242-515 AGD: 11. Textures 104104
// the floor Box floor = new Box(Vector3f.ZERO, 2, 0.1f, 2); Geometry floorGeom = new Geometry("Floor", floor);
Material fmat = new Material(assetManager, "Common/MatDefs/Light/Lighting.j3md"); fmat.setBoolean("UseMaterialColors",true); fmat.setColor("Diffuse", ColorRGBA.Blue); fmat.setColor("Specular", ColorRGBA.White); fmat.setFloat("Shininess", 16f); // [0,128] floorGeom.setMaterial(fmat);
floorGeom.setShadowMode(ShadowMode.Receive); rootNode.attachChild(floorGeom); :
242-515 AGD: 11. Textures 105105
// the teapot teapot = assetManager.loadModel("Models/Teapot/Teapot.obj"); teapot.setLocalScale(1.5f);
Material tmat = new Material(assetManager, "Common/MatDefs/Light/Lighting.j3md"); tmat.setBoolean("UseMaterialColors", true); tmat.setColor("Diffuse", ColorRGBA.Orange); tmat.setColor("Specular", ColorRGBA.White); tmat.setFloat("Shininess", 12); teapot.setMaterial(tmat);
RenderState rs = tmat.getAdditionalRenderState(); rs.setFaceCullMode(RenderState.FaceCullMode.Off);
teapot.setShadowMode(ShadowMode.CastAndReceive); rootNode.attachChild(teapot); :
242-515 AGD: 11. Textures 106106
BasicShadowRenderer bsr = new BasicShadowRenderer(assetManager, 512); bsr.setDirection(new Vector3f(-1, -1, -1).normalizeLocal()); viewPort.addProcessor(bsr);
// add a light to make the lit objects visible DirectionalLight sun = new DirectionalLight(); sun.setDirection(new Vector3f(-1, -1, -1).normalizeLocal()); sun.setColor(ColorRGBA.White); rootNode.addLight(sun);
242-515 AGD: 11. Textures 107107
TeapotPssm.java• The same scene graph as before, but using PSSM.
Parallel-Split Shadow Map
242-515 AGD: 11. Textures 108108
• The only change is the replacement of the BasicShadowRenderer object by a PssmShadowRenderer
PssmShadowRenderer pr = new PssmShadowRenderer(assetManager, 1024, 3); pr.setDirection( new Vector3f(-1, -1, -1).normalizeLocal()); viewPort.addProcessor(pr);
• On my low-end machine, PSSM shadows often do not render correctly when the camera is moved.
Partial Code