• Register
Post tutorial Report RSS Compiling a volumetric texture for Source Engine

The reason of writing this article is that there is little to none information about compiling 3D textures for Source on Valve Developer Wiki. The only phrase I could find there about volumetric textures is something like "Usually you don't need them so forget about this feature."

Posted by on - Intermediate Textures

Volumetric rendering got popular theese days and many modern effects such as volumeric fog, godrays, procedural clouds are built from base 3D noise. Usually it is low-resolution perlin/worley noise at various octaves combined into multiple layers. For example, Lost Squad uses 128x128x128 3D noise texture to build procedural clouds.

But it's not immidiately clear how to compile such texture into Source. VTFEditor won't help you with that, moreover, it may corrupt your texture or render it with artifacts so forget about VTFEditor at all - we are going to work with vtex.exe only.

An example 3D texture we use to build our procedural clouds.

Notice the amount of Slices there which means this is a 3D texture with 128 layers


Let's start:

1. It is supposed that you already know how to create a 3D texture. Tutorial won't cover the process of creation it, but it's not hard, more like just time consuming.

2. Generate n-amount of 2D layers of your future 3D texture or split existing 3D texture into multiple 2D layers (if you are using Photoshop you might need to export each layer in Photoshop as separate file. To do this go to File->Scripts->Export each layer as separate file...). Make sure each layer is a .tga image file (or .psd if you really want to). Then you must give a name to each layer using the following format:

yourfilename_z00x.tga

where yourfilename - is any name (but make sure the name is not too long, because vtex.exe has limit of 2048 characters per line and if you try to compile high amount of layers it may fail to process compile command if you specify all file names in it) and x - is a frame number (starting from 0). NOTE: amount of layers must be power of 2 as well!

3. Go to materialsrc folder of your mod (if you don't have this folder - create it), create some subfolder in it, for example 'volumetric' and put your .tga layers there.

4. Create a .txt file with the name of your 3D texture (without _zxxx stuff) where you need to write:

volumetexture n

where n is amount of layers.

NOTE: you can also specify each filename if you really want to. It will look like this:

volumetexture yourfilename_z000.tga,yourfilename_z001.tga,...,yourfilename_zxxx.tga

in other words, put all filenames of your layers there and make sure you don't have spaces between commas and file names. But it may not work with older versions of vtex.exe.

5. Add a line containing

nocompress 1;

It's very important to turn compression off or 3D textures might not work correctly. NOTE: for some reason, vtex.exe compiles textures with BGRA8888 format instead of RGBA8888. Keep that in mind!

6. Go to game-you-modding bin folder (for example Source SDK Base 2013/bin) and find vtex.exe. For better usability, make a shorcut of it in your materialsrc folder with .tga's and .txt. NOTE: I suggest using CS:GO's or Insurgency's vtex.exe instead of Alien Swarm's one since it is more up-to-date and faster than ASw's mess.

7. Drag-n-drop your .txt on vtex.exe shortcut and enjoy. A volumetric texture should appear in yourmod materials/volumetric fodler.


That's pretty much all of it! Hope this tutorial was useful for you and happy volumetring!

The following images are our results of procedural clouds generated from 3D Perlin-Worley noise in realtime.



Post comment Comments
woookieee
woookieee - - 86 comments

Wonderful work, keep it up!

Reply Good karma Bad karma+11 votes
FlippedOutKyrii
FlippedOutKyrii - - 3,502 comments

Holy **** that Sky Retexture gives me the impression the Citadel Fire itself is burrowing a hole into the Ozone Layer.

Can't wait to see how you interpret that monolith exploding!

Reply Good karma Bad karma+7 votes
hogsy
hogsy - - 619 comments

"The reason of writing this article is that there is little to none information about compiling 3D textures for Source on Valve Developer Wiki. The only phrase I could found there about volumetric textures is something like 'Usually you don't need them so forget about this feature.'"

Why not add this information to the Valve Developer Wiki in this case? I'm pretty sure anyone can contribute to it, as I have done in the past.

Reply Good karma Bad karma+5 votes
bm_killer10
bm_killer10 - - 156 comments

this is so cool, trying is out to get it to work, think Codeproject.com

with code in


private void animateBitmap(float[,,] Values, Bitmap tmp, bool greyscale)
{

//for (int k = 0; k < Values.GetLength(2); k++) //z is time
int k= 0;
// while (!Noise3dSTOP)
while (k < 129)
{

for (int i = 0; i < Values.GetLength(0); i++)
{
for (int j = 0; j < Values.GetLength(1); j++)
{
float v = Values[i, j,k] ;

if (v < 0)
v = 0;

if (v > 255f)
v = 255f;

Color clr;
if (greyscale)
clr = Color.FromArgb((int)v, (int)v, (int)v);
else
clr = Color.FromArgb((int)v, 255, 255, 255);
tmp.SetPixel(i, j, clr);

}
}

//refresh
pictureBox1.Image = tmp;
pictureBox1.Refresh();

pictureBox2.Image = tmp;
pictureBox3.Image = tmp;
pictureBox4.Image = tmp;
pictureBox5.Image = tmp;
pictureBox2.Refresh();
pictureBox3.Refresh();
pictureBox4.Refresh();
pictureBox5.Refresh();

// Bitmap image1;
// image1 = new Bitmap("Shapes.bmp");
//SAVING TO FILE
Bitmap save = new Bitmap(tmp);
// g.Dispose();
save.Save("lava"+k.ToString()+".bmp", System.Drawing.Imaging.ImageFormat.Bmp);

Application.DoEvents();

k = k + 1;
k = k % (Values.GetLength(2));

FrameLbl.Text = "Frame: " + k.ToString() + "/" + Values.GetLength(2).ToString();

if (Noise3dSTOP) {
Noise3dSTOP = false;
return;
}
}
}

Reply Good karma Bad karma+1 vote
GimmeHat
GimmeHat - - 1 comments

Как использовать эту текстуру?

Reply Good karma Bad karma+1 vote
Noctara
Noctara - - 1 comments

You told how to create texture, but not told how to create material and how to use it. Can you tell please? I searched it but found nothing about it(.

Reply Good karma Bad karma+1 vote
WormSlayer
WormSlayer - - 9 comments

Has anyone except OP ever got volumetric textures working? Compiling them seems to work fine, but I cant get them to not show up as black materials in-game.

Reply Good karma Bad karma+1 vote
celisej567
celisej567 - - 39 comments

How should i use it?

Reply Good karma Bad karma+1 vote
Post a comment

Your comment will be anonymous unless you join the community. Or sign in with your social account: