[2952] | 1 | #ifndef _DEFERREDRENDERER_H__
|
---|
| 2 | #define _DEFERREDRENDERER_H__
|
---|
[2858] | 3 |
|
---|
| 4 | #include "common.h"
|
---|
[3085] | 5 | #include "Matrix4x4.h"
|
---|
| 6 | #include "Vector3.h"
|
---|
[2896] | 7 |
|
---|
[2858] | 8 | namespace CHCDemoEngine
|
---|
| 9 | {
|
---|
| 10 |
|
---|
| 11 | class FrameBufferObject;
|
---|
[2860] | 12 | class Vector3;
|
---|
[3062] | 13 | class PerspectiveCamera;
|
---|
[2861] | 14 | class Matrix4x4;
|
---|
[2896] | 15 | class ShadowMap;
|
---|
[2952] | 16 | class DirectionalLight;
|
---|
[2858] | 17 |
|
---|
[2896] | 18 |
|
---|
[3019] | 19 |
|
---|
| 20 |
|
---|
[2859] | 21 | /** This class implements a deferred shading algorithm that takes
|
---|
| 22 | a frame buffer object as input and outputs an image in the given size
|
---|
[2858] | 23 | */
|
---|
[2896] | 24 | class DeferredRenderer
|
---|
[2858] | 25 | {
|
---|
| 26 | public:
|
---|
[2874] | 27 | /** Constructor for a deferred shader taking the requested output image size,
|
---|
[3068] | 28 | the current camera;
|
---|
[2858] | 29 | */
|
---|
[3068] | 30 | DeferredRenderer(int w, int h, PerspectiveCamera *cam);
|
---|
[2874] | 31 | /** The algorithm renders the scene given an fbo consists of 1 color buffer,
|
---|
[2861] | 32 | 1 position buffer, and 1 normal buffer.
|
---|
| 33 | We also need the projection view matrix of the last frame for reprojection, and
|
---|
| 34 | a smoothing factor for temporal coherence
|
---|
[2858] | 35 | */
|
---|
[3021] | 36 |
|
---|
| 37 | ~DeferredRenderer();
|
---|
| 38 |
|
---|
[2900] | 39 | void Render(FrameBufferObject *fbo,
|
---|
[2901] | 40 | float tempCohFactor,
|
---|
[2952] | 41 | DirectionalLight *light,
|
---|
[2991] | 42 | bool useToneMapping,
|
---|
| 43 | ShadowMap *shadowMap = NULL
|
---|
| 44 | );
|
---|
[2859] | 45 |
|
---|
[3021] | 46 |
|
---|
[2875] | 47 | void SetUseTemporalCoherence(bool temporal);
|
---|
[2874] | 48 |
|
---|
[2930] | 49 | enum SAMPLING_METHOD {SAMPLING_POISSON, SAMPLING_QUADRATIC, SAMPLING_DEFAULT};
|
---|
[2896] | 50 | enum SHADING_METHOD {DEFAULT, SSAO, GI};
|
---|
[3068] | 51 | /** Set the samplig method for the indirect illumination
|
---|
| 52 | */
|
---|
[2896] | 53 | void SetSamplingMethod(SAMPLING_METHOD s);
|
---|
[3068] | 54 | /** Set the shading method (SSAO, SSAO + color bleeding
|
---|
| 55 | */
|
---|
[2897] | 56 | void SetShadingMethod(SHADING_METHOD s);
|
---|
[3021] | 57 |
|
---|
[3068] | 58 | // hack: store the color buffer idx for the currently used flip flop-MRT here
|
---|
[3038] | 59 | // TODO matt: make this less hacky
|
---|
[2976] | 60 | static int colorBufferIdx;
|
---|
[2887] | 61 |
|
---|
[3038] | 62 |
|
---|
[2859] | 63 | protected:
|
---|
| 64 |
|
---|
[3085] | 65 | void ComputeSsao(FrameBufferObject *fbo, float tempCohFactor);
|
---|
[2859] | 66 |
|
---|
[3085] | 67 | void ComputeGlobIllum(FrameBufferObject *fbo, float tempCohFactor);
|
---|
[2873] | 68 |
|
---|
[2952] | 69 | void FirstPass(FrameBufferObject *fbo, DirectionalLight *light);
|
---|
[2868] | 70 |
|
---|
[2952] | 71 | void FirstPassShadow(FrameBufferObject *fbo, DirectionalLight *light, ShadowMap *shadowMap);
|
---|
[2896] | 72 |
|
---|
[3038] | 73 | void ComputeToneParameters(FrameBufferObject *fbo,
|
---|
| 74 | DirectionalLight *light,
|
---|
| 75 | float &imageKey,
|
---|
| 76 | float &whiteLum,
|
---|
| 77 | float &middleGrey);
|
---|
[2972] | 78 |
|
---|
[3007] | 79 | void ToneMap(FrameBufferObject *fbo, float imageKey, float whiteLum, float middleGrey);
|
---|
[2972] | 80 |
|
---|
[2973] | 81 |
|
---|
[2880] | 82 | void CombineSsao(FrameBufferObject *fbo);
|
---|
| 83 | void CombineIllum(FrameBufferObject *fbo);
|
---|
| 84 |
|
---|
[2970] | 85 | void AntiAliasing(FrameBufferObject *fbo, DirectionalLight *light);
|
---|
[3006] | 86 | /** Downsample buffer of fbo to buffer of downSampleFbo. The downSampleFbo must have half the
|
---|
| 87 | resolution of fbo.
|
---|
| 88 | */
|
---|
| 89 | void DownSample(FrameBufferObject *fbo, int bufferIdx,
|
---|
| 90 | FrameBufferObject *downSampleFbo, int downSampleBufferIdx);
|
---|
[2972] | 91 |
|
---|
[3026] | 92 | void DrawQuad(ShaderProgram *p);
|
---|
[2972] | 93 |
|
---|
[3038] | 94 | /** Initialises the deferred shader and loads the required shaders:
|
---|
| 95 | This function has to be called only once.
|
---|
| 96 | */
|
---|
| 97 | void InitCg();
|
---|
[3085] | 98 | /** Is called once per render call and sets the most important parameters.
|
---|
| 99 | */
|
---|
| 100 | void InitFrame();
|
---|
[3026] | 101 |
|
---|
| 102 |
|
---|
[2859] | 103 | ////////////
|
---|
| 104 |
|
---|
| 105 | int mWidth;
|
---|
| 106 | int mHeight;
|
---|
| 107 |
|
---|
[3062] | 108 | PerspectiveCamera *mCamera;
|
---|
[2860] | 109 |
|
---|
[2875] | 110 | bool mUseTemporalCoherence;
|
---|
[2887] | 111 |
|
---|
[2896] | 112 | int mSamplingMethod;
|
---|
| 113 |
|
---|
| 114 | int mShadingMethod;
|
---|
| 115 |
|
---|
| 116 | bool mRegenerateSamples;
|
---|
[2976] | 117 |
|
---|
[3019] | 118 | int mIllumFboIndex;
|
---|
| 119 | // the fbo for indirect illumination (ssao + color bleeding)
|
---|
| 120 | FrameBufferObject *mIllumFbo;
|
---|
[2994] | 121 |
|
---|
| 122 | FrameBufferObject *mDownSampleFbo;
|
---|
[3019] | 123 |
|
---|
| 124 | FBOContainer mFBOs;
|
---|
| 125 |
|
---|
| 126 | static ShaderContainer sShaders;
|
---|
[3085] | 127 |
|
---|
| 128 | Matrix4x4 mProjViewMatrix;
|
---|
| 129 | Matrix4x4 mOldProjViewMatrix;
|
---|
| 130 |
|
---|
| 131 | Vector3 mCornersView[4];
|
---|
| 132 | Vector3 mOldCornersView[4];
|
---|
| 133 |
|
---|
| 134 | Vector3 mEyePos;
|
---|
| 135 | Vector3 mOldEyePos;
|
---|
[2858] | 136 | };
|
---|
| 137 |
|
---|
[3038] | 138 |
|
---|
[2858] | 139 | } // namespace
|
---|
[2886] | 140 |
|
---|
[2859] | 141 | #endif // _SsaoShader_H__ |
---|