Skip to content

Commit b1f61de

Browse files
authored
Merge pull request #6302 from AnalyticalGraphicsInc/gltf-tangents
Fix a couple issues with glTF tangent processing.
2 parents 7a86dcf + d85c9f1 commit b1f61de

File tree

2 files changed

+15
-9
lines changed

2 files changed

+15
-9
lines changed

CHANGES.md

+5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
Change Log
22
==========
33

4+
### 1.44 - 2018-04-02
5+
6+
##### Fixes :wrench:
7+
* Fixed support of glTF-supplied tangent vectors. [#6302](https://github.com/AnalyticalGraphicsInc/cesium/pull/6302)
8+
49
### 1.43 - 2018-03-01
510

611
##### Major Announcements :loudspeaker:

Source/ThirdParty/GltfPipeline/processPbrMetallicRoughness.js

+10-9
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ define([
239239
vertexShaderMain += ' vec3 weightedNormal = a_normal;\n';
240240
}
241241
if (hasTangents) {
242-
vertexShaderMain += ' vec3 weightedTangent = a_tangent;\n';
242+
vertexShaderMain += ' vec4 weightedTangent = a_tangent;\n';
243243
}
244244
if (hasMorphTargets) {
245245
for (var k = 0; k < morphTargets.length; k++) {
@@ -258,7 +258,7 @@ define([
258258
} else if (targetAttribute === 'NORMAL') {
259259
vertexShaderMain += ' weightedNormal += u_morphWeights[' + k + '] * a_' + attributeLower + ';\n';
260260
} else if (targetAttribute === 'TANGENT') {
261-
vertexShaderMain += ' weightedTangent += u_morphWeights[' + k + '] * a_' + attributeLower + ';\n';
261+
vertexShaderMain += ' weightedTangent.xyz += u_morphWeights[' + k + '] * a_' + attributeLower + ';\n';
262262
}
263263
}
264264
}
@@ -305,13 +305,14 @@ define([
305305
techniqueAttributes.a_tangent = 'tangent';
306306
techniqueParameters.tangent = {
307307
semantic : 'TANGENT',
308-
type : WebGLConstants.FLOAT_VEC3
308+
type : WebGLConstants.FLOAT_VEC4
309309
};
310-
vertexShader += 'attribute vec3 a_tangent;\n';
311-
vertexShader += 'varying vec3 v_tangent;\n';
312-
vertexShaderMain += ' v_tangent = (u_modelViewMatrix * vec4(weightedTangent, 1.0)).xyz;\n';
310+
vertexShader += 'attribute vec4 a_tangent;\n';
311+
vertexShader += 'varying vec4 v_tangent;\n';
312+
vertexShaderMain += ' v_tangent.xyz = u_normalMatrix * weightedTangent.xyz;\n';
313+
vertexShaderMain += ' v_tangent.w = weightedTangent.w;\n';
313314

314-
fragmentShader += 'varying vec3 v_tangent;\n';
315+
fragmentShader += 'varying vec4 v_tangent;\n';
315316
}
316317

317318
// Add texture coordinates if the material uses them
@@ -420,8 +421,8 @@ define([
420421
if (defined(parameterValues.normalTexture)) {
421422
if (hasTangents) {
422423
// Read tangents from varying
423-
fragmentShader += ' vec3 t = normalize(v_tangent);\n';
424-
fragmentShader += ' vec3 b = normalize(cross(ng, t));\n';
424+
fragmentShader += ' vec3 t = normalize(v_tangent.xyz);\n';
425+
fragmentShader += ' vec3 b = normalize(cross(ng, t) * v_tangent.w);\n';
425426
fragmentShader += ' mat3 tbn = mat3(t, b, ng);\n';
426427
fragmentShader += ' vec3 n = texture2D(u_normalTexture, ' + v_texcoord + ').rgb;\n';
427428
fragmentShader += ' n = normalize(tbn * (2.0 * n - 1.0));\n';

0 commit comments

Comments
 (0)