diff --git a/data/shaders/detailledobject_pass2.frag b/data/shaders/detailledobject_pass2.frag index 832a68f70..5b19966cc 100644 --- a/data/shaders/detailledobject_pass2.frag +++ b/data/shaders/detailledobject_pass2.frag @@ -1,9 +1,11 @@ #ifdef GL_ARB_bindless_texture layout(bindless_sampler) uniform sampler2D Albedo; layout(bindless_sampler) uniform sampler2D Detail; +layout(bindless_sampler) uniform sampler2D SpecMap; #else uniform sampler2D Albedo; uniform sampler2D Detail; +uniform sampler2D SpecMap; #endif #if __VERSION__ >= 130 @@ -28,5 +30,6 @@ void main(void) #endif vec4 detail = texture(Detail, uv_bis); color *= detail; - FragColor = vec4(getLightFactor(color.xyz, vec3(1.), 1.), 1.); + float specmap = texture(SpecMap, uv).g; + FragColor = vec4(getLightFactor(color.xyz, vec3(1.), specmap), 1.); } diff --git a/data/shaders/grass_pass2.frag b/data/shaders/grass_pass2.frag index 10d747e1b..6b677ceea 100644 --- a/data/shaders/grass_pass2.frag +++ b/data/shaders/grass_pass2.frag @@ -1,9 +1,11 @@ #ifdef GL_ARB_bindless_texture layout(bindless_sampler) uniform sampler2D Albedo; layout(bindless_sampler) uniform sampler2D dtex; +layout(bindless_sampler) uniform sampler2D SpecMap; #else uniform sampler2D Albedo; uniform sampler2D dtex; +uniform sampler2D SpecMap; #endif uniform vec3 SunDir; @@ -38,7 +40,8 @@ void main(void) float fLdotNBack = max(0., - dot(nor, SunDir) * 0.6 + 0.4); float scattering = mix(fPowEdotL, fLdotNBack, .5); + float specmap = texture(SpecMap, uv).g; - vec3 LightFactor = color.xyz * (scattering * 0.3) + getLightFactor(color.xyz, vec3(1.), 1.); + vec3 LightFactor = color.xyz * (scattering * 0.3) + getLightFactor(color.xyz, vec3(1.), specmap); FragColor = vec4(color.xyz * LightFactor, 1.); } diff --git a/data/shaders/object_pass2.frag b/data/shaders/object_pass2.frag index 53341f689..dc2fca7f1 100644 --- a/data/shaders/object_pass2.frag +++ b/data/shaders/object_pass2.frag @@ -1,7 +1,9 @@ #ifdef GL_ARB_bindless_texture layout(bindless_sampler) uniform sampler2D Albedo; +layout(bindless_sampler) uniform sampler2D SpecMap; #else uniform sampler2D Albedo; +uniform sampler2D SpecMap; #endif in vec2 uv; @@ -21,5 +23,6 @@ void main(void) vec4 col = texture(Albedo, uv); #endif col.xyz *= pow(color.xyz, vec3(2.2)); - FragColor = vec4(getLightFactor(color.xyz, vec3(1.), 1.), 1.); + float specmap = texture(SpecMap, uv).g; + FragColor = vec4(getLightFactor(color.xyz, vec3(1.), specmap), 1.); } diff --git a/data/shaders/objectref_pass2.frag b/data/shaders/objectref_pass2.frag index d6b2d1f1c..ae1531a98 100644 --- a/data/shaders/objectref_pass2.frag +++ b/data/shaders/objectref_pass2.frag @@ -1,7 +1,9 @@ #ifdef GL_ARB_bindless_texture layout(bindless_sampler) uniform sampler2D Albedo; +layout(bindless_sampler) uniform sampler2D SpecMap; #else uniform sampler2D Albedo; +uniform sampler2D SpecMap; #endif in vec2 uv; @@ -20,5 +22,6 @@ void main(void) #endif col.xyz *= pow(color.xyz, vec3(2.2)); if (col.a * color.a < 0.5) discard; - FragColor = vec4(getLightFactor(color.xyz, vec3(1.), 1.), 1.); + float specmap = texture(SpecMap, uv).g; + FragColor = vec4(getLightFactor(color.xyz, vec3(1.), specmap), 1.); } diff --git a/src/graphics/shaders.cpp b/src/graphics/shaders.cpp index 61148e2ac..289d81660 100644 --- a/src/graphics/shaders.cpp +++ b/src/graphics/shaders.cpp @@ -854,7 +854,7 @@ namespace MeshShader GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/utils/getLightFactor.frag").c_str(), GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/object_pass2.frag").c_str()); AssignUniforms("ModelMatrix", "TextureMatrix"); - AssignSamplerNames(Program, 0, "DiffuseMap", 1, "SpecularMap", 2, "SSAO", 3, "Albedo"); + AssignSamplerNames(Program, 0, "DiffuseMap", 1, "SpecularMap", 2, "SSAO", 3, "Albedo", 4, "Specmap"); } InstancedObjectPass2Shader::InstancedObjectPass2Shader() @@ -886,7 +886,7 @@ namespace MeshShader GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/utils/getLightFactor.frag").c_str(), GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/detailledobject_pass2.frag").c_str()); AssignUniforms("ModelMatrix"); - AssignSamplerNames(Program, 0, "DiffuseMap", 1, "SpecularMap", 2, "SSAO", 3, "Albedo", 4, "Detail"); + AssignSamplerNames(Program, 0, "DiffuseMap", 1, "SpecularMap", 2, "SSAO", 3, "Albedo", 4, "Detail", 5, "Specmap"); } InstancedDetailledObjectPass2Shader::InstancedDetailledObjectPass2Shader() @@ -926,7 +926,7 @@ namespace MeshShader GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/utils/getLightFactor.frag").c_str(), GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/objectref_pass2.frag").c_str()); AssignUniforms("ModelMatrix", "TextureMatrix"); - AssignSamplerNames(Program, 0, "DiffuseMap", 1, "SpecularMap", 2, "SSAO", 3, "Albedo"); + AssignSamplerNames(Program, 0, "DiffuseMap", 1, "SpecularMap", 2, "SSAO", 3, "Albedo", 4, "Specmap"); } GrassPass2Shader::GrassPass2Shader() @@ -936,7 +936,7 @@ namespace MeshShader GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/utils/getLightFactor.frag").c_str(), GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/grass_pass2.frag").c_str()); AssignUniforms("ModelMatrix", "windDir"); - AssignSamplerNames(Program, 0, "DiffuseMap", 1, "SpecularMap", 2, "SSAO", 3, "Albedo"); + AssignSamplerNames(Program, 0, "DiffuseMap", 1, "SpecularMap", 2, "SSAO", 3, "Albedo", 4, "Specmap"); } InstancedGrassPass2Shader::InstancedGrassPass2Shader() @@ -947,7 +947,7 @@ namespace MeshShader GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/utils/getLightFactor.frag").c_str(), GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/instanced_grass_pass2.frag").c_str()); AssignUniforms("windDir", "SunDir"); - AssignSamplerNames(Program, 0, "DiffuseMap", 1, "SpecularMap", 2, "SSAO", 3, "dtex", 4, "Albedo", 4, "SpecMap"); + AssignSamplerNames(Program, 0, "DiffuseMap", 1, "SpecularMap", 2, "SSAO", 3, "dtex", 4, "Albedo", 5, "SpecMap"); } SphereMapShader::SphereMapShader() diff --git a/src/graphics/shaders.hpp b/src/graphics/shaders.hpp index 719bf63b0..3113ce75c 100644 --- a/src/graphics/shaders.hpp +++ b/src/graphics/shaders.hpp @@ -101,7 +101,7 @@ public: InstancedNormalMapShader(); }; -class ObjectPass2Shader : public ShaderHelperSingleton, public TextureRead +class ObjectPass2Shader : public ShaderHelperSingleton, public TextureRead { public: ObjectPass2Shader(); @@ -119,7 +119,7 @@ public: InstancedObjectRefPass2Shader(); }; -class DetailledObjectPass2Shader : public ShaderHelperSingleton, public TextureRead +class DetailledObjectPass2Shader : public ShaderHelperSingleton, public TextureRead { public: DetailledObjectPass2Shader(); @@ -143,13 +143,13 @@ public: InstancedObjectUnlitShader(); }; -class ObjectRefPass2Shader : public ShaderHelperSingleton, public TextureRead +class ObjectRefPass2Shader : public ShaderHelperSingleton, public TextureRead { public: ObjectRefPass2Shader(); }; -class GrassPass2Shader : public ShaderHelperSingleton, public TextureRead +class GrassPass2Shader : public ShaderHelperSingleton, public TextureRead { public: GrassPass2Shader();