diff --git a/data/shaders/dof.frag b/data/shaders/dof.frag index 35259d26d..90938d68f 100644 --- a/data/shaders/dof.frag +++ b/data/shaders/dof.frag @@ -21,62 +21,58 @@ void main() vec2 offset = 10. / screen; - vec4 col = texture2D(tex, uv); + vec4 col = texture(tex, uv); vec4 colOriginal = col; // Weight from here http://artmartinsh.blogspot.fr/2010/02/glsl-lens-blur-filter-with-bokeh.html - col += texture2D(tex, uv + (vec2(0.0, 0.4) * offset) * blur); - col += texture2D(tex, uv + (vec2(0.15, 0.37) * offset) * blur); - col += texture2D(tex, uv + (vec2(0.29,0.29) * offset) * blur); - col += texture2D(tex, uv + (vec2(-0.37,0.15) * offset) * blur); - col += texture2D(tex, uv + (vec2(0.4, 0.0) * offset) * blur); - col += texture2D(tex, uv + (vec2(0.37, -0.15) * offset) * blur); - col += texture2D(tex, uv + (vec2(0.29, -0.29) * offset) * blur); - col += texture2D(tex, uv + (vec2(-0.15, -0.37) * offset) * blur); - col += texture2D(tex, uv + (vec2(0.0, -0.4) * offset) * blur); - col += texture2D(tex, uv + (vec2(-0.15, 0.37) * offset) * blur); - col += texture2D(tex, uv + (vec2(-0.29, 0.29) * offset) * blur); - col += texture2D(tex, uv + (vec2(0.37, 0.15) * offset) * blur); - col += texture2D(tex, uv + (vec2(-0.4, 0.0) * offset) * blur); - col += texture2D(tex, uv + (vec2(-0.37, -0.15) * offset) * blur); - col += texture2D(tex, uv + (vec2(-0.29, -0.29) * offset) * blur); - col += texture2D(tex, uv + (vec2(0.15, -0.37) * offset) * blur); + col += texture(tex, uv + (vec2(0.0, 0.4) * offset) * blur); + col += texture(tex, uv + (vec2(0.15, 0.37) * offset) * blur); + col += texture(tex, uv + (vec2(0.29,0.29) * offset) * blur); + col += texture(tex, uv + (vec2(-0.37,0.15) * offset) * blur); + col += texture(tex, uv + (vec2(0.4, 0.0) * offset) * blur); + col += texture(tex, uv + (vec2(0.37, -0.15) * offset) * blur); + col += texture(tex, uv + (vec2(0.29, -0.29) * offset) * blur); + col += texture(tex, uv + (vec2(-0.15, -0.37) * offset) * blur); + col += texture(tex, uv + (vec2(0.0, -0.4) * offset) * blur); + col += texture(tex, uv + (vec2(-0.15, 0.37) * offset) * blur); + col += texture(tex, uv + (vec2(-0.29, 0.29) * offset) * blur); + col += texture(tex, uv + (vec2(0.37, 0.15) * offset) * blur); + col += texture(tex, uv + (vec2(-0.4, 0.0) * offset) * blur); + col += texture(tex, uv + (vec2(-0.37, -0.15) * offset) * blur); + col += texture(tex, uv + (vec2(-0.29, -0.29) * offset) * blur); + col += texture(tex, uv + (vec2(0.15, -0.37) * offset) * blur); - col += texture2D(tex, uv + (vec2(0.15, 0.37) * offset) * blur * 0.9); - col += texture2D(tex, uv + (vec2(-0.37, 0.15) * offset) * blur * 0.9); - col += texture2D(tex, uv + (vec2(0.37, -0.15) * offset) * blur * 0.9); - col += texture2D(tex, uv + (vec2(-0.15, -0.37) * offset) * blur * 0.9); - col += texture2D(tex, uv + (vec2(-0.15, 0.37) * offset) * blur * 0.9); - col += texture2D(tex, uv + (vec2(0.37, 0.15) * offset) * blur * 0.9); - col += texture2D(tex, uv + (vec2(-0.37, -0.15) * offset) * blur * 0.9); - col += texture2D(tex, uv + (vec2(0.15, -0.37) * offset) * blur * 0.9); + col += texture(tex, uv + (vec2(0.15, 0.37) * offset) * blur * 0.9); + col += texture(tex, uv + (vec2(-0.37, 0.15) * offset) * blur * 0.9); + col += texture(tex, uv + (vec2(0.37, -0.15) * offset) * blur * 0.9); + col += texture(tex, uv + (vec2(-0.15, -0.37) * offset) * blur * 0.9); + col += texture(tex, uv + (vec2(-0.15, 0.37) * offset) * blur * 0.9); + col += texture(tex, uv + (vec2(0.37, 0.15) * offset) * blur * 0.9); + col += texture(tex, uv + (vec2(-0.37, -0.15) * offset) * blur * 0.9); + col += texture(tex, uv + (vec2(0.15, -0.37) * offset) * blur * 0.9); - col += texture2D(tex, uv + (vec2(0.29, 0.29) * offset) * blur * 0.7); - col += texture2D(tex, uv + (vec2(0.4, 0.0) * offset) * blur * 0.7); - col += texture2D(tex, uv + (vec2(0.29, -0.29) * offset) * blur * 0.7); - col += texture2D(tex, uv + (vec2(0.0, -0.4) * offset) * blur * 0.7); - col += texture2D(tex, uv + (vec2(-0.29, 0.29) * offset) * blur * 0.7); - col += texture2D(tex, uv + (vec2(-0.4, 0.0) * offset) * blur * 0.7); - col += texture2D(tex, uv + (vec2(-0.29, -0.29) * offset) * blur * 0.7); - col += texture2D(tex, uv + (vec2(0.0, 0.4) * offset) * blur *0.7); + col += texture(tex, uv + (vec2(0.29, 0.29) * offset) * blur * 0.7); + col += texture(tex, uv + (vec2(0.4, 0.0) * offset) * blur * 0.7); + col += texture(tex, uv + (vec2(0.29, -0.29) * offset) * blur * 0.7); + col += texture(tex, uv + (vec2(0.0, -0.4) * offset) * blur * 0.7); + col += texture(tex, uv + (vec2(-0.29, 0.29) * offset) * blur * 0.7); + col += texture(tex, uv + (vec2(-0.4, 0.0) * offset) * blur * 0.7); + col += texture(tex, uv + (vec2(-0.29, -0.29) * offset) * blur * 0.7); + col += texture(tex, uv + (vec2(0.0, 0.4) * offset) * blur *0.7); - col += texture2D(tex, uv + (vec2(0.29, 0.29) * offset) * blur * 0.4); - col += texture2D(tex, uv + (vec2(0.4, 0.0) * offset) * blur * 0.4); - col += texture2D(tex, uv + (vec2(0.29, -0.29) * offset) * blur * 0.4); - col += texture2D(tex, uv + (vec2(0.0, -0.4) * offset) * blur * 0.4); - col += texture2D(tex, uv + (vec2(-0.29, 0.29) * offset) * blur * 0.4); - col += texture2D(tex, uv + (vec2(-0.4, 0.0) * offset) * blur * 0.4); - col += texture2D(tex, uv + (vec2(-0.29, -0.29) * offset) * blur * 0.4); - col += texture2D(tex, uv + (vec2(0.0, 0.4) * offset) * blur * 0.4); + col += texture(tex, uv + (vec2(0.29, 0.29) * offset) * blur * 0.4); + col += texture(tex, uv + (vec2(0.4, 0.0) * offset) * blur * 0.4); + col += texture(tex, uv + (vec2(0.29, -0.29) * offset) * blur * 0.4); + col += texture(tex, uv + (vec2(0.0, -0.4) * offset) * blur * 0.4); + col += texture(tex, uv + (vec2(-0.29, 0.29) * offset) * blur * 0.4); + col += texture(tex, uv + (vec2(-0.4, 0.0) * offset) * blur * 0.4); + col += texture(tex, uv + (vec2(-0.29, -0.29) * offset) * blur * 0.4); + col += texture(tex, uv + (vec2(0.0, 0.4) * offset) * blur * 0.4); col = vec4(col.rgb / 41.0, col.a); depth = clamp((FragPos.z/280), 0., 1.); depth = (1 - depth); vec3 final = colOriginal.rgb * depth + col.rgb * (1 - depth); -/* - FragColor.xyz = vec3(depth); - FragColor.a = 1.0; - */ FragColor = vec4(final, 1.); } diff --git a/data/shaders/linearizedepth.frag b/data/shaders/linearizedepth.frag new file mode 100644 index 000000000..fdb456f48 --- /dev/null +++ b/data/shaders/linearizedepth.frag @@ -0,0 +1,13 @@ +uniform sampler2D tex; +uniform float zn; +uniform float zf; + +in vec2 uv; +out float Depth; + +void main() +{ + float d = texture(tex, uv).x; + float c0 = zn * zf, c1 = zn - zf, c2 = zf; + Depth = c0 / (d * c1 + c2); +} diff --git a/data/shaders/ssao.frag b/data/shaders/ssao.frag index 5c0080ead..95daf0f89 100644 --- a/data/shaders/ssao.frag +++ b/data/shaders/ssao.frag @@ -1,9 +1,7 @@ // From paper http://graphics.cs.williams.edu/papers/AlchemyHPG11/ // and improvements here http://graphics.cs.williams.edu/papers/SAOHPG12/ -uniform sampler2D ntex; uniform sampler2D dtex; -uniform sampler2D noise_texture; uniform vec4 samplePoints[16]; uniform vec2 screen; @@ -28,33 +26,34 @@ out float AO; const float sigma = 1.; const float tau = 7.; -const float beta = 0.0001; +const float beta = 0.001; const float epsilon = .00001; -const float radius = 1.5; -const float k = 1.; +const float radius = 1.; +const float k = 1.5; #define SAMPLES 16 const float invSamples = 1. / SAMPLES; -vec3 DecodeNormal(vec2 n); -vec4 getPosFromUVDepth(vec3 uvDepth, mat4 InverseProjectionMatrix); +vec3 getXcYcZc(int x, int y, float zC) +{ + // We use perspective symetric projection matrix hence P(0,2) = P(1, 2) = 0 + float xC= (1. - 2 * (float(x) + 0.5) / screen.x) * zC / ProjectionMatrix[0][0]; + float yC= (1. + 2 * (float(y) + 0.5) / screen.y) * zC / ProjectionMatrix[1][1]; + return vec3(xC, yC, zC); +} void main(void) { - vec4 cur = texture(ntex, uv); - float curdepth = texture(dtex, uv).x; - vec4 FragPos = getPosFromUVDepth(vec3(uv, curdepth), InverseProjectionMatrix); + float lineardepth = textureLod(dtex, uv, 0.).x; + int x = int(gl_FragCoord.x), y = int(gl_FragCoord.y); + vec3 FragPos = getXcYcZc(x, y, lineardepth); // get the normal of current fragment - vec3 ddx = dFdx(FragPos.xyz); - vec3 ddy = dFdy(FragPos.xyz); - vec3 norm = normalize(cross(ddy, ddx)); - // Workaround for nvidia and skyboxes - float len = dot(vec3(1.0), abs(cur.xyz)); - if (len < 0.2) discard; + vec3 ddx = dFdx(FragPos); + vec3 ddy = dFdy(FragPos); + vec3 norm = -normalize(cross(ddy, ddx)); - int x = int(gl_FragCoord.x), y = int(gl_FragCoord.y); float r = radius / FragPos.z; float phi = 30. * (x ^ y) + 10. * x * y; float bl = 0.0; @@ -63,20 +62,17 @@ void main(void) float alpha = (i + .5) * invSamples; float theta = 2. * 3.14 * tau * alpha + phi; float h = r * alpha; - vec2 occluder_uv = h * vec2(cos(theta), sin(theta)) * screen; - occluder_uv += gl_FragCoord.xy; + vec2 offset = h * vec2(cos(theta), sin(theta)) * screen; - float m = round(log2(h)) + 7; - ivec2 ioccluder_uv = ivec2(occluder_uv); - occluder_uv = (ioccluder_uv >> int(m)) << int(m); - occluder_uv /= screen; + float m = round(log2(h) + 6); + ivec2 ioccluder_uv = ivec2(x, y) + ivec2(offset); - if (occluder_uv.x < 0. || occluder_uv.x > 1. || occluder_uv.y < 0. || occluder_uv.y > 1.) continue; + if (ioccluder_uv.x < 0 || ioccluder_uv.x > screen.x || ioccluder_uv.y < 0 || ioccluder_uv.y > screen.y) continue; - float occluderFragmentDepth = textureLod(dtex, occluder_uv, m).x; - vec4 OccluderPos = getPosFromUVDepth(vec3(occluder_uv, occluderFragmentDepth), InverseProjectionMatrix); + float LinearoccluderFragmentDepth = textureLod(dtex, vec2(ioccluder_uv) / screen, m).x; + vec3 OccluderPos = getXcYcZc(ioccluder_uv.x, ioccluder_uv.y, LinearoccluderFragmentDepth); - vec3 vi = (OccluderPos - FragPos).xyz; + vec3 vi = OccluderPos - FragPos; bl += max(0, dot(vi, norm) - FragPos.z * beta) / (dot(vi, vi) + epsilon); } diff --git a/lib/irrlicht/include/IGUISkin.h b/lib/irrlicht/include/IGUISkin.h index d3bf337df..53664f3da 100644 --- a/lib/irrlicht/include/IGUISkin.h +++ b/lib/irrlicht/include/IGUISkin.h @@ -12,6 +12,7 @@ namespace irr { +namespace video { class ITexture; } namespace gui { class IGUIFont; @@ -564,6 +565,10 @@ namespace gui //! get the type of this skin virtual EGUI_SKIN_TYPE getType() const { return EGST_UNKNOWN; } + + virtual void draw2DImage(const video::ITexture* texture, const core::rect& destRect, + const core::rect& sourceRect, const core::rect* clipRect, + const video::SColor* const colors, bool useAlphaChannelOfTexture) = 0; }; diff --git a/lib/irrlicht/source/Irrlicht/CGUIButton.cpp b/lib/irrlicht/source/Irrlicht/CGUIButton.cpp index 5a451cdbd..21be74646 100644 --- a/lib/irrlicht/source/Irrlicht/CGUIButton.cpp +++ b/lib/irrlicht/source/Irrlicht/CGUIButton.cpp @@ -249,11 +249,16 @@ void CGUIButton::draw() pos.X -= ImageRect.getWidth() / 2; pos.Y -= ImageRect.getHeight() / 2; - driver->draw2DImage(Image, - ScaleImage? AbsoluteRect : - core::recti(pos, ImageRect.getSize()), - ImageRect, &AbsoluteClippingRect, - 0, UseAlphaChannel); + skin->draw2DImage(Image, + ScaleImage ? AbsoluteRect : + core::recti(pos, ImageRect.getSize()), + ImageRect, &AbsoluteClippingRect, + 0, UseAlphaChannel); + //driver->draw2DImage(Image, + // ScaleImage? AbsoluteRect : + // core::recti(pos, ImageRect.getSize()), + // ImageRect, &AbsoluteClippingRect, + // 0, UseAlphaChannel); } } else diff --git a/lib/irrlicht/source/Irrlicht/CGUISkin.cpp b/lib/irrlicht/source/Irrlicht/CGUISkin.cpp index b0b2b39c3..df3238e5c 100644 --- a/lib/irrlicht/source/Irrlicht/CGUISkin.cpp +++ b/lib/irrlicht/source/Irrlicht/CGUISkin.cpp @@ -179,6 +179,13 @@ CGUISkin::~CGUISkin() } +void CGUISkin::draw2DImage(const video::ITexture* texture, const core::rect& destRect, + const core::rect& sourceRect, const core::rect* clipRect, + const video::SColor* const colors, bool useAlphaChannelOfTexture) +{ + Driver->draw2DImage(texture, destRect, sourceRect, clipRect, colors, useAlphaChannelOfTexture); +} + //! returns default color video::SColor CGUISkin::getColor(EGUI_DEFAULT_COLOR color) const { diff --git a/lib/irrlicht/source/Irrlicht/CGUISkin.h b/lib/irrlicht/source/Irrlicht/CGUISkin.h index 903d856d6..ebaab6d2a 100644 --- a/lib/irrlicht/source/Irrlicht/CGUISkin.h +++ b/lib/irrlicht/source/Irrlicht/CGUISkin.h @@ -224,6 +224,10 @@ namespace gui //! scripting languages, editors, debuggers or xml deserialization purposes. virtual void deserializeAttributes(io::IAttributes* in, io::SAttributeReadWriteOptions* options=0); + virtual void draw2DImage(const video::ITexture* texture, const core::rect& destRect, + const core::rect& sourceRect, const core::rect* clipRect, + const video::SColor* const colors, bool useAlphaChannelOfTexture); + private: video::SColor Colors[EGDC_COUNT]; diff --git a/src/graphics/glwrap.cpp b/src/graphics/glwrap.cpp index 4dfd2f2bc..638f3f192 100644 --- a/src/graphics/glwrap.cpp +++ b/src/graphics/glwrap.cpp @@ -490,6 +490,7 @@ ScopedGPUTimer::ScopedGPUTimer(GPUTimer &timer) if (!UserConfigParams::m_profiler_enabled) return; if (profiler.isFrozen()) return; +#ifdef GL_TIME_ELAPSED irr::video::COpenGLDriver *gl_driver = (irr::video::COpenGLDriver *)irr_driver->getDevice()->getVideoDriver(); if (!timer.initialised) { @@ -497,14 +498,17 @@ ScopedGPUTimer::ScopedGPUTimer(GPUTimer &timer) timer.initialised = true; } gl_driver->extGlBeginQuery(GL_TIME_ELAPSED, timer.query); +#endif } ScopedGPUTimer::~ScopedGPUTimer() { if (!UserConfigParams::m_profiler_enabled) return; if (profiler.isFrozen()) return; +#ifdef GL_TIME_ELAPSED irr::video::COpenGLDriver *gl_driver = (irr::video::COpenGLDriver *)irr_driver->getDevice()->getVideoDriver(); gl_driver->extGlEndQuery(GL_TIME_ELAPSED); +#endif } GPUTimer::GPUTimer() : initialised(false) diff --git a/src/graphics/glwrap.hpp b/src/graphics/glwrap.hpp index df3827d0f..56fd99ee4 100644 --- a/src/graphics/glwrap.hpp +++ b/src/graphics/glwrap.hpp @@ -5,6 +5,12 @@ # include # include # define OGL32CTX +# ifdef GL_ARB_instanced_arrays +# define glVertexAttribDivisor glVertexAttribDivisorARB +# endif +# ifndef GL_TEXTURE_SWIZZLE_RGBA +# define GL_TEXTURE_SWIZZLE_RGBA 0x8E46 +# endif #elif defined(ANDROID) # include #elif defined(WIN32) diff --git a/src/graphics/irr_driver.cpp b/src/graphics/irr_driver.cpp index f6efd907b..fb1fcef43 100644 --- a/src/graphics/irr_driver.cpp +++ b/src/graphics/irr_driver.cpp @@ -2313,7 +2313,7 @@ void IrrDriver::applyObjectPassShader() // ---------------------------------------------------------------------------- -scene::ISceneNode *IrrDriver::addLight(const core::vector3df &pos, float energy, +scene::ISceneNode *IrrDriver::addLight(const core::vector3df &pos, float energy, float radius, float r, float g, float b, bool sun, scene::ISceneNode* parent) { if (m_glsl) @@ -2322,7 +2322,7 @@ scene::ISceneNode *IrrDriver::addLight(const core::vector3df &pos, float energy, LightNode *light = NULL; if (!sun) - light = new LightNode(m_scene_manager, parent, energy, r, g, b); + light = new LightNode(m_scene_manager, parent, energy, radius, r, g, b); else light = new SunNode(m_scene_manager, parent, r, g, b); diff --git a/src/graphics/irr_driver.hpp b/src/graphics/irr_driver.hpp index 08cd55b4b..04ebfbf1f 100644 --- a/src/graphics/irr_driver.hpp +++ b/src/graphics/irr_driver.hpp @@ -563,8 +563,8 @@ public: void applyObjectPassShader(); void applyObjectPassShader(scene::ISceneNode * const node, bool rimlit = false); // ------------------------------------------------------------------------ - scene::ISceneNode *addLight(const core::vector3df &pos, float energy = 1., float r = 1.0f, - float g = 1.0f, float b = 1.0f, bool sun = false, scene::ISceneNode* parent = NULL); + scene::ISceneNode *addLight(const core::vector3df &pos, float energy, float radius, float r, + float g, float b, bool sun = false, scene::ISceneNode* parent = NULL); // ------------------------------------------------------------------------ void clearLights(); // ------------------------------------------------------------------------ diff --git a/src/graphics/light.cpp b/src/graphics/light.cpp index d534ad4cb..068809995 100644 --- a/src/graphics/light.cpp +++ b/src/graphics/light.cpp @@ -34,10 +34,11 @@ using namespace core; aabbox3df LightNode::box; -LightNode::LightNode(scene::ISceneManager* mgr, scene::ISceneNode* parent, float e, float r, float g, float b): +LightNode::LightNode(scene::ISceneManager* mgr, scene::ISceneNode* parent, float e, float d, float r, float g, float b): ISceneNode(parent == NULL ? mgr->getRootSceneNode() : parent, mgr, -1) { m_energy = e; + m_radius = d; m_energy_multiplier = 1.0f; m_color[0] = r; m_color[1] = g; diff --git a/src/graphics/light.hpp b/src/graphics/light.hpp index 1f17c5aad..62b3bd44f 100644 --- a/src/graphics/light.hpp +++ b/src/graphics/light.hpp @@ -40,7 +40,7 @@ class LightNode: public scene::ISceneNode #endif public: - LightNode(scene::ISceneManager* mgr, scene::ISceneNode* parent, float energy, float r, float g, float b); + LightNode(scene::ISceneManager* mgr, scene::ISceneNode* parent, float energy, float d, float r, float g, float b); virtual ~LightNode(); virtual void render() OVERRIDE; @@ -55,7 +55,7 @@ public: virtual u32 getMaterialCount() const OVERRIDE { return 1; } virtual bool isPointLight() { return true; } - //float getRadius() const { return m_radius; } + float getRadius() const { return m_radius; } float getEnergy() const { return m_energy; } float getEffectiveEnergy() const { return m_energy_multiplier * m_energy; } core::vector3df getColor() const { return core::vector3df(m_color[0], m_color[1], m_color[2]); } @@ -66,7 +66,7 @@ public: protected: static core::aabbox3df box; - //float m_radius; + float m_radius; float m_color[3]; float m_energy; diff --git a/src/graphics/post_processing.cpp b/src/graphics/post_processing.cpp index 354340e91..54f3b6516 100644 --- a/src/graphics/post_processing.cpp +++ b/src/graphics/post_processing.cpp @@ -451,12 +451,22 @@ void PostProcessing::renderSSAO() glDisable(GL_BLEND); glDisable(GL_ALPHA_TEST); + // Generate linear depth buffer + glBindFramebuffer(GL_FRAMEBUFFER, irr_driver->getFBO(FBO_LINEAR_DEPTH)); + glUseProgram(FullScreenShader::LinearizeDepthShader::Program); + glBindVertexArray(FullScreenShader::LinearizeDepthShader::vao); + setTexture(0, irr_driver->getDepthStencilTexture(), GL_LINEAR, GL_LINEAR); + FullScreenShader::LinearizeDepthShader::setUniforms(irr_driver->getSceneManager()->getActiveCamera()->getNearValue(), irr_driver->getSceneManager()->getActiveCamera()->getFarValue(), 0); + glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); + glBindFramebuffer(GL_FRAMEBUFFER, irr_driver->getFBO(FBO_SSAO)); + if (!noise_tex) noise_tex = irr_driver->getTexture(file_manager->getAsset("textures/noise.png").c_str()); glUseProgram(FullScreenShader::SSAOShader::Program); glBindVertexArray(FullScreenShader::SSAOShader::vao); - setTexture(0, irr_driver->getDepthStencilTexture(), GL_LINEAR, GL_LINEAR_MIPMAP_NEAREST); + + setTexture(0, irr_driver->getRenderTargetTexture(RTT_LINEAR_DEPTH), GL_LINEAR, GL_LINEAR_MIPMAP_LINEAR); glGenerateMipmap(GL_TEXTURE_2D); setTexture(1, getTextureGLuint(noise_tex), GL_LINEAR, GL_LINEAR); diff --git a/src/graphics/render.cpp b/src/graphics/render.cpp index 13e71a5c8..617327452 100644 --- a/src/graphics/render.cpp +++ b/src/graphics/render.cpp @@ -341,6 +341,8 @@ void IrrDriver::renderScene(scene::ICameraSceneNode * const camnode, std::vector renderDisplacement(); PROFILER_POP_CPU_MARKER(); } + // Ensure that no object will be drawn after that by using invalid pass + irr_driver->setPhase(PASS_COUNT); } // -------------------------------------------- @@ -874,7 +876,7 @@ void IrrDriver::renderLights(scene::ICameraSceneNode * const camnode, float dt) PointLightsInfo[lightnum].blue = col.Z; // Light radius - PointLightsInfo[lightnum].radius = 20 * light_node->getEffectiveEnergy(); + PointLightsInfo[lightnum].radius = light_node->getRadius(); } } if (lightnum > MAXLIGHT) diff --git a/src/graphics/rtts.cpp b/src/graphics/rtts.cpp index fd14fb5fe..ae071b595 100644 --- a/src/graphics/rtts.cpp +++ b/src/graphics/rtts.cpp @@ -83,6 +83,7 @@ RTT::RTT() RenderTargetTextures[RTT_TMP2] = generateRTT(res, GL_RGBA16F, GL_BGRA, GL_FLOAT); RenderTargetTextures[RTT_TMP3] = generateRTT(res, GL_RGBA16F, GL_BGRA, GL_FLOAT); RenderTargetTextures[RTT_TMP4] = generateRTT(res, GL_R16F, GL_RED, GL_FLOAT); + RenderTargetTextures[RTT_LINEAR_DEPTH] = generateRTT(res, GL_R32F, GL_RED, GL_FLOAT); RenderTargetTextures[RTT_NORMAL_AND_DEPTH] = generateRTT(res, GL_RGBA16F, GL_RGBA, GL_FLOAT); RenderTargetTextures[RTT_COLOR] = generateRTT(res, GL_RGBA16F, GL_BGRA, GL_FLOAT); RenderTargetTextures[RTT_MLAA_COLORS] = generateRTT(res, GL_SRGB, GL_BGR, GL_UNSIGNED_BYTE); @@ -118,6 +119,7 @@ RTT::RTT() FrameBuffers[FBO_TMP1_WITH_DS] = generateFBO(RenderTargetTextures[RTT_TMP1], DepthStencilTexture); FrameBuffers[FBO_TMP2_WITH_DS] = generateFBO(RenderTargetTextures[RTT_TMP2], DepthStencilTexture); FrameBuffers[FBO_TMP4] = generateFBO(RenderTargetTextures[RTT_TMP4], DepthStencilTexture); + FrameBuffers[FBO_LINEAR_DEPTH] = generateFBO(RenderTargetTextures[RTT_LINEAR_DEPTH]); FrameBuffers[FBO_DISPLACE] = generateFBO(RenderTargetTextures[RTT_DISPLACE], DepthStencilTexture); FrameBuffers[FBO_HALF1] = generateFBO(RenderTargetTextures[RTT_HALF1]); FrameBuffers[FBO_HALF2] = generateFBO(RenderTargetTextures[RTT_HALF2]); diff --git a/src/graphics/rtts.hpp b/src/graphics/rtts.hpp index a8234bb76..6edab8556 100644 --- a/src/graphics/rtts.hpp +++ b/src/graphics/rtts.hpp @@ -31,6 +31,7 @@ enum TypeRTT RTT_TMP2, RTT_TMP3, RTT_TMP4, + RTT_LINEAR_DEPTH, RTT_NORMAL_AND_DEPTH, RTT_COLOR, RTT_LOG_LUMINANCE, @@ -87,6 +88,7 @@ enum TypeFBO FBO_TMP1_WITH_DS, FBO_TMP2_WITH_DS, FBO_TMP4, + FBO_LINEAR_DEPTH, FBO_HALF1, FBO_HALF2, FBO_QUARTER1, diff --git a/src/graphics/shaders.cpp b/src/graphics/shaders.cpp index 51df04a30..883fe75b6 100644 --- a/src/graphics/shaders.cpp +++ b/src/graphics/shaders.cpp @@ -311,6 +311,7 @@ void Shaders::loadShaders() FullScreenShader::PenumbraVShader::init(); FullScreenShader::GlowShader::init(); FullScreenShader::PassThroughShader::init(); + FullScreenShader::LinearizeDepthShader::init(); FullScreenShader::SSAOShader::init(); FullScreenShader::SunLightShader::init(); FullScreenShader::DiffuseEnvMapShader::init(); @@ -2510,6 +2511,29 @@ namespace FullScreenShader vao = createVAO(Program); } + GLuint LinearizeDepthShader::Program; + GLuint LinearizeDepthShader::uniform_zn; + GLuint LinearizeDepthShader::uniform_zf; + GLuint LinearizeDepthShader::uniform_texture; + GLuint LinearizeDepthShader::vao; + void LinearizeDepthShader::init() + { + Program = LoadProgram( + GL_VERTEX_SHADER, file_manager->getAsset("shaders/screenquad.vert").c_str(), + GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/linearizedepth.frag").c_str()); + uniform_texture = glGetUniformLocation(Program, "texture"); + uniform_zf = glGetUniformLocation(Program, "zf"); + uniform_zn = glGetUniformLocation(Program, "zn"); + vao = createVAO(Program); + } + + void LinearizeDepthShader::setUniforms(float zn, float zf, unsigned TU_tex) + { + glUniform1f(uniform_zn, zn); + glUniform1f(uniform_zf, zf); + glUniform1i(uniform_texture, TU_tex); + } + GLuint GlowShader::Program; GLuint GlowShader::uniform_tex; GLuint GlowShader::vao; diff --git a/src/graphics/shaders.hpp b/src/graphics/shaders.hpp index f70fbaf20..3a3ec8e31 100644 --- a/src/graphics/shaders.hpp +++ b/src/graphics/shaders.hpp @@ -713,6 +713,17 @@ public: static void init(); }; +class LinearizeDepthShader +{ +public: + static GLuint Program; + static GLuint uniform_zn, uniform_zf, uniform_texture; + static GLuint vao; + + static void init(); + static void setUniforms(float zn, float zf, unsigned TU_tex); +}; + class GlowShader { public: diff --git a/src/graphics/sun.cpp b/src/graphics/sun.cpp index dd20a74b4..3399cd668 100644 --- a/src/graphics/sun.cpp +++ b/src/graphics/sun.cpp @@ -35,7 +35,7 @@ using namespace scene; using namespace core; SunNode::SunNode(scene::ISceneManager* mgr, scene::ISceneNode* parent, float r, float g, float b): - LightNode(mgr, parent, 0., r, g, b) + LightNode(mgr, parent, 0., 0., r, g, b) { m_color[0] = r; m_color[1] = g; diff --git a/src/guiengine/skin.cpp b/src/guiengine/skin.cpp index e0d015a90..6d2292573 100644 --- a/src/guiengine/skin.cpp +++ b/src/guiengine/skin.cpp @@ -2267,6 +2267,15 @@ void Skin::drawIcon (IGUIElement *element, EGUI_DEFAULT_ICON icon, // ----------------------------------------------------------------------------- +void Skin::draw2DImage(const video::ITexture* texture, const core::rect& destRect, + const core::rect& sourceRect, const core::rect* clipRect, + const video::SColor* const colors, bool useAlphaChannelOfTexture) +{ + ::draw2DImage(texture, destRect, sourceRect, clipRect, colors, useAlphaChannelOfTexture); +} + +// ----------------------------------------------------------------------------- + video::SColor Skin::getColor (EGUI_DEFAULT_COLOR color) const { /* diff --git a/src/guiengine/skin.hpp b/src/guiengine/skin.hpp index 3c8eac393..f13a5066a 100644 --- a/src/guiengine/skin.hpp +++ b/src/guiengine/skin.hpp @@ -381,6 +381,11 @@ namespace GUIEngine const core::rect< s32 > &rect, const core::rect< s32 > *clip, core::rect* checkClientArea=0); + + virtual void draw2DImage(const video::ITexture* texture, const core::rect& destRect, + const core::rect& sourceRect, const core::rect* clipRect, + const video::SColor* const colors, bool useAlphaChannelOfTexture); + virtual void drawIcon (gui::IGUIElement *element, gui::EGUI_DEFAULT_ICON icon, const core::position2di position, diff --git a/src/network/protocols/connect_to_server.cpp b/src/network/protocols/connect_to_server.cpp index 0cc8d314f..bc4dda7fd 100644 --- a/src/network/protocols/connect_to_server.cpp +++ b/src/network/protocols/connect_to_server.cpp @@ -153,7 +153,7 @@ void ConnectToServer::asynchronousUpdate() if (m_server_address.ip == 0 || m_server_address.port == 0) { // server data not correct, hide address and stop m_state = HIDING_ADDRESS; - Log::error("ConnectToServer", "Server address is "ADDRESS_FORMAT, ADDRESS_ARGS(m_server_address.ip, m_server_address.port)); + Log::error("ConnectToServer", "Server address is " ADDRESS_FORMAT, ADDRESS_ARGS(m_server_address.ip, m_server_address.port)); m_current_protocol_id = m_listener->requestStart(new HidePublicAddress()); return; } diff --git a/src/states_screens/feature_unlocked.cpp b/src/states_screens/feature_unlocked.cpp index 07b24c348..d251c56e4 100644 --- a/src/states_screens/feature_unlocked.cpp +++ b/src/states_screens/feature_unlocked.cpp @@ -302,7 +302,7 @@ void FeatureUnlockedCutScene::init() 120, 120)); const core::vector3df &sun_pos = core::vector3df( 0, 200, 100.0f ); - m_light = irr_driver->addLight(sun_pos, 10000.0f, 1, 1, 1); + m_light = irr_driver->addLight(sun_pos, 10000.0f, 1., 1, 1, 1, true); #ifdef DEBUG m_light->setName("light"); #endif diff --git a/src/tracks/track.cpp b/src/tracks/track.cpp index 2010adb30..ae9fe5aab 100644 --- a/src/tracks/track.cpp +++ b/src/tracks/track.cpp @@ -1719,7 +1719,7 @@ void Track::loadTrackModel(bool reverse_track, unsigned int mode_id) } const video::SColorf tmpf(m_sun_diffuse_color); - m_sun = irr_driver->addLight(m_sun_position, 0., tmpf.r, tmpf.g, tmpf.b, true); + m_sun = irr_driver->addLight(m_sun_position, 0., 0., tmpf.r, tmpf.g, tmpf.b, true); if (!irr_driver->isGLSL()) { diff --git a/src/tracks/track_object_presentation.cpp b/src/tracks/track_object_presentation.cpp index 02345c57f..c6d9f95e4 100644 --- a/src/tracks/track_object_presentation.cpp +++ b/src/tracks/track_object_presentation.cpp @@ -675,15 +675,15 @@ TrackObjectPresentationLight::TrackObjectPresentationLight(const XMLNode& xml_no xml_node.get("color", &m_color); const video::SColorf colorf(m_color); - //m_distance = 25.0f; - //xml_node.get("distance", &m_distance); - m_energy = 1.0f; xml_node.get("energy", &m_energy); + m_distance = 20. * m_energy; + xml_node.get("distance", &m_distance); + if (irr_driver->isGLSL()) { - m_node = irr_driver->addLight(m_init_xyz, m_energy, colorf.r, colorf.g, colorf.b, false, parent); + m_node = irr_driver->addLight(m_init_xyz, m_energy, m_distance, colorf.r, colorf.g, colorf.b, false, parent); } else { diff --git a/src/tracks/track_object_presentation.hpp b/src/tracks/track_object_presentation.hpp index 561df9ff5..ba7bb95a5 100644 --- a/src/tracks/track_object_presentation.hpp +++ b/src/tracks/track_object_presentation.hpp @@ -307,7 +307,7 @@ class TrackObjectPresentationLight : public TrackObjectPresentationSceneNode { private: video::SColor m_color; - //float m_distance; + float m_distance; float m_energy; public: