[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,
|
---|
[2991] | 46 | bool useToneMapping,
|
---|
| 47 | ShadowMap *shadowMap = NULL
|
---|
| 48 | );
|
---|
[2859] | 49 |
|
---|
| 50 | /** Initialises the deferred shader and loads the required shaders:
|
---|
| 51 | This function has to be called only once.
|
---|
| 52 | */
|
---|
| 53 | static void Init(CGcontext context);
|
---|
| 54 |
|
---|
[2896] | 55 | ~DeferredRenderer();
|
---|
[2859] | 56 |
|
---|
[2875] | 57 | void SetUseTemporalCoherence(bool temporal);
|
---|
[2874] | 58 |
|
---|
[2930] | 59 | enum SAMPLING_METHOD {SAMPLING_POISSON, SAMPLING_QUADRATIC, SAMPLING_DEFAULT};
|
---|
[2896] | 60 | enum SHADING_METHOD {DEFAULT, SSAO, GI};
|
---|
[2875] | 61 |
|
---|
[2896] | 62 | void SetSamplingMethod(SAMPLING_METHOD s);
|
---|
[2887] | 63 |
|
---|
[2897] | 64 | void SetShadingMethod(SHADING_METHOD s);
|
---|
[2976] | 65 | static int colorBufferIdx;
|
---|
[2887] | 66 |
|
---|
[2859] | 67 | protected:
|
---|
| 68 |
|
---|
[2928] | 69 | void ComputeSsao(FrameBufferObject *fbo,
|
---|
| 70 | float tempCohFactor,
|
---|
| 71 | const Matrix4x4 &oldProjViewMatrix,
|
---|
| 72 | const Matrix4x4 &projViewMatrix);
|
---|
[2859] | 73 |
|
---|
[2901] | 74 | void ComputeGlobIllum(FrameBufferObject *fbo, float tempCohFactor, const Matrix4x4 &oldProjViewMatrix);
|
---|
[2873] | 75 |
|
---|
[2952] | 76 | void FirstPass(FrameBufferObject *fbo, DirectionalLight *light);
|
---|
[2868] | 77 |
|
---|
[2952] | 78 | void FirstPassShadow(FrameBufferObject *fbo, DirectionalLight *light, ShadowMap *shadowMap);
|
---|
[2896] | 79 |
|
---|
[2973] | 80 | void ComputeToneParameters(FrameBufferObject *fbo, DirectionalLight *light, float &imageKey, float &whiteLum, float &middleGrey);
|
---|
[2972] | 81 |
|
---|
[2973] | 82 | void ToneMap(FrameBufferObject *fbo, DirectionalLight *light, float imageKey, float whiteLum, float middleGrey);
|
---|
[2972] | 83 |
|
---|
[2973] | 84 |
|
---|
[2880] | 85 | void CombineSsao(FrameBufferObject *fbo);
|
---|
| 86 | void CombineIllum(FrameBufferObject *fbo);
|
---|
| 87 |
|
---|
[2970] | 88 | void AntiAliasing(FrameBufferObject *fbo, DirectionalLight *light);
|
---|
[2889] | 89 | /** Helper method that computes the view vectors in the corners of the current view frustum.
|
---|
| 90 | */
|
---|
[2861] | 91 | void ComputeViewVectors(Vector3 &tl, Vector3 &tr, Vector3 &bl, Vector3 &br);
|
---|
[2965] | 92 |
|
---|
[2972] | 93 | void DownSample(FrameBufferObject *fbo);
|
---|
[2859] | 94 |
|
---|
[2972] | 95 |
|
---|
| 96 |
|
---|
[2859] | 97 | ////////////
|
---|
| 98 |
|
---|
| 99 | int mWidth;
|
---|
| 100 | int mHeight;
|
---|
| 101 |
|
---|
[2957] | 102 | /// a scale factor of scene positions in order to get better float precision in the shader
|
---|
[2859] | 103 | float mScaleFactor;
|
---|
[2860] | 104 |
|
---|
| 105 | Camera *mCamera;
|
---|
| 106 |
|
---|
[2875] | 107 | bool mUseTemporalCoherence;
|
---|
[2887] | 108 |
|
---|
[2896] | 109 | int mSamplingMethod;
|
---|
[2891] | 110 | int mFboIndex;
|
---|
[2896] | 111 |
|
---|
| 112 | int mShadingMethod;
|
---|
| 113 |
|
---|
| 114 | bool mRegenerateSamples;
|
---|
[2976] | 115 |
|
---|
[2994] | 116 | // the main fbo we are working with
|
---|
| 117 | FrameBufferObject *mFbo;
|
---|
| 118 |
|
---|
| 119 | FrameBufferObject *mDownSampleFbo;
|
---|
[2858] | 120 | };
|
---|
| 121 |
|
---|
| 122 | } // namespace
|
---|
[2886] | 123 |
|
---|
[2859] | 124 | #endif // _SsaoShader_H__ |
---|