2y ago · Jul 29, 2024 4:15 PM
Chams (colored material replacement on 3D character meshes) make players visible through walls without any 2D overlay math.
How Chams work in Unity:
By replacing the or of the player's (or ) with an unlit shader where depth testing () is disabled ():
How Chams work in Unity:
By replacing the
CSHARP
material CSHARP
sharedMaterial CSHARP
Renderer CSHARP
SkinnedMeshRenderer CODE
_ZTest CODE
CompareFunction.Always CSHARP
using UnityEngine;
public static class ChamsManager
{
private static Material _chamMaterialOccluded;
private static Material _chamMaterialVisible;
public static void InitializeChams()
{
Shader shader = Shader.Find("Hidden/Internal-Colored");
// Occluded (Behind Walls) - Red
_chamMaterialOccluded = new Material(shader);
_chamMaterialOccluded.SetInt("_ZTest", (int)UnityEngine.Rendering.CompareFunction.Greater);
_chamMaterialOccluded.color = new Color(1f, 0.2f, 0.2f, 1f);
// Visible (In Line of Sight) - Green
_chamMaterialVisible = new Material(shader);
_chamMaterialVisible.SetInt("_ZTest", (int)UnityEngine.Rendering.CompareFunction.LessEqual);
_chamMaterialVisible.color = new Color(0.2f, 1f, 0.2f, 1f);
}
public static void ApplyChams(GameObject playerObj)
{
if (_chamMaterialVisible == null) InitializeChams();
var renderers = playerObj.GetComponentsInChildren<Renderer>();
foreach (var rend in renderers)
{
if (rend == null) continue;
// Apply dual-pass materials: Behind wall (Red) & Visible (Green)
rend.materials = new Material[] { _chamMaterialOccluded, _chamMaterialVisible };
}
}
}
GlowShader | Shaders, Stencils & DirectX DrawLists
The following users thanked GlowShader for this post: