Class ProjectedDecalSystem
Namespace: ValveResourceFormat.Renderer.Decals
Assembly: Renderer.dll
Decals projected onto whatever the resolved scene depth holds inside their box, such as bullet impacts. The boxes are binned with the tiled light culling, and one full screen pass walks the decals reaching each pixel, with every decal material and texture held on the GPU.
public sealed class ProjectedDecalSystemInheritance
object ← ProjectedDecalSystem
Constructors
ProjectedDecalSystem(Scene)
Initializes a decal system for a scene.
public ProjectedDecalSystem(Scene scene)Parameters
scene Scene
Fields
MaxDecals
The most decals kept at once, one cull batch. Adding past it removes the oldest that is not permanent.
public const int MaxDecals = 320Field Value
int
Properties
Count
Gets the number of decals currently alive.
public int Count { get; }Property Value
int
Methods
Add(string, Matrix4x4, Vector4, bool, BaseEntity?, bool)
Adds a decal.
public ProjectedDecalHandle Add(string materialPath, Matrix4x4 boxTransform, Vector4 tint, bool flipU = false, BaseEntity? parent = null, bool permanent = false)Parameters
materialPath string
A projected decal material.
boxTransform Matrix4x4
Maps a unit cube centred on the origin to the decal box, see ProjectedDecalSystem.CreateBoxTransform(Vector3, Vector3, Vector3, Vector3).
tint Vector4
Linear color and opacity multiplier.
flipU bool
Whether to mirror the texture horizontally.
parent BaseEntity?
An entity the decal moves with, or null for the static world.
permanent bool
Whether the decal neither fades nor makes way for newer ones, as one placed with a map.
Returns
A handle to the decal, which is not valid when the material could not be loaded or there was no room.
Add(int, Matrix4x4, Vector4, bool, BaseEntity?, bool)
Adds a decal.
public ProjectedDecalHandle Add(int decal, Matrix4x4 boxTransform, Vector4 tint, bool flipU = false, BaseEntity? parent = null, bool permanent = false)Parameters
decal int
A handle from ProjectedDecalSystem.Register(ProjectedDecalDefinition) or ProjectedDecalSystem.RegisterMaterial(string, string?).
boxTransform Matrix4x4
Maps a unit cube centred on the origin to the decal box, see ProjectedDecalSystem.CreateBoxTransform(Vector3, Vector3, Vector3, Vector3).
tint Vector4
Linear color and opacity multiplier.
flipU bool
Whether to mirror the texture horizontally.
parent BaseEntity?
An entity the decal moves with, or null for the static world.
permanent bool
Whether the decal neither fades nor makes way for newer ones, as one placed with a map.
Returns
A handle to the decal, which is not valid when the material handle was not or there was no room.
AddFollowing(int, Matrix4x4, Vector4, bool)
Adds a decal that the caller keeps placing and tinting with ProjectedDecalSystem.Move(ProjectedDecalHandle, Matrix4x4, Vector4), such as one following a particle. It does not fade with age, and makes way for newer decals like any decal that is not permanent.
public ProjectedDecalHandle AddFollowing(int decal, Matrix4x4 boxTransform, Vector4 tint, bool flipU = false)Parameters
decal int
A handle from ProjectedDecalSystem.Register(ProjectedDecalDefinition) or ProjectedDecalSystem.RegisterMaterial(string, string?).
boxTransform Matrix4x4
Maps a unit cube centred on the origin to the decal box, see ProjectedDecalSystem.CreateBoxTransform(Vector3, Vector3, Vector3, Vector3).
tint Vector4
Linear color and opacity multiplier.
flipU bool
Whether to mirror the texture horizontally.
Returns
A handle to the decal, which is not valid when the material handle was not or there was no room.
Clear()
Removes every decal and releases the materials, textures and buffers they used.
public void Clear()CreateBoxTransform(Vector3, Vector3, Vector3, Vector3)
Builds the transform mapping a unit cube onto a decal box. The texture spans the box's X and Y axes with its top toward up, and projects along Z, which points out of the surface.
public static Matrix4x4 CreateBoxTransform(Vector3 center, Vector3 normal, Vector3 up, Vector3 size)Parameters
center Vector3
The box centre.
normal Vector3
The projection axis, pointing out of the surface.
up Vector3
The direction of the texture's top edge, flattened onto the surface.
size Vector3
The width, height and depth of the box.
Returns
Delete()
Releases every GPU resource, the same as ProjectedDecalSystem.Clear().
public void Delete()FindBulletImpactSound(uint)
Finds the sound event a bullet makes on a surface.
public string? FindBulletImpactSound(uint surfacePropertyHash)Parameters
surfacePropertyHash uint
The hash of the hit surface property, or zero for the default surface.
Returns
string?
The sound event, or null for a silent surface.
FindImpactEffect(uint)
Finds the particle effect a bullet throws up from a surface.
public string? FindImpactEffect(uint surfacePropertyHash)Parameters
surfacePropertyHash uint
The hash of the hit surface property, or zero for the default surface.
Returns
string?
The effect, or null when the game names none.
Move(ProjectedDecalHandle, Matrix4x4, Vector4)
Moves and retints a decal added without a parent, such as one following a particle.
public bool Move(ProjectedDecalHandle handle, Matrix4x4 boxTransform, Vector4 tint)Parameters
handle ProjectedDecalHandle
The handle the decal was added with.
boxTransform Matrix4x4
The new box, see ProjectedDecalSystem.CreateBoxTransform(Vector3, Vector3, Vector3, Vector3).
tint Vector4
The new linear color and opacity multiplier.
Returns
bool
Whether the decal is still there; it is gone once it made way for newer ones.
Register(ProjectedDecalDefinition)
Registers a decal kind. Its textures are loaded here and join every other decal's in the one draw, as files or atlas parts. Color and normal must be BC7, occlusion ATI2N and height ATI1N.
public int Register(ProjectedDecalDefinition definition)Parameters
definition ProjectedDecalDefinition
What the decal looks like.
Returns
int
A handle to add decals with, or -1 when the color texture could not be loaded.
RegisterMaterial(string, string?)
Registers the decal a projected decal material describes, or finds it if it was registered before.
public int RegisterMaterial(string materialPath, string? sequenceName = null)Parameters
materialPath string
The material.
sequenceName string?
A sequence of the material's sprite sheet, for a material that holds many decals in one.
Returns
int
A handle to add decals with, or -1 when the material could not be loaded.
Remove(ProjectedDecalHandle)
Removes a decal, if it is still there.
public void Remove(ProjectedDecalHandle handle)Parameters
handle ProjectedDecalHandle
The handle the decal was added with.
Render(RenderContext, bool)
Draws the decals over the opaque scene. Needs the scene depth resolved into the reserved g_tSceneDepth texture beforehand, see SceneViewState.WantsSceneDepth, and this scene's cull masks bound.
public void Render(Scene.RenderContext context, bool translucentSurfaces = false)Parameters
context Scene.RenderContext
The render context of the main scene.
translucentSurfaces bool
Draws them over the translucent surfaces in front of the opaque scene instead, which needs g_tTranslucentSceneDepth filled and the translucent layer drawn.
Spawn(int, Vector3, Vector3, Vector3, BaseEntity?, float)
Adds a decal on a surface, at the size its definition gives, varied as much as the definition allows and mirrored at random.
public ProjectedDecalHandle Spawn(int decal, Vector3 position, Vector3 normal, Vector3 up, BaseEntity? parent = null, float sizeOverride = 0)Parameters
decal int
A handle from ProjectedDecalSystem.Register(ProjectedDecalDefinition) or ProjectedDecalSystem.RegisterMaterial(string, string?).
position Vector3
The position on the surface.
normal Vector3
The surface normal.
up Vector3
The direction of the texture's top edge, flattened onto the surface.
parent BaseEntity?
The entity the surface belongs to, which the decal moves with, or null for the static world.
sizeOverride float
The width and height of the decal, or zero for the size its definition gives.
Returns
A handle to the decal, which is not valid when none was added.
SpawnGroupDecal(string, Vector3, Vector3, BaseEntity?, float)
Adds a decal picked from a decal group, turned at random on the surface.
public ProjectedDecalHandle SpawnGroupDecal(string groupName, Vector3 position, Vector3 normal, BaseEntity? parent = null, float sizeOverride = 0)Parameters
groupName string
A group in scripts/decalgroups.vdata or scripts/decals_subrect.txt.
position Vector3
The position on the surface.
normal Vector3
The surface normal.
parent BaseEntity?
The entity the surface belongs to, which the decal moves with, or null for the static world.
sizeOverride float
The width and height of the decal, or zero for the size its material gives.
Returns
A handle to the decal, which is not valid when none was added.
SpawnImpactDecal(Vector3, Vector3, Vector3, uint, BaseEntity?)
Adds the decal a bullet leaves where it hits a surface, picked from the impact decal group of the surface property.
public ProjectedDecalHandle SpawnImpactDecal(Vector3 position, Vector3 normal, Vector3 direction, uint surfacePropertyHash, BaseEntity? parent = null)Parameters
position Vector3
The hit position.
normal Vector3
The surface normal at the hit.
direction Vector3
The direction the bullet travels.
surfacePropertyHash uint
The hash of the hit surface property, or zero for the default surface.
parent BaseEntity?
The entity that was hit, which the decal moves with, or null for the static world.
Returns
A handle to the decal, which is not valid when none was added.
SpawnKnifeDecal(Vector3, Vector3, Vector3, uint, BaseEntity?)
Adds the scuff a knife leaves where it hits a surface. Surfaces that take no bullet decals take no scuff either.
public ProjectedDecalHandle SpawnKnifeDecal(Vector3 position, Vector3 normal, Vector3 direction, uint surfacePropertyHash, BaseEntity? parent = null)Parameters
position Vector3
The hit position.
normal Vector3
The surface normal at the hit.
direction Vector3
The direction the knife swings toward.
surfacePropertyHash uint
The hash of the hit surface property, or zero for the default surface.
parent BaseEntity?
The entity that was hit, which the decal moves with, or null for the static world.
Returns
A handle to the decal, which is not valid when none was added.
Update(float)
Fades decals out as they age and drops them once gone. Moves decals with the entities they were added on, hides them while their entity is not drawn, and drops them once it is removed. Call once a frame, before the cull batch reads ProjectedDecalSystem.BoxTransforms.
public void Update(float currentTime)Parameters
currentTime float
The time the view constants carry this frame, which the decals age against.

