Changeset 1535 for GTP/trunk/App/Demos/Illum/Ogre/Media/materials/programs
- Timestamp:
- 09/29/06 09:07:32 (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/App/Demos/Illum/Ogre/Media/materials/programs/GameTools_Diffuse.hlsl
r1525 r1535 103 103 } 104 104 105 105 /* 106 106 float4 DiffusePS( vertOUT IN, 107 107 uniform float3 cameraPos, … … 112 112 ) : COLOR0 113 113 { 114 REDUCED_CUBEMAP_SIZE = 4; 115 float width = 1.0 /REDUCED_CUBEMAP_SIZE; 116 117 normalize( V ); 118 float3 V = normalize(IN.wPos - cameraPos); // 119 float3 N = mul( float4(IN.mNormal,1), world_IT).xyz; 120 //float3 N = IN.mNormal; 121 N = normalize( N ); 122 float3 R = reflect(V, N); 123 float3 pos = IN.wPos - lastCenter; 124 125 float4 intens = 0; 126 //intens = readCubeMap(SmallEnvMapSampler, pos); 127 128 float3 L1, L2, L3, L4, L; 129 float4 Le; 130 float d; 131 132 for (int x = 0; x < REDUCED_CUBEMAP_SIZE - 1; x++) // az envmap minden texelére 133 for (int y = 0; y < REDUCED_CUBEMAP_SIZE - 1; y++) 134 { 135 float2 p, tpos; 136 tpos.x = (x + 0.5) /(float)REDUCED_CUBEMAP_SIZE; // 0..1 137 tpos.y = (y + 0.5) /(float)REDUCED_CUBEMAP_SIZE; // 0..1 138 139 p.x = tpos.x; 140 p.y = 1-tpos.y; 141 p.xy = 2 * p.xy - 1; // -1..1 // az adott texel középpont pozíciója 142 143 L1 = float3(p.x - width, p.y - width, 1); 144 L2 = float3(p.x + width, p.y - width, 1); 145 L3 = float3(p.x + width, p.y + width, 1); 146 L4 = float3(p.x - width, p.y + width, 1); 147 L = float3(p.x, p.y, 1); 148 Le = readCubeMap(SmallEnvMapSampler, L); 149 d = readDistanceCubeMap(DistanceEnvMapSampler, L); 150 intens += 0.5 * Le * GetContibution( L1, L2, L3, L4, pos, N, SmallEnvMapSampler, d); 151 } 152 153 for (int x = 0; x < REDUCED_CUBEMAP_SIZE - 1; x++) // az envmap minden texelére 154 for (int y = 0; y < REDUCED_CUBEMAP_SIZE - 1; y++) 155 { 156 float2 p, tpos; 157 tpos.x = (x + 0.5) /(float)REDUCED_CUBEMAP_SIZE; // 0..1 158 tpos.y = (y + 0.5) /(float)REDUCED_CUBEMAP_SIZE; // 0..1 159 160 p.x = tpos.x; 161 p.y = 1-tpos.y; 162 p.xy = 2 * p.xy - 1; // -1..1 // az adott texel középpont pozíciója 163 164 L4 = float3(p.x - width, p.y - width, -1); 165 L3 = float3(p.x + width, p.y - width, -1); 166 L2 = float3(p.x + width, p.y + width, -1); 167 L1 = float3(p.x - width, p.y + width, -1); 168 L = float3(p.x, p.y, -1); 169 Le = readCubeMap(SmallEnvMapSampler, L); 170 d = readDistanceCubeMap(DistanceEnvMapSampler, L); 171 intens += 0.5 * Le * GetContibution( L1, L2, L3, L4, pos, N, SmallEnvMapSampler, d); 172 } 173 174 for (int x = 0; x < REDUCED_CUBEMAP_SIZE - 1; x++) // az envmap minden texelére 175 for (int y = 0; y < REDUCED_CUBEMAP_SIZE - 1; y++) 176 { 177 float2 p, tpos; 178 tpos.x = (x + 0.5) /(float)REDUCED_CUBEMAP_SIZE; // 0..1 179 tpos.y = (y + 0.5) /(float)REDUCED_CUBEMAP_SIZE; // 0..1 180 181 p.x = tpos.x; 182 p.y = 1-tpos.y; 183 p.xy = 2 * p.xy - 1; // -1..1 // az adott texel középpont pozíciója 184 185 L4 = float3(p.x - width, 1, p.y - width); 186 L3 = float3(p.x + width, 1, p.y - width); 187 L2 = float3(p.x + width, 1, p.y + width); 188 L1 = float3(p.x - width, 1, p.y + width); 189 L = float3(p.x, 1, p.y); 190 Le = readCubeMap(SmallEnvMapSampler, L); 191 d = readDistanceCubeMap(DistanceEnvMapSampler, L); 192 intens += 0.5 * Le * GetContibution( L1, L2, L3, L4, pos, N, SmallEnvMapSampler, d); 193 } 194 195 for (int x = 0; x < REDUCED_CUBEMAP_SIZE - 1; x++) // az envmap minden texelére 196 for (int y = 0; y < REDUCED_CUBEMAP_SIZE - 1; y++) 197 { 198 float2 p, tpos; 199 tpos.x = (x + 0.5) /(float)REDUCED_CUBEMAP_SIZE; // 0..1 200 tpos.y = (y + 0.5) /(float)REDUCED_CUBEMAP_SIZE; // 0..1 201 202 p.x = tpos.x; 203 p.y = 1-tpos.y; 204 p.xy = 2 * p.xy - 1; // -1..1 // az adott texel középpont pozíciója 205 206 L1 = float3(p.x - width, -1, p.y - width); 207 L2 = float3(p.x + width, -1, p.y - width); 208 L3 = float3(p.x + width, -1, p.y + width); 209 L4 = float3(p.x - width, -1, p.y + width); 210 L = float3(p.x, -1, p.y); 211 Le = readCubeMap(SmallEnvMapSampler, L); 212 d = readDistanceCubeMap(DistanceEnvMapSampler, L); 213 intens += 0.5 * Le * GetContibution( L1, L2, L3, L4, pos, N, SmallEnvMapSampler, d); 214 } 215 216 for (int x = 0; x < REDUCED_CUBEMAP_SIZE - 1; x++) // az envmap minden texelére 217 for (int y = 0; y < REDUCED_CUBEMAP_SIZE - 1; y++) 218 { 219 float2 p, tpos; 220 tpos.x = (x + 0.5) /(float)REDUCED_CUBEMAP_SIZE; // 0..1 221 tpos.y = (y + 0.5) /(float)REDUCED_CUBEMAP_SIZE; // 0..1 222 223 p.x = tpos.x; 224 p.y = 1-tpos.y; 225 p.xy = 2 * p.xy - 1; // -1..1 // az adott texel középpont pozíciója 226 227 L1 = float3(1, p.x - width, p.y - width); 228 L2 = float3(1, p.x + width, p.y - width); 229 L3 = float3(1, p.x + width, p.y + width); 230 L4 = float3(1, p.x - width, p.y + width); 231 L = float3(1, p.x, p.y); 232 Le = readCubeMap(SmallEnvMapSampler, L); 233 d = readDistanceCubeMap(DistanceEnvMapSampler, L); 234 intens += 0.5 * Le * GetContibution( L1, L2, L3, L4, pos, N, SmallEnvMapSampler, d); 235 } 236 237 for (int x = 0; x < REDUCED_CUBEMAP_SIZE - 1; x++) // az envmap minden texelére 238 for (int y = 0; y < REDUCED_CUBEMAP_SIZE - 1; y++) 239 { 240 float2 p, tpos; 241 tpos.x = (x + 0.5) /(float)REDUCED_CUBEMAP_SIZE; // 0..1 242 tpos.y = (y + 0.5) /(float)REDUCED_CUBEMAP_SIZE; // 0..1 243 244 p.x = tpos.x; 245 p.y = 1-tpos.y; 246 p.xy = 2 * p.xy - 1; // -1..1 // az adott texel középpont pozíciója 247 248 L4 = float3(-1, p.x - width, p.y - width); 249 L3 = float3(-1, p.x + width, p.y - width); 250 L2 = float3(-1, p.x + width, p.y + width); 251 L1 = float3(-1, p.x - width, p.y + width); 252 L = float3(-1, p.x, p.y); 253 Le = readCubeMap(SmallEnvMapSampler, L); 254 d = readDistanceCubeMap(DistanceEnvMapSampler, L); 255 intens += 0.5 * Le * GetContibution( L1, L2, L3, L4, pos, N, SmallEnvMapSampler, d); 256 } 257 258 259 //return float4(pos, 1); 260 return intens; 261 } 262 263 */ 264 265 266 float4 DiffusePS( vertOUT IN, 267 uniform float3 cameraPos, 268 uniform float3 lastCenter, //LI// 269 uniform samplerCUBE SmallEnvMapSampler : register(s0), 270 uniform samplerCUBE DistanceEnvMapSampler : register(s1), 271 uniform float4x4 world_IT 272 ) : COLOR0 273 { 274 float3 corner[] = {float3(1,-1,1),// float3(0,0,1), 275 float3(-1,-1,-1), // 0,0,-1 276 float3(-1,1,-1), // 0,1,0 277 float3(-1,-1, 1), // 0,-1,0 278 float3(1,-1,-1), // 1,0,0 279 float3(-1,-1, 1)}; // -1,0,0 280 281 float3 right[] = {float3(-1,0,0), 282 float3(1,0,0), 283 float3(1,0,0), 284 float3(-1,0,0), 285 float3(0,0,1), 286 float3(0,0,-1)}; 287 288 float3 up[] = {float3(0,1,0), 289 float3(0,1,0), 290 float3(0,0,1), 291 float3(0,0,1), 292 float3(0,1,0), 293 float3(0,1,0)}; 294 114 295 REDUCED_CUBEMAP_SIZE = 4; 115 296 float width = 1.0 /REDUCED_CUBEMAP_SIZE; … … 129 310 float4 Le; 130 311 float d; 312 313 for (int x = 0; x < REDUCED_CUBEMAP_SIZE; x++) 314 for (int y = 0; y < REDUCED_CUBEMAP_SIZE; y++) 315 for (int f = 0; f < 6; f++) 316 { 317 318 float2 p, tpos; 319 tpos.x = (x + 0.5) * 2 * width; // 0..2 320 tpos.y = (y + 0.5) * 2 * width; // 0..2 321 322 p = tpos; 323 324 L = corner[0] + p.x * right[0] + p.y * up[0]; 325 L1 = normalize(L - width * right[f] + width * up[f]); 326 L2 = normalize(L + width * right[f] + width * up[f]); 327 L3 = normalize(L + width * right[f] - width * up[f]); 328 L4 = normalize(L - width * right[f] - width * up[f]); 329 Le = texCUBE(SmallEnvMapSampler, L); 330 d = texCUBE(DistanceEnvMapSampler, L).r; 331 332 L1 = d * L1; 333 L2 = d * L2; 334 L3 = d * L3; 335 L4 = d * L4; 336 337 float3 r1 = normalize(L1 - pos); 338 float3 r2 = normalize(L2 - pos); 339 float3 r3 = normalize(L3 - pos); 340 float3 r4 = normalize(L4 - pos); 131 341 132 for (int x = 0; x < REDUCED_CUBEMAP_SIZE - 1; x++) // az envmap minden texelére 133 for (int y = 0; y < REDUCED_CUBEMAP_SIZE - 1; y++) 134 { 135 float2 p, tpos; 136 tpos.x = (x + 0.5) /(float)REDUCED_CUBEMAP_SIZE; // 0..1 137 tpos.y = (y + 0.5) /(float)REDUCED_CUBEMAP_SIZE; // 0..1 138 139 p.x = tpos.x; 140 p.y = 1-tpos.y; 141 p.xy = 2 * p.xy - 1; // -1..1 // az adott texel középpont pozíciója 142 143 L1 = float3(p.x - width, p.y - width, 1); 144 L2 = float3(p.x + width, p.y - width, 1); 145 L3 = float3(p.x + width, p.y + width, 1); 146 L4 = float3(p.x - width, p.y + width, 1); 147 L = float3(p.x, p.y, 1); 148 Le = readCubeMap(SmallEnvMapSampler, L); 149 d = readDistanceCubeMap(DistanceEnvMapSampler, L); 150 intens += 0.5 * Le * GetContibution( L1, L2, L3, L4, pos, N, SmallEnvMapSampler, d); 151 } 152 153 for (int x = 0; x < REDUCED_CUBEMAP_SIZE - 1; x++) // az envmap minden texelére 154 for (int y = 0; y < REDUCED_CUBEMAP_SIZE - 1; y++) 155 { 156 float2 p, tpos; 157 tpos.x = (x + 0.5) /(float)REDUCED_CUBEMAP_SIZE; // 0..1 158 tpos.y = (y + 0.5) /(float)REDUCED_CUBEMAP_SIZE; // 0..1 159 160 p.x = tpos.x; 161 p.y = 1-tpos.y; 162 p.xy = 2 * p.xy - 1; // -1..1 // az adott texel középpont pozíciója 163 164 L4 = float3(p.x - width, p.y - width, -1); 165 L3 = float3(p.x + width, p.y - width, -1); 166 L2 = float3(p.x + width, p.y + width, -1); 167 L1 = float3(p.x - width, p.y + width, -1); 168 L = float3(p.x, p.y, -1); 169 Le = readCubeMap(SmallEnvMapSampler, L); 170 d = readDistanceCubeMap(DistanceEnvMapSampler, L); 171 intens += 0.5 * Le * GetContibution( L1, L2, L3, L4, pos, N, SmallEnvMapSampler, d); 172 } 173 174 for (int x = 0; x < REDUCED_CUBEMAP_SIZE - 1; x++) // az envmap minden texelére 175 for (int y = 0; y < REDUCED_CUBEMAP_SIZE - 1; y++) 176 { 177 float2 p, tpos; 178 tpos.x = (x + 0.5) /(float)REDUCED_CUBEMAP_SIZE; // 0..1 179 tpos.y = (y + 0.5) /(float)REDUCED_CUBEMAP_SIZE; // 0..1 180 181 p.x = tpos.x; 182 p.y = 1-tpos.y; 183 p.xy = 2 * p.xy - 1; // -1..1 // az adott texel középpont pozíciója 184 185 L4 = float3(p.x - width, 1, p.y - width); 186 L3 = float3(p.x + width, 1, p.y - width); 187 L2 = float3(p.x + width, 1, p.y + width); 188 L1 = float3(p.x - width, 1, p.y + width); 189 L = float3(p.x, 1, p.y); 190 Le = readCubeMap(SmallEnvMapSampler, L); 191 d = readDistanceCubeMap(DistanceEnvMapSampler, L); 192 intens += 0.5 * Le * GetContibution( L1, L2, L3, L4, pos, N, SmallEnvMapSampler, d); 193 } 194 195 for (int x = 0; x < REDUCED_CUBEMAP_SIZE - 1; x++) // az envmap minden texelére 196 for (int y = 0; y < REDUCED_CUBEMAP_SIZE - 1; y++) 197 { 198 float2 p, tpos; 199 tpos.x = (x + 0.5) /(float)REDUCED_CUBEMAP_SIZE; // 0..1 200 tpos.y = (y + 0.5) /(float)REDUCED_CUBEMAP_SIZE; // 0..1 201 202 p.x = tpos.x; 203 p.y = 1-tpos.y; 204 p.xy = 2 * p.xy - 1; // -1..1 // az adott texel középpont pozíciója 205 206 L1 = float3(p.x - width, -1, p.y - width); 207 L2 = float3(p.x + width, -1, p.y - width); 208 L3 = float3(p.x + width, -1, p.y + width); 209 L4 = float3(p.x - width, -1, p.y + width); 210 L = float3(p.x, -1, p.y); 211 Le = readCubeMap(SmallEnvMapSampler, L); 212 d = readDistanceCubeMap(DistanceEnvMapSampler, L); 213 intens += 0.5 * Le * GetContibution( L1, L2, L3, L4, pos, N, SmallEnvMapSampler, d); 214 } 215 216 for (int x = 0; x < REDUCED_CUBEMAP_SIZE - 1; x++) // az envmap minden texelére 217 for (int y = 0; y < REDUCED_CUBEMAP_SIZE - 1; y++) 218 { 219 float2 p, tpos; 220 tpos.x = (x + 0.5) /(float)REDUCED_CUBEMAP_SIZE; // 0..1 221 tpos.y = (y + 0.5) /(float)REDUCED_CUBEMAP_SIZE; // 0..1 222 223 p.x = tpos.x; 224 p.y = 1-tpos.y; 225 p.xy = 2 * p.xy - 1; // -1..1 // az adott texel középpont pozíciója 226 227 L1 = float3(1, p.x - width, p.y - width); 228 L2 = float3(1, p.x + width, p.y - width); 229 L3 = float3(1, p.x + width, p.y + width); 230 L4 = float3(1, p.x - width, p.y + width); 231 L = float3(1, p.x, p.y); 232 Le = readCubeMap(SmallEnvMapSampler, L); 233 d = readDistanceCubeMap(DistanceEnvMapSampler, L); 234 intens += 0.5 * Le * GetContibution( L1, L2, L3, L4, pos, N, SmallEnvMapSampler, d); 235 } 236 237 for (int x = 0; x < REDUCED_CUBEMAP_SIZE - 1; x++) // az envmap minden texelére 238 for (int y = 0; y < REDUCED_CUBEMAP_SIZE - 1; y++) 239 { 240 float2 p, tpos; 241 tpos.x = (x + 0.5) /(float)REDUCED_CUBEMAP_SIZE; // 0..1 242 tpos.y = (y + 0.5) /(float)REDUCED_CUBEMAP_SIZE; // 0..1 243 244 p.x = tpos.x; 245 p.y = 1-tpos.y; 246 p.xy = 2 * p.xy - 1; // -1..1 // az adott texel középpont pozíciója 247 248 L4 = float3(-1, p.x - width, p.y - width); 249 L3 = float3(-1, p.x + width, p.y - width); 250 L2 = float3(-1, p.x + width, p.y + width); 251 L1 = float3(-1, p.x - width, p.y + width); 252 L = float3(-1, p.x, p.y); 253 Le = readCubeMap(SmallEnvMapSampler, L); 254 d = readDistanceCubeMap(DistanceEnvMapSampler, L); 255 intens += 0.5 * Le * GetContibution( L1, L2, L3, L4, pos, N, SmallEnvMapSampler, d); 256 } 257 258 259 //return float4(pos, 1); 342 float tri1 = acos(dot(r1, r2)) * dot(cross(r1, r2), N); 343 float tri2 = acos(dot(r2, r3)) * dot(cross(r2, r3), N); 344 float tri3 = acos(dot(r3, r4)) * dot(cross(r3, r4), N); 345 float tri4 = acos(dot(r4, r1)) * dot(cross(r4, r1), N); 346 347 // intens += Le / 16.0 + pos.x*0.000000000001; 348 intens += 0.5 * Le * max(tri1 + tri2 + tri3 + tri4, 0); 349 } 350 260 351 return intens; 261 352 }
Note: See TracChangeset
for help on using the changeset viewer.