mirror of
https://github.com/lubosz/overte.git
synced 2025-04-26 22:35:27 +02:00
Fewer texture lookups when diffusing.
This commit is contained in:
parent
49da612a4e
commit
590672d035
3 changed files with 16 additions and 10 deletions
interface
|
@ -14,15 +14,14 @@ uniform sampler2D originalTexture;
|
|||
// the texture containing the diffused color
|
||||
uniform sampler2D diffusedTexture;
|
||||
|
||||
// the scale of diffusion
|
||||
uniform vec2 diffusionScale;
|
||||
|
||||
void main(void) {
|
||||
float ds = dFdx(gl_TexCoord[0].s);
|
||||
float dt = dFdy(gl_TexCoord[0].t);
|
||||
gl_FragColor = (texture2D(diffusedTexture, gl_TexCoord[0].st + vec2(-ds, -dt)) +
|
||||
texture2D(diffusedTexture, gl_TexCoord[0].st + vec2(0.0, -dt)) +
|
||||
texture2D(diffusedTexture, gl_TexCoord[0].st + vec2(ds, -dt)) +
|
||||
texture2D(diffusedTexture, gl_TexCoord[0].st + vec2(ds, 0.0)) +
|
||||
texture2D(diffusedTexture, gl_TexCoord[0].st + vec2(ds, dt)) +
|
||||
texture2D(diffusedTexture, gl_TexCoord[0].st + vec2(0.0, dt)) +
|
||||
texture2D(diffusedTexture, gl_TexCoord[0].st + vec2(-ds, dt)) +
|
||||
texture2D(diffusedTexture, gl_TexCoord[0].st + vec2(-ds, 0.0))) / 8.5 + texture2D(originalTexture, gl_TexCoord[0].st) * 0.1;
|
||||
vec2 minExtents = gl_TexCoord[0].st + diffusionScale * vec2(-1.5, -1.5);
|
||||
vec2 maxExtents = gl_TexCoord[0].st + diffusionScale * vec2(1.5, 1.5);
|
||||
gl_FragColor = (texture2D(diffusedTexture, minExtents) +
|
||||
texture2D(diffusedTexture, vec2(maxExtents.s, minExtents.t)) +
|
||||
texture2D(diffusedTexture, vec2(minExtents.s, maxExtents.t)) +
|
||||
texture2D(diffusedTexture, maxExtents)) / 4.25 + texture2D(originalTexture, gl_TexCoord[0].st) * 0.1;
|
||||
}
|
||||
|
|
|
@ -57,6 +57,8 @@ void GlowEffect::init() {
|
|||
_diffuseProgram->bind();
|
||||
_diffuseProgram->setUniformValue("diffusedTexture", 1);
|
||||
_diffuseProgram->release();
|
||||
|
||||
_diffusionScaleLocation = _diffuseProgram->uniformLocation("diffusionScale");
|
||||
}
|
||||
|
||||
void GlowEffect::prepare() {
|
||||
|
@ -125,7 +127,11 @@ void GlowEffect::render() {
|
|||
glBindTexture(GL_TEXTURE_2D, oldDiffusedFBO->texture());
|
||||
|
||||
_diffuseProgram->bind();
|
||||
QSize size = Application::getInstance()->getGLWidget()->size();
|
||||
_diffuseProgram->setUniformValue(_diffusionScaleLocation, 1.0f / size.width(), 1.0f / size.height());
|
||||
|
||||
renderFullscreenQuad();
|
||||
|
||||
_diffuseProgram->release();
|
||||
|
||||
newDiffusedFBO->release();
|
||||
|
|
|
@ -57,6 +57,7 @@ private:
|
|||
ProgramObject* _verticalBlurProgram;
|
||||
ProgramObject* _addSeparateProgram;
|
||||
ProgramObject* _diffuseProgram;
|
||||
int _diffusionScaleLocation;
|
||||
|
||||
bool _isEmpty; ///< set when nothing in the scene is currently glowing
|
||||
bool _isOddFrame; ///< controls the alternation between texture targets in diffuse add mode
|
||||
|
|
Loading…
Reference in a new issue