namespace HDK_Sample {
const char *copy_frag =
"#version 150\n"
"uniform sampler2D beauty;\n"
"in vec2 texcoord0; \n"
"out vec4 color; \n"
"void main()\n"
"{ color = texture(beauty, texcoord0); }\n";
const char *bloom_vert =
"#version 150\n"
"in vec3 P;\n"
"in vec2 uv;\n"
"out vec2 texcoord0;\n"
"void main()\n"
"{\n"
" texcoord0 = uv;\n"
" gl_Position = vec4(P, 1.0);\n"
"}\n";
const char *bloom_frag =
"#version 150\n"
"uniform sampler2D beauty;\n"
"uniform sampler2D bloom;\n"
"uniform vec2 off;\n"
"in vec2 texcoord0; \n"
"out vec4 color; \n"
"void main()\n"
"{\n"
" float scale = 2.5 - texture(beauty, texcoord0).a * 2.0;\n"
" color = scale * (texture( bloom, texcoord0) * 0.24 +"
" (texture2D(bloom, texcoord0 + vec2(off.x, 0.0)) + \n"
" texture2D(bloom, texcoord0 + vec2(-off.x, 0.0)) + \n"
" texture2D(bloom, texcoord0 + vec2(0.0, -off.y)) + \n"
" texture2D(bloom, texcoord0 + vec2(0.0, off.y))) * 0.12 +\n"
" (texture2D(bloom, texcoord0 + off) + \n"
" texture2D(bloom, texcoord0 - off) + \n"
" texture2D(bloom, texcoord0 + vec2(off.x,-off.y)) + \n"
" texture2D(bloom, texcoord0 - vec2(off.x,-off.y)))*0.07);\n"
"}\n";
{
public:
myBloomBuffer(NULL),
myBloomTexture(NULL)
{}
~DM_LightBloomRenderHook() override
{
delete myBloomTexture;
delete myBloomBuffer;
}
{ return true; }
void viewportClosed() override;
{
delete myBloomTexture;
delete myBloomBuffer;
myBloomTexture = NULL;
myBloomBuffer = NULL;
}
private:
};
{
public:
~DM_LightBloomHook() override {}
{ return new DM_LightBloomRenderHook(vport); }
{ delete hook; }
};
}
using namespace HDK_Sample;
RE_Shader *DM_LightBloomRenderHook::theCopyShader = NULL;
RE_Shader *DM_LightBloomRenderHook::theBloomShader = NULL;
bool
{
return false;
RE_Texture *beauty = viewport().getBeautyPassTexture(r);
if(!beauty)
return false;
if(!theCopyShader)
{
if(!theCopyShader->linkShaders(r))
{
return false;
}
}
if(!theBloomShader)
{
if(!theBloomShader->linkShaders(r))
{
return false;
}
theBloomShader->bindInt(r, RE_UniformNames::beauty, 0);
theBloomShader->bindInt(r, RE_UniformNames::bloom, 1);
}
if(myBloomBuffer &&
(myBloomBuffer->getWidth() != bw || myBloomBuffer->getHeight() != bh))
{
}
if(!myBloomBuffer)
{
myBloomBuffer->setResolution(bw, bh);
if(!myBloomTexture || !myBloomBuffer->isValid(r))
{
return false;
}
}
fpreal32 view[12] = { -1.f, -1.f, -0.1f, -1.f, 1.f, -0.1f, 1.f, -1.f, -0.1f, 1.f, 1.f, -1.f };
fpreal32 texc[8] = { 0, 0, 0, 1, 1, 0, 1, 1 };
geo.draw(r, 0);
offset[0] = 2.0 / bw;
offset[1] = 2.0 / bh;
theBloomShader->bindVariable2(r, RE_UniformNames::off, offset);
theBloomShader->getUniformTextureUnit("beauty"));
theBloomShader->getUniformTextureUnit("bloom"));
geo.draw(r, 0);
return false;
}
void
DM_LightBloomRenderHook::viewportClosed()
{
}
void
{
}