From b02900478f3e8a56b707ee2d0647ae53f8d29de0 Mon Sep 17 00:00:00 2001 From: Marcus Brummer Date: Mon, 7 Dec 2020 22:02:17 +0100 Subject: [PATCH] Fixed the inverse(mat3) polyfill for GLES2 --- drivers/gles2/shaders/stdlib.glsl | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/drivers/gles2/shaders/stdlib.glsl b/drivers/gles2/shaders/stdlib.glsl index 9c744187430..0ba19536fcc 100644 --- a/drivers/gles2/shaders/stdlib.glsl +++ b/drivers/gles2/shaders/stdlib.glsl @@ -309,11 +309,15 @@ highp mat2 inverse(highp mat2 m) { } highp mat3 inverse(highp mat3 m) { - highp float d = 1.0 / (m[0].x * (m[1].y * m[2].z - m[2].y * m[1].z) - m[1].x * (m[0].y * m[2].z - m[2].y * m[0].z) + m[2].x * (m[0].y * m[1].z - m[1].y * m[0].z)); - return mat3( - vec3((m[1].y * m[2].z - m[2].y * m[1].z), -(m[1].x * m[2].z - m[2].x * m[1].z), (m[1].x * m[2].y - m[2].x * m[1].y)) * d, - vec3(-(m[0].y * m[2].z - m[2].y * m[0].z), (m[0].x * m[2].z - m[2].x * m[0].z), -(m[0].x * m[2].y - m[2].x * m[0].y)) * d, - vec3((m[0].y * m[1].z - m[1].y * m[0].z), -(m[0].x * m[1].z - m[1].x * m[0].z), (m[0].x * m[1].y - m[1].x * m[0].y)) * d); + highp float c01 = m[2].z * m[1].y - m[1].z * m[2].y; + highp float c11 = -m[2].z * m[1].x + m[1].z * m[2].x; + highp float c21 = m[2].y * m[1].x - m[1].y * m[2].x; + highp float d = 1.0 / (m[0].x * c01 + m[0].y * c11 + m[0].z * c21); + + return mat3(c01, (-m[2].z * m[0].y + m[0].z * m[2].y), (m[1].z * m[0].y - m[0].z * m[1].y), + c11, (m[2].z * m[0].x - m[0].z * m[2].x), (-m[1].z * m[0].x + m[0].z * m[1].x), + c21, (-m[2].y * m[0].x + m[0].y * m[2].x), (m[1].y * m[0].x - m[0].y * m[1].x)) * + d; } highp mat4 inverse(highp mat4 m) {