Changeset 3025
- Timestamp:
- 10/12/08 11:46:50 (16 years ago)
- Location:
- GTP/trunk/App/Demos/Vis/FriendlyCulling
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/App/Demos/Vis/FriendlyCulling/FriendlyCulling.vcproj
r3021 r3025 244 244 </File> 245 245 <File 246 RelativePath=".\src\ShaderProgram.cpp" 247 > 248 </File> 249 <File 246 250 RelativePath=".\src\ShaderProgram.h" 247 251 > -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/DeferredRenderer.cpp
r3021 r3025 66 66 static CGparameter sFilterOffsetsParam; 67 67 static CGparameter sFilterWeightsParam; 68 static CGparameter sPCFFilterWeightsParam; 68 69 69 70 static CGprogram sCgDownSampleProgram; … … 174 175 175 176 int DeferredRenderer::colorBufferIdx = 0; 177 178 179 180 static float GaussianDistribution(float x, float y, float rho) 181 { 182 float g = 1.0f / sqrtf(2.0f * M_PI * rho * rho); 183 g *= expf( -(x*x + y*y) / (2.0f * rho * rho)); 184 185 return g; 186 } 176 187 177 188 … … 380 391 ShaderProgram *pr; 381 392 382 383 393 sCgDeferredProgram = 384 394 cgCreateProgramFromFile(context, … … 583 593 sEyePosShadowParam = cgGetNamedParameter(sCgDeferredShadowProgram, "eyePos"); 584 594 595 float filterWeights[NUM_PCF_TABS]; 596 597 sPCFFilterWeightsParam = cgGetNamedParameter(sCgDeferredShadowProgram, "weights"); 598 585 599 PoissonDiscSampleGenerator2 poisson(NUM_PCF_TABS, 1.0f); 586 600 poisson.Generate((float *)pcfSamples); 587 601 602 603 for (int i = 0; i < NUM_PCF_TABS; ++ i) 604 { 605 filterWeights[i] = GaussianDistribution(pcfSamples[i].x, pcfSamples[i].y, 1.0f); 606 } 607 588 608 cgGLSetParameterArray2f(sSamplesShadowParam, 0, NUM_PCF_TABS, (const float *)pcfSamples); 609 cgGLSetParameterArray1f(sPCFFilterWeightsParam, 0, NUM_PCF_TABS, (const float *)filterWeights); 589 610 590 611 pr = new ShaderProgram(sCgDeferredShadowProgram); … … 777 798 #endif 778 799 779 780 800 cgGLSetMatrixParameterfc(sOldModelViewProjMatrixParam, (const float *)oldProjViewMatrix.x); 781 801 #if 0 … … 1129 1149 1130 1150 1131 static float GaussianDistribution(float x, float y, float rho)1132 {1133 float g = 1.0f / sqrtf(2.0f * M_PI * rho * rho);1134 g *= expf( -(x*x + y*y) / (2.0f * rho * rho));1135 1136 return g;1137 }1138 1139 1140 1151 void DeferredRenderer::CombineSsao(FrameBufferObject *fbo) 1141 1152 { … … 1238 1249 1239 1250 cgGLSetParameter1f(sSampleWidthParam, 2.0f / shadowMap->GetSize()); 1240 1251 1241 1252 1242 1253 cgGLSetMatrixParameterfc(sShadowMatrixParam, (const float *)shadowMatrix.x); … … 1441 1452 1442 1453 fbo->Bind(); 1443 #if 1 1454 1444 1455 colorBufferIdx = 3 - colorBufferIdx; 1445 1456 glDrawBuffers(1, mrt + colorBufferIdx); … … 1468 1479 1469 1480 glEnd(); 1470 #endif1471 1481 1472 1482 cgGLDisableTextureParameter(sColorsTexToneParam); -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ShaderProgram.h
r3021 r3025 7 7 #include <Cg/cg.h> 8 8 #include <Cg/cgGL.h> 9 #include <string> 10 #include <map> 9 11 10 12 … … 19 21 class DirectionalLight; 20 22 23 typedef std::map<std::string, CGparameter> CGParameterMap; 24 typedef std::vector<CGparameter> CGParameterArray; 25 21 26 22 27 class ShaderProgram … … 26 31 ShaderProgram(CGprogram program): mProgram(program) {} 27 32 28 ~ShaderProgram() { cgDestroyProgram(mProgram); } 33 ShaderProgram(CGcontext context, 34 const std::string &filename, 35 CGprofile profile, 36 const std::string &functionName); 37 38 ~ShaderProgram() { if (mProgram != NULL) cgDestroyProgram(mProgram); } 39 40 void SetValue1f(const std::string &name, float value); 41 void SetValue2f(const std::string &name, float val1, float val2); 42 void SetValue3f(const std::string &name, float val1, float val, float val3); 43 44 void SetArray1f(const std::string &name, float *vals, int numElements); 45 void SetArray2f(const std::string &name, float *vals, int numElements); 46 void SetArray3f(const std::string &name, float *vals, int numElements); 47 48 void SetMatrix(const std::string &name, const Matrix4x4 &mat); 49 50 void SetTexture(const std::string &name, unsigned int tex); 51 52 void Release(); 53 54 void Bind(); 55 56 inline bool IsValid() { return mProgram != NULL; } 57 58 59 protected: 60 61 CGparameter GetOrCreateParameter(const std::string &name); 62 63 CGParameterMap mParamHash; 64 //CGParameterArray mParameters; 65 66 CGParameterArray mTextureParams; 29 67 30 68 CGprogram mProgram; 31 69 }; 70 32 71 33 72 typedef std::vector<ShaderProgram *> ShaderContainer; -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/deferred.cg
r3024 r3025 91 91 float CalcShadowTerm(fragment IN, 92 92 uniform sampler2D shadowMap, 93 uniform float w,93 uniform float scale, 94 94 uniform float2 lightSpacePos, 95 95 uniform float depth, 96 96 uniform float2 samples[NUM_PCF_TABS], 97 uniform float weights[NUM_PCF_TABS], 97 98 uniform sampler2D noiseTexture 98 99 ) … … 101 102 //return step(depth, shadowDepth); 102 103 103 float total_d = 0.0; 104 104 float total_d = .0f; 105 float total_w = .0f; 106 105 107 for (int i = 0; i < NUM_PCF_TABS; ++ i) 106 108 { 107 109 const float2 offset = samples[i]; 110 const float w = weights[i]; 108 111 109 112 #if 1 … … 117 120 #endif 118 121 // weight with projected coordinate to reach similar kernel size for near and far 119 float2 texcoord = lightSpacePos + offsetTransformed * w;122 float2 texcoord = lightSpacePos + offsetTransformed * scale; 120 123 121 124 float shadowDepth = tex2D(shadowMap, texcoord).x; 122 125 123 total_d += step(depth, shadowDepth); 126 total_d += w * step(depth, shadowDepth); 127 total_w += w; 124 128 } 125 129 126 total_d /= (float) NUM_PCF_TABS;130 total_d /= (float)total_w; 127 131 128 132 return total_d; 129 133 } 134 130 135 131 136 inline float3 Interpol(float2 w, float3 bl, float3 br, float3 tl, float3 tr) … … 195 200 196 201 float shadowTerm = CalcShadowTerm(IN, shadowMap, sampleWidth, lightSpacePos.xy, lightSpacePos.z, samples, weights, noiseTexture); 202 //float shadowTerm = CalcShadowTerm(IN, shadowMap, sampleWidth, lightSpacePos.xy, lightSpacePos.z, samples, noiseTexture); 197 203 198 204 diffuse *= shadowTerm;
Note: See TracChangeset
for help on using the changeset viewer.