Skip to content
Snippets Groups Projects
Commit 1c962a48 authored by Anakin's avatar Anakin
Browse files

implemented light into cpp,

bug:
everything is dark,
need to calculate the normal matrix once in cpp and not for every pixel
parent 86c0559f
No related branches found
No related tags found
No related merge requests found
......@@ -37,6 +37,11 @@ private:
bool z = true;
} m_rotDirections;
struct {
QVector3D position = { 1,1,1 };
QVector3D intensities = { 1,1,1 };
} m_light;
QOpenGLShaderProgram m_program;
GeometryEngine *m_dataEngine;
......
......@@ -6,6 +6,7 @@ precision mediump float;
uniform mat3 n_matrix;
uniform sampler2D texture;
uniform mat4 m_matrix;
uniform struct Light {
vec3 position;
......@@ -20,7 +21,7 @@ varying vec3 v_normal;
void main()
{
mat3 normalMatrix = transpose(inverse(mat3(m_matrix)));
vec3 normal = normalize(n_matrix * v_normal);
vec3 surfaceToLight = light.position - v_position;
......
......@@ -225,6 +225,10 @@ void OglViewerWidget::paintGL()
// Set view-projection matrix
m_program.setUniformValue("vp_matrix", m_projection * view);
// Set Light
m_program.setUniformValue("light.position", m_light.position);
m_program.setUniformValue("light.intensities", m_light.intensities);
// Draw cube geometry
m_dataEngine->drawGeometry(&m_program, m_wireframe);
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment