Show only the part of a marked character that is hidden behind a building, as a filled highlight silhouette (Overwatch-style). Visible parts render normally. - Shader: xray_mesh.frag samples G-buffer hardware depth (binding 7) and compares it against its own fragment depth: occluded (behind) pixels emit the highlight, visible pixels discard. Drawn as a second pass over the scene with depth test/write off + alpha blend. - RenderSystem3D: MeshRenderer gains xrayShader + xrayHighlight. X-ray targets are skipped in the G-buffer (their pixels record occluder depth), then redrawn with the X-ray shader; scene depth is bound via Graphics::setMesh3DSceneDepth. - Graphics: new setMesh3DSceneDepth + Shader::setXray. Vulkan adds binding 7 to the mesh3d set layout and a dedicated X-ray pipeline variant. - WebGPU: new newMeshShaderFromWgsl (WGSL custom mesh shaders), scene-depth binding 9, X-ray pipeline variant, xray params packed into the Frame UBO, and the G-buffer hardware depth is exposed/sampleable (getHwDepthTexture). AO (SPIR-V) is skipped on WebGPU via supportsGBufferPost. - stylize: 'xray' style registered (createMeshShader dispatches SPIR-V on Vulkan / WGSL on WebGPU) with push-constant params. - Tests: test/Xray.cpp (shader/flags + occluded-silhouette render smoke).
74 lines
2.3 KiB
Python
74 lines
2.3 KiB
Python
#!/usr/bin/env python3
|
|
"""Compile stylize GLSL fragments to SPIR-V C++ include arrays."""
|
|
|
|
from __future__ import annotations
|
|
|
|
import struct
|
|
import subprocess
|
|
import sys
|
|
from pathlib import Path
|
|
|
|
ROOT = Path(__file__).resolve().parents[1]
|
|
SHADER_DIR = ROOT / "src" / "modules" / "stylize" / "shaders"
|
|
|
|
FRAGS = [
|
|
"cartoon_post.frag",
|
|
"watercolor_post.frag",
|
|
"ink_post.frag",
|
|
"pixel_post.frag",
|
|
"ink_mesh.frag",
|
|
"xray_mesh.frag",
|
|
]
|
|
|
|
|
|
def spv_to_inc(spv_path: Path, array_name: str, out_path: Path) -> None:
|
|
data = spv_path.read_bytes()
|
|
if len(data) % 4 != 0:
|
|
raise SystemExit(f"SPIR-V size not multiple of 4: {spv_path}")
|
|
words = struct.unpack(f"<{len(data) // 4}I", data)
|
|
if not words or words[0] != 0x07230203:
|
|
raise SystemExit(f"bad SPIR-V magic in {spv_path}")
|
|
lines = [f"static const uint32_t {array_name}[] = {{"]
|
|
row: list[str] = []
|
|
for i, w in enumerate(words):
|
|
row.append(f"0x{w:08x}")
|
|
if len(row) == 8:
|
|
lines.append(" " + ", ".join(row) + ",")
|
|
row = []
|
|
if row:
|
|
lines.append(" " + ", ".join(row) + ",")
|
|
lines.append("};")
|
|
lines.append(f"static const size_t {array_name}_count = {len(words)};")
|
|
lines.append("")
|
|
out_path.write_text("\n".join(lines), encoding="utf-8")
|
|
print(f"wrote {out_path.relative_to(ROOT)} ({len(words)} words)")
|
|
|
|
|
|
def compile_frag(src: Path) -> Path:
|
|
out = src.with_suffix(".spv")
|
|
cmd = ["glslc", "-fshader-stage=frag", str(src), "-o", str(out)]
|
|
r = subprocess.run(cmd, capture_output=True, text=True)
|
|
if r.returncode != 0:
|
|
raise SystemExit(f"glslc failed for {src.name}:\n{r.stderr or r.stdout}")
|
|
return out
|
|
|
|
|
|
def main() -> int:
|
|
if not SHADER_DIR.is_dir():
|
|
raise SystemExit(f"missing shader dir: {SHADER_DIR}")
|
|
for name in FRAGS:
|
|
src = SHADER_DIR / name
|
|
if not src.is_file():
|
|
raise SystemExit(f"missing {src}")
|
|
spv = compile_frag(src)
|
|
stem = src.stem # e.g. cartoon_post
|
|
array = f"{stem}_frag_spv"
|
|
spv_to_inc(spv, array, SHADER_DIR / f"{stem}_frag_spv.inc")
|
|
spv.unlink(missing_ok=True)
|
|
# Mesh ink reuses mesh3d_toon.vert SPIR-V from graphics; no vert compile here.
|
|
return 0
|
|
|
|
|
|
if __name__ == "__main__":
|
|
sys.exit(main())
|