-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathShader.h
More file actions
187 lines (157 loc) · 6.19 KB
/
Shader.h
File metadata and controls
187 lines (157 loc) · 6.19 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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
#pragma once
#include "GL/glew.h"
#include <iostream>
#include <string>
#include <fstream>
#include <vector>
#include "DirectionalLight.h"
#include "PointLight.h"
#include "SpotLight.h"
#include "CommonValues.h"
#include <glm/gtc/type_ptr.hpp>
class Shader
{
public:
//Constructor
Shader();
//Destructor
~Shader();
//Creates Shader from string
void CreateShadersFromText(const char* vShaderCode, const char* fShaderCode);
//Creates shaders from files (vertex and fragment)
void CreateShadersFromFiles(const char* vShaderPath, const char* fShaderPath);
//Creates shaders from files (vertex ,geometry and fragment)
void CreateShadersFromFiles(const char* vShaderPath, const char* gShaderPath,const char* fShaderPath);
//Reads the shader file and returns cpp string
std::string ReadFile(const char* FilePath);
//Enables the shader during rendering
void EnableShader();
//Disables the shader.THIS MUST BE CALLED AT THE END OF EACH RENDER LOOP.
void DisableShader();
//Completely clears the shader
void ClearShaders();
void ValidateShaders();
//Attaches a directional light to the shader to pass information
void SetDirectionalLight(DirectionalLight* TheLight);
//Enables the information in the directional light to be passed on to shader during rendering
void EnableDirectionalLight();
//Attaches a point light to the shader to pass information
void SetPointLight(PointLight* TheLight, GLuint PointLightCount);
//Enables information contained within the point light(s) to be passed on to shader during runtime
void EnablePointLight(GLuint TexUnit);
//Attaches spot light to communicate with shader
void SetSpotLight(SpotLight* TheLight,GLuint NumberOfSpotLights);
//Enables information contained within the spot light(s) to be passed on to shader during runtime
void EnableSpotLight(GLuint TexUnit);
//Sets a texture unit as tex2dsampler in shader.frag
void SetTexture(GLuint TextureUnit);
//Sets a texture unit as shadowmap in shader.frag
void SetDirectionalShadowMap(GLuint TextureUnit);
//Sets a matrix as the light transform in shader.frag
void SetDirectionalLightTransform(glm::mat4 DirectionalLightTransform);
void SetLightMatrices(std::vector<glm::mat4> lightMatrices);
//Returns Uniform variable Model location ID
GLuint GetUniformModel();
//Returns uniform variable projection location ID
GLuint GetUniformProjection();
//Returns uniform variable view location ID
GLuint GetUniformView();
//Returns uniform variable ambient light colour ID
GLuint GetUniformAmbientLightColour();
//Returns uniform variable ambient light intensity ID
GLuint GetUniformAmbientLightIntensity();
//Returns uniform variable diffuse light direction ID
GLuint GetUniformDiffuseDirection();
//Returns uniform variable diffuse light intensity ID
GLuint GetUniformDiffuseIntensity();
//Returns uniform variable specular intensity ID
GLuint GetUniformSpecularIntensity();
//Returns uniform variable specular shininess intensity ID
GLuint GetUniformSpecularShininess();
//Returns uniform variable camera view ID
GLuint GetUniformCameraPosition();
//Returns omni directional light map far plane uniform location Id
GLuint GetUniformFarPlane();
//Returns omni directional light map point/spot light position uniform location Id
GLuint GetUniformOmniLightPosition();
private:
//Actually the program id to which the shaders are linked to
GLuint ShaderId;
//Uniform variable Model location ID
GLuint UniformModel;
//Uniform variable projection location ID.Used to set whether projection is orthographic or perspective projection.
GLuint UniformProjection;
//User's perspective (not the projection,this is their POV) uniform location ID
GLuint UniformView;
//Specular intensity uniform location ID
GLuint UniformSpecularIntensity;
//Specular shininess uniform location ID
GLuint UniformSpecularShininess;
//User's camera position uniform location ID
GLuint UniformCameraPosition;
//Number of point lights uniform location ID
GLuint UniformPointLightCount;
//Number of spot lights uniform location ID
GLuint UniformSpotLightCount;
//Texture sampler location ID
GLuint UniformTex2DSampler;
//Shadow amp sampler location ID
GLuint UniformShadowMap;
//UniformLightSpaceTransform
GLuint UniformDirectionalLightSpaceTransform;
//point and Spot light far plane uniform location ID
GLuint UniformFarPlane;
//Omni directional light map spot and point light pos
GLuint UniformOmniLightPosition;
//point and Spot light far plane uniform location ID
GLuint UniformLightMatrices[6];
struct DirectionalLightUniformVars {
GLuint UniformAmbientLightColour;
GLuint UniformAmbientLightIntensity;
GLuint UniformDiffuseDirection;
GLuint UniformDiffuseIntensity;
} DirectionalLightUniformContainer;
//Pointer to directional light
DirectionalLight* dLight;
//Structure which stores all uniform location IDs needed for a point light
struct PointLightUniformVars{
GLuint UniformAmbientLightColour;
GLuint UniformAmbientLightIntensity;
GLuint UniformDiffuseIntensity;
GLuint UniformCoeffA;
GLuint UniformCoeffB;
GLuint UniformCoeffC;
GLuint UniformLightPosition;
}PointLightUniformContainer[MAX_POINT_LIGHTS];
//Number of point lights to be rendered
GLuint PointLightCount;
//Pointer to array of point lights to be rendered
PointLight *pLight;
struct SpotLightUniformVars {
GLuint UniformAmbientLightColour;
GLuint UniformAmbientLightIntensity;
GLuint UniformDiffuseIntensity;
GLuint UniformCoeffA;
GLuint UniformCoeffB;
GLuint UniformCoeffC;
GLuint UniformLightPosition;
GLuint UniformSpotLightDirection;
GLuint UniformCutoff;
GLuint UniformSpotLightStatus;
}SpotLightUniformContainer[MAX_SPOT_LIGHTS];
struct OmniMapUniformVars {
GLuint UniformFPlane;
GLuint UniformShadowTexture;
}OmniMapUniformContainer[MAX_SPOT_LIGHTS+MAX_POINT_LIGHTS];
//Spot light array ptr;
SpotLight* sLight;
//Spot Light array count
GLuint SpotLightCount;
//Adds the shader to the program
GLuint AddShader(GLuint TheProgram, const char* ShaderCode, GLenum ShaderType);
//Compiles the shader
void CompileShaders(const char* vShaderCode, const char* fShaderCode);
//Compiles the shader
void CompileShaders(const char* vShaderCode, const char* gShaderCode,const char* fShaderCode);
void GetAllUniforms();
};