From 78a5e5b4e8efa635c9caf624c148f840a1ac8b9f Mon Sep 17 00:00:00 2001 From: Dominic Masters Date: Tue, 4 Apr 2023 22:27:27 -0700 Subject: [PATCH] Fixed the billboard shader to be what I intended from the start. --- .../display/shader/SimpleBillboardedShader.cpp | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/dawnopengl/display/shader/SimpleBillboardedShader.cpp b/src/dawnopengl/display/shader/SimpleBillboardedShader.cpp index 37da2400..95d62b37 100644 --- a/src/dawnopengl/display/shader/SimpleBillboardedShader.cpp +++ b/src/dawnopengl/display/shader/SimpleBillboardedShader.cpp @@ -27,10 +27,13 @@ void SimpleBillboardedShaderProgram::compile() { "out vec2 o_TextCoord;\n" "void main() {\n" - "vec3 camRight = vec3(u_View[0][0], u_View[1][0], u_View[2][0]);\n" - "vec3 camUp = vec3(u_View[0][1], u_View[1][1], u_View[2][1]);\n" - "vec3 billboardPos = u_View[3].xyz + aPos.x * camRight + aPos.y * camUp;\n" - "gl_Position = u_Proj * u_View * u_Model * vec4(billboardPos, 1.0);\n" + "vec3 billboardPos = u_Model[3].xyz;\n" + "vec3 viewDirection = normalize(billboardPos - u_View[3].xyz);\n" + "vec3 up = normalize(vec3(0, 1, 0));\n" + "vec3 right = normalize(cross(up, viewDirection));\n" + "up = normalize(cross(viewDirection, right));\n" + "vec3 billboardPosCam = vec3(u_View * vec4(billboardPos, 1.0));\n" + "gl_Position = u_Proj * vec4(billboardPosCam + (right * aPos.x + up * aPos.y), 1.0);\n" "o_TextCoord = vec2(aTexCoord.x, aTexCoord.y);\n" "}",