// Copyright (c) 2023 Dominic Masters // // This software is released under the MIT License. // https://opensource.org/licenses/MIT #include "SimpleBillboardedShader.hpp" using namespace Dawn; void SimpleBillboardedShader::compile() { #if DAWN_OPENGL_GLSL this->compileShader( { { "aPos", 0 }, { "aTexCoord", 1 } }, // Vertex Shader "#version 330 core\n" "layout (location = 0) in vec3 aPos;\n" "layout (location = 1) in vec2 aTexCoord;\n" "uniform mat4 u_Proj;\n" "uniform mat4 u_View;\n" "uniform mat4 u_Model;\n" "out vec2 o_TextCoord;\n" "void main() {\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" "}", // Fragment Shader "#version 330 core\n" "in vec2 o_TextCoord;\n" "out vec4 o_Color;\n" "uniform vec4 u_Color;\n" "uniform bool u_HasTexture;\n" "uniform sampler2D u_Text;\n" "void main() {\n" "if(u_HasTexture) {\n" "o_Color = texture(u_Text, o_TextCoord) * u_Color;\n" "} else {\n" "o_Color = u_Color;" "}\n" "}\n" ); #endif this->paramProjection = this->getParameterByName("u_Proj"); this->paramView = this->getParameterByName("u_View"); this->paramModel = this->getParameterByName("u_Model"); this->paramColor = this->getParameterByName("u_Color"); this->paramTexture = this->getParameterByName("u_Text"); this->paramHasTexture = this->getParameterByName("u_HasTexture"); }