[2896] | 1 | #ifndef _DeferredRenderer_H__
|
---|
| 2 | #define _DeferredRenderer_H__
|
---|
[2858] | 3 |
|
---|
| 4 | #include "common.h"
|
---|
[2859] | 5 | #include "glInterface.h"
|
---|
[2896] | 6 |
|
---|
[2859] | 7 | #include <Cg/cg.h>
|
---|
| 8 | #include <Cg/cgGL.h>
|
---|
[2858] | 9 |
|
---|
[2859] | 10 |
|
---|
[2858] | 11 | namespace CHCDemoEngine
|
---|
| 12 | {
|
---|
| 13 |
|
---|
| 14 | class FrameBufferObject;
|
---|
[2860] | 15 | class Vector3;
|
---|
| 16 | class Camera;
|
---|
[2861] | 17 | class Matrix4x4;
|
---|
[2896] | 18 | class ShadowMap;
|
---|
[2858] | 19 |
|
---|
[2896] | 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,
|
---|
[2861] | 28 | the current camera, and a scaling factor.
|
---|
[2860] | 29 |
|
---|
| 30 | The parameter scaleFactor must be reciprocal value of the
|
---|
| 31 | scale factor used for creating the positions texture. It is used recover the
|
---|
| 32 | exact scene size that was scaled in order to improve floating point precision.
|
---|
[2858] | 33 | */
|
---|
[2896] | 34 | DeferredRenderer(int w, int h, Camera *cam, float scaleFactor);
|
---|
[2874] | 35 | /** The algorithm renders the scene given an fbo consists of 1 color buffer,
|
---|
[2861] | 36 | 1 position buffer, and 1 normal buffer.
|
---|
| 37 | We also need the projection view matrix of the last frame for reprojection, and
|
---|
| 38 | a smoothing factor for temporal coherence
|
---|
[2858] | 39 | */
|
---|
[2900] | 40 | void Render(FrameBufferObject *fbo,
|
---|
| 41 | const Matrix4x4 &oldProjViewMatrix,
|
---|
| 42 | const Matrix4x4 &projViewMatrix,
|
---|
[2901] | 43 | float tempCohFactor,
|
---|
[2900] | 44 | ShadowMap *shadowMap = NULL);
|
---|
[2859] | 45 |
|
---|
| 46 | /** Initialises the deferred shader and loads the required shaders:
|
---|
| 47 | This function has to be called only once.
|
---|
| 48 | */
|
---|
| 49 | static void Init(CGcontext context);
|
---|
| 50 |
|
---|
[2896] | 51 | ~DeferredRenderer();
|
---|
[2859] | 52 |
|
---|
[2875] | 53 | void SetUseTemporalCoherence(bool temporal);
|
---|
[2874] | 54 |
|
---|
[2887] | 55 | enum SAMPLING_METHOD {POISSON, GAUSS};
|
---|
[2896] | 56 | enum SHADING_METHOD {DEFAULT, SSAO, GI};
|
---|
[2875] | 57 |
|
---|
[2896] | 58 | void SetSamplingMethod(SAMPLING_METHOD s);
|
---|
[2887] | 59 |
|
---|
[2897] | 60 | void SetShadingMethod(SHADING_METHOD s);
|
---|
[2887] | 61 |
|
---|
[2859] | 62 | protected:
|
---|
| 63 |
|
---|
[2901] | 64 | void ComputeSsao(FrameBufferObject *fbo, float tempCohFactor, const Matrix4x4 &oldProjViewMatrix, const Matrix4x4 &projViewMatrix);
|
---|
[2859] | 65 |
|
---|
[2901] | 66 | void ComputeGlobIllum(FrameBufferObject *fbo, float tempCohFactor, const Matrix4x4 &oldProjViewMatrix);
|
---|
[2873] | 67 |
|
---|
[2868] | 68 | void FirstPass(FrameBufferObject *fbo);
|
---|
| 69 |
|
---|
[2896] | 70 | void FirstPassShadow(FrameBufferObject *fbo, ShadowMap *shadowMap);
|
---|
| 71 |
|
---|
[2880] | 72 | void CombineSsao(FrameBufferObject *fbo);
|
---|
| 73 | void CombineIllum(FrameBufferObject *fbo);
|
---|
| 74 |
|
---|
[2865] | 75 | void AntiAliasing(FrameBufferObject *fbo);
|
---|
[2859] | 76 |
|
---|
[2889] | 77 | /** Helper method that computes the view vectors in the corners of the current view frustum.
|
---|
| 78 | */
|
---|
[2861] | 79 | void ComputeViewVectors(Vector3 &tl, Vector3 &tr, Vector3 &bl, Vector3 &br);
|
---|
[2859] | 80 |
|
---|
[2861] | 81 |
|
---|
[2859] | 82 | ////////////
|
---|
| 83 |
|
---|
| 84 | int mWidth;
|
---|
| 85 | int mHeight;
|
---|
| 86 |
|
---|
| 87 | /// this is just a scale factor for the scene depth in order to get better float precision in the shader
|
---|
| 88 | float mScaleFactor;
|
---|
[2860] | 89 |
|
---|
| 90 | Camera *mCamera;
|
---|
| 91 |
|
---|
[2891] | 92 | FrameBufferObject *mFbo;
|
---|
[2875] | 93 |
|
---|
| 94 | bool mUseTemporalCoherence;
|
---|
[2887] | 95 |
|
---|
[2896] | 96 | int mSamplingMethod;
|
---|
[2891] | 97 | int mFboIndex;
|
---|
[2896] | 98 |
|
---|
| 99 | int mShadingMethod;
|
---|
| 100 |
|
---|
| 101 | bool mRegenerateSamples;
|
---|
[2858] | 102 | };
|
---|
| 103 |
|
---|
| 104 | } // namespace
|
---|
[2886] | 105 |
|
---|
[2859] | 106 | #endif // _SsaoShader_H__ |
---|