Changeset 1712 for GTP/trunk/App/Demos/Illum/Ogre/Media/materials/programs
- Timestamp:
- 11/03/06 09:52:40 (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/App/Demos/Illum/Ogre/Media/materials/programs/GameTools_Localized_EnvMap.hlsl
r1700 r1712 31 31 { 32 32 float dist = texCUBE(dcm, float3(coord.xy, - coord.z)).r; 33 if(dist == 0) dist = 100000; ///sky33 //if(dist == 0) dist = 1000; ///sky 34 34 return dist; 35 35 } 36 36 37 /* 38 float3 Hit( float3 x, float3 R, samplerCUBE mp ) 39 { 40 41 float rl = readDistanceCubeMap(mp, R); // |r| 42 43 float dp = rl - dot(x, R); // parallax 44 45 float3 p = x + R * dp; 37 38 39 #define LIN_ITERATIONCOUNT_L0 20 40 #define LIN_ITERATIONCOUNT_L1 5 41 #define LIN_ITERATIONCOUNT_L2 3 42 #define LIN_ITERATIONCOUNT_L3 1 43 #define SECANT_ITERATIONCOUNT 2 44 45 float3 Hit(float3 x, float3 R, samplerCUBE mp, float cameraDistance = 0) 46 { 47 R = normalize(R); 48 49 float3 Ra = abs(R); 50 float3 xa = abs(x); 51 float a = max(max(xa.x,xa.y),xa.z) / 52 max(max(Ra.x,Ra.y),Ra.z); 53 54 bool overshoot = false, undershoot = false; 55 float dp, dl = 0, ppp, llp; 56 float lR = readDistanceCubeMap(mp, R); 57 float3 p = R; 58 59 float LIN_ITERATIONCOUNT = LIN_ITERATIONCOUNT_L0; 60 /* 61 if(cameraDistance < 100) 62 LIN_ITERATIONCOUNT = (float) LIN_ITERATIONCOUNT_L0; 63 else if(cameraDistance < 200) 64 LIN_ITERATIONCOUNT = (float) LIN_ITERATIONCOUNT_L1; 65 else if(cameraDistance < 300) 66 LIN_ITERATIONCOUNT = (float) LIN_ITERATIONCOUNT_L2; 67 else 68 LIN_ITERATIONCOUNT = (float) LIN_ITERATIONCOUNT_L3; 69 */ 70 71 float dt = 1.0 / LIN_ITERATIONCOUNT; 72 73 //linear iteration 74 float t = 0; 75 while(t < 1.0) 76 { 77 if(!overshoot) 78 { 79 dp = a * t / (1 - t); 80 p = x + R * dp; 81 float dist = readDistanceCubeMap(mp, p); 82 if(dist > 0) 83 { 84 ppp = length(p) / dist; 85 if(ppp < 1) 86 { 87 dl = dp; 88 llp = ppp; 89 undershoot = true; 90 } 91 else 92 { 93 if (undershoot) 94 overshoot = true; 95 } 96 } 97 else 98 undershoot = false; 99 } 100 t += dt; 101 } 102 103 if(overshoot) 104 { 105 float dnew; 106 for(int i = 0; i < SECANT_ITERATIONCOUNT; i++ ) 107 { 108 dnew = dl + (dp - dl) * (1 - llp) / (ppp - llp); 109 110 p = x + R * dnew; 111 half pppnew = length(p) / readDistanceCubeMap(mp, p); 112 if(pppnew < 1) 113 { 114 llp = pppnew; 115 dl = dnew; 116 } 117 else 118 { 119 ppp = pppnew; 120 dp = dnew; 121 } 122 } 123 } 124 else 125 p = float3(0,0,0); 126 46 127 return p; 47 }*/ 48 49 #define LIN_ITERATIONCOUNT 5 50 #define SECANT_ITERATIONCOUNT 0 128 } 129 51 130 /* 52 131 float3 Hit(float3 x, float3 R, samplerCUBE mp) … … 81 160 } 82 161 } 83 84 float3 dirUn = normalize(under); 85 float3 dirOv = normalize(over); 86 float tun = d / dot(N, dirUn); 87 float pun = tun / length(under); 88 float dun = length(tun * dirUn - x); 89 float tov = d / dot(N, dirOv); 90 float pov = tov / length(over); 91 float dov = length(tov * dirOv - x); 92 float tl = (d - dot(N, over)) / dot(N, under - over); 93 float3 l = over + tl * (under - over); 94 float dl = length(l - x); 95 96 //secant iteration 97 for( int i = 0; i < SECANT_ITERATIONCOUNT; i++ ) 98 { 99 float llp = length( l ) / readDistanceCubeMap( mp, l); // |l|/|l| 100 if ( llp < 0.999f ) // undershooting 101 { 102 dun = dl; pun = llp; // last undershooting 103 dl += ( dl - dov ) * ( 1 - llp ) / ( llp - pov ); // eq. 3 104 } else if ( llp > 1.001f ) // overshooting 105 { 106 dov = dl; pov = llp; // last overshooting 107 dl += ( dl - dun ) * ( 1 - llp ) / ( llp - pun );// eq. 3 108 } 109 l = x + R * dl; // ray equation 110 } 111 112 return l; 113 return over; 114 return (under + over)/2.0; 162 return over; 115 163 } 116 164 */ 117 float3 Hit(float3 x, float3 R, samplerCUBE mp)118 {119 R = normalize(R);120 float3 xNorm = normalize(x);121 float3 dt = (R - xNorm) / (float) LIN_ITERATIONCOUNT;122 float dx = length(cross(R,x));123 124 float3 pN = normalize(cross(R, xNorm));125 float3 N = normalize(cross(pN,R));126 float d = dot(x, N);127 128 float3 under = xNorm * readDistanceCubeMap(mp, x);129 float3 over = R * readDistanceCubeMap(mp, R);130 131 //linear iteration132 for(int i = 1; i < LIN_ITERATIONCOUNT; i++)133 {134 float3 ldir = normalize(xNorm + dt * i);135 float lL = readDistanceCubeMap( mp, dir);136 float3 l_ = dir * dist;137 float alpha = (dot(x, l_) - dot(R, l_) * dot(x, R)) / (lL * lL - dot(R, l_) * dot(R, l_));138 float d = dot(l_, R) * alpha - dot(x, R);139 140 if( dot(N, point) > d)//undershooting141 {142 under = point;143 }144 else //overshooting145 {146 over = point;147 i = LIN_ITERATIONCOUNT;148 }149 }150 151 float3 dirUn = normalize(under);152 float3 dirOv = normalize(over);153 float tun = d / dot(N, dirUn);154 float pun = tun / length(under);155 float dun = length(tun * dirUn - x);156 float tov = d / dot(N, dirOv);157 float pov = tov / length(over);158 float dov = length(tov * dirOv - x);159 float tl = (d - dot(N, over)) / dot(N, under - over);160 float3 l = over + tl * (under - over);161 float dl = length(l - x);162 163 //secant iteration164 for( int i = 0; i < SECANT_ITERATIONCOUNT; i++ )165 {166 float llp = length( l ) / readDistanceCubeMap( mp, l); // |l|/|l|167 if ( llp < 0.999f ) // undershooting168 {169 dun = dl; pun = llp; // last undershooting170 dl += ( dl - dov ) * ( 1 - llp ) / ( llp - pov ); // eq. 3171 } else if ( llp > 1.001f ) // overshooting172 {173 dov = dl; pov = llp; // last overshooting174 dl += ( dl - dun ) * ( 1 - llp ) / ( llp - pun );// eq. 3175 }176 l = x + R * dl; // ray equation177 }178 179 return l;180 return over;181 return (under + over)/2.0;182 }183 184 165 185 166 /* 186 // This function is called several times.187 167 float3 Hit( float3 x, float3 R, samplerCUBE mp ) 188 168 { … … 195 175 196 176 // iteration 197 for( int i = 0; i < 2; i++ ) // 2 !!!!!!!!!!!!!!!!!!!!!!!177 for( int i = 0; i < SECANT_ITERATIONCOUNT; i++ ) 198 178 { 199 179 float llp = length( l ) / readDistanceCubeMap( mp, l); // |l|/|l| … … 293 273 float3 newTexCoord; 294 274 float3 mPos = wPos - lastCenter; 295 float3 V = normalize(wPos - cameraPos); 275 float3 V = (wPos - cameraPos); 276 float cameraDistace = length(V); 277 V = normalize(V); 296 278 float3 R = normalize(reflect( V, mNormal)); 297 279 298 280 newTexCoord = R; 299 281 300 newTexCoord = Hit(mPos, R, DistanceMap); 301 302 Color = readCubeMap(CubeMap, newTexCoord ) /*+ lastCenter.x*0.000001*/; 282 newTexCoord = Hit(mPos, R, DistanceMap, cameraDistace); 283 if(dot(newTexCoord,newTexCoord) == 0) 284 Color = float4(0.5,0.5,0.5,1); 285 else 286 Color = readCubeMap(CubeMap, newTexCoord ); 303 287 304 288 float ctheta_in = dot(mNormal,R);
Note: See TracChangeset
for help on using the changeset viewer.