- Timestamp:
- 10/02/08 14:21:10 (16 years ago)
- Location:
- GTP/trunk/App/Demos/Vis/FriendlyCulling/src
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/DeferredRenderer.cpp
r2988 r2990 89 89 static CGparameter sBRParam; 90 90 static CGparameter sBLParam; 91 92 93 static CGparameter sTLGiParam; 94 static CGparameter sTRGiParam; 95 static CGparameter sBRGiParam; 96 static CGparameter sBLGiParam; 97 98 static CGparameter sEyePosGiParam; 99 100 91 101 92 102 //////////// … … 390 400 391 401 sOldSsaoTexGiParam = cgGetNamedParameter(sCgGiProgram, "oldSsaoTex"); 392 sOldIllumTexGiParam = cgGetNamedParameter(sCgGiProgram, "oldIllumTex"); 402 sOldIllumTexGiParam = cgGetNamedParameter(sCgGiProgram, "oldIllumTex"); 403 404 sTLGiParam = cgGetNamedParameter(sCgGiProgram, "tl"); 405 sTRGiParam = cgGetNamedParameter(sCgGiProgram, "tr"); 406 sBRGiParam = cgGetNamedParameter(sCgGiProgram, "br"); 407 sBLGiParam = cgGetNamedParameter(sCgGiProgram, "bl"); 408 409 sEyePosGiParam = cgGetNamedParameter(sCgGiProgram, "eyePos"); 393 410 } 394 411 else … … 477 494 sNoiseTexShadowParam = cgGetNamedParameter(sCgDeferredShadowProgram, "noiseTexture"); 478 495 sSamplesShadowParam = cgGetNamedParameter(sCgDeferredShadowProgram, "samples"); 479 480 496 sLightDirShadowParam = cgGetNamedParameter(sCgDeferredShadowProgram, "lightDir"); 481 482 497 sOldColorsTexShadowParam = cgGetNamedParameter(sCgDeferredShadowProgram, "oldColors"); 483 498 … … 576 591 else 577 592 FirstPass(fbo, light); 593 594 glBindTexture(GL_TEXTURE_2D, fbo->GetColorBuffer(colorBufferIdx)->GetTexture()); 595 glGenerateMipmapEXT(GL_TEXTURE_2D); 578 596 579 597 switch (mShadingMethod) … … 921 939 cgGLSetParameter1f(sMaxDepthGiParam, mScaleFactor); 922 940 941 923 942 cgGLSetParameter1f(sTemporalCoherenceGiParam, (mUseTemporalCoherence && !mRegenerateSamples) ? tempCohFactor : 0); 924 943 … … 943 962 Vector3 tl, tr, bl, br; 944 963 ComputeViewVectors(tl, tr, bl, br); 964 965 const Vector3 pos = mCamera->GetPosition() / mScaleFactor; 966 cgGLSetParameter3f(sEyePosGiParam, pos.x, pos.y, pos.z); 967 968 cgGLSetParameter3f(sBLGiParam, bl.x, bl.y, bl.z); 969 cgGLSetParameter3f(sBRGiParam, br.x, br.y, br.z); 970 cgGLSetParameter3f(sTLGiParam, tl.x, tl.y, tl.z); 971 cgGLSetParameter3f(sTRGiParam, tr.x, tr.y, tr.z); 972 945 973 946 974 glBegin(GL_QUADS); -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/chcdemo.cpp
r2989 r2990 525 525 526 526 527 const float turbitiy = 9.0f;527 const float turbitiy = 5.0f; 528 528 preetham = new SkyPreetham(turbitiy, skyDome); 529 529 -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/deferred.cg
r2988 r2990 82 82 83 83 OUT.color = col; 84 85 OUT.color.xyz = color.w;86 84 87 85 #if 1 -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/globillum.cg
r2976 r2990 44 44 45 45 46 float3 Interpol(float2 w, float3 bl, float3 br, float3 tl, float3 tr) 47 { 48 //float3 x1 = lerp(oldColor.w, logLumScaled, 0.1f); 49 float3 x1 = lerp(bl, tl, w.y); //bl * (1.0f - w.x) + br * w.x; 50 float3 x2 = lerp(br, tr, w.y); //tl * (1.0f - w.x) + tr * w.x; 51 52 float3 v = lerp(x1, x2, w.x); //x1 * (1.0f - w.y) + x2 * w.y; 53 54 return v; 55 } 56 57 46 58 /** Computes diffuse reflections + ambient occlusion 47 59 */ 48 60 GiStruct globIllum(fragment IN, 49 uniform sampler2D colors, 50 uniform sampler2D positions, 51 uniform sampler2D noiseTexture, 52 uniform float2 samples[NUM_SAMPLES], 53 uniform float3 currentNormal, 54 uniform float4 centerPosition, 55 float w 56 //, uniform float3 currentViewDir 57 ) 61 uniform sampler2D colors, 62 uniform sampler2D positions, 63 uniform sampler2D noiseTexture, 64 uniform float2 samples[NUM_SAMPLES], 65 uniform float3 currentNormal, 66 uniform float4 centerPosition, 67 float w, 68 // uniform float3 viewDir, 69 uniform float3 eyePos, 70 uniform float3 bl, 71 uniform float3 br, 72 uniform float3 tl, 73 uniform float3 tr 74 ) 58 75 { 59 76 GiStruct gi; … … 89 106 ++ numSamples; 90 107 108 // reconstruct world space position from sample 109 float4 sample = tex2Dlod(colors, float4(texcoord, 0, SSAO_MIPMAP_LEVEL)); 110 const float eyeSpaceDepth = sample.w; 111 float3 rotView = normalize(Interpol(texcoord, bl, br, tl, tr)); 112 113 const float3 sample_position = eyePos - rotView * eyeSpaceDepth; 114 const float3 sample_color = sample.xyz; 115 91 116 // use lower lod level to improve cache coherence 92 float3 sample_position = tex2Dlod(positions, float4(texcoord, 0, SSAO_MIPMAP_LEVEL)).xyz;93 float3 sample_color = tex2Dlod(colors, float4(texcoord, 0, GI_MIPMAP_LEVEL)).xyz;117 //float3 sample_position = tex2Dlod(positions, float4(texcoord, 0, SSAO_MIPMAP_LEVEL)).xyz; 118 //float3 sample_color = tex2Dlod(colors, float4(texcoord, 0, GI_MIPMAP_LEVEL)).xyz; 94 119 95 120 float3 vector_to_sample = sample_position - centerPosition.xyz; … … 106 131 107 132 // if normal perpenticular to view dir, only half of the samples count 108 /* 133 #if 0 109 134 const float view_correction = 1.0f + VIEW_CORRECTION_SCALE * (1.0f - dot(currentViewDir, currentNormal)); 110 135 total_color.w -= cos_angle * distance_intensity * view_correction; 111 136 total_color.xyz += cos_angle * distance_intensity * view_correction * sample_color * ILLUM_INTENSITY; 112 */ 137 #endif 113 138 total_ao += cos_angle * distance_intensity; 114 139 total_color += cos_angle * distance_intensity * sample_color * ILLUM_INTENSITY; … … 135 160 const uniform float4x4 oldModelViewProj, 136 161 uniform float maxDepth, 137 uniform float temporalCoherence 162 uniform float temporalCoherence, 163 uniform float3 eyePos, 164 uniform float3 bl, 165 uniform float3 br, 166 uniform float3 tl, 167 uniform float3 tr 138 168 ) 139 169 { … … 144 174 // something like a constant ambient term 145 175 const float amb = norm.w; 176 146 177 /// the current view direction 147 178 //float3 viewDir = normalize(IN.view); … … 156 187 const float currentDepth = centerPosition.w; 157 188 158 GiStruct gi = globIllum(IN, colors, positions, noiseTexture, samples, normal, centerPosition, w ); //, viewDir);189 GiStruct gi = globIllum(IN, colors, positions, noiseTexture, samples, normal, centerPosition, w, eyePos, bl, br, tl, tr); 159 190 160 191 -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/ssao.cg
r2989 r2990 21 21 22 22 23 float2 myreflect(float2 pt, float2 n)23 inline float2 myreflect(float2 pt, float2 n) 24 24 { 25 25 // distance to plane … … 32 32 33 33 34 float3 RotateY(float3 v, float a) 35 { 36 float3 r; 37 38 r.z = v.z * cos(a) - v.x * sin(a); 39 r.x = v.z * sin(a) + v.x * cos(a); 40 r.y = v.y; 41 42 return r; 43 } 44 45 46 float3 RotateX(float3 v, float a) 47 { 48 float3 r; 49 50 r.y = v.y * cos(a) - v.z * sin(a); 51 r.z = v.y * sin(a) + v.z * cos(a); 52 r.x = v.x; 53 54 return r; 55 } 56 57 58 float3 Interpol(float2 w, float3 bl, float3 br, float3 tl, float3 tr) 34 inline float3 Interpol(float2 w, float3 bl, float3 br, float3 tl, float3 tr) 59 35 { 60 36 //float3 x1 = lerp(oldColor.w, logLumScaled, 0.1f); … … 68 44 69 45 70 float2 Interpol2(float2 w, float2 bl, float2 br, float2 tl, float2 tr) 71 { 72 //float3 x1 = lerp(oldColor.w, logLumScaled, 0.1f); 73 float2 x1 = lerp(bl, tl, w.y); //bl * (1.0f - w.x) + br * w.x; 74 float2 x2 = lerp(br, tr, w.y); //tl * (1.0f - w.x) + tr * w.x; 75 76 float2 v = lerp(x1, x2, w.x); //x1 * (1.0f - w.y) + x2 * w.y; 77 78 return v; 46 inline float3 ReconstructSamplePosition(uniform sampler2D colors, float2 texcoord, float3 bl, float3 br, float3 tl, float3 tr) 47 { 48 /*float eyeSpaceDepth = tex2Dlod(colors, float4(texcoord, 0, SSAO_MIPMAP_LEVEL)).w; 49 50 // reconstruct world space position 51 float3 rotView = normalize(Interpol(texcoord, bl, br, tl, tr)); 52 float3 sample_position = eyePos - rotView * eyeSpaceDepth; 53 */ 54 float3 sample_position = tex2Dlod(colors, float4(texcoord, 0, SSAO_MIPMAP_LEVEL)).xyz; 55 56 return sample_position; 79 57 } 80 58 … … 89 67 uniform float4 centerPosition, 90 68 uniform float scaleFactor, 91 uniform float3 viewDir,69 //uniform float3 viewDir, 92 70 uniform float3 eyePos, 93 71 uniform float3 bl, … … 124 102 ++ numSamples; 125 103 126 // sample downsampled texture in order to speed up texture accesses 127 float eyeSpaceDepth = tex2Dlod(colors, float4(texcoord, 0, SSAO_MIPMAP_LEVEL)).w; 128 129 // reconstruct world space position 130 float3 rotView = normalize(Interpol(texcoord, bl, br, tl, tr)); 131 float3 sample_position = eyePos - rotView * eyeSpaceDepth; 132 133 //float3 sample_position = tex2Dlod(positions, float4(texcoord, 0, SSAO_MIPMAP_LEVEL)).xyz; 104 float3 sample_position = ReconstructSamplePosition(colors, texcoord, bl, br, tl, tr); 134 105 135 106 float3 vector_to_sample = sample_position - centerPosition.xyz; … … 190 161 // the current world position 191 162 const float4 centerPosition = tex2D(positions, IN.texCoord.xy); 163 164 /* 192 165 /// the current view direction 193 166 float3 viewDir = normalize(IN.view); 194 195 /*const float eyeDepth = tex2D(colors, IN.texCoord.xy).w; 167 const float eyeDepth = tex2D(colors, IN.texCoord.xy).w; 196 168 float4 centerPosition2; 197 169 centerPosition2.xyz = eyePos - view2 * eyeDepth; … … 202 174 203 175 //const float2 ao = ssao(IN, positions, noiseTexture, samples, normal, centerPosition, w, viewDir, eyePos); 204 const float2 ao = ssao(IN, colors, noiseTexture, samples, normal, centerPosition, w, viewDir,eyePos, bl, br, tl, tr);176 const float2 ao = ssao(IN, positions, noiseTexture, samples, normal, centerPosition, w, /*viewDir, */eyePos, bl, br, tl, tr); 205 177 206 178 … … 271 243 float4 ao = tex2D(ssaoTex, IN.texCoord.xy); 272 244 273 //OUT.illum_col = col * ao.x;274 OUT.illum_col = float4(ao.x,ao.x,ao.x, ao.w);245 OUT.illum_col = col * ao.x; 246 //OUT.illum_col = float4(ao.x,ao.x,ao.x, ao.w); 275 247 OUT.illum_col.w = col.w; 276 248
Note: See TracChangeset
for help on using the changeset viewer.