00001
00032 #ifndef LL_POSTPROCESS_H
00033 #define LL_POSTPROCESS_H
00034
00035 #include <map>
00036 #include <fstream>
00037 #include "llgl.h"
00038 #include "llglheaders.h"
00039
00040 class LLPostProcess
00041 {
00042 public:
00043
00044 typedef enum _QuadType {
00045 QUAD_NORMAL,
00046 QUAD_NOISE,
00047 QUAD_BLOOM_EXTRACT,
00048 QUAD_BLOOM_COMBINE
00049 } QuadType;
00050
00052 typedef std::map<const char *, GLuint> glslUniforms;
00053
00054 struct PostProcessTweaks : public LLSD {
00055 inline PostProcessTweaks() : LLSD(LLSD::emptyMap())
00056 {
00057 }
00058
00059 inline LLSD & brightMult() {
00060 return (*this)["brightness_multiplier"];
00061 }
00062
00063 inline LLSD & noiseStrength() {
00064 return (*this)["noise_strength"];
00065 }
00066
00067 inline LLSD & noiseSize() {
00068 return (*this)["noise_size"];
00069 }
00070
00071 inline LLSD & extractLow() {
00072 return (*this)["extract_low"];
00073 }
00074
00075 inline LLSD & extractHigh() {
00076 return (*this)["extract_high"];
00077 }
00078
00079 inline LLSD & bloomWidth() {
00080 return (*this)["bloom_width"];
00081 }
00082
00083 inline LLSD & bloomStrength() {
00084 return (*this)["bloom_strength"];
00085 }
00086
00087 inline LLSD & brightness() {
00088 return (*this)["brightness"];
00089 }
00090
00091 inline LLSD & contrast() {
00092 return (*this)["contrast"];
00093 }
00094
00095 inline LLSD & contrastBaseR() {
00096 return (*this)["contrast_base"][0];
00097 }
00098
00099 inline LLSD & contrastBaseG() {
00100 return (*this)["contrast_base"][1];
00101 }
00102
00103 inline LLSD & contrastBaseB() {
00104 return (*this)["contrast_base"][2];
00105 }
00106
00107 inline LLSD & contrastBaseIntensity() {
00108 return (*this)["contrast_base"][3];
00109 }
00110
00111 inline LLSD & saturation() {
00112 return (*this)["saturation"];
00113 }
00114
00115 inline LLSD & useNightVisionShader() {
00116 return (*this)["enable_night_vision"];
00117 }
00118
00119 inline LLSD & useBloomShader() {
00120 return (*this)["enable_bloom"];
00121 }
00122
00123 inline LLSD & useColorFilter() {
00124 return (*this)["enable_color_filter"];
00125 }
00126
00127
00128 inline F32 getBrightMult() const {
00129 return F32((*this)["brightness_multiplier"].asReal());
00130 }
00131
00132 inline F32 getNoiseStrength() const {
00133 return F32((*this)["noise_strength"].asReal());
00134 }
00135
00136 inline F32 getNoiseSize() const {
00137 return F32((*this)["noise_size"].asReal());
00138 }
00139
00140 inline F32 getExtractLow() const {
00141 return F32((*this)["extract_low"].asReal());
00142 }
00143
00144 inline F32 getExtractHigh() const {
00145 return F32((*this)["extract_high"].asReal());
00146 }
00147
00148 inline F32 getBloomWidth() const {
00149 return F32((*this)["bloom_width"].asReal());
00150 }
00151
00152 inline F32 getBloomStrength() const {
00153 return F32((*this)["bloom_strength"].asReal());
00154 }
00155
00156 inline F32 getBrightness() const {
00157 return F32((*this)["brightness"].asReal());
00158 }
00159
00160 inline F32 getContrast() const {
00161 return F32((*this)["contrast"].asReal());
00162 }
00163
00164 inline F32 getContrastBaseR() const {
00165 return F32((*this)["contrast_base"][0].asReal());
00166 }
00167
00168 inline F32 getContrastBaseG() const {
00169 return F32((*this)["contrast_base"][1].asReal());
00170 }
00171
00172 inline F32 getContrastBaseB() const {
00173 return F32((*this)["contrast_base"][2].asReal());
00174 }
00175
00176 inline F32 getContrastBaseIntensity() const {
00177 return F32((*this)["contrast_base"][3].asReal());
00178 }
00179
00180 inline F32 getSaturation() const {
00181 return F32((*this)["saturation"].asReal());
00182 }
00183
00184 };
00185
00186 GLuint sceneRenderTexture;
00187 GLuint noiseTexture;
00188 GLuint tempBloomTexture;
00189 bool initialized;
00190 PostProcessTweaks tweaks;
00191
00192
00193 LLSD mAllEffects;
00194
00195 public:
00196 LLPostProcess(void);
00197
00198 ~LLPostProcess(void);
00199
00200 void apply(unsigned int width, unsigned int height);
00201
00203 static void initClass(void);
00204
00205
00206 static void cleanupClass();
00207
00208 void setSelectedEffect(std::string const & effectName);
00209
00210 inline LLString const & getSelectedEffect(void) const {
00211 return mSelectedEffectName;
00212 }
00213
00214 void saveEffect(std::string const & effectName);
00215
00216 private:
00218 std::string mShaderErrorString;
00219 unsigned int screenW;
00220 unsigned int screenH;
00221
00222 float noiseTextureScale;
00223
00225 glslUniforms nightVisionUniforms;
00226 glslUniforms bloomExtractUniforms;
00227 glslUniforms bloomBlurUniforms;
00228 glslUniforms colorFilterUniforms;
00229
00230
00231
00232 LLString mSelectedEffectName;
00233
00235 void initialize(unsigned int width, unsigned int height);
00236 void doEffects(void);
00237 void applyShaders(void);
00238 bool shadersEnabled(void);
00239
00241 void createNightVisionShader(void);
00242 void applyNightVisionShader(void);
00243
00245 void createBloomShader(void);
00246 void applyBloomShader(void);
00247
00249 void createColorFilterShader(void);
00250 void applyColorFilterShader(void);
00251
00253 void getShaderUniforms(glslUniforms & uniforms, GLhandleARB & prog);
00254 void createTexture(GLuint & texture, unsigned int width, unsigned int height);
00255 void copyFrameBuffer(GLuint & texture, unsigned int width, unsigned int height);
00256 void createNoiseTexture(GLuint & texture);
00257 bool checkError(void);
00258 void checkShaderError(GLhandleARB shader);
00259 void drawOrthoQuad(unsigned int width, unsigned int height, QuadType type);
00260 void viewOrthogonal(unsigned int width, unsigned int height);
00261 void changeOrthogonal(unsigned int width, unsigned int height);
00262 void viewPerspective(void);
00263 void textureBlendReplace(void);
00264 void textureBlendAdd(void);
00265 void textureBlendSubtract(void);
00266 void textureBlendAddSigned(void);
00267 void textureBlendAlpha(void);
00268 void textureBlendMultiply(void);
00269 void textureBlendMultiplyX2(void);
00270 };
00271
00272 extern LLPostProcess * gPostProcess;
00273
00274
00275 #endif // LL_POSTPROCESS_H