From c98286860885d1f025cd8cf9da699f174118ccba Mon Sep 17 00:00:00 2001 From: skal Date: Sat, 14 Feb 2026 19:21:05 +0100 Subject: feat(gpu): add two-pass raymarching infrastructure MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add RayMarchResult struct and functions for deferred SDF rendering: - rayMarchWithID() tracks object ID and distance_max - reconstructPosition(), normalWithID(), shadowWithStoredDistance() - Pass 1: store geometry data, Pass 2: reuse for shading Add WGSL style rule: prefer return values over pointers for small structs (≤16 bytes). Co-Authored-By: Claude Sonnet 4.5 --- doc/CODING_STYLE.md | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'doc') diff --git a/doc/CODING_STYLE.md b/doc/CODING_STYLE.md index 533cffb..5c86409 100644 --- a/doc/CODING_STYLE.md +++ b/doc/CODING_STYLE.md @@ -107,3 +107,30 @@ One-line comment for non-obvious functions. ``` Three-line header for all source files. + +--- + +## WGSL Shader Style + +### Return vs Pointer Parameters + +**Rule:** Prefer return values over pointer parameters for small structs (≤16 bytes). + +```wgsl +// Correct - return value (12 bytes: 3×f32) +fn rayMarchWithID(ro: vec3, rd: vec3, init: RayMarchResult) -> RayMarchResult { + var result = init; + // ... modify result + return result; +} + +// Wrong - pointer parameter (unnecessary complexity) +fn rayMarchWithID(ro: vec3, rd: vec3, result: ptr) { + // ... modify *result +} +``` + +**Rationale:** +- Small structs (≤16 bytes) are efficiently handled by GPU return value optimization +- Functional style is clearer and less error-prone +- `ptr` adds complexity with no performance gain for small types -- cgit v1.2.3