Skip to content
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
10 changes: 8 additions & 2 deletions examples/jsm/loaders/KTX2Loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ import {
SRGBColorSpace,
UnsignedByteType,
UnsignedInt5999Type,
UnsignedInt101111Type
UnsignedInt101111Type,
UnsignedShortType
} from 'three';
import { WorkerPool } from '../utils/WorkerPool.js';
import {
Expand Down Expand Up @@ -83,6 +84,7 @@ import {
VK_FORMAT_PVRTC1_2BPP_SRGB_BLOCK_IMG,
VK_FORMAT_PVRTC1_2BPP_UNORM_BLOCK_IMG,
VK_FORMAT_R16G16B16A16_SFLOAT,
VK_FORMAT_R16G16B16A16_UNORM,
VK_FORMAT_R16G16_SFLOAT,
VK_FORMAT_R16_SFLOAT,
VK_FORMAT_R32G32B32A32_SFLOAT,
Expand Down Expand Up @@ -964,6 +966,8 @@ const FORMAT_MAP = {
[ VK_FORMAT_R16G16_SFLOAT ]: RGFormat,
[ VK_FORMAT_R16_SFLOAT ]: RedFormat,

[ VK_FORMAT_R16G16B16A16_UNORM ]: RGBAFormat,

[ VK_FORMAT_R8G8B8A8_SRGB ]: RGBAFormat,
[ VK_FORMAT_R8G8B8A8_UNORM ]: RGBAFormat,
[ VK_FORMAT_R8G8_SRGB ]: RGFormat,
Expand Down Expand Up @@ -1022,6 +1026,8 @@ const TYPE_MAP = {
[ VK_FORMAT_R16G16_SFLOAT ]: HalfFloatType,
[ VK_FORMAT_R16_SFLOAT ]: HalfFloatType,

[ VK_FORMAT_R16G16B16A16_UNORM ]: UnsignedShortType,

[ VK_FORMAT_R8G8B8A8_SRGB ]: UnsignedByteType,
[ VK_FORMAT_R8G8B8A8_UNORM ]: UnsignedByteType,
[ VK_FORMAT_R8G8_SRGB ]: UnsignedByteType,
Expand Down Expand Up @@ -1149,7 +1155,7 @@ async function createRawTexture( container ) {

);

} else if ( TYPE_MAP[ vkFormat ] === HalfFloatType ) {
} else if ( TYPE_MAP[ vkFormat ] === HalfFloatType || TYPE_MAP[ vkFormat ] === UnsignedShortType ) {

data = new Uint16Array(

Expand Down
Binary file not shown.
1 change: 1 addition & 0 deletions examples/webgl_loader_texture_ktx2.html
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@
{ path: '2d_rgba8.ktx2' },
{ path: '2d_rgba8_linear.ktx2' },
{ path: '2d_rgba16_linear.ktx2' },
{ path: '2d_rgba16unorm_linear.ktx2' },
{ path: '2d_rgba32_linear.ktx2' },
{ path: '2d_rgb9e5_linear.ktx2' },
{ path: '2d_r11g11b10_linear.ktx2' },
Expand Down
1 change: 1 addition & 0 deletions src/loaders/ObjectLoader.js
Original file line number Diff line number Diff line change
Expand Up @@ -757,6 +757,7 @@ class ObjectLoader extends Loader {
if ( data.premultiplyAlpha !== undefined ) texture.premultiplyAlpha = data.premultiplyAlpha;
if ( data.unpackAlignment !== undefined ) texture.unpackAlignment = data.unpackAlignment;
if ( data.compareFunction !== undefined ) texture.compareFunction = data.compareFunction;
if ( data.normalized !== undefined ) texture.normalized = data.normalized;

if ( data.userData !== undefined ) texture.userData = data.userData;

Expand Down
26 changes: 24 additions & 2 deletions src/renderers/webgl-fallback/utils/WebGLTextureUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ class WebGLTextureUtils {
* @param {boolean} [forceLinearTransfer=false] - Whether to force a linear transfer or not.
* @return {GLenum} The internal format.
*/
getInternalFormat( internalFormatName, glFormat, glType, colorSpace, forceLinearTransfer = false ) {
getInternalFormat( internalFormatName, glFormat, glType, normalized, colorSpace, forceLinearTransfer = false ) {

const { gl, extensions } = this;

Expand All @@ -174,6 +174,20 @@ class WebGLTextureUtils {

}

let extTextureNorm16 = null;

if ( normalized ) {

extTextureNorm16 = extensions.get( 'EXT_texture_norm16' );

if ( ! extTextureNorm16 ) {

warn( 'WebGLRenderer: Unable to use normalized textures without EXT_texture_norm16 extension' );

}

}

let internalFormat = glFormat;

if ( glFormat === gl.RED ) {
Expand All @@ -182,6 +196,8 @@ class WebGLTextureUtils {
if ( glType === gl.HALF_FLOAT ) internalFormat = gl.R16F;
if ( glType === gl.UNSIGNED_BYTE ) internalFormat = gl.R8;
if ( glType === gl.BYTE ) internalFormat = gl.R8_SNORM;
if ( glType === gl.UNSIGNED_SHORT && extTextureNorm16 ) internalFormat = extTextureNorm16.R16_EXT;
if ( glType === gl.SHORT && extTextureNorm16 ) internalFormat = extTextureNorm16.R16_SNORM_EXT;

}

Expand All @@ -202,6 +218,8 @@ class WebGLTextureUtils {
if ( glType === gl.HALF_FLOAT ) internalFormat = gl.RG16F;
if ( glType === gl.UNSIGNED_BYTE ) internalFormat = gl.RG8;
if ( glType === gl.BYTE ) internalFormat = gl.RG8_SNORM;
if ( glType === gl.UNSIGNED_SHORT && extTextureNorm16 ) internalFormat = extTextureNorm16.RG16_EXT;
if ( glType === gl.SHORT && extTextureNorm16 ) internalFormat = extTextureNorm16.RG16_SNORM_EXT;

}

Expand All @@ -224,6 +242,8 @@ class WebGLTextureUtils {
if ( glType === gl.HALF_FLOAT ) internalFormat = gl.RGB16F;
if ( glType === gl.UNSIGNED_BYTE ) internalFormat = ( transfer === SRGBTransfer ) ? gl.SRGB8 : gl.RGB8;
if ( glType === gl.BYTE ) internalFormat = gl.RGB8_SNORM;
if ( glType === gl.UNSIGNED_SHORT && extTextureNorm16 ) internalFormat = extTextureNorm16.RGB16_EXT;
if ( glType === gl.SHORT && extTextureNorm16 ) internalFormat = extTextureNorm16.RGB16_SNORM_EXT;
if ( glType === gl.UNSIGNED_SHORT_5_6_5 ) internalFormat = gl.RGB565;
if ( glType === gl.UNSIGNED_SHORT_5_5_5_1 ) internalFormat = gl.RGB5_A1;
if ( glType === gl.UNSIGNED_SHORT_4_4_4_4 ) internalFormat = gl.RGB4;
Expand Down Expand Up @@ -251,6 +271,8 @@ class WebGLTextureUtils {
if ( glType === gl.HALF_FLOAT ) internalFormat = gl.RGBA16F;
if ( glType === gl.UNSIGNED_BYTE ) internalFormat = ( transfer === SRGBTransfer ) ? gl.SRGB8_ALPHA8 : gl.RGBA8;
if ( glType === gl.BYTE ) internalFormat = gl.RGBA8_SNORM;
if ( glType === gl.UNSIGNED_SHORT && extTextureNorm16 ) internalFormat = extTextureNorm16.RGBA16_EXT;
if ( glType === gl.SHORT && extTextureNorm16 ) internalFormat = extTextureNorm16.RGBA16_SNORM_EXT;
if ( glType === gl.UNSIGNED_SHORT_4_4_4_4 ) internalFormat = gl.RGBA4;
if ( glType === gl.UNSIGNED_SHORT_5_5_5_1 ) internalFormat = gl.RGB5_A1;

Expand Down Expand Up @@ -411,7 +433,7 @@ class WebGLTextureUtils {

const glFormat = backend.utils.convert( texture.format, texture.colorSpace );
const glType = backend.utils.convert( texture.type );
const glInternalFormat = this.getInternalFormat( texture.internalFormat, glFormat, glType, texture.colorSpace, texture.isVideoTexture );
const glInternalFormat = this.getInternalFormat( texture.internalFormat, glFormat, glType, texture.normalized, texture.colorSpace, texture.isVideoTexture );

const textureGPU = gl.createTexture();
const glTextureType = this.getGLTextureType( texture );
Expand Down
34 changes: 28 additions & 6 deletions src/renderers/webgl/WebGLTextures.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,

}

function getInternalFormat( internalFormatName, glFormat, glType, colorSpace, forceLinearTransfer = false ) {
function getInternalFormat( internalFormatName, glFormat, glType, normalized, colorSpace, forceLinearTransfer = false ) {

if ( internalFormatName !== null ) {

Expand All @@ -135,13 +135,29 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,

}

let ext_texture_norm16;

if ( normalized ) {

ext_texture_norm16 = extensions.get( 'EXT_texture_norm16' );

if ( ! ext_texture_norm16 ) {

warn( 'WebGLRenderer: Unable to use normalized textures without EXT_texture_norm16 extension' );

}

}

let internalFormat = glFormat;

if ( glFormat === _gl.RED ) {

if ( glType === _gl.FLOAT ) internalFormat = _gl.R32F;
if ( glType === _gl.HALF_FLOAT ) internalFormat = _gl.R16F;
if ( glType === _gl.UNSIGNED_BYTE ) internalFormat = _gl.R8;
if ( glType === _gl.UNSIGNED_SHORT && ext_texture_norm16 ) internalFormat = ext_texture_norm16.R16_EXT;
if ( glType === _gl.SHORT && ext_texture_norm16 ) internalFormat = ext_texture_norm16.R16_SNORM_EXT;

}

Expand All @@ -161,6 +177,8 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
if ( glType === _gl.FLOAT ) internalFormat = _gl.RG32F;
if ( glType === _gl.HALF_FLOAT ) internalFormat = _gl.RG16F;
if ( glType === _gl.UNSIGNED_BYTE ) internalFormat = _gl.RG8;
if ( glType === _gl.UNSIGNED_SHORT && ext_texture_norm16 ) internalFormat = ext_texture_norm16.RG16_EXT;
if ( glType === _gl.SHORT && ext_texture_norm16 ) internalFormat = ext_texture_norm16.RG16_SNORM_EXT;

}

Expand Down Expand Up @@ -199,6 +217,8 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,

if ( glFormat === _gl.RGB ) {

if ( glType === _gl.UNSIGNED_SHORT && ext_texture_norm16 ) internalFormat = ext_texture_norm16.RGB16_EXT;
if ( glType === _gl.SHORT && ext_texture_norm16 ) internalFormat = ext_texture_norm16.RGB16_SNORM_EXT;
if ( glType === _gl.UNSIGNED_INT_5_9_9_9_REV ) internalFormat = _gl.RGB9_E5;
if ( glType === _gl.UNSIGNED_INT_10F_11F_11F_REV ) internalFormat = _gl.R11F_G11F_B10F;

Expand All @@ -211,6 +231,8 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
if ( glType === _gl.FLOAT ) internalFormat = _gl.RGBA32F;
if ( glType === _gl.HALF_FLOAT ) internalFormat = _gl.RGBA16F;
if ( glType === _gl.UNSIGNED_BYTE ) internalFormat = ( transfer === SRGBTransfer ) ? _gl.SRGB8_ALPHA8 : _gl.RGBA8;
if ( glType === _gl.UNSIGNED_SHORT && ext_texture_norm16 ) internalFormat = ext_texture_norm16.RGBA16_EXT;
if ( glType === _gl.SHORT && ext_texture_norm16 ) internalFormat = ext_texture_norm16.RGBA16_SNORM_EXT;
if ( glType === _gl.UNSIGNED_SHORT_4_4_4_4 ) internalFormat = _gl.RGBA4;
if ( glType === _gl.UNSIGNED_SHORT_5_5_5_1 ) internalFormat = _gl.RGB5_A1;

Expand Down Expand Up @@ -908,7 +930,7 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
const glFormat = utils.convert( texture.format, texture.colorSpace );

const glType = utils.convert( texture.type );
let glInternalFormat = getInternalFormat( texture.internalFormat, glFormat, glType, texture.colorSpace, texture.isVideoTexture );
let glInternalFormat = getInternalFormat( texture.internalFormat, glFormat, glType, texture.normalized, texture.colorSpace, texture.isVideoTexture );

setTextureParameters( textureType, texture );

Expand Down Expand Up @@ -1357,7 +1379,7 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
const image = cubeImage[ 0 ],
glFormat = utils.convert( texture.format, texture.colorSpace ),
glType = utils.convert( texture.type ),
glInternalFormat = getInternalFormat( texture.internalFormat, glFormat, glType, texture.colorSpace );
glInternalFormat = getInternalFormat( texture.internalFormat, glFormat, glType, texture.normalized, texture.colorSpace );

const useTexStorage = ( texture.isVideoTexture !== true );
const allocateMemory = ( sourceProperties.__version === undefined ) || ( forceUpload === true );
Expand Down Expand Up @@ -1553,7 +1575,7 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,

const glFormat = utils.convert( texture.format, texture.colorSpace );
const glType = utils.convert( texture.type );
const glInternalFormat = getInternalFormat( texture.internalFormat, glFormat, glType, texture.colorSpace );
const glInternalFormat = getInternalFormat( texture.internalFormat, glFormat, glType, texture.normalized, texture.colorSpace );
const renderTargetProperties = properties.get( renderTarget );
const textureProperties = properties.get( texture );

Expand Down Expand Up @@ -1632,7 +1654,7 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,

const glFormat = utils.convert( texture.format, texture.colorSpace );
const glType = utils.convert( texture.type );
const glInternalFormat = getInternalFormat( texture.internalFormat, glFormat, glType, texture.colorSpace );
const glInternalFormat = getInternalFormat( texture.internalFormat, glFormat, glType, texture.normalized, texture.colorSpace );

if ( useMultisampledRTT( renderTarget ) ) {

Expand Down Expand Up @@ -2022,7 +2044,7 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,

const glFormat = utils.convert( texture.format, texture.colorSpace );
const glType = utils.convert( texture.type );
const glInternalFormat = getInternalFormat( texture.internalFormat, glFormat, glType, texture.colorSpace, renderTarget.isXRRenderTarget === true );
const glInternalFormat = getInternalFormat( texture.internalFormat, glFormat, glType, texture.normalized, texture.colorSpace, renderTarget.isXRRenderTarget === true );
const samples = getRenderTargetSamples( renderTarget );
_gl.renderbufferStorageMultisample( _gl.RENDERBUFFER, samples, glInternalFormat, renderTarget.width, renderTarget.height );

Expand Down
7 changes: 4 additions & 3 deletions src/renderers/webgpu/nodes/WGSLNodeBuilder.js
Original file line number Diff line number Diff line change
Expand Up @@ -1876,6 +1876,7 @@ ${ flowData.code }
*/
getUniforms( shaderStage ) {

const backend = this.renderer.backend;
const uniforms = this.uniforms[ shaderStage ];

const bindingSnippets = [];
Expand Down Expand Up @@ -1913,7 +1914,7 @@ ${ flowData.code }

let multisampled = '';

const { primarySamples } = this.renderer.backend.utils.getTextureSampleData( texture );
const { primarySamples } = backend.utils.getTextureSampleData( texture );

if ( primarySamples > 1 ) {

Expand All @@ -1931,7 +1932,7 @@ ${ flowData.code }

} else if ( texture.isDepthTexture === true ) {

if ( this.renderer.backend.compatibilityMode && texture.compareFunction === null ) {
if ( backend.compatibilityMode && texture.compareFunction === null ) {

textureType = `texture${ multisampled }_2d<f32>`;

Expand All @@ -1943,7 +1944,7 @@ ${ flowData.code }

} else if ( uniform.node.isStorageTextureNode === true ) {

const format = getFormat( texture );
const format = getFormat( texture, backend.device );
const access = this.getStorageAccess( uniform.node, shaderStage );

const is3D = uniform.node.value.is3DTexture;
Expand Down
8 changes: 8 additions & 0 deletions src/renderers/webgpu/utils/WebGPUConstants.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,8 @@ export const GPUTextureFormat = {
RG8Snorm: 'rg8snorm',
RG8Uint: 'rg8uint',
RG8Sint: 'rg8sint',
R16Unorm: 'r16unorm',
R16Snorm: 'r16snorm',

// 32-bit formats

Expand All @@ -112,7 +114,11 @@ export const GPUTextureFormat = {
RGBA8Sint: 'rgba8sint',
BGRA8Unorm: 'bgra8unorm',
BGRA8UnormSRGB: 'bgra8unorm-srgb',
RG16Unorm: 'rg16unorm',
RG16Snorm: 'rg16snorm',

// Packed 32-bit formats

RGB9E5UFloat: 'rgb9e5ufloat',
RGB10A2Unorm: 'rgb10a2unorm',
RG11B10UFloat: 'rg11b10ufloat',
Expand All @@ -125,6 +131,8 @@ export const GPUTextureFormat = {
RGBA16Uint: 'rgba16uint',
RGBA16Sint: 'rgba16sint',
RGBA16Float: 'rgba16float',
RGBA16Unorm: 'rgba16unorm',
RGBA16Snorm: 'rgba16snorm',

// 128-bit formats

Expand Down
Loading
Loading