forked from lokesh-sharma/GameEngine
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathForwardDirectional.h
More file actions
77 lines (70 loc) · 3.97 KB
/
ForwardDirectional.h
File metadata and controls
77 lines (70 loc) · 3.97 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#ifndef FORWARDDIRECTIONAL_H_INCLUDED
#define FORWARDDIRECTIONAL_H_INCLUDED
#include"Light.h"
#include"shader.h"
class ForwardDirectional: public Shader
{
public:
ForwardDirectional(const std::string fileName): Shader(fileName)
{
m_uniforms["fogColor"] = glGetUniformLocation(m_program , "fogColor");
m_uniforms["eyePos"] = glGetUniformLocation(m_program , "eyePos");
m_uniforms["clipPlane"] = glGetUniformLocation(m_program , "clipPlane");
m_uniforms["shadowTexelSize"] = glGetUniformLocation(m_program , "shadowTexelSize");
m_uniforms["shadowBias"] = glGetUniformLocation(m_program , "shadowBias");
m_uniforms["lightMatrix"] = glGetUniformLocation(m_program , "lightMatrix");
m_uniforms["specularPower"] = glGetUniformLocation(m_program , "specularPower");
m_uniforms["specularIntensity"] = glGetUniformLocation(m_program , "specularIntensity");
m_uniforms["dispMapScale"] = glGetUniformLocation(m_program , "dispMapScale");
m_uniforms["dispMapBias"] = glGetUniformLocation(m_program , "dispMapBias");
int diffuseLocation = glGetUniformLocation(m_program , "diffuse");
if(diffuseLocation>=0)
m_uniforms["diffuse"] = diffuseLocation;
int normalMapLocation = glGetUniformLocation(m_program , "normalMap");
if(normalMapLocation>=0)
m_uniforms["normalMap"] = normalMapLocation;
int dispMapLocation = glGetUniformLocation(m_program , "dispMap");
if(dispMapLocation>=0)
m_uniforms["dispMap"] = dispMapLocation;
int shadowMapLocation = glGetUniformLocation(m_program , "shadowMap");
if(shadowMapLocation>=0)
m_uniforms["shadowMap"] = shadowMapLocation;
std::string light = "directionalLight";
m_uniforms[light + ".base.color"] = glGetUniformLocation(m_program ,(light+".base.color").c_str());
m_uniforms[light + ".base.intensity"] = glGetUniformLocation(m_program ,(light+".base.intensity").c_str());
m_uniforms[light + ".direction"] = glGetUniformLocation(m_program ,(light+".direction").c_str());
}
void Update(const Transform& transform,const Camera&c,const Material& material , RenderingEngine* renderingEngine)
{
renderingEngine->getDirShadowMap()->Bind(3);
glm::mat4 lightMat = renderingEngine->getLightMatrix()*transform.GetModel();
setUniformMatrix4f("lightMatrix" , &lightMat[0][0]);
Shader::Update(transform , c,material,renderingEngine);
setUniformSampler("diffuse" , 0);
setUniformSampler("normalMap" , 1);
setUniformSampler("dispMap" , 2);
setUniformSampler("shadowMap" , 3);
setUniform1f("dispMapScale" , material.getDispMapScale());
float baseBias = material.getDispMapScale()/2.0f;
setUniform1f("dispMapBias" , -baseBias + baseBias*material.getDispMapOffset());
std::string light = "directionalLight";
DirectionalLight* dirlight = renderingEngine->getActiveDirectionalLight();
glm::vec3 color = dirlight->getColor();
setUniformVector3f(light+".base.color" ,color.x , color.y , color.z);
setUniform1f(light+".base.intensity" , dirlight->getIntensity());
glm::vec3 dir = dirlight->getDirection();
setUniformVector3f(light+".direction" ,dir.x , dir.y , dir.z);
setUniform1f("specularPower" , material.getSpecularPower());
setUniform1f("shadowBias" , renderingEngine->getShadowBias());
glm::vec3 tSize = renderingEngine->getShadowTexelSize();
setUniformVector3f("shadowTexelSize" , tSize.x , tSize.y , tSize.z);
setUniform1f("specularIntensity" , material.getSpecularIntensity());
glm::vec3 p = c.getPos();
setUniformVector3f("eyePos" , p.x , p.y , p.z);
glm::vec4 plane = renderingEngine->getClipingPlane();
setUniformVector4f("clipPlane" ,plane.x , plane.y , plane.z , plane.w );
glm::vec4 fc = renderingEngine->getFogColor();
setUniformVector4f("fogColor" , fc.x , fc.y , fc.z , fc.w);
}
};
#endif // FORWARDDIRECTIONAL_H_INCLUDED