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

WebGLRenderer: Enable usage of SRGB8_ALPHA8 again. #22952

Merged
merged 2 commits into from
Dec 3, 2021
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
5 changes: 2 additions & 3 deletions examples/jsm/renderers/webgl/nodes/WebGLNodeBuilder.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import SlotNode from './SlotNode.js';
import GLSLNodeParser from '../../nodes/parsers/GLSLNodeParser.js';
import WebGLPhysicalContextNode from './WebGLPhysicalContextNode.js';

import { ShaderChunk /*, LinearEncoding, RGBAFormat, UnsignedByteType, sRGBEncoding */ } from '../../../../../build/three.module.js';
import { ShaderChunk, LinearEncoding, RGBAFormat, UnsignedByteType, sRGBEncoding } from '../../../../../build/three.module.js';

const shaderStages = [ 'vertex', 'fragment' ];

Expand Down Expand Up @@ -286,15 +286,14 @@ class WebGLNodeBuilder extends NodeBuilder {

getTextureEncodingFromMap( map ) {

/*
const isWebGL2 = this.renderer.capabilities.isWebGL2;

if ( isWebGL2 && map && map.isTexture && map.format === RGBAFormat && map.type === UnsignedByteType && map.encoding === sRGBEncoding ) {

return LinearEncoding; // disable inline decode for sRGB textures in WebGL 2

}
*/

return super.getTextureEncodingFromMap( map );

}
Expand Down
Binary file modified examples/screenshots/webgl_loader_md2.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 3 additions & 4 deletions src/extras/PMREMGenerator.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
NoBlending,
RGBDEncoding,
RGBEEncoding,
RGBAFormat,
RGBEFormat,
RGBM16Encoding,
RGBM7Encoding,
Expand Down Expand Up @@ -349,17 +350,15 @@ class PMREMGenerator {

_setEncoding( uniform, texture ) {

/* if ( this._renderer.capabilities.isWebGL2 === true && texture.format === RGBAFormat && texture.type === UnsignedByteType && texture.encoding === sRGBEncoding ) {
if ( this._renderer.capabilities.isWebGL2 === true && texture.format === RGBAFormat && texture.type === UnsignedByteType && texture.encoding === sRGBEncoding ) {

uniform.value = ENCODINGS[ LinearEncoding ];

} else {

uniform.value = ENCODINGS[ texture.encoding ];

} */

uniform.value = ENCODINGS[ texture.encoding ];
}

}

Expand Down
6 changes: 3 additions & 3 deletions src/renderers/webgl/WebGLPrograms.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { BackSide, DoubleSide, CubeUVRefractionMapping, CubeUVReflectionMapping, LinearEncoding, ObjectSpaceNormalMap, TangentSpaceNormalMap, NoToneMapping } from '../../constants.js';
import { BackSide, DoubleSide, CubeUVRefractionMapping, CubeUVReflectionMapping, LinearEncoding, sRGBEncoding, ObjectSpaceNormalMap, TangentSpaceNormalMap, NoToneMapping, RGBAFormat, UnsignedByteType } from '../../constants.js';
import { WebGLProgram } from './WebGLProgram.js';
import { ShaderLib } from '../shaders/ShaderLib.js';
import { UniformsUtils } from '../shaders/UniformsUtils.js';
Expand Down Expand Up @@ -108,11 +108,11 @@ function WebGLPrograms( renderer, cubemaps, cubeuvmaps, extensions, capabilities

}

/* if ( isWebGL2 && map && map.isTexture && map.format === RGBAFormat && map.type === UnsignedByteType && map.encoding === sRGBEncoding ) {
if ( isWebGL2 && map && map.isTexture && map.format === RGBAFormat && map.type === UnsignedByteType && map.encoding === sRGBEncoding ) {

encoding = LinearEncoding; // disable inline decode for sRGB textures in WebGL 2

} */
}

return encoding;

Expand Down
8 changes: 3 additions & 5 deletions src/renderers/webgl/WebGLTextures.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { LinearFilter, LinearMipmapLinearFilter, LinearMipmapNearestFilter, NearestFilter, NearestMipmapLinearFilter, NearestMipmapNearestFilter, RGBFormat, RGBAFormat, DepthFormat, DepthStencilFormat, UnsignedShortType, UnsignedIntType, UnsignedInt248Type, FloatType, HalfFloatType, MirroredRepeatWrapping, ClampToEdgeWrapping, RepeatWrapping } from '../../constants.js';
import { LinearFilter, LinearMipmapLinearFilter, LinearMipmapNearestFilter, NearestFilter, NearestMipmapLinearFilter, NearestMipmapNearestFilter, RGBFormat, RGBAFormat, DepthFormat, DepthStencilFormat, UnsignedShortType, UnsignedIntType, UnsignedInt248Type, FloatType, HalfFloatType, MirroredRepeatWrapping, ClampToEdgeWrapping, RepeatWrapping, sRGBEncoding } from '../../constants.js';
import * as MathUtils from '../../math/MathUtils.js';
import { createElementNS } from '../../utils.js';

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

}

function getInternalFormat( internalFormatName, glFormat, glType/*, encoding*/ ) {
function getInternalFormat( internalFormatName, glFormat, glType, encoding ) {

if ( isWebGL2 === false ) return glFormat;

Expand Down Expand Up @@ -164,9 +164,7 @@ 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 = ( encoding === sRGBEncoding ) ? _gl.SRGB8_ALPHA8 : _gl.RGBA8;
if ( glType === _gl.UNSIGNED_BYTE ) internalFormat = _gl.RGBA8;

if ( glType === _gl.UNSIGNED_BYTE ) internalFormat = ( encoding === sRGBEncoding ) ? _gl.SRGB8_ALPHA8 : _gl.RGBA8;

}

Expand Down