Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| b1a59e0ed2 | |||
| b3038ef713 |
@@ -21,6 +21,8 @@ public:
|
|||||||
std::string GetFileName() const;
|
std::string GetFileName() const;
|
||||||
GLuint GetHandle() const;
|
GLuint GetHandle() const;
|
||||||
bool IsCompiled() const;
|
bool IsCompiled() const;
|
||||||
|
static std::string ReadFile(std::string fileName);
|
||||||
|
private:
|
||||||
protected:
|
protected:
|
||||||
GLenum m_ShaderType;
|
GLenum m_ShaderType;
|
||||||
std::string m_FileName;
|
std::string m_FileName;
|
||||||
|
|||||||
@@ -116,12 +116,7 @@ LightResult CalcDirectionalLightSource(vec4 direction, vec4 color, float intensi
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
vec4 CalcNormalMappedValue(vec3 normal, vec3 tangent, vec3 bitangent, vec2 textureCoordinate, sampler2D normalMap)
|
#include "Shaders/Util/CommonUniforms.glsl"
|
||||||
{
|
|
||||||
mat3 TBN = mat3(tangent, bitangent, normal);
|
|
||||||
vec3 NormalMap = texture(normalMap, textureCoordinate).xyz * 2.0 - vec3(1.0);
|
|
||||||
return vec4(TBN * normalize(NormalMap), 0.0);
|
|
||||||
}
|
|
||||||
|
|
||||||
void main()
|
void main()
|
||||||
{
|
{
|
||||||
@@ -180,6 +175,7 @@ void main()
|
|||||||
color_result += FillColor;
|
color_result += FillColor;
|
||||||
}
|
}
|
||||||
sceneColor = vec4(color_result.xyz, clamp(color_result.a, 0, 1));
|
sceneColor = vec4(color_result.xyz, clamp(color_result.a, 0, 1));
|
||||||
|
//sceneColor = CommonUniforms.testColour;
|
||||||
//sceneColor = vec4(reflectionColor.xyz, 1);
|
//sceneColor = vec4(reflectionColor.xyz, 1);
|
||||||
color_result += glowTexel*GlowIntensity;
|
color_result += glowTexel*GlowIntensity;
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,6 @@
|
|||||||
|
vec4 CalcNormalMappedValue(vec3 normal, vec3 tangent, vec3 bitangent, vec2 textureCoordinate, sampler2D normalMap)
|
||||||
|
{
|
||||||
|
mat3 TBN = mat3(tangent, bitangent, normal);
|
||||||
|
vec3 NormalMap = texture(normalMap, textureCoordinate).xyz * 2.0 - vec3(1.0);
|
||||||
|
return vec4(TBN * normalize(NormalMap), 0.0);
|
||||||
|
}
|
||||||
@@ -4,22 +4,32 @@ GLuint Shader::CompileShader(GLenum shaderType, std::string fileName)
|
|||||||
{
|
{
|
||||||
LOG_INFO("Compiling shader \"%s\"", fileName.c_str());
|
LOG_INFO("Compiling shader \"%s\"", fileName.c_str());
|
||||||
|
|
||||||
std::string shaderFile;
|
std::string shaderFile = ReadFile(fileName);
|
||||||
std::ifstream in(fileName, std::ios::in);
|
|
||||||
if (!in) {
|
|
||||||
LOG_ERROR("Error: Failed to open shader file \"%s\"", fileName.c_str());
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
in.seekg(0, std::ios::end);
|
|
||||||
shaderFile.resize((int)in.tellg());
|
|
||||||
in.seekg(0, std::ios::beg);
|
|
||||||
in.read(&shaderFile[0], shaderFile.size());
|
|
||||||
in.close();
|
|
||||||
|
|
||||||
GLuint shader = glCreateShader(shaderType);
|
GLuint shader = glCreateShader(shaderType);
|
||||||
if (GLERROR("glCreateShader"))
|
if (GLERROR("glCreateShader"))
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
|
std::size_t startPos = 0;
|
||||||
|
std::size_t SEofNewFile[2];
|
||||||
|
std::string key = "#include";
|
||||||
|
while((startPos = shaderFile.find(key, startPos)) != std::string::npos)
|
||||||
|
{
|
||||||
|
SEofNewFile[0] = shaderFile.find('"', startPos+key.length())+1;
|
||||||
|
SEofNewFile[1] = shaderFile.find('"', SEofNewFile[0]);
|
||||||
|
if (SEofNewFile[0] == std::string::npos || SEofNewFile[1] == std::string::npos)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
std::string replacementFileName = shaderFile.substr(SEofNewFile[0], SEofNewFile[1] - SEofNewFile[0]);
|
||||||
|
std::string replacementString = ReadFile(replacementFileName);
|
||||||
|
size_t firstof = replacementString.find_first_of((char)0);
|
||||||
|
replacementString.erase(firstof, replacementString.size() - firstof);
|
||||||
|
if (replacementString.length() <= 0)
|
||||||
|
return 0;
|
||||||
|
shaderFile.replace(startPos, SEofNewFile[1]+2 - startPos, replacementString + "\n");
|
||||||
|
startPos += replacementString.length(); //This might not be wanted.
|
||||||
|
}
|
||||||
|
|
||||||
const GLchar* shaderFiles = shaderFile.c_str();
|
const GLchar* shaderFiles = shaderFile.c_str();
|
||||||
const GLint length = static_cast<GLint>(shaderFile.length());
|
const GLint length = static_cast<GLint>(shaderFile.length());
|
||||||
glShaderSource(shader, 1, &shaderFiles, &length);
|
glShaderSource(shader, 1, &shaderFiles, &length);
|
||||||
@@ -46,6 +56,24 @@ GLuint Shader::CompileShader(GLenum shaderType, std::string fileName)
|
|||||||
return shader;
|
return shader;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::string Shader::ReadFile(std::string fileName)
|
||||||
|
{
|
||||||
|
std::string shaderFile;
|
||||||
|
std::ifstream in(fileName, std::ios::in);
|
||||||
|
if (!in) {
|
||||||
|
LOG_ERROR("Error: Failed to open shader file \"%s\"", fileName.c_str());
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
|
in.seekg(0, std::ios::end);
|
||||||
|
shaderFile.resize((int)in.tellg());
|
||||||
|
in.seekg(0, std::ios::beg);
|
||||||
|
in.read(&shaderFile[0], shaderFile.size());
|
||||||
|
in.close();
|
||||||
|
return shaderFile;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
Shader::Shader(GLenum shaderType, std::string fileName) : m_ShaderType(shaderType), m_FileName(fileName)
|
Shader::Shader(GLenum shaderType, std::string fileName) : m_ShaderType(shaderType), m_FileName(fileName)
|
||||||
{
|
{
|
||||||
m_ShaderHandle = 0;
|
m_ShaderHandle = 0;
|
||||||
|
|||||||
Reference in New Issue
Block a user