Skip to content

PBR extension: anisotropy - #32

Open
alemuntoni wants to merge 29 commits into
cnr-isti-vclab:mainfrom
dlupo2:pbr-ext-anisotropy
Open

PBR extension: anisotropy#32
alemuntoni wants to merge 29 commits into
cnr-isti-vclab:mainfrom
dlupo2:pbr-ext-anisotropy

Conversation

@alemuntoni

@alemuntoni alemuntoni commented Mar 12, 2026

Copy link
Copy Markdown
Member

TODO:

  • fix mipmap creation for normal texture images (assigned to @malomo)
    use floats instead of uint8 per channel, trough bimg functions
  • check commit 6c2f4ce

@alemuntoni

Copy link
Copy Markdown
Member Author

test: ANISOTROPY_ROTATION_TEST in 950-pbr

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds initial support for the glTF KHR_materials_anisotropy extension across the asset pipeline (glTF import → material/uniform plumbing → PBR shader evaluation) and provides new sample assets to validate anisotropy strength/rotation/texture behavior.

Changes:

  • Implement anisotropic GGX specular + reflection “bent normal” path in the PBR shader, and plumb anisotropy strength/rotation + anisotropy texture through uniforms.
  • Extend material/texture typing to include an anisotropy texture and serialize/deserialize anisotropy parameters.
  • Update texture-stage/sampler layout and add new glTF examples/assets for anisotropy testing.

Reviewed changes

Copilot reviewed 12 out of 23 changed files in this pull request and generated 10 comments.

Show a summary per file
File Description
vclib/render/shaders/vclib/bgfx/pbr_common.sh Adds anisotropic GGX functions and threads anisotropy parameters into pbrColorLights; also changes default light settings.
vclib/render/shaders/vclib/bgfx/drawable/uniforms/material_uniforms.sh Adds u_anisotropyPack uniform macros for strength/rotation.
vclib/render/shaders/vclib/bgfx/drawable/uniforms/drawable_mesh_texture_uniforms.sh Adds anisotropy texture sampling helpers and shifts BRDF LUT to stage position 6.
vclib/render/shaders/vclib/bgfx/drawable/drawable_mesh/surface/fs_surface_uber_pbr.sc Computes anisotropy tangent frame + reflection bending; passes anisotropy data into pbrColorLights.
vclib/render/include/vclib/bgfx/drawable/uniforms/material_uniforms.h Adds/binds the anisotropy uniform pack on the C++ side.
vclib/render/include/vclib/bgfx/drawable/uniforms/drawable_mesh_uniforms.h Adds ANISOTROPY texture type to the packed-stage enum.
vclib/render/include/vclib/bgfx/drawable/drawable_environment.h Changes BRDF LUT sampler uniform from s_tex5s_tex6.
vclib/core/include/vclib/space/core/material.h Adds anisotropy parameters and anisotropy texture type + serialization support.
vclib/core/include/vclib/io/mesh/gltf/detail/load_mesh.h Loads KHR_materials_anisotropy extension values/texture into Material.
examples/render/950-pbr/main.cpp Adds anisotropy-related sample selections and prints anisotropy material info.
assets/example_meshes/gltf/CarbonFibre/CarbonFibre_occlusion.png New sample texture (CarbonFibre).
assets/example_meshes/gltf/CarbonFibre/CarbonFibre_anisotropy.png New sample anisotropy texture (CarbonFibre).
assets/example_meshes/gltf/CarbonFibre/CarbonFibre.gltf New CarbonFibre glTF sample using KHR_materials_anisotropy.
assets/example_meshes/gltf/AnisotropyRotationTest/Heights_1d_Normals_v2.png New anisotropy rotation test texture.
assets/example_meshes/gltf/AnisotropyRotationTest/GridWithMarkers.png New anisotropy rotation test texture.
assets/example_meshes/gltf/AnisotropyRotationTest/AnisotropyRotationTest.gltf New anisotropy rotation test scene using KHR_materials_anisotropy.
assets/example_meshes/gltf/AnisotropyRotationTest/AnisoRotation30_Linear.png New anisotropy rotation test texture.
assets/example_meshes/gltf/AnisotropyRotationTest/AnisoRotation10_Linear.png New anisotropy rotation test texture.
assets/example_meshes/gltf/AnisotropyRotationTest/AnisoDonutLabels.png New anisotropy rotation test texture.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review. Take the survey.

Comment thread vclib/render/shaders/vclib/bgfx/pbr_common.sh Outdated
Comment thread vclib/render/shaders/vclib/bgfx/pbr_common.sh Outdated
Comment thread vclib/render/shaders/vclib/bgfx/pbr_common.sh Outdated
Comment thread vclib/core/include/vclib/io/mesh/gltf/detail/load_mesh.h
Comment thread vclib/render/shaders/vclib/bgfx/pbr_common.sh Outdated
Comment thread vclib/core/include/vclib/space/core/material.h Outdated
Comment thread vclib/render/include/vclib/bgfx/drawable/drawable_environment.h Outdated
@alemuntoni alemuntoni mentioned this pull request Mar 23, 2026
1 task
alemuntoni and others added 3 commits March 25, 2026 15:52
# Conflicts:
#	vclib/render/shaders/vclib/bgfx/drawable/uniforms/drawable_mesh_texture_uniforms.sh
#	vclib/render/shaders/vclib/bgfx/drawable/uniforms/material_uniforms.sh
Comment thread vclib/render/include/vclib/bgfx/drawable/drawable_environment.h
@alemuntoni

Copy link
Copy Markdown
Member Author

Fixed mipmap downsampling for normal maps (commit 6c2f4ce):

Normal Map Downsampling Fixes

  • Custom Downsampling Logic: Extracted the normal map downsampling routine into a dedicated lambda (downsampleNormalMap2x2) outside of setTexture to improve readability and isolation of logic.
  • Correct Vector Math: Instead of relying on standard image downsampling (which shortens normal vectors by linear interpolation), the new logic fetches the 4 adjacent pixels, remaps their RGB channels from [0, 255] to [-1.0, 1.0], averages them, and then explicitly normalizes the resulting vector. This ensures normal maps maintain unit length across all mip levels, preventing shading artifacts in PBR anisotropy.
  • Alpha Channel Preservation: The custom lambda correctly applies standard bilinear interpolation to the alpha channel. This fixes a major issue where bimg's normal map downsample function would discard or corrupt the alpha channel entirely.
  • Integration: Updated the setTexture lambda signature to accept an isNormalMap boolean flag. At invocation, it checks if textureType == Material::TextureType::NORMAL to seamlessly route the data to either the custom normal map downsampler or the standard bimg::imageRgba8Downsample2x2 for color/data textures.

# Conflicts:
#	vclib/render/include/vclib/bgfx/drawable/uniforms/material_uniforms.h
#	vclib/render/shaders/vclib/bgfx/drawable/drawable_mesh/material_uniforms.sh
#	vclib/render/shaders/vclib/bgfx/drawable/drawable_mesh/surface_pbr/fs_surface_pbr.sc
#	vclib/render/shaders/vclib/bgfx/drawable/drawable_mesh/texture_uniforms.sh
#	vclib/render/shaders/vclib/bgfx/pbr_common.sh
# Conflicts:
#	tests/render/006-mesh-pbr-headless/main.cpp
#	vclib/render/include/vclib/bgfx/drawable/uniforms/material_uniforms.h
# Conflicts:
#	vclib/render/include/vclib/bgfx/drawable/mesh/mesh_render_buffers.h
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants