Fix uninitialized UVs, missing CUDA_CHECK in cleanup, face-skip warning, and unused alias#24
Merged
pmudry merged 2 commits intoTexture-and-MTL-supportfrom Mar 17, 2026
Merged
Conversation
Merged
…, unused var) Co-authored-by: pmudry <[email protected]>
Copilot
AI
changed the title
[WIP] Add texture and MTL support for OBJ meshes
Fix uninitialized UVs, missing CUDA_CHECK in cleanup, face-skip warning, and unused alias
Mar 17, 2026
Docs out of sync?This PR changes 3 source file(s) but no pages under If this is a significant change (new feature, new CLI flag, new material/geometry type, performance improvement), please update the relevant documentation page. See the mapping in If this change genuinely doesn't affect the docs, you can ignore this message. |
pmudry
approved these changes
Mar 17, 2026
pmudry
added a commit
that referenced
this pull request
Mar 17, 2026
* Milestone explorer script for documentation
* Add MTL material loading and diffuse texture support for OBJ meshes
- MTL loader (mtl_loader.hpp): parse Kd/Ke/Ns/Ni/d/map_Kd, heuristic material
type assignment (LAMBERTIAN/ROUGH_MIRROR/GLASS/LIGHT/MIRROR)
- Texture loader (texture_loader.cc): stb_image-based RGBA loader, dedup by path
- OBJ loader rewrite: parse mtllib/usemtl, UV indices; calls appropriate
addTriangle variant (normals+UVs / UVs only / normals / plain)
- scene_description.hpp: TextureDesc struct, textures vector, addTexture(),
addTriangleWithUVs(), addTriangleWithNormalsAndUVs(), UV fields on triangle
- yaml_scene_loader: material: now optional for OBJ entries (fallback -1);
texture: key in material definitions
- CUDA backend: UV interpolation in hit_triangle(), tex2D sampling in
apply_material(), cudaTextureObject upload/cleanup in scene_builder_cuda.cu
- OptiX backend: UV via intersection attributes (numAttributeValues 5),
texture sampling in __closesthit__ch, d_textures in launch params + cleanup
- CMakeLists: fix OptiX source ordering race (target_sources after find_path);
add texture_loader.cc to SOURCE_RAYON
- Assets: scripts/generate_grid_texture.py, scripts/generate_uv_models.py,
resources/textures/grid_512.png, resources/models/{plane,cube,sphere}_uv.obj,
resources/models/texture_test.mtl, resources/scenes/texture_test.yaml
* Updating things to do and .gitignore
* perf: fix BVH not activating in texture_test scene (20x CUDA speedup)
The YAML parser only recognizes 'camera:' and 'settings:' as top-level section
headers. texture_test.yaml nested its settings under 'scene:' (unrecognized),
so the 'use_bvh: true' key was stored as 'camera.use_bvh', never matching
'settings.use_bvh'. BVH was disabled, causing a linear O(4053) triangle scan
per ray instead of O(log n) BVH traversal.
Fixes:
- texture_test.yaml: use top-level 'camera:' and 'settings:' sections
- yaml_scene_loader.cc: also accept 'scene.use_bvh' as a legacy alias
Result: 1.9M -> 38M rays/sec (20x speedup, 85% of the non-textured baseline)
* - Reimplemented fibonacci dots and displaced sphere in OptiX
- Larger grid textures generation script
- Update to Suzanne model
* New test object from Sketchfab, CC0, https://sketchfab.com/pooyast/collections/shader-258e0160e20c4c80967e43cfa1141671
* Render sphere CCA information
* Working on textures projections
* Potential fix for pull request finding
Hard-coded paths correction
Co-authored-by: Copilot Autofix powered by AI <[email protected]>
* Updating TODOS.md in favor of git issues
* fix: address PR review comments
- Add missing <cmath>/<cctype> headers in mtl_loader.hpp; use std::tolower safely
- Resolve texture paths relative to YAML scene_dir in yaml_scene_loader.cc
- Fix comment/code order mismatch in cuda_raytracer.cuh (texture overwrites pattern)
- Fix cudaArray_t GPU memory leaks in optix_renderer.cu (rebuild + cleanup paths)
- Fix cudaArray_t GPU memory leaks in scene_builder_cuda.cu (freeGPUScene)
- Fix mtl_dir resolved from mtl file path, not OBJ dir in obj_loader.hpp
- Fix OBJ visible flag applied to whole triangle range, not just last triangle
- Document 'stripes' pattern in SCENE_FORMAT.md"
* fix: address PR reviews comments
* Potential fix for pull request finding
Co-authored-by: Copilot Autofix powered by AI <[email protected]>
* Fix uninitialized UVs, missing CUDA_CHECK in cleanup, face-skip warning, and unused alias (#24)
* Initial plan
* fix: address unresolved review comments (UV init, CUDA_CHECK, warning, unused var)
Co-authored-by: pmudry <[email protected]>
---------
Co-authored-by: copilot-swe-agent[bot] <[email protected]>
Co-authored-by: pmudry <[email protected]>
---------
Co-authored-by: Copilot Autofix powered by AI <[email protected]>
Co-authored-by: Copilot <[email protected]>
Co-authored-by: pmudry <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Five unresolved review issues from the texture/MTL PR, all in the GPU scene build and OBJ loading paths.
Changes
scene_description.hpp—addTriangle()andaddTriangleWithNormals()sethas_uvs = falsebut leftuv0/uv1/uv2uninitialized. Now explicitly zero-initialized toVec3(0,0,0).scene_builder_cuda.cu—convertGeometry()— UVs were unconditionally copied fromGeometryDesceven whenhas_uvs = false, reading uninitialized memory into GPU buffers. Now guarded:scene_builder_cuda.cu—freeGPUScene()— Bare CUDA calls in the texture teardown path (cudaMemcpy,cudaGetTextureObjectResourceDesc,cudaDestroyTextureObject,cudaFreeArray,cudaFree) were not error-checked. All wrapped withCUDA_CHECKfor consistency.obj_loader.hpp— Faces encountered before anyusemtl(with no fallback) were silently skipped despite the docstring claiming a warning was emitted. Added a per-callface_skip_warnedflag that emits onestd::cerrdiagnostic perloadOBJ()invocation, and updated the docstring to match.generate_uv_models.py—N = normal = (0, 1, 0)leftnormalunused (Nwas the actual use site). Simplified tonormal = (0, 1, 0)with the one use site updated accordingly.📱 Kick off Copilot coding agent tasks wherever you are with GitHub Mobile, available on iOS and Android.