KhronosGroup / glTF

glTF – Runtime 3D Asset Delivery
Other
7.12k stars 1.13k forks source link

Texture swizzling support #1125

Closed Themaister closed 5 years ago

Themaister commented 6 years ago

Especially PBR metallic roughness has a particular swizzling scheme. It would be desirable to have a way to specify the texture swizzle for images which are loaded. Especially for compressed GPU formats, it might not be possible to efficiently represent PBR textures with G/B swizzle, and R/G two-component formats might be more suitable. Also, single-component compressed textures could be used to represent roughness, while swizzling in 0 or 1 for metallic.

GL maps this to GL_TEXTURE_SWIZZLE_RGBA, and Vulkan maps this in with VkImageView.

I could see an interface looking something like:

"textures": [
  { "sampler": 0, "sources": 0, "swizzle": [ "green", "blue", "red", "one" ] },
]

Alternatives are placing the swizzle along-side the "source", which means that a texture can only have one swizzle scheme, or as part of the "sampler", which matches more closely to how swizzling works in GL, but would be rather awkward for other APIs.

lexaknyazev commented 6 years ago

We've considered arbitrary texture channel mapping, but it didn't make to the core spec. One of the main obstacles is the lack of native swizzling support in some APIs (e.g. see rationale in WebGL 2.0 spec).

It's still possible to make a glTF extension with such functionality.

/cc @sbtron @bghgary

Themaister commented 6 years ago

It is also not supported on GLES2 to my knowledge, so a KHR extension probably makes more sense.

lexaknyazev commented 5 years ago

In the short term, swizzling will be partly achievable via KTX2 file format metadata (glTF schema TBD).