Implement lightning effect using shaders
This commit is contained in:
parent
66909086fd
commit
8a288f05ff
7
data/shaders/lightning.frag
Normal file
7
data/shaders/lightning.frag
Normal file
@ -0,0 +1,7 @@
|
||||
uniform vec3 intensity;
|
||||
out vec4 FragColor;
|
||||
|
||||
void main()
|
||||
{
|
||||
FragColor = vec4(intensity, 1.0f);
|
||||
}
|
@ -818,6 +818,24 @@ public:
|
||||
} // render
|
||||
}; // SunLightShader
|
||||
|
||||
// ============================================================================
|
||||
class LightningShader : public TextureShader<LightningShader, 1,
|
||||
core::vector3df>
|
||||
{
|
||||
public:
|
||||
LightningShader()
|
||||
{
|
||||
loadProgram(OBJECT, GL_VERTEX_SHADER, "screenquad.vert",
|
||||
GL_FRAGMENT_SHADER, "lightning.frag");
|
||||
assignUniforms("intensity");
|
||||
} // LightningShader
|
||||
// ------------------------------------------------------------------------
|
||||
void render(core::vector3df intensity)
|
||||
{
|
||||
drawFullScreenEffect(intensity);
|
||||
} // render
|
||||
}; // LightningShader
|
||||
|
||||
// ============================================================================
|
||||
|
||||
PostProcessing::PostProcessing(IVideoDriver* video_driver)
|
||||
@ -1408,6 +1426,18 @@ void PostProcessing::applyMLAA()
|
||||
glDisable(GL_STENCIL_TEST);
|
||||
} // applyMLAA
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
void PostProcessing::renderLightning(core::vector3df intensity)
|
||||
{
|
||||
glEnable(GL_BLEND);
|
||||
glBlendFunc(GL_ONE, GL_ONE);
|
||||
glBlendEquation(GL_FUNC_ADD);
|
||||
|
||||
LightningShader::getInstance()->render(intensity);
|
||||
|
||||
glDisable(GL_BLEND);
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
/** Render the post-processed scene */
|
||||
FrameBuffer *PostProcessing::render(scene::ICameraSceneNode * const camnode,
|
||||
|
@ -105,6 +105,7 @@ public:
|
||||
void renderMotionBlur(unsigned cam, const FrameBuffer &in_fbo,
|
||||
FrameBuffer &out_fbo);
|
||||
void renderGlow(unsigned tex);
|
||||
void renderLightning(core::vector3df intensity);
|
||||
|
||||
/** Render the post-processed scene */
|
||||
FrameBuffer *render(scene::ICameraSceneNode * const camnode, bool isRace);
|
||||
|
@ -22,11 +22,13 @@
|
||||
|
||||
#include "audio/music_manager.hpp"
|
||||
#include "config/user_config.hpp"
|
||||
#include "graphics/camera.hpp"
|
||||
#include "graphics/2dutils.hpp"
|
||||
#include "graphics/camera.hpp"
|
||||
#include "graphics/central_settings.hpp"
|
||||
#include "graphics/irr_driver.hpp"
|
||||
#include "graphics/material.hpp"
|
||||
#include "graphics/material_manager.hpp"
|
||||
#include "graphics/post_processing.hpp"
|
||||
#include "graphics/referee.hpp"
|
||||
#include "guiengine/scalable_font.hpp"
|
||||
#include "io/file_manager.hpp"
|
||||
@ -410,6 +412,17 @@ void RaceGUIBase::preRenderCallback(const Camera *camera)
|
||||
// ----------------------------------------------------------------------------
|
||||
void RaceGUIBase::renderPlayerView(const Camera *camera, float dt)
|
||||
{
|
||||
if (CVS->isGLSL())
|
||||
{
|
||||
if (m_lightning > 0.0f)
|
||||
{
|
||||
core::vector3df intensity = {0.7f * m_lightning,
|
||||
0.7f * m_lightning,
|
||||
0.7f * std::min(1.0f, m_lightning * 1.5f)};
|
||||
irr_driver->getPostProcessing()->renderLightning(intensity);
|
||||
}
|
||||
}
|
||||
|
||||
#if 0
|
||||
const core::recti &viewport = camera->getViewport();
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user