1
0
Fork 0

Implement sun for program "textured"

This commit is contained in:
Meoweg 2015-11-14 08:31:56 +00:00
parent 259fd81271
commit 57cfc83b9f
3 changed files with 7 additions and 1 deletions

View File

@ -7,10 +7,11 @@ varying float light_weight;
uniform mat4 mvp;
uniform mat3 local_modelview;
uniform vec3 sun_direction;
void main(void) {
gl_Position = mvp * position;
f_tex_coord = tex_coord;
vec3 transformed_normal = local_modelview * normal;
light_weight = max(dot(transformed_normal, vec3(0.0, 1.0, 0.0)), 0.0);
light_weight = max(dot(transformed_normal, -sun_direction), 0.0);
}

View File

@ -2,6 +2,7 @@
#include "../mtllib.hpp"
#include "../program.hpp"
#include "../scene.hpp"
#include <vector>
#include <fstream>
@ -21,6 +22,7 @@ const GLchar *const Static::attribs[] = {
const GLchar *const Static::uniforms[] = {
"mvp",
"local_modelview",
"sun_direction",
};
const std::string Static::filename(const std::string &name)
@ -133,6 +135,8 @@ void Static::draw(const Scene &scene, const glm::mat4 &mvp, const glm::mat4 &tra
const glm::mat3 local_modelview = glm::transpose(glm::inverse(glm::mat3(transformation)));
glUniformMatrix3fv(exe->uniform(Uniform::local_modelview), 1, GL_FALSE, glm::value_ptr(local_modelview));
glUniform3fv(exe->uniform(Uniform::sun_direction), 1, glm::value_ptr(scene.sun()->direction));
_material->use();
glEnableVertexAttribArray(position);

View File

@ -41,6 +41,7 @@ namespace Models
{
mvp,
local_modelview,
sun_direction,
__uniform_count
};