From ba452b41c9e3cb0a039ddf0a9e3ba30808c29fc5 Mon Sep 17 00:00:00 2001 From: Jeremy HU Date: Wed, 21 Sep 2022 22:14:02 +1000 Subject: [PATCH] Show plain color without any light --- application/shaders/model_core.frag | 9 +++++++-- application/shaders/model_core.vert | 18 +++++++++++++++++- application/sources/model_widget.cc | 5 +++-- 3 files changed, 27 insertions(+), 5 deletions(-) diff --git a/application/shaders/model_core.frag b/application/shaders/model_core.frag index f50d46e2..c2970b21 100644 --- a/application/shaders/model_core.frag +++ b/application/shaders/model_core.frag @@ -1,7 +1,12 @@ #version 330 -uniform vec4 defaultColor; +in vec3 pointPosition; +in vec3 pointNormal; +in vec3 pointColor; +in float pointAlpha; +in float pointMetalness; +in float pointRoughness; out vec4 fragColor; void main() { - fragColor = defaultColor; + fragColor = vec4(pointColor, pointAlpha); } \ No newline at end of file diff --git a/application/shaders/model_core.vert b/application/shaders/model_core.vert index 13829aeb..9a70ba6e 100644 --- a/application/shaders/model_core.vert +++ b/application/shaders/model_core.vert @@ -10,7 +10,23 @@ layout(location = 7) in float alpha; uniform mat4 modelMatrix; uniform mat4 viewMatrix; uniform mat4 projectionMatrix; +uniform vec3 lightDirection; +uniform vec3 eyePosition; +out vec3 pointPosition; +out vec3 pointNormal; +out vec3 pointColor; +out float pointAlpha; +out float pointMetalness; +out float pointRoughness; + void main() { - gl_Position = projectionMatrix * viewMatrix * modelMatrix * vertex; + pointPosition = (modelMatrix * vertex).xyz; + pointNormal = normalize((modelMatrix * vec4(normal, 1.0)).xyz); + pointColor = color; + pointAlpha = alpha; + pointMetalness = metalness; + pointRoughness = roughness; + + gl_Position = projectionMatrix * viewMatrix * vec4(pointPosition, 1.0); } \ No newline at end of file diff --git a/application/sources/model_widget.cc b/application/sources/model_widget.cc index 2f96026f..1ab0f021 100644 --- a/application/sources/model_widget.cc +++ b/application/sources/model_widget.cc @@ -176,14 +176,15 @@ void ModelWidget::paintGL() m_openGLProgram->bind(); + m_openGLProgram->setUniformValue(m_openGLProgram->getUniformLocationByName("eyePosition"), m_eyePosition); + m_openGLProgram->setUniformValue(m_openGLProgram->getUniformLocationByName("lightDirection"), QVector3D(-1.0, -1.0, -1.0).normalized()); m_openGLProgram->setUniformValue(m_openGLProgram->getUniformLocationByName("projectionMatrix"), m_projection); m_openGLProgram->setUniformValue(m_openGLProgram->getUniformLocationByName("modelMatrix"), m_world); m_openGLProgram->setUniformValue(m_openGLProgram->getUniformLocationByName("viewMatrix"), m_camera); - m_openGLProgram->setUniformValue(m_openGLProgram->getUniformLocationByName("defaultColor"), QVector4D(1.0, 1.0, 1.0, 1.0)); if (m_openGLObject) m_openGLObject->draw(); - + m_openGLProgram->release(); }