From cc68bba3a4e1a78bc8b62a5902230a4ae5043ccb Mon Sep 17 00:00:00 2001 From: chai Date: Wed, 3 Nov 2021 19:14:51 +0800 Subject: * rename .GLSL(gamelab shading language) to .GLS(gamelab shader) --- Data/Resources/Shaders/BaseColor.gls | 43 ++++++++++++++++++++++++++++++ Data/Resources/Shaders/BaseColor.glsl | 43 ------------------------------ Data/Resources/Shaders/Editor-Text.gls | 47 +++++++++++++++++++++++++++++++++ Data/Resources/Shaders/Editor-Text.glsl | 47 --------------------------------- Data/Resources/Shaders/Editor-UI.gls | 45 +++++++++++++++++++++++++++++++ Data/Resources/Shaders/Editor-UI.glsl | 46 -------------------------------- Data/Scripts/Editor/AssetBrowser.lua | 2 +- Runtime/Graphics/Shader.cpp | 4 +-- Runtime/Graphics/ShaderCompiler.cpp | 46 ++++++++++++++++---------------- Runtime/Graphics/ShaderCompiler.h | 14 +++++----- 10 files changed, 168 insertions(+), 169 deletions(-) create mode 100644 Data/Resources/Shaders/BaseColor.gls delete mode 100644 Data/Resources/Shaders/BaseColor.glsl create mode 100644 Data/Resources/Shaders/Editor-Text.gls delete mode 100644 Data/Resources/Shaders/Editor-Text.glsl create mode 100644 Data/Resources/Shaders/Editor-UI.gls delete mode 100644 Data/Resources/Shaders/Editor-UI.glsl diff --git a/Data/Resources/Shaders/BaseColor.gls b/Data/Resources/Shaders/BaseColor.gls new file mode 100644 index 0000000..b1aed17 --- /dev/null +++ b/Data/Resources/Shaders/BaseColor.gls @@ -0,0 +1,43 @@ +#version 330 core + +VSH_BEGIN + +vec3 vPos; +vec3 vNormal; +vec4 vTangent; +vec4 vColor; +vec2 vUV; +vec2 vUV2; +vec2 vUV3; +vec2 vUV4; + +uniform mat4 gamelab_mat_model; +uniform mat4 gamelab_mat_vp; +uniform vec4 gamelab_screen; +uniform vec4 gamelab_time; + +uniform mat4 mvp; + +out vec2 uv; + +void main() +{ + vec4 clip = mvp * vec4(vPos, -1, 1.0); + gl_Position = clip; + uv = vUV; +} + +VSH_END + +FSH_BEGIN +uniform sampler2D uiTex; + +in vec2 uv; + +out vec4 FragColor; + +void main() +{ + FragColor = texture(uiTex, uv); +} +FSH_END diff --git a/Data/Resources/Shaders/BaseColor.glsl b/Data/Resources/Shaders/BaseColor.glsl deleted file mode 100644 index b1aed17..0000000 --- a/Data/Resources/Shaders/BaseColor.glsl +++ /dev/null @@ -1,43 +0,0 @@ -#version 330 core - -VSH_BEGIN - -vec3 vPos; -vec3 vNormal; -vec4 vTangent; -vec4 vColor; -vec2 vUV; -vec2 vUV2; -vec2 vUV3; -vec2 vUV4; - -uniform mat4 gamelab_mat_model; -uniform mat4 gamelab_mat_vp; -uniform vec4 gamelab_screen; -uniform vec4 gamelab_time; - -uniform mat4 mvp; - -out vec2 uv; - -void main() -{ - vec4 clip = mvp * vec4(vPos, -1, 1.0); - gl_Position = clip; - uv = vUV; -} - -VSH_END - -FSH_BEGIN -uniform sampler2D uiTex; - -in vec2 uv; - -out vec4 FragColor; - -void main() -{ - FragColor = texture(uiTex, uv); -} -FSH_END diff --git a/Data/Resources/Shaders/Editor-Text.gls b/Data/Resources/Shaders/Editor-Text.gls new file mode 100644 index 0000000..7548507 --- /dev/null +++ b/Data/Resources/Shaders/Editor-Text.gls @@ -0,0 +1,47 @@ +// 渲染编辑器文字 + +#version 330 core + +CMD_BEGIN +Cull Off +Blend SrcAlpha OneMinusSrcAlpha +DepthTest Off +CMD_END + +uniform mat4 gamelab_mat_mvp; +uniform sampler2D gamelab_main_tex; +uniform vec2 gamelab_ui_position; + +VSH_BEGIN +layout (location = 0) in vec2 vPos; +layout (location = 1) in vec2 vUV; +layout (location = 2) in vec4 vColor; + +out vec2 uv; +out vec4 color; + +void main() +{ + vec2 pos = vPos + gamelab_ui_position; + vec4 clip = gamelab_mat_mvp * vec4(pos, -1, 1.0); + gl_Position = clip; + uv = vUV; + color = vColor; +} +VSH_END + +FSH_BEGIN +in vec2 uv; +in vec4 color; + +out vec4 FragColor; + +void main() +{ + //vec2 uv = vec2(uv.x, 1 - uv.y); + vec4 sampled = vec4(0.8,0.8,0.8,texture(gamelab_main_tex, uv).r); + sampled *= color; + //sampled = vec4(1,1,1,1); + FragColor = sampled; +} +FSH_END diff --git a/Data/Resources/Shaders/Editor-Text.glsl b/Data/Resources/Shaders/Editor-Text.glsl deleted file mode 100644 index 7548507..0000000 --- a/Data/Resources/Shaders/Editor-Text.glsl +++ /dev/null @@ -1,47 +0,0 @@ -// 渲染编辑器文字 - -#version 330 core - -CMD_BEGIN -Cull Off -Blend SrcAlpha OneMinusSrcAlpha -DepthTest Off -CMD_END - -uniform mat4 gamelab_mat_mvp; -uniform sampler2D gamelab_main_tex; -uniform vec2 gamelab_ui_position; - -VSH_BEGIN -layout (location = 0) in vec2 vPos; -layout (location = 1) in vec2 vUV; -layout (location = 2) in vec4 vColor; - -out vec2 uv; -out vec4 color; - -void main() -{ - vec2 pos = vPos + gamelab_ui_position; - vec4 clip = gamelab_mat_mvp * vec4(pos, -1, 1.0); - gl_Position = clip; - uv = vUV; - color = vColor; -} -VSH_END - -FSH_BEGIN -in vec2 uv; -in vec4 color; - -out vec4 FragColor; - -void main() -{ - //vec2 uv = vec2(uv.x, 1 - uv.y); - vec4 sampled = vec4(0.8,0.8,0.8,texture(gamelab_main_tex, uv).r); - sampled *= color; - //sampled = vec4(1,1,1,1); - FragColor = sampled; -} -FSH_END diff --git a/Data/Resources/Shaders/Editor-UI.gls b/Data/Resources/Shaders/Editor-UI.gls new file mode 100644 index 0000000..b2b348b --- /dev/null +++ b/Data/Resources/Shaders/Editor-UI.gls @@ -0,0 +1,45 @@ +#version 330 core + +CMD_BEGIN +Cull Off +Blend SrcAlpha OneMinusSrcAlpha +DepthTest Off +CMD_END + +uniform mat4 gamelab_mat_mvp; +uniform sampler2D gamelab_main_tex; +uniform vec2 gamelab_ui_position; + +VSH_BEGIN +layout (location = 0) in vec2 vPos; +layout (location = 1) in vec2 vUV; +layout (location = 2) in vec4 vColor; + +out vec2 uv; +out vec4 color; + +void main() +{ + vec2 pos = vPos + gamelab_ui_position; + vec4 clip = gamelab_mat_mvp * vec4(pos, -1, 1.0); + gl_Position = clip; + uv = vUV; + color = vColor; +} +VSH_END + +FSH_BEGIN +in vec2 uv; +in vec4 color; + +out vec4 FragColor; + +void main() +{ + //vec2 uv = vec2(uv.x, 1 - uv.y); + vec4 sampled = texture(gamelab_main_tex, uv); + // sampled *= color; + //sampled = vec4(1,1,1,1); + FragColor = sampled; +} +FSH_END diff --git a/Data/Resources/Shaders/Editor-UI.glsl b/Data/Resources/Shaders/Editor-UI.glsl deleted file mode 100644 index b831d6c..0000000 --- a/Data/Resources/Shaders/Editor-UI.glsl +++ /dev/null @@ -1,46 +0,0 @@ - -#version 330 core - -CMD_BEGIN -Cull Off -Blend SrcAlpha OneMinusSrcAlpha -DepthTest Off -CMD_END - -uniform mat4 gamelab_mat_mvp; -uniform sampler2D gamelab_main_tex; -uniform vec2 gamelab_ui_position; - -VSH_BEGIN -layout (location = 0) in vec2 vPos; -layout (location = 1) in vec2 vUV; -layout (location = 2) in vec4 vColor; - -out vec2 uv; -out vec4 color; - -void main() -{ - vec2 pos = vPos + gamelab_ui_position; - vec4 clip = gamelab_mat_mvp * vec4(pos, -1, 1.0); - gl_Position = clip; - uv = vUV; - color = vColor; -} -VSH_END - -FSH_BEGIN -in vec2 uv; -in vec4 color; - -out vec4 FragColor; - -void main() -{ - //vec2 uv = vec2(uv.x, 1 - uv.y); - vec4 sampled = texture(gamelab_main_tex, uv); - // sampled *= color; - //sampled = vec4(1,1,1,1); - FragColor = sampled; -} -FSH_END diff --git a/Data/Scripts/Editor/AssetBrowser.lua b/Data/Scripts/Editor/AssetBrowser.lua index 177d073..a0cb295 100644 --- a/Data/Scripts/Editor/AssetBrowser.lua +++ b/Data/Scripts/Editor/AssetBrowser.lua @@ -24,7 +24,7 @@ AssetBrowser.OnGUI = function(self) if shader == nil then -- local glsl = IO.ReadFile("./Resources/Shaders/Editor-Text.glsl", IO.EFileMode.Text) -- shader = Engine.Rendering.Shader.New(glsl) - shader = Engine.Rendering.Shader.CreateFromFile("./Resources/Shaders/Editor-Text.glsl") + shader = Engine.Rendering.Shader.CreateFromFile("./Resources/Shaders/Editor-Text.gls") end local ortho = Matrix44.New() diff --git a/Runtime/Graphics/Shader.cpp b/Runtime/Graphics/Shader.cpp index 013b1ba..8df3624 100644 --- a/Runtime/Graphics/Shader.cpp +++ b/Runtime/Graphics/Shader.cpp @@ -53,9 +53,9 @@ Shader::Shader(LuaBind::VM*vm, std::string& glslShader) std::string fsh ; try { - GLSLCompiler::Compile(glslShader, vsh, fsh, m_Commands); + GLSCompiler::Compile(glslShader, vsh, fsh, m_Commands); } - catch (GLSLCompileException& e) + catch (GLSCompileException& e) { ReleaseRenderCommandGroup(m_Commands); throw ShaderCompileExecption(e.what()); diff --git a/Runtime/Graphics/ShaderCompiler.cpp b/Runtime/Graphics/ShaderCompiler.cpp index 20b19f5..ddd21a6 100644 --- a/Runtime/Graphics/ShaderCompiler.cpp +++ b/Runtime/Graphics/ShaderCompiler.cpp @@ -13,18 +13,18 @@ static const char* CMD_END = "CMD_END"; std::string s_CompileError = ""; -// GLSL·ÖΪËIJ¿·Ö +// GLS·ÖΪËIJ¿·Ö // * CMD_BEGIN ºÍ CMD_END Ö®¼äµÄÃüÁî // * VERTEX_SHADER_BEGIN ºÍ VERTEX_SHADER_ENDÖ®¼äµÄ¶¥µã×ÅÉ«Æ÷ // * FRAGMENT_SHADER_BEGIN ºÍ FRAGMENT_SHADER_ENDÖ®¼äµÄƬ¶Î×ÅÉ«Æ÷ // * ÈýÕßÖ®ÍâµÄ¹«¹²²¿·Ö -void GLSLCompiler::Compile(std::string& src, std::string& vsh, std::string& fsh, RenderCommandGroup& group)/*throw GLSLCompileException*/ +void GLSCompiler::Compile(std::string& src, std::string& vsh, std::string& fsh, RenderCommandGroup& group)/*throw GLSCompileException*/ { #define CheckLabel(label) {\ int pos = src.find(label);\ if(pos == string::npos || !IsLabelActive(src, label)) {\ s_CompileError = std::string("Compile Shader Error: No ") + #label + " label";\ - throw GLSLCompileException(s_CompileError.c_str());\ + throw GLSCompileException(s_CompileError.c_str());\ }} CheckLabel(VSH_BEGIN); @@ -59,7 +59,7 @@ if(pos == string::npos || !IsLabelActive(src, label)) {\ fsh = common + fsh; } -std::string GLSLCompiler::GetContent(std::string& src, const char* from, const char* to) +std::string GLSCompiler::GetContent(std::string& src, const char* from, const char* to) { int begin = src.find(from); int end = src.find(to); @@ -71,7 +71,7 @@ std::string GLSLCompiler::GetContent(std::string& src, const char* from, const c return content; } -std::string GLSLCompiler::TrimContent(std::string& src, const char* from, const char* to) +std::string GLSCompiler::TrimContent(std::string& src, const char* from, const char* to) { int begin = src.find(from); int end = src.find(to); @@ -79,7 +79,7 @@ std::string GLSLCompiler::TrimContent(std::string& src, const char* from, const return result; } -bool GLSLCompiler::IsLabelActive(std::string& src, const char* label) +bool GLSCompiler::IsLabelActive(std::string& src, const char* label) { int pos = src.find(label); if (pos == string::npos) @@ -98,7 +98,7 @@ bool GLSLCompiler::IsLabelActive(std::string& src, const char* label) return true; } -bool GLSLCompiler::IsCommandActive(std::string& src, const char* label) +bool GLSCompiler::IsCommandActive(std::string& src, const char* label) { int pos = src.find(label); if (pos == string::npos) @@ -117,7 +117,7 @@ bool GLSLCompiler::IsCommandActive(std::string& src, const char* label) return true; } -void GLSLCompiler::ParseCmd(std::string& cmds, RenderCommandGroup& group) +void GLSCompiler::ParseCmd(std::string& cmds, RenderCommandGroup& group) { istringstream ss = istringstream(cmds); string line; @@ -139,7 +139,7 @@ void GLSLCompiler::ParseCmd(std::string& cmds, RenderCommandGroup& group) else { s_CompileError = string("Unknown command " + cmdName); - throw GLSLCompileException(s_CompileError.c_str()); + throw GLSCompileException(s_CompileError.c_str()); } } } @@ -147,7 +147,7 @@ void GLSLCompiler::ParseCmd(std::string& cmds, RenderCommandGroup& group) #define IsSeperator(c) (c == ' ' || c == '\r' || c == '\n' || c == /*tab*/9) // ÕÒµ½ÐÐÄڵĵÚÒ»¸öµ¥´Ê£¬×÷ΪÃüÁîÃû -bool GLSLCompiler::FindCmdPos(std::string& line, int* start, int* end) +bool GLSCompiler::FindCmdPos(std::string& line, int* start, int* end) { for (int i = 0; i < line.size(); ++i) { @@ -166,7 +166,7 @@ bool GLSLCompiler::FindCmdPos(std::string& line, int* start, int* end) return false; } -bool GLSLCompiler::IsLineCommentd(std::string& line) +bool GLSCompiler::IsLineCommentd(std::string& line) { for (int i = 0; i < line.size(); ++i) { @@ -185,7 +185,7 @@ bool GLSLCompiler::IsLineCommentd(std::string& line) #define MAX_PARAM 2 -void GLSLCompiler::CommandCull(std::string& p, RenderCommandGroup& group) +void GLSCompiler::CommandCull(std::string& p, RenderCommandGroup& group) { std::string params[1]; GetParams("Cull", p, params, 1); @@ -200,12 +200,12 @@ void GLSLCompiler::CommandCull(std::string& p, RenderCommandGroup& group) { delete pCull; s_CompileError = string("Compile Shader Error: Invalid parameter of Cull: " + params[0]); - throw GLSLCompileException(s_CompileError.c_str()); + throw GLSCompileException(s_CompileError.c_str()); } group.push_back(pCull); } -void GLSLCompiler::CommandBlend(std::string& p, RenderCommandGroup& group) +void GLSCompiler::CommandBlend(std::string& p, RenderCommandGroup& group) { std::string params[2]; GetParams("Blend", p, params, 2); @@ -239,7 +239,7 @@ void GLSLCompiler::CommandBlend(std::string& p, RenderCommandGroup& group) { delete pblend; s_CompileError = string("Compile Shader Error: Invalid parameter of Blend: " + params[0]); - throw GLSLCompileException(s_CompileError.c_str()); + throw GLSCompileException(s_CompileError.c_str()); } if (params[1] == "Zero") blend.dstFac = Cmd_Blend::Blend_Zero; @@ -260,13 +260,13 @@ void GLSLCompiler::CommandBlend(std::string& p, RenderCommandGroup& group) { delete pblend; s_CompileError = string("Compile Shader Error: Invalid parameter of Blend: " + params[1]); - throw GLSLCompileException(s_CompileError.c_str()); + throw GLSCompileException(s_CompileError.c_str()); } group.push_back(pblend); } -void GLSLCompiler::CommandDepthTest(std::string& p, RenderCommandGroup& group) +void GLSCompiler::CommandDepthTest(std::string& p, RenderCommandGroup& group) { std::string params[1]; GetParams("DepthTest", p, params, 1); @@ -286,12 +286,12 @@ void GLSLCompiler::CommandDepthTest(std::string& p, RenderCommandGroup& group) { delete pTest; s_CompileError = string("Compile Shader Error: Invalid parameter of DepthTest: " + params[0]); - throw GLSLCompileException(s_CompileError.c_str()); + throw GLSCompileException(s_CompileError.c_str()); } group.push_back(pTest); } -void GLSLCompiler::CommandDepthWrite(std::string& p, RenderCommandGroup& group) +void GLSCompiler::CommandDepthWrite(std::string& p, RenderCommandGroup& group) { std::string params[1]; GetParams("DepthWrite", p, params, 1); @@ -304,12 +304,12 @@ void GLSLCompiler::CommandDepthWrite(std::string& p, RenderCommandGroup& group) { delete pwrite; s_CompileError = string("Compile Shader Error: Invalid parameter of DepthWrite: " + params[0]); - throw GLSLCompileException(s_CompileError.c_str()); + throw GLSCompileException(s_CompileError.c_str()); } group.push_back(pwrite); } -void GLSLCompiler::GetParams(const char* cmdName, std::string& params, std::string* out, int n) +void GLSCompiler::GetParams(const char* cmdName, std::string& params, std::string* out, int n) { int index = 0; for (int i = 0; i < params.size(); ++i) @@ -324,7 +324,7 @@ void GLSLCompiler::GetParams(const char* cmdName, std::string& params, std::stri if (index >= n) { s_CompileError = string("Compile Shader Error: Invalid parameter count of ") + cmdName +" : " + params; - throw GLSLCompileException(s_CompileError.c_str()); + throw GLSCompileException(s_CompileError.c_str()); } if(!IsSeperator(params[j])) out[index++] = params.substr(i, j - i + 1); @@ -337,7 +337,7 @@ void GLSLCompiler::GetParams(const char* cmdName, std::string& params, std::stri if (index >= n) { s_CompileError = string("Compile Shader Error: Invalid parameter count of ") + cmdName + " : " + params; - throw GLSLCompileException(s_CompileError.c_str()); + throw GLSCompileException(s_CompileError.c_str()); } out[index++] = params.substr(i, j - i); break; diff --git a/Runtime/Graphics/ShaderCompiler.h b/Runtime/Graphics/ShaderCompiler.h index 891efb7..2d48bb0 100644 --- a/Runtime/Graphics/ShaderCompiler.h +++ b/Runtime/Graphics/ShaderCompiler.h @@ -6,36 +6,36 @@ #include "Runtime/Threading/Job.h" #include "Runtime/Graphics/RenderCommands.h" -// ±àÒëGLSL(GameLab Shading Language) +// ±àÒëGLS(GameLab Shader) // in: .glsl path // out: vsh & fsh -class CompileGLSLJob : public Job +class CompileGLSJob : public Job { }; // in: glsl shader // out: vsh & fsh -class CompileGLSLShaderJob : public Job +class CompileGLSShaderJob : public Job { }; -class GLSLCompileException : public std::exception +class GLSCompileException : public std::exception { public: - GLSLCompileException(const char* what) + GLSCompileException(const char* what) : std::exception(what) { } }; -class GLSLCompiler +class GLSCompiler { public: - static void Compile(std::string& src, std::string& vsh, std::string& fsh, RenderCommandGroup& cmd)/*throw GLSLCompileException*/; + static void Compile(std::string& src, std::string& vsh, std::string& fsh, RenderCommandGroup& cmd)/*throw GLSCompileException*/; private: static std::string GetContent(std::string& src, const char* from, const char* to); -- cgit v1.1-26-g67d0