Changeset 3009 for GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders
- Timestamp:
- 10/06/08 17:39:30 (16 years ago)
- Location:
- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/deferred.cg
r3005 r3009 6 6 // normalized screen position 7 7 float4 pos: WPOS; 8 float 4texCoord: TEXCOORD0;9 float3 view: COLOR0;8 float2 texCoord: TEXCOORD0; 9 float3 view: TEXCOORD1; 10 10 }; 11 11 … … 32 32 float4 shade(fragment IN, 33 33 uniform float4 color, 34 uniform float4 position,35 34 uniform float3 normal, 36 35 uniform float emmisive, … … 49 48 50 49 // hack: prevent shading the sky 51 if ( position.z> 1e19f) outColor = color;50 if (color.w > 1e19f) outColor = color; 52 51 //if (emmisive > 1.5f) outColor = color; 53 52 else outColor = (ambient + diffuse) * color; … … 70 69 pixel OUT; 71 70 72 float4 norm = tex2D(normals, IN.texCoord .xy);73 float4 color = tex2Dlod(colors, float4(IN.texCoord .xy, 0, 0));74 float4 position = tex2D(positions, IN.texCoord.xy);71 float4 norm = tex2D(normals, IN.texCoord); 72 float4 color = tex2Dlod(colors, float4(IN.texCoord, 0, 0)); 73 75 74 76 75 // an ambient color term 77 76 float amb = color.w; 78 77 float3 normal = normalize(norm.xyz); 79 float4 col = shade(IN, color, position,normal, amb, lightDir);78 float4 col = shade(IN, color, normal, amb, lightDir); 80 79 81 80 OUT.color = col; 82 83 #if 184 85 81 OUT.color.w = color.w; 86 87 #else88 89 ////////////90 //-- write out logaritmic luminance for tone mapping91 92 // the old loglum is stored in the hightest mipmap-level93 float oldLogLum = tex2Dlod(colors, float4(IN.texCoord.xy, 0, MAX_LOD_LEVEL)).w;94 95 const float3 w = float3(0.299f, 0.587f, 0.114f);96 97 float lum = dot(OUT.color.rgb, w);98 float logLum = log(1e-5f + lum);99 100 float logLumOffset = MINLOGLUM * INV_LOGLUM_RANGE;101 float logLumScaled = logLum * INV_LOGLUM_RANGE - logLumOffset;102 103 if (oldLogLum > 0)104 OUT.color.w = lerp(oldLogLum, logLumScaled, 0.1f);105 else106 OUT.color.w = logLumScaled;107 108 #endif109 82 110 83 return OUT; … … 134 107 //-- add random noise: reflect around random normal vector (warning: slow!) 135 108 136 float2 mynoise = tex2D(noiseTexture, IN.texCoord .xy).xy;109 float2 mynoise = tex2D(noiseTexture, IN.texCoord).xy; 137 110 const float2 offsetTransformed = myreflect(offset, mynoise); 138 111 #else … … 150 123 151 124 return total_d; 125 } 126 127 inline float3 Interpol(float2 w, float3 bl, float3 br, float3 tl, float3 tr) 128 { 129 float3 x1 = lerp(bl, tl, w.y); 130 float3 x2 = lerp(br, tr, w.y); 131 float3 v = lerp(x1, x2, w.x); 132 133 return v; 152 134 } 153 135 … … 163 145 uniform sampler2D noiseTexture, 164 146 uniform float2 samples[NUM_PCF_TABS], 165 uniform float3 lightDir 166 //, uniform sampler2D oldColors 147 uniform float3 lightDir, 148 uniform float3 eyePos, 149 uniform float3 bl, 150 uniform float3 br, 151 uniform float3 tl, 152 uniform float3 tr 167 153 ) 168 154 { … … 170 156 171 157 float4 norm = tex2D(normals, IN.texCoord.xy); 172 float4 color = tex2Dlod(colors, float4(IN.texCoord.xy, 0, 0));173 float4 position = tex2D(positions, IN.texCoord.xy);174 175 158 const float3 normal = normalize(norm.xyz); 176 177 // hack: an emmisive color term 178 float emmisive = color.w; 179 159 160 float4 color = tex2Dlod(colors, float4(IN.texCoord, 0, 0)); 161 162 /// reconstruct position from the eye space depth 163 float3 viewDir = IN.view; 164 const float eyeDepth = tex2Dlod(colors, float4(IN.texCoord, 0, 0)).w; 165 166 float4 position; 167 position.xyz = eyePos - viewDir * eyeDepth; 168 169 180 170 // diffuse intensity 181 171 const float angle = saturate(dot(normal, lightDir)); … … 186 176 float4 diffuse = lightDiffuse * angle; 187 177 178 // hack: prevent shadowing the sky 179 const bool useShading = (color.w < 1e19f); 180 188 181 // calc diffuse illumination + shadow term 189 //if ((emmisive < 1.5f) // hack: prevent shadowing the sky 190 if ((position.z < 1e19f) 191 && (angle > 1e-3f) // shadow only if diffuse color has some minimum intensity 182 if (useShading && 183 (angle > 1e-3f) // shadow only if diffuse color has some minimum intensity 192 184 ) 193 185 { … … 205 197 // light ambient term 206 198 const float4 ambient = glstate.light[0].ambient; 207 208 // base lighting 209 //OUT.color = (emmisive > 1.5f) ? color: (ambient + diffuse) * color; 210 OUT.color = (position.z > 1e19f) ? color: (ambient + diffuse) * color; 211 212 213 //////////// 214 //-- write out logaritmic luminance for tone mapping 215 216 #if 1 199 // compute shading 200 OUT.color = useShading ? (ambient + diffuse) * color : color; 201 217 202 OUT.color.w = color.w; 218 #else 219 220 float oldLogLum = tex2Dlod(colors, float4(IN.texCoord.xy, 0, MAX_LOD_LEVEL)).w; 221 222 const float3 w = float3(0.299f, 0.587f, 0.114f); 223 224 float lum = dot(OUT.color.rgb, w); 225 float logLum = log(1e-5f + lum); 226 227 float logLumOffset = MINLOGLUM * INV_LOGLUM_RANGE; 228 float logLumScaled = logLum * INV_LOGLUM_RANGE - logLumOffset; 229 230 if (oldLogLum > 0) 231 OUT.color.w = lerp(oldLogLum, logLumScaled, 0.1f); 232 else 233 OUT.color.w = logLumScaled; 234 #endif 203 235 204 return OUT; 236 205 } -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/globillum.cg
r3006 r3009 11 11 float4 pos: WPOS; 12 12 float4 texCoord: TEXCOORD0; 13 float3 view: COLOR0;13 float3 view: TEXCOORD1; 14 14 }; 15 15 … … 177 177 //-- reconstruct position from the eye space depth 178 178 179 float3 viewDir = I nterpol(IN.texCoord.xy, bl, br, tl, tr);//IN.view;179 float3 viewDir = IN.view; 180 180 const float eyeDepth = tex2Dlod(colors, float4(IN.texCoord.xy, 0, 0)).w; 181 181 … … 234 234 (tex.x >= 0.0f) && (tex.x < 1.0f) && 235 235 (tex.y >= 0.0f) && (tex.y < 1.0f) && 236 (abs(depthDif) < 1e-3f)236 (abs(depthDif) < MIN_DEPTH_DIFF) 237 237 // check if something changed in the surrounding area 238 238 //&& (oldNumSamples > 0.2 * gi.ao.y) -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/mrt.cg
r3005 r3009 38 38 { 39 39 float4 col: COLOR0; 40 //float4 pos: COLOR1; 41 float3 pos: COLOR1; 42 float4 norm: COLOR2; 40 float4 norm: COLOR1; 41 float3 pos: COLOR2; 43 42 }; 44 43 … … 113 112 pix.col.w = length(eyePos - IN.worldPos.xyz) * maxDepth / magView; 114 113 115 #if 1114 #if 0 116 115 // save world position in second render target 117 116 pix.pos = IN.worldPos.xyz * maxDepth; … … 145 144 //pix.col.w = glstate.material.emission.x; 146 145 147 // compute eye linear depth 146 // compute eye linear depth and scale with lenght to avoid sqr root in pixel shader 148 147 float2 screenCoord = projPos.xy * 0.5f + 0.5f; 149 148 const float magView = length(Interpol(screenCoord, bl, br, tl, tr)); 150 149 pix.col.w = length(eyePos - IN.worldPos.xyz) * maxDepth / magView; 151 150 152 #if 1151 #if 0 153 152 pix.pos = IN.worldPos.xyz * maxDepth; 154 153 #endif -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/sky_preetham.cg
r3005 r3009 30 30 struct pixel 31 31 { 32 33 float3 pos: COLOR1;34 float4 norm: COLOR2;32 float4 col: COLOR0; 33 float4 norm: COLOR1; 34 float3 pos: COLOR2; 35 35 }; 36 36 … … 112 112 113 113 pix.col = IN.color2; 114 pix.col.w = 2.0f;114 pix.col.w = 1e20f; 115 115 116 116 pix.norm.xyz = IN.normal; 117 117 pix.norm.w = IN.mypos.w; 118 118 119 pix.pos = 1e20f;119 //pix.pos = 1e20f; 120 120 121 121 return pix; -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/ssao.cg
r3006 r3009 230 230 (tex.x >= 0.0f) && (tex.x < 1.0f) && 231 231 (tex.y >= 0.0f) && (tex.y < 1.0f) && 232 (abs(depthDif) < 1e-4f)232 (abs(depthDif) < MIN_DEPTH_DIFF) 233 233 // if visibility changed in the surrounding area we have to recompute 234 234 //&& (oldNumSamples > 0.8f * newNumSamples)
Note: See TracChangeset
for help on using the changeset viewer.