- Timestamp:
- 10/30/06 13:47:11 (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/App/Demos/Illum/Ogre/Media/materials/programs/GameTools_Localized_EnvMap.hlsl
r1699 r1700 49 49 #define LIN_ITERATIONCOUNT 5 50 50 #define SECANT_ITERATIONCOUNT 0 51 51 /* 52 52 float3 Hit(float3 x, float3 R, samplerCUBE mp) 53 53 { … … 71 71 float3 point = dir * dist; 72 72 73 if( dot(N, point) > d)//undershooting 74 { 75 under = point; 76 } 77 else //overshooting 78 { 79 over = point; 80 i = LIN_ITERATIONCOUNT; 81 } 82 } 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; 115 } 116 */ 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 iteration 132 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 73 140 if( dot(N, point) > d)//undershooting 74 141 {
Note: See TracChangeset
for help on using the changeset viewer.