diff --git a/data/shaders/object_pass2.frag b/data/shaders/object_pass2.frag index 838570ead..93f0a0fb0 100644 --- a/data/shaders/object_pass2.frag +++ b/data/shaders/object_pass2.frag @@ -40,7 +40,7 @@ void main(void) col = vec4(new_color.r, new_color.g, new_color.b, col.a); } -#ifdef GL_ES +#if defined(GL_ES) && !defined(Advanced_Lighting_Enabled) col.xyz *= color.xyz; #else col.xyz *= pow(color.xyz, vec3(2.2)); diff --git a/data/shaders/object_unlit.frag b/data/shaders/object_unlit.frag index 15c775fbd..d13305612 100644 --- a/data/shaders/object_unlit.frag +++ b/data/shaders/object_unlit.frag @@ -16,7 +16,13 @@ void main(void) col.xyz = pow(col.xyz, vec3(2.2)); #endif #endif - col.xyz *= pow(color.xyz, vec3(2.2)); if (col.a < 0.5) discard; + +#if defined(GL_ES) && !defined(Advanced_Lighting_Enabled) + col.xyz *= color.xyz; +#else + col.xyz *= pow(color.xyz, vec3(2.2)); +#endif + FragColor = vec4(col.xyz, 1.); } diff --git a/data/shaders/objectref_pass2.frag b/data/shaders/objectref_pass2.frag index a6374bd0d..3dacf6bdb 100644 --- a/data/shaders/objectref_pass2.frag +++ b/data/shaders/objectref_pass2.frag @@ -25,8 +25,13 @@ void main(void) col.xyz = pow(col.xyz, vec3(2.2)); #endif #endif - col.xyz *= pow(color.xyz, vec3(2.2)); if (col.a * color.a < 0.5) discard; + +#if defined(GL_ES) && !defined(Advanced_Lighting_Enabled) + col.xyz *= color.xyz; +#else + col.xyz *= pow(color.xyz, vec3(2.2)); +#endif float mask = texture(colorization_mask, uv).a; if (color_change.x > 0.0) diff --git a/data/shaders/tonemap.frag b/data/shaders/tonemap.frag index 13c6b32ce..251f18ac1 100644 --- a/data/shaders/tonemap.frag +++ b/data/shaders/tonemap.frag @@ -13,7 +13,9 @@ void main() // Uncharted2 tonemap with Auria's custom coefficients vec4 perChannel = (col * (6.9 * col + .5)) / (col * (5.2 * col + 1.7) + 0.06); +#if !(defined(GL_ES) && defined(Advanced_Lighting_Enabled)) perChannel = pow(perChannel, vec4(2.2)); +#endif vec2 inside = uv - 0.5; float vignette = 1. - dot(inside, inside) * vignette_weight; diff --git a/data/shaders/utils/getLightFactor.frag b/data/shaders/utils/getLightFactor.frag index 4fb754069..7096ac48d 100644 --- a/data/shaders/utils/getLightFactor.frag +++ b/data/shaders/utils/getLightFactor.frag @@ -14,7 +14,7 @@ vec3 getLightFactor(vec3 diffuseMatColor, vec3 specularMatColor, float specMapVa vec3 DiffuseComponent = texture(DiffuseMap, tc).xyz; vec3 SpecularComponent = texture(SpecularMap, tc).xyz; float ao = texture(SSAO, tc).x; -#ifdef GL_ES +#if defined(GL_ES) && !defined(Advanced_Lighting_Enabled) DiffuseComponent = pow(DiffuseComponent, vec3(1. / 2.2)); SpecularComponent = pow(SpecularComponent, vec3(1. / 2.2)); #endif diff --git a/src/graphics/shader_files_manager.cpp b/src/graphics/shader_files_manager.cpp index 2a69220db..6682af1b6 100644 --- a/src/graphics/shader_files_manager.cpp +++ b/src/graphics/shader_files_manager.cpp @@ -164,6 +164,8 @@ GLuint ShaderFilesManager::loadShader(const std::string &file, unsigned type) code << "#define VSLayer\n"; if (CVS->needsRGBBindlessWorkaround()) code << "#define SRGBBindlessFix\n"; + if (CVS->isDefferedEnabled()) + code << "#define Advanced_Lighting_Enabled\n"; #if !defined(USE_GLES2) // shader compilation fails with some drivers if there is no precision diff --git a/src/graphics/skybox.cpp b/src/graphics/skybox.cpp index 9c7a27a48..f8d503cd6 100644 --- a/src/graphics/skybox.cpp +++ b/src/graphics/skybox.cpp @@ -163,19 +163,6 @@ void Skybox::generateCubeMapFromTextures() assert(img != NULL); img->copyToScaling(rgba[i], size, size); -#if defined(USE_GLES2) - if (CVS->isEXTTextureFormatBGRA8888Usable()) - { - // BGRA image returned by getTextureImage causes black sky in gles - for (unsigned int j = 0; j < size * size; j++) - { - char tmp_val = rgba[i][j * 4]; - rgba[i][j * 4] = rgba[i][j * 4 + 2]; - rgba[i][j * 4 + 2] = tmp_val; - } - } -#endif - if (i == 2 || i == 3) { char *tmp = new char[size * size * 4]; @@ -196,7 +183,8 @@ void Skybox::generateCubeMapFromTextures() GL_COMPRESSED_SRGB_ALPHA : GL_SRGB_ALPHA; GLint format = GL_BGRA; #else - GLint internal_format = GL_RGBA8; + GLint internal_format = CVS->isDefferedEnabled() ? GL_SRGB8_ALPHA8 + : GL_RGBA8; GLint format = GL_RGBA; #endif diff --git a/src/graphics/spherical_harmonics.cpp b/src/graphics/spherical_harmonics.cpp index 3a4a4c9f7..c94149bbf 100644 --- a/src/graphics/spherical_harmonics.cpp +++ b/src/graphics/spherical_harmonics.cpp @@ -565,15 +565,12 @@ void SphericalHarmonics::setTextures(const std::vector &spher assert(img != NULL); img->copyToScaling(sh_rgba[i], sh_w, sh_h); #if defined(USE_GLES2) - if (!CVS->isEXTTextureFormatBGRA8888Usable()) + // Code here assume color format is BGRA + for (unsigned int j = 0; j < sh_w * sh_h; j++) { - // Code here assume color format is BGRA - for (unsigned int j = 0; j < sh_w * sh_h; j++) - { - char tmp_val = sh_rgba[i][j * 4]; - sh_rgba[i][j * 4] = sh_rgba[i][j * 4 + 2]; - sh_rgba[i][j * 4 + 2] = tmp_val; - } + char tmp_val = sh_rgba[i][j * 4]; + sh_rgba[i][j * 4] = sh_rgba[i][j * 4 + 2]; + sh_rgba[i][j * 4 + 2] = tmp_val; } #endif } //for (unsigned i = 0; i < 6; i++) diff --git a/src/graphics/stk_texture.cpp b/src/graphics/stk_texture.cpp index 3a6a078f7..a1963993c 100644 --- a/src/graphics/stk_texture.cpp +++ b/src/graphics/stk_texture.cpp @@ -52,6 +52,10 @@ STKTexture::STKTexture(const std::string& path, TexConfig* tc, bool no_upload) #ifndef SERVER_ONLY if (m_tex_config && !CVS->isGLSL()) m_tex_config->m_srgb = false; +#ifdef USE_GLES2 + if (m_tex_config && !CVS->isDefferedEnabled()) + m_tex_config->m_srgb = false; +#endif if (!CVS->isARBTextureSwizzleUsable()) m_single_channel = false; #endif @@ -215,7 +219,8 @@ void STKTexture::reload(bool no_upload, uint8_t* preload_data, const unsigned int w = m_size.Width; const unsigned int h = m_size.Height; unsigned int format = m_single_channel ? GL_RED : GL_BGRA; - unsigned int internal_format = m_single_channel ? GL_R8 : GL_RGBA; + unsigned int internal_format = m_single_channel ? GL_R8 : isSrgb() ? + GL_SRGB8_ALPHA8 : GL_RGBA8; #if !defined(USE_GLES2) if (isMeshTexture() && CVS->isTextureCompressionEnabled()) @@ -224,12 +229,8 @@ void STKTexture::reload(bool no_upload, uint8_t* preload_data, isSrgb() ? GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT : GL_COMPRESSED_RGBA_S3TC_DXT5_EXT; } - else - { - internal_format = - m_single_channel ? GL_R8 : isSrgb() ? GL_SRGB8_ALPHA8 : GL_RGBA8; - } #endif + if (!useThreadedLoading()) formatConversion(data, &format, w, h); @@ -303,7 +304,7 @@ void STKTexture::formatConversion(uint8_t* data, unsigned int* format, unsigned int w, unsigned int h) const { #if defined(USE_GLES2) - if (!CVS->isEXTTextureFormatBGRA8888Usable() && !m_single_channel) + if (!m_single_channel) { if (format) *format = GL_RGBA;