|
Projective TexturesDocument Summary: A comprehensive reference and guide to setting up Projectors. Document Changelog: Last updated by Jason Lentz (DemiurgeStudios) for the 2110 build. Original author was Lode Vandevenne (UdnStaff).
IntroductionWith Projective Textures you can project a texture on anything (walls, floors, actors, Static Meshes, Particle Systems, etc...) to create effects such as shadows, light effects or decals. For example, the shadow of this tree is made with a Projective Texture, it's an artist created shadow texture; it wasn't raytraced by the editor. This creates a much sharper shadow. You can see every leave of the tree in there. Also, the Projective Texture will look the same on BSP, Terrain, Static Meshes or anything else, so the player can't see an unrealistic difference anymore. Another example is light shining through a stained glass window: because the raytracer doesn't support multicolored light through a translucent surface, you can create the effect yourself with a colored Projective Texture: Projective Textures can also be used for decals, for example bloodsplatters or bulletholes:The ProjectorDrawScaleIn the properties of the Projector --> Display, you can change the width and height of the box with DrawScale. The length of the box is not changed with this; that is determinated by MaxTraceDistance. Since you can't change width and height independently, the projection will always be a square. So with DrawScale you change the size of the texture, but you can also do this with FOV, however if you use DrawScale you can change the size without changing the Field Of View. For example, if you want to simulate a shadow from sunlight, where the rays are parallel, and you want the make the texture bigger while the rays still stay parallel, you have to use DrawScale. On the screenshots, the first projector has a DrawScale of 0.5 and the second one 1.5. The DrawScale matches with the Scaling values you can give the BSP surfaces, so the size of the box will also change if you use a bigger or smaller Projective Texture.RotationIf you rotate the Projector, the arrow points towards the direction the texture will be projected, and the blue and yellow box rotate together with the arrow. With Pitch and Yaw you can rotate the projection to the floor, the ceiling, or any of the walls. But you can also Roll the Projector, and this will rotate the Projective Texture itself around its own axis, for example here the graffiti is rotated: You can rotate the projector with the Rotation Tool, but you can also change these settings in its properties --> Movement --> Rotation. 360 degrees is equal to 65536 units (2^16) in the Rotation settings.bClipBSPThe texture is repeated over the whole BSP surface, but if you set in the properties of the Projector bClipBSP to True. When you did this, the projected texture will be there only once, inside the blue frustum. bClipBSP works on BSP surfaces only, there's also a better way to make the texture not repeating on all types of geometry, explained later in this tutorial.bClipStaticMeshJust like bClipBSP, the texture will be repeated over the entire surface of any StaticMesh that has any polygons inside the blue frustum of the Projector.bDynamicAttachThis setting only exists for the editor to call it while the game is in progress. You should not need to touch this value and it is best to leave it at its default False setting.bGradientIf this value is set to True, then the projected texture will become more transparent the further away from the projector is from the point of contact on a surface. This is useful for creating shadows or lights that fade out as the fall further from their source.bLevelStaticIf you set bLevelStatic to True, the actual Projector Actor will be destroyed immediately when you open the map in the game, however the projection will stay on the wall forever. This means, the projection that was created at the moment you opened the map, right before the Projector was destroyed, becomes "frozen" on the walls. If the Projector has bProjectActor = True, and a player walks in the blue box, the player will not get the projection on him, because the projector itself has disappeared. If bLevelStatic is False, the Projector will stay in the map forever, and if now players or other actors walk in the frustum, they'll get the projection on their body. For example, on the first screenshot bLevelStatic = True, and on the second screenshot bLevelStatic = False. I also set bHidden to False for the Projector, so you can see the Projector has disappeared on the first picture, but not on the second. If you hold a weapon, you can also see the projection on the weapon, if bLevelStatic = False. For decals such as this graffiti, you better set bLevelStatic to True, but for light and shadow effects you can set it to False, so the light or shadow will also be projected on the players.bProjectActorIf this is set True, the Projector will make its projection on actors such as players and the weapons that they are holding.bProjectBSPIf you set this value to be True, the Project will project on to BSP geometry.bProjectOnAlpha & bProjectOnParallelBSPThese settings no longer have any effect.bProjectOnBackfacesThis setting controls the intensity of the projection on a surface. If left False, the projection will be more transparent on more oblique angles and more opaque on more perpendicular angles. If set to True, the entire projection will be equally bright on all angles that it projects on to. The True setting is useful for projecting shadows since they do not appear more or less dark depending on the angle of incidence of the shadow. Note: IIRC GeForce 1/2 cards will always project on backfaces in certain cases as they can't handle the stage setup required to cullbProjectOnUnlitThis setting allows you to choose if the project should or should not project on unlit surfaces. For example if you made a surface Unlit because you don't want it to receive shadows, you should set bProjectOnUnlit to False for a Projector that casts a shadow.bProjectParticlesIf this is set True, the Projector will show up on particles in particle systems. This can be useful for creating effects with particle system dust or snow passing through a beam of light from a window (or perhaps a stained glass window).bProjectStaticMeshIf this is set True, the Projector will show up on StaticMeshes.bProjectTerrainSetting this value to True will cause this projector on to terrain.FOVWith FOV you can change the Field Of View of the blue frustrum. Don't set the FOV to 0, then the projection looks weird. For example on the screenshots, the Projector on the left has a FOV of 50 and the one on the right has a FOV of 5. With a high FOV, especially higher than 100, the result will look weird. Also, the higher the FOV, the more there will be cut away some sides of the texture. So it is better to leave a large enough transparent border around the texture so the invisible parts are removed and you can't see the difference. Note that, if the arrow of the Projector is pointing upwards, but because of the FOV the floor still touches the blue frustum, there will be no projection on the floor.FrameBufferBlendingOp & MaterialBlendingOpThese options two fields determine the blending operation between the material being projected onto and the projected texture. Below each of their effects are described. Nearly each combination of every setting can produce a different effect. Below is a list of what each setting will get you. I have used both a StaticMesh and a ProjTexture with AlphaChannels to illustrate all the nuances. This is the Texture used for the ProjTexture: FrameBufferBlendingOp = NoneMaterialBlendingOp = None MaterialBlendingOp = Modulated MaterialBlendingOp = AlphaBlend  :MaterialBlendingOp = Add FrameBufferBlendingOp = Modulated MaterialBlendingOp = None MaterialBlendingOp = Modulated MaterialBlendingOp = AlphaBlend MaterialBlendingOp = Add FrameBufferBlendingOp = AlphaBlend MaterialBlendingOp = None MaterialBlendingOp = Modulated MaterialBlendingOp = AlphaBlend MaterialBlendingOp = Add FrameBufferBlendingOp = Add MaterialBlendingOp = None MaterialBlendingOp = Modulated MaterialBlendingOp = AlphaBlend MaterialBlendingOp = Add MaxTraceDistanceWith MaxTraceDistance you can change the length of the box; anything behind this length will not get the projection anymore. For example, on the screenshot the left Projector has a MaxTraceDistance of 200, and this is too short to hit the wall, so it won't cast a projection on the wall. The projector on the right has a MaxTraceDistance of 400 and is long enough, so the traces hit the wall and there will be a projection on the wall. Also keep in mind that the Project can project through walls, and it will cast on any surface that is within its MaxTraceDistance and facing the Projector.ProjectTagThis allows you to limit the Project to projecting onto StaticMeshes that share the same tag as the one that is entered in this field. The Projector will still render onto Actors, Terrain, BSP geometry, etc., though even if it does not have a matching Tag to the ProjectTag assigned in this field. bDynamicAttach must also be set to False for this option to work. To disable the projector on the other surfaces you must set the corresponding values to false (respectively: bProjectActor, bProjectTerrain, and bProjectBSP, etc.).ProjTextureThe Projective Textures are projected with Projectors. This is an actor class like any other, where you can set the texture you want it to project, the direction, the FOV, and more. The Projector is in the Actor Class Browser --> Projector. When you add one in your map, the Projector is represented with a projector sprite. To give the projector a texture, open the Texture Browser, and select the texture you want to use, preferably a texture with a transparent background. The texture should be a square texture, for example 256*256, and not a texture with a different height and width, for example 256*128. In the last case, the texture will be resized to make it a square. When you have selected the texture, go to the properties of the Projector, expand Projector and click on ProjTexture. Press the Use button that appears, so the name of the selected texture appears in the text field. Also, set the FOV setting to something higher than 0, because if this setting is 0 the projection will look weird. For example if you set it to 1, it'll be almost parallel. Now that it has a texture, rotate the Projector with the Rotation Tool , so the arrow points towards the wall, ground, terrain or whatever you want the texture to be projected at. You should also see a yellow box and a blue frustum when you selected the Projector. The blue frustum represents the rays of the projector, and the section of the surfaces with this box will get the projection (in most cases). When you rotated it towards a BSP wall that's close enough, you should see something like this:ClampModeIf you project the texture on something, it'll normally be repeating. Only if you set bClipBSP to True, it'll not be repeating on BSP, but on other things, such as large Static Meshes, it still will. To avoid this, you have to set the UClampMode and VClampMode of the used texture to TC_Clamp. These settings are in the Texture Properties --> Texture. For example, if you leave for this texture UClampMode and VClampMode to TC_Wrap, and you project the texture on this big Static Mesh, it'll be repeating: If you set UClampMode to TC_Clamp and VClampMode to TC_Wrap, it'll look like the first screenshot, and it you set UClampMode to TC_Wrap and VClampMode to TC_Clamp, it'll look like the second picture: When you set both UClampMode and VClampMode to TC_Clamp, the texture will not be repeating anymore: Warning: when you use TC_Clamp, make sure all the pixels at the edge of the texture are 100% transparent: otherwise, these outer pixels are spread over the whole surface. For example, if I set bAlphaTexture to False for the texture, it'll become 100% opaque, and the whole Static Mesh has got the red-greed gradient now. You also have to make sure all the mipmaps have a transparent border, otherwise you may see the texture spread out if you look at it from a distance. If you save it as a *.dds file with the DDS Plug-in (in PSP or PhotoShop), make sure you set the Border Color of the mipmaps to something that will become transparent, this means 127-grey if you want to use the texture modulated, black if it's transparent, or the alpha channel is black at the borders if you want to use it as AlphaTexture. If you want the texture to be repeating, set one or both of the settings to TC_Wrap, and if you project on BSP surfaces, also make sure bClipBSP is False. On BSP, the texture will only be repeated on the walls that touch the blue frustum, for example the wall on the screenshot exists out of 2 BSP surfaces: the upper one with the green texture, and the lower one with the grey texture. The texture will only be repeated on both surfaces if the projector is placed this way, that the blue frustum touches both surfaces:ShadowYou can use the Projective Textures for decals, most of the examples above were decals, but you can also use them for shadow and light effects. If you want to make a shadow, you need a grayscale texture that darkens the surface, and has the same shape as the object where the shadow comes from. For example, you could give this tree a shadow with a Projective Texture: it'll look 100 times better compared to what the raytracer can do on terrain. First you need to make the shadow texture. To do this, an easy way is to take a screenshot of the tree when it's inside a black room, and then it's easy to select the tree in PSP or PhotoShop with a Magic Wand tool. Take this screenshot from the same angle as where the light is coming from. For shadows, it's best to make the texture modulated (the Projector does this by default): then all the grey values darker than 127 will darken the surface where it's projected on. So you need to make everything inside the selection dark grey: the darker you make it, the darker the shadow will be. Then, the background should get the grey value 127, this is the RGB color with R=G=B=127: when you make the texture modulated in the editor, this grey is going to become invisible. Finally, you have to resize the texture to a square, with the sizes a power of 2, for example you can make it 256*256. Import it into the editor, and in the Texture Properties --> Surface set bModulated to True. Also set the U and VClampMode to TC_Clamp, otherwise the texture will be partially repeating on the terrain. Then give the texture to the projector, place the projector above the tree, and give it the same angle as the light. Give it the correct DrawScale, and make the FOV=1 if the shadow is caused by the sun, so it has parallel rays, or make the FOV bigger if it isn't sunlight. Also make sure bLevelStatic=False, so the players will get the shadow on them when they walk under the tree. Now the tree should have an incredibly detailed shadow:LightYou can make lighting exactly the same way as the shadow explained above, only this time use a color brighter than the 127-grey for the parts of the Projective Textures that have to brighten the surface. But for the change, it's done with the AlphaChannel of a RGBA8 texture in this example. Also, this example uses multicolored lighting: light shining through a stained glass window. This is something you can't do with Rebuild Lighting, only with Projective Textures. This is the actual stained glass window in the wall. The objective is to cast the light coming through this window on the floor. The texture used for this stained glass window can't be used for the Projector, because the window texture hasn't got the correct alpha-channel. You can use the same RGB part for the Projective Texture, only make sure it's a square (add borders if it isn't). Then, in the alpha-channel of the texture, make everything black, except the parts where the light will shine through. For example, where all the little glass windows are, it should be grey, because the light goes partially through these. The brighter the grey, the brighter the light will be there. Where the little stone columns and arches are, the alpha-channel should be black: light doesn't go through stone. Also, if you had to added borders to the texture to make it square, the alpha-channel should be black there too. You can also make the alpha-channel a little blurry, because the lighting of stained glass isn't very sharp in reality. The first screenshot shows the RGB part of the texture, and the second screenshot shows the alpha-channel. Save this texture as a 32 bit RGBA file and import it into the editor. In the Texture Properties set bAlphaTexture=True. Give it to a Projector, give the projector the correct DrawScale and angle, and it should work: Note that the texture for the window itself (so not the one used for the Projector) is also a RGBA8 texture, and that the alpha-channel of this texture is the inverse of the alpha-channel for the Projector: for this one, the stone columns and arches should not be invisible, but opaque instead, so the alpha-channel is white there.Spawned DecalsYou can spawn Projectors during game play with a script, for example for the holes in the wall caused by bullets, or blood splatters when a player dies. If the Projector Actor is spawned in the game, the Projector Actor itself can be destroyed immediately after it was spawned. The projection on the surface will stay then. This is the same as what happens when you set bLevelStatic=True: also then the Projector Actor gets destroyed, but it's projection stays. There are decals like this in the Actor Class Browser --> Projector --> Scorch.Rotating ProjectionsYou can make the Projector Actor to rotate, then the projected texture will rotate, but the frustrum of the Projector will not! In other words, the projected texture will always be projected on the same surfaces, no matter how the Projector rotates. This means, only roll is really useful: this makes rotate the projected texture around it's center, so it can be used for the shadow of a spinning fan. First of all, make sure the U and VClampMode of the texture you want to use are set to TC_Clamp. Otherwise, the texture will be repeating inside the frustum, even if bClipBSP=True. Then, once you have a Projector with the texture, open the Projector Properties, and expand Movement. There set bFixedRotationDir = True, Physics = PHYS_Rotating, and inside RotationRate set the Roll you want. The higher the Roll, the faster the texture will rotate. When you set Physics to PHYS_Rotating, you'll see the blue and yellow boxes become bigger, this is because it has to contain the corners of the texture when it's rotating. Note that you also can use Pitch and Yaw, but the yellow and blue boxes will remain fixed, so you see the texture rotating while it's still projected on the same wall. If you set the U and VClampMode of the Projective Texture to TC_Wrap, and bClipBSP=False, the texture is repeating on the wall, and the whole thing will rotate then. This can for example be used for rotating water, you can determinate the center where the water spins around with the location of the Projector then.Final Notes
|