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

IBL: support 32-bit KTX files #234

Merged
4 commits merged into from
Jan 20, 2020
Merged
Show file tree
Hide file tree
Changes from all 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
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