Tutorials

Transparent Texture Shadows



In this tutorial you will learn how you can make the opaque parts of a transparent texture on a model cast shadows.

You may be wondering "What does alpha mean?" Alpha - or more specifically the alpha channel, is what defines transparency in an image. For example, glass textures have an alpha channel that makes them transparent.

For example: a fence
news post image

The fence's grating has an alpha channel that allows you to see through it. This is great for visual looks like looking through it, but source has no idea what to do about lighting for the alpha channel for props, and it simply uses the collision model as a shadow reference. This would be okay, but it looks really unrealistic when a light is near it.

news post image

In the days of the HL2 Source engine and the HL2:EP1 engine you had to make a grating yourself, by taking a blocklight texture and cutting it out. Nobody ever wanted to do this because it was pointless and very time consuming (And the shadows looked blocky)

Then came the Orangebox engine, and at first, we could use projectedtextures to create our dynamic lights, but then nVidia complained about the shadows from these entities and resulted in nVidia users getting these nasty grainy-edged shadows. Yes, they were dynamic (And partially better than what i'm about to teach you about), but they are really bad looking.

Skip forward to now, where we have learned that the light compiler (vrad) now has an option to allow the alpha channel to allow light through. That command? -TextureShadows.

This command, combined with -StaticPropPolys, can allow your alpha channels to create shadows. This is better than before, but there are still some flaws. These shadows are lightmap shadows, so they cannot be moved and thus, are static.

But if you're using a static prop you shouldn't care anyways.

Anyways, you may be wondering "Alright, this sounds cool, how do I accomplish this?".

Basic requirements

Orangebox /Source 2009 Engine Game (Half-Life 2 Episode 2 or Left 4 Dead)

Prop with texture that has alpha channel (In this case we'll be using a fence model)

Step 1 - Create a lights.rad file

First of all, go into notepad and copy this

lights/fluorescentcool001a	189 231 232 350
lights/fluorescentcool001b	236 255 182 350
lights/fluorescentcool002a	189 231 232 400
lights/fluorescentcool002b	236 255 182 400
lights/fluorescentcool003a	189 231 232 300
lights/fluorescentwarm001a	239 216 193 350
lights/fluorescentwarm002a	239 216 193 400
lights/fluorescentwhite001a	245 245 245 350
lights/fluorescentwhite002a	245 245 245 400


lights/hazzardred001a		228 37 0 300
lights/hazzardyellow001a	250 215 74 300

lights/HIDcool001a		145 222 172 650
lights/HIDcool001b		205 232 255 650
lights/HIDwarm001a		255 201 116 650

lights/white001			250 240 205 100
lights/white002			189 233 247 425
lights/white003			232 246 190 350
lights/white004			170 228 247 425
lights/white005			234 235 220 375
lights/white006			234 235 220 100

lights/blue001			166 180 196 200 166 180 196 100
lights/blue002			141 176 203 200 141 176 203 100
lights/red001			63 1 1 200 63 1 1 100

lights/white001_nochop	250 240 205 100
lights/white002_nochop	189 233 247 425
lights/white003_nochop	232 246 190 350
lights/white004_nochop	170 228 247 425
lights/white005_nochop	234 235 220 375
lights/white006_nochop	234 235 220 100

lights/incandescentcool001a	235 235 235 300
lights/incandescentwarm001a	250 226 129 300


glass/glassscreen001a		172 192 161 225
glass/glasspipe001f		214 72 44 200
glass/glassscreen001c		172 192 161 225
glass/glassscreen001d		211 187 134 225
glass/glassblock001a		70 194 209 200 
composite/citadelfloor001a	103 143 203 200
props/tvscreen006a		196 0 0 200
shadertest/gooinglass		149 49 15 50

glass/glasswindow002e		189 233 247 425
glass/glasswindow035a		145 222 172 100

dev/DEV_INTERIORLIGHT02B	151 176 204 225

plaster/plasterwall029h		189 223 227 125
building_template/Building_Trainstation_Template001d	230 230 200 65
building_template/Building_Trainstation_Template001e	230 230 200 150
building_template/Building_Trainstation_window002d	230 230 200 300
building_template/Building_Trainstation_window002e	230 230 200 300

lights/physgunlight	189 231 232 20

noshadow tree_deciduous_01a_branches.vmt
noshadow tree_deciduous_01a_leaves.vmt
noshadow tree_deciduous_01a_lod.vmt
noshadow tree_deciduous_01a_lod-leaves.vmt

forcetextureshadow props_foliage/tree_dead01.mdl
forcetextureshadow props_foliage/tree_dead02.mdl
forcetextureshadow props_foliage/tree_dead03.mdl
forcetextureshadow props_foliage/tree_dead04.mdl
forcetextureshadow props_foliage/tree_dry01.mdl
forcetextureshadow props_foliage/tree_dry02.mdl
forcetextureshadow props_foliage/tree_pine_large.mdl
forcetextureshadow props_foliage/tree_pine04.mdl
forcetextureshadow props_foliage/tree_pine05.mdl
forcetextureshadow props_foliage/tree_pine06.mdl
forcetextureshadow props_foliage/tree_deciduous_01a.mdl
forcetextureshadow props_foliage/tree_deciduous_02a.mdl
forcetextureshadow props_wasteland/interior_fence001a.mdl
forcetextureshadow props_wasteland/interior_fence001b.mdl
forcetextureshadow props_wasteland/interior_fence001c.mdl
forcetextureshadow props_wasteland/interior_fence001d.mdl
forcetextureshadow props_wasteland/interior_fence001e.mdl
forcetextureshadow props_wasteland/interior_fence001g.mdl
forcetextureshadow props_wasteland/interior_fence002a.mdl
forcetextureshadow props_wasteland/interior_fence002b.mdl
forcetextureshadow props_wasteland/interior_fence002c.mdl
forcetextureshadow props_wasteland/interior_fence002d.mdl
forcetextureshadow props_wasteland/interior_fence002e.mdl
forcetextureshadow props_wasteland/interior_fence002f.mdl
forcetextureshadow props_wasteland/interior_fence003a.mdl
forcetextureshadow props_wasteland/interior_fence003b.mdl
forcetextureshadow props_wasteland/interior_fence003d.mdl
forcetextureshadow props_wasteland/interior_fence003e.mdl
forcetextureshadow props_wasteland/interior_fence003f.mdl
forcetextureshadow props_wasteland/interior_fence004a.mdl
forcetextureshadow props_wasteland/interior_fence004b.mdl
forcetextureshadow props_forest/fence_barb_256.mdl
forcetextureshadow props_forest/fence_barb_512.mdl
forcetextureshadow props_forest/fence_border_128.mdl
forcetextureshadow props_forest/fence_border_256.mdl
forcetextureshadow props_forest/fence_border_512.mdl
forcetextureshadow props_forest/fence_trail_128.mdl
forcetextureshadow props_forest/fence_trail_256.mdl
forcetextureshadow props_forest/fence_trail_512.mdl
forcetextureshadow props_wasteland/exterior_fence_notbarbed002a.mdl
forcetextureshadow props_wasteland/exterior_fence_notbarbed002b.mdl
forcetextureshadow props_wasteland/exterior_fence_notbarbed002c.mdl
forcetextureshadow props_wasteland/exterior_fence_notbarbed002d.mdl
forcetextureshadow props_wasteland/exterior_fence_notbarbed002e.mdl
forcetextureshadow props_wasteland/exterior_fence_notbarbed002f.mdl
forcetextureshadow props_wasteland/exterior_fence001a.mdl
forcetextureshadow props_wasteland/exterior_fence001b.mdl
forcetextureshadow props_wasteland/exterior_fence002a.mdl
forcetextureshadow props_wasteland/exterior_fence002b.mdl
forcetextureshadow props_wasteland/exterior_fence002c.mdl
forcetextureshadow props_wasteland/exterior_fence002d.mdl
forcetextureshadow props_wasteland/exterior_fence002e.mdl
forcetextureshadow props_wasteland/exterior_fence003a.mdl
forcetextureshadow props_wasteland/exterior_fence003b.mdl
forcetextureshadow props_foliage/fern01.mdl
forcetextureshadow props_foliage/ferns01.mdl
forcetextureshadow props_foliage/ferns02.mdl
forcetextureshadow props_foliage/ferns03.mdl
forcetextureshadow props_forest/fern01.mdl
forcetextureshadow props_forest/fern01lg.mdl
forcetextureshadow props_c17/fence03a.mdl



This is Episode 2's lights file. It tells what textures give off light, and at the bottom, tells which models create shadows from their alpha channel.

You should add in your own models if they have an alpha channel if you want to. Simply create a new line and put in "forcetextureshadow" (without quotes) and then the path to your model (without the models part, so if you had "ep2/models/props_lol/lolball.mdl" you would put in "props_lol/lolball.mdl")

Save this file as lights.rad (not lights.rad.txt, make sure of this) in your Episode 2 / left 4 dead directory (c:\program files\steam\steamapps\username\Half Life 2 Episode 2\ep2\ or c:\program files\steam\steamapps\common\left4dead\l4d\)

Step 2 - Placing models and fulfilling requirements

Now, the fun part. Place your models you added into the list (or the ones that are already on the list) into your map. (For the sake of this tutorial, i'm using the one i added into the lights.rad file for everyone, models/props_c17/fence03a.mdl.)These models must be prop_static!. After you've placed your models where you want them, make sure there's a nearby light source. Having no light is pointless, and it strains your processor to compile what you can't even see.

Once you've done this, set the lightmaps around your fence/model down very low (2 is what seems to work the best, 4 is the minimum requirement). This will allow you to see the shadows, since they are fairly faint.

Step 3 - Compiling

Now that you've done this, it's time to compile! Press F9 and go to the button that says "Expert..."
Now you'll see a list of things like $bsp_exe and such. Click on $light_exe.

Now in the parameters section on the right, select all text there and replace it with the following

-StaticPropPolys -TextureShadows -game $gamedir $path\$file



And that's it! You're now ready to compile. Press "Go!" from the box (DO NOT SWITCH BACK TO NORMAL MODE) And after a compile (It may take a lot longer because it's very processor intensive) you'll hopefully have pretty shadows.

news post image

- Jimmy422

View comments ( 23 )

Back to top