PCG-FPS  v2 m0.22.4
Simple First Person Shooter with Procedurally Generated Level
PointLight.h
Go to the documentation of this file.
1 #ifndef SKR_FPS2_RENDERER_OPENGL_POINTLIGHT_H
2 #define SKR_FPS2_RENDERER_OPENGL_POINTLIGHT_H
3 
4 #include "..\..\pch.h"
5 #include "Shader.h"
6 
7 namespace skr
8 {
9 namespace fps2
10 {
11 namespace Renderer
12 {
13 namespace OpenGL
14 {
15  constexpr glm::vec3 Default_Ambient_Color = glm::vec3(0.2f);
16  constexpr glm::vec3 Default_Diffuse_Color = glm::vec3(0.8f);
17  constexpr glm::vec3 Default_Specular_Color = glm::vec3(0.5f);
18 
19  constexpr float Default_Attenuation_Constant = 1.0f;
20  constexpr float Default_Attenuation_Linear = 0.25f;
21  constexpr float Default_Attenuation_Quadratic = 0.060f;
22 
25  class PointLight
26  {
27  public:
37  (
38  std::array<float, 3> pos,
39  glm::vec3 ambientColor = Default_Ambient_Color,
40  glm::vec3 diffuseColor = Default_Diffuse_Color,
41  glm::vec3 specularColor = Default_Specular_Color,
42  float constant = Default_Attenuation_Constant,
43  float linear = Default_Attenuation_Linear,
44  float quadratic = Default_Attenuation_Quadratic
45  );
46 
56  (
57  glm::vec3 pos,
58  glm::vec3 ambientColor = Default_Ambient_Color,
59  glm::vec3 diffuseColor = Default_Diffuse_Color,
60  glm::vec3 specularColor = Default_Specular_Color,
61  float constant = Default_Attenuation_Constant,
62  float linear = Default_Attenuation_Linear,
63  float quadratic = Default_Attenuation_Quadratic
64  );
65 
66  #pragma region Inline functions to generate names for shader variables
67 
69  inline static std::string GetPositionName();
72  inline static std::string GetPositionName(int index);
73 
75  inline static std::string GetAmbientName();
78  inline static std::string GetAmbientName(int index);
80  inline static std::string GetDiffuseName();
83  inline static std::string GetDiffuseName(int index);
85  inline static std::string GetSpecularName();
88  inline static std::string GetSpecularName(int index);
89 
91  inline static std::string GetConstantName();
94  inline static std::string GetConstantName(int index);
96  inline static std::string GetLinearName();
99  inline static std::string GetLinearName(int index);
101  inline static std::string GetQuadraticName();
104  inline static std::string GetQuadraticName(int index);
105 #pragma endregion
106 
109  void SetBasicLighting(Shader shader);
110 
114  void SetBasicLighting(Shader shader, glm::vec3 pos);
115 
120  void SetBasicLight(Shader shader, PointLight pl, glm::vec3 diffColor);
121 
124  void SetPointLight(Shader shader);
125 
129  void SetPointLight(Shader shader, glm::vec3 pos);
130 
135  void SetPointLight(Shader shader, glm::vec3 pos, size_t index);
136 
141  void SetPointLight(Shader shader, glm::vec3 ambColor, glm::vec3 diffColor);
142 
143 
144  glm::vec3 _position;
145 
146  glm::vec3 _ambientColor;
147  glm::vec3 _diffuseColor;
148  glm::vec3 _specularColor;
149 
150  float _constant;
151  float _linear;
152  float _quadratic;
153 
154  private:
155  static const std::string _PointLightMultipleName;
156  static const std::string _PointLightSingleName;
157 };
158 
159 }
160 }
161 }
162 }
163 
164 #endif // !SKR_FPS2_RENDERER_OPENGL_POINTLIGHT_H
165 
skr::fps2::Renderer::OpenGL::PointLight::_ambientColor
glm::vec3 _ambientColor
ambient color
Definition: PointLight.h:146
skr::fps2::Renderer::OpenGL::Default_Specular_Color
constexpr glm::vec3 Default_Specular_Color
default specular color
Definition: PointLight.h:17
skr::fps2::Renderer::OpenGL::PointLight::_PointLightMultipleName
static const std::string _PointLightMultipleName
name template of pointlight in shader if multiple are used
Definition: PointLight.h:155
skr::fps2::Renderer::OpenGL::PointLight::GetPositionName
static std::string GetPositionName()
function to generate name of position for shader variable
Definition: PointLight.cpp:38
skr::fps2::Renderer::OpenGL::PointLight::_linear
float _linear
attenuation linear factor
Definition: PointLight.h:151
skr::fps2::Renderer::OpenGL::PointLight::_specularColor
glm::vec3 _specularColor
specular color
Definition: PointLight.h:148
skr::fps2::Renderer::OpenGL::PointLight::SetBasicLight
void SetBasicLight(Shader shader, PointLight pl, glm::vec3 diffColor)
set basic light properties in given shader
Definition: PointLight.cpp:126
skr::fps2::Renderer::OpenGL::PointLight::_PointLightSingleName
static const std::string _PointLightSingleName
name template of pointlight in shader
Definition: PointLight.h:156
skr::fps2::Renderer::OpenGL::Default_Ambient_Color
constexpr glm::vec3 Default_Ambient_Color
default ambient color
Definition: PointLight.h:15
skr::fps2::Renderer::OpenGL::PointLight::_diffuseColor
glm::vec3 _diffuseColor
diffuse color
Definition: PointLight.h:147
skr::fps2::Renderer::OpenGL::PointLight::PointLight
PointLight(std::array< float, 3 > pos, glm::vec3 ambientColor=Default_Ambient_Color, glm::vec3 diffuseColor=Default_Diffuse_Color, glm::vec3 specularColor=Default_Specular_Color, float constant=Default_Attenuation_Constant, float linear=Default_Attenuation_Linear, float quadratic=Default_Attenuation_Quadratic)
contructor
Definition: PointLight.cpp:21
skr::fps2::Renderer::OpenGL::Default_Diffuse_Color
constexpr glm::vec3 Default_Diffuse_Color
default diffuse color
Definition: PointLight.h:16
skr::fps2::Renderer::OpenGL::Shader
handles shader loading, compiling and linking. Also provides access to set uniform ids and usage.
Definition: Shader.h:31
skr::fps2::Renderer::OpenGL::Default_Attenuation_Constant
constexpr float Default_Attenuation_Constant
default attenuation constant factor
Definition: PointLight.h:19
skr::fps2::Renderer::OpenGL::PointLight::SetPointLight
void SetPointLight(Shader shader)
set light properties in given shader
Definition: PointLight.cpp:136
skr::fps2::Renderer::OpenGL::PointLight::_quadratic
float _quadratic
attenuation quadrtic factor
Definition: PointLight.h:152
Shader.h
skr::fps2::Renderer::OpenGL::PointLight::SetBasicLighting
void SetBasicLighting(Shader shader)
set basic light properties in given shader
Definition: PointLight.cpp:110
skr::fps2::Renderer::OpenGL::PointLight::GetConstantName
static std::string GetConstantName()
function to generate name of attenuation constant factor for shader variable
Definition: PointLight.cpp:78
skr::fps2::Renderer::OpenGL::PointLight::_constant
float _constant
attenuation constant factor
Definition: PointLight.h:150
skr
Definition: AssetPath.h:10
skr::fps2::Renderer::OpenGL::PointLight::GetAmbientName
static std::string GetAmbientName()
function to generate name of ambient color for shader variable
Definition: PointLight.cpp:48
skr::fps2::Renderer::OpenGL::PointLight::_position
glm::vec3 _position
position
Definition: PointLight.h:144
skr::fps2::Renderer::OpenGL::PointLight::GetQuadraticName
static std::string GetQuadraticName()
function to generate name of attenuation quadratic factor for shader variable
Definition: PointLight.cpp:98
skr::fps2::Renderer::OpenGL::Default_Attenuation_Quadratic
constexpr float Default_Attenuation_Quadratic
default attenuation quadratic factor
Definition: PointLight.h:21
skr::fps2::Renderer::OpenGL::PointLight
defines a point light, emitting light in all directions
Definition: PointLight.h:26
skr::fps2::Renderer::OpenGL::PointLight::GetSpecularName
static std::string GetSpecularName()
function to generate name of specular color for shader variable
Definition: PointLight.cpp:68
skr::fps2::Renderer::OpenGL::Default_Attenuation_Linear
constexpr float Default_Attenuation_Linear
default attenuation linear factor
Definition: PointLight.h:20
skr::fps2::Renderer::OpenGL::PointLight::GetLinearName
static std::string GetLinearName()
function to generate name of attenuation linear factor for shader variable
Definition: PointLight.cpp:88
skr::fps2::Renderer::OpenGL::PointLight::GetDiffuseName
static std::string GetDiffuseName()
function to generate name of diffuse color for shader variable
Definition: PointLight.cpp:58