Tutorial collection, comprehensive listings on main site.

category
Texture Creation

description
Allowing transparent textures to project shadows, for example a wire fence.

keywords

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

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.

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
Code: Select all
lights/fluorescentcool001a   189 231 232 350lights/fluorescentcool001b   236 255 182 350lights/fluorescentcool002a   189 231 232 400lights/fluorescentcool002b   236 255 182 400lights/fluorescentcool003a   189 231 232 300lights/fluorescentwarm001a   239 216 193 350lights/fluorescentwarm002a   239 216 193 400lights/fluorescentwhite001a   245 245 245 350lights/fluorescentwhite002a   245 245 245 400lights/hazzardred001a      228 37 0 300lights/hazzardyellow001a   250 215 74 300lights/HIDcool001a      145 222 172 650lights/HIDcool001b      205 232 255 650lights/HIDwarm001a      255 201 116 650lights/white001         250 240 205 100lights/white002         189 233 247 425lights/white003         232 246 190 350lights/white004         170 228 247 425lights/white005         234 235 220 375lights/white006         234 235 220 100lights/blue001         166 180 196 200 166 180 196 100lights/blue002         141 176 203 200 141 176 203 100lights/red001         63 1 1 200 63 1 1 100lights/white001_nochop   250 240 205 100lights/white002_nochop   189 233 247 425lights/white003_nochop   232 246 190 350lights/white004_nochop   170 228 247 425lights/white005_nochop   234 235 220 375lights/white006_nochop   234 235 220 100lights/incandescentcool001a   235 235 235 300lights/incandescentwarm001a   250 226 129 300glass/glassscreen001a      172 192 161 225glass/glasspipe001f      214 72 44 200glass/glassscreen001c      172 192 161 225glass/glassscreen001d      211 187 134 225glass/glassblock001a      70 194 209 200 composite/citadelfloor001a   103 143 203 200props/tvscreen006a      196 0 0 200shadertest/gooinglass      149 49 15 50glass/glasswindow002e      189 233 247 425glass/glasswindow035a      145 222 172 100dev/DEV_INTERIORLIGHT02B   151 176 204 225plaster/plasterwall029h      189 223 227 125building_template/Building_Trainstation_Template001d   230 230 200 65building_template/Building_Trainstation_Template001e   230 230 200 150building_template/Building_Trainstation_window002d   230 230 200 300building_template/Building_Trainstation_window002e   230 230 200 300lights/physgunlight   189 231 232 20noshadow tree_deciduous_01a_branches.vmtnoshadow tree_deciduous_01a_leaves.vmtnoshadow tree_deciduous_01a_lod.vmtnoshadow tree_deciduous_01a_lod-leaves.vmtforcetextureshadow props_foliage/tree_dead01.mdlforcetextureshadow props_foliage/tree_dead02.mdlforcetextureshadow props_foliage/tree_dead03.mdlforcetextureshadow props_foliage/tree_dead04.mdlforcetextureshadow props_foliage/tree_dry01.mdlforcetextureshadow props_foliage/tree_dry02.mdlforcetextureshadow props_foliage/tree_pine_large.mdlforcetextureshadow props_foliage/tree_pine04.mdlforcetextureshadow props_foliage/tree_pine05.mdlforcetextureshadow props_foliage/tree_pine06.mdlforcetextureshadow props_foliage/tree_deciduous_01a.mdlforcetextureshadow props_foliage/tree_deciduous_02a.mdlforcetextureshadow props_wasteland/interior_fence001a.mdlforcetextureshadow props_wasteland/interior_fence001b.mdlforcetextureshadow props_wasteland/interior_fence001c.mdlforcetextureshadow props_wasteland/interior_fence001d.mdlforcetextureshadow props_wasteland/interior_fence001e.mdlforcetextureshadow props_wasteland/interior_fence001g.mdlforcetextureshadow props_wasteland/interior_fence002a.mdlforcetextureshadow props_wasteland/interior_fence002b.mdlforcetextureshadow props_wasteland/interior_fence002c.mdlforcetextureshadow props_wasteland/interior_fence002d.mdlforcetextureshadow props_wasteland/interior_fence002e.mdlforcetextureshadow props_wasteland/interior_fence002f.mdlforcetextureshadow props_wasteland/interior_fence003a.mdlforcetextureshadow props_wasteland/interior_fence003b.mdlforcetextureshadow props_wasteland/interior_fence003d.mdlforcetextureshadow props_wasteland/interior_fence003e.mdlforcetextureshadow props_wasteland/interior_fence003f.mdlforcetextureshadow props_wasteland/interior_fence004a.mdlforcetextureshadow props_wasteland/interior_fence004b.mdlforcetextureshadow props_forest/fence_barb_256.mdlforcetextureshadow props_forest/fence_barb_512.mdlforcetextureshadow props_forest/fence_border_128.mdlforcetextureshadow props_forest/fence_border_256.mdlforcetextureshadow props_forest/fence_border_512.mdlforcetextureshadow props_forest/fence_trail_128.mdlforcetextureshadow props_forest/fence_trail_256.mdlforcetextureshadow props_forest/fence_trail_512.mdlforcetextureshadow props_wasteland/exterior_fence_notbarbed002a.mdlforcetextureshadow props_wasteland/exterior_fence_notbarbed002b.mdlforcetextureshadow props_wasteland/exterior_fence_notbarbed002c.mdlforcetextureshadow props_wasteland/exterior_fence_notbarbed002d.mdlforcetextureshadow props_wasteland/exterior_fence_notbarbed002e.mdlforcetextureshadow props_wasteland/exterior_fence_notbarbed002f.mdlforcetextureshadow props_wasteland/exterior_fence001a.mdlforcetextureshadow props_wasteland/exterior_fence001b.mdlforcetextureshadow props_wasteland/exterior_fence002a.mdlforcetextureshadow props_wasteland/exterior_fence002b.mdlforcetextureshadow props_wasteland/exterior_fence002c.mdlforcetextureshadow props_wasteland/exterior_fence002d.mdlforcetextureshadow props_wasteland/exterior_fence002e.mdlforcetextureshadow props_wasteland/exterior_fence003a.mdlforcetextureshadow props_wasteland/exterior_fence003b.mdlforcetextureshadow props_foliage/fern01.mdlforcetextureshadow props_foliage/ferns01.mdlforcetextureshadow props_foliage/ferns02.mdlforcetextureshadow props_foliage/ferns03.mdlforcetextureshadow props_forest/fern01.mdlforcetextureshadow props_forest/fern01lg.mdlforcetextureshadow 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")

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
Code: Select all
-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.

- Jimmy422
- Don't send PM's to this user -
Tutorial
Not A Real User

Joined: Sun Mar 06, 2005 11:00 pm

Friggin hot. Great tutorial. Definitely gonna give it a go.

srredfire
Veteran

Joined: Sat Jul 22, 2006 10:44 pm

Really great tutorial !
More shadows more candy for eyes :) .

But I've got a question, it wont create some problems when a person starts running through area with such shadows ? The shadows on his models would look...weird, aren't they ?
Avager
Member

Joined: Mon May 26, 2008 10:56 pm

Last edited by Spike on Wed Feb 11, 2009 11:01 pm, edited 1 time in total.

Spike
May Contain Skills

Joined: Wed Sep 17, 2008 7:10 pm

Quality tutorial.
Undue Punishment : 'An experimental FP Fighting game with stealth elements. ' -- TBD
Torn : 'A First Person RTS ' -- In Development as of 03/2014
Jeeves
Regular

Joined: Mon Sep 01, 2008 9:53 pm

I've done exacly the same thing on this tutorial, but when I load the map it's all fullbright. If I write mat_fullbright 0 on console it's sill fullbright. What have I done wrong?

nvm, got it working

Spike
May Contain Skills

Joined: Wed Sep 17, 2008 7:10 pm

Whoa, got published, sweet.

Jimmy422
Regular

Joined: Sat Sep 15, 2007 2:59 pm

Avager wrote:Really great tutorial !
More shadows more candy for eyes :) .

But I've got a question, it wont create some problems when a person starts running through area with such shadows ? The shadows on his models would look...weird, aren't they ?

They look fine actually. VALVe uses this a lot on Episode 2 maps, just check out some of the shadows from the trees or the silo map background, you'll notice it.

Just noticed there's a typo on the description of this :(
"In this tutorial you will ealrn how you can make the opaque parts of a transparent texture on a model cast shadows."

Jimmy422
Regular

Joined: Sat Sep 15, 2007 2:59 pm

bloody nice dude, this will make a great addition to my left 4 dead campaign in the future XD

serpent666
Sir Post-a-lot

Joined: Thu Apr 07, 2005 1:03 pm
Location: Perth , Western Australia

Jimmy422 wrote:"In this tutorial you will ealrn how you can make the opaque parts of a transparent texture on a model cast shadows."

Cool 'n that

Joined: Fri Oct 08, 2004 4:16 pm
Location: UK

Ths tutorial is awesome.
zombie@computer wrote:Thank god the government knows best.

korge
Pheropod

Joined: Fri Dec 28, 2007 4:16 pm

This Tutorial is of course awesome, its another great option to push the overall quality of a Map or Level! What brings me to a further question. If you look at the last Image from above you see that the Shadow is really hard, that doesn't look really realistic. So my question is, could it be possible to tune the shadow to something transparent, modification of the Alpha Channel or something else like that?

Again thanks for the clear an simple Tutorial, you rock ;)

*Ahhrr, my Nipples they Hurt, they Hurt when i twist them*

FlynT
Been Here A While

Joined: Sun Jun 15, 2008 2:59 am
Location: Germany

FlynT wrote:This Tutorial is of course awesome, its another great option to push the overall quality of a Map or Level! What brings me to a further question. If you look at the last Image from above you see that the Shadow is really hard, that doesn't look really realistic. So my question is, could it be possible to tune the shadow to something transparent, modification of the Alpha Channel or something else like that?

Again thanks for the clear an simple Tutorial, you rock ;)

I thought the hard shadows were more realistic, but i guess not. I was using a lightmap scale of 1 in that, so that's probably why.

Lower lightmaps should fix it.

Jimmy422
Regular

Joined: Sat Sep 15, 2007 2:59 pm

Jimmy422 wrote:Lower lightmaps should fix it.

I agree. I bet 2 would almost be perfect if you are trying to go for a noticeable shadow anyways.
zombie@computer wrote:Thank god the government knows best.

korge
Pheropod

Joined: Fri Dec 28, 2007 4:16 pm

MrTwoVideoCards
Monothetic

Joined: Thu Aug 02, 2007 11:18 am