Making a custom breakable surface: Difference between revisions

From Valve Developer Community
Jump to navigation Jump to search
No edit summary
m (→‎The damaged texture: use %notooltexture)
 
(17 intermediate revisions by 3 users not shown)
Line 1: Line 1:


{{note|This so far has only been tested in Half-Life 2 {{hl2}} in the 2009 branch of the Source Engine, but in other Source games that support DirectX 9, and where this entity is fully programmatically functional, this should still work.}}
{{note|This so far has been tested in Half-Life 2 {{hl2}} in the 2009 branch of the Source Engine and Team Fortress 2 {{tf2}}, but in other Source games where this entity is fully functional, this should still work.}}
{{todo|Test with other surface properties}}
{{todo|Test with other surface properties (seems not to work with non-glass surface types so far)}}
==What you need==
==What you need==


You will need:
You will need:


*A [[Valve Texture Format|VTF]] editor/maker ([[VTFEdit]] was used in the making of this tutorial, but [[VTEX]] can be used also.) to make the textures VTF files
*A [[Valve Texture Format|VTF]] editor/maker ([[VTFEdit]] was used in the making of this tutorial, but [[Vtex (Source 1)|VTEX]] can be used also.) to manipulate the textures as .VTF files


*A VTF texture to represent the intact material
*A VTF texture to represent the intact material


*A VTF texture '''with an alpha channel''' (8-bit for semi-transparent surfaces) to represent the damaged material
*A VTF texture '''with an alpha channel''' (8-bit alpha for semi-transparent surfaces) to represent the damaged material


A mask for both textures is optional.
A mask for both textures is optional.
Line 17: Line 17:
*After you've got your 2 masks and/or textures, place them in the appropriate game/mod materials directory (and whatever subfolders you wish to put them in) (e.g Half-Life 2/hl2/materials).  
*After you've got your 2 masks and/or textures, place them in the appropriate game/mod materials directory (and whatever subfolders you wish to put them in) (e.g Half-Life 2/hl2/materials).  


*Create 2 text documents in the same folder your VTFs are in, with each one having the same file name as a respective VTF. Make sure you have extensions visible and change the file extension to .vmt, or save the text documents as .vmt in whatever text editor you're using.
*Create 2 text documents in the same folder your VTFs are in, with each one sharing a file name with one of your VTF texture files respectively. Make sure you have extensions visible in your computer's file browser, then change the file extension of one text file to .vmt, or save a text document with a .vmt file extension in whatever text editor you're using.


:{{note|It's good practice to name your materials (whatever)001a/(whatever)001b and so on when you are switching between said materials on a brush face(s) in game}}
:{{note|It's good practice to name your materials (whatever)'''001a''' for the first frame then (whatever)'''001b''' for the second frame and so on when you are switching between said materials on a brush face(s) in game (in this instance, between an intact and broken material)}}


==The intact texture==
==The intact texture==


After you have created the material/textures in the appropriate paths, copy and paste the following code into your intact material VMT:
After you have created the material/textures in the appropriate paths, copy, paste and fill the "(...)" enclosed strings with the paths to the respective VTF files into your intact material VMT:
 
<pre>
 
"LightmappedGeneric"
 
 
 
 
 
"[[LightmappedGeneric]]"
 
{
{
"$basetexture" "(VTF NAME HERE)"
"$envmap" "env_cubemap"
"$surfaceprop" "(Surface property param goes here, is usually glass)"
"$envmapmask" "(VTF MASK NAME GOES HERE (if used that is, otherwise comment out this line with //))"
"$translucent" 1
"$multipass" 1
"$nocull" 1
"$crackmaterial" "(DAMAGED MATERIAL PATH GOES HERE)"


"[[$basetexture]]" "(VTF NAME HERE)"
"LightmappedGeneric_hdr_dx9"
 
"[[$envmap]]" "env_cubemap"
 
"[[$surfaceprop]]" "(Surface properties goes here, it's ***glass*** by default)"
 
"[[%keywords]]" "c17industrial"
 
"[[$envmapmask]]" "(VTF MASK NAME GOES HERE)"
 
"[[$translucent]]" 1
 
"[[$multipass]]" 1
 
"[[$nocull]]" 1
 
"[[$crackmaterial]]" "(DAMAGED MATERIAL PATH GOES HERE)"
 
 
"[[LightmappedGeneric_hdr_dx9]]"
 
{
{
 
"$envmaptint" "[.08 .08 .08]"  
 
"[[$envmaptint]]" "[ .08 .08 .08]"  
 
 
}
}
}
}
 
</pre>
 
 
 
 
 
 




Line 85: Line 55:


Copy and paste the following code into your damaged material VMT
Copy and paste the following code into your damaged material VMT
 
<pre>
 
"ShatteredGlass"
 
 
 
 
 
 
 
"[[ShatteredGlass]]"
 
{
{
$basetexture "(VTF NAME GOES HERE)"
$detail "(VTF NAME GOES HERE)"
$envmap "env_cubemap"
$surfaceprop "(Surface properties goes here, it's glass by default)"
$envmapmask "(TEXTURE MASK GOES HERE (if used, otherwise comment out this line with //))"
$translucent 1
$basetexturetransform "scale .7 .7"
$detailscale 0.7
$unlitfactor 0.0


"[[$basetexture]]" "(VTF NAME GOES HERE)"
"ShatteredGlass_DX8"
 
"[[$detail]]" "(VTF NAME GOES HERE)"
 
"[[$envmap]]" "env_cubemap"
 
"[[$surfaceprop]]" "(Surface properties goes here, it's ***glass*** by default)"
 
"[[%keywords]]" "c17industrial"
 
"[[$envmapmask]]" "(TEXTURE MASK GOES HERE)"
 
"[[$translucent]]" 1
 
"[[$basetexturetransform]]" "scale .7 .7"
 
"[[$detailscale]]" 0.7
 
"[[$unlitfactor]]" 0.0
 
 
"[[ShatteredGlass_DX8]]"
 
{
{
 
$unlitfactor 0.3
"[[$unlitfactor]]" 0.3
 


// This is roughly equal to the average value of envmapmask of the unbroken texture
// This is roughly equal to the average value of envmapmask of the unbroken texture
 
$envmaptint "{201 201 201}"
"[[$envmaptint]]" "{201 201 201}"
 
}
}


// On the low end, envmaptint + lightmap tint both use the average alpha value  
// On the low end, envmaptint + lightmap tint both use the average alpha value  
 
"ShatteredGlass_DX7"
"[[ShatteredGlass_DX7]]"
 
{
{
// This is roughly equal to the average value of alpha channel of the unbroken basetexture
// This is roughly equal to the average value of alpha channel of the unbroken basetexture
 
$lightmaptint "{128 128 128}"
"[[$lightmaptint]]" "{128 128 128}"
 


// This is roughly equal to the average value of envmapmask of the unbroken texture
// This is roughly equal to the average value of envmapmask of the unbroken texture
// times the average value of the alpha value of the unbroken base texture
// times the average value of the alpha value of the unbroken base texture
 
$envmaptint "{100 100 100}"
"[[$envmaptint]]" "{100 100 100}"


}
}


"[[$nocull]]" 1
$nocull 1
 
%notooltexture 1 // hide in texture browser, because it isn't intended to be used directly
"[[Proxies]]"


"Proxies"
{
{
 
"BreakableSurface"
"[[BreakableSurface]]"
 
{
{
}
}
}
}
}
}
 
</pre>
 
 




{{note|If you are not using a texture mask, comment out (type // behind) the line $envmapmask is on.}}
{{note|If you are not using a texture mask, comment out (type // behind) the line $envmapmask is on.}}


==End==
==End==
Line 179: Line 107:
Provided you have done everything right, you should now have a texture that works fully with the [[func_breakable_surf]] brush entity provided all except 1 side is [[Tool textures|Nodraw]].
Provided you have done everything right, you should now have a texture that works fully with the [[func_breakable_surf]] brush entity provided all except 1 side is [[Tool textures|Nodraw]].


Modifications to the independent parameters (e.g $lightmaptint) can be made without any loss of functionality, however since func_breakable_surf is mostly used for glass, it has been optimised as such (hopefully).
Modifications to the other parameters (e.g $lightmaptint) can of course be made without any loss of functionality.


==See also==


*[[Breakable Glass]]
*[[func_breakable_surf]]


[[Category:Material System]]
[[Category:Material System]]
[[Category:Tutorials]]
[[Category:Tutorials]]

Latest revision as of 20:16, 14 April 2024

Note.pngNote:This so far has been tested in Half-Life 2 Half-Life 2 in the 2009 branch of the Source Engine and Team Fortress 2 Team Fortress 2, but in other Source games where this entity is fully functional, this should still work.
Todo: Test with other surface properties (seems not to work with non-glass surface types so far)

What you need

You will need:

  • A VTF editor/maker (VTFEdit was used in the making of this tutorial, but VTEX can be used also.) to manipulate the textures as .VTF files
  • A VTF texture to represent the intact material
  • A VTF texture with an alpha channel (8-bit alpha for semi-transparent surfaces) to represent the damaged material

A mask for both textures is optional.

Handling the material/texture files

  • After you've got your 2 masks and/or textures, place them in the appropriate game/mod materials directory (and whatever subfolders you wish to put them in) (e.g Half-Life 2/hl2/materials).
  • Create 2 text documents in the same folder your VTFs are in, with each one sharing a file name with one of your VTF texture files respectively. Make sure you have extensions visible in your computer's file browser, then change the file extension of one text file to .vmt, or save a text document with a .vmt file extension in whatever text editor you're using.
Note.pngNote:It's good practice to name your materials (whatever)001a for the first frame then (whatever)001b for the second frame and so on when you are switching between said materials on a brush face(s) in game (in this instance, between an intact and broken material)

The intact texture

After you have created the material/textures in the appropriate paths, copy, paste and fill the "(...)" enclosed strings with the paths to the respective VTF files into your intact material VMT:

"LightmappedGeneric"
{
	"$basetexture" "(VTF NAME HERE)"
	"$envmap" "env_cubemap"
	"$surfaceprop" "(Surface property param goes here, is usually glass)"
	"$envmapmask" "(VTF MASK NAME GOES HERE (if used that is, otherwise comment out this line with //))" 
	"$translucent" 1
	"$multipass" 1
	"$nocull" 1
	"$crackmaterial" "(DAMAGED MATERIAL PATH GOES HERE)"

	"LightmappedGeneric_hdr_dx9"
	{
		"$envmaptint" "[.08 .08 .08]" 
	}
}


Note.pngNote:If you are not using a texture mask, comment out (type // behind) the line $envmapmask is on.

Insert the appropriate paths where $basetexture, $envmapmask and $crackmaterial are specified

Save the VMT in the same folder as your first (intact) VTF file

The damaged texture

The damaged texture needs to have an alpha channel otherwise skybox/black texture will appear when the surface breaks.

Copy and paste the following code into your damaged material VMT

"ShatteredGlass"
{
	$basetexture "(VTF NAME GOES HERE)"
	$detail "(VTF NAME GOES HERE)"
	$envmap "env_cubemap"
	$surfaceprop "(Surface properties goes here, it's glass by default)"
	$envmapmask "(TEXTURE MASK GOES HERE (if used, otherwise comment out this line with //))"
	$translucent 1
	$basetexturetransform "scale .7 .7"
	$detailscale 0.7
	$unlitfactor 0.0

	"ShatteredGlass_DX8"
	{
		$unlitfactor 0.3

		// This is roughly equal to the average value of envmapmask of the unbroken texture
		$envmaptint "{201 201 201}"
	}

	// On the low end, envmaptint + lightmap tint both use the average alpha value 
	"ShatteredGlass_DX7"
	{
		// This is roughly equal to the average value of alpha channel of the unbroken basetexture
		$lightmaptint "{128 128 128}"

		// This is roughly equal to the average value of envmapmask of the unbroken texture
		// times the average value of the alpha value of the unbroken base texture
		$envmaptint "{100 100 100}"

	}

	$nocull 1
	%notooltexture 1 // hide in texture browser, because it isn't intended to be used directly

	"Proxies"
	{
		"BreakableSurface"
		{
		}
	}
}


Note.pngNote:If you are not using a texture mask, comment out (type // behind) the line $envmapmask is on.

End

Provided you have done everything right, you should now have a texture that works fully with the func_breakable_surf brush entity provided all except 1 side is Nodraw.

Modifications to the other parameters (e.g $lightmaptint) can of course be made without any loss of functionality.

See also