mirror of
https://github.com/Linloir/SceneEditor.git
synced 2025-12-17 07:28:12 +08:00
[CORE][CHG] Update illuminer API
- Add logger to 'updateShader' func - Add 'toWorldSpace' transform
This commit is contained in:
parent
032d346151
commit
05a5494693
@ -23,14 +23,20 @@ void DirLight::updateShader(ShaderProgram shader, int index) const {
|
|||||||
// vec3 specular;
|
// vec3 specular;
|
||||||
// };
|
// };
|
||||||
|
|
||||||
shader.setUniform("dirlights[" + std::to_string(index) + "].direction", -_direction);
|
Logger::debug("Setting dir light " + std::to_string(index) + " to shader");
|
||||||
|
Logger::debug("[+] Direction: " + std::to_string(_direction.x) + ", " + std::to_string(_direction.y) + ", " + std::to_string(_direction.z));
|
||||||
|
Logger::debug("[+] Ambient: " + std::to_string(ambientLightColor().x) + ", " + std::to_string(ambientLightColor().y) + ", " + std::to_string(ambientLightColor().z));
|
||||||
|
Logger::debug("[+] Diffuse: " + std::to_string(diffuseLightColor().x) + ", " + std::to_string(diffuseLightColor().y) + ", " + std::to_string(diffuseLightColor().z));
|
||||||
|
Logger::debug("[+] Specular: " + std::to_string(specularLightColor().x) + ", " + std::to_string(specularLightColor().y) + ", " + std::to_string(specularLightColor().z));
|
||||||
|
|
||||||
|
shader.setUniform("dirlights[" + std::to_string(index) + "].direction", _direction);
|
||||||
shader.setUniform("dirlights[" + std::to_string(index) + "].ambient", ambientLightColor());
|
shader.setUniform("dirlights[" + std::to_string(index) + "].ambient", ambientLightColor());
|
||||||
shader.setUniform("dirlights[" + std::to_string(index) + "].diffuse", diffuseLightColor());
|
shader.setUniform("dirlights[" + std::to_string(index) + "].diffuse", diffuseLightColor());
|
||||||
shader.setUniform("dirlights[" + std::to_string(index) + "].specular", specularLightColor());
|
shader.setUniform("dirlights[" + std::to_string(index) + "].specular", specularLightColor());
|
||||||
}
|
}
|
||||||
|
|
||||||
ScopedLight::ScopedLight(glm::vec3 position, glm::vec3 direction, glm::vec3 color) :
|
ScopedLight::ScopedLight(glm::vec3 position, glm::vec3 direction, glm::vec3 color) :
|
||||||
Illuminer(color), _position(position), _direction(direction)
|
Illuminer(color), _position(position), _direction(direction), _idealDistance(32)
|
||||||
{
|
{
|
||||||
updateLinear();
|
updateLinear();
|
||||||
updateQuadratic();
|
updateQuadratic();
|
||||||
@ -43,6 +49,10 @@ ScopedLight::ScopedLight(int distance, glm::vec3 position, glm::vec3 direction,
|
|||||||
updateQuadratic();
|
updateQuadratic();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ScopedLight::ScopedLight(glm::vec3 position, glm::vec3 direction, float cutOffAngle, int idealDistance, float linear, float quadratic, glm::vec3 color) :
|
||||||
|
Illuminer(color), _position(position), _direction(direction), _cutOffAngle(cutOffAngle), _idealDistance(idealDistance), _attLinear(linear), _attQuadratic(quadratic)
|
||||||
|
{}
|
||||||
|
|
||||||
ScopedLight::~ScopedLight() {}
|
ScopedLight::~ScopedLight() {}
|
||||||
|
|
||||||
inline void ScopedLight::updateLinear() {
|
inline void ScopedLight::updateLinear() {
|
||||||
@ -58,8 +68,8 @@ inline void ScopedLight::updateQuadratic() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void ScopedLight::setIdealDistance(int distance) {
|
void ScopedLight::setIdealDistance(int distance) {
|
||||||
if (distance < 10) {
|
if (distance < 5) {
|
||||||
distance = 10;
|
distance = 5;
|
||||||
}
|
}
|
||||||
if (distance > 3500) {
|
if (distance > 3500) {
|
||||||
distance = 3500;
|
distance = 3500;
|
||||||
@ -83,6 +93,12 @@ inline float ScopedLight::innerCutOffAngle() const {
|
|||||||
return 0.0011 * glm::pow(_cutOffAngle, 2) + 0.6440 * _cutOffAngle;
|
return 0.0011 * glm::pow(_cutOffAngle, 2) + 0.6440 * _cutOffAngle;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ScopedLight ScopedLight::toWorldSpace(glm::mat4 modelMatrix) const {
|
||||||
|
glm::vec3 position = glm::vec3(modelMatrix * glm::vec4(_position, 1.0f));
|
||||||
|
glm::vec3 direction = glm::vec3(modelMatrix * glm::vec4(_direction, 0.0f));
|
||||||
|
return ScopedLight(position, direction, _cutOffAngle, _idealDistance, _attLinear, _attQuadratic, _lightColor);
|
||||||
|
}
|
||||||
|
|
||||||
void ScopedLight::updateShader(ShaderProgram shader, int index) const {
|
void ScopedLight::updateShader(ShaderProgram shader, int index) const {
|
||||||
// Recall PointLight and SpotLight structure in fragment shader
|
// Recall PointLight and SpotLight structure in fragment shader
|
||||||
// -------------
|
// -------------
|
||||||
@ -112,6 +128,13 @@ void ScopedLight::updateShader(ShaderProgram shader, int index) const {
|
|||||||
// Check the cutoff angle to determine the type of light
|
// Check the cutoff angle to determine the type of light
|
||||||
if (abs(_cutOffAngle - 180.0f) < 1e-6) {
|
if (abs(_cutOffAngle - 180.0f) < 1e-6) {
|
||||||
// Point light
|
// Point light
|
||||||
|
Logger::debug("Setting point light " + std::to_string(index) + " to shader");
|
||||||
|
Logger::debug("[+] Position: " + std::to_string(_position.x) + ", " + std::to_string(_position.y) + ", " + std::to_string(_position.z));
|
||||||
|
Logger::debug("[+] Ambient: " + std::to_string(ambientLightColor().x) + ", " + std::to_string(ambientLightColor().y) + ", " + std::to_string(ambientLightColor().z));
|
||||||
|
Logger::debug("[+] Diffuse: " + std::to_string(diffuseLightColor().x) + ", " + std::to_string(diffuseLightColor().y) + ", " + std::to_string(diffuseLightColor().z));
|
||||||
|
Logger::debug("[+] Specular: " + std::to_string(specularLightColor().x) + ", " + std::to_string(specularLightColor().y) + ", " + std::to_string(specularLightColor().z));
|
||||||
|
Logger::debug("[+] Linear: " + std::to_string(_attLinear));
|
||||||
|
Logger::debug("[+] Quadratic: " + std::to_string(_attQuadratic));
|
||||||
shader.setUniform("pointlights[" + std::to_string(index) + "].position", _position);
|
shader.setUniform("pointlights[" + std::to_string(index) + "].position", _position);
|
||||||
shader.setUniform("pointlights[" + std::to_string(index) + "].ambient", ambientLightColor());
|
shader.setUniform("pointlights[" + std::to_string(index) + "].ambient", ambientLightColor());
|
||||||
shader.setUniform("pointlights[" + std::to_string(index) + "].diffuse", diffuseLightColor());
|
shader.setUniform("pointlights[" + std::to_string(index) + "].diffuse", diffuseLightColor());
|
||||||
@ -122,8 +145,18 @@ void ScopedLight::updateShader(ShaderProgram shader, int index) const {
|
|||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
// Spot light
|
// Spot light
|
||||||
|
Logger::debug("Setting spot light " + std::to_string(index) + " to shader");
|
||||||
|
Logger::debug("[+] Position: " + std::to_string(_position.x) + ", " + std::to_string(_position.y) + ", " + std::to_string(_position.z));
|
||||||
|
Logger::debug("[+] Direction: " + std::to_string(_direction.x) + ", " + std::to_string(_direction.y) + ", " + std::to_string(_direction.z));
|
||||||
|
Logger::debug("[+] Ambient: " + std::to_string(ambientLightColor().x) + ", " + std::to_string(ambientLightColor().y) + ", " + std::to_string(ambientLightColor().z));
|
||||||
|
Logger::debug("[+] Diffuse: " + std::to_string(diffuseLightColor().x) + ", " + std::to_string(diffuseLightColor().y) + ", " + std::to_string(diffuseLightColor().z));
|
||||||
|
Logger::debug("[+] Specular: " + std::to_string(specularLightColor().x) + ", " + std::to_string(specularLightColor().y) + ", " + std::to_string(specularLightColor().z));
|
||||||
|
Logger::debug("[+] Linear: " + std::to_string(_attLinear));
|
||||||
|
Logger::debug("[+] Quadratic: " + std::to_string(_attQuadratic));
|
||||||
|
Logger::debug("[+] CutOff: " + std::to_string(_cutOffAngle));
|
||||||
|
Logger::debug("[+] InnerCutOff: " + std::to_string(innerCutOffAngle()));
|
||||||
shader.setUniform("spotlights[" + std::to_string(index) + "].position", _position);
|
shader.setUniform("spotlights[" + std::to_string(index) + "].position", _position);
|
||||||
shader.setUniform("spotlights[" + std::to_string(index) + "].direction", -_direction);
|
shader.setUniform("spotlights[" + std::to_string(index) + "].direction", _direction);
|
||||||
shader.setUniform("spotlights[" + std::to_string(index) + "].ambient", ambientLightColor());
|
shader.setUniform("spotlights[" + std::to_string(index) + "].ambient", ambientLightColor());
|
||||||
shader.setUniform("spotlights[" + std::to_string(index) + "].diffuse", diffuseLightColor());
|
shader.setUniform("spotlights[" + std::to_string(index) + "].diffuse", diffuseLightColor());
|
||||||
shader.setUniform("spotlights[" + std::to_string(index) + "].specular", specularLightColor());
|
shader.setUniform("spotlights[" + std::to_string(index) + "].specular", specularLightColor());
|
||||||
|
|||||||
@ -36,9 +36,9 @@ public:
|
|||||||
~DirLight();
|
~DirLight();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual glm::vec3 ambientLightColor() const override { return _lightColor * 0.2f; }
|
virtual glm::vec3 ambientLightColor() const override { return glm::vec3(0.2f) * _lightColor; }
|
||||||
virtual glm::vec3 diffuseLightColor() const override { return _lightColor * 0.5f; }
|
virtual glm::vec3 diffuseLightColor() const override { return glm::vec3(0.6f) * _lightColor; }
|
||||||
virtual glm::vec3 specularLightColor() const override { return _lightColor * 0.9f; }
|
virtual glm::vec3 specularLightColor() const override { return glm::vec3(1.0f) * _lightColor; }
|
||||||
|
|
||||||
public:
|
public:
|
||||||
glm::vec3 lightDirection() const { return _direction; } // The same direction as the outgoing direction
|
glm::vec3 lightDirection() const { return _direction; } // The same direction as the outgoing direction
|
||||||
@ -66,8 +66,9 @@ protected:
|
|||||||
float _attQuadratic = 0.07f; // attenuation quad term
|
float _attQuadratic = 0.07f; // attenuation quad term
|
||||||
|
|
||||||
public:
|
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 position, glm::vec3 direction = glm::vec3(0.0f, -1.0f, 0.0f), glm::vec3 color = glm::vec3(1.0f, 1.0f, 1.0f));
|
||||||
ScopedLight(int distance, glm::vec3 position, glm::vec3 direction = glm::vec3(0.0f, -1.0f, 0.0f), glm::vec3 color = glm::vec3(1.0f));
|
ScopedLight(int distance, glm::vec3 position, glm::vec3 direction = glm::vec3(0.0f, -1.0f, 0.0f), glm::vec3 color = glm::vec3(1.0f, 1.0f, 1.0f));
|
||||||
|
ScopedLight(glm::vec3 position, glm::vec3 direction, float cutOffAngle, int idealDistance, float linear, float quadratic, glm::vec3 color);
|
||||||
~ScopedLight();
|
~ScopedLight();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
@ -77,9 +78,9 @@ private:
|
|||||||
inline float innerCutOffAngle() const;
|
inline float innerCutOffAngle() const;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual glm::vec3 ambientLightColor() const override { return _lightColor * 0.2f; }
|
virtual glm::vec3 ambientLightColor() const override { return glm::vec3(0.2f) * _lightColor; }
|
||||||
virtual glm::vec3 diffuseLightColor() const override { return _lightColor * 0.5f; }
|
virtual glm::vec3 diffuseLightColor() const override { return glm::vec3(0.7f) * _lightColor; }
|
||||||
virtual glm::vec3 specularLightColor() const override { return _lightColor * 0.9f; }
|
virtual glm::vec3 specularLightColor() const override { return glm::vec3(1.0f) * _lightColor; }
|
||||||
|
|
||||||
public:
|
public:
|
||||||
// Property setters and getters
|
// Property setters and getters
|
||||||
@ -90,6 +91,10 @@ public:
|
|||||||
float cutOffAngle() const { return _cutOffAngle; }
|
float cutOffAngle() const { return _cutOffAngle; }
|
||||||
void setCutOffAngle(float angle);
|
void setCutOffAngle(float angle);
|
||||||
|
|
||||||
|
bool isPointLight() const { return abs(_cutOffAngle - 180.0f) < 1e-6; }
|
||||||
|
|
||||||
|
ScopedLight toWorldSpace(glm::mat4 modelMatrix) const;
|
||||||
|
|
||||||
// Render util function
|
// Render util function
|
||||||
virtual void updateShader(ShaderProgram shader, int index) const override;
|
virtual void updateShader(ShaderProgram shader, int index) const override;
|
||||||
};
|
};
|
||||||
Loading…
x
Reference in New Issue
Block a user