Tutorials

Random Sprite Placement



OK, so in this tutorial I will tell you how to make the HL2 map compiler place sprites randomly on your displacement textures. This tutorial presumes you have looked at my previous one on making custom blending textures, although this is not 100% necessary.

So, to start, we make our own VMT file which consisted of this:

"WorldVertexTransition"
{
	"$basetexture" 	"brick/brickfloor001a"
	"$basetexture2" "concrete/concretefloor005a"
	"%tooltexture" "nature/blendsandgrass008a_tooltexture"
	"$detail" "overlays/macro01a"
	"$detailscale" .1
	"$basetexturetransform" "center .5 .5 scale 1 1 rotate 0 translate 0 0"
        "$basetexturetransform2" "center .5 .5 scale 1 1 rotate 0 translate 0 0"
        "%detailtype" "smiff_test"
}



Now, the important part of this is the "%detailtype". As you can see, mine is called smiff_test, but you can put whatever you want here. This %detailtype is linked to a file called "detail.vbsp" which is used by the compiler for the random sprite placement. So, make a detail.vbsp file in your SDK mod dir. mine is;

D:\Steam\SteamApps\my@address.com\sourcesdk\hl2mp_sample_content



The contents of my detail.vbsp file is as follows:


============= (these are just to break it up so you know where it starts ;P)

details

{

	smiff_test

	{

		"density" "500.0"

		Group1

		{

			"alpha" "1.0"

			Model1

			{

				"sprite" "288 0 128 128 512" 

				"spritesize" "0.5 0.0 19 25"

				"spriterandomscale" "0.2"

				"amount" "0.2"

				"detailOrientation" "2"

			}

			Model2

			{

				"sprite" "0 0 128 128 512"

				"spritesize" "0.5 0.0 23 30"

				"spriterandomscale" "0.2"

				"amount" "0.1"

				"detailOrientation" "2"

			}

				Model3

			{

				"sprite" "0 144 128 128 512"

				"spritesize" "0.5 0.0 23 30"

				"spriterandomscale" "0.2"

				"amount" "0.1"

				"detailOrientation" "2"

			}

		}

		
	}

}

=============== (end of the detail.vbsp)



Now, what this does, is tell the compiler which sprites, from the sprite file to use. Now, you might be saying "what sprite file??" well. HL2 has a default one, called detailsprites.vtf - Don't worry, you don't need to edit this file (although you could if you wanted...)

news post image

That is a copy of what is contained within the file (without the pink numbers - they were for me!)

So, now I will explain the detail.vbsp file in more depth;

You make a group (in this case called smiff_test), inside this group is the information about the different groups of sprites to use. Each main group (smiff_test) can have a subgroup (group1) - and these subgroups can be filled with "models" (even though they are sprites - the random model placement doesnt seem to work

yet..)

This line;

"sprite" "288 0 128 128 512" 



is the important one for now.

The first number ( 288 ) is how many pixels across from the left hand side (the x axis), the compiler should start reading from. The next number is how many down from the top (y axis) it should start reading from.

The next 2 numbers are the size of the sprite, and the final number is the size of the detailsprite.vtf in pixels. But really, all we need are the first two numbers.

Now, take a look at the my sprite picture example. Each sprite is 128x128 pixesl and each sprite has a 16 pixel gap inbetween it. So, if you wanted the middle sprite (numbered 5) you would want these numbers;

x axis = 128 + 16
y axis = 128 + 16



Which gives us 144 for both.

"sprite" "144 144 128 128 512"



In theory, this would start reading from the label on the image (the really badly drawn star thing).

Another example, for the bottom middle sprite, we would want:

x axis = 128 + 16 = 144
y axis = 128 + 16 + 128 + 16 = 288



So we'd end up with;

"sprite" "144 144 128 128 512"




So. Thats the sprite line of the .vbsp file.....

Also "amount" is the percentage of this certain sprite that will be put on the terrain. For example, 0.1 would mean that 10% of the sprites would be this one. 0.2 would mean 20%.. etc etc. I'd guess having all of the amounts in a group adding up to one might be a good idea, though i've had no problems with it not (as in the above example!)

The others aren't really important for now, but you can look into them at:

http://www.valve-erc.com/srcsdk/Levels/prop_types.html
(right down the bottom)

Ok, so we've set up our 1st "group" called smiff_test - Inside smiff_test is group1, which contains 3 different sprites to scatter randomly about on our alpha painted displacement brush.

Have fun, and remember - don't be scared to experiment

And now, a screenshot of what you could come out with if you follow this and the last tutorial!

news post image

(using my dodgy brick and concrete blend, and some random sprites)

Have Fun!

supersmithy

View comments ( 13 )

Back to top