Skip to content

Commit

Permalink
glTF texture encoding, colorSpaceConversion (x3dom#1297)
Browse files Browse the repository at this point in the history
* test

* colorSpaceConversion field

* decodeGamma for gltf emissive

* changelog
  • Loading branch information
andreasplesch committed Sep 21, 2023
1 parent fc93440 commit a224ef0
Show file tree
Hide file tree
Showing 7 changed files with 53 additions and 21 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.github/workflows/static.yml
.travis.yml
.idea
_site
Expand Down Expand Up @@ -27,3 +28,4 @@ src/.vscode
# remove with new build system
src/version.js
src/x3dom.js

1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
## Version 1.8.4-dev

* Features
* ImageTexture colorSpaceConversion field
* support for glTF punctual lights, emissive strength, webp, mesh quantization and meshopt compression extensions
* field values from metadata for non-standard nodes

Expand Down
10 changes: 10 additions & 0 deletions src/nodes/Texturing/ImageTexture.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,16 @@ x3dom.registerNodeType(
function ( ctx )
{
x3dom.nodeTypes.ImageTexture.superClass.call( this, ctx );

/**
* Specifies whether embedded color profiles are used in conversion to rendering. true for X3D, false for glTF.
* @var {x3dom.fields.SFBool} colorSpaceConversion
* @memberof x3dom.nodeTypes.ImageTexture
* @initvalue true
* @field x3dom
* @instance
*/
this.addField_SFBool( ctx, "colorSpaceConversion", true );
}
)
);
20 changes: 17 additions & 3 deletions src/shader/ShaderDynamic.js
Original file line number Diff line number Diff line change
Expand Up @@ -1069,16 +1069,30 @@ x3dom.shader.DynamicShader.prototype.generateFragmentShader = function ( gl, pro
shader += "_specularColor = texture2D(specularMap, vec2(texcoord.x, 1.0-texcoord.y)).rgb;\n";
}

//Specularmap
//Emissivemap
if ( properties.EMISSIVEMAP )
{
if ( properties.EMISSIVEMAPCHANNEL )
{
shader += "_emissiveColor = _emissiveColor * texture2D(emissiveMap, vec2(texcoord2.x, 1.0-texcoord2.y)).rgb;\n";
if ( properties.PBR_MATERIAL )
{
shader += "_emissiveColor = _emissiveColor * " + x3dom.shader.decodeGamma( properties, "texture2D(emissiveMap, vec2(texcoord2.x, 1.0-texcoord2.y)).rgb" ) + ";\n";
}
else
{
shader += "_emissiveColor = _emissiveColor * texture2D(emissiveMap, vec2(texcoord2.x, 1.0-texcoord2.y)).rgb;\n";
}
}
else
{
shader += "_emissiveColor = _emissiveColor * texture2D(emissiveMap, vec2(texcoord.x, 1.0-texcoord.y)).rgb;\n";
if ( properties.PBR_MATERIAL )
{
shader += "_emissiveColor = _emissiveColor * " + x3dom.shader.decodeGamma( properties, "texture2D(emissiveMap, vec2(texcoord.x, 1.0-texcoord.y)).rgb" ) + ";\n";
}
else
{
shader += "_emissiveColor = _emissiveColor * texture2D(emissiveMap, vec2(texcoord.x, 1.0-texcoord.y)).rgb;\n";
}
}
}

Expand Down
4 changes: 4 additions & 0 deletions src/util/Utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,10 @@ x3dom.Utils.createTexture2D = function ( gl, doc, src, bgnd, crossOrigin, scale,
gl.pixelStorei( gl.UNPACK_FLIP_Y_WEBGL, true );
}
gl.bindTexture( gl.TEXTURE_2D, texture );
if ( tex && tex._vf.colorSpaceConversion == false )
{
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 ( genMipMaps )
Expand Down
3 changes: 2 additions & 1 deletion src/util/glTF/glTF2Loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -775,7 +775,7 @@ x3dom.glTF2Loader.prototype._generateX3DPhysicalMaterial = function ( material )
*/
x3dom.glTF2Loader.prototype._generateX3DImageTexture = function ( texture, containerField, channel, transform )
{
var image = this._gltf.images[ texture.source ];
var image = this._gltf.images[ texture.source ];

var webpImageUrl = "";

Expand All @@ -791,6 +791,7 @@ x3dom.glTF2Loader.prototype._generateX3DImageTexture = function ( texture, conta

imagetexture.setAttribute( "origChannelCount", "2" );
imagetexture.setAttribute( "flipY", "true" );
imagetexture.setAttribute( "colorSpaceConversion", "false" );

if ( containerField )
{
Expand Down
34 changes: 17 additions & 17 deletions test/functional/inline-gltf.html
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
<meta http-equiv="X-UA-Compatible" content="chrome=1,IE=edge" />
<meta name="theme-color" content="#86c540">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
<title>X3DOM // GLTF 2.0</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
<title>X3DOM // GLTF 2.0</title>
<script type="text/javascript" src="../x3dom-include.js?full"></script>
<link href="https://fonts.googleapis.com/css?family=Roboto:400,500,700,900" rel="stylesheet">
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
Expand Down Expand Up @@ -370,7 +370,7 @@
<section class="main-wrapper">

<section class="sidebar">

<div class="sidebar-header">Basic Tests</div>

<div class="sidebar-entry" onclick="load('Triangle',undefined,'negZ')">Triangle</div>
Expand All @@ -385,6 +385,7 @@
<div class="sidebar-entry" onclick="load('TextureCoordinateTest',undefined,'negZ')">Texture Coordinate Test</div>
<div class="sidebar-entry" onclick="load('TextureSettingsTest',undefined,'negZ')">Texture Settings Test</div>
<div class="sidebar-entry" onclick="load('TextureTransformTest',undefined,'negZ')">Texture Transform Test</div>
<div class="sidebar-entry" onclick="load('TextureEncodingTest',undefined,'negZ')">Texture Encoding Test</div>
<div class="sidebar-entry" onclick="load('AlphaBlendModeTest',undefined,'negZ')">Alpha Blend Mode Test</div>
<div class="sidebar-entry" onclick="load('NormalTangentTest',undefined,'negZ')">Normal Tangent Test</div>
<div class="sidebar-entry" onclick="load('NormalTangentMirrorTest',undefined,'negZ')">Normal Tangent Mirror Test</div>
Expand Down Expand Up @@ -450,19 +451,18 @@
<div class="sidebar-entry" onclick="load('https://raw.githubusercontent.com/CesiumGS/cesium/bd8be76b7707ddb9c858ae39538c18064c218f98/Specs/Data/Models/Box-Textured-Webp/CesiumBoxWebp.gltf','direct','negZ')">Cesium, embedded, webp</div>
<div class="sidebar-entry" onclick="load('https://raw.githubusercontent.com/zeux/meshoptimizer/master/demo/pirate.glb','direct','negZ')">Pirate, meshopt+quant., glb</div>
<div class="sidebar-entry" onclick="load('https://assets.babylonjs.com/meshes/Buggy/glTF-MeshOpt/Buggy.gltf','direct','negZ')">BJS Buggy, meshopt+quant., gltf</div>

<div class="sidebar-header">VR Controller</div>

<div class="sidebar-entry" onclick="updateInline('https://x3dom.org/download/assets/vr/vive.glb')">Vive</div>
<div class="sidebar-entry" onclick="updateInline('https://x3dom.org/download/assets/vr/oculus-go.glb')">Oculus Go</div>
<div class="sidebar-entry" onclick="updateInline('https://x3dom.org/download/assets/vr/oculus-left.glb')">Oculus Left</div>
<div class="sidebar-entry" onclick="updateInline('https://x3dom.org/download/assets/vr/oculus-right.glb')">Oculus Right</div>
<div class="sidebar-entry" onclick="updateInline('https://x3dom.org/download/assets/vr/daydream.glb')">Daydream</div>
<div class="sidebar-entry" onclick="updateInline('https://x3dom.org/download/assets/vr/gearvr.glb')">GearVR</div>
<div class="sidebar-entry" onclick="updateInline('https://x3dom.org/download/assets/vr/microsoft-left.glb')">Microsoft Left</div>
<div class="sidebar-entry" onclick="updateInline('https://x3dom.org/download/assets/vr/microsoft-right.glb')">Microsoft Right</div>
<div class="sidebar-entry" onclick="updateInline('https://cdn.rawgit.com/KhronosGroup/glTF-Blender-Exporter/0e23c773bf27dad67d2c25f060370d6fa012d87d/polly/project_polly.gltf')">Polly</div>


<div class="sidebar-header">VR Controller</div>

<div class="sidebar-entry" onclick="updateInline('https://x3dom.org/download/assets/vr/vive.glb')">Vive</div>
<div class="sidebar-entry" onclick="updateInline('https://x3dom.org/download/assets/vr/oculus-go.glb')">Oculus Go</div>
<div class="sidebar-entry" onclick="updateInline('https://x3dom.org/download/assets/vr/oculus-left.glb')">Oculus Left</div>
<div class="sidebar-entry" onclick="updateInline('https://x3dom.org/download/assets/vr/oculus-right.glb')">Oculus Right</div>
<div class="sidebar-entry" onclick="updateInline('https://x3dom.org/download/assets/vr/daydream.glb')">Daydream</div>
<div class="sidebar-entry" onclick="updateInline('https://x3dom.org/download/assets/vr/gearvr.glb')">GearVR</div>
<div class="sidebar-entry" onclick="updateInline('https://x3dom.org/download/assets/vr/microsoft-left.glb')">Microsoft Left</div>
<div class="sidebar-entry" onclick="updateInline('https://x3dom.org/download/assets/vr/microsoft-right.glb')">Microsoft Right</div>
<div class="sidebar-entry" onclick="updateInline('https://cdn.rawgit.com/KhronosGroup/glTF-Blender-Exporter/0e23c773bf27dad67d2c25f060370d6fa012d87d/polly/project_polly.gltf')">Polly</div>

</section>

Expand Down

0 comments on commit a224ef0

Please sign in to comment.