@ericrisco/rsc 0.1.34 → 0.1.36
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +28 -2
- package/manifest.json +241 -2
- package/package.json +1 -1
- package/scripts/lib/domains.js +1 -0
- package/scripts/lib/recommend.js +4 -0
- package/skills/agent-eval/SKILL.md +1 -1
- package/skills/analyze/SKILL.md +1 -1
- package/skills/brand-voice/SKILL.md +1 -1
- package/skills/brand-voice/references/voice-guide-template.md +14 -0
- package/skills/building-agents/SKILL.md +2 -2
- package/skills/competitor-watch/SKILL.md +9 -4
- package/skills/competitor-watch/references/tracker-schema.md +19 -0
- package/skills/constitution/references/constitution-template.md +10 -0
- package/skills/content-engine/SKILL.md +1 -1
- package/skills/content-engine/references/brief-and-pipeline.md +15 -1
- package/skills/course-builder/references/grounding-and-scoping.md +23 -0
- package/skills/course-storytelling/references/learner-grounding.md +22 -2
- package/skills/decision-records/SKILL.md +14 -1
- package/skills/decision-records/references/templates.md +20 -0
- package/skills/design/references/brand-grounding.md +11 -1
- package/skills/game-design/SKILL.md +170 -0
- package/skills/game-design/evals/README.md +13 -0
- package/skills/game-design/evals/cases.yaml +47 -0
- package/skills/game-design/references/mechanics-and-loops.md +78 -0
- package/skills/game-design/references/playtesting-and-scope.md +58 -0
- package/skills/game-design/references/progression-and-economy.md +70 -0
- package/skills/game-storytelling/SKILL.md +159 -0
- package/skills/game-storytelling/evals/README.md +28 -0
- package/skills/game-storytelling/evals/cases.yaml +51 -0
- package/skills/game-storytelling/references/branching-and-state.md +134 -0
- package/skills/game-storytelling/references/dialogue-tools.md +117 -0
- package/skills/game-storytelling/references/environmental-storytelling.md +71 -0
- package/skills/gamedev-multiplayer/SKILL.md +250 -0
- package/skills/gamedev-multiplayer/evals/README.md +12 -0
- package/skills/gamedev-multiplayer/evals/cases.yaml +44 -0
- package/skills/gamedev-multiplayer/references/godot-high-level-multiplayer.md +133 -0
- package/skills/gamedev-multiplayer/references/prediction-and-latency.md +104 -0
- package/skills/gamedev-multiplayer/references/unity-and-unreal-netcode.md +166 -0
- package/skills/gamedev-pathing/SKILL.md +242 -0
- package/skills/gamedev-pathing/evals/README.md +14 -0
- package/skills/gamedev-pathing/evals/cases.yaml +49 -0
- package/skills/gamedev-pathing/references/navmesh-workflow.md +110 -0
- package/skills/gamedev-pathing/references/search-algorithms.md +135 -0
- package/skills/gamedev-pathing/references/steering-and-avoidance.md +120 -0
- package/skills/gamedev-physics/SKILL.md +225 -0
- package/skills/gamedev-physics/evals/README.md +12 -0
- package/skills/gamedev-physics/evals/cases.yaml +54 -0
- package/skills/gamedev-physics/references/character-controllers.md +120 -0
- package/skills/gamedev-physics/references/determinism-and-queries.md +124 -0
- package/skills/gamedev-physics/references/layers-and-masks.md +115 -0
- package/skills/gamedev-shaders/SKILL.md +252 -0
- package/skills/gamedev-shaders/evals/README.md +14 -0
- package/skills/gamedev-shaders/evals/cases.yaml +45 -0
- package/skills/gamedev-shaders/references/effect-recipes.md +205 -0
- package/skills/gamedev-shaders/references/godot-shading-language.md +133 -0
- package/skills/gamedev-shaders/references/unity-and-unreal-shaders.md +169 -0
- package/skills/gamedev-shipping/SKILL.md +236 -0
- package/skills/gamedev-shipping/evals/README.md +9 -0
- package/skills/gamedev-shipping/evals/cases.yaml +55 -0
- package/skills/gamedev-shipping/references/mobile-and-desktop.md +127 -0
- package/skills/gamedev-shipping/references/stores-and-ci.md +162 -0
- package/skills/gamedev-shipping/references/web-export-headers.md +140 -0
- package/skills/godot/SKILL.md +319 -0
- package/skills/godot/evals/README.md +13 -0
- package/skills/godot/evals/cases.yaml +50 -0
- package/skills/godot/references/export-and-testing.md +102 -0
- package/skills/godot/references/gdscript-style.md +84 -0
- package/skills/godot/references/godot3-to-4-traps.md +89 -0
- package/skills/godot/references/nodes-scenes-resources.md +109 -0
- package/skills/harness/SKILL.md +3 -3
- package/skills/harness/references/daily-curation-automation.md +8 -6
- package/skills/harness/references/obsidian-scaffolding.md +16 -9
- package/skills/harness/references/wiki-article-template.md +31 -14
- package/skills/harness/references/wiki-index-template.md +7 -3
- package/skills/harness/references/wiki-protocol.md +120 -54
- package/skills/harness/references/wiki-worklog-template.md +5 -1
- package/skills/instagram-api/SKILL.md +8 -1
- package/skills/instagram-api/references/insights-metrics.md +8 -1
- package/skills/knowledge-ops/SKILL.md +9 -9
- package/skills/knowledge-ops/evals/cases.yaml +1 -1
- package/skills/knowledge-ops/references/gardening-playbook.md +18 -8
- package/skills/level-design/SKILL.md +175 -0
- package/skills/level-design/evals/README.md +35 -0
- package/skills/level-design/evals/cases.yaml +58 -0
- package/skills/level-design/references/blockout-to-art.md +118 -0
- package/skills/level-design/references/guidance-and-readability.md +152 -0
- package/skills/level-design/references/pacing-and-encounters.md +142 -0
- package/skills/linkedin-api/SKILL.md +10 -1
- package/skills/linkedin-strategy/SKILL.md +12 -0
- package/skills/linkedin-strategy/references/wiki-records.md +27 -1
- package/skills/marketing/references/brand-grounding.md +22 -2
- package/skills/medium-strategy/SKILL.md +12 -0
- package/skills/medium-strategy/references/wiki-records.md +39 -1
- package/skills/medium-writing/SKILL.md +19 -0
- package/skills/plan/references/plan-template.md +12 -1
- package/skills/roast-me/tools/adapters/__pycache__/__init__.cpython-312.pyc +0 -0
- package/skills/roast-me/tools/adapters/__pycache__/base.cpython-312.pyc +0 -0
- package/skills/roast-me/tools/adapters/__pycache__/claude.cpython-312.pyc +0 -0
- package/skills/roast-me/tools/adapters/__pycache__/codex.cpython-312.pyc +0 -0
- package/skills/roast-me/tools/adapters/__pycache__/gemini.cpython-312.pyc +0 -0
- package/skills/roast-me/tools/adapters/__pycache__/registry.cpython-312.pyc +0 -0
- package/skills/shortform-packaging/SKILL.md +7 -2
- package/skills/shortform-packaging/references/package-templates.md +13 -2
- package/skills/shortform-strategy/SKILL.md +30 -6
- package/skills/shortform-strategy/references/learning-loop-template.md +9 -1
- package/skills/specify/references/spec-template.md +12 -1
- package/skills/tiktok-api/SKILL.md +6 -2
- package/skills/tiktok-api/references/wiki-schema.md +38 -4
- package/skills/unity/SKILL.md +282 -0
- package/skills/unity/evals/README.md +8 -0
- package/skills/unity/evals/cases.yaml +43 -0
- package/skills/unity/references/build-and-platforms.md +65 -0
- package/skills/unity/references/input-system.md +102 -0
- package/skills/unity/references/lifecycle-deep-dive.md +75 -0
- package/skills/unreal/SKILL.md +270 -0
- package/skills/unreal/evals/README.md +12 -0
- package/skills/unreal/evals/cases.yaml +45 -0
- package/skills/unreal/references/blueprint-cpp-parity.md +109 -0
- package/skills/unreal/references/gameplay-framework.md +95 -0
- package/skills/unreal/references/packaging.md +83 -0
- package/skills/verify/SKILL.md +11 -1
- package/skills/youtube-api/SKILL.md +7 -2
- package/skills/youtube-api/references/wiki-schema.md +25 -4
- package/skills/youtube-packaging/SKILL.md +10 -2
- package/skills/youtube-packaging/references/description-and-chapters.md +70 -2
- package/skills/youtube-strategy/SKILL.md +9 -2
- package/skills/youtube-strategy/references/wiki-records.md +39 -6
- package/skills/youtube-strategy/scripts/verify.sh +4 -0
- package/skills/youtube-thumbnails/SKILL.md +10 -5
- package/skills/youtube-thumbnails/references/experiment-log-format.md +28 -2
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
# Character controllers — kinematic vs dynamic, per engine
|
|
2
|
+
|
|
3
|
+
A "character controller" is the code that turns intent (move left, jump) into collision-resolved
|
|
4
|
+
motion. Two approaches; pick one and commit.
|
|
5
|
+
|
|
6
|
+
## Kinematic vs dynamic — the trade
|
|
7
|
+
|
|
8
|
+
| | Kinematic character | Dynamic (rigidbody) character |
|
|
9
|
+
| --- | --- | --- |
|
|
10
|
+
| Motion | you set velocity, a sweep resolves it | forces/impulses, solver resolves it |
|
|
11
|
+
| Feel | precise, snappy, fully authored | physical, momentum-y, harder to make crisp |
|
|
12
|
+
| Pushed by physics | no (you handle it) | yes, for free |
|
|
13
|
+
| Pushes dynamics | yes | yes |
|
|
14
|
+
| Gravity | you add it manually | automatic |
|
|
15
|
+
| Typical use | platformers, shooters, most players | ragdoll-ish, vehicles, physics puzzles |
|
|
16
|
+
| Pain points | you re-implement gravity/slopes/steps | tipping, sliding, jitter — needs constraints + friction |
|
|
17
|
+
|
|
18
|
+
Default to **kinematic** for a controllable character. Reach for dynamic only when physical
|
|
19
|
+
interaction *is* the gameplay.
|
|
20
|
+
|
|
21
|
+
## Godot 4 — CharacterBody (kinematic)
|
|
22
|
+
|
|
23
|
+
`CharacterBody2D/3D` exposes a `velocity` property and `move_and_slide()`, which sweeps by
|
|
24
|
+
`velocity` (already delta-scaled) and slides along surfaces.
|
|
25
|
+
|
|
26
|
+
```gdscript
|
|
27
|
+
extends CharacterBody3D
|
|
28
|
+
|
|
29
|
+
const SPEED := 5.0
|
|
30
|
+
const JUMP_VELOCITY := 4.5
|
|
31
|
+
|
|
32
|
+
func _physics_process(delta: float) -> void:
|
|
33
|
+
if not is_on_floor():
|
|
34
|
+
velocity += get_gravity() * delta # get_gravity() is 4.3+; else read ProjectSettings
|
|
35
|
+
if Input.is_action_just_pressed("jump") and is_on_floor():
|
|
36
|
+
velocity.y = JUMP_VELOCITY
|
|
37
|
+
var input := Input.get_vector("left", "right", "up", "down")
|
|
38
|
+
var dir := (transform.basis * Vector3(input.x, 0, input.y)).normalized()
|
|
39
|
+
velocity.x = dir.x * SPEED
|
|
40
|
+
velocity.z = dir.z * SPEED
|
|
41
|
+
move_and_slide()
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
Tuning knobs on the node:
|
|
45
|
+
- `up_direction` — defines "up" for floor/wall/ceiling classification (default `Vector3.UP`).
|
|
46
|
+
- `floor_max_angle` — steepest slope treated as floor (radians; default 45°). Steeper = wall.
|
|
47
|
+
- `floor_snap_length` — pulls the body to the ground while descending ramps/stairs (kills
|
|
48
|
+
launch-off-ramp and airborne-on-stairs). Requires `floor_stop_on_slope` behavior tuning.
|
|
49
|
+
- `is_on_floor()` / `is_on_wall()` / `is_on_ceiling()`, `get_floor_normal()`,
|
|
50
|
+
`get_slide_collision_count()` + `get_slide_collision(i)` to inspect what was hit.
|
|
51
|
+
- `move_and_collide(motion)` — lower-level single sweep returning a `KinematicCollision`; use when
|
|
52
|
+
you want full manual control (custom slide, wall-jump math).
|
|
53
|
+
|
|
54
|
+
For one-off exact motion (dashes, kinematic bodies not needing slide) use `move_and_collide`.
|
|
55
|
+
|
|
56
|
+
## Unity 6 — CharacterController (kinematic) and the dynamic alternative
|
|
57
|
+
|
|
58
|
+
`CharacterController` is a built-in kinematic capsule with sweeping `Move`. It handles steps and
|
|
59
|
+
slopes via `stepOffset` and `slopeLimit`; it does **not** apply gravity — you do.
|
|
60
|
+
|
|
61
|
+
```csharp
|
|
62
|
+
[RequireComponent(typeof(CharacterController))]
|
|
63
|
+
public class Player : MonoBehaviour {
|
|
64
|
+
public float speed = 6f, jumpVelocity = 5f, gravity = -20f;
|
|
65
|
+
CharacterController cc;
|
|
66
|
+
Vector3 vel; // world-space velocity we integrate ourselves
|
|
67
|
+
|
|
68
|
+
void Awake() => cc = GetComponent<CharacterController>();
|
|
69
|
+
|
|
70
|
+
void Update() { // CharacterController is kinematic: Update is fine
|
|
71
|
+
if (cc.isGrounded && vel.y < 0f) vel.y = -2f; // keep grounded
|
|
72
|
+
Vector3 wish = transform.right * Input.GetAxis("Horizontal")
|
|
73
|
+
+ transform.forward * Input.GetAxis("Vertical");
|
|
74
|
+
if (cc.isGrounded && Input.GetButtonDown("Jump")) vel.y = jumpVelocity;
|
|
75
|
+
vel.y += gravity * Time.deltaTime; // integrate gravity
|
|
76
|
+
cc.Move((wish * speed + Vector3.up * vel.y) * Time.deltaTime);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
Key fields: `isGrounded`, `slopeLimit` (max walkable slope), `stepOffset` (max step height),
|
|
82
|
+
`skinWidth` (small penetration tolerance — keep ~10% of radius; too small causes jitter),
|
|
83
|
+
`center`/`radius`/`height`. `Move` returns `CollisionFlags`; hook `OnControllerColliderHit` to push
|
|
84
|
+
dynamic rigidbodies.
|
|
85
|
+
|
|
86
|
+
**Dynamic rigidbody character** instead: `Rigidbody` with `freezeRotation = true` (or constrain
|
|
87
|
+
X/Z rotation), a high-friction physics material, movement via `AddForce`/target-velocity in
|
|
88
|
+
`FixedUpdate`, and a grounded raycast. More physical, more tuning.
|
|
89
|
+
|
|
90
|
+
## Unreal (UE5) — Character + CharacterMovementComponent
|
|
91
|
+
|
|
92
|
+
`ACharacter` bundles a capsule + `UCharacterMovementComponent` (CMC), a sophisticated kinematic
|
|
93
|
+
controller. It sweeps, handles Walking / Falling / Swimming / Flying **movement modes**, and applies
|
|
94
|
+
its own gravity scale.
|
|
95
|
+
|
|
96
|
+
- **Input → movement:** `AddMovementInput(WorldDirection, ScaleValue)`; jump via `Jump()` /
|
|
97
|
+
`StopJumping()` (`ACharacter` overrides).
|
|
98
|
+
- **Slopes/steps:** CMC `MaxStepHeight`, `SetWalkableFloorAngle` / `GetWalkableFloorAngle`,
|
|
99
|
+
`MaxWalkSpeed`, `GravityScale`, `JumpZVelocity`, `AirControl`.
|
|
100
|
+
- **Ground state:** `Movement->IsMovingOnGround()`, `IsFalling()`; `CurrentFloor` holds the hit.
|
|
101
|
+
- Moving platforms are handled by CMC's base-relative movement when the character stands on a
|
|
102
|
+
movable primitive set as its movement base.
|
|
103
|
+
|
|
104
|
+
For non-Character pawns you can drive a movable component manually or add a `PawnMovementComponent`.
|
|
105
|
+
|
|
106
|
+
## Ground detection, slopes, steps, moving platforms — the recurring problems
|
|
107
|
+
|
|
108
|
+
- **Ground detection** must be robust: a single downward ray can miss on ledges. Use the built-in
|
|
109
|
+
`is_on_floor()` / `isGrounded` / `IsMovingOnGround()` where possible; if rolling your own, use a
|
|
110
|
+
short **shapecast** (capsule/sphere) slightly wider than the character, not a thin ray.
|
|
111
|
+
- **Slopes:** set the max-walkable-angle knob so steep slopes read as walls; add slide-down on
|
|
112
|
+
too-steep surfaces if desired. Project intended velocity onto the floor plane to avoid bumpy speed
|
|
113
|
+
on ramps.
|
|
114
|
+
- **Steps/stairs:** rely on `stepOffset` / `MaxStepHeight` / `floor_snap_length`. A capsule collider
|
|
115
|
+
climbs small steps far more smoothly than a box.
|
|
116
|
+
- **Moving platforms:** the platform must be a **kinematic mover** that reports motion (Godot
|
|
117
|
+
`AnimatableBody` with `sync_to_physics = true`; Unity kinematic `Rigidbody.MovePosition` in
|
|
118
|
+
`FixedUpdate`; Unreal movable primitive as movement base). A **static** body will not carry a
|
|
119
|
+
character. For a kinematic character on a moving platform, add the platform's per-tick delta to the
|
|
120
|
+
character before moving, or parent to the platform's motion.
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
# Determinism, stability & queries
|
|
2
|
+
|
|
3
|
+
Most "my physics is unstable" reports reduce to running simulation in the wrong loop, scaling by the
|
|
4
|
+
wrong delta, or tunneling. This is the fix list plus the query APIs.
|
|
5
|
+
|
|
6
|
+
## The fixed timestep — where physics must live
|
|
7
|
+
|
|
8
|
+
Engines separate the **render frame** (variable rate, once per drawn image) from the **physics tick**
|
|
9
|
+
(fixed rate, e.g. 60 Hz). The solver assumes a constant `dt`; feeding it a variable frame time makes
|
|
10
|
+
behavior frame-rate-dependent — the same jump reaches different heights at 30 vs 144 fps.
|
|
11
|
+
|
|
12
|
+
| Engine | Fixed-tick callback | Rate setting |
|
|
13
|
+
| --- | --- | --- |
|
|
14
|
+
| Godot 4 | `_physics_process(delta)` | `Engine.physics_ticks_per_second` / Project Settings → Physics → Physics Ticks per Second (default 60) |
|
|
15
|
+
| Unity 6 | `FixedUpdate()` | `Time.fixedDeltaTime` / Project Settings → Time → Fixed Timestep |
|
|
16
|
+
| Unreal | Chaos **substepping** / Async Physics Tick | Project Settings → Physics → Substepping (`Max Substep Delta Time`, `Max Substeps`) |
|
|
17
|
+
|
|
18
|
+
**Pattern:** poll input in the frame update (`_process` / `Update` / `Tick`), cache intent, then
|
|
19
|
+
*apply* forces/velocity and run physics queries in the fixed tick. Never move a physics body or read
|
|
20
|
+
physics state from the render frame.
|
|
21
|
+
|
|
22
|
+
In Unreal, enabling **Substepping** lets the solver take several fixed sub-steps within a long frame,
|
|
23
|
+
keeping constraints stable at low fps; for hard determinism use the Chaos async physics tick, which
|
|
24
|
+
runs your callback at a fixed rate off the game thread.
|
|
25
|
+
|
|
26
|
+
## Scale by delta — but not twice
|
|
27
|
+
|
|
28
|
+
- Manual position changes, accelerations, and continuous forces you integrate yourself: multiply by
|
|
29
|
+
the tick delta (`delta` / `fixedDeltaTime`).
|
|
30
|
+
- Helpers that already integrate time: do **not** delta-scale their input. Godot `move_and_slide()`
|
|
31
|
+
takes a per-second `velocity` and applies the timestep internally. Unity `CharacterController.Move`
|
|
32
|
+
expects a per-*frame* displacement, so you pass `velocity * Time.deltaTime` (velocity is per
|
|
33
|
+
second) — the classic mistake is forgetting the delta there while double-applying it elsewhere.
|
|
34
|
+
- Gravity done by hand: `velocity += gravity * delta` each tick (gravity is an acceleration).
|
|
35
|
+
|
|
36
|
+
## Interpolation — smooth visuals without touching the sim
|
|
37
|
+
|
|
38
|
+
At frame rates above the tick rate, rendering the raw physics position looks choppy. Turn on
|
|
39
|
+
interpolation to render an in-between pose; it is **purely visual** and never alters the simulation.
|
|
40
|
+
|
|
41
|
+
- Godot 4: physics interpolation (Project Settings → Physics → Common → Physics Interpolation, plus
|
|
42
|
+
per-node where applicable).
|
|
43
|
+
- Unity: `Rigidbody.interpolation = RigidbodyInterpolation.Interpolate` (or `Extrapolate`).
|
|
44
|
+
- Unreal: interpolation handled by the movement/render sync; async physics results are interpolated.
|
|
45
|
+
|
|
46
|
+
## Tunneling & CCD
|
|
47
|
+
|
|
48
|
+
A fast body moving more than its own thickness per tick can pass fully through a thin collider before
|
|
49
|
+
any overlap is tested (discrete collision). Fixes, cheapest first:
|
|
50
|
+
|
|
51
|
+
1. Make the wall/collider thicker than the fastest per-tick travel, or the projectile bigger.
|
|
52
|
+
2. Enable **Continuous Collision Detection** on the *fast* body only (it is expensive):
|
|
53
|
+
- Godot: `continuous_cd` (RigidBody2D: Disabled / Cast Ray / Cast Shape; RigidBody3D: on/off).
|
|
54
|
+
- Unity: `Rigidbody.collisionDetectionMode = Continuous` / `ContinuousDynamic` /
|
|
55
|
+
`ContinuousSpeculative`.
|
|
56
|
+
- Unreal: **Use CCD** on the body instance.
|
|
57
|
+
3. For bullets, prefer a **raycast/shapecast-then-move**: sweep from last position to next, and if it
|
|
58
|
+
hits, resolve at the hit point. This is more reliable than CCD for very small, very fast objects.
|
|
59
|
+
|
|
60
|
+
## Other stability rules
|
|
61
|
+
|
|
62
|
+
- **Mass ratios:** keep interacting/jointed bodies within ~10:1 (100:1 blows up). Very light bodies
|
|
63
|
+
under very heavy ones jitter or get ejected.
|
|
64
|
+
- **Never scale a collider at runtime.** Scaling the transform of a body with a collider (especially
|
|
65
|
+
non-uniform scale) corrupts the shape and broadphase — swap the shape or size the shape resource
|
|
66
|
+
instead.
|
|
67
|
+
- **Never write `transform`/`position`/`rotation` on a dynamic (simulated) body.** It teleports past
|
|
68
|
+
the solver, producing explosions, missed contacts, and ghost collisions. Move dynamics with
|
|
69
|
+
forces/impulses/velocity; move kinematics with the provided API (`MovePosition`,
|
|
70
|
+
`move_and_slide`, `SetWorldLocation` with sweep).
|
|
71
|
+
- **Sleeping:** resting bodies sleep to save CPU and stop micro-jitter. Applying a force or a query
|
|
72
|
+
may need to wake them (`RigidBody.sleeping = false`, `Rigidbody.WakeUp()`); don't fight the sleep
|
|
73
|
+
system with tiny constant forces.
|
|
74
|
+
- **Solver iterations:** if stacks/joints sag or jitter, raise solver iteration counts (Project/
|
|
75
|
+
physics settings) before hacking masses.
|
|
76
|
+
|
|
77
|
+
## Queries — raycast, shapecast, overlap
|
|
78
|
+
|
|
79
|
+
Run queries in the fixed tick so they see the simulated state, and filter by layer/mask/channel.
|
|
80
|
+
|
|
81
|
+
**Godot 4** — via the space state (works in `_physics_process`):
|
|
82
|
+
|
|
83
|
+
```gdscript
|
|
84
|
+
var space := get_world_3d().direct_space_state
|
|
85
|
+
var q := PhysicsRayQueryParameters3D.create(from, to)
|
|
86
|
+
q.collision_mask = 0b0001 # only scan layer 1
|
|
87
|
+
q.exclude = [self] # ignore ourselves
|
|
88
|
+
var hit := space.intersect_ray(q) # {} if nothing; else position, normal, collider, ...
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
Shape sweep: `PhysicsShapeQueryParameters3D` + `intersect_shape` (overlap) or `cast_motion` (how far
|
|
92
|
+
a shape can move before hitting). Node helpers `RayCast2D/3D` and `ShapeCast2D/3D` update every tick.
|
|
93
|
+
|
|
94
|
+
**Unity 6:**
|
|
95
|
+
|
|
96
|
+
```csharp
|
|
97
|
+
int mask = LayerMask.GetMask("Ground");
|
|
98
|
+
if (Physics.Raycast(origin, dir, out RaycastHit hit, dist, mask)) { /* hit.point, hit.normal */ }
|
|
99
|
+
if (Physics.SphereCast(origin, radius, dir, out RaycastHit sh, dist, mask)) { /* swept */ }
|
|
100
|
+
Collider[] hits = Physics.OverlapSphere(center, radius, mask); // overlap test
|
|
101
|
+
bool blocked = Physics.CheckSphere(center, radius, mask); // cheap boolean
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
Use `RaycastNonAlloc` / `OverlapSphereNonAlloc` in hot paths to avoid garbage. 2D equivalents live on
|
|
105
|
+
`Physics2D` (`Raycast`, `OverlapCircle`, `CircleCast`).
|
|
106
|
+
|
|
107
|
+
**Unreal (UE5):**
|
|
108
|
+
|
|
109
|
+
```cpp
|
|
110
|
+
FHitResult Hit;
|
|
111
|
+
FCollisionQueryParams Params(NAME_None, /*bTraceComplex=*/false, this);
|
|
112
|
+
bool bHit = GetWorld()->LineTraceSingleByChannel(
|
|
113
|
+
Hit, Start, End, ECC_Visibility, Params); // trace channel
|
|
114
|
+
GetWorld()->SweepSingleByChannel( // shapecast
|
|
115
|
+
Hit, Start, End, FQuat::Identity, ECC_Pawn,
|
|
116
|
+
FCollisionShape::MakeSphere(30.f), Params);
|
|
117
|
+
TArray<FOverlapResult> Overlaps; // overlap test
|
|
118
|
+
GetWorld()->OverlapMultiByChannel(
|
|
119
|
+
Overlaps, Center, FQuat::Identity, ECC_WorldDynamic,
|
|
120
|
+
FCollisionShape::MakeBox(FVector(50)), Params);
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
Use `...ByObjectType` variants to query by object channels, `...ByChannel` for trace channels. Set
|
|
124
|
+
`bTraceComplex = true` only when you need per-triangle precision (costly).
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
# Collision layers & masks — the filtering that trips everyone up
|
|
2
|
+
|
|
3
|
+
The single most common physics bug that is not a crash: "these two things should collide and they
|
|
4
|
+
don't," or "this ghost trigger fires on everything." Both are filtering. The concept is universal;
|
|
5
|
+
only the words change.
|
|
6
|
+
|
|
7
|
+
**Layer = what I *am*. Mask = what I *scan for*.** They are independent bit sets. A body being in
|
|
8
|
+
layer 3 says nothing about what it collides with — that is the mask's job.
|
|
9
|
+
|
|
10
|
+
## Godot 4
|
|
11
|
+
|
|
12
|
+
Two properties on every `CollisionObject2D/3D` (StaticBody, RigidBody, CharacterBody, Area):
|
|
13
|
+
|
|
14
|
+
- `collision_layer` — the layer bits this body occupies (what it *is*).
|
|
15
|
+
- `collision_mask` — the layer bits this body scans (what it *looks for*).
|
|
16
|
+
|
|
17
|
+
**The rule:** a contact is registered when **either** body's `collision_mask` intersects the
|
|
18
|
+
other's `collision_layer`. It is an **OR**, which is why detection can be *asymmetric* — body A can
|
|
19
|
+
detect body B even if B does not scan for A. This is deliberate (one-way triggers, sensors) but is
|
|
20
|
+
also the classic footgun. **Keep layer/mask symmetric for solid collisions** unless you truly want
|
|
21
|
+
one-way behavior.
|
|
22
|
+
|
|
23
|
+
For an `Area2D/3D`, the split matters: the Area's **mask** determines which bodies/areas it
|
|
24
|
+
*detects* (fires `body_entered` / `area_entered`); the Area's **layer** determines whether something
|
|
25
|
+
else can detect the Area. A detector-only Area often has a mask set and layer cleared.
|
|
26
|
+
|
|
27
|
+
Name your layers in **Project Settings → Layer Names → 2D/3D Physics** so the inspector shows
|
|
28
|
+
"player / enemy / world / pickup" instead of bare numbers. Set bits from code with the helpers, not
|
|
29
|
+
raw math:
|
|
30
|
+
|
|
31
|
+
```gdscript
|
|
32
|
+
set_collision_layer_value(2, true) # I am on layer 2
|
|
33
|
+
set_collision_mask_value(1, true) # I scan layer 1
|
|
34
|
+
set_collision_mask_value(3, true) # ...and layer 3
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
Bits are 1-indexed in these helpers; the raw `collision_layer` int is a bitmask (layer 1 = value 1,
|
|
38
|
+
layer 2 = value 2, layer 3 = value 4, ...). `collision_layer = 0b101` means layers 1 and 3.
|
|
39
|
+
|
|
40
|
+
## Unity 6
|
|
41
|
+
|
|
42
|
+
Physics filtering is layer-pair based, not per-object masks:
|
|
43
|
+
|
|
44
|
+
1. Assign each GameObject a **Layer** (Inspector top-right; define names in Tags & Layers). Physics
|
|
45
|
+
layers are the same 32 layers used everywhere.
|
|
46
|
+
2. **Project Settings → Physics → Layer Collision Matrix** (and Physics 2D separately) is a
|
|
47
|
+
checkbox grid: an unticked cell means those two layers **never** collide or trigger. This is the
|
|
48
|
+
global filter.
|
|
49
|
+
3. Toggle a single pair at runtime: `Physics.IgnoreLayerCollision(layerA, layerB, true)` — or
|
|
50
|
+
`Physics.IgnoreCollision(colliderA, colliderB)` for two specific colliders.
|
|
51
|
+
|
|
52
|
+
Queries take a **`LayerMask`** argument, which is a *different* use of the same layers — it says
|
|
53
|
+
which layers the ray/overlap considers:
|
|
54
|
+
|
|
55
|
+
```csharp
|
|
56
|
+
// Build a mask from names, then raycast only against Ground + Enemy.
|
|
57
|
+
int mask = LayerMask.GetMask("Ground", "Enemy");
|
|
58
|
+
if (Physics.Raycast(origin, dir, out RaycastHit hit, 50f, mask)) { /* ... */ }
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
A `LayerMask` is a bitfield: `1 << layerIndex`. Combine with `|`, exclude with `~`. A common mistake
|
|
62
|
+
is passing a layer *index* where a *mask* is expected — always shift or use `LayerMask.GetMask`.
|
|
63
|
+
|
|
64
|
+
## Unreal (UE5, Chaos)
|
|
65
|
+
|
|
66
|
+
Two axes per primitive component, configured via **Collision Presets** (Details → Collision):
|
|
67
|
+
|
|
68
|
+
- **Object Type** — the single channel this component *is* (WorldStatic, WorldDynamic, Pawn,
|
|
69
|
+
PhysicsBody, or a custom object channel). This is "what I am."
|
|
70
|
+
- **Collision Responses** — for every channel, one of **Block / Overlap / Ignore**. This is "how I
|
|
71
|
+
react to each kind of thing."
|
|
72
|
+
|
|
73
|
+
For two components to physically **block**, *both* must respond Block to the other's object type. For
|
|
74
|
+
an **overlap** event, at least one responds Overlap (and the other not Ignore) and **Generate
|
|
75
|
+
Overlap Events** is enabled on both. Bundle a configuration into a named **Collision Preset**
|
|
76
|
+
(Project Settings → Collision) so a whole class of actors shares it — e.g. a `Trigger` preset that
|
|
77
|
+
overlaps Pawns and ignores everything else.
|
|
78
|
+
|
|
79
|
+
**Trace channels** (Visibility, Camera, or custom) are a *separate* set used only by line/shape
|
|
80
|
+
traces, distinct from object channels used for physical collision. A common error is tracing on an
|
|
81
|
+
object channel or vice versa.
|
|
82
|
+
|
|
83
|
+
```cpp
|
|
84
|
+
// Custom object channel example (defined in DefaultEngine.ini as ECC_GameTraceChannel1).
|
|
85
|
+
Comp->SetCollisionObjectType(ECC_Pawn);
|
|
86
|
+
Comp->SetCollisionResponseToAllChannels(ECR_Ignore);
|
|
87
|
+
Comp->SetCollisionResponseToChannel(ECC_WorldStatic, ECR_Block);
|
|
88
|
+
Comp->SetCollisionResponseToChannel(ECC_Pawn, ECR_Overlap);
|
|
89
|
+
Comp->SetGenerateOverlapEvents(true);
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
## Worked example — player / enemy / pickup / wall
|
|
93
|
+
|
|
94
|
+
Desired: player and enemies collide with walls and each other; the pickup collides with nothing but
|
|
95
|
+
detects the player touching it.
|
|
96
|
+
|
|
97
|
+
| Thing | Godot layer | Godot mask | Unity layer / matrix | Unreal preset |
|
|
98
|
+
| --- | --- | --- | --- | --- |
|
|
99
|
+
| Wall | World | (none needed) | World; collides with Player, Enemy | BlockAll |
|
|
100
|
+
| Player | Player | World, Enemy, Pickup | Player; collides World, Enemy | Pawn (blocks World/Pawn) |
|
|
101
|
+
| Enemy | Enemy | World, Player, Enemy | Enemy; collides World, Player, Enemy | Pawn |
|
|
102
|
+
| Pickup (Area/Trigger) | Pickup | Player | Pickup; **only** Player pair ticked, `IsTrigger` | Custom `Pickup`: overlap Pawn, ignore all else |
|
|
103
|
+
|
|
104
|
+
The pickup is a **trigger/Area**: it scans only for the Player layer and produces an overlap event,
|
|
105
|
+
never a solid collision.
|
|
106
|
+
|
|
107
|
+
## Debug checklist when a collision "doesn't happen"
|
|
108
|
+
|
|
109
|
+
- Do the layer/mask bits actually overlap? (Godot: is one body's mask covering the other's layer?)
|
|
110
|
+
- Unity: is the pair ticked in the **Layer Collision Matrix**, and did you use 2D matrix for 2D?
|
|
111
|
+
- Unity trigger: is there a **Rigidbody** on at least one of the two objects? Trigger events need one.
|
|
112
|
+
- Unreal: are **both** set to Block (for solid) or is Generate Overlap Events on **both** (for overlap)?
|
|
113
|
+
- Query returns nothing: are you passing a **mask/channel** that includes the target? Passing a raw
|
|
114
|
+
layer index instead of a shifted mask silently matches the wrong layer.
|
|
115
|
+
- One-way collision you did not intend → Godot asymmetric mask; make it symmetric.
|
|
@@ -0,0 +1,252 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: gamedev-shaders
|
|
3
|
+
description: "Use when writing shaders, materials, VFX, or post-processing for a game engine, or asking \"how do I make this effect\" — covers the vertex→fragment pipeline, UVs / normals / coordinate spaces, and per-engine authoring in Godot 4.x (shader_type spatial/canvas_item/particles, source_color, hint_screen_texture, ShaderMaterial), Unity 6 (Shader Graph vs HLSL, URP/HDRP, ShaderLab), and Unreal 5.x (Material graph, material domains, Custom HLSL node). Includes recipes for dissolve, rim/outline, toon/cel, water/flow, force field, hologram; full-screen post-process; and shader performance (overdraw, texture-sample cost, branching, mobile). Triggers: \"write a dissolve shader\", \"rim light\", \"toon shading\", \"screen-space effect\", \"my shader is slow on mobile\", \"cómo hago un shader de agua\". NOT gameplay or engine-API code (→ godot / unity / unreal) and NOT physics simulation, collision, or rigid bodies (→ gamedev-physics)."
|
|
4
|
+
tags: [shaders, vfx, materials, post-processing, shadergraph]
|
|
5
|
+
recommends: [godot, unity, unreal, gamedev-shipping]
|
|
6
|
+
profiles: [full]
|
|
7
|
+
origin: risco
|
|
8
|
+
---
|
|
9
|
+
|
|
10
|
+
# Shaders & VFX (game engines)
|
|
11
|
+
|
|
12
|
+
Author shaders, materials, and full-screen effects across Godot, Unity, and Unreal. One
|
|
13
|
+
mental model — the GPU pipeline — mapped onto each engine's authoring surface, plus recipes
|
|
14
|
+
for the effects people actually ask for. Fires on writing/debugging a shader or material,
|
|
15
|
+
building a VFX/post-process effect, or "how do I make X look like Y".
|
|
16
|
+
|
|
17
|
+
## Version contract — read first
|
|
18
|
+
|
|
19
|
+
Target the current stable line of each engine and never emit its retired APIs. If unsure a
|
|
20
|
+
symbol is current, say so rather than guess.
|
|
21
|
+
|
|
22
|
+
| Engine | Target | Never emit → use instead |
|
|
23
|
+
| --- | --- | --- |
|
|
24
|
+
| **Godot** | 4.x (4.4/4.5 stable) | `SCREEN_TEXTURE`/`DEPTH_TEXTURE`/`NORMAL_TEXTURE` built-ins → declare a `uniform sampler2D … : hint_screen_texture` / `hint_depth_texture` / `hint_normal_roughness_texture`. `hint_color`/`hint_albedo` → `source_color`. `hint_white`/`hint_black` → `hint_default_white`/`hint_default_black`. GLES2-era guides. |
|
|
25
|
+
| **Unity** | 6 (6000.x LTS), URP/HDRP | Surface shaders (`#pragma surface`) — Built-in-RP only, they do **not** compile under URP/HDRP. `CGPROGRAM`+`UnityCG.cginc`, `UnityObjectToClipPos`, `mul(UNITY_MATRIX_MVP, v)` → `HLSLPROGRAM` + URP `Core.hlsl` and `TransformObjectToHClip(posOS)`. `OnRenderImage`/`Graphics.Blit` post FX → URP Renderer Feature / Fullscreen Shader Graph. |
|
|
26
|
+
| **Unreal** | 5.x (5.4+) | `SceneTexture:PostProcessInput0` outside a Post Process material; Opacity without a translucent blend mode; Opacity Mask without a Masked blend mode. Prefer graph nodes; drop to a Custom HLSL node only for logic nodes can't express. |
|
|
27
|
+
|
|
28
|
+
`shader_type` tokens in Godot 4 are exact: `spatial`, `canvas_item` (underscore), `particles`
|
|
29
|
+
(plural), `sky`, `fog`.
|
|
30
|
+
|
|
31
|
+
## When to use / When NOT to use
|
|
32
|
+
|
|
33
|
+
**Use when:** writing or debugging a `.gdshader`/`ShaderMaterial`, a `.shader`/Shader Graph, or
|
|
34
|
+
a UE Material; building a VFX look (dissolve, rim, toon, water, shield, hologram, trails);
|
|
35
|
+
authoring post-processing / screen-space effects; a shader is slow, flickers, or looks wrong;
|
|
36
|
+
choosing per-vertex vs per-pixel; converting an effect between engines.
|
|
37
|
+
|
|
38
|
+
**When NOT to use (delegate):**
|
|
39
|
+
|
|
40
|
+
- Gameplay logic, nodes/components, input, engine APIs, scene setup → [`godot`](../godot/SKILL.md) /
|
|
41
|
+
[`unity`](../unity/SKILL.md) / [`unreal`](../unreal/SKILL.md). This skill owns the *shading*, not the C#/GDScript/Blueprint around it.
|
|
42
|
+
- Physics simulation, collisions, rigid bodies, character controllers → [`gamedev-physics`](../gamedev-physics/SKILL.md).
|
|
43
|
+
(A shader that *fakes* refraction is here; simulating fluid dynamics is not.)
|
|
44
|
+
- Shipping, platform export, shader-variant stripping in the build pipeline → [`gamedev-shipping`](../gamedev-shipping/SKILL.md)
|
|
45
|
+
(this skill keeps the per-shader performance work).
|
|
46
|
+
|
|
47
|
+
## Shader fundamentals (the pipeline)
|
|
48
|
+
|
|
49
|
+
Every engine compiles your material into the same GPU stages. Two you write:
|
|
50
|
+
|
|
51
|
+
- **Vertex stage** — runs **once per vertex**. Transforms position into clip space and passes
|
|
52
|
+
interpolated data (UVs, normals, custom `varying`s) down. Cheap; scales with mesh vertex count.
|
|
53
|
+
- **Rasterizer** (fixed) turns triangles into fragments and *interpolates* the vertex outputs.
|
|
54
|
+
- **Fragment / pixel stage** — runs **once per covered pixel** (× overdraw). Samples textures,
|
|
55
|
+
does lighting, writes the final color. Expensive; scales with screen coverage.
|
|
56
|
+
|
|
57
|
+
**Per-vertex vs per-pixel is the core performance lever:** compute anything that interpolates
|
|
58
|
+
linearly (position offsets, un-normalized directions, scalar masks) in the vertex stage and pass
|
|
59
|
+
it as a `varying`; keep only what must be exact per-pixel (normalizing interpolated normals,
|
|
60
|
+
texture sampling, lighting, fresnel) in the fragment stage.
|
|
61
|
+
|
|
62
|
+
**UVs** are per-vertex 2D texture coordinates (0–1), interpolated across the face — you sample
|
|
63
|
+
textures and drive scrolling/tiling/masks with them. **Normals** are surface directions used for
|
|
64
|
+
lighting and rim; interpolated normals must be re-normalized per pixel. **Normal maps** store
|
|
65
|
+
directions in **tangent space** (unpack with `×2−1`); respect handedness.
|
|
66
|
+
|
|
67
|
+
**Coordinate spaces** — know which space each value is in before you do math on it:
|
|
68
|
+
|
|
69
|
+
| Space | Meaning | Typical use |
|
|
70
|
+
| --- | --- | --- |
|
|
71
|
+
| Object / model | mesh-local, origin at the pivot | authoring positions/normals start here |
|
|
72
|
+
| World | scene-global | world-space effects, triplanar, lighting |
|
|
73
|
+
| View / camera | relative to the camera | Godot spatial `NORMAL`/`VIEW` live here |
|
|
74
|
+
| Clip / NDC | post-projection homogeneous coords | the vertex stage's required output |
|
|
75
|
+
| Tangent | per-fragment surface basis (T,B,N) | normal maps are decoded here |
|
|
76
|
+
| Screen / UV | 0–1 across the framebuffer | post-process sampling (`SCREEN_UV`) |
|
|
77
|
+
|
|
78
|
+
## Per-engine authoring
|
|
79
|
+
|
|
80
|
+
### Godot 4.x
|
|
81
|
+
|
|
82
|
+
Godot ships its own GLSL-like language (`.gdshader`). Pick a `shader_type`, declare `uniform`s
|
|
83
|
+
(exposed as material parameters), pass data with `varying`, write `vertex()`/`fragment()`
|
|
84
|
+
(+`light()`). A **ShaderMaterial** binds the shader to a node and holds uniform values; set them
|
|
85
|
+
from code with `material.set_shader_parameter("name", value)`. Uniform hints: `source_color`
|
|
86
|
+
(sRGB→linear color pickers), `hint_range(a,b)`, `hint_default_white`, `hint_screen_texture`,
|
|
87
|
+
plus texture filters/repeats (`filter_linear_mipmap`, `repeat_enable`).
|
|
88
|
+
|
|
89
|
+
Small **canvas_item** (2D) shader — scroll and tint a texture:
|
|
90
|
+
|
|
91
|
+
```glsl
|
|
92
|
+
shader_type canvas_item;
|
|
93
|
+
uniform sampler2D noise : repeat_enable;
|
|
94
|
+
uniform vec4 tint : source_color = vec4(1.0);
|
|
95
|
+
uniform float speed = 0.1;
|
|
96
|
+
|
|
97
|
+
void fragment() {
|
|
98
|
+
vec2 uv = UV + vec2(TIME * speed, 0.0); // UV is the node's texcoord
|
|
99
|
+
COLOR = texture(noise, uv) * tint * COLOR; // in COLOR = vertex/modulate color
|
|
100
|
+
}
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
Small **spatial** (3D) shader — a fresnel rim glow (`NORMAL` and `VIEW` are **view-space** here):
|
|
104
|
+
|
|
105
|
+
```glsl
|
|
106
|
+
shader_type spatial;
|
|
107
|
+
render_mode blend_add, cull_back;
|
|
108
|
+
uniform vec3 rim_color : source_color = vec3(0.2, 0.6, 1.0);
|
|
109
|
+
uniform float power : hint_range(0.0, 8.0) = 3.0;
|
|
110
|
+
|
|
111
|
+
varying vec3 v_normal;
|
|
112
|
+
void vertex() { v_normal = NORMAL; } // pass to fragment via varying
|
|
113
|
+
void fragment() {
|
|
114
|
+
float f = pow(1.0 - dot(normalize(v_normal), normalize(VIEW)), power);
|
|
115
|
+
EMISSION = rim_color * f;
|
|
116
|
+
ALPHA = f;
|
|
117
|
+
}
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
Deep dive (built-in variables per type, render_modes, particles/sky/fog, screen/depth reads) →
|
|
121
|
+
`references/godot-shading-language.md`.
|
|
122
|
+
|
|
123
|
+
### Unity 6
|
|
124
|
+
|
|
125
|
+
Two authoring paths, both on the Scriptable Render Pipeline (**URP** for most projects, **HDRP**
|
|
126
|
+
for high-end):
|
|
127
|
+
|
|
128
|
+
- **Shader Graph** — visual node graph feeding a *master stack* (Vertex + Fragment blocks).
|
|
129
|
+
Artist-friendly, URP/HDRP only, compiles to HLSL. Default choice for surface looks and VFX.
|
|
130
|
+
- **Hand-written HLSL** — a `Shader "…" { … }` (ShaderLab) wrapping `Properties` and `Pass`
|
|
131
|
+
blocks; the program goes in an `HLSLPROGRAM … ENDHLSL` block that `#include`s URP's `Core.hlsl`
|
|
132
|
+
/ `Lighting.hlsl`. Use for full control, custom lighting, or compute-driven effects.
|
|
133
|
+
|
|
134
|
+
**Surface shaders are Built-in-RP only** — under URP/HDRP write a lit HLSL pass or a Shader Graph;
|
|
135
|
+
use `TransformObjectToHClip` for the clip transform, not the retired `UnityObjectToClipPos`. Set
|
|
136
|
+
parameters at runtime through a `MaterialPropertyBlock` or `Material.SetFloat/SetColor/SetTexture`.
|
|
137
|
+
Full URP unlit + lit HLSL pass and a Shader Graph mapping → `references/unity-and-unreal-shaders.md`.
|
|
138
|
+
|
|
139
|
+
### Unreal 5.x
|
|
140
|
+
|
|
141
|
+
A **Material** is a node graph the engine compiles to HLSL. You wire outputs on the main result
|
|
142
|
+
node — Base Color, Metallic, Roughness, Emissive Color, Normal, Opacity / Opacity Mask, World
|
|
143
|
+
Position Offset. Key knobs on the material:
|
|
144
|
+
|
|
145
|
+
- **Material Domain** — what the material drives: *Surface* (default meshes), *Deferred Decal*,
|
|
146
|
+
*Light Function*, *Volume*, *Post Process* (full-screen), *User Interface*.
|
|
147
|
+
- **Blend Mode** (Opaque/Masked/Translucent/Additive…) and **Shading Model** (Default Lit,
|
|
148
|
+
Unlit, Subsurface, …). Opacity needs Translucent; Opacity Mask needs Masked.
|
|
149
|
+
- **Material Instances** expose parameters (scalar/vector/texture/switch) for cheap variants and
|
|
150
|
+
runtime tweaks via a Dynamic Material Instance (`SetScalarParameterValue`, …).
|
|
151
|
+
- **Custom node** — a raw HLSL escape hatch: set Output Type, add named Inputs, `return …;`.
|
|
152
|
+
Reach for it only when the node set can't express the logic (loops, bitops). Reuse via Material
|
|
153
|
+
Functions. UE5.5+ adds *Substrate* as an opt-in shading system; the standard material is still default.
|
|
154
|
+
|
|
155
|
+
Custom-node HLSL, domains, and a Godot↔Unreal recipe mapping → `references/unity-and-unreal-shaders.md`.
|
|
156
|
+
|
|
157
|
+
## Common effect recipes (concepts)
|
|
158
|
+
|
|
159
|
+
Each is a *technique*, engine-agnostic — the reference has full per-engine code.
|
|
160
|
+
|
|
161
|
+
| Effect | Core idea |
|
|
162
|
+
| --- | --- |
|
|
163
|
+
| **Dissolve** | Threshold a noise texture against an animated cutoff; `discard`/clip below it; add an emissive band at the edge. |
|
|
164
|
+
| **Rim / outline** | Rim = fresnel `pow(1 − N·V, p)`. Outline = inverted-hull pass (scale along normals, flip culling) **or** a post-process depth/normal edge detect. |
|
|
165
|
+
| **Toon / cel** | Quantize diffuse `N·L` into bands (`step`/`smoothstep` or a ramp texture); hard-stepped specular. |
|
|
166
|
+
| **Water / flow** | Scroll two normal maps at different speeds (or advect a flow-map's RG); refract the screen texture; depth-difference foam at shorelines. |
|
|
167
|
+
| **Force field** | Fresnel + scrolling hex/pattern texture + intersection glow from a scene-depth difference; additive. |
|
|
168
|
+
| **Hologram** | Scanlines `sin(worldY·f + TIME)` + fresnel + flicker + slight RGB channel offset; additive/translucent. |
|
|
169
|
+
|
|
170
|
+
**Worked example — dissolve (Godot spatial):**
|
|
171
|
+
|
|
172
|
+
```glsl
|
|
173
|
+
shader_type spatial;
|
|
174
|
+
render_mode cull_disabled;
|
|
175
|
+
uniform sampler2D dissolve_noise : hint_default_white;
|
|
176
|
+
uniform float threshold : hint_range(0.0, 1.0) = 0.0; // animate 0 → 1
|
|
177
|
+
uniform float edge = 0.05;
|
|
178
|
+
uniform vec3 edge_color : source_color = vec3(1.0, 0.4, 0.0);
|
|
179
|
+
|
|
180
|
+
void fragment() {
|
|
181
|
+
float n = texture(dissolve_noise, UV).r;
|
|
182
|
+
if (n < threshold) discard; // cut the hole
|
|
183
|
+
float e = smoothstep(threshold, threshold + edge, n);
|
|
184
|
+
EMISSION = edge_color * (1.0 - e); // glowing burn ring
|
|
185
|
+
ALBEDO = vec3(0.6);
|
|
186
|
+
}
|
|
187
|
+
```
|
|
188
|
+
|
|
189
|
+
Drive `threshold` from an `AnimationPlayer` or `set_shader_parameter`. The same math ports to
|
|
190
|
+
Unity (`clip(n - threshold)`) and Unreal (Opacity Mask + a threshold parameter). All six recipes,
|
|
191
|
+
per engine → `references/effect-recipes.md`.
|
|
192
|
+
|
|
193
|
+
## Post-processing / full-screen effects
|
|
194
|
+
|
|
195
|
+
- **Godot** — a `canvas_item` shader on a full-rect `ColorRect` reading `hint_screen_texture`, or
|
|
196
|
+
a spatial unshaded full-screen quad reading `hint_screen_texture`/`hint_depth_texture`; or a
|
|
197
|
+
`CompositorEffect` (4.3+) for a custom render pass. Environment already covers glow/tonemap/SSAO.
|
|
198
|
+
- **Unity (URP)** — a **Full Screen Pass Renderer Feature** driving a *Fullscreen* Shader Graph
|
|
199
|
+
(or a Blit pass). HDRP uses Custom Pass / Fullscreen. Legacy `OnRenderImage` is Built-in-RP only.
|
|
200
|
+
- **Unreal** — a **Post Process Material** (Material Domain = Post Process) on a Post Process
|
|
201
|
+
Volume; read the frame with **SceneTexture** nodes (SceneColor, SceneDepth, custom stencil).
|
|
202
|
+
Blendable Location orders it against tonemapping.
|
|
203
|
+
|
|
204
|
+
## Performance
|
|
205
|
+
|
|
206
|
+
- **Overdraw** is the top cost: transparent/additive layers each re-shade the same pixels. Prefer
|
|
207
|
+
opaque, sort and minimize overlap, keep particle fill low. `discard`/`clip` **disables early-Z**
|
|
208
|
+
— don't use it as a cheap "invisible".
|
|
209
|
+
- **Texture sampling** = a memory fetch + filter each call; *dependent* reads (UV derived from a
|
|
210
|
+
prior sample) stall the pipeline. Pack masks into channels, atlas, and cache samples in locals.
|
|
211
|
+
- **Branching**: a divergent `if` across a GPU warp can execute *both* sides. Prefer
|
|
212
|
+
`step`/`mix`/`clamp`; branches on a **uniform** (same value for all pixels) are cheap; static
|
|
213
|
+
branches compile out.
|
|
214
|
+
- **LOD & precision**: use mipmaps, shader LOD variants, and `mediump`/half precision on mobile;
|
|
215
|
+
full `float` only where banding shows. Move linear work to the vertex stage.
|
|
216
|
+
- **Mobile / tile GPUs**: bandwidth-bound — keep render targets small, avoid mid-pass framebuffer
|
|
217
|
+
reads, and note that `discard` and large full-screen passes break tile hidden-surface removal.
|
|
218
|
+
|
|
219
|
+
## Guardrails / gotchas
|
|
220
|
+
|
|
221
|
+
- Godot 4: the `SCREEN_TEXTURE`/`DEPTH_TEXTURE` built-ins are gone — declare `hint_screen_texture`
|
|
222
|
+
/ `hint_depth_texture` uniforms. `hint_color` → `source_color`. Author colors as `source_color`
|
|
223
|
+
so sRGB→linear conversion is correct.
|
|
224
|
+
- Unity: don't write a surface shader or include `UnityCG.cginc` for a URP/HDRP project.
|
|
225
|
+
- Unreal: `SceneTexture` post-process nodes only work in the Post Process domain; match Opacity to
|
|
226
|
+
the blend mode.
|
|
227
|
+
- Normalize interpolated normals per pixel; unpack normal maps (`×2−1`) and mind tangent handedness.
|
|
228
|
+
- Watch color space (linear vs sRGB) at every texture read and color output — the #1 "looks washed
|
|
229
|
+
out / too dark" bug.
|
|
230
|
+
|
|
231
|
+
## Related skills
|
|
232
|
+
|
|
233
|
+
- [`godot`](../godot/SKILL.md) / [`unity`](../unity/SKILL.md) / [`unreal`](../unreal/SKILL.md) — the
|
|
234
|
+
engine skills own gameplay code, nodes/components, and scene wiring; this skill owns the shaders/materials.
|
|
235
|
+
- [`gamedev-physics`](../gamedev-physics/SKILL.md) — simulation, collision, rigid bodies (a shader that *fakes* an effect stays here).
|
|
236
|
+
- [`gamedev-shipping`](../gamedev-shipping/SKILL.md) — platform export and shader-variant stripping in the build.
|
|
237
|
+
|
|
238
|
+
## Checklist
|
|
239
|
+
|
|
240
|
+
- [ ] Correct engine + version idiom (no banned API from the Version contract table).
|
|
241
|
+
- [ ] Right `shader_type` / render pipeline / material domain for the target (2D vs 3D, URP vs HDRP, Surface vs Post Process).
|
|
242
|
+
- [ ] Work placed in the right stage: linear math per-vertex via `varying`, exact math per-pixel.
|
|
243
|
+
- [ ] Colors authored in the correct space (`source_color` / sRGB handling); normals normalized and unpacked.
|
|
244
|
+
- [ ] Uniforms/parameters exposed and driven from code or an animation track — not hard-coded.
|
|
245
|
+
- [ ] Performance sanity: overdraw, sample count, and branching considered; mobile precision set if targeted.
|
|
246
|
+
- [ ] Post-process uses the engine's supported full-screen path (not a retired Built-in-RP mechanism).
|
|
247
|
+
|
|
248
|
+
## References
|
|
249
|
+
|
|
250
|
+
- `references/godot-shading-language.md` — shader types, built-ins per type, render_modes, `varying`, screen/depth reads, ShaderMaterial from code.
|
|
251
|
+
- `references/unity-and-unreal-shaders.md` — Unity URP HLSL pass + Shader Graph mapping; Unreal domains, Custom node HLSL, Material Instances.
|
|
252
|
+
- `references/effect-recipes.md` — dissolve, rim/outline, toon/cel, water/flow, force field, hologram — full code per engine.
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
# Eval harness — `gamedev-shaders` skill
|
|
2
|
+
|
|
3
|
+
These cases are run by the rsc skill-eval harness (a Claude agent with the full catalog loaded),
|
|
4
|
+
or read manually. They assert two things: **triggering** — the description fires on shader /
|
|
5
|
+
material / VFX / post-process / "how do I make X effect" prompts (including Spanish and
|
|
6
|
+
symptom-only phrasings like "slow on mobile") and stays quiet on near-misses, routing each to the
|
|
7
|
+
right sibling (`godot`/`unity`/`unreal` for gameplay-or-setup, `gamedev-physics` for simulation,
|
|
8
|
+
`gamedev-shipping` for variant stripping, `sql` for the false-friend "optimize"); and
|
|
9
|
+
**capability** — that with `SKILL.md` and its references loaded, the generated Godot 4 dissolve
|
|
10
|
+
shader satisfies the rubric (valid `shader_type`, `discard` against an animatable threshold, an
|
|
11
|
+
emissive `smoothstep` edge, `source_color` hints, no removed `SCREEN_TEXTURE`/`hint_color` APIs,
|
|
12
|
+
code-driven animation, and an overdraw note). Run 3–5 trials per prompt since routing is
|
|
13
|
+
non-deterministic; a prompt passes on a majority. No network needed — the capability rubric is
|
|
14
|
+
judged by reading the output against the points.
|