[CORE][FIX] Fix illuminer shader update API

- Add index parameter
This commit is contained in:
Linloir 2022-12-17 22:40:52 +08:00
parent 9604e68aa4
commit b2bcba75ea
No known key found for this signature in database
GPG Key ID: 58EEB209A0F2C366
2 changed files with 26 additions and 26 deletions

View File

@ -13,7 +13,7 @@ DirLight::DirLight(glm::vec3 direction, glm::vec3 color) :
DirLight::~DirLight() {}
void DirLight::updateShader(ShaderProgram shader) const {
void DirLight::updateShader(ShaderProgram shader, int index) const {
// Recall DirLight structure in fragment shader
// -------------
// struct DirLight {
@ -23,10 +23,10 @@ void DirLight::updateShader(ShaderProgram shader) const {
// vec3 specular;
// };
shader.setUniform("DirLight.direction", -_direction);
shader.setUniform("DirLight.ambient", ambientLightColor());
shader.setUniform("DirLight.diffuse", diffuseLightColor());
shader.setUniform("DirLight.specular", specularLightColor());
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) + "].diffuse", diffuseLightColor());
shader.setUniform("dirlights[" + std::to_string(index) + "].specular", specularLightColor());
}
ScopedLight::ScopedLight(glm::vec3 position, glm::vec3 direction, glm::vec3 color) :
@ -83,7 +83,7 @@ inline float ScopedLight::innerCutOffAngle() const {
return 0.0011 * glm::pow(_cutOffAngle, 2) + 0.6440 * _cutOffAngle;
}
void ScopedLight::updateShader(ShaderProgram shader) const {
void ScopedLight::updateShader(ShaderProgram shader, int index) const {
// Recall PointLight and SpotLight structure in fragment shader
// -------------
// struct PointLight {
@ -112,25 +112,25 @@ void ScopedLight::updateShader(ShaderProgram shader) const {
// Check the cutoff angle to determine the type of light
if (abs(_cutOffAngle - 180.0f) < 1e-6) {
// Point light
shader.setUniform("PointLight.position", _position);
shader.setUniform("PointLight.ambient", ambientLightColor());
shader.setUniform("PointLight.diffuse", diffuseLightColor());
shader.setUniform("PointLight.specular", specularLightColor());
shader.setUniform("PointLight.constant", _attConstant);
shader.setUniform("PointLight.linear", _attLinear);
shader.setUniform("PointLight.quadratic", _attQuadratic);
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) + "].diffuse", diffuseLightColor());
shader.setUniform("pointlights[" + std::to_string(index) + "].specular", specularLightColor());
shader.setUniform("pointlights[" + std::to_string(index) + "].constant", _attConstant);
shader.setUniform("pointlights[" + std::to_string(index) + "].linear", _attLinear);
shader.setUniform("pointlights[" + std::to_string(index) + "].quadratic", _attQuadratic);
}
else {
// Spot light
shader.setUniform("SpotLight.position", _position);
shader.setUniform("SpotLight.direction", -_direction);
shader.setUniform("SpotLight.ambient", ambientLightColor());
shader.setUniform("SpotLight.diffuse", diffuseLightColor());
shader.setUniform("SpotLight.specular", specularLightColor());
shader.setUniform("SpotLight.constant", _attConstant);
shader.setUniform("SpotLight.linear", _attLinear);
shader.setUniform("SpotLight.quadratic", _attQuadratic);
shader.setUniform("SpotLight.innercutoff", glm::cos(glm::radians(innerCutOffAngle())));
shader.setUniform("SpotLight.outercutoff", glm::cos(glm::radians(_cutOffAngle)));
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) + "].ambient", ambientLightColor());
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) + "].constant", _attConstant);
shader.setUniform("spotlights[" + std::to_string(index) + "].linear", _attLinear);
shader.setUniform("spotlights[" + std::to_string(index) + "].quadratic", _attQuadratic);
shader.setUniform("spotlights[" + std::to_string(index) + "].innercutoff", glm::cos(glm::radians(innerCutOffAngle())));
shader.setUniform("spotlights[" + std::to_string(index) + "].outercutoff", glm::cos(glm::radians(_cutOffAngle)));
}
}

View File

@ -19,7 +19,7 @@ protected:
virtual glm::vec3 diffuseLightColor() const = 0;
virtual glm::vec3 specularLightColor() const = 0;
virtual void updateShader(ShaderProgram shader) const = 0;
virtual void updateShader(ShaderProgram shader, int index) const = 0;
public:
glm::vec3 lightColor() const { return _lightColor; }
@ -45,7 +45,7 @@ public:
void setLightDirection(glm::vec3 direction) { _direction = direction; }
// Render util function
virtual void updateShader(ShaderProgram shader) const override;
virtual void updateShader(ShaderProgram shader, int index) const override;
};
// Scoped Light is a combination of point light and spot light
@ -91,5 +91,5 @@ public:
void setCutOffAngle(float angle);
// Render util function
virtual void updateShader(ShaderProgram shader) const override;
virtual void updateShader(ShaderProgram shader, int index) const override;
};