Day 12 done, we now have various kinds of lights.
This commit is contained in:
parent
fb2c871419
commit
a1d2c7768d
59 changed files with 13605 additions and 0 deletions
63
12-direction-lights/src/shader.hpp
Normal file
63
12-direction-lights/src/shader.hpp
Normal file
|
|
@ -0,0 +1,63 @@
|
|||
#pragma once
|
||||
|
||||
#include <glad/glad.h>
|
||||
#include <string>
|
||||
#include <climits>
|
||||
#include <glm/glm.hpp>
|
||||
|
||||
struct Material {
|
||||
glm::vec3 ambient{0.1f,0.1f,0.1f};
|
||||
float shininess{32.0f};
|
||||
unsigned int diffuseMap = 0;
|
||||
unsigned int specularMap = 0;
|
||||
};
|
||||
|
||||
struct Light {
|
||||
glm::vec3 position;
|
||||
glm::vec3 direction;
|
||||
glm::vec3 ambient;
|
||||
glm::vec3 diffuse;
|
||||
glm::vec3 specular;
|
||||
float constant;
|
||||
float linear;
|
||||
float quadratic;
|
||||
float cutOff;
|
||||
float outerCutOff;
|
||||
};
|
||||
|
||||
class Shader
|
||||
{
|
||||
public:
|
||||
unsigned int ID = UINT_MAX;
|
||||
|
||||
Shader(const char* vertexPath, const char* fragmentPath);
|
||||
unsigned int load_shader(const std::string& filename, GLenum shader_type);
|
||||
void use() const;
|
||||
void setBool(const std::string &name, bool value) const;
|
||||
void setInt(const std::string &name, int value) const;
|
||||
void setFloat(const std::string &name, float value) const;
|
||||
void setVec4(const std::string &name, float v1, float v2, float v3, float v4) const;
|
||||
void setVec4(const std::string &name, const glm::vec4& value) const;
|
||||
void setVec3(const std::string &name, float v1, float v2, float v3) const;
|
||||
void setVec3(const std::string &name, const glm::vec3& value) const;
|
||||
void setMat4(const std::string &name, const glm::mat4& what) const;
|
||||
void cleanup();
|
||||
|
||||
void applyMaterial(const Material& material) {
|
||||
setVec3("material.ambient", material.ambient);
|
||||
setFloat("material.shininess", material.shininess);
|
||||
}
|
||||
|
||||
void applyLight(const Light& light) {
|
||||
setVec3("light.position", light.position);
|
||||
setVec3("light.direction", light.direction);
|
||||
setVec3("light.ambient", light.ambient);
|
||||
setVec3("light.diffuse", light.diffuse);
|
||||
setVec3("light.specular", light.specular);
|
||||
setFloat("light.constant", light.constant);
|
||||
setFloat("light.linear", light.linear);
|
||||
setFloat("light.quadratic", light.quadratic);
|
||||
setFloat("light.cutOff", glm::cos(glm::radians(light.cutOff)));
|
||||
setFloat("light.outerCutOff", glm::cos(glm::radians(light.outerCutOff)));
|
||||
}
|
||||
};
|
||||
Loading…
Add table
Add a link
Reference in a new issue