diff --git a/data/shaders/godfade.frag b/data/shaders/godfade.frag index e44fdec04..cb16f93ab 100644 --- a/data/shaders/godfade.frag +++ b/data/shaders/godfade.frag @@ -1,11 +1,13 @@ -#version 330 compatibility +#version 330 uniform sampler2D tex; uniform vec3 col; + +in vec2 uv; out vec4 FragColor; void main() { - vec4 res = texture(tex, gl_TexCoord[0].xy); + vec4 res = texture(tex, uv); // Keep the sun fully bright, but fade the sky float mul = distance(res.xyz, col); diff --git a/data/shaders/godray.frag b/data/shaders/godray.frag index 83422eb9c..b83e2bd12 100644 --- a/data/shaders/godray.frag +++ b/data/shaders/godray.frag @@ -1,4 +1,4 @@ -#version 330 compatibility +#version 330 uniform sampler2D tex; uniform vec2 sunpos; @@ -6,11 +6,12 @@ uniform vec2 sunpos; const float decaystep = 0.88; +in vec2 uv; out vec4 FragColor; void main() { - vec2 texc = gl_TexCoord[0].xy; + vec2 texc = uv; vec2 tosun = sunpos - texc; if (dot(tosun, tosun) > 0.49) discard; diff --git a/src/graphics/shaders.cpp b/src/graphics/shaders.cpp index 853b6073b..397560bf8 100644 --- a/src/graphics/shaders.cpp +++ b/src/graphics/shaders.cpp @@ -239,6 +239,8 @@ void Shaders::loadShaders() FullScreenShader::SunLightShader::init(); FullScreenShader::ShadowedSunLightShader::init(); FullScreenShader::MotionBlurShader::init(); + FullScreenShader::GodFadeShader::init(); + FullScreenShader::GodRayShader::init(); MeshShader::ColorizeShader::init(); MeshShader::NormalMapShader::init(); MeshShader::ObjectPass1Shader::init(); @@ -1724,6 +1726,44 @@ namespace FullScreenShader glUniform1f(uniform_max_tex_height, max_tex_height); glUniform1i(uniform_color_buffer, TU_cb); } + + GLuint GodFadeShader::Program; + GLuint GodFadeShader::uniform_tex; + GLuint GodFadeShader::uniform_col; + GLuint GodFadeShader::vao; + + void GodFadeShader::init() + { + Program = LoadProgram(file_manager->getAsset("shaders/screenquad.vert").c_str(), file_manager->getAsset("shaders/godfade.frag").c_str()); + uniform_tex = glGetUniformLocation(Program, "tex"); + uniform_col = glGetUniformLocation(Program, "col"); + vao = createVAO(Program); + } + + void GodFadeShader::setUniforms(const SColor &col, unsigned TU_tex) + { + glUniform3f(uniform_col, col.getRed() / 255., col.getGreen() / 255., col.getBlue() / 255.); + glUniform1i(uniform_tex, TU_tex); + } + + GLuint GodRayShader::Program; + GLuint GodRayShader::uniform_tex; + GLuint GodRayShader::uniform_sunpos; + GLuint GodRayShader::vao; + + void GodRayShader::init() + { + Program = LoadProgram(file_manager->getAsset("shaders/screenquad.vert").c_str(), file_manager->getAsset("shaders/godray.frag").c_str()); + uniform_tex = glGetUniformLocation(Program, "tex"); + uniform_sunpos = glGetUniformLocation(Program, "sunpos"); + vao = createVAO(Program); + } + + void GodRayShader::setUniforms(const core::vector2df &sunpos, unsigned TU_tex) + { + glUniform2f(uniform_sunpos, sunpos.X, sunpos.Y); + glUniform1i(uniform_tex, TU_tex); + } } namespace UIShader diff --git a/src/graphics/shaders.hpp b/src/graphics/shaders.hpp index 5231010d6..8463a163d 100644 --- a/src/graphics/shaders.hpp +++ b/src/graphics/shaders.hpp @@ -534,6 +534,28 @@ public: static void setUniforms(float boost_amount, const core::vector2df ¢er, const core::vector2df &direction, float mask_radius, float max_tex_height, unsigned TU_cb); }; +class GodFadeShader +{ +public: + static GLuint Program; + static GLuint uniform_tex, uniform_col; + static GLuint vao; + + static void init(); + static void setUniforms(const video::SColor &col, unsigned TU_tex); +}; + +class GodRayShader +{ +public: + static GLuint Program; + static GLuint uniform_tex, uniform_sunpos; + static GLuint vao; + + static void init(); + static void setUniforms(const core::vector2df &sunpos, unsigned TU_tex); +}; + } namespace UIShader