Skip to content
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

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 74 additions & 0 deletions extensions/2.0/Khronos/KHR_image_ktx2/README.md
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.

A JSON form of the KTX2 header is 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 uncomressed RGBA8 2D image without precomputed mip levelsswizzling metadata.
lexaknyazev marked this conversation as resolved.
Show resolved Hide resolved

```json
{
"asset": {
"version": "2.0"
},
"extesnionsUsed": ["KHR_image_ktx2"],
lexaknyazev marked this conversation as resolved.
Show resolved Hide resolved
"images": [
{
"uri": "texture.ktx2",
"extensions": {
"KHR_image_ktx2" : {
"vkFormat": 37,
"pixelWidth": 512,
"pixelHeight": 512,
Copy link
Member

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?

Copy link
Member Author

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.

"levels": [
{
"byteOffset": 256,
"byteLength": 1048576,
}
],
"metadata": {
lexaknyazev marked this conversation as resolved.
Show resolved Hide resolved
"KTXswizzle": "bgra"
}
}
}
}
]
}
```

### Validation and implementation notes

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.
Copy link
Contributor

Choose a reason for hiding this comment

The 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 image/ktx2 MIME type on the image objects that are referenced directly)

Copy link
Contributor

@donmccurdy donmccurdy Nov 20, 2019

Choose a reason for hiding this comment

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

My understanding is that KHR_image_ktx2 may be dropped entirely, and that the other extensions in this PR would simply independently allow KTX2 images. @lexaknyazev @bghgary is that a correct understanding of #1705 (comment)? This was confusing me as well.

Copy link
Contributor

Choose a reason for hiding this comment

The 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)

Copy link
Contributor

Choose a reason for hiding this comment

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

KHR_image_ktx2 may be dropped entirely

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)
lexaknyazev marked this conversation as resolved.
Show resolved Hide resolved

## 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
},
"arrayElements": {
"type": "integer",
"minimum": 0,
"default": 0
},
"faces": {
"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
},
"byteLengthUncompressed": {
"type": "integer",
"minimum": 0
}
},
"additionalProperties": false,
"required": [
bghgary marked this conversation as resolved.
Show resolved Hide resolved
"offset",
"bytesOfImages"
]
}
},
"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"]
}
Loading