Switchable Textures

Tutorial collection, comprehensive listings on main site.

Switchable Textures

Postby Tutorial on Thu May 19, 2005 6:38 pm

category
Texture Creation

description
Creating textures that can change state, very useful.

keywords
switch, switchable, texture, textures, light, lights.

When making a map for the Half-Life 1 engine it was possible to create an entity with a switchable texture. It was possible to create a lightswitch (func_button) for example that could switch between a "pressed state" texture and an "unpressed state" texture. It was also possible to create a television screen (func_wall) for example that could switch between different "channels". If you want to find out how this is possible in the Source engine, read on!

In this tutorial I'll show you how to make a lightswitch with a texture that changes when the switch is pressed. I assume you already created two textures.

Example:
Image
Image

I also assume you have some basic knowledge of the Source engine directory structure (you know where the tool vtex and your materialsrc and materials folders are located) and of creating a map in Hammer (you know how to create brushes, apply textures and insert entities). If not go read one of the excellent tutorials here on these subjects first!

Step 1: Creating the texture
1) Make sure your textures are called switch001.tga and switch002.tga and that they are in your materialsrc folder
2) Create a text file called switch.txt (in your materialsrc folder) and insert the following text:
Code: Select all
"startframe" "1"
"endframe" "2"

3) Drag and drop the text file to vtex, the file switch.vtf is now created in your materials folder (alternatively use the command line vtex <materialsrc folder>\switch.txt).
4) Create a text file called switch.vmt (in your materials folder) and insert the following text:
Code: Select all
"LightmappedGeneric"
{   
   "$baseTexture" "mydir/switch"
   "Proxies"
   {
      "ToggleTexture"
      {
         "toggleTextureVar" "$baseTexture"
                     "toggleTextureFrameNumVar" "$frame"
                     "toggleTextureShouldWrap" "0"
      }
   }
}

Replace "mydir/switch" with the accurate location of your switch texture.

Step 2: Adding the lightswitch in your map
1) Use the Block Tool (Shift+B) to create a small brush and place it somewhere on a wall, and apply the switch texture to it.
2) Use the Entity Tool (Shift+E) to insert an env_texturetoggle somewhere near the brush. Set the keyvalue Name to "switch_tt" and the keyvalue Target Brush(es) to "switch". Click Apply and close the properties window.

Example:
Image

3) Select the brush and tie it to an entity (CTRL+T), then choose func_button from the Class drop down list.
4) Set the keyvalue Name to "switch", and if you want the keyvalue Sounds to Lightswitch. Click Apply. On the Flags tab check Don't move, Toggle and Use Activates.
5) On the Outputs tab add two OnPressed outputs, one that points to the input IncrementTextureIndex of your env_texturetoggle ("switch_tt" ) and one that points to the input Toggle of a light (in my case called "light" ) or to whatever you want the switch to control.

Example:
Image

Finally, click Apply and close the properties window. Now compile and run your map and enjoy your beautiful lightswitch.

Example:
Image

Image

Notes:
-Instead of using IncrementTextureIndex you could use SetTextureIndex to switch to a specific frame of the texture, useful in my example of the television screen: You could make a remote control with a few buttons, each button pointing to another frame ("channel" ).
-In this case there's a func_button that switches its own texture via an env_texturetoggle, but it's also possible to let a func_button switch a texture on an external entity such as a func_wall via an env_texturetoggle.

There are many more possibilities and many more ideas of using this method. I found it strange there's no good documentation about switchable texture so I hope this tutorial was useful!



NightHawk
- Don't send PM's to this user -
Tutorial
Not A Real User
 
Joined: Sun Mar 06, 2005 11:00 pm

Postby ColinDoody on Tue Aug 16, 2005 1:19 am

Is there any way to toggle VMT files?

An example would be ... say ... you want to toggle the selfillum ... or you want to toggle the alpha ... that would require changing more than just the texture , but the actual material

Great tut btw;
Vicious Specs: eVGA geForce 6800GT 2.8ghz p4, 1gb ddr, 22" NEC, Audigy 2 Plat, 860GB
Image
User avatar
ColinDoody
Regular
Regular
 
Joined: Wed Jul 27, 2005 11:10 am
Location: Tokyo, Japan

Postby jacc0s on Fri Nov 18, 2005 6:57 pm

cool nice tutorial :roll:
jacc0s
Member
Member
 
Joined: Sat Jul 23, 2005 5:54 pm

Postby Hydra on Wed Sep 20, 2006 5:42 am

ColinDoody wrote:An example would be ... say ... you want to toggle the selfillum ... or you want to toggle the alpha ... that would require changing more than just the texture


Okay, sorry for being a thread necro but I was searching the net all over and ended up here again (Hey, this place has the best info I guess right? :)). If you want a different alpha for the different frames, just change the alpha channel for the TGA file. I just tested this out myself on a button I just made w/ self illumination. I just set the off TGA to have a solid black alpha while the on state has the alpha set to where I want it to illuminate. My texture actualy has 3 frames, a red one and a green one as well as the off state and this way you can have logic set the texture to red, green, or off based on what the player does and triggers you've got set up. Also, thanks for the tutorial dude, it helped a LOT.

Again, sorry for being a thread necro on a topic over a year old, I just figured I'd answer this question so that anyone that stumbles across it isn't disappointed.
Image
Image
User avatar
Hydra
Regular
Regular
 
Joined: Fri Aug 18, 2006 9:35 am

Postby Megadude on Tue Oct 03, 2006 1:10 am

Great tutorial. Thought it would be difficult but it's quite easy really. One thing about the alpha thing that's been mentioned. I've done the same as Hydra for the illumination of the on/off button, with the black alpha and the white alpha. However, when testing, I've found that both textures get illuminated instead of just the one with the completly white alpha :?
Wrathborne 711 wrote:OH MY GOD.........MEXICANS!


Image

End of Humanity - beta version 3.0 released!
User avatar
Megadude
Veteran
Veteran
 
Joined: Tue Sep 20, 2005 6:20 pm
Location: UK

Postby Hydra on Wed Oct 04, 2006 1:20 am

Well, that's only if you have it light up w/ your .rad file. If you want an actual light to turn on just have it turn a light entity on at the same time as what ever else it's doing too - afaik the .rad file treats animated (and multiframe) textures as a whole. I don't use a .rad reference for that texture I made. It's the odd looking box w/ the red and black hazard stripes nex to the forcefield texture.

Image
Image
Image
User avatar
Hydra
Regular
Regular
 
Joined: Fri Aug 18, 2006 9:35 am

Postby Megadude on Wed Oct 04, 2006 2:45 am

I don't use any .rad stuff for the textures I'm using either. Its just alpha channels and the self illumination.

Image

The green and red textures are meant to be the off textures, but they are both illuminated.
Wrathborne 711 wrote:OH MY GOD.........MEXICANS!


Image

End of Humanity - beta version 3.0 released!
User avatar
Megadude
Veteran
Veteran
 
Joined: Tue Sep 20, 2005 6:20 pm
Location: UK

Postby TheBloodyDutchman on Mon Oct 09, 2006 7:11 pm

does anyone know how to make switching textures using the vtf plugin for photoshop? or can you only do it using vtex?
TheBloodyDutchman
Member
Member
 
Joined: Mon Jul 31, 2006 11:46 pm
Location: CA

Postby Pig Popper on Sat Jan 06, 2007 2:15 pm

Hi, does anyone know if i can change the speed of the texture toggle in the vtf?

im using a trigger multiple to play a small animation but it's a little too slow.
User avatar
Pig Popper
Regular
Regular
 
Joined: Mon Oct 30, 2006 1:59 pm
Location: The Pig Sty - London

Postby Hydra on Sun Jan 07, 2007 10:51 am

You might just want to compile an animated texture. It might be more efficient I would think. And easier since you wouldn't need triggers. Just a guess though.
Image
Image
User avatar
Hydra
Regular
Regular
 
Joined: Fri Aug 18, 2006 9:35 am

Postby Pig Popper on Sun Jan 07, 2007 11:00 am

Hydra wrote:You might just want to compile an animated texture. It might be more efficient I would think. And easier since you wouldn't need triggers. Just a guess though.


i thought i did, i got 8 frames saved as tga and vtex'd em with a startframe/endfame txt file. Is there a different/better way, would you explain how to do it? thanks
User avatar
Pig Popper
Regular
Regular
 
Joined: Mon Oct 30, 2006 1:59 pm
Location: The Pig Sty - London

Postby jacc0s on Sun Sep 09, 2007 8:42 pm

How can i have more than 2 textures with this?
jacc0s
Member
Member
 
Joined: Sat Jul 23, 2005 5:54 pm

Re: Switchable Textures

Postby Jim the Hermit on Mon Mar 22, 2010 1:16 pm

when I drag a drop the txt file onto VTFEdit 1.2.5 and click ok, it says "error loading image" - what else am I suppose to do?
User avatar
Jim the Hermit
Regular
Regular
 
Joined: Wed May 13, 2009 6:13 pm

Re: Switchable Textures

Postby Chrille on Fri Oct 21, 2011 11:22 am

10$ that's a spambot
Chrille
Been Here A While
Been Here A While
 
Joined: Sun Feb 25, 2007 4:38 pm

Return to Tutorials

Who is online

Users browsing this forum: No registered users