summaryrefslogtreecommitdiff
path: root/cnn_v3
AgeCommit message (Collapse)Author
22 hoursfeat(cnn_v3): shadow→dif migration complete (ch18)skal
Replace raw shadow (ch18) with dif = max(0,dot(normal,KEY_LIGHT))*shadow across all layers. Channel count stays 20, weight shapes unchanged. - gbuf_pack.wgsl: t1.z = pack4x8unorm(mip2.g, mip2.b, dif, transp); t1.w = 0u - gbuf_deferred.wgsl: read dif from unpack4x8unorm(t1.z).z - gbuf_view.wgsl: revert to 4×5 grid, ch18=dif label, ch19=trns label - tools/shaders.js: FULL_PACK_SHADER adds oct_decode + computes dif - cnn_v3_utils.py: assemble_features() computes dif on-the-fly via oct_decode - docs: CNN_V3.md, HOWTO.md, HOW_TO_CNN.md, GBUF_DIF_MIGRATION.md updated handoff(Gemini): shadow→dif migration done, ready for first training pass
22 hourswip(cnn_v3): shadow→dif intermediate + scene tweaks + migration planskal
- gbuf_shadow.wgsl: normal bias 0.05→0.02 - gbuf_pack.wgsl: compute dif=diffuse*shadow, drop shadow from t1.z, store dif in t1.w (INTERMEDIATE — incorrect packing, see migration plan) - gbuf_deferred.wgsl: read dif from t1.w.x (matches intermediate packing) - gbuf_view.wgsl: expand to 4×6 grid, show dif.r/g/b in row 5 (INTERMEDIATE — to be reverted to 4×5 with ch18=dif) - gbuffer_effect.cc: add small hovering sphere (r=0.6) above scene; swap cube/sphere positions; both spheres pulsate - docs/GBUF_DIF_MIGRATION.md: full migration plan with checklist handoff(Claude): intermediate commit — GBUF_DIF_MIGRATION.md §Current State describes what is wrong and the full implementation checklist (5 steps).
22 hoursrefactor(cnn_v3): simplify sphere SDF in shadow pass, remove per-frame allocskal
gbuf_shadow.wgsl — dfWithID(): - Sphere: replace inv_model local-space transform with direct world-space formula (length(p - center) - radius). Exact, no matrix multiply, no floating-point error from matrix inversion that can corrupt soft-shadow penumbra over 64 march steps. - lp/scale now computed only inside the cases that need them (box/torus/plane) instead of eagerly for every object. gbuffer_effect.cc — upload_scene_data(): - Replace per-frame std::vector<GBufObjectData> heap allocation with a file-static staging buffer s_obj_staging[256]: zero alloc per frame. handoff(Gemini): sphere SDF now exact; shadow march should be cleaner.
23 hoursfix(cnn_v3): shadow pass — 5 bugs fixed, labels in gbuf_viewskal
1. Camera Y-inversion: proj.m[5] = -proj.m[5] in upload_scene_data + WGPUFrontFace_CCW on raster pipeline. 2. Shadow formula: replace shadowWithStoredDistance with 64-step IQ soft shadow (8*d/t, unbounded). 3. Local→world SDF scale: d *= length(obj.model[0].xyz). 4. Shadow bias: use rasterized normal from normal_mat_tex (binding 4) instead of light direction — fixes terminator self-shadow on spheres. 5. ShaderComposer: GBufViewEffect now resolves #include via ShaderComposer::Get().Compose(). Also: per-tile channel labels in gbuf_view.wgsl via debug_str. Scene simplified to 1 cube + 1 sphere for debugging (restore TODO). Scale propagation for pulsating sphere confirmed correct end-to-end. handoff(Gemini): shadow validated. Next: restore full scene in GBufferEffect::set_scene() (20 cubes + 4 spheres, 2 lights), then run training pass per cnn_v3/docs/HOWTO.md §3.
26 hoursdocs+feat(cnn_v3): compact context, re-enable shadow in GBufDeferredEffectskal
- TODO/PROJECT_CONTEXT updated to reflect operational pipeline state - GBufDeferredEffect: shadow re-enabled (albedo * (ambient + diffuse * shadow)) feat_tex1 binding restored for shadow channel debugging handoff(Gemini): shadow pass live again — investigate why shadow looks broken.
26 hoursfeat(shaders): add ray_sphere snippet, use in gbuf_raster impostorskal
26 hoursfix(cnn_v3): frontFace_CW for raster pipeline + sphere impostor in gbuf_rasterskal
- Missing WGPUFrontFace_CW (Y-flipped perspective) caused back faces to render instead of front faces → cubes appeared inside-out. - Sphere objects now use ray-sphere impostor in fs_main: correct silhouette, smooth normal from hit point, and reprojected clip-space depth.
26 hoursfix(cnn_v3): resolve #include via ShaderComposer in GBufDeferredEffectskal
Raw WGSL was sent to WebGPU without resolving the math/normal include. Also removed unused feat_tex1 binding (shadow dropped for now).
26 hoursfix(cnn_v3): deferred render — diffuse only, drop broken shadowskal
26 hoursfix(cnn_v3): use model matrix for normal transform in gbuf_rasterskal
inv_model applies the inverse rotation → normals pointing inward. model matrix is correct for uniform-scale objects (matches rotating_cube.wgsl).
26 hoursrefactor(shaders): extract oct-normal encode/decode into math/normal snippetskal
New src/shaders/math/normal.wgsl: oct_encode, oct_decode, oct_encode_unorm, oct_decode_unorm. Registered in InitShaderComposer as "math/normal". Removed inline copies from gbuf_raster.wgsl and gbuf_pack.wgsl. 18/18 tests passing.
26 hoursfeat(cnn_v3): GBufDeferredEffect — simple deferred render (albedo * shadow)skal
New effect unpacks feat_tex0/feat_tex1 and outputs albedo * shadow. Replaces CNNv3Effect in cnn_v3_test sequence until training is complete. 37/37 tests passing. handoff(Gemini): GBufDeferredEffect wired in timeline; CNN v3 pipeline: GBufferEffect → GBufDeferredEffect → sink.
26 hoursfix(cnn_v3): call set_scene() in constructor + orbiting cameraskal
- GBufferEffect::render() was a no-op (scene_ready_=false) because set_scene() was never called from the timeline sequence constructor. Fixed by calling set_scene() at the end of the constructor. - Camera now orbits the scene at 0.3 rad/s (R=6, y=2.5). handoff(Gemini): cnn_v3_test sequence now renders G-buffer + GBufViewEffect with animated orbiting camera.
27 hoursrefactor(cnn_v3): GBufferEffect cleanupskal
Remove dead code and reduce duplication: - drop create_bilinear_sampler() (never called) - drop update_pack_bind_group() stub and pack_bind_group_ member - drop node_feat0_/node_feat1_; use output_nodes_[0/1] directly - Compose({}, src) consistently for all three pipelines - extract clear_r8_node() helper to replace two identical 10-line blocks No behavior change. 36/36 tests pass.
27 hoursfeat(cnn_v3): Phase 4 — type-aware SDF in shadow passskal
dfWithID() in gbuf_shadow.wgsl now branches on obj.params.x (ObjectType) instead of using sdBox for everything: 0=CUBE → sdBox(lp, vec3(1)) 1=SPHERE → sdSphere(lp, 1.0) 2=PLANE → sdPlane(lp, vec3(0,1,0), obj.params.y) 3=TORUS → sdTorus(lp, vec2(0.8, 0.2)) 36/36 tests pass.
27 hoursfeat(cnn_v3): GBufferEffect Pass 2 — SDF shadow raymarchingskal
Implements gbuf_shadow.wgsl: fullscreen render pass that reads depth from Pass 1, reconstructs world-space positions, evaluates a proxy-box SDF for each object (via inv_model), computes soft shadows for both directional lights using shadowWithStoredDistance(), and writes shadow factor to the RGBA8Unorm node_shadow_ target consumed by gbuf_pack.wgsl. Bind layout: B0=GlobalUniforms, B1=ObjectsBuffer (storage-read), B2=texture_depth_2d, B3=GBufLightsUniforms. Sky fragments (depth=1.0) are output as 1.0 (fully lit). Falls back to clear(1.0) if pipeline is not ready. 36/36 tests pass. handoff(Gemini): Pass 2 done. Pass 3 (transparency) still TODO. Phase 4 (type-aware SDF) optional after visual validation.
27 hoursfeat(cnn_v3): GBufferEffect internal scene + GBufViewEffect debug wiringskal
GBufferEffect: - set_scene() now owns Scene/Camera internally; no external pointers needed - 20 randomly rotating cubes (xorshift32 seed, axis-angle animation) - 4 pumping spheres (radius = base_r * (1 + audio_intensity * 0.8)) - Camera at (0,2.5,6) looking at origin; aspect updated per-frame - GBufLightsUniforms: 2 directional lights (warm key + cool fill) - object_type written to ObjectData.params.x (ready for SDF shadow) - shadow/transp nodes cleared via zero-draw render passes (placeholder) - bilinear sampler cached via create_linear_sampler() / sampler_.get() - dead placeholder textures removed GBufViewEffect: - gbuf_view.wgsl: all channels now fully grayscale (removed color tint) - seq_compiler.py: GBufViewEffect added to CLASS_TO_HEADER - timeline.seq: cnn_v3_test uses GBufViewEffect -> sink for debug view Docs: HOWTO.md §1 updated with set_scene() description + §1b implementation plan for Pass 2 SDF shadow (shader spec, bind layout, C++ additions) handoff(Gemini): GBufferEffect has internal scene, 36/36 tests green. Next: implement Pass 2 shadow (gbuf_shadow.wgsl) per §1b plan in HOWTO.md.
28 hoursadd full datasetskal
29 hoursfeat(cnn_v3/tools): zoom canvas shows region around clicked texelskal
30 hoursfix(cnn_v3/tools): don't destroy feat textures after runFromFeat (breaks viz)skal
30 hoursfix(cnn_v3/tools): refresh zoom canvas when new sample is loadedskal
30 hoursfix(cnn_v3/tools): zoom canvas fits remaining panel space (both axes, rAF ↵skal
measure)
30 hoursfix(cnn_v3/tools): fit zoom canvas to panel width by scaling canvas attributesskal
30 hoursfix(cnn_v3/tools): zoom channel via WebGPU re-render + fill panel widthskal
30 hoursfeat(cnn_v3/tools): click vignette to show enlarged channel below gridskal
30 hoursfix(cnn_v3/tools): remove unused sampler binding from FULL_PACK_SHADERskal
WebGPU auto-reflects the BGL from the shader; a declared-but-unused sampler binding is omitted from the layout, causing CreateBindGroup to reject it. Removed binding 6 (sampler) entirely — all reads use textureLoad(). Renumbered f0/f1 from 7/8 to 6/7 to match.
30 hoursfeat(cnn_v3): add G-buffer visualizer + web sample loader (Phase 7)skal
C++ GBufViewEffect: renders all 20 feature channels from feat_tex0/feat_tex1 in a 4×5 tiled grid. Custom BGL with WGPUTextureSampleType_Uint; bind group rebuilt per frame via wgpuRenderPipelineGetBindGroupLayout. Web tool: "Load sample directory" button — webkitdirectory picker, FULL_PACK_SHADER compute (matches gbuf_pack.wgsl packing), runFromFeat() skips photo-pack step, computePSNR() readback + comparison vs target.png side-by-side. 36/36 tests pass. Docs updated: HOWTO.md §9, README, PROJECT_CONTEXT, TODO, COMPLETED. handoff(Gemini): CNN v3 Phase 7 done. Next: run train_cnn_v3.py (see HOWTO §3).
33 hoursfix(cnn_v3/tools): fix getElementById illegal invocation + auto-preload weightsskal
- Bind document.getElementById in filmParams() to fix 'Illegal invocation' error - Add preload() that auto-fetches cnn_v3_weights.bin + cnn_v3_film_mlp.bin from workspaces/main/weights/ on init; skips silently if files not found - Add '↺ Reload from workspace weights/' button for manual re-fetch handoff(Gemini): cnn_v3 web tool fixed; serve from repo root via http.server
33 hoursfix(cnn_v3): fix texture format mismatches in cnn_v3_test sequenceskal
- seq_compiler: add gbuf_albedo/gbuf_rgba32uint to NODE_TYPES - timeline: declare gbuf_feat0/feat1 as gbuf_rgba32uint, route CNNv3Effect output through cnn_v3_out (gbuf_albedo) + Passthrough to sink (dec0 can't write directly to Rgba8Unorm sink) - cnn_v3_effect: fix update_bind_groups using .set() instead of .replace() causing FATAL assert on second frame - TODO: add CNN v3 "2D mode" (G-buffer-free) future task handoff(Gemini): CNNv3Effect now runs without crashes at --seek 48
33 hoursfeat(cnn_v3): wire trained weights into CNNv3Effect + add timeline test sequenceskal
- CNNv3Effect constructor loads ASSET_WEIGHTS_CNN_V3 via GetAsset on startup - seq_compiler.py: CLASS_TO_HEADER supports full #include paths for cnn_v3/ classes - timeline.seq: add cnn_v3_test sequence at 48s (GBufferEffect → CNNv3Effect) - test_cnn_v3_parity: zero_weights test now explicitly uploads zeros to override asset handoff(Gemini): CNNv3Effect ready; export weights to workspaces/main/weights/ and seek to 48s to test
34 hoursfeat(cnn_v3): add weight assets to assets.txt, update HOW_TO_CNN export docsskal
- Add WEIGHTS_CNN_V3 and WEIGHTS_CNN_V3_FILM_MLP to workspaces/main/assets.txt - Add opencv-python and pillow to export_cnn_v3_weights.py uv inline deps - Update HOW_TO_CNN.md §3 export target → workspaces/main/weights/ - Update HOW_TO_CNN.md §4 weight loading → SafeGetAsset (asset system) handoff(Gemini): cnn_v3 weight assets registered; export and C++ load path documented
34 hoursdocs(cnn_v3): add uv inline deps to export_cnn_v3_weights.pyskal
34 hoursfix sizeskal
https://colorifyai.art/photo-to-sketch/#playground with 'Ink Sketch' does a small zooming and resize
34 hoursfeat(cnn_v3): patch alignment search, resume, Ctrl-C saveskal
- --patch-search-window N: at dataset init, find per-patch (dx,dy) in [-N,N]² that minimises grayscale MSE between source albedo and target; result cached so __getitem__ pays only a list-lookup per sample. - --resume [CKPT]: restore model + Adam state from a checkpoint; omit path to auto-select the latest in --checkpoint-dir. - Ctrl-C (SIGINT) finishes the current batch, then saves a checkpoint before exiting; finally-block guarded so no spurious epoch-0 save. - Review: remove unused sd variable, lift patch_idx out of duplicate computation, move _LUMA to Constants block, update module docstring. handoff(Gemini): cnn_v3/training updated — no C++ or test changes.
34 hoursnormalize sample dimensionskal
35 hoursdocs(cnn_v3): add uv inline deps to train_cnn_v3.py + HOW_TO_CNN noteskal
handoff(Gemini): train_cnn_v3.py now has uv script metadata block (torch, torchvision, numpy, pillow, opencv-python). HOW_TO_CNN §2 Prerequisites updated with uv quick-start alternative.
35 hoursperf(cnn_v3): cache dataset images at init to avoid per-patch disk I/Oskal
handoff(Gemini): CNNv3Dataset now loads all samples once in __init__ into self._cache; __getitem__ reads from cache instead of reloading PNGs each call. Eliminates N×patches_per_image file loads per epoch.
35 hoursdocs(cnn_v3): add Windows 10 + CUDA training section to HOW_TO_CNN §2skal
35 hoursfix(cnn_v3): correct weight budget in docstring (3.9→5.4 KB f16)skal
36 hoursfix(cnn_v3): resize target to albedo dims when sizes differskal
target.png can have a different resolution than albedo.png in simple samples; patch slicing into the smaller target produced 0×0 tensors, crashing torch.stack in the DataLoader collate. handoff(Gemini): target resized in _load_sample (LANCZOS) + note in HOW_TO_CNN §1c.
36 hoursdocs(cnn_v3): add full Old House example to HOW_TO_CNN §1bskal
handoff(Gemini): added render + batch-pack example commands at end of section 1b
36 hoursfix(cnn_v3): native OPEN_EXR_MULTILAYER + quiet render + flexible channel namesskal
blender_export.py: - Replace broken compositor FileOutput approach with native OPEN_EXR_MULTILAYER render output; all enabled passes included automatically, no socket wiring needed - Suppress Fra:/Mem: render spam via os.dup2 fd redirect; per-frame progress printed to stderr via render_post handler pack_blender_sample.py: - get_pass_r: try .R/.X/.Y/.Z/'' suffixes + aliases param for Depth→Z fallback - combined_rgba loaded once via ("Combined","Image") loop; shared by transp+target - Remove unused sys import HOW_TO_CNN.md: update channel table to native EXR naming (Depth.Z, IndexOB.X, Shadow.X), fix example command, note Shadow defaults to 255 when absent handoff(Gemini): blender pipeline now produces correct multilayer EXR with all G-buffer passes; pack script handles native channel naming
36 hoursdocs(cnn_v3): blender4 alias + Blender 4.5 LTS requirement for training dataskal
37 hoursfix(blender_export): version detection + Blender 5.x warning + cleanupskal
- Use bpy.app.version for version detection instead of attribute sniffing - Blender 5.0.x: warn that per-pass compositor routing is broken (Combined only); compositing_node_group path kept ready for when Blender fixes this upstream - Remove all DEBUG prints and failed use_nodes=True experiment - configure_scene() returns only discard_dir (compositor always configured) - Move _SOCKET_ALIASES to module level; simplify slots/None fallback handoff(Gemini): blender_export.py stable for Blender 4.5 LTS; Blender 5.x path is forward-compatible but produces Combined-only output until upstream fix.
37 hoursfix(cnn_v3): blender_export Blender 5 compositor activation + document ↵skal
RenderLayer sockets - Activate compositor in Blender 5.0+ by relying on compositing_node_group assignment (no use_nodes needed, avoids deprecation warning) - Document full CompositorNodeRLayers output socket list for Blender 5.0.1 - Clean up SOCKET_ALIASES to match confirmed socket names
38 hoursfeat(cnn_v3): blender_export print pack_blender_sample.py batch command ↵skal
after render
38 hoursfix(cnn_v3): blender_export fallback socket name aliases for Shadow etc.skal
38 hoursfix(cnn_v3): blender_export discard dir next to --output, not in /tmpskal
38 hoursfix(cnn_v3): blender_export.py Blender 5 File Output node slots + file_nameskal
- Prefer file_output_items over file_slots; use explicit is-None checks so empty collections do not fall through to the legacy attribute. - Clear out_node.file_name so multilayer EXR frames are named 0001.exr instead of file_name0001.exr. handoff(Gemini): blender_export.py now produces frames/0001.exr on Blender 5.0.1.
38 hoursdocs(cnn_v3): clarify --output is a base dir, not a frame_### patternskal