Changeset 3017
- Timestamp:
- 10/09/08 11:19:33 (16 years ago)
- Location:
- GTP/trunk/App/Demos/Vis/FriendlyCulling
- Files:
-
- 1 added
- 13 edited
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/App/Demos/Vis/FriendlyCulling/FriendlyCulling.sln
r3012 r3017 12 12 EndProject 13 13 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "IrradianceMapping", "IrradianceMapping.vcproj", "{91680C49-A358-48AE-A02C-66CB884B7D7F}" 14 ProjectSection(ProjectDependencies) = postProject 15 {03661866-4093-4B02-B26A-028EA91AF023} = {03661866-4093-4B02-B26A-028EA91AF023} 16 EndProjectSection 14 17 EndProject 15 18 Global -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/DeferredRenderer.cpp
r3016 r3017 53 53 54 54 static CGparameter sDownSampleOffsetParam; 55 55 static CGparameter sFilterOffsetsParam; 56 static CGparameter sFilterWeightsParam; 56 57 57 58 static CGprogram sCgDownSampleProgram; … … 65 66 66 67 static CGparameter sColorsTexParam; 67 static CGparameter sPositionsTexParam;68 68 static CGparameter sNormalsTexParam; 69 69 … … 175 175 } 176 176 177 177 static void ComputeSampleOffsets(float *sampleOffsets, int w, int h) 178 { 179 /* 180 const float xoffs = 0.5f / w; 181 const float yoffs = 0.5f / h; 182 183 sampleOffsets[0] = xoffs; sampleOffsets[1] = yoffs; 184 sampleOffsets[2] = xoffs; sampleOffsets[3] = -yoffs; 185 sampleOffsets[4] = -xoffs; sampleOffsets[5] = -yoffs; 186 sampleOffsets[6] = -xoffs; sampleOffsets[7] = yoffs; 187 */ 188 //const float xoffs = .5f / w; 189 //const float yoffs = .5f / h; 190 191 const float xoffs = 1.0f / w; 192 const float yoffs = 1.0f / h; 193 194 int idx = 0; 195 196 for (int x = -1; x <= 1; ++ x) 197 { 198 for (int y = -1; y <= 1; ++ y) 199 { 200 sampleOffsets[idx + 0] = x * xoffs; 201 sampleOffsets[idx + 1] = y * yoffs; 202 203 idx += 2; 204 } 205 } 206 } 178 207 179 208 /** Generate poisson disc distributed sample points on the unit disc … … 284 313 285 314 mFbo = new FrameBufferObject(w / 2, h / 2, FrameBufferObject::DEPTH_NONE); 286 287 mFbo->AddColorBuffer(ColorBufferObject::RGBA_FLOAT_32, ColorBufferObject::WRAP_CLAMP_TO_EDGE, ColorBufferObject::FILTER_LINEAR); 288 mFbo->AddColorBuffer(ColorBufferObject::RGBA_FLOAT_32, ColorBufferObject::WRAP_CLAMP_TO_EDGE, ColorBufferObject::FILTER_LINEAR); 289 mFbo->AddColorBuffer(ColorBufferObject::RGBA_FLOAT_32, ColorBufferObject::WRAP_CLAMP_TO_EDGE, ColorBufferObject::FILTER_LINEAR); 290 mFbo->AddColorBuffer(ColorBufferObject::RGBA_FLOAT_32, ColorBufferObject::WRAP_CLAMP_TO_EDGE, ColorBufferObject::FILTER_LINEAR); 315 //mFbo = new FrameBufferObject(w, h, FrameBufferObject::DEPTH_NONE); 316 317 mFbo->AddColorBuffer(ColorBufferObject::RGB_FLOAT_32, ColorBufferObject::WRAP_CLAMP_TO_EDGE, ColorBufferObject::FILTER_LINEAR); 318 mFbo->AddColorBuffer(ColorBufferObject::RGB_FLOAT_32, ColorBufferObject::WRAP_CLAMP_TO_EDGE, ColorBufferObject::FILTER_LINEAR); 319 mFbo->AddColorBuffer(ColorBufferObject::RGB_FLOAT_32, ColorBufferObject::WRAP_CLAMP_TO_EDGE, ColorBufferObject::FILTER_LINEAR); 320 mFbo->AddColorBuffer(ColorBufferObject::RGB_FLOAT_32, ColorBufferObject::WRAP_CLAMP_TO_EDGE, ColorBufferObject::FILTER_LINEAR); 291 321 292 322 mDownSampleFbo = new FrameBufferObject(w / 2, h / 2, FrameBufferObject::DEPTH_NONE); 323 293 324 mDownSampleFbo->AddColorBuffer(ColorBufferObject::RGBA_FLOAT_32, ColorBufferObject::WRAP_CLAMP_TO_EDGE, ColorBufferObject::FILTER_LINEAR); 294 mDownSampleFbo->AddColorBuffer(ColorBufferObject::RGBA_FLOAT_16, ColorBufferObject::WRAP_CLAMP_TO_EDGE, ColorBufferObject::FILTER_LINEAR); 295 mDownSampleFbo->AddColorBuffer(ColorBufferObject::RGBA_FLOAT_32, ColorBufferObject::WRAP_CLAMP_TO_EDGE, ColorBufferObject::FILTER_LINEAR); 325 mDownSampleFbo->AddColorBuffer(ColorBufferObject::RGB_FLOAT_16, ColorBufferObject::WRAP_CLAMP_TO_EDGE, ColorBufferObject::FILTER_LINEAR); 296 326 } 297 327 … … 361 391 cgGLLoadProgram(sCgSsaoProgram); 362 392 363 sPositionsTexParam = cgGetNamedParameter(sCgSsaoProgram, "positions");364 393 sColorsTexParam = cgGetNamedParameter(sCgSsaoProgram, "colors"); 365 394 sEyePosParam = cgGetNamedParameter(sCgSsaoProgram, "eyePos"); … … 452 481 sColorsTexCombinedSsaoParam = cgGetNamedParameter(sCgCombinedSsaoProgram, "colors"); 453 482 sSsaoTexCombinedSsaoParam = cgGetNamedParameter(sCgCombinedSsaoProgram, "ssaoTex"); 483 484 sFilterOffsetsParam = cgGetNamedParameter(sCgCombinedSsaoProgram, "filterOffs"); 485 sFilterWeightsParam = cgGetNamedParameter(sCgCombinedSsaoProgram, "filterWeights"); 454 486 } 455 487 else … … 622 654 DownSample(fbo, colorBufferIdx, mDownSampleFbo, 0); 623 655 DownSample(fbo, 1, mDownSampleFbo, 1); 624 DownSample(fbo, 2, mDownSampleFbo, 2);625 656 626 657 ComputeSsao(fbo, tempCohFactor, oldProjViewMatrix, projViewMatrix); … … 690 721 GLuint colorsTex = fbo->GetColorBuffer(colorBufferIdx)->GetTexture(); 691 722 GLuint normalsTex = fbo->GetColorBuffer(1)->GetTexture(); 692 GLuint positionsTex = fbo->GetColorBuffer(2)->GetTexture();693 723 #else 694 724 GLuint colorsTex = mDownSampleFbo->GetColorBuffer(0)->GetTexture(); 695 725 GLuint normalsTex = mDownSampleFbo->GetColorBuffer(1)->GetTexture(); 696 GLuint positionsTex = mDownSampleFbo->GetColorBuffer(2)->GetTexture();697 726 #endif 698 727 … … 708 737 709 738 cgGLBindProgram(sCgSsaoProgram); 710 711 cgGLSetTextureParameter(sPositionsTexParam, positionsTex);712 cgGLEnableTextureParameter(sPositionsTexParam);713 739 714 740 cgGLSetTextureParameter(sColorsTexParam, colorsTex); … … 764 790 glTexCoord2f(0, 1); glMultiTexCoord3fARB(GL_TEXTURE1_ARB, tl.x, tl.y, tl.z); glVertex3f(-offs, offs, -0.5f); 765 791 792 //cout<<bl << " " << br << endl; 793 766 794 glEnd(); 767 795 768 796 cgGLDisableTextureParameter(sColorsTexParam); 769 cgGLDisableTextureParameter(sPositionsTexParam);770 797 cgGLDisableTextureParameter(sNormalsTexParam); 771 798 cgGLDisableTextureParameter(sNoiseTexParam); … … 1040 1067 1041 1068 1069 static float GaussianDistribution(float x, float y, float rho) 1070 { 1071 float g = 1.0f / sqrtf(2.0f * M_PI * rho * rho); 1072 g *= expf( -(x*x + y*y) / (2.0f * rho * rho)); 1073 1074 return g; 1075 } 1076 1077 1042 1078 void DeferredRenderer::CombineSsao(FrameBufferObject *fbo) 1043 1079 { … … 1054 1090 1055 1091 cgGLBindProgram(sCgCombinedSsaoProgram); 1092 1093 float filterOffsets[NUM_DOWNSAMPLES * 2]; 1094 float filterWeights[NUM_DOWNSAMPLES]; 1095 1096 PoissonDiscSampleGenerator2 poisson(NUM_DOWNSAMPLES, 1.0f); 1097 poisson.Generate((float *)filterOffsets); 1098 1099 const float xoffs = 2.0f / fbo->GetWidth(); 1100 const float yoffs = 2.0f / fbo->GetHeight(); 1101 1102 for (int i = 0; i < NUM_DOWNSAMPLES; ++ i) 1103 { 1104 float x = filterOffsets[2 * i + 0]; 1105 float y = filterOffsets[2 * i + 1]; 1106 1107 filterOffsets[2 * i + 0] *= xoffs; 1108 filterOffsets[2 * i + 1] *= yoffs; 1109 1110 filterWeights[i] = GaussianDistribution(x, y, 1.0f); 1111 } 1112 1113 //ComputeSampleOffsets(filterOffsets, fbo->GetWidth(), fbo->GetHeight()); 1114 cgGLSetParameterArray2f(sFilterOffsetsParam, 0, NUM_DOWNSAMPLES, (const float *)filterOffsets); 1115 cgGLSetParameterArray1f(sFilterWeightsParam, 0, NUM_DOWNSAMPLES, (const float *)filterWeights); 1056 1116 1057 1117 cgGLSetTextureParameter(sColorsTexCombinedSsaoParam, colorsTex); … … 1187 1247 1188 1248 const float minKey = 0.09f; 1189 const float maxKey = 0. 5f;1249 const float maxKey = 0.45f; 1190 1250 1191 1251 const float lightIntensity = DotProd(-light->GetDirection(), Vector3::UNIT_Z()); 1192 1252 middleGrey = lightIntensity * maxKey + (1.0f - lightIntensity) * minKey; 1193 1253 1194 1195 #if 11196 1254 1197 1255 ////////// … … 1226 1284 PrintGLerror("ToneMapParams"); 1227 1285 1228 #endif1229 1286 1230 1287 /////////////////// … … 1265 1322 1266 1323 1267 static void ComputeDownsSampleOffsets(float *downSampleOffsets, int w, int h)1268 {1269 /*1270 float downSampleOffsets[8];1271 1272 const float xoffs = 0.5f / w;1273 const float yoffs = 0.5f / h;1274 1275 downSampleOffsets[0] = xoffs; downSampleOffsets[1] = yoffs;1276 downSampleOffsets[2] = xoffs; downSampleOffsets[3] = -yoffs;1277 downSampleOffsets[4] = -xoffs; downSampleOffsets[5] = -yoffs;1278 downSampleOffsets[6] = -xoffs; downSampleOffsets[7] = yoffs;1279 */1280 //const float xoffs = .5f / w;1281 //const float yoffs = .5f / h;1282 1283 const float xoffs = 1.0f / w;1284 const float yoffs = 1.0f / h;1285 1286 int idx = 0;1287 1288 for (int x = -1; x <= 1; ++ x)1289 {1290 for (int y = -1; y <= 1; ++ y)1291 {1292 downSampleOffsets[idx + 0] = x * xoffs;1293 downSampleOffsets[idx + 1] = y * yoffs;1294 1295 idx += 2;1296 }1297 }1298 }1299 1300 1301 1324 void DeferredRenderer::DownSample(FrameBufferObject *fbo, int bufferIdx, 1302 1325 FrameBufferObject *downSampleFbo, 1303 1326 int downSampleBufferIdx) 1304 1327 { 1305 float downSampleOffsets[NUM_DOWNSAMPLES * 2];1306 ComputeDownsSampleOffsets(downSampleOffsets, fbo->GetWidth(), fbo->GetHeight());1307 1308 1328 ColorBufferObject *colorBuffer = fbo->GetColorBuffer(bufferIdx); 1309 1329 GLuint colorsTex = colorBuffer->GetTexture(); … … 1316 1336 cgGLSetTextureParameter(sColorsTexDownSampleParam, colorsTex); 1317 1337 cgGLEnableTextureParameter(sColorsTexDownSampleParam); 1338 1339 float downSampleOffsets[NUM_DOWNSAMPLES * 2]; 1340 ComputeSampleOffsets(downSampleOffsets, fbo->GetWidth(), fbo->GetHeight()); 1318 1341 1319 1342 cgGLSetParameterArray2f(sDownSampleOffsetParam, 0, NUM_DOWNSAMPLES, (const float *)downSampleOffsets); -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/FrameBufferObject.cpp
r3007 r3017 93 93 { 94 94 case RGB_UBYTE: 95 mGlFormat = GL_UNSIGNED_BYTE; mInternalFormat = GL_RGB8; 96 components = GL_RGB; 97 break; 95 mGlFormat = GL_UNSIGNED_BYTE; mInternalFormat = GL_RGB8; components = GL_RGB; break; 98 96 case RGBA_UBYTE: 99 97 mGlFormat = GL_UNSIGNED_BYTE; mInternalFormat = GL_RGBA8; break; 98 case RGB_FLOAT_32: 99 mGlFormat = GL_FLOAT; mInternalFormat = GL_RGB16F_ARB; components = GL_RGB; break; 100 100 case RGBA_FLOAT_16: 101 101 mGlFormat = GL_FLOAT; mInternalFormat = GL_RGBA16F_ARB; break; 102 case RGB_FLOAT_32: 103 mGlFormat = GL_FLOAT; mInternalFormat = GL_RGB32F_ARB; 104 components = GL_RGB; 105 break; 102 case RGB_FLOAT_16: 103 mGlFormat = GL_FLOAT; mInternalFormat = GL_RGB32F_ARB; components = GL_RGB; break; 106 104 case RGBA_FLOAT_32: 107 105 mGlFormat = GL_FLOAT; mInternalFormat = GL_RGBA32F_ARB; break; -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/FrameBufferObject.h
r3007 r3017 15 15 public: 16 16 17 enum FORMAT { RGB_UBYTE, RGBA_UBYTE, RGBA_FLOAT_16, RGB_FLOAT_32, RGBA_FLOAT_32}; 17 enum FORMAT { RGB_UBYTE, RGBA_UBYTE, RGB_FLOAT_16, RGBA_FLOAT_16, RGB_FLOAT_32, RGBA_FLOAT_32 }; 18 18 19 enum WRAP_TYPE { WRAP_REPEAT, WRAP_CLAMP_TO_EDGE }; 19 20 enum FILTER_TYPE { FILTER_NEAREST, FILTER_LINEAR }; -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/SkyPreetham.cpp
r2983 r3017 343 343 diffuse = color * 3e-1f; 344 344 345 // diffuse component should be more saturated (and less blueish) for high sun positions 346 diffuse.x *= 1.2f; 347 diffuse.z *= 0.8f; 348 349 // scale diffuse component in order to make sky look less bright in relation to 350 // the geometry in the evening 345 351 diffuse *= (2.0f - 1.0f * DotProd(sunDir, Vector3::UNIT_Z())); 346 352 -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/chcdemo.cpp
r3016 r3017 616 616 fbo->AddColorBuffer(ColorBufferObject::RGBA_FLOAT_32, ColorBufferObject::WRAP_CLAMP_TO_EDGE, ColorBufferObject::FILTER_LINEAR, ColorBufferObject::FILTER_NEAREST); 617 617 // the normals buffer 618 fbo->AddColorBuffer(ColorBufferObject::RGB A_FLOAT_16, ColorBufferObject::WRAP_CLAMP_TO_EDGE, ColorBufferObject::FILTER_NEAREST);618 fbo->AddColorBuffer(ColorBufferObject::RGB_FLOAT_16, ColorBufferObject::WRAP_CLAMP_TO_EDGE, ColorBufferObject::FILTER_NEAREST); 619 619 // the positions buffer 620 620 //fbo->AddColorBuffer(ColorBufferObject::RGBA_FLOAT_32, ColorBufferObject::WRAP_CLAMP_TO_EDGE, ColorBufferObject::FILTER_NEAREST); … … 947 947 cgGLSetParameter3f(sTRParam, tr.x, tr.y, tr.z); 948 948 949 //cout<<bl << " " << br << endl; 949 950 cgGLSetParameter3f(sBLParamTex, bl.x, bl.y, bl.z); 950 951 cgGLSetParameter3f(sBRParamTex, br.x, br.y, br.z); 951 952 cgGLSetParameter3f(sTLParamTex, tl.x, tl.y, tl.z); 952 953 cgGLSetParameter3f(sTRParamTex, tr.x, tr.y, tr.z); 954 953 955 954 956 // draw to 3 color buffers -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaderenv.h
r3016 r3017 10 10 11 11 // for quadratic falloff 12 #define SAMPLE_INTENSITY 0.1 5f13 //#define SAMPLE_INTENSITY 0. 32f12 #define SAMPLE_INTENSITY 0.1f 13 //#define SAMPLE_INTENSITY 0.2f 14 14 15 #define AREA_SIZE8e-1f15 #define SAMPLE_RADIUS 8e-1f 16 16 17 17 //#define DISTANCE_SCALE 1e-1f 18 18 #define DISTANCE_SCALE 5e-2f 19 19 20 #define ILLUM_INTENSITY 5e-2f20 #define ILLUM_INTENSITY 8e-2f 21 21 22 #define VIEW_CORRECTION_SCALE 0.1f22 #define VIEW_CORRECTION_SCALE 1.0f 23 23 24 24 … … 40 40 #define MAX_LOD_LEVEL 10 41 41 42 #define MIN_DEPTH_DIFF 1e- 3f42 #define MIN_DEPTH_DIFF 1e-6f 43 43 // burnout 44 44 #define WHITE_LUMINANCE 3e4f … … 46 46 /////////////////// 47 47 48 #define NUM_DOWNSAMPLES 948 #define NUM_DOWNSAMPLES 16 49 49 50 50 -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/deferred.cg
r3016 r3017 168 168 // diffuse intensity 169 169 const float angle = saturate(dot(normal, lightDir)); 170 //float4 lightDiffuse = float4(1.0f, 1.0f, 0.9f, 1.0f);171 170 const float4 lightDiffuse = glstate.light[0].diffuse; 172 //float4(1.0f, 1.0f, 0.9f, 1.0f); 173 171 174 172 float4 diffuse = lightDiffuse * angle; 175 173 -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/globillum.cg
r3016 r3017 8 8 struct fragment 9 9 { 10 // normalized screen position11 float4 pos: WPOS;12 10 float2 texCoord: TEXCOORD0; 13 11 float3 view: TEXCOORD1; … … 68 66 uniform float3 tl, 69 67 uniform float3 tr 70 //, uniform float3 viewDir68 , uniform float3 viewDir 71 69 ) 72 70 { … … 98 96 #endif 99 97 // weight with projected coordinate to reach similar kernel size for near and far 100 float2 texcoord = IN.texCoord.xy + offsetTransformed * AREA_SIZE *w;98 float2 texcoord = IN.texCoord.xy + offsetTransformed * w; 101 99 102 100 //if ((texcoord.x <= 1.0f) && (texcoord.x >= 0.0f) && (texcoord.y <= 1.0f) && (texcoord.y >= 0.0f)) ++ numSamples; … … 115 113 const float3 sample_color = sample.xyz; 116 114 115 // distance between current position and sample position controls AO intensity. 116 117 117 float3 vector_to_sample = sample_position - centerPosition.xyz; 118 118 const float length_to_sample = length(vector_to_sample); … … 124 124 125 125 const float denom = (DISTANCE_SCALE + length_to_sample * length_to_sample); 126 // distance between current position and sample position controls AO intensity. 126 127 127 const float ssao_intensity = SAMPLE_INTENSITY / denom; 128 129 128 const float illum_intensity = ILLUM_INTENSITY / denom; 130 129 131 // if normal perpenticular to view dir, only half of the samples count 132 #if 0 133 const float view_correction = 1.0f + VIEW_CORRECTION_SCALE * (1.0f - dot(currentViewDir, currentNormal)); 134 total_color.w -= cos_angle * distance_intensity * view_correction; 135 total_color.xyz += cos_angle * distance_intensity * view_correction * sample_color * ILLUM_INTENSITY; 136 #endif 130 // if normal perpenticular to view dir, only the samples approx count half 131 #if 1 132 const float view_correction = 1.0f + VIEW_CORRECTION_SCALE * dot(viewDir, currentNormal); 133 134 total_ao += cos_angle * ssao_intensity * view_correction; 135 total_color += cos_angle * illum_intensity * sample_color * view_correction; 136 #else 137 137 total_ao += cos_angle * ssao_intensity; 138 138 total_color += cos_angle * illum_intensity * sample_color; 139 #endif 139 140 } 140 141 … … 170 171 float3 normal = normalize(norm.xyz); 171 172 172 // the w coordinate from the persp. projection 173 float w = norm.w; 174 175 173 176 174 ///////////// 177 175 //-- reconstruct position from the eye space depth … … 182 180 const float3 eyeSpacePos = -viewDir * eyeDepth; 183 181 184 float3 centerPosition = eyePos + eyeSpacePos; 185 //const float3 centerPosition = tex2D(positions, IN.texCoord.xy).xyz; 186 182 const float3 centerPosition = eyePos + eyeSpacePos; 183 const float4 realPos = float4(centerPosition, 1.0f); 184 185 // calculcate the current projected depth for next frame 186 float4 currentPos = mul(modelViewProj, realPos); 187 const float w = SAMPLE_RADIUS / currentPos.w; 188 currentPos /= currentPos.w; 189 const float currentDepth = currentPos.z * 1e-3f; 187 190 188 191 /////////// 189 192 //-- compute color bleeding + ao 190 193 191 GiStruct gi = globIllum(IN, colors, noiseTexture, samples, normal, eyeSpacePos, w, bl, br, tl, tr );194 GiStruct gi = globIllum(IN, colors, noiseTexture, samples, normal, eyeSpacePos, w, bl, br, tl, tr, normalize(IN.view)); 192 195 193 196 … … 195 198 //-- compute temporally smoothing 196 199 197 float4 realPos = float4(centerPosition, 1.0f); 198 199 200 // calculcate the current projected depth for next frame 201 float4 currentPos = mul(modelViewProj, realPos); 202 currentPos /= currentPos.w; 203 const float currentDepth = currentPos.z; 204 205 206 /////////// 207 //-- reprojection new frame into old one 208 200 201 // reprojection new frame into old one 209 202 // calculate projected depth 210 203 float4 projPos = mul(oldModelViewProj, realPos); … … 212 205 213 206 // the current depth projected into the old frame 214 const float projDepth = projPos.z ;207 const float projDepth = projPos.z * 1e-3f; 215 208 216 209 // fit from unit cube into 0 .. 1 217 float2 tex = (projPos.xy)* 0.5f + 0.5f;210 float2 tex = projPos.xy * 0.5f + 0.5f; 218 211 219 212 // retrieve the sample from the last frame … … 221 214 float4 oldIllum = tex2D(oldIllumTex, tex); 222 215 223 const float oldDepth = oldSsao.w; 224 const float depthDif = 1.0f - projDepth / oldDepth; 225 226 float oldWeight = clamp(oldSsao.z, 0, temporalCoherence); 216 const float oldDepth = oldSsao.z; 217 //const float depthDif = 1.0f - projDepth / oldDepth; 218 const float depthDif = projDepth - oldDepth; 219 220 float oldWeight = clamp(oldSsao.y, 0, temporalCoherence); 227 221 228 222 float newWeight; 229 223 230 224 //const float oldNumSamples = oldSsao.y; 231 //const float oldAvgDepth = oldSsao.z; 232 225 233 226 if (//(temporalCoherence > 0.0f) && 234 227 (tex.x >= 0.0f) && (tex.x < 1.0f) && … … 241 234 newWeight = oldWeight + 1; 242 235 243 OUT.ssao_col.x y = (gi.ao + oldSsao.xy* oldWeight) / newWeight;236 OUT.ssao_col.x = (gi.ao + oldSsao.x * oldWeight) / newWeight; 244 237 OUT.illum_col.xyz = (gi.illum + oldIllum.xyz * oldWeight) / newWeight; 245 238 } … … 248 241 newWeight = 0; 249 242 250 OUT.ssao_col.x y = gi.ao.xy;243 OUT.ssao_col.x = gi.ao.x; 251 244 OUT.illum_col.xyz = gi.illum; 252 245 } 253 246 254 OUT.ssao_col. z= newWeight;255 OUT.ssao_col. w= currentDepth;247 OUT.ssao_col.y = newWeight; 248 OUT.ssao_col.z = currentDepth; 256 249 257 250 return OUT; -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/mrt.cg
r3016 r3017 17 17 float4 worldPos: TEXCOORD1; // world position 18 18 float3 normal: TEXCOORD2; 19 float4 mypos: TEXCOORD3;19 float4 projPos: TEXCOORD3; 20 20 }; 21 21 … … 28 28 float4 texCoord: TEXCOORD0; 29 29 30 float4 projPos: WPOS;30 float4 winPos: WPOS; 31 31 float4 worldPos: TEXCOORD1; // world position 32 32 float3 normal: TEXCOORD2; 33 float4 mypos: TEXCOORD3;33 float4 projPos: TEXCOORD3; 34 34 }; 35 35 … … 38 38 { 39 39 float4 col: COLOR0; 40 float 4norm: COLOR1;40 float3 norm: COLOR1; 41 41 float3 pos: COLOR2; 42 42 }; … … 59 59 60 60 OUT.normal = IN.normal; 61 OUT. mypos = OUT.position;61 OUT.projPos = OUT.position; 62 62 63 63 return OUT; … … 75 75 } 76 76 77 //#pragma position_invariant fragtex 77 78 78 79 pixel fragtex(fragin IN, … … 96 97 // hack: use combination of emmisive + diffuse (emmisive used as constant ambient term) 97 98 pix.col = (glstate.material.emission + glstate.material.diffuse) * texColor; 98 // save world space normal in third rt 99 pix.norm.xyz = IN.normal; 100 // store projection coordinates with positions (used for ssao) 101 pix.norm.w = IN.projPos.w; 99 // save world space normal in rt 100 pix.norm = IN.normal; 102 101 103 const float4 projPos = IN.mypos / IN.mypos.w;104 105 102 // hack: squeeze some information about ambient into the texture 106 103 //pix.col.w = glstate.material.emission.x; 107 104 108 105 // compute eye linear depth 109 const float 2 screenCoord = projPos.xy * 0.5f + 0.5f;110 const float magView = length(Interpol(screenCoord, bl, br, tl, tr));111 pix.col.w = length(eyePos - IN.worldPos.xyz) / magView;112 113 #if 0 114 // save world position in second render target115 pix.pos = IN.worldPos.xyz * maxDepth;116 #endif 106 const float4 projPos = IN.projPos / IN.projPos.w; 107 108 float2 screenCoord = projPos.xy * 0.5f + 0.5f; 109 110 const float3 viewVec = Interpol(screenCoord, bl, br, tl, tr); 111 const float invMagView = 1.0f / length(viewVec); 112 // note: has to done in this order, otherwise strange precision problems! 113 pix.col.w = invMagView * length(eyePos - IN.worldPos.xyz); 117 114 118 115 return pix; … … 132 129 pix.col = glstate.material.diffuse + glstate.material.emission; 133 130 134 pix.norm.xyz = IN.normal; 135 136 // store projection coordinates with positions (used for ssao) 137 pix.norm.w = IN.mypos.w; 138 139 const float4 projPos = IN.mypos / IN.mypos.w; 131 pix.norm = IN.normal; 140 132 141 133 // hack: squeeze some information about the ambient term into the target … … 143 135 144 136 // compute eye linear depth and scale with lenght to avoid sqr root in pixel shader 137 const float4 projPos = IN.projPos / IN.projPos.w; 138 145 139 float2 screenCoord = projPos.xy * 0.5f + 0.5f; 146 140 const float magView = length(Interpol(screenCoord, bl, br, tl, tr)); 147 pix.col.w = length(eyePos - IN.worldPos.xyz) / magView; 148 149 #if 0 150 pix.pos = IN.worldPos.xyz * maxDepth; 151 #endif 141 pix.col.w = length(eyePos - IN.worldPos.xyz) / magView; 152 142 153 143 return pix; -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/ssao.cg
r3016 r3017 11 11 struct fragment 12 12 { 13 // normalized screen position14 float4 pos: WPOS;15 13 float2 texCoord: TEXCOORD0; 16 14 float3 view: TEXCOORD1; … … 46 44 47 45 // reconstruct world space position 48 inline float3 ReconstructSamplePosition( 49 uniform sampler2D colors, 50 float2 texcoord, 51 float3 bl, float3 br, float3 tl, float3 tr) 52 { 53 #if USE_EYE_SPACE_DEPTH 54 float eyeSpaceDepth = tex2Dlod(colors, float4(texcoord, 0, 0)).w; 55 //float3 rotView = normalize(Interpol(texcoord, bl, br, tl, tr)); 56 float3 rotView = Interpol(texcoord, bl, br, tl, tr); 57 58 float3 samplePos = -rotView * eyeSpaceDepth; 59 #else 60 float3 samplePos = tex2Dlod(colors, float4(texcoord, 0, SSAO_MIPMAP_LEVEL)).xyz; 61 #endif 46 inline float3 ReconstructSamplePos(uniform sampler2D colors, 47 float2 texcoord, 48 float3 bl, float3 br, float3 tl, float3 tr) 49 { 50 const float eyeSpaceDepth = tex2Dlod(colors, float4(texcoord, 0, 0)).w; 51 float3 viewVec = Interpol(texcoord, bl, br, tl, tr); 52 float3 samplePos = -viewVec * eyeSpaceDepth; 53 62 54 return samplePos; 63 55 } … … 76 68 uniform float3 br, 77 69 uniform float3 tl, 78 uniform float3 tr 79 //,uniform float3 viewDir70 uniform float3 tr, 71 uniform float3 viewDir 80 72 ) 81 73 { … … 96 88 // add random noise: reflect around random normal vector (warning: slow!) 97 89 98 float2 mynoise = tex2D(noiseTexture, IN.texCoord .xy).xy;90 float2 mynoise = tex2D(noiseTexture, IN.texCoord).xy; 99 91 const float2 offsetTransformed = myreflect(offset, mynoise); 100 92 #else … … 102 94 #endif 103 95 // weight with projected coordinate to reach similar kernel size for near and far 104 float2 texcoord = IN.texCoord.xy + offsetTransformed * AREA_SIZE *scaleFactor;96 float2 texcoord = IN.texCoord.xy + offsetTransformed * scaleFactor; 105 97 106 98 //if ((texcoord.x <= 1.0f) && (texcoord.x >= 0.0f) && (texcoord.y <= 1.0f) && (texcoord.y >= 0.0f))++ numSamples; 107 99 108 float3 samplePos = ReconstructSamplePosition(colors, texcoord, bl, br, tl, tr);109 110 111 /////// 112 //-- compute contribution of current sample taking into accountdirection and angle113 114 float3 dirSample = samplePos - centerPosition .xyz;100 const float3 samplePos = ReconstructSamplePos(colors, texcoord, bl, br, tl, tr); 101 102 103 //////////////// 104 //-- compute contribution of sample using the direction and angle 105 106 float3 dirSample = samplePos - centerPosition; 115 107 const float lengthSample = length(dirSample); 116 108 … … 118 110 119 111 // angle between current normal and direction to sample controls AO intensity. 120 const float cos _angle = max(dot(nDirSample, currentNormal), 0.0f);112 const float cosAngle = max(dot(nDirSample, currentNormal), 0.0f); 121 113 122 114 // the distance_scale offset is used to avoid singularity that occurs at global illumination when 123 115 // the distance to a sample approaches zero 124 const float intensity = 125 //(SAMPLE_INTENSITY * DISTANCE_SCALE) / (DISTANCE_SCALE + lengthSample * lengthSample); 126 SAMPLE_INTENSITY / (DISTANCE_SCALE + lengthSample * lengthSample); 127 128 #if 0 116 const float intensity = SAMPLE_INTENSITY / (DISTANCE_SCALE + lengthSample * lengthSample); 117 118 #if 1 129 119 // if surface normal perpenticular to view dir, approx. half of the samples will not count 130 120 // => compensate for this (on the other hand, projected sampling area could be larger!) 131 const float viewCorrection = 1.0f + VIEW_CORRECTION_SCALE * (1.0f - dot(currentViewDir, currentNormal)); 132 total_ao += cos_angle * intensity * viewCorrection; 121 const float viewCorrection = 1.0f + VIEW_CORRECTION_SCALE * dot(viewDir, currentNormal); 122 total_ao += cosAngle * intensity * viewCorrection; 123 #else 124 total_ao += cosAngle * intensity; 133 125 #endif 134 total_ao += cos_angle * intensity;135 126 } 136 127 … … 138 129 } 139 130 131 #pragma position_invariant main 140 132 141 133 /** The mrt shader for screen space ambient occlusion … … 143 135 pixel main(fragment IN, 144 136 uniform sampler2D colors, 145 uniform sampler2D positions,146 137 uniform sampler2D normals, 147 138 uniform sampler2D noiseTexture, … … 161 152 162 153 float4 norm = tex2Dlod(normals, float4(IN.texCoord, 0 ,0)); 163 float3 normal = normalize(norm.xyz); 164 165 // the w coordinate from the persp. projection 166 float w = norm.w; 167 168 169 #if USE_EYE_SPACE_DEPTH 154 const float3 normal = normalize(norm.xyz); 155 170 156 /// reconstruct position from the eye space depth 171 157 float3 viewDir = IN.view; 172 158 const float eyeDepth = tex2Dlod(colors, float4(IN.texCoord, 0, 0)).w; 173 174 159 const float3 eyeSpacePos = -viewDir * eyeDepth; 175 176 float3 centerPosition; 177 centerPosition.xyz = eyePos + eyeSpacePos; 178 179 const float2 ao = ssao(IN, colors, noiseTexture, samples, normal, eyeSpacePos, w, bl, br, tl, tr); 180 181 #else 182 183 // the current world position 184 const float3 centerPosition = tex2Dlod(positions, float4(IN.texCoord, 0, 0)).xyz; 185 186 const float2 ao = ssao(IN, positions, noiseTexture, samples, normal, centerPosition, w, bl, br, tl, tr); 187 188 #endif 160 const float3 centerPosition = eyePos + eyeSpacePos; 161 162 float4 realPos = float4(centerPosition, 1.0f); 163 164 165 //////////////// 166 //-- calculcate the current projected depth for next frame 167 168 float4 currentPos = mul(modelViewProj, realPos); 169 170 const float w = SAMPLE_RADIUS / currentPos.w; 171 currentPos /= currentPos.w; 172 173 const float currentDepth = currentPos.z * 1e-3f; 174 175 const float2 ao = ssao(IN, colors, noiseTexture, samples, normal, eyeSpacePos, w, bl, br, tl, tr, normalize(viewDir)); 176 189 177 190 178 ///////////////// 191 179 //-- compute temporally smoothing 192 180 193 float4 realPos = float4(centerPosition, 1.0f); 194 195 196 // calculcate the current projected depth for next frame 197 float4 currentPos = mul(modelViewProj, realPos); 198 currentPos /= currentPos.w; 199 const float currentDepth = currentPos.z; 200 201 202 /////////// 203 //-- reprojection new frame into old one 181 182 // reproject new frame into old one 204 183 205 184 // calculate projected depth … … 208 187 209 188 // the current depth projected into the old frame 210 const float projDepth = projPos.z ;189 const float projDepth = projPos.z * 1e-3f; 211 190 212 191 // fit from unit cube into 0 .. 1 213 float2 tex = (projPos.xy)* 0.5f + 0.5f;192 const float2 tex = projPos.xy * 0.5f + 0.5f; 214 193 215 194 // retrieve the sample from the last frame 216 195 float4 oldCol = tex2D(oldTex, tex); 217 196 218 const float oldDepth = oldCol.w; 219 const float depthDif = 1.0f - projDepth / oldDepth; 197 const float oldDepth = oldCol.z; 198 //const float depthDif = 1.0f - projDepth / oldDepth; 199 const float depthDif = projDepth - oldDepth; 220 200 221 201 222 202 //const float oldNumSamples = oldCol.y; 223 const float oldWeight = clamp(oldCol. z, 0, temporalCoherence);203 const float oldWeight = clamp(oldCol.y, 0, temporalCoherence); 224 204 225 205 float newWeight; … … 227 207 // the number of valid samples in this frame 228 208 //const float newNumSamples = ao.y; 229 230 209 231 210 if (//(temporalCoherence > 0) && … … 239 218 // increase the weight for convergence 240 219 newWeight = oldWeight + 1.0f; 241 OUT.illum_col.x y = (ao.xy + oldCol.xy* oldWeight) / newWeight;220 OUT.illum_col.x = (ao.x + oldCol.x * oldWeight) / newWeight; 242 221 //if (!(oldNumSamples > ao.y - 1.5f)) newWeight = 0; 243 222 } 244 223 else 245 224 { 246 OUT.illum_col.x y = ao.xy;225 OUT.illum_col.x = ao.x; 247 226 newWeight = 0; 248 227 } 249 228 250 OUT.illum_col.z = newWeight; 251 OUT.illum_col.w = currentDepth; 229 //OUT.illum_col.y=depthDif; 230 OUT.illum_col.y = newWeight; 231 OUT.illum_col.z = currentDepth; 252 232 253 233 return OUT; 234 } 235 236 237 float Filter(float2 texCoord, 238 uniform sampler2D ssaoTex, 239 uniform float2 filterOffs[NUM_DOWNSAMPLES], 240 uniform float filterWeights[NUM_DOWNSAMPLES] 241 ) 242 { 243 float average = .0f; 244 float w = .0f; 245 246 for (int i = 0; i < NUM_DOWNSAMPLES; ++ i) 247 { 248 average += filterWeights[i] * tex2Dlod(ssaoTex, float4(texCoord + filterOffs[i], 0, 0)).x; 249 w += filterWeights[i]; 250 } 251 252 average *= 1.0f / (float)w; 253 254 return average; 254 255 } 255 256 … … 257 258 pixel combine(fragment IN, 258 259 uniform sampler2D colors, 259 uniform sampler2D ssaoTex) 260 uniform sampler2D ssaoTex, 261 uniform float2 filterOffs[NUM_DOWNSAMPLES], 262 uniform float filterWeights[NUM_DOWNSAMPLES] 263 ) 260 264 { 261 265 pixel OUT; 262 266 263 267 float4 col = tex2Dlod(colors, float4(IN.texCoord, 0, 0)); 264 float4 ao = tex2Dlod(ssaoTex, float4(IN.texCoord, 0, 0)); 268 float3 ao = tex2Dlod(ssaoTex, float4(IN.texCoord, 0, 0)); 269 270 if (ao.y < 2000.0f) 271 ao.x = Filter(IN.texCoord, ssaoTex, filterOffs, filterWeights); 265 272 266 273 OUT.illum_col = col * ao.x; 267 //OUT.illum_col = float4(ao.x,ao.x,ao.x, ao.w);274 //OUT.illum_col.xyz = float3(ao.x,1-ao.y*1e-2f, 0); 268 275 OUT.illum_col.w = col.w; 269 276 -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/ssao3d.cg
r3010 r3017 64 64 65 65 float3 mynoise = (float3)tex2D(noiseTexture, IN.texCoord.xy); 66 const float3 offsetTransformed = myreflect(offset, mynoise) * AREA_SIZE;67 //const float3 offsetTransformed = offset * AREA_SIZE;66 const float3 offsetTransformed = myreflect(offset, mynoise) * SAMPLE_RADIUS; 67 //const float3 offsetTransformed = offset * SAMPLE_RADIUS; 68 68 69 69 // compute position -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/tonemap.cg
r3016 r3017 46 46 return average; 47 47 }*/ 48 48 49 50 // let bilinear filtering do its work 49 51 float4 DownSample(frag IN, 50 52 uniform sampler2D colors,
Note: See TracChangeset
for help on using the changeset viewer.