Subversion Repository Public Repository

Divide-Framework

This repository has no backups
This repository's network speed is throttled to 100KB/sec

Diff Revisions 167 vs 168 for /trunk/Source Code/Rendering/PostFX/PostFX.cpp

Diff revisions: vs.
  @@ -26,25 +26,27 @@
26 26 _currentCamera(NULL),
27 27 _underwater(false),
28 28 _FXAAinit(false),
29 - _gfx(GFX_DEVICE){
30 - _anaglyphFBO[0] = NULL;
31 - _anaglyphFBO[1] = NULL;
29 + _gfx(GFX_DEVICE)
30 + {
31 + PreRenderStageBuilder::createInstance();
32 + _anaglyphFBO[0] = _anaglyphFBO[1] = NULL;
32 33 }
33 34
34 - PostFX::~PostFX(){
35 - if(_renderQuad){
35 + PostFX::~PostFX()
36 + {
37 + if(_renderQuad)
36 38 RemoveResource(_renderQuad);
37 - }
38 -
39 +
39 40 if(_enablePostProcessing){
40 - if(_underwaterTexture){
41 +
42 + if(_underwaterTexture)
41 43 RemoveResource(_underwaterTexture);
42 - }
43 44
44 45 SAFE_DELETE(_screenFBO);
45 46 SAFE_DELETE(_depthFBO);
46 47
47 48 RemoveResource(_postProcessingShader);
49 +
48 50 if(_enableAnaglyph){
49 51 RemoveResource(_anaglyphShader);
50 52 SAFE_DELETE(_anaglyphFBO[0]);
  @@ -52,20 +54,19 @@
52 54 }
53 55
54 56 if(_enableDOF || _enableBloom){
55 - if(_enableBloom){
57 + if(_enableBloom)
56 58 SAFE_DELETE(_bloomFBO);
57 - }
58 - if(_enableDOF){
59 + if(_enableDOF)
59 60 SAFE_DELETE(_depthOfFieldFBO);
60 - }
61 61 }
62 +
62 63 if(_enableNoise){
63 64 RemoveResource(_noise);
64 65 RemoveResource(_screenBorder);
65 66 }
66 - if(_enableSSAO){
67 +
68 + if(_enableSSAO)
67 69 SAFE_DELETE(_SSAO_FBO);
68 - }
69 70 }
70 71 PreRenderStageBuilder::getInstance().DestroyInstance();
71 72 }
  @@ -84,17 +85,19 @@
84 85 _enableHDR = par.getParam<bool>("rendering.enableHDR");
85 86
86 87 if(_enablePostProcessing){
87 - ///Screen FBO should use MSAA if available, else fallback to normal color FBO (no AA or FXAA)
88 + //Screen FBO should use MSAA if available, else fallback to normal color FBO (no AA or FXAA)
88 89 _screenFBO = _gfx.newFBO(FBO_2D_COLOR_MS);
89 90 _depthFBO = _gfx.newFBO(FBO_2D_DEPTH);
90 91
92 + SamplerDescriptor screenSampler;
91 93 TextureDescriptor screenDescriptor(TEXTURE_2D,
92 94 RGBA,
93 95 RGBA8,
94 - UNSIGNED_BYTE); ///Default filters, LINEAR is OK for this
96 + UNSIGNED_BYTE); //Default filters, LINEAR is OK for this
95 97
96 - screenDescriptor.setWrapMode(TEXTURE_CLAMP_TO_EDGE,TEXTURE_CLAMP_TO_EDGE);
97 - screenDescriptor._generateMipMaps = false; //it's a flat texture on a full screen quad. really?
98 + screenSampler.setWrapMode(TEXTURE_CLAMP_TO_EDGE);
99 + screenSampler.toggleMipMaps(false); //it's a flat texture on a full screen quad. really?
100 + screenDescriptor.setSampler(screenSampler);
98 101
99 102 _screenFBO->AddAttachment(screenDescriptor,TextureDescriptor::Color0);
100 103 _screenFBO->toggleDepthBuffer(true);//Do we need a depth buffer?
  @@ -103,9 +106,10 @@
103 106 DEPTH_COMPONENT,
104 107 DEPTH_COMPONENT,
105 108 UNSIGNED_BYTE); ///Default filters, LINEAR is OK for this
106 - depthDescriptor._useRefCompare = true; //< Use compare function
107 - depthDescriptor._cmpFunc = CMP_FUNC_LEQUAL; //< Use less or equal
108 - depthDescriptor._depthCompareMode = LUMINANCE;
109 + screenSampler._useRefCompare = true; //< Use compare function
110 + screenSampler._cmpFunc = CMP_FUNC_LEQUAL; //< Use less or equal
111 + screenSampler._depthCompareMode = LUMINANCE;
112 + depthDescriptor.setSampler(screenSampler);
109 113
110 114 _depthFBO->AddAttachment(depthDescriptor, TextureDescriptor::Depth);
111 115 _depthFBO->toggleColorWrites(false);
  @@ -133,8 +137,8 @@
133 137
134 138 createOperators();
135 139
136 - _postProcessingShader->Uniform("noise_tile", 0.05f);
137 - _postProcessingShader->Uniform("noise_factor", 0.02f);
140 + _postProcessingShader->Uniform("_noiseTile", 0.05f);
141 + _postProcessingShader->Uniform("_noiseFactor", 0.02f);
138 142 }
139 143
140 144 _timer = 0;
  @@ -151,19 +155,22 @@
151 155 ParamHandler& par = ParamHandler::getInstance();
152 156
153 157 if(_enableAnaglyph && !_anaglyphFBO[0]){
154 - TextureDescriptor screenDescriptor(TEXTURE_2D,
158 + SamplerDescriptor screenSampler;
159 + TextureDescriptor screenDescriptor(TEXTURE_2D,
155 160 RGBA,
156 161 RGBA8,
157 162 FLOAT_32); ///Default filters, LINEAR is OK for this
158 163
159 - screenDescriptor.setWrapMode(TEXTURE_CLAMP_TO_EDGE,TEXTURE_CLAMP_TO_EDGE);
160 - screenDescriptor._generateMipMaps = false; //it's a flat texture on a full screen quad. really?
164 + screenSampler.setWrapMode(TEXTURE_CLAMP_TO_EDGE);
165 + screenSampler.toggleMipMaps(false); //it's a flat texture on a full screen quad. really?
166 + screenDescriptor.setSampler(screenSampler);
161 167
162 168 _anaglyphFBO[0] = _gfx.newFBO(FBO_2D_COLOR_MS);
163 169 _anaglyphFBO[1] = _gfx.newFBO(FBO_2D_COLOR_MS);
164 170 _anaglyphFBO[0]->AddAttachment(screenDescriptor,TextureDescriptor::Color0);
165 171 _anaglyphFBO[1]->AddAttachment(screenDescriptor,TextureDescriptor::Color0);
166 -
172 + _anaglyphFBO[0]->toggleDepthBuffer(true);//Do we need a depth buffer?
173 + _anaglyphFBO[1]->toggleDepthBuffer(true);//Do we need a depth buffer?
167 174 _anaglyphShader = CreateResource<ShaderProgram>(ResourceDescriptor("anaglyph"));
168 175 _eyeOffset = par.getParam<F32>("postProcessing.anaglyphOffset");
169 176 }
  @@ -214,12 +221,13 @@
214 221 }
215 222
216 223 void PostFX::displaySceneWithAnaglyph(bool deferred){
217 - _currentCamera->SaveCamera();
218 - F32 _eyePos[2] = {_eyeOffset/2, -_eyeOffset};
224 + _currentCamera->saveCamera();
225 +
226 + _currentCamera->setIOD(_eyeOffset);
219 227
220 228 for(I32 i=0; i<2; i++){
221 - _currentCamera->MoveAnaglyph(_eyePos[i]);
222 - _currentCamera->RenderLookAt();
229 +
230 + _currentCamera->renderAnaglyph(i == 0 ? true : false);
223 231
224 232 _anaglyphFBO[i]->Begin();
225 233
  @@ -228,7 +236,7 @@
228 236 _anaglyphFBO[i]->End();
229 237 }
230 238
231 - _currentCamera->RestoreCamera();
239 + _currentCamera->restoreCamera();
232 240
233 241 _anaglyphShader->bind();
234 242 {
  @@ -244,11 +252,10 @@
244 252 _anaglyphFBO[1]->Unbind(1);
245 253 _anaglyphFBO[0]->Unbind(0);
246 254 }
247 - //_anaglyphShader->unbind();
248 255 }
249 256
250 257 void PostFX::displaySceneWithoutAnaglyph(bool deferred){
251 - _currentCamera->RenderLookAt();
258 + _currentCamera->renderLookAt();
252 259
253 260 if(_enableDOF){
254 261 _depthFBO->Begin();
  @@ -329,13 +336,14 @@
329 336 }
330 337
331 338 ///Post-Processing in deferred renderer is disabled for now (needs a lot of work)
332 - void PostFX::render(Camera* const camera){
333 - _currentCamera = camera;
334 - bool deferred = GFX_DEVICE.getDeferredRendering();
339 + void PostFX::render(){
340 + _currentCamera = &(GET_ACTIVE_SCENE()->renderState().getCamera());
341 +
342 + bool deferred = GFX_DEVICE.getRenderer()->getType() != RENDERER_FORWARD;
335 343 if(_enablePostProcessing && !deferred){ /*deferred check here is temporary until PostFx are compatible with deferred rendering -Ionut*/
336 344 _enableAnaglyph ? displaySceneWithAnaglyph(deferred) : displaySceneWithoutAnaglyph(deferred);
337 345 }else{
338 - _currentCamera->RenderLookAt();
346 + _currentCamera->renderLookAt();
339 347 SceneManager::getInstance().render(deferred ? DEFERRED_STAGE : FINAL_STAGE);
340 348 }
341 349 }