[2859] | 1 | #include "SsaoShader.h"
|
---|
| 2 | #include "FrameBufferObject.h"
|
---|
| 3 | #include "RenderState.h"
|
---|
| 4 | #include "SampleGenerator.h"
|
---|
[2860] | 5 | #include "Vector3.h"
|
---|
| 6 | #include "Camera.h"
|
---|
[2858] | 7 |
|
---|
[2859] | 8 |
|
---|
[2858] | 9 | using namespace std;
|
---|
| 10 |
|
---|
[2860] | 11 | static GLenum mymrt[] = {GL_COLOR_ATTACHMENT0_EXT, GL_COLOR_ATTACHMENT1_EXT, GL_COLOR_ATTACHMENT2_EXT};
|
---|
[2858] | 12 |
|
---|
| 13 | namespace CHCDemoEngine
|
---|
| 14 | {
|
---|
| 15 |
|
---|
[2860] | 16 | // number of ssao samples
|
---|
| 17 | #define NUM_SAMPLES 16
|
---|
| 18 |
|
---|
| 19 |
|
---|
[2859] | 20 | static CGprogram sCgSsaoProgram = NULL;
|
---|
| 21 |
|
---|
| 22 | static CGparameter sColorsTexParam;
|
---|
| 23 | static CGparameter sPositionsTexParam;
|
---|
| 24 | static CGparameter sNormalsTexParam;
|
---|
| 25 | static CGparameter sOldModelViewProjMatrixParam;
|
---|
| 26 | static CGparameter sMaxDepthParam;
|
---|
| 27 | static CGparameter sSamplesParam;
|
---|
| 28 | static CGparameter sOldTexParam;
|
---|
| 29 | static CGparameter sNoiseTexParam;
|
---|
| 30 | static CGparameter sNoiseMultiplierParam;
|
---|
| 31 | static CGparameter sExpFactorParam;
|
---|
[2865] | 32 | static CGprogram sCgAntiAliasingProgram;
|
---|
[2859] | 33 |
|
---|
[2865] | 34 | static CGparameter sColorsTexAntiAliasingParam;
|
---|
| 35 | static CGparameter sNormalsTexAntiAliasingParam;
|
---|
| 36 |
|
---|
| 37 |
|
---|
[2860] | 38 | static GLuint noiseTex;
|
---|
[2859] | 39 |
|
---|
| 40 | // ssao random spherical samples
|
---|
| 41 | static Sample2 samples[NUM_SAMPLES];
|
---|
| 42 |
|
---|
| 43 |
|
---|
| 44 | static void PrintGLerror(char *msg)
|
---|
| 45 | {
|
---|
| 46 | GLenum errCode;
|
---|
| 47 | const GLubyte *errStr;
|
---|
| 48 |
|
---|
| 49 | if ((errCode = glGetError()) != GL_NO_ERROR)
|
---|
| 50 | {
|
---|
| 51 | errStr = gluErrorString(errCode);
|
---|
| 52 | fprintf(stderr,"OpenGL ERROR: %s: %s\n", errStr, msg);
|
---|
| 53 | }
|
---|
| 54 | }
|
---|
| 55 |
|
---|
| 56 |
|
---|
| 57 | /** Generate poisson disc distributed sample points on the unit disc
|
---|
| 58 | */
|
---|
| 59 | static void GenerateSamples()
|
---|
| 60 | {
|
---|
| 61 | static PoissonDiscSampleGenerator poisson(NUM_SAMPLES, 1.0f);
|
---|
| 62 | poisson.Generate((Sample2 *)samples);
|
---|
| 63 | }
|
---|
| 64 |
|
---|
| 65 |
|
---|
[2867] | 66 | SsaoShader::SsaoShader(int w, int h, Camera *cam, float scaleFactor):
|
---|
[2860] | 67 | mWidth(w), mHeight(h),
|
---|
| 68 | mCamera(cam),
|
---|
| 69 | mScaleFactor(scaleFactor)
|
---|
[2861] | 70 | {
|
---|
| 71 |
|
---|
| 72 | ///////////
|
---|
| 73 | //-- the flip-flop fbos
|
---|
[2859] | 74 |
|
---|
[2861] | 75 | mNewFbo = new FrameBufferObject(w, h, FrameBufferObject::DEPTH_NONE);
|
---|
| 76 | // the diffuse color buffer
|
---|
[2867] | 77 | mNewFbo->AddColorBuffer(ColorBufferObject::BUFFER_FLOAT_32, ColorBufferObject::WRAP_CLAMP_TO_EDGE, ColorBufferObject::FILTER_LINEAR, false);
|
---|
[2861] | 78 |
|
---|
| 79 | mOldFbo = new FrameBufferObject(w, h, FrameBufferObject::DEPTH_NONE);
|
---|
| 80 | // the diffuse color buffer
|
---|
[2867] | 81 | mOldFbo->AddColorBuffer(ColorBufferObject::BUFFER_FLOAT_32, ColorBufferObject::WRAP_CLAMP_TO_EDGE, ColorBufferObject::FILTER_LINEAR, false);
|
---|
[2861] | 82 |
|
---|
[2859] | 83 |
|
---|
[2861] | 84 | // create noise texture for ssao
|
---|
| 85 | CreateNoiseTex2D();
|
---|
| 86 | }
|
---|
| 87 |
|
---|
| 88 |
|
---|
| 89 | SsaoShader::~SsaoShader()
|
---|
| 90 | {
|
---|
| 91 | if (sCgSsaoProgram)
|
---|
| 92 | cgDestroyProgram(sCgSsaoProgram);
|
---|
| 93 |
|
---|
| 94 | DEL_PTR(mNewFbo);
|
---|
| 95 | DEL_PTR(mOldFbo);
|
---|
| 96 |
|
---|
| 97 | glDeleteTextures(1, &noiseTex);
|
---|
| 98 | }
|
---|
| 99 |
|
---|
| 100 |
|
---|
[2859] | 101 | void SsaoShader::Init(CGcontext context)
|
---|
[2861] | 102 | {
|
---|
[2859] | 103 | ///////////////
|
---|
| 104 |
|
---|
| 105 | sCgSsaoProgram =
|
---|
| 106 | cgCreateProgramFromFile(context,
|
---|
| 107 | CG_SOURCE,
|
---|
| 108 | "src/shaders/deferred.cg",
|
---|
| 109 | RenderState::sCgFragmentProfile,
|
---|
| 110 | "main_ssao",
|
---|
| 111 | NULL);
|
---|
| 112 |
|
---|
| 113 | if (sCgSsaoProgram != NULL)
|
---|
| 114 | {
|
---|
| 115 | cgGLLoadProgram(sCgSsaoProgram);
|
---|
| 116 |
|
---|
| 117 | // we need size of texture for scaling
|
---|
| 118 | sPositionsTexParam = cgGetNamedParameter(sCgSsaoProgram, "positions");
|
---|
| 119 | sColorsTexParam = cgGetNamedParameter(sCgSsaoProgram, "colors");
|
---|
| 120 | sNormalsTexParam = cgGetNamedParameter(sCgSsaoProgram, "normals");
|
---|
| 121 | sNoiseTexParam = cgGetNamedParameter(sCgSsaoProgram, "noiseTexture");
|
---|
| 122 | sNoiseMultiplierParam = cgGetNamedParameter(sCgSsaoProgram, "noiseMultiplier");
|
---|
| 123 | sOldModelViewProjMatrixParam = cgGetNamedParameter(sCgSsaoProgram, "oldModelViewProj");
|
---|
| 124 | sMaxDepthParam = cgGetNamedParameter(sCgSsaoProgram, "maxDepth");
|
---|
| 125 | sExpFactorParam = cgGetNamedParameter(sCgSsaoProgram, "expFactor");
|
---|
| 126 |
|
---|
| 127 | sSamplesParam = cgGetNamedParameter(sCgSsaoProgram, "samples");
|
---|
| 128 | sOldTexParam = cgGetNamedParameter(sCgSsaoProgram, "oldTex");
|
---|
| 129 |
|
---|
| 130 | // generate samples for ssao kernel
|
---|
| 131 | GenerateSamples();
|
---|
| 132 | cgGLSetParameterArray2f(sSamplesParam, 0, NUM_SAMPLES, (const float *)samples);
|
---|
| 133 | }
|
---|
| 134 | else
|
---|
| 135 | cerr << "ssao program failed to load" << endl;
|
---|
| 136 |
|
---|
[2865] | 137 | sCgAntiAliasingProgram =
|
---|
| 138 | cgCreateProgramFromFile(context,
|
---|
| 139 | CG_SOURCE,
|
---|
| 140 | "src/shaders/antialiasing.cg",
|
---|
| 141 | RenderState::sCgFragmentProfile,
|
---|
| 142 | "main",
|
---|
| 143 | NULL);
|
---|
| 144 |
|
---|
| 145 | if (sCgAntiAliasingProgram != NULL)
|
---|
| 146 | {
|
---|
| 147 | cgGLLoadProgram(sCgAntiAliasingProgram);
|
---|
| 148 |
|
---|
| 149 | sColorsTexAntiAliasingParam = cgGetNamedParameter(sCgAntiAliasingProgram, "colors");
|
---|
| 150 | sNormalsTexAntiAliasingParam = cgGetNamedParameter(sCgAntiAliasingProgram, "normals");
|
---|
| 151 | }
|
---|
| 152 | else
|
---|
| 153 | cerr << "antialiasing program failed to load" << endl;
|
---|
| 154 |
|
---|
| 155 |
|
---|
[2859] | 156 | PrintGLerror("init");
|
---|
| 157 | }
|
---|
| 158 |
|
---|
| 159 |
|
---|
[2861] | 160 | void SsaoShader::Render(FrameBufferObject *fbo,
|
---|
| 161 | const Matrix4x4 &oldProjViewMatrix,
|
---|
| 162 | float expFactor)
|
---|
[2859] | 163 | {
|
---|
[2861] | 164 | cgGLSetMatrixParameterfc(sOldModelViewProjMatrixParam, (const float *)oldProjViewMatrix.x);
|
---|
| 165 |
|
---|
[2867] | 166 | glPushAttrib(GL_VIEWPORT_BIT);
|
---|
| 167 | glViewport(0, 0, mWidth, mHeight);
|
---|
| 168 |
|
---|
| 169 | glDrawBuffers(1, mymrt);
|
---|
| 170 |
|
---|
| 171 | cgGLEnableProfile(RenderState::sCgFragmentProfile);
|
---|
| 172 |
|
---|
| 173 | glDisable(GL_ALPHA_TEST);
|
---|
| 174 | glDisable(GL_TEXTURE_2D);
|
---|
| 175 | glDisable(GL_LIGHTING);
|
---|
| 176 |
|
---|
| 177 | glMatrixMode(GL_PROJECTION);
|
---|
| 178 | glPushMatrix();
|
---|
| 179 | glLoadIdentity();
|
---|
| 180 |
|
---|
| 181 | glMatrixMode(GL_MODELVIEW);
|
---|
| 182 | glPushMatrix();
|
---|
| 183 | glLoadIdentity();
|
---|
| 184 |
|
---|
| 185 | const float offs = 0.5f;
|
---|
| 186 | glOrtho(-offs, offs, -offs, offs, 0, 1);
|
---|
| 187 |
|
---|
[2861] | 188 | // switch roles of old and new fbo
|
---|
| 189 | // the algorihm uses two input fbos, where the one
|
---|
| 190 | // contais the color buffer from the last frame,
|
---|
| 191 | // the other one will be written
|
---|
| 192 | swap(mNewFbo, mOldFbo);
|
---|
| 193 |
|
---|
[2863] | 194 | ComputeSsao(fbo, expFactor);
|
---|
[2861] | 195 | // the second pass just renders the combined solution
|
---|
[2865] | 196 | //DisplayTexture();
|
---|
| 197 | AntiAliasing(fbo);
|
---|
[2867] | 198 |
|
---|
| 199 | glEnable(GL_LIGHTING);
|
---|
| 200 | glDisable(GL_TEXTURE_2D);
|
---|
| 201 |
|
---|
| 202 | glMatrixMode(GL_PROJECTION);
|
---|
| 203 | glPopMatrix();
|
---|
| 204 |
|
---|
| 205 | glMatrixMode(GL_MODELVIEW);
|
---|
| 206 | glPopMatrix();
|
---|
| 207 |
|
---|
| 208 | glPopAttrib();
|
---|
| 209 |
|
---|
| 210 | cgGLDisableProfile(RenderState::sCgFragmentProfile);
|
---|
[2859] | 211 | }
|
---|
| 212 |
|
---|
| 213 |
|
---|
[2863] | 214 | void SsaoShader::ComputeSsao(FrameBufferObject *fbo, float expFactor)
|
---|
[2859] | 215 | {
|
---|
| 216 | GLuint colorsTex = fbo->GetColorBuffer(0)->GetTexture();
|
---|
[2861] | 217 | GLuint positionsTex = fbo->GetColorBuffer(1)->GetTexture();
|
---|
| 218 | GLuint normalsTex = fbo->GetColorBuffer(2)->GetTexture();
|
---|
[2859] | 219 |
|
---|
[2867] | 220 | if (1)
|
---|
| 221 | {
|
---|
| 222 | // generate mip map levels for position texture
|
---|
| 223 | glBindTexture(GL_TEXTURE_2D, positionsTex);
|
---|
| 224 | glGenerateMipmapEXT(GL_TEXTURE_2D);
|
---|
| 225 | }
|
---|
| 226 |
|
---|
| 227 |
|
---|
[2861] | 228 | // read the second buffer, write to the first buffer
|
---|
| 229 | mNewFbo->Bind();
|
---|
| 230 | GLuint oldTex = mOldFbo->GetColorBuffer(0)->GetTexture();
|
---|
[2860] | 231 |
|
---|
| 232 | glDrawBuffers(1, mymrt);
|
---|
[2859] | 233 |
|
---|
| 234 | glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
---|
| 235 |
|
---|
| 236 | cgGLBindProgram(sCgSsaoProgram);
|
---|
| 237 |
|
---|
| 238 | cgGLSetTextureParameter(sPositionsTexParam, positionsTex);
|
---|
| 239 | cgGLEnableTextureParameter(sPositionsTexParam);
|
---|
| 240 |
|
---|
| 241 | cgGLSetTextureParameter(sColorsTexParam, colorsTex);
|
---|
| 242 | cgGLEnableTextureParameter(sColorsTexParam);
|
---|
| 243 |
|
---|
| 244 | cgGLSetTextureParameter(sNormalsTexParam, normalsTex);
|
---|
| 245 | cgGLEnableTextureParameter(sNormalsTexParam);
|
---|
| 246 |
|
---|
| 247 | cgGLSetTextureParameter(sNoiseTexParam, noiseTex);
|
---|
| 248 | cgGLEnableTextureParameter(sNoiseTexParam);
|
---|
| 249 |
|
---|
| 250 | cgGLSetTextureParameter(sOldTexParam, oldTex);
|
---|
| 251 | cgGLEnableTextureParameter(sOldTexParam);
|
---|
| 252 |
|
---|
| 253 | cgGLSetParameter1f(sNoiseMultiplierParam, RandomValue(3.0f, 17.0f));
|
---|
| 254 |
|
---|
| 255 | cgGLSetParameter1f(sMaxDepthParam, mScaleFactor);
|
---|
[2861] | 256 | cgGLSetParameter1f(sExpFactorParam, expFactor);
|
---|
[2859] | 257 |
|
---|
| 258 |
|
---|
[2865] | 259 | //GenerateSamples();
|
---|
[2859] | 260 | cgGLSetParameterArray2f(sSamplesParam, 0, NUM_SAMPLES, (const float *)samples);
|
---|
| 261 |
|
---|
| 262 | Vector3 tl, tr, bl, br;
|
---|
| 263 | ComputeViewVectors(tl, tr, bl, br);
|
---|
| 264 |
|
---|
| 265 | glColor3f(1.0f, 1.0f, 1.0f);
|
---|
| 266 |
|
---|
| 267 | glBegin(GL_QUADS);
|
---|
| 268 |
|
---|
| 269 | // note: slightly larger texture hides ambient occlusion error on border but costs resolution
|
---|
[2860] | 270 | //const float new_offs = 0.55f;
|
---|
| 271 | const float new_offs = 0.5f;
|
---|
| 272 |
|
---|
| 273 | glColor3f(bl.x, bl.y, bl.z); glTexCoord2f(0, 0); glVertex3f(-new_offs, -new_offs, -0.5f);
|
---|
| 274 | glColor3f(br.x, br.y, br.z); glTexCoord2f(1, 0); glVertex3f( new_offs, -new_offs, -0.5f);
|
---|
| 275 | glColor3f(tr.x, tr.y, tr.z); glTexCoord2f(1, 1); glVertex3f( new_offs, new_offs, -0.5f);
|
---|
| 276 | glColor3f(tl.x, tl.y, tl.z); glTexCoord2f(0, 1); glVertex3f(-new_offs, new_offs, -0.5f);
|
---|
[2859] | 277 |
|
---|
| 278 | glEnd();
|
---|
| 279 |
|
---|
[2860] | 280 | cgGLDisableTextureParameter(sColorsTexParam);
|
---|
| 281 | cgGLDisableTextureParameter(sPositionsTexParam);
|
---|
| 282 | cgGLDisableTextureParameter(sNormalsTexParam);
|
---|
| 283 | cgGLDisableTextureParameter(sNoiseTexParam);
|
---|
| 284 | cgGLDisableTextureParameter(sOldTexParam);
|
---|
[2859] | 285 |
|
---|
[2861] | 286 | FrameBufferObject::Release();
|
---|
[2859] | 287 |
|
---|
| 288 | PrintGLerror("ssao first pass");
|
---|
| 289 | }
|
---|
| 290 |
|
---|
| 291 |
|
---|
[2860] | 292 | void SsaoShader::ComputeViewVectors(Vector3 &tl, Vector3 &tr, Vector3 &bl, Vector3 &br)
|
---|
| 293 | {
|
---|
| 294 | Vector3 ftl, ftr, fbl, fbr, ntl, ntr, nbl, nbr;
|
---|
[2859] | 295 |
|
---|
[2860] | 296 | mCamera->ComputePoints(ftl, ftr, fbl, fbr, ntl, ntr, nbl, nbr);
|
---|
| 297 |
|
---|
[2863] | 298 | #if 1 // matT: debug this!!
|
---|
[2860] | 299 |
|
---|
[2863] | 300 | bl = -Normalize(nbl - fbl);
|
---|
| 301 | br = -Normalize(nbr - fbr);
|
---|
| 302 | tl = -Normalize(ntl - ftl);
|
---|
| 303 | tr = -Normalize(ntr - ftr);
|
---|
[2860] | 304 |
|
---|
| 305 | #else // just take camera direction
|
---|
| 306 |
|
---|
| 307 | bl = -Normalize(mCamera->GetDirection());
|
---|
| 308 | br = -Normalize(mCamera->GetDirection());
|
---|
| 309 | tl = -Normalize(mCamera->GetDirection());
|
---|
| 310 | tr = -Normalize(mCamera->GetDirection());
|
---|
| 311 |
|
---|
| 312 | #endif
|
---|
| 313 |
|
---|
| 314 | // normalize to 0 .. 1
|
---|
| 315 | bl = bl * 0.5f + 0.5f;
|
---|
| 316 | br = br * 0.5f + 0.5f;
|
---|
| 317 | tl = tl * 0.5f + 0.5f;
|
---|
| 318 | tr = tr * 0.5f + 0.5f;
|
---|
| 319 | }
|
---|
| 320 |
|
---|
| 321 |
|
---|
| 322 | void SsaoShader::CreateNoiseTex2D()
|
---|
| 323 | {
|
---|
[2867] | 324 | //GLubyte *randomNormals = new GLubyte[mWidth * mHeight * 3];
|
---|
| 325 | float *randomNormals = new float[mWidth * mHeight * 3];
|
---|
[2860] | 326 |
|
---|
| 327 | for (int i = 0; i < mWidth * mHeight * 3; i += 3)
|
---|
| 328 | {
|
---|
[2866] | 329 | // create random samples on a circle
|
---|
[2860] | 330 | const float rx = RandomValue(0, 1);
|
---|
| 331 | const float theta = 2.0f * acos(sqrt(1.0f - rx));
|
---|
| 332 |
|
---|
[2867] | 333 | //randomNormals[i + 0] = (GLubyte)((cos(theta) * 0.5f + 0.5f) * 255.0f);
|
---|
| 334 | //randomNormals[i + 1] = (GLubyte)((sin(theta) * 0.5f + 0.5f) * 255.0f);
|
---|
| 335 | randomNormals[i + 0] = cos(theta);
|
---|
| 336 | randomNormals[i + 1] = sin(theta);
|
---|
[2860] | 337 | randomNormals[i + 2] = 0;
|
---|
| 338 | }
|
---|
| 339 |
|
---|
| 340 | glEnable(GL_TEXTURE_2D);
|
---|
| 341 | glGenTextures(1, &noiseTex);
|
---|
| 342 | glBindTexture(GL_TEXTURE_2D, noiseTex);
|
---|
| 343 |
|
---|
| 344 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
---|
| 345 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
---|
| 346 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
|
---|
| 347 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
|
---|
| 348 |
|
---|
[2867] | 349 | //glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB8, mWidth, mHeight, 0, GL_RGB, GL_UNSIGNED_BYTE, randomNormals);
|
---|
| 350 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA16F_ARB, mWidth, mHeight, 0, GL_RGB, GL_FLOAT, randomNormals);
|
---|
[2860] | 351 |
|
---|
| 352 | glBindTexture(GL_TEXTURE_2D, 0);
|
---|
| 353 | glDisable(GL_TEXTURE_2D);
|
---|
| 354 |
|
---|
| 355 | delete [] randomNormals;
|
---|
| 356 |
|
---|
| 357 | cout << "created noise texture" << endl;
|
---|
| 358 |
|
---|
| 359 | PrintGLerror("noisetexture");
|
---|
| 360 | }
|
---|
| 361 |
|
---|
| 362 |
|
---|
[2865] | 363 |
|
---|
| 364 | static void SetVertex(float x, float y, float x_offs, float y_offs)
|
---|
| 365 | {
|
---|
| 366 | glMultiTexCoord2fARB(GL_TEXTURE0_ARB, x, y); // center
|
---|
| 367 | glMultiTexCoord2fARB(GL_TEXTURE1_ARB, x - x_offs, y + y_offs); // left top
|
---|
| 368 | glMultiTexCoord2fARB(GL_TEXTURE2_ARB, x + x_offs, y - y_offs); // right bottom
|
---|
| 369 | glMultiTexCoord2fARB(GL_TEXTURE3_ARB, x + x_offs, y + y_offs); // right top
|
---|
| 370 | glMultiTexCoord2fARB(GL_TEXTURE4_ARB, x - x_offs, y - y_offs); // left bottom
|
---|
| 371 |
|
---|
| 372 | glMultiTexCoord4fARB(GL_TEXTURE5_ARB, x - x_offs, y, x + x_offs, y); // left right
|
---|
| 373 | glMultiTexCoord4fARB(GL_TEXTURE6_ARB, x, y + y_offs, x, y - y_offs); // top bottom
|
---|
| 374 |
|
---|
| 375 | glVertex3f(x - 0.5f, y - 0.5f, -0.5f);
|
---|
| 376 | }
|
---|
| 377 |
|
---|
| 378 |
|
---|
| 379 | void SsaoShader::AntiAliasing(FrameBufferObject *fbo)
|
---|
| 380 | {
|
---|
| 381 | GLuint colorsTex = mNewFbo->GetColorBuffer(0)->GetTexture();
|
---|
| 382 | GLuint normalsTex = fbo->GetColorBuffer(2)->GetTexture();
|
---|
| 383 |
|
---|
| 384 | glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
---|
| 385 |
|
---|
| 386 | cgGLEnableProfile(RenderState::sCgFragmentProfile);
|
---|
| 387 |
|
---|
| 388 | cgGLBindProgram(sCgAntiAliasingProgram);
|
---|
| 389 |
|
---|
| 390 | cgGLSetTextureParameter(sColorsTexAntiAliasingParam, colorsTex);
|
---|
| 391 | cgGLEnableTextureParameter(sColorsTexAntiAliasingParam);
|
---|
| 392 |
|
---|
| 393 | cgGLSetTextureParameter(sNormalsTexAntiAliasingParam, normalsTex);
|
---|
| 394 | cgGLEnableTextureParameter(sNormalsTexAntiAliasingParam);
|
---|
| 395 |
|
---|
| 396 | glColor3f(1.0f, 1.0f, 1.0f);
|
---|
| 397 |
|
---|
| 398 | float offs2 = 0.5f;
|
---|
| 399 |
|
---|
| 400 | glBegin(GL_QUADS);
|
---|
| 401 |
|
---|
| 402 | // the neighbouring texels
|
---|
| 403 | float x_offs = 1.0f / mWidth;
|
---|
| 404 | float y_offs = 1.0f / mHeight;
|
---|
| 405 |
|
---|
| 406 | SetVertex(0, 0, x_offs, y_offs);
|
---|
| 407 | SetVertex(1, 0, x_offs, y_offs);
|
---|
| 408 | SetVertex(1, 1, x_offs, y_offs);
|
---|
| 409 | SetVertex(0, 1, x_offs, y_offs);
|
---|
| 410 |
|
---|
| 411 | glEnd();
|
---|
| 412 |
|
---|
| 413 | cgGLDisableTextureParameter(sColorsTexAntiAliasingParam);
|
---|
| 414 | cgGLDisableTextureParameter(sNormalsTexAntiAliasingParam);
|
---|
| 415 |
|
---|
[2867] | 416 | PrintGLerror("antialiasing");
|
---|
[2865] | 417 | }
|
---|
| 418 |
|
---|
| 419 |
|
---|
[2858] | 420 | } // namespace
|
---|