[2952] | 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;
|
---|
[2952] | 19 | class DirectionalLight;
|
---|
[2858] | 20 |
|
---|
[2896] | 21 |
|
---|
[2859] | 22 | /** This class implements a deferred shading algorithm that takes
|
---|
| 23 | a frame buffer object as input and outputs an image in the given size
|
---|
[2858] | 24 | */
|
---|
[2896] | 25 | class DeferredRenderer
|
---|
[2858] | 26 | {
|
---|
| 27 | public:
|
---|
[2874] | 28 | /** Constructor for a deferred shader taking the requested output image size,
|
---|
[2861] | 29 | the current camera, and a scaling factor.
|
---|
[2860] | 30 |
|
---|
| 31 | The parameter scaleFactor must be reciprocal value of the
|
---|
[2952] | 32 | scale factor used for creating the world space position texture. It is used recover the
|
---|
[2860] | 33 | exact scene size that was scaled in order to improve floating point precision.
|
---|
[2858] | 34 | */
|
---|
[2896] | 35 | DeferredRenderer(int w, int h, Camera *cam, float scaleFactor);
|
---|
[2874] | 36 | /** The algorithm renders the scene given an fbo consists of 1 color buffer,
|
---|
[2861] | 37 | 1 position buffer, and 1 normal buffer.
|
---|
| 38 | We also need the projection view matrix of the last frame for reprojection, and
|
---|
| 39 | a smoothing factor for temporal coherence
|
---|
[2858] | 40 | */
|
---|
[2900] | 41 | void Render(FrameBufferObject *fbo,
|
---|
| 42 | const Matrix4x4 &oldProjViewMatrix,
|
---|
| 43 | const Matrix4x4 &projViewMatrix,
|
---|
[2901] | 44 | float tempCohFactor,
|
---|
[2952] | 45 | DirectionalLight *light,
|
---|
[2900] | 46 | ShadowMap *shadowMap = NULL);
|
---|
[2859] | 47 |
|
---|
| 48 | /** Initialises the deferred shader and loads the required shaders:
|
---|
| 49 | This function has to be called only once.
|
---|
| 50 | */
|
---|
| 51 | static void Init(CGcontext context);
|
---|
| 52 |
|
---|
[2896] | 53 | ~DeferredRenderer();
|
---|
[2859] | 54 |
|
---|
[2875] | 55 | void SetUseTemporalCoherence(bool temporal);
|
---|
[2874] | 56 |
|
---|
[2930] | 57 | enum SAMPLING_METHOD {SAMPLING_POISSON, SAMPLING_QUADRATIC, SAMPLING_DEFAULT};
|
---|
[2896] | 58 | enum SHADING_METHOD {DEFAULT, SSAO, GI};
|
---|
[2875] | 59 |
|
---|
[2896] | 60 | void SetSamplingMethod(SAMPLING_METHOD s);
|
---|
[2887] | 61 |
|
---|
[2897] | 62 | void SetShadingMethod(SHADING_METHOD s);
|
---|
[2887] | 63 |
|
---|
[2859] | 64 | protected:
|
---|
| 65 |
|
---|
[2928] | 66 | void ComputeSsao(FrameBufferObject *fbo,
|
---|
| 67 | float tempCohFactor,
|
---|
| 68 | const Matrix4x4 &oldProjViewMatrix,
|
---|
| 69 | const Matrix4x4 &projViewMatrix);
|
---|
[2859] | 70 |
|
---|
[2901] | 71 | void ComputeGlobIllum(FrameBufferObject *fbo, float tempCohFactor, const Matrix4x4 &oldProjViewMatrix);
|
---|
[2873] | 72 |
|
---|
[2952] | 73 | void FirstPass(FrameBufferObject *fbo, DirectionalLight *light);
|
---|
[2868] | 74 |
|
---|
[2952] | 75 | void FirstPassShadow(FrameBufferObject *fbo, DirectionalLight *light, ShadowMap *shadowMap);
|
---|
[2896] | 76 |
|
---|
[2880] | 77 | void CombineSsao(FrameBufferObject *fbo);
|
---|
| 78 | void CombineIllum(FrameBufferObject *fbo);
|
---|
| 79 |
|
---|
[2970] | 80 | void AntiAliasing(FrameBufferObject *fbo, DirectionalLight *light);
|
---|
[2889] | 81 | /** Helper method that computes the view vectors in the corners of the current view frustum.
|
---|
| 82 | */
|
---|
[2861] | 83 | void ComputeViewVectors(Vector3 &tl, Vector3 &tr, Vector3 &bl, Vector3 &br);
|
---|
[2965] | 84 |
|
---|
[2859] | 85 |
|
---|
| 86 | ////////////
|
---|
| 87 |
|
---|
| 88 | int mWidth;
|
---|
| 89 | int mHeight;
|
---|
| 90 |
|
---|
[2957] | 91 | /// a scale factor of scene positions in order to get better float precision in the shader
|
---|
[2859] | 92 | float mScaleFactor;
|
---|
[2860] | 93 |
|
---|
| 94 | Camera *mCamera;
|
---|
| 95 |
|
---|
[2891] | 96 | FrameBufferObject *mFbo;
|
---|
[2875] | 97 |
|
---|
| 98 | bool mUseTemporalCoherence;
|
---|
[2887] | 99 |
|
---|
[2896] | 100 | int mSamplingMethod;
|
---|
[2891] | 101 | int mFboIndex;
|
---|
[2896] | 102 |
|
---|
| 103 | int mShadingMethod;
|
---|
| 104 |
|
---|
| 105 | bool mRegenerateSamples;
|
---|
[2858] | 106 | };
|
---|
| 107 |
|
---|
| 108 | } // namespace
|
---|
[2886] | 109 |
|
---|
[2859] | 110 | #endif // _SsaoShader_H__ |
---|