- Timestamp:
- 08/27/08 15:09:04 (16 years ago)
- Location:
- GTP/trunk/App/Demos/Vis/FriendlyCulling
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/App/Demos/Vis/FriendlyCulling/FriendlyCulling.vcproj
r2869 r2873 792 792 </File> 793 793 <File 794 RelativePath=".\src\shaders\globillum.cg" 795 > 796 </File> 797 <File 794 798 RelativePath=".\src\shaders\mrt.cg" 795 799 > -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/SampleGenerator.cpp
r2865 r2873 19 19 void PoissonDiscSampleGenerator::Generate(Sample2 *samples) const 20 20 { 21 // this is a hacky poisson sampling generator which does random dart-throwing 22 // until it is not able to place any dart for a number of tries 23 // in this case, the required min distance is reduced 24 // the solution is a possion sampling with respect to the adjusted min distance 25 // better solutions have been proposed, i.e., using hierarchical sampling 26 27 const float maxTries = 1000; 28 const float f_reduction = 0.9f; 29 21 30 static HaltonSequence halton; 22 31 float r[2]; 23 32 24 33 // generates poisson distribution on disc 25 float minDist = 4.0f / sqrt((float)mNumSamples);34 float minDist = 2.0f / sqrt((float)mNumSamples); 26 35 27 36 //cout << "minDist before= " << minDist << endl; … … 66 75 } 67 76 68 if (tries > 2000)77 if (tries > maxTries) 69 78 { 70 minDist *= 0.9f;79 minDist *= f_reduction; 71 80 tries = 0; 72 81 } -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/SsaoShader.cpp
r2871 r2873 15 15 16 16 // number of ssao samples 17 #define NUM_SAMPLES 1 617 #define NUM_SAMPLES 10 18 18 19 19 20 20 static CGprogram sCgSsaoProgram = NULL; 21 static CGprogram sCgDeferredProgram2 = NULL; 21 static CGprogram sCgGiProgram = NULL; 22 23 static CGprogram sCgDeferredProgram = NULL; 22 24 static CGprogram sCgAntiAliasingProgram = NULL; 23 25 static CGprogram sCgCombineProgram = NULL; … … 30 32 static CGparameter sNormalsTexDeferredParam; 31 33 34 35 ///////////////////////////////////////7 36 37 32 38 static CGparameter sColorsTexParam; 33 39 static CGparameter sPositionsTexParam; 34 40 static CGparameter sNormalsTexParam; 35 36 41 37 42 static CGparameter sOldModelViewProjMatrixParam; … … 43 48 static CGparameter sExpFactorParam; 44 49 50 51 /////////////////////////////////////// 52 53 54 static CGparameter sColorsTexGiParam; 55 static CGparameter sPositionsTexGiParam; 56 static CGparameter sNormalsTexGiParam; 57 58 59 static CGparameter sOldModelViewProjMatrixGiParam; 60 static CGparameter sMaxDepthGiParam; 61 static CGparameter sSamplesGiParam; 62 static CGparameter sOldSsaoTexGiParam; 63 static CGparameter sOldIllumTexGiParam; 64 static CGparameter sNoiseTexGiParam; 65 static CGparameter sNoiseMultiplierGiParam; 66 static CGparameter sExpFactorGiParam; 67 68 69 //////////// 70 45 71 static CGparameter sColorsTexAntiAliasingParam; 46 72 static CGparameter sNormalsTexAntiAliasingParam; … … 88 114 mNewFbo->AddColorBuffer(ColorBufferObject::BUFFER_FLOAT_32, ColorBufferObject::WRAP_CLAMP_TO_EDGE, ColorBufferObject::FILTER_LINEAR, false); 89 115 mNewFbo->AddColorBuffer(ColorBufferObject::BUFFER_FLOAT_32, ColorBufferObject::WRAP_CLAMP_TO_EDGE, ColorBufferObject::FILTER_LINEAR, false); 116 mNewFbo->AddColorBuffer(ColorBufferObject::BUFFER_FLOAT_32, ColorBufferObject::WRAP_CLAMP_TO_EDGE, ColorBufferObject::FILTER_LINEAR, false); 90 117 91 118 mOldFbo = new FrameBufferObject(w, h, FrameBufferObject::DEPTH_NONE); … … 93 120 mOldFbo->AddColorBuffer(ColorBufferObject::BUFFER_FLOAT_32, ColorBufferObject::WRAP_CLAMP_TO_EDGE, ColorBufferObject::FILTER_LINEAR, false); 94 121 mOldFbo->AddColorBuffer(ColorBufferObject::BUFFER_FLOAT_32, ColorBufferObject::WRAP_CLAMP_TO_EDGE, ColorBufferObject::FILTER_LINEAR, false); 122 mOldFbo->AddColorBuffer(ColorBufferObject::BUFFER_FLOAT_32, ColorBufferObject::WRAP_CLAMP_TO_EDGE, ColorBufferObject::FILTER_LINEAR, false); 95 123 96 124 mFbo3 = new FrameBufferObject(w, h, FrameBufferObject::DEPTH_NONE); … … 98 126 mFbo3->AddColorBuffer(ColorBufferObject::BUFFER_FLOAT_32, ColorBufferObject::WRAP_CLAMP_TO_EDGE, ColorBufferObject::FILTER_LINEAR, false); 99 127 100 mFbo4 = new FrameBufferObject(w, h, FrameBufferObject::DEPTH_NONE);101 // the diffuse color buffer102 mFbo4->AddColorBuffer(ColorBufferObject::BUFFER_FLOAT_32, ColorBufferObject::WRAP_CLAMP_TO_EDGE, ColorBufferObject::FILTER_LINEAR, false);103 128 104 129 // create noise texture for ssao … … 121 146 void SsaoShader::Init(CGcontext context) 122 147 { 123 sCgDeferredProgram 2=148 sCgDeferredProgram = 124 149 cgCreateProgramFromFile(context, 125 150 CG_SOURCE, 126 151 "src/shaders/deferred.cg", 127 152 RenderState::sCgFragmentProfile, 128 "main 2",153 "main", 129 154 NULL); 130 155 131 if (sCgDeferredProgram 2!= NULL)132 { 133 cgGLLoadProgram(sCgDeferredProgram 2);156 if (sCgDeferredProgram != NULL) 157 { 158 cgGLLoadProgram(sCgDeferredProgram); 134 159 135 160 // we need size of texture for scaling 136 sPositionsTexDeferredParam = cgGetNamedParameter(sCgDeferredProgram 2, "positions");137 sColorsTexDeferredParam = cgGetNamedParameter(sCgDeferredProgram 2, "colors");138 sNormalsTexDeferredParam = cgGetNamedParameter(sCgDeferredProgram 2, "normals");161 sPositionsTexDeferredParam = cgGetNamedParameter(sCgDeferredProgram, "positions"); 162 sColorsTexDeferredParam = cgGetNamedParameter(sCgDeferredProgram, "colors"); 163 sNormalsTexDeferredParam = cgGetNamedParameter(sCgDeferredProgram, "normals"); 139 164 } 140 165 else 141 166 cerr << "deferred program failed to load" << endl; 142 167 143 144 /*sCgCombineProgram =145 cgCreateProgramFromFile(context,146 CG_SOURCE,147 "src/shaders/ssao.cg",148 RenderState::sCgFragmentProfile,149 "combined",150 NULL);151 152 if (sCgCombineProgram != NULL)153 {154 cgGLLoadProgram(sCgCombineProgram);155 156 // we need size of texture for scaling157 sColorsTexCombineParam = cgGetNamedParameter(sCgCombineProgram, "colors");158 sSsaoTexCombineParam = cgGetNamedParameter(sCgCombineProgram, "ssaoTex");159 }160 else161 cerr << "combined program failed to load" << endl;162 */163 168 164 169 /////////////// … … 189 194 sSamplesParam = cgGetNamedParameter(sCgSsaoProgram, "samples"); 190 195 sOldTexParam = cgGetNamedParameter(sCgSsaoProgram, "oldTex"); 196 191 197 192 198 // generate samples for ssao kernel … … 196 202 else 197 203 cerr << "ssao program failed to load" << endl; 204 205 sCgGiProgram = 206 cgCreateProgramFromFile(context, 207 CG_SOURCE, 208 "src/shaders/globillum.cg", 209 RenderState::sCgFragmentProfile, 210 "main", 211 NULL); 212 213 if (sCgGiProgram != NULL) 214 { 215 cgGLLoadProgram(sCgGiProgram); 216 217 // we need size of texture for scaling 218 sPositionsTexGiParam = cgGetNamedParameter(sCgGiProgram, "positions"); 219 sColorsTexGiParam = cgGetNamedParameter(sCgGiProgram, "colors"); 220 sNormalsTexGiParam = cgGetNamedParameter(sCgGiProgram, "normals"); 221 sNoiseTexGiParam = cgGetNamedParameter(sCgGiProgram, "noiseTexture"); 222 sNoiseMultiplierGiParam = cgGetNamedParameter(sCgGiProgram, "noiseMultiplier"); 223 224 sOldModelViewProjMatrixParam = cgGetNamedParameter(sCgGiProgram, "oldModelViewProj"); 225 sMaxDepthGiParam = cgGetNamedParameter(sCgGiProgram, "maxDepth"); 226 sExpFactorGiParam = cgGetNamedParameter(sCgGiProgram, "expFactor"); 227 228 sSamplesGiParam = cgGetNamedParameter(sCgGiProgram, "samples"); 229 230 sOldSsaoTexGiParam = cgGetNamedParameter(sCgGiProgram, "oldSsaoTex"); 231 sOldIllumTexGiParam = cgGetNamedParameter(sCgGiProgram, "oldIllumTex"); 232 233 // generate samples for ssao kernel 234 GenerateSamples(); 235 cgGLSetParameterArray2f(sSamplesGiParam, 0, NUM_SAMPLES, (const float *)samples); 236 } 237 else 238 cerr << "globillum program failed to load" << endl; 198 239 199 240 sCgAntiAliasingProgram = … … 258 299 259 300 FirstPass(fbo); 301 260 302 ComputeSsao(fbo, expFactor); 303 //ComputeGlobIllum(fbo, expFactor); 304 261 305 //Combine(fbo); 262 306 AntiAliasing(fbo); … … 323 367 324 368 325 //GenerateSamples(); 369 // q: should we generate new samples or only rotate the old ones? 370 // in the first case, the sample patterns look nicer, but the kernel 371 // needs longer to converge 372 GenerateSamples(); 326 373 cgGLSetParameterArray2f(sSamplesParam, 0, NUM_SAMPLES, (const float *)samples); 327 374 … … 499 546 cgGLEnableProfile(RenderState::sCgFragmentProfile); 500 547 501 cgGLBindProgram(sCgDeferredProgram 2);548 cgGLBindProgram(sCgDeferredProgram); 502 549 503 550 cgGLSetTextureParameter(sColorsTexDeferredParam, colorsTex); … … 535 582 536 583 537 void SsaoShader::Com bine(FrameBufferObject *fbo)584 void SsaoShader::ComputeGlobIllum(FrameBufferObject *fbo, float expFactor) 538 585 { 539 586 GLuint colorsTex = mFbo3->GetColorBuffer(0)->GetTexture(); 540 GLuint ssaoTex = mNewFbo->GetColorBuffer(0)->GetTexture(); 541 542 mFbo4->Bind(); 543 //mNewFbo->Bind(); 587 GLuint positionsTex = fbo->GetColorBuffer(1)->GetTexture(); 588 GLuint normalsTex = fbo->GetColorBuffer(2)->GetTexture(); 589 590 if (1) 591 { 592 // generate mip map levels for position texture 593 glBindTexture(GL_TEXTURE_2D, positionsTex); 594 glGenerateMipmapEXT(GL_TEXTURE_2D); 595 596 // generate mip map levels for position texture 597 glBindTexture(GL_TEXTURE_2D, colorsTex); 598 glGenerateMipmapEXT(GL_TEXTURE_2D); 599 } 600 601 602 // read the second buffer, write to the first buffer 603 mNewFbo->Bind(); 604 glDrawBuffers(3, mymrt); 605 606 GLuint oldSsaoTex = mOldFbo->GetColorBuffer(0)->GetTexture(); 607 GLuint oldIllumTex = mOldFbo->GetColorBuffer(2)->GetTexture(); 544 608 545 609 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 546 547 glDrawBuffers(1, mymrt);548 610 549 611 cgGLEnableProfile(RenderState::sCgFragmentProfile); 550 551 cgGLBindProgram(sCgCombineProgram); 552 553 cgGLSetTextureParameter(sColorsTexCombineParam, colorsTex); 554 cgGLEnableTextureParameter(sColorsTexCombineParam); 555 556 cgGLSetTextureParameter(sSsaoTexCombineParam, ssaoTex); 557 cgGLEnableTextureParameter(sSsaoTexCombineParam); 612 cgGLBindProgram(sCgGiProgram); 613 614 cgGLSetTextureParameter(sPositionsTexGiParam, positionsTex); 615 cgGLEnableTextureParameter(sPositionsTexGiParam); 616 617 cgGLSetTextureParameter(sColorsTexGiParam, colorsTex); 618 cgGLEnableTextureParameter(sColorsTexGiParam); 619 620 cgGLSetTextureParameter(sNormalsTexGiParam, normalsTex); 621 cgGLEnableTextureParameter(sNormalsTexGiParam); 622 623 cgGLSetTextureParameter(sNoiseTexGiParam, noiseTex); 624 cgGLEnableTextureParameter(sNoiseTexGiParam); 625 626 cgGLSetTextureParameter(sOldSsaoTexGiParam, oldSsaoTex); 627 cgGLEnableTextureParameter(sOldSsaoTexGiParam); 628 629 cgGLSetTextureParameter(sOldIllumTexGiParam, oldIllumTex); 630 cgGLEnableTextureParameter(sOldIllumTexGiParam); 631 632 cgGLSetParameter1f(sNoiseMultiplierGiParam, RandomValue(3.0f, 17.0f)); 633 634 cgGLSetParameter1f(sMaxDepthGiParam, mScaleFactor); 635 cgGLSetParameter1f(sExpFactorGiParam, expFactor); 636 637 638 // q: should we generate new samples or only rotate the old ones? 639 // in the first case, the sample patterns look nicer, but the kernel 640 // needs longer to converge 641 GenerateSamples(); 642 cgGLSetParameterArray2f(sSamplesGiParam, 0, NUM_SAMPLES, (const float *)samples); 643 644 Vector3 tl, tr, bl, br; 645 ComputeViewVectors(tl, tr, bl, br); 558 646 559 647 glColor3f(1.0f, 1.0f, 1.0f); 560 648 561 const float offs = 0.5f;562 563 649 glBegin(GL_QUADS); 564 650 565 glTexCoord2f(0, 0); glVertex3f(-offs, -offs, -0.5f); 566 glTexCoord2f(1, 0); glVertex3f( offs, -offs, -0.5f); 567 glTexCoord2f(1, 1); glVertex3f( offs, offs, -0.5f); 568 glTexCoord2f(0, 1); glVertex3f(-offs, offs, -0.5f); 651 // note: slightly larger texture hides ambient occlusion error on border but costs resolution 652 //const float new_offs = 0.55f; 653 const float new_offs = 0.5f; 654 655 glColor3f(bl.x, bl.y, bl.z); glTexCoord2f(0, 0); glVertex3f(-new_offs, -new_offs, -0.5f); 656 glColor3f(br.x, br.y, br.z); glTexCoord2f(1, 0); glVertex3f( new_offs, -new_offs, -0.5f); 657 glColor3f(tr.x, tr.y, tr.z); glTexCoord2f(1, 1); glVertex3f( new_offs, new_offs, -0.5f); 658 glColor3f(tl.x, tl.y, tl.z); glTexCoord2f(0, 1); glVertex3f(-new_offs, new_offs, -0.5f); 569 659 570 660 glEnd(); 571 661 572 cgGLDisableTextureParameter(sColorsTexCombineParam); 573 cgGLDisableTextureParameter(sSsaoTexCombineParam); 574 575 cgGLDisableProfile(RenderState::sCgFragmentProfile); 662 cgGLDisableTextureParameter(sColorsTexGiParam); 663 cgGLDisableTextureParameter(sPositionsTexGiParam); 664 cgGLDisableTextureParameter(sNormalsTexGiParam); 665 cgGLDisableTextureParameter(sNoiseTexGiParam); 666 cgGLDisableTextureParameter(sOldSsaoTexGiParam); 667 cgGLDisableTextureParameter(sOldIllumTexGiParam); 576 668 577 669 FrameBufferObject::Release(); 578 670 579 PrintGLerror(" deferred shading");671 PrintGLerror("globillum first pass"); 580 672 } 581 673 -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/SsaoShader.h
r2869 r2873 50 50 void ComputeSsao(FrameBufferObject *fbo, float expFactor); 51 51 52 void ComputeGlobIllum(FrameBufferObject *fbo, float expFactor); 53 52 54 void FirstPass(FrameBufferObject *fbo); 53 55 54 56 void AntiAliasing(FrameBufferObject *fbo); 55 void Combine(FrameBufferObject *fbo);56 57 57 58 void CreateNoiseTex2D(); … … 72 73 FrameBufferObject *mNewFbo; 73 74 FrameBufferObject *mFbo3; 74 FrameBufferObject *mFbo4;75 75 }; 76 76 -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/chcdemo.cpp
r2868 r2873 274 274 Vector3 camDir(.0f, 1.0f, .0f); 275 275 276 cout << "=== reading environment file === "<< endl;276 cout << "=== reading environment file ===" << endl << endl; 277 277 278 278 string envFileName = "default.env"; … … 303 303 //env.GetIntParam(string("numSssaoSamples"), numSsaoSamples); 304 304 305 306 cout << "*********** parameters ***************" << endl;307 305 308 306 cout << "assumedVisibleFrames: " << assumedVisibleFrames << endl; … … 318 316 cout << "camPosition: " << camPos << endl; 319 317 cout << "expFactor: " << ssaoExpFactor << endl; 318 320 319 //cout << "model path: " << model_path << endl; 320 321 cout << "**** end parameters ****" << endl; 321 322 } 322 323 … … 538 539 539 540 // the diffuse color buffer 541 //fbo->AddColorBuffer(ColorBufferObject::BUFFER_FLOAT_32, ColorBufferObject::WRAP_CLAMP_TO_EDGE, ColorBufferObject::FILTER_MIPMAP_LINEAR, true); 540 542 fbo->AddColorBuffer(ColorBufferObject::BUFFER_FLOAT_32, ColorBufferObject::WRAP_CLAMP_TO_EDGE, ColorBufferObject::FILTER_NEAREST, false); 541 543 542 544 // the positions buffer 543 545 fbo->AddColorBuffer(ColorBufferObject::BUFFER_FLOAT_32, ColorBufferObject::WRAP_CLAMP_TO_EDGE, ColorBufferObject::FILTER_MIPMAP_LINEAR, true); 544 //fbo->AddColorBuffer(ColorBufferObject::BUFFER_FLOAT_32, ColorBufferObject::WRAP_CLAMP_TO_EDGE, ColorBufferObject::FILTER_NEAREST, true);546 //fbo->AddColorBuffer(ColorBufferObject::BUFFER_FLOAT_32, ColorBufferObject::WRAP_CLAMP_TO_EDGE, ColorBufferObject::FILTER_NEAREST, false); 545 547 546 548 // the normals buffer -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/deferred.cg
r2868 r2873 42 42 43 43 44 /** The mrt shader for standard rendering45 */46 pixel main2(fragment IN,47 uniform sampler2D colors,48 uniform sampler2D positions,49 uniform sampler2D normals50 )51 {52 pixel OUT;53 54 float4 norm = tex2D(normals, IN.texCoord.xy);55 float4 color = tex2D(colors, IN.texCoord.xy);56 float4 position = tex2D(positions, IN.texCoord.xy);57 58 // an ambient color term59 float amb = norm.w;60 61 // expand normal62 float3 normal = normalize(norm.xyz);// * 2.0f - float4(1.0f));63 64 float4 col = shade(IN, color, position, normal, amb);65 66 //OUT.color = float4(1.0f);67 OUT.color = col;68 OUT.color.w = color.w;69 70 return OUT;71 }72 44 73 45 /** The mrt shader for standard rendering -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/mrt.cg
r2867 r2873 101 101 102 102 pixel frag(fragin IN, 103 uniform float maxDepth, 104 uniform float4 ambient, 105 uniform float4 diffuse) 103 uniform float maxDepth, 104 uniform float4 ambient, 105 uniform float4 diffuse 106 ) 106 107 { 107 108 pixel pix; … … 109 110 pix.col = diffuse; 110 111 pix.pos = IN.worldPos * maxDepth; 112 111 113 //pix.norm.xyz = IN.normal * 0.5f + float3(0.5f); 112 114 pix.norm.xyz = IN.normal; 115 113 116 // hack: squeeze some information about the ambient term into the target 114 117 pix.norm.w = ambient.x; 115 118 pix.pos.w = IN.mypos.w; 119 120 // the projected depth 116 121 pix.col.w = IN.mypos.z / IN.mypos.w; 117 122 -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/ssao.cg
r2872 r2873 3 3 // based on shader of Alexander Kusternig 4 4 5 //#define NUM_SAMPLES 8 6 #define NUM_SAMPLES 165 #define NUM_SAMPLES 10 6 //#define NUM_SAMPLES 16 7 7 8 8 // rule of thumb: approx 1 / NUM_SAMPLES 9 #define SAMPLE_INTENSITY 0.15 10 //#define SAMPLE_INTENSITY 0.125f9 //#define SAMPLE_INTENSITY 0.15f 10 #define SAMPLE_INTENSITY 0.2f 11 11 12 12 #define AREA_SIZE 7e-1f … … 43 43 44 44 45 /*float2 rotate(float2 pt, float2 n)46 {47 float2 ptTransformed;48 ptTransformed.x = n.r * pt.x - n.g * pt.y;49 ptTransformed.y = n.g * pt.x + n.r * pt.y;50 51 return ptTransformed;52 }*/53 54 45 55 46 /** The ssao shader returning the an intensity value between 0 and 1 … … 74 65 float total_ao = 0.0; 75 66 76 const float areaSize = 5e-1f;77 78 67 for (int i = 0; i < NUM_SAMPLES; i ++) 79 68 { 80 69 float2 offset = samples[i]; 81 70 82 //sample noisetex; r stores costheta, g stores sintheta 71 //////////////////// 72 // add random noise: r stores costheta, g stores sintheta 73 83 74 //float2 mynoise = tex2D(noiseTexture, IN.texCoord.xy * noiseMultiplier).xy * 2.0f - 1.0f; 84 75 float2 mynoise = tex2D(noiseTexture, IN.texCoord.xy * noiseMultiplier).xy; 85 76 86 // rotation87 //float2 offsetTransformed = offset;88 //float2 offsetTransformed = rotate(offset, mynoise);89 77 float2 offsetTransformed = reflect(offset, mynoise); 90 78 … … 117 105 return max(0.0f, 1.0f - total_ao); 118 106 //return dot(currentViewDir, currentNormal); 119 }120 121 122 /** Computes ambient occlusion + diffuse reflections123 */124 float4 globIllum(fragment IN,125 uniform sampler2D colors,126 uniform sampler2D positions,127 uniform sampler2D noiseTexture,128 uniform float2 samples[NUM_SAMPLES],129 uniform float3 currentNormal,130 uniform float3 currentViewDir,131 uniform float noiseMultiplier,132 uniform float4 centerPosition133 )134 {135 // the w coordinate from the persp. projection136 float w = centerPosition.w;137 138 // Check in a circular area around the current position.139 // Shoot vectors to the positions there, and check the angle to these positions.140 // Summing up these angles gives an estimation of the occlusion at the current position.141 142 // ao is in stored in the w143 float4 total_color = float4(0, 0, 0, 1);144 145 const float areaSize = 5e-1f;146 147 for (int i = 0; i < NUM_SAMPLES; i ++)148 {149 float2 offset = samples[i];150 151 //sample noisetex; r stores costheta, g stores sintheta152 float2 mynoise = tex2D(noiseTexture, IN.texCoord.xy * noiseMultiplier).xy;153 154 // rotation155 float2 offsetTransformed = reflect(offset, mynoise);156 157 // weight with projected coordinate to reach similar kernel size for near and far158 float2 texcoord = IN.texCoord.xy + offsetTransformed * AREA_SIZE * w;159 160 float3 sample_position = tex2Dlod(positions, float4(texcoord, 0, 1)).xyz;161 float3 sample_color = tex2Dlod(colors, float4(texcoord, 0, 1)).xyz;162 163 float3 vector_to_sample = sample_position - centerPosition.xyz;164 float length_to_sample = length(vector_to_sample);165 float3 direction_to_sample = vector_to_sample / length_to_sample;166 167 // Angle between current normal and direction to sample controls AO intensity.168 float cos_angle = dot(direction_to_sample, currentNormal);169 cos_angle = max(cos_angle, 0.0f);170 171 // distance between current position and sample position controls AO intensity.172 float distance_intensity =173 (SAMPLE_INTENSITY * DISTANCE_SCALE) / (DISTANCE_SCALE + length_to_sample * length_to_sample);174 175 // if normal perpenticular to view dir, only half of the samples count176 float view_correction = 1.0f + VIEW_CORRECTION_SCALE * (1.0f - dot(currentViewDir, currentNormal));177 178 total_color.w -= cos_angle * distance_intensity * view_correction;179 180 const float scale_factor = 0.3f;181 total_color.xyz += cos_angle * distance_intensity * view_correction * sample_color * scale_factor;182 }183 184 return saturate(total_color);185 107 } 186 108 … … 220 142 const float currentDepth = currentCol.w; 221 143 222 //float4 new_col = (float4)ssao(IN, positions, noiseTexture, samples, normal, viewDir, noiseMultiplier, centerPosition); 223 float4 new_col = globIllum(IN, colors, positions, noiseTexture, samples, normal, viewDir, noiseMultiplier, centerPosition); 224 144 const float ao = ssao(IN, positions, noiseTexture, samples, normal, viewDir, noiseMultiplier, centerPosition); 145 225 146 226 147 ///////////////// 227 //-- compute temporally smooth ed value148 //-- compute temporally smoothing 228 149 229 150 float4 realPos = centerPosition * maxDepth; … … 240 161 const float depthDif = 1.0f - newDepth / oldDepth; 241 162 163 242 164 if ((tex.x >= 0.0f) && (tex.x < 1.0f) && 243 165 (tex.y >= 0.0f) && (tex.y < 1.0f) && 244 (abs(depthDif) < 1e- 4f))166 (abs(depthDif) < 1e-3f)) 245 167 { 246 OUT.illum_col = new_col * expFactor + oldCol * float4(1.0f - expFactor);168 OUT.illum_col.x = ao * expFactor + oldCol.x * (1.0f - expFactor); 247 169 } 248 170 else 249 171 { 250 OUT.illum_col = new_col;172 OUT.illum_col.x = ao; 251 173 } 252 174 253 //const float ao =OUT.illum_col.x;254 const float ao = OUT.illum_col.w;175 OUT.combined_col = currentCol * OUT.illum_col.x; 176 OUT.illum_col.w = currentDepth; 255 177 256 //OUT.combined_col = (currentCol + OUT.illum_col) * ao; 257 OUT.combined_col = currentCol * ao; 258 259 OUT.illum_col.w = currentDepth; 178 260 179 261 180 return OUT; 262 181 } 263 264 /*265 pixel combined(fragment IN,266 uniform sampler2D colors,267 uniform sampler2D ssaoTex268 )269 {270 pixel OUT;271 272 float4 col = tex2D(colors, IN.texCoord.xy);273 float4 ao = tex2D(ssaoTex, IN.texCoord.xy);274 //float4 illum = tex2D(ssaoTex, IN.texCoord.xy);275 276 OUT.illum_col = col * ao;277 278 return OUT;279 }*/
Note: See TracChangeset
for help on using the changeset viewer.