Skip to content

Add KHR_materials_volume export support#8278

Merged
willeastcott merged 1 commit intomainfrom
gltf-exp-vol
Dec 19, 2025
Merged

Add KHR_materials_volume export support#8278
willeastcott merged 1 commit intomainfrom
gltf-exp-vol

Conversation

@willeastcott
Copy link
Contributor

@willeastcott willeastcott commented Dec 19, 2025

This PR adds export support for the KHR_materials_volume glTF extension to the GltfExporter.

Changes

GltfExporter (src/extras/exporters/gltf-exporter.js)

  • Export KHR_materials_volume extension when volume properties are set:
    • thicknessFactor from material.thickness (if not 0)
    • thicknessTexture from material.thicknessMap
    • attenuationDistance from material.attenuationDistance (if not 0)
    • attenuationColor from material.attenuation (linear converted, if not white)
  • Only exported when material.useDynamicRefraction is true (matching parser behavior)
  • Added thicknessMap to texture semantics for proper texture collection

glTF Extension Reference

The KHR_materials_volume extension adds volumetric properties to materials. Combined with KHR_materials_transmission, it enables realistic rendering of glass, liquids, and other refractive materials with proper light absorption and scattering.

Example Output

{
  "extensions": {
    "KHR_materials_volume": {
      "thicknessFactor": 0.5,
      "attenuationDistance": 1.0,
      "attenuationColor": [0.9, 0.95, 1.0]
    }
  }
}

Notes

  • The parser sets blendType = BLEND_NORMAL when loading volume materials
  • Works in conjunction with KHR_materials_transmission and KHR_materials_ior

Checklist

  • I have read the contributing guidelines
  • My code follows the project's coding standards
  • This PR focuses on a single change

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR adds export support for the KHR_materials_volume glTF extension, enabling volumetric properties like thickness and light attenuation to be exported from materials. The implementation mirrors the existing parser functionality and follows established patterns for other material extensions.

  • Exports volume extension when useDynamicRefraction is enabled and volume properties are set
  • Handles thicknessFactor, thicknessTexture, attenuationDistance, and attenuationColor properties
  • Adds thicknessMap to the list of supported texture semantics for proper texture collection

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

@willeastcott willeastcott merged commit 06606f5 into main Dec 19, 2025
13 checks passed
@willeastcott willeastcott deleted the gltf-exp-vol branch December 19, 2025 13:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement Request for a new feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants