-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Basis Universal and IBL with KTX2 images #1612
Changes from all commits
8ed0c8c
75408a0
aaac46b
3548da4
7840aad
4b466a6
74279e8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
# KHR_image_ktx2 | ||
|
||
## Contributors | ||
|
||
* Norbert Nopper, UX3D | ||
* Alexey Knyazev | ||
* Members of 3D Formats Working Group | ||
|
||
## Status | ||
|
||
Draft | ||
|
||
## Dependencies | ||
|
||
Written against the glTF 2.0 spec. | ||
|
||
## Overview | ||
|
||
This extension adds the ability to specify images using the [KTX2 file format](http://github.khronos.org/KTX-Specification/) (KTX2). An implementation of this extension can use the images provided in the KTX2 files as an alternative to the PNG or JPG images available in glTF 2.0. Furthermore, specifying images having advanced features such as mip map levels, cube map faces, or arrays is possible. | ||
|
||
When the extension is used, it's allowed to use value `image/ktx2` for the `image.mimeType` property. | ||
|
||
Optionally, a JSON form of the KTX2 header may be provided in the extension object, so implementations can check whether the image is compatible with the GPU and allocate memory before fetching the actual image data. Also, this allows immediately requesting needed parts (e.g., mip levels) of the KTX2 file by skipping the binary KTX2 header. | ||
|
||
Because of glTF compatibility requirements, the image cannot be used directly from any glTF core object, so additional extensions are required to use KTX2 images with glTF textures. The following example shows a complete glTF 2.0 asset containing only an uncompressed RGBA8 2D image with BGRA swizzling metadata and without precomputed mip levels. | ||
|
||
```json | ||
{ | ||
"asset": { | ||
"version": "2.0" | ||
}, | ||
"extensionsUsed": ["KHR_image_ktx2"], | ||
"images": [ | ||
{ | ||
"uri": "texture.ktx2", | ||
"extensions": { | ||
"KHR_image_ktx2" : { | ||
"vkFormat": 37, | ||
"pixelWidth": 512, | ||
"pixelHeight": 512, | ||
"levels": [ | ||
{ | ||
"byteOffset": 256, | ||
"byteLength": 1048576, | ||
} | ||
], | ||
"metadata": { | ||
lexaknyazev marked this conversation as resolved.
Show resolved
Hide resolved
|
||
"KTXswizzle": "bgra" | ||
} | ||
} | ||
} | ||
} | ||
] | ||
} | ||
``` | ||
|
||
### Validation and implementation notes | ||
|
||
If present, the information in the extension object must exactly match KTX2 header. | ||
|
||
JSON type of each metadata entry depends on the type of the original value. The JSON-Schema provides types for metadata keys defined in the KTX2 specification. | ||
|
||
This extension does not restrict texel formats or other features of the KTX2 images. Such limitations must be defined by other glTF extensions referring to this extension. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this necessary when the extension is marked as required? (I understand that it's possible to replace references to KTX2 images in "texture" object with references through extensions, but I'm not sure I understand why this is better than simply using an There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. My understanding is that There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. (quick clarification, the comment got misplaced and refers to line 65 - implementation note - of the spec, not line 63) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
This was my suggestion after attempting to implement it in Babylon. Unless we need some other metadata that goes with the extension, it will likely end up with a no-op implementation. |
||
|
||
> **Implementation Note:** The core glTF 2.0 spec allows only PNG and JPEG images, so references to KTX2 images can appear only in extension objects. | ||
|
||
|
||
## glTF Schema Updates | ||
|
||
* **JSON schema**: [image.KHR_image_ktx2.schema.json](schema/image.KHR_image_ktx2.schema.json) | ||
|
||
## Known Implementations | ||
|
||
None. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,145 @@ | ||
{ | ||
"$schema": "http://json-schema.org/draft-04/schema", | ||
"title": "KHR_image_ktx2", | ||
"type": "object", | ||
"description": "KTX2 file format header", | ||
"allOf": [ | ||
{ | ||
"$ref": "glTFProperty.schema.json" | ||
} | ||
], | ||
"properties": { | ||
"vkFormat": { | ||
"type": "integer", | ||
"minimum": 0, | ||
"default": 0 | ||
}, | ||
"pixelWidth": { | ||
"type": "integer", | ||
"minimum": 1 | ||
}, | ||
"pixelHeight": { | ||
"type": "integer", | ||
"minimum": 0, | ||
"default": 0 | ||
}, | ||
"pixelDepth": { | ||
"type": "integer", | ||
"minimum": 0, | ||
"default": 0 | ||
}, | ||
"layerCount": { | ||
"type": "integer", | ||
"minimum": 0, | ||
"default": 0 | ||
}, | ||
"faceCount": { | ||
"type": "integer", | ||
"enum": [ | ||
1, | ||
6 | ||
], | ||
"default": 1 | ||
}, | ||
"supercompressionScheme": { | ||
"type": "integer", | ||
"minimum": 0, | ||
"default": 0 | ||
}, | ||
"dfdByteOffset": { | ||
"type": "integer", | ||
"minimum": 0 | ||
}, | ||
"dfdByteLength": { | ||
"type": "integer", | ||
"minimum": 0 | ||
}, | ||
"sgdByteOffset": { | ||
"type": "integer", | ||
"minimum": 0, | ||
"default": 0 | ||
}, | ||
"sgdByteLength": { | ||
"type": "integer", | ||
"minimum": 0, | ||
"default": 0 | ||
}, | ||
"generateMipmaps": { | ||
"type": "boolean", | ||
"default": false | ||
}, | ||
"levels": { | ||
"type": "array", | ||
"minItems": 1, | ||
"items": { | ||
"type": "object", | ||
"properties": { | ||
"byteOffset": { | ||
"type": "integer", | ||
"minimum": 0 | ||
}, | ||
"byteLength": { | ||
"type": "integer", | ||
"minimum": 0 | ||
}, | ||
"uncompressedByteLength": { | ||
"type": "integer", | ||
"minimum": 0 | ||
} | ||
}, | ||
"additionalProperties": false, | ||
"required": [ | ||
bghgary marked this conversation as resolved.
Show resolved
Hide resolved
|
||
"byteOffset", | ||
"byteLength" | ||
] | ||
} | ||
}, | ||
"metadata": { | ||
"type": "object", | ||
"properties": { | ||
"KTXcubemapIncomplete": { | ||
"type": "integer", | ||
"minimum": 1, | ||
"maximum": 63 | ||
}, | ||
"KTXorientation": { | ||
"type": "string", | ||
"pattern": "^[rl]([du]|[du][oi])?$" | ||
}, | ||
"KTXglFormat": { | ||
"type": "array", | ||
"minItems": 3, | ||
"maxItems": 3, | ||
"items": { | ||
"type": "integer", | ||
"minimum": 0 | ||
} | ||
}, | ||
"KTXdxgiFormat__": { | ||
"type": "integer", | ||
"minimum": 0 | ||
}, | ||
"KTXmetalPixelFormat": { | ||
"type": "integer", | ||
"minimum": 0 | ||
}, | ||
"KTXswizzle": { | ||
"type": "string", | ||
"pattern": "^[rgba01]{4}$" | ||
}, | ||
"KTXwriter": { | ||
"type": "string" | ||
}, | ||
"KTXastcDecodeRGB9E5": { | ||
"type": "boolean", | ||
"enum": [ | ||
true | ||
] | ||
} | ||
} | ||
}, | ||
"extensions": {}, | ||
"extras": {} | ||
}, | ||
"required": ["pixelWidth", "dfdByteOffset", "dfdByteLength", "levels"] | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are there multiple sources of truth here, width/height/etc being specified both here and in the KTX2 file?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As per the discussion above, we've agreed to not require this block of information. When present, it must match the KTX2 file.
Whether to support it at all (or remove from the schema) so loaders could directly peek into the KTX2 file is up to implementors feedback.