diff --git a/data/shaders/diffuseenvmap.frag b/data/shaders/IBL.frag similarity index 100% rename from data/shaders/diffuseenvmap.frag rename to data/shaders/IBL.frag diff --git a/data/shaders/gi.frag b/data/shaders/gi.frag index e90f88d92..9ab0f9dfd 100644 --- a/data/shaders/gi.frag +++ b/data/shaders/gi.frag @@ -9,7 +9,6 @@ uniform sampler3D SHR; uniform sampler3D SHG; uniform sampler3D SHB; -uniform float R_wcs = 10.; uniform vec3 extents; uniform mat4 RHMatrix; uniform mat4 InvRHMatrix; diff --git a/data/shaders/pointlight.frag b/data/shaders/pointlight.frag index c479ec7ce..cabadc0b5 100644 --- a/data/shaders/pointlight.frag +++ b/data/shaders/pointlight.frag @@ -10,7 +10,7 @@ out vec4 Diffuse; out vec4 Specular; vec3 DecodeNormal(vec2 n); -vec3 getSpecular(vec3 normal, vec3 eyedir, vec3 lightdir, vec3 color, float roughness); +vec3 SpecularBRDF(vec3 normal, vec3 eyedir, vec3 lightdir, vec3 color, float roughness); vec4 getPosFromUVDepth(vec3 uvDepth, mat4 InverseProjectionMatrix); void main() @@ -38,5 +38,5 @@ void main() float NdotL = max(0., dot(norm, L)); Diffuse = vec4(NdotL * light_col * att, 1.); - Specular = vec4(getSpecular(norm, eyedir, L, light_col, roughness) * NdotL * att, 1.); + Specular = vec4(SpecularBRDF(norm, eyedir, L, light_col, roughness) * NdotL * att, 1.); } diff --git a/data/shaders/sunlight.frag b/data/shaders/sunlight.frag index e3bcc8942..e7503241e 100644 --- a/data/shaders/sunlight.frag +++ b/data/shaders/sunlight.frag @@ -13,7 +13,7 @@ out vec4 Diff; out vec4 Spec; vec3 DecodeNormal(vec2 n); -vec3 getSpecular(vec3 normal, vec3 eyedir, vec3 lightdir, vec3 color, float roughness); +vec3 SpecularBRDF(vec3 normal, vec3 eyedir, vec3 lightdir, vec3 color, float roughness); vec4 getPosFromUVDepth(vec3 uvDepth, mat4 InverseProjectionMatrix); vec3 getMostRepresentativePoint(vec3 direction, vec3 R, float angularRadius) @@ -52,7 +52,7 @@ void main() { vec3 R = reflect(-eyedir, norm); vec3 Lightdir = getMostRepresentativePoint(direction, R, angle); - vec3 Specular = getSpecular(norm, eyedir, Lightdir, col, roughness) * NdotL; + vec3 Specular = SpecularBRDF(norm, eyedir, Lightdir, col, roughness) * NdotL; vec3 outcol = NdotL * col; diff --git a/data/shaders/sunlightshadow.frag b/data/shaders/sunlightshadow.frag index f903148c2..c60665e63 100644 --- a/data/shaders/sunlightshadow.frag +++ b/data/shaders/sunlightshadow.frag @@ -16,7 +16,7 @@ out vec4 Diff; out vec4 Spec; vec3 DecodeNormal(vec2 n); -vec3 getSpecular(vec3 normal, vec3 eyedir, vec3 lightdir, vec3 color, float roughness); +vec3 SpecularBRDF(vec3 normal, vec3 eyedir, vec3 lightdir, vec3 color, float roughness); vec4 getPosFromUVDepth(vec3 uvDepth, mat4 InverseProjectionMatrix); vec3 getMostRepresentativePoint(vec3 direction, vec3 R, float angularRadius) @@ -66,7 +66,7 @@ void main() { vec3 R = reflect(-eyedir, norm); vec3 Lightdir = getMostRepresentativePoint(direction, R, angle); - vec3 Specular = getSpecular(norm, eyedir, Lightdir, col, roughness) * NdotL; + vec3 Specular = SpecularBRDF(norm, eyedir, Lightdir, col, roughness) * NdotL; vec3 outcol = NdotL * col; diff --git a/data/shaders/utils/getSpecular.frag b/data/shaders/utils/SpecularBRDF.frag similarity index 76% rename from data/shaders/utils/getSpecular.frag rename to data/shaders/utils/SpecularBRDF.frag index 85ed5e761..2795b3f48 100644 --- a/data/shaders/utils/getSpecular.frag +++ b/data/shaders/utils/SpecularBRDF.frag @@ -1,6 +1,5 @@ - - -vec3 getSpecular(vec3 normal, vec3 eyedir, vec3 lightdir, vec3 color, float roughness) +// Blinn Phong with emulated fresnel factor +vec3 SpecularBRDF(vec3 normal, vec3 eyedir, vec3 lightdir, vec3 color, float roughness) { float exponentroughness = exp2(10. * roughness + 1.); // Half Light View direction diff --git a/src/graphics/post_processing.cpp b/src/graphics/post_processing.cpp index 123da79ba..9d8dcf0b0 100644 --- a/src/graphics/post_processing.cpp +++ b/src/graphics/post_processing.cpp @@ -228,12 +228,12 @@ void PostProcessing::renderEnvMap(const float *bSHCoeff, const float *gSHCoeff, glBlendEquation(GL_FUNC_ADD); glBlendFunc(GL_ONE, GL_ONE); - glUseProgram(FullScreenShader::EnvMapShader::getInstance()->Program); + glUseProgram(FullScreenShader::IBLShader::getInstance()->Program); glBindVertexArray(SharedObject::FullScreenQuadVAO); - FullScreenShader::EnvMapShader::getInstance()->SetTextureUnits(irr_driver->getRenderTargetTexture(RTT_NORMAL_AND_DEPTH), irr_driver->getDepthStencilTexture(), skybox); + FullScreenShader::IBLShader::getInstance()->SetTextureUnits(irr_driver->getRenderTargetTexture(RTT_NORMAL_AND_DEPTH), irr_driver->getDepthStencilTexture(), skybox); core::matrix4 TVM = irr_driver->getViewMatrix().getTransposed(); - FullScreenShader::EnvMapShader::getInstance()->setUniforms(TVM, std::vector(bSHCoeff, bSHCoeff + 9), std::vector(gSHCoeff, gSHCoeff + 9), std::vector(rSHCoeff, rSHCoeff + 9)); + FullScreenShader::IBLShader::getInstance()->setUniforms(TVM, std::vector(bSHCoeff, bSHCoeff + 9), std::vector(gSHCoeff, gSHCoeff + 9), std::vector(rSHCoeff, rSHCoeff + 9)); glDrawArrays(GL_TRIANGLES, 0, 3); glBindVertexArray(0); diff --git a/src/graphics/shaders.cpp b/src/graphics/shaders.cpp index f7c8b8e24..3706f140e 100644 --- a/src/graphics/shaders.cpp +++ b/src/graphics/shaders.cpp @@ -1426,7 +1426,7 @@ namespace LightShader Program = LoadProgram(OBJECT, GL_VERTEX_SHADER, file_manager->getAsset("shaders/pointlight.vert").c_str(), GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/utils/decodeNormal.frag").c_str(), - GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/utils/getSpecular.frag").c_str(), + GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/utils/SpecularBRDF.frag").c_str(), GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/utils/getPosFromUVDepth.frag").c_str(), GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/pointlight.frag").c_str()); @@ -1625,7 +1625,7 @@ namespace FullScreenShader Program = LoadProgram(OBJECT, GL_VERTEX_SHADER, file_manager->getAsset("shaders/screenquad.vert").c_str(), GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/utils/decodeNormal.frag").c_str(), - GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/utils/getSpecular.frag").c_str(), + GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/utils/SpecularBRDF.frag").c_str(), GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/utils/getPosFromUVDepth.frag").c_str(), GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/sunlight.frag").c_str()); @@ -1633,13 +1633,13 @@ namespace FullScreenShader AssignUniforms("direction", "col"); } - EnvMapShader::EnvMapShader() + IBLShader::IBLShader() { Program = LoadProgram(OBJECT, GL_VERTEX_SHADER, file_manager->getAsset("shaders/screenquad.vert").c_str(), GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/utils/decodeNormal.frag").c_str(), GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/utils/getPosFromUVDepth.frag").c_str(), - GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/diffuseenvmap.frag").c_str()); + GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/IBL.frag").c_str()); AssignUniforms("TransposeViewMatrix", "blueLmn[0]", "greenLmn[0]", "redLmn[0]"); AssignSamplerNames(Program, 0, "ntex", 1, "dtex", 2, "tex"); } @@ -1649,7 +1649,7 @@ namespace FullScreenShader Program = LoadProgram(OBJECT, GL_VERTEX_SHADER, file_manager->getAsset("shaders/screenquad.vert").c_str(), GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/utils/decodeNormal.frag").c_str(), - GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/utils/getSpecular.frag").c_str(), + GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/utils/SpecularBRDF.frag").c_str(), GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/utils/getPosFromUVDepth.frag").c_str(), GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/sunlightshadow.frag").c_str()); diff --git a/src/graphics/shaders.hpp b/src/graphics/shaders.hpp index 518f7fad0..2251cbb65 100644 --- a/src/graphics/shaders.hpp +++ b/src/graphics/shaders.hpp @@ -411,10 +411,10 @@ public: SunLightShader(); }; -class EnvMapShader : public ShaderHelperSingleton, std::vector, std::vector >, public TextureRead +class IBLShader : public ShaderHelperSingleton, std::vector, std::vector >, public TextureRead { public: - EnvMapShader(); + IBLShader(); }; class ShadowedSunLightShader : public ShaderHelperSingleton, public TextureRead