Game Development Community

Bloom post-processor effect - help?

by RollerJesus · in Torque X 2D · 06/27/2010 (10:35 am) · 9 replies

So I'm trying to get my feet wet in some post processing. My ultimate goal is to implement motion blur but I wanted to start off with the built in bloom effect to get things moving. I'm having some problems though.
BloomPostProcessor bloom = new BloomPostProcessor();
ITextureMaterial mat = (ITextureMaterial)playerFollower.Material;

Resource<Texture> res = mat.Texture;
Texture2D bloomTex = (Texture2D)res.Instance;

bloom.BlurMaterial.Size = new Vector2(100.0f, 100.0f);
bloom.BlurMaterial.BlurAmount = 150.0f;
bloom.CombineMaterial.BaseIntensity = 100.0f;
bloom.CombineMaterial.BloomIntensity = 100.0f;
bloom.BlurMaterial.IsTranslucent = true;

bloom.Cleanup();
bloom.Setup(10, 10);
bloom.Run(bloomTex, playerFollower.Position, new Vector2(100.0f, 100.0f));
The code executes but I don't see any effect. So I was stepping through the code and I noticed that the bloom.Material.Texture was null and thought that was a likely culprit but I can't seem to get a cast working to assign anything to it. Adding in the following throws a nullReferenceException.
bloom.Material.Texture = bloomTex;
Any direction here would be greatly appreciated.

`Patrick

#1
06/27/2010 (10:51 am)
You need to tell your sceneview to use the postprocessor

www.torquepowered.com/community/forums/viewthread/116867
#2
06/27/2010 (3:30 pm)
Thanks Duncan! I read that thread several times and never absorbed the sceneview part.

For posterity's sake:
BloomPostProcessor bloom = new BloomPostProcessor();
                        
      GUISceneview bloomSV = new GUISceneview();
      bloomSV = TorqueObjectDatabase.Instance.FindObject<GUISceneview>("DefaultSceneView");
      bloomSV.PostProcessor = bloom;

      ITextureMaterial mat = (ITextureMaterial)playerFollower.Material;

     Resource<Texture> res = mat.Texture;
     Texture2D bloomTex = (Texture2D)res.Instance;
     bloom.BlurMaterial.Size = new Vector2(1.0f, 1.0f);
     bloom.BlurMaterial.BlurAmount = 1.0f;
     bloom.CombineMaterial.BaseIntensity = 1.0f;
     bloom.CombineMaterial.BloomIntensity = 1.0f;
     bloom.BlurMaterial.IsTranslucent = true;

     bloom.Cleanup();
     bloom.Setup(10, 10);
     bloom.Run(bloomTex, playerFollower.Position, new Vector2(100.0f, 100.0f));

`Patrick
#3
08/04/2010 (6:21 am)
I'm trying to add this bloom effect to my 2d Torque X Platformer based on the platformer kit and I'm running into trouble.

I've got the bloom effect working, but it's causing some pixelization issues. I've tried editing the settings but haven't been able to fix it. Here is the code:

// set the parallax manager's target object
T2DSceneCamera camera = TorqueObjectDatabase.Instance.FindObject<T2DSceneCamera>("Camera");

ParallaxManager.Instance.ParallaxTarget = camera;
_sceneGraph = camera.SceneGraph as T2DSceneGraph;

// create game gui
GUIStyle playStyle = new GUIStyle();
GUISceneview play = new GUISceneview();
play.Name = "PlayScreen";
play.Style = playStyle;
play.Camera = camera;

BloomPostProcessor bloom = new BloomPostProcessor();

play.PostProcessor = bloom;

bloom.Setup(20, 20);
bloom.ExtractMaterial.BloomThreshold = 0.5f;
bloom.BlurMaterial.IsTranslucent = true;
bloom.BlurMaterial.Size = new Vector2(1.0f, 1.0f);
bloom.BlurMaterial.BlurAmount = 5.0f;
bloom.CombineMaterial.BaseIntensity = .9f;
bloom.CombineMaterial.BloomIntensity = 1.5f;
bloom.CombineMaterial.BaseSaturation = .9f;
bloom.CombineMaterial.BloomSaturation = 1.0f;


bloom.Cleanup();

GUICanvas.Instance.SetContentControl(play);
PlatformerDemoGUI.Instance.GUI.Folder = GUICanvas.Instance;

Any help would be appreciated. Thanks
#4
08/04/2010 (6:51 am)
p.s. here are some images to illustrate what I'm talking about

without bloom:

http://s989.photobucket.com/albums/af17/grantham_a/?action=view&current=WithoutBloom.jpg


with bloom:

http://s989.photobucket.com/albums/af17/grantham_a/?action=view&current=WithBloom.jpg
#5
08/04/2010 (7:30 am)
BlurMaterial.Size doesn't need to be set, it is set by the post effect automatically, also the shaders don't offset the texture coordinates by a half pixel as the should.

Quick fix would be
// In GaussianBlur.fx, BloomExtract.fx, and BloomCombine.fx change
output.texCoord = input.texCoord;
// to this where width is the and height of the renderTarget
// by default it is 1/2 whatever your games' screen resolution is
// so for 1280 x 720, it width would be 640 and height 360
output.texCoord = input.texCoord + float2(0.5 / width, 0.5 / height);
#6
08/04/2010 (8:23 am)
How do I access the GaussianBlur.fx, BloomExtract.fx, and BloomCombine.fx? I cannot find them anywhere
#7
08/04/2010 (8:59 am)
You need the source code, if you have it they are in TorqueCore Project
TorqueCore\EngineData\effects
#8
08/05/2010 (6:25 am)
awesome, it works. thanks
#9
12/03/2010 (5:53 am)
Nice work Alex, I used this today to get some really accurate blooms in my game =) Generally speaking, it can look way nicer with your change in place, and get very accurate effects.