From 89cf5fe86e33b389c48bde75454eb2fb0def8bad Mon Sep 17 00:00:00 2001 From: "Eunki, Hong" Date: Wed, 10 May 2023 10:35:07 +0900 Subject: [PATCH] Fix normal vector error when we use skin Since dali's world matrix use left-hand-coordinate, the constrainted world matrix value in uBone need to be multiply negative Y. To apply this information, let we use uYDirection value if we use skin. Also, we need to use same precision if we use same uniform both vertex and fragment shaders. To specify the precision, make uYDirection as mediump. Change-Id: Ibf6ca7ee0cc88fba1214b4a68a0eea7a4805f7e5 Signed-off-by: Eunki, Hong --- .../graphics/shaders/default-physically-based-shader.frag | 2 +- .../graphics/shaders/default-physically-based-shader.vert | 9 +++++---- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/dali-scene3d/internal/graphics/shaders/default-physically-based-shader.frag b/dali-scene3d/internal/graphics/shaders/default-physically-based-shader.frag index bfcc18b..e701162 100644 --- a/dali-scene3d/internal/graphics/shaders/default-physically-based-shader.frag +++ b/dali-scene3d/internal/graphics/shaders/default-physically-based-shader.frag @@ -77,7 +77,7 @@ uniform sampler2D sbrdfLUT; uniform samplerCube sDiffuseEnvSampler; uniform samplerCube sSpecularEnvSampler; uniform float uIblIntensity; -uniform vec3 uYDirection; +uniform mediump vec3 uYDirection; uniform float uMaxLOD; // For Alpha Mode. diff --git a/dali-scene3d/internal/graphics/shaders/default-physically-based-shader.vert b/dali-scene3d/internal/graphics/shaders/default-physically-based-shader.vert index 5b48af0..8ca91ea 100644 --- a/dali-scene3d/internal/graphics/shaders/default-physically-based-shader.vert +++ b/dali-scene3d/internal/graphics/shaders/default-physically-based-shader.vert @@ -41,6 +41,7 @@ uniform mat4 uProjection; in vec4 aWeights; #define MAX_BONES 64 uniform mat4 uBone[MAX_BONES]; + uniform mediump vec3 uYDirection; #endif #ifdef MORPH @@ -141,10 +142,8 @@ void main() uBone[int(aJoints.z)] * aWeights.z + uBone[int(aJoints.w)] * aWeights.w; position = bone * position; - normal = (bone * vec4(normal, 0.0)).xyz; - tangent = (bone * vec4(tangent, 0.0)).xyz; - normal = normalize(normal); - tangent = normalize(tangent); + normal = uYDirection * (bone * vec4(normal, 0.0)).xyz; + tangent = uYDirection * (bone * vec4(tangent, 0.0)).xyz; highp vec4 positionW = position; #else @@ -154,6 +153,8 @@ void main() vPositionToCamera = transpose(mat3(uViewMatrix)) * -vec3(positionV.xyz / positionV.w); + normal = normalize(normal); + tangent = normalize(tangent); vec3 bitangent = cross(normal, tangent); #ifdef VEC4_TANGENT bitangent *= aTangent.w; -- 2.7.4