Skip to content

Commit

Permalink
Merge pull request #234 from KhronosGroup/feature/KTX-support-32-SFLOAT
Browse files Browse the repository at this point in the history
IBL: support 32-bit KTX files
  • Loading branch information
Benjamin Schmithüsen authored Jan 20, 2020
2 parents 058a12d + a423c7c commit 9c88ef1
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 5 deletions.
9 changes: 7 additions & 2 deletions libs/ktx2image.js
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,10 @@ class Ktx2Image
{
face.data = new Uint16Array(arrayBuffer, faceOffset, faceLength / this.typeSize);
}
else if (this.vkFormat == VK_FORMAT.R32G32B32A32_SFLOAT)
{
face.data = new Float32Array(arrayBuffer, faceOffset, faceLength / this.typeSize);
}

level.faces.push(face);
}
Expand Down Expand Up @@ -206,7 +210,8 @@ class Ktx2Image
// https://www.khronos.org/registry/vulkan/specs/1.1-extensions/man/html/VkFormat.html
const VK_FORMAT =
{
R16G16B16A16_SFLOAT: 97
R16G16B16A16_SFLOAT: 97,
R32G32B32A32_SFLOAT: 109
};

export { Ktx2Image };
export { Ktx2Image, VK_FORMAT };
15 changes: 14 additions & 1 deletion src/image.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { HDRImage } from '../libs/hdrpng.js';
import { Ktx2Image } from '../libs/ktx2image.js';
import { Ktx2Image, VK_FORMAT } from '../libs/ktx2image.js';
import { WebGl } from './webgl.js';
import { GltfObject } from './gltf_object.js';
import { isPowerOf2 } from './math_utils.js';
Expand Down Expand Up @@ -92,6 +92,19 @@ class gltfImage extends GltfObject
.then(response =>
{
this.image.initialize(response.data);

if (this.image.vkFormat == VK_FORMAT.R16G16B16A16_SFLOAT)
{
this.image.glInternalFormat = WebGl.context.RGBA16F;
this.image.glFormat = WebGl.context.RGBA;
this.image.glType = WebGl.context.HALF_FLOAT;
}
else if (this.image.vkFormat == VK_FORMAT.R32G32B32A32_SFLOAT)
{
this.image.glInternalFormat = WebGl.context.RGBA32F;
this.image.glFormat = WebGl.context.RGBA;
this.image.glType = WebGl.context.FLOAT;
}
});
}
else
Expand Down
6 changes: 4 additions & 2 deletions src/webgl.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,12 +95,14 @@ class gltfWebGl

if (image.image instanceof Ktx2Image)
{
for (const level of image.image.levels)
const ktxImage = image.image;

for (const level of ktxImage.levels)
{
let faceType = WebGl.context.TEXTURE_CUBE_MAP_POSITIVE_X;
for (const face of level.faces)
{
WebGl.context.texImage2D(faceType, level.miplevel, WebGl.context.RGBA16F, level.width, level.height, 0, WebGl.context.RGBA, WebGl.context.HALF_FLOAT, face.data);
WebGl.context.texImage2D(faceType, level.miplevel, ktxImage.glInternalFormat, level.width, level.height, 0, ktxImage.glFormat, ktxImage.glType, face.data);

faceType++;
}
Expand Down

0 comments on commit 9c88ef1

Please sign in to comment.