From 2ecf3bd14c15cc5975b634e9eaeb1d8b0b87c619 Mon Sep 17 00:00:00 2001 From: Linloir <3145078758@qq.com> Date: Sat, 17 Dec 2022 21:51:50 +0800 Subject: [PATCH] [CORE][CHG] Illuminer API --- FinalProject/FinalProject.vcxproj | 4 +- FinalProject/FinalProject.vcxproj.filters | 8 ++- FinalProject/illuminant.h | 24 ------- FinalProject/illuminer.h | 84 +++++++++++++++++++++++ FinalProject/mainwindow.qrc | 2 + 5 files changed, 96 insertions(+), 26 deletions(-) delete mode 100644 FinalProject/illuminant.h create mode 100644 FinalProject/illuminer.h diff --git a/FinalProject/FinalProject.vcxproj b/FinalProject/FinalProject.vcxproj index 2df4171..2722289 100644 --- a/FinalProject/FinalProject.vcxproj +++ b/FinalProject/FinalProject.vcxproj @@ -143,7 +143,7 @@ - + @@ -168,6 +168,8 @@ + + diff --git a/FinalProject/FinalProject.vcxproj.filters b/FinalProject/FinalProject.vcxproj.filters index 6a5c503..8190b67 100644 --- a/FinalProject/FinalProject.vcxproj.filters +++ b/FinalProject/FinalProject.vcxproj.filters @@ -212,7 +212,7 @@ Header Files\OpenGL Abstractions - + Header Files\OpenGL Abstractions @@ -267,5 +267,11 @@ Resource Files + + Resource Files + + + Resource Files + \ No newline at end of file diff --git a/FinalProject/illuminant.h b/FinalProject/illuminant.h deleted file mode 100644 index 0eda181..0000000 --- a/FinalProject/illuminant.h +++ /dev/null @@ -1,24 +0,0 @@ -#pragma once - -#include -#include -#include - -#include "shader.h" -#include "logger.h" - -class Illuminant { - -}; - -class DirLight : public Illuminant { - -}; - -class SpotLight : public Illuminant { - -}; - -class PointLight : public Illuminant { - -}; \ No newline at end of file diff --git a/FinalProject/illuminer.h b/FinalProject/illuminer.h new file mode 100644 index 0000000..8fd1524 --- /dev/null +++ b/FinalProject/illuminer.h @@ -0,0 +1,84 @@ +#pragma once + +#include +#include +#include + +#include "shader.h" +#include "logger.h" + +class Illuminer { +protected: + glm::vec3 _lightColor; + +public: + Illuminer(glm::vec3 color); + ~Illuminer(); + +public: + virtual glm::vec3 ambientLightColor() const = 0; + virtual glm::vec3 diffuseLightColor() const = 0; + virtual glm::vec3 specularLightColor() const = 0; + + virtual void updateShader(ShaderProgram shader) const = 0; + +public: + glm::vec3 lightColor() const { return _lightColor; } + void setLightColor(glm::vec3 lightColor) { _lightColor = lightColor; } +}; + +// Direction light +class DirLight : public Illuminer{ +protected: + glm::vec3 _direction; // The outgoing direction of the light source + +public: + DirLight(glm::vec3 direction = glm::vec3(0.0f, -1.0f, 0.0f), glm::vec3 color = glm::vec3(1.0f)); + ~DirLight(); + +public: + // Getter APIs + glm::vec3 lightDirection() const { return _direction; } // The same direction as the outgoing direction + + // Setter + void setLightDirection(glm::vec3 direction) { _direction = direction; } + + // Render util function + virtual void updateShader(ShaderProgram shader) const override; +}; + +// Scoped Light is a combination of point light and spot light +// Shader setting is automatically configured based on the phi value +// If phi < 162.5, then the light is considered as spot light +// Otherwise it's considered as point light +class ScopedLight : public Illuminer{ +protected: + // Light source status + glm::vec3 _position; + glm::vec3 _direction; + float _innerCutOffAngle = 162.5f; + float _outerCutOffAngle = 180.0f; + + // Light property + int _idealDistance = 32; // ideally calculated distance + const float _attConstant = 1.0f; // attenuation constant + float _attLinear = 0.14f; // attenuation linear term + float _attQuadratic = 0.07f; // attenuation quad term + +public: + ScopedLight(glm::vec3 position, glm::vec3 direction = glm::vec3(0.0f, -1.0f, 0.0f), glm::vec3 color = glm::vec3(1.0f)); + ScopedLight(glm::vec3 distance, glm::vec3 position, glm::vec3 direction = glm::vec3(0.0f, -1.0f, 0.0f), glm::vec3 color = glm::vec3(1.0f)); + ~ScopedLight(); + +public: + // Property setters and getters + int idealDistance() const { return _idealDistance; } + void setIdealDistance(int distance); + glm::vec3 lightDirection() const { return _direction; } + void setLightDirection(glm::vec3 direction) { _direction = direction; } + float cutOffAngle() const { return _outerCutOffAngle; } + void setCutOffAngle(float angle); + + // Render util function + virtual void updateShader(ShaderProgram shader) const override; +}; \ No newline at end of file diff --git a/FinalProject/mainwindow.qrc b/FinalProject/mainwindow.qrc index 0a9d314..160a689 100644 --- a/FinalProject/mainwindow.qrc +++ b/FinalProject/mainwindow.qrc @@ -2,6 +2,8 @@ fragmentshader.fs vertexshader.vs + illuminant.fs + illuminant.vs font_awesome_6_regular_free.otf