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

Add sRGB handling for ETC texture formats #12567

Merged
merged 3 commits into from
May 24, 2022
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
3 changes: 3 additions & 0 deletions packages/dev/core/src/Engines/WebGPU/webgpuTextureHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -720,7 +720,10 @@ export class WebGPUTextureHelper {
case Constants.TEXTUREFORMAT_COMPRESSED_RGBA_ASTC_4x4:
return useSRGBBuffer ? WebGPUConstants.TextureFormat.ASTC4x4UnormSRGB : WebGPUConstants.TextureFormat.ASTC4x4Unorm;
case Constants.TEXTUREFORMAT_COMPRESSED_RGB_ETC1_WEBGL:
case Constants.TEXTUREFORMAT_COMPRESSED_RGB8_ETC2:
return useSRGBBuffer ? WebGPUConstants.TextureFormat.ETC2RGB8UnormSRGB : WebGPUConstants.TextureFormat.ETC2RGB8Unorm;
case Constants.TEXTUREFORMAT_COMPRESSED_RGBA8_ETC2_EAC:
return useSRGBBuffer ? WebGPUConstants.TextureFormat.ETC2RGBA8UnormSRGB : WebGPUConstants.TextureFormat.ETC2RGBA8Unorm;
}

switch (type) {
Expand Down
20 changes: 20 additions & 0 deletions packages/dev/core/src/Engines/thinEngine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1227,6 +1227,10 @@ export class ThinEngine {
this._gl.COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT = this._caps.s3tc_srgb.COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT;
this._gl.COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT = this._caps.s3tc_srgb.COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT;
}
if (this._caps.etc2) {
this._gl.COMPRESSED_SRGB8_ETC2 = this._caps.etc2.COMPRESSED_SRGB8_ETC2;
this._gl.COMPRESSED_SRGB8_ALPHA8_ETC2_EAC = this._caps.etc2.COMPRESSED_SRGB8_ALPHA8_ETC2_EAC;
}

// Checks if some of the format renders first to allow the use of webgl inspector.
if (this._webGLVersion > 1) {
Expand Down Expand Up @@ -4481,6 +4485,22 @@ export class ThinEngine {

if (texture._useSRGBBuffer) {
switch (internalFormat) {
case Constants.TEXTUREFORMAT_COMPRESSED_RGB8_ETC2:
case Constants.TEXTUREFORMAT_COMPRESSED_RGB_ETC1_WEBGL:
// Note, if using ETC1 and sRGB is requested, this will use ETC2 if available.
if (this._caps.etc2) {
internalFormat = gl.COMPRESSED_SRGB8_ETC2;
} else {
texture._useSRGBBuffer = false;
}
break;
case Constants.TEXTUREFORMAT_COMPRESSED_RGBA8_ETC2_EAC:
if (this._caps.etc2) {
internalFormat = gl.COMPRESSED_SRGB8_ALPHA8_ETC2_EAC;
} else {
texture._useSRGBBuffer = false;
}
break;
kircher1 marked this conversation as resolved.
Show resolved Hide resolved
case Constants.TEXTUREFORMAT_COMPRESSED_RGBA_BPTC_UNORM:
internalFormat = gl.COMPRESSED_SRGB_ALPHA_BPTC_UNORM_EXT;
break;
Expand Down
2 changes: 2 additions & 0 deletions packages/dev/core/src/LibDeclarations/webgl.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ interface WebGLRenderingContext {
COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT: number;
COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT: number;
COMPRESSED_SRGB_ALPHA_BPTC_UNORM_EXT: number;
COMPRESSED_SRGB8_ETC2: number;
COMPRESSED_SRGB8_ALPHA8_ETC2_EAC: number;

UNSIGNED_INT_24_8: number;
DEPTH24_STENCIL8: number;
Expand Down