if (!isSupported() || !useCurrentScene && _spatials.size() == 0) {
return;
}
final BlendState blend = (BlendState) fullScreenQuad.getWorldRenderState(RenderState.StateType.Blend);
if (sinceLast > throttle) {
sinceLast = 0;
tRenderer.getCamera().setLocation(cam.getLocation());
tRenderer.getCamera().setDirection(cam.getDirection());
tRenderer.getCamera().setUp(cam.getUp());
tRenderer.getCamera().setLeft(cam.getLeft());
blend.setEnabled(false);
final TextureState ts = (TextureState) fullScreenQuad.getWorldRenderState(RenderState.StateType.Texture);
// see if we should use the current scene to bloom, or only things added to the pass.
if (useCurrentScene) {
// grab backbuffer to texture
if (screenTexture == null) {
final DisplaySettings settings = new DisplaySettings(cam.getWidth(), cam.getHeight(), 24, 0, 0, 8,
0, 0, false, false);
fullTRenderer = TextureRendererFactory.INSTANCE.createTextureRenderer(settings, false, r,
ContextManager.getCurrentContext().getCapabilities());
screenTexture = new Texture2D();
screenTexture.setWrap(Texture.WrapMode.Clamp);
screenTexture.setMagnificationFilter(Texture.MagnificationFilter.Bilinear);
fullTRenderer.setupTexture(screenTexture);
}
fullTRenderer.copyToTexture(screenTexture, 0, 0, cam.getWidth(), cam.getHeight(), 0, 0);
ts.setTexture(screenTexture, 0);
} else {
// Render scene to texture
tRenderer.render(_spatials, mainTexture, Renderer.BUFFER_COLOR_AND_DEPTH);
ts.setTexture(mainTexture, 0);
}
// Extract intensity
extractionShader.setUniform("exposurePow", getExposurePow());
extractionShader.setUniform("exposureCutoff", getExposureCutoff());
fullScreenQuad.setRenderState(extractionShader);
fullScreenQuad.updateWorldRenderStates(false);
// fullScreenQuad.states[RenderState.StateType.GLSLShaderObjects.ordinal()] = extractionShader;
tRenderer.render(fullScreenQuad, secondTexture, Renderer.BUFFER_NONE);
if (!useSeparateConvolution) {
blurShader.setUniform("sampleDist", getBlurSize());
blurShader.setUniform("blurIntensityMultiplier", getBlurIntensityMultiplier());
ts.setTexture(secondTexture, 0);
fullScreenQuad.setRenderState(blurShader);
fullScreenQuad.updateWorldRenderStates(false);
// fullScreenQuad.states[RenderState.StateType.GLSLShaderObjects.ordinal()] = blurShader;
tRenderer.render(fullScreenQuad, mainTexture, Renderer.BUFFER_NONE);
// Extra blur passes
for (int i = 1; i < getNrBlurPasses(); i++) {
blurShader.setUniform("sampleDist", getBlurSize() - i * getBlurSize() / getNrBlurPasses());
if (i % 2 == 1) {
ts.setTexture(mainTexture, 0);
tRenderer.render(fullScreenQuad, secondTexture, Renderer.BUFFER_NONE);
} else {
ts.setTexture(secondTexture, 0);
tRenderer.render(fullScreenQuad, mainTexture, Renderer.BUFFER_NONE);
}
}
if (getNrBlurPasses() % 2 == 1) {
ts.setTexture(mainTexture, 0);
} else {
ts.setTexture(secondTexture, 0);
tRenderer.render(fullScreenQuad, mainTexture, Renderer.BUFFER_NONE);
ts.setTexture(mainTexture, 0);
}
} else {
blurShaderVertical.setUniform("blurIntensityMultiplier", getBlurIntensityMultiplier());
for (int i = 0; i < getNrBlurPasses(); i++) {
blurShaderHorizontal
.setUniform("sampleDist", getBlurSize() - i * getBlurSize() / getNrBlurPasses());
blurShaderVertical.setUniform("sampleDist", getBlurSize() - i * getBlurSize() / getNrBlurPasses());
ts.setTexture(secondTexture, 0);
fullScreenQuad.setRenderState(blurShaderHorizontal);
fullScreenQuad.updateWorldRenderStates(false);
// fullScreenQuad.states[RenderState.StateType.GLSLShaderObjects.ordinal()] = blurShaderHorizontal;
tRenderer.render(fullScreenQuad, mainTexture, Renderer.BUFFER_NONE);
ts.setTexture(mainTexture, 0);
fullScreenQuad.setRenderState(blurShaderVertical);
fullScreenQuad.updateWorldRenderStates(false);
// fullScreenQuad.states[RenderState.StateType.GLSLShaderObjects.ordinal()] = blurShaderVertical;
tRenderer.render(fullScreenQuad, secondTexture, Renderer.BUFFER_NONE);
}
ts.setTexture(secondTexture, 0);
}
}
// Final blend
blend.setEnabled(true);
fullScreenQuad.setRenderState(finalShader);
fullScreenQuad.updateWorldRenderStates(false);
// fullScreenQuad.states[RenderState.StateType.GLSLShaderObjects.ordinal()] = finalShader;
r.draw((Renderable) fullScreenQuad);