Camera and shader now fixed up.
This commit is contained in:
parent
47bd233722
commit
a7beb5a92a
5 changed files with 60 additions and 53 deletions
|
|
@ -124,3 +124,53 @@ void Shader::setMat4(const std::string &name, const glm::mat4& mat) const {
|
|||
unsigned int loc = glGetUniformLocation(ID, name.c_str());
|
||||
glUniformMatrix4fv(loc, 1, GL_FALSE, glm::value_ptr(mat));
|
||||
}
|
||||
|
||||
void Shader::apply_material(const Material& material) {
|
||||
setVec3("material.ambient", material.ambient);
|
||||
setFloat("material.shininess", material.shininess);
|
||||
}
|
||||
|
||||
void Shader::apply_lighting(const Lighting& lighting) {
|
||||
apply_dir_light(lighting.directional);
|
||||
|
||||
setInt("pointLightCount", lighting.positioned.size());
|
||||
|
||||
for(size_t i = 0; i < lighting.positioned.size(); i++) {
|
||||
apply_point_light(lighting.positioned[i], i);
|
||||
}
|
||||
|
||||
apply_spot_light(lighting.spot);
|
||||
}
|
||||
|
||||
void Shader::apply_dir_light(const Light& light) {
|
||||
setVec3("dirLight.direction", light.direction);
|
||||
setVec3("dirLight.ambient", light.ambient);
|
||||
setVec3("dirLight.diffuse", light.diffuse);
|
||||
setVec3("dirLight.specular", light.specular);
|
||||
}
|
||||
|
||||
void Shader::apply_point_light(const Light& light, size_t index) {
|
||||
dbc::check(index < NR_POINT_LIGHTS, "too many positioned lights");
|
||||
|
||||
setVec3(std::format("pointLights[{}].position", index), light.position);
|
||||
setVec3(std::format("pointLights[{}].ambient", index), light.ambient);
|
||||
setVec3(std::format("pointLights[{}].diffuse", index), light.diffuse);
|
||||
setVec3(std::format("pointLights[{}].specular", index), light.specular);
|
||||
|
||||
setFloat(std::format("pointLights[{}].constant", index), light.constant);
|
||||
setFloat(std::format("pointLights[{}].linear", index), light.linear);
|
||||
setFloat(std::format("pointLights[{}].quadratic", index), light.quadratic);
|
||||
}
|
||||
|
||||
void Shader::apply_spot_light(const Light& light) {
|
||||
setVec3("spotLight.position", light.position);
|
||||
setVec3("spotLight.direction", light.direction);
|
||||
setVec3("spotLight.ambient", light.ambient);
|
||||
setVec3("spotLight.diffuse", light.diffuse);
|
||||
setVec3("spotLight.specular", light.specular);
|
||||
setFloat("spotLight.constant", light.constant);
|
||||
setFloat("spotLight.linear", light.linear);
|
||||
setFloat("spotLight.quadratic", light.quadratic);
|
||||
setFloat("spotLight.cutOff", glm::cos(glm::radians(light.cutOff)));
|
||||
setFloat("spotLight.outerCutOff", glm::cos(glm::radians(light.outerCutOff)));
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue