hge::shader::SunShader::SunShader(const glm::vec3 &sunDirection): shaderProgram(render::ShaderEngine::createProgram()) { std::string pVS( "#version 430\n" "layout (location = 0) in vec3 vertex;" //All of the normals must be normalized. "layout (location = 1) in vec3 normal;" "layout (location = 2) in vec2 uv;" "out vec2 outUV;" "out float lightIntensity;" "uniform mat4 mvp;" "uniform mat4 m;" //Sun direction must be normalized. "uniform vec3 s;" "void main()" "{" "lightIntensity = float(max(float(dot(s, vec3(m * vec4(normal, 1.0)))), 0.1));" "gl_Position = mvp * vec4(vertex, 1.0);" "outUV = uv;" "}"); /////////////////////////////////////////////////////////////////////// std::string pFS( "#version 430\n" "in vec2 outUV;" "out vec4 fragColor;" "in float lightIntensity;" "uniform sampler2D textureSampler;" "void main()" "{" "fragColor=texture2D(textureSampler,outUV.xy)*lightIntensity;" "};"); /////////////////////////////////////////////////////////////////////// vertexShaderProgram = render::ShaderEngine::addShaderToProgram(pVS, GL_VERTEX_SHADER, shaderProgram); fragmentShaderProgram = render::ShaderEngine::addShaderToProgram(pFS, GL_FRAGMENT_SHADER, shaderProgram); hge::render::ShaderEngine::run(shaderProgram); modelMatrixUniformLocation = render::ShaderEngine::getUniformLocation(std::string("m"), shaderProgram); assert(modelMatrixUniformLocation != 0xFFFFFFFF); modelViewProjectionMatrixUniformLocation = render::ShaderEngine::getUniformLocation(std::string("mvp"), shaderProgram); assert(modelViewProjectionMatrixUniformLocation != 0xFFFFFFFF); sunLightDirectionUniformLocation = render::ShaderEngine::getUniformLocation(std::string("s"), shaderProgram); assert(sunLightDirectionUniformLocation != 0xFFFFFFFF); textureSamplerLocation = render::ShaderEngine::getUniformLocation(std::string("textureSampler"), shaderProgram); assert(textureSamplerLocation != 0xFFFFFFFF); glUniform1i(textureSamplerLocation, 0); }
void CMesh::VertexShade(VERTEX(*pVS)(VERTEX V)) { for (size_t i = 0; i < m_Vertices.size(); i++) m_Vertices[i] = pVS(m_Vertices[i]); }