[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,
|
---|
[3175] | 43 | bool useAntiAliasing,
|
---|
[2991] | 44 | ShadowMap *shadowMap = NULL
|
---|
| 45 | );
|
---|
[2859] | 46 |
|
---|
[3021] | 47 |
|
---|
[2875] | 48 | void SetUseTemporalCoherence(bool temporal);
|
---|
[2874] | 49 |
|
---|
[2930] | 50 | enum SAMPLING_METHOD {SAMPLING_POISSON, SAMPLING_QUADRATIC, SAMPLING_DEFAULT};
|
---|
[2896] | 51 | enum SHADING_METHOD {DEFAULT, SSAO, GI};
|
---|
[3068] | 52 | /** Set the samplig method for the indirect illumination
|
---|
| 53 | */
|
---|
[2896] | 54 | void SetSamplingMethod(SAMPLING_METHOD s);
|
---|
[3068] | 55 | /** Set the shading method (SSAO, SSAO + color bleeding
|
---|
| 56 | */
|
---|
[2897] | 57 | void SetShadingMethod(SHADING_METHOD s);
|
---|
[3021] | 58 |
|
---|
[3189] | 59 | void SetSortSamples(bool sortSamples) { mSortSamples = sortSamples; }
|
---|
| 60 |
|
---|
[3212] | 61 | void SetSampleIntensity(float sampleIntensity);
|
---|
| 62 |
|
---|
| 63 | void SetKernelRadius(float kernelRadius);
|
---|
| 64 |
|
---|
| 65 |
|
---|
[3068] | 66 | // hack: store the color buffer idx for the currently used flip flop-MRT here
|
---|
[3038] | 67 | // TODO matt: make this less hacky
|
---|
[2976] | 68 | static int colorBufferIdx;
|
---|
[2887] | 69 |
|
---|
[3038] | 70 |
|
---|
[2859] | 71 | protected:
|
---|
| 72 |
|
---|
[3085] | 73 | void ComputeSsao(FrameBufferObject *fbo, float tempCohFactor);
|
---|
[2859] | 74 |
|
---|
[3085] | 75 | void ComputeGlobIllum(FrameBufferObject *fbo, float tempCohFactor);
|
---|
[2873] | 76 |
|
---|
[2952] | 77 | void FirstPass(FrameBufferObject *fbo, DirectionalLight *light);
|
---|
[2868] | 78 |
|
---|
[2952] | 79 | void FirstPassShadow(FrameBufferObject *fbo, DirectionalLight *light, ShadowMap *shadowMap);
|
---|
[2896] | 80 |
|
---|
[3038] | 81 | void ComputeToneParameters(FrameBufferObject *fbo,
|
---|
| 82 | DirectionalLight *light,
|
---|
| 83 | float &imageKey,
|
---|
| 84 | float &whiteLum,
|
---|
| 85 | float &middleGrey);
|
---|
[2972] | 86 |
|
---|
[3007] | 87 | void ToneMap(FrameBufferObject *fbo, float imageKey, float whiteLum, float middleGrey);
|
---|
[2972] | 88 |
|
---|
[2973] | 89 |
|
---|
[2880] | 90 | void CombineSsao(FrameBufferObject *fbo);
|
---|
| 91 | void CombineIllum(FrameBufferObject *fbo);
|
---|
| 92 |
|
---|
[2970] | 93 | void AntiAliasing(FrameBufferObject *fbo, DirectionalLight *light);
|
---|
[3006] | 94 | /** Downsample buffer of fbo to buffer of downSampleFbo. The downSampleFbo must have half the
|
---|
| 95 | resolution of fbo.
|
---|
| 96 | */
|
---|
[3137] | 97 | void DownSample(FrameBufferObject *fbo,
|
---|
| 98 | int bufferIdx,
|
---|
| 99 | FrameBufferObject *downSampleFbo,
|
---|
| 100 | int downSampleBufferIdx,
|
---|
| 101 | ShaderProgram *program);
|
---|
[2972] | 102 |
|
---|
[3026] | 103 | void DrawQuad(ShaderProgram *p);
|
---|
[2972] | 104 |
|
---|
[3132] | 105 | void Output(FrameBufferObject *fbo);
|
---|
| 106 |
|
---|
[3038] | 107 | /** Initialises the deferred shader and loads the required shaders:
|
---|
| 108 | This function has to be called only once.
|
---|
| 109 | */
|
---|
| 110 | void InitCg();
|
---|
[3085] | 111 | /** Is called once per render call and sets the most important parameters.
|
---|
| 112 | */
|
---|
| 113 | void InitFrame();
|
---|
[3026] | 114 |
|
---|
[3132] | 115 | void FlipFbos(FrameBufferObject *fbo);
|
---|
[3026] | 116 |
|
---|
[3155] | 117 | void PrepareSsao(FrameBufferObject *fbo);
|
---|
[3132] | 118 |
|
---|
[3167] | 119 | void SortSamples();
|
---|
[3155] | 120 |
|
---|
[3213] | 121 | void LenseFlare(FrameBufferObject *fbo, DirectionalLight *light);
|
---|
| 122 |
|
---|
[3155] | 123 |
|
---|
[2859] | 124 | ////////////
|
---|
| 125 |
|
---|
| 126 | int mWidth;
|
---|
| 127 | int mHeight;
|
---|
| 128 |
|
---|
[3062] | 129 | PerspectiveCamera *mCamera;
|
---|
[2860] | 130 |
|
---|
[2875] | 131 | bool mUseTemporalCoherence;
|
---|
[2887] | 132 |
|
---|
[2896] | 133 | int mSamplingMethod;
|
---|
| 134 |
|
---|
| 135 | int mShadingMethod;
|
---|
| 136 |
|
---|
| 137 | bool mRegenerateSamples;
|
---|
[2976] | 138 |
|
---|
[3019] | 139 | int mIllumFboIndex;
|
---|
| 140 | // the fbo for indirect illumination (ssao + color bleeding)
|
---|
| 141 | FrameBufferObject *mIllumFbo;
|
---|
[2994] | 142 |
|
---|
| 143 | FrameBufferObject *mDownSampleFbo;
|
---|
[3019] | 144 |
|
---|
| 145 | FBOContainer mFBOs;
|
---|
| 146 |
|
---|
| 147 | static ShaderContainer sShaders;
|
---|
[3085] | 148 |
|
---|
| 149 | Matrix4x4 mProjViewMatrix;
|
---|
| 150 | Matrix4x4 mOldProjViewMatrix;
|
---|
| 151 |
|
---|
| 152 | Vector3 mCornersView[4];
|
---|
| 153 | Vector3 mOldCornersView[4];
|
---|
| 154 |
|
---|
| 155 | Vector3 mEyePos;
|
---|
| 156 | Vector3 mOldEyePos;
|
---|
[3189] | 157 |
|
---|
| 158 | bool mSortSamples;
|
---|
[3212] | 159 |
|
---|
| 160 | float mKernelRadius;
|
---|
| 161 | float mSampleIntensity;
|
---|
[2858] | 162 | };
|
---|
| 163 |
|
---|
[3038] | 164 |
|
---|
[2858] | 165 | } // namespace
|
---|
[2886] | 166 |
|
---|
[2859] | 167 | #endif // _SsaoShader_H__ |
---|