Custom shaders
Chams materials with your own HLSL.
scene
Chams materials with the script's own HLSL pixel shader, drawn on players, the first-person weapon or arms and dropped weapons.
Everything here needs Allow custom shaders in Scripts > Security (off by default).
scene.material(spec) -> Material | nil, stringYour own chams material: an HLSL pixel shader you write, for Player:set_material / scene.viewmodel / scene.item. spec = {hlsl: string (required), color?, occluded_color? (behind walls, default color), layer?: "both" | "visible" | "occluded", params?: {name = number | colour string / table}, textures?: {image | file, ...} (at most 4: draw.load_image / media / world.overview images or a .png / .jpg in the scripts folder)}. hlsl defines float4 Surface(SurfaceInput s, MaterialParams p) with s = {position, normal (towards the eye), facing (1 = facing the camera), view, bind (bind-pose position), uv (bind.xy / 100), color, time (seconds), screen (pixels), depth, occluded, hitgroup (-1)} and p = the params in name order (a number is a float, a colour a float4); tex0(uv)..tex3(uv) sample the textures in order (wrapping, straight alpha; a missing one is transparent). ps_5_0, at most 16 KiB of source, 16 params, 2048 instructions; no #directives, own textures / samplers, register() or [loop]: every loop needs [unroll(n)], n <= 64, covering all its iterations, and a function is defined before its first use. An array, and a struct with its nested members, holds at most 256 values (vector / matrix components and struct members count); an array needs a literal size. A struct is defined at file scope (not in a function, struct or block) and once per name (SurfaceInput, MaterialParams, VO and PO are taken), without inheritance; class, vector<>, matrix<> and typedef are refused. What the text check refuses comes back at once as "line N: ..." of your text; the compile itself runs in the background (at most 4 a script at a time): the material draws flat in its color until Material:ready(), and compiler errors, or "shader compile took too long" when it is not done within 2 s, arrive as Material:error() and on the console. A source that took too long is refused without compiling again while it is among the 16 most recent such sources (of any script). After 2 compiles that took too long the script cannot start or queue more until it is reloaded. A reload of the same source is ready at once. A material over the GPU budget (a median over 0.5 ms, 4 ms twice, 1 ms for all of them) is drawn flat from then on and Material:error() says why. At most 8 a script; released with the script (unload, reload, error, suspend). Needs the "Allow custom shaders" permission (shaders).
| Name | Type | Description |
|---|---|---|
spec | table |
Material | nil, string
local holo = scene.material{ color = "#4fd8ff", hlsl = [[float4 Surface(SurfaceInput s, MaterialParams p) { return s.color * (0.4 + 0.6 * pow(1 - s.facing, 2)); }]] }scene.viewmodel(m [, part]) -> booleanThe first-person "weapon" or "arms" drawn with m (also when weapon / hands chams are off) until cleared (nil = back to the chams settings).
| Name | Type | Default | Description |
|---|---|---|---|
m | Material | nil | ||
partoptional | string | "weapon" |
boolean
scene.viewmodel(holo, "weapon")scene.item(index, m [, opts]) -> booleanA dropped weapon (entities.items index) drawn with m for 1 s, or opts.lease seconds; renew it to keep it. Needs the map depth (a loaded map).
| Name | Type | Description |
|---|---|---|
index | integer | |
m | Material | nil | |
optsoptional | table |
boolean
for _, it in ipairs(entities.items()) do scene.item(it.index, holo) endscene.materials() -> table[]This script's materials: {id, compiling, ready, gpu_ms?, error?, users}.
table[]
for _, m in ipairs(scene.materials()) do print(m.id, m.gpu_ms) endEverything here needs Allow custom shaders in Scripts > Security (off by default).
Material:set(name, value) -> booleanSet a param (uploaded once a frame). false for an unknown name; a value of the wrong type is an error.
| Name | Type | Description |
|---|---|---|
name | string | |
value | number | color |
boolean
holo:set("speed", 1.2)Material:get(name) -> number | color | nilA param's value.
| Name | Type | Description |
|---|---|---|
name | string |
number | color | nil
local s = holo:get("speed")Material:error() -> string | nilWhy the material is not drawn as written: compiler errors ("line N: ..."), "shader compile took too long", "2 shader compiles of this script took too long: reload it to compile more", "disabled: over GPU budget". nil while it compiles.
string | nil
print(holo:error())Material:ready() -> booleanTrue once it draws as written: its compile finished without an error (and it was not disabled).
boolean
if holo:ready() then print("hologram compiled") endMaterial:gpu_ms() -> number | nilIts smoothed GPU time a frame (sampled frames); nil until measured.
number | nil
print(holo:gpu_ms())Material:release()Free it and clear what it is assigned to.
holo:release()Its id (scene.materials).
integer