x3dom / x3dom

X3DOM. A framework for integrating and manipulating X3D scenes as HTML5/DOM elements.
http://x3dom.org
Other
813 stars 271 forks source link

gltf fails texture encoding test #1258

Closed andreasplesch closed 9 months ago

andreasplesch commented 1 year ago

The glTF renderer fails this test:

https://github.com/KhronosGroup/glTF-Sample-Models/tree/master/2.0/TextureEncodingTest

for emissive texture, and texture images files with embedded color profiles.

Emissive texture must be decoded from sRGB to linear and this can be done in the shader construction in DynamicShader.js where the EMISSIVEMAP is added.

The typical solution for ignoring embedded color profiles is to use createImageBitmap( imageElement, { colorSpaceConversion: "none" } ) which is not available for Safari at this point. Probably ImageTexture will need another field "colorSpaceConversion".

andreasplesch commented 9 months ago
gl.bindTexture( gl.TEXTURE_2D, texture );
        gl.pixelStorei(gl.UNPACK_COLORSPACE_CONVERSION_WEBGL, gl.NONE); 
        //gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, false);
        gl.texImage2D( gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, image );
if ( properties.EMISSIVEMAPCHANNEL )
                {
                    shader += "_emissiveColor = _emissiveColor * " + x3dom.shader.decodeGamma( properties, "texture2D(emissiveMap, vec2(texcoord2.x, 1.0-texcoord2.y)).rgb" ) + ";\n";
                }
                else
                {
                    shader += "_emissiveColor = _emissiveColor * " + x3dom.shader.decodeGamma( properties, "texture2D(emissiveMap, vec2(texcoord.x, 1.0-texcoord.y)).rgb" ) + ";\n";
                }
andreasplesch commented 9 months ago

see https://github.com/mrdoob/three.js/issues/21318

andreasplesch commented 9 months ago

PR #1297