Changeset 1724 for GTP/trunk/App/Demos/Illum/Ogre/Media/materials/programs
- Timestamp:
- 11/08/06 14:03:40 (18 years ago)
- Location:
- GTP/trunk/App/Demos/Illum/Ogre/Media/materials/programs
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/App/Demos/Illum/Ogre/Media/materials/programs/GameTools_Localized_EnvMap.hlsl
r1720 r1724 46 46 float3 Hit(float3 x, float3 R, samplerCUBE mp, float cameraDistance = 0) 47 47 { 48 return R + 0.000000001 *x; 48 49 R = normalize(R); 49 50 … … 197 198 out float4 hPos : POSITION, 198 199 uniform float4x4 worldViewProj, 199 uniform float4x4 world) 200 uniform float4x4 world, 201 uniform float4x4 worldI 202 ) 200 203 { 201 204 202 205 hPos = mul(worldViewProj, position); 203 206 wPos = mul(world, position).xyz; 204 mNormal = normal;207 mNormal = mul(normal, worldI); 205 208 otexCoord = texCoord; 206 209 } -
GTP/trunk/App/Demos/Illum/Ogre/Media/materials/programs/MetalTeapot.hlsl
r1720 r1724 9 9 float readDistanceCubeMap(samplerCUBE dcm, float3 coord) 10 10 { 11 float dist = texCUBE(dcm, float3(coord.xy, - coord.z)). r;11 float dist = texCUBE(dcm, float3(coord.xy, - coord.z)).a; 12 12 return dist; 13 13 } … … 15 15 16 16 17 #define LIN_ITERATIONCOUNT 217 #define LIN_ITERATIONCOUNT 5 18 18 #define SECANT_ITERATIONCOUNT 2 19 /* 20 float 3 Hit(float3 x, float3 R, samplerCUBE mp, float cameraDistance = 0)19 20 float Hit(float3 x, float3 R, samplerCUBE mp, out float3 newDir) 21 21 { 22 22 R = normalize(R); … … 30 30 float dp, dl = 0, ppp, llp; 31 31 float lR = readDistanceCubeMap(mp, R); 32 float3 p = R; 33 32 //float3 p = R; 33 float3 p = 0; 34 34 35 float dt = 1.0 / LIN_ITERATIONCOUNT; 35 36 … … 38 39 while(t < 1.0 && !overshoot) 39 40 { 40 //if(!overshoot) 41 //{ 42 dp = a * t / (1 - t); 43 p = x + R * dp; 44 float dist = readDistanceCubeMap(mp, p); 45 if(dist > 0) 46 { 47 ppp = length(p) / dist; 48 if(ppp < 1) 49 { 50 dl = dp; 51 llp = ppp; 52 undershoot = true; 53 } 54 else 55 { 56 if (undershoot) 57 overshoot = true; 58 } 59 } 60 else 61 undershoot = false; 62 //} 41 dp = a * t / (1 - t); 42 p = x + R * dp; 43 float dist = readDistanceCubeMap(mp, p); 44 if(dist > 0) 45 { 46 ppp = length(p) / dist; 47 if(ppp < 1) 48 { 49 dl = dp; 50 llp = ppp; 51 undershoot = true; 52 } 53 else 54 { 55 if (undershoot) 56 overshoot = true; 57 } 58 } 59 else 60 undershoot = false; 61 63 62 t += dt; 64 63 } … … 87 86 else 88 87 p = float3(0,0,0); 89 90 return p; 91 } 92 */ 93 88 89 newDir = p; 90 return dp; 91 } 92 93 /* 94 94 float3 Hit( float3 x, float3 R, samplerCUBE mp ) 95 95 { 96 return R + 0.00000000001 * x;96 //return R + 0.00000000001 * x; 97 97 float rl = readDistanceCubeMap( mp, R); // |r| 98 98 … … 103 103 104 104 // iteration 105 for( int i = 0; i < 2; i++ ) // 2 !!!!!!!!!!!!!!!!!!!!!!!105 for( int i = 0; i < SECANT_ITERATIONCOUNT; i++ ) 106 106 { 107 107 float llp = length( l ) / readDistanceCubeMap( mp, l); // |l|/|l| … … 120 120 return l; // computed hit point 121 121 } 122 123 void LocalizedVS(float4 position : POSITION, 124 out float3 wPos : TEXCOORD1, 125 float2 texCoord : TEXCOORD0, 126 out float2 otexCoord : TEXCOORD0, 127 float3 normal : NORMAL, 128 out float3 mNormal : TEXCOORD2, 129 out float4 hPos : POSITION, 130 uniform float4x4 worldViewProj, 131 uniform float4x4 world) 132 { 133 134 hPos = mul(worldViewProj, position); 135 wPos = mul(world, position).xyz; 136 mNormal = normal; 137 otexCoord = texCoord; 138 } 139 140 ////////////// 141 //Localized reflection 142 ////////////// 143 void LocalizedPS( float2 texCoord : TEXCOORD0, 144 float3 wPos : TEXCOORD1, 145 float3 mNormal : TEXCOORD2, 146 uniform float3 cameraPos, 147 uniform samplerCUBE CubeMap : register(s0), 148 uniform samplerCUBE DistanceMap : register(s1), 149 uniform float3 lastCenter, 150 uniform float3 lightPosition, 151 out float4 Color :COLOR0) 152 { 153 154 Color = float4(1,1,1,1); 155 156 mNormal = normalize(mNormal); 157 float3 RR, TT; 158 float3 mPos = wPos - lastCenter; 159 float3 V = normalize(wPos - cameraPos); 160 float3 R = /*normalize*/(reflect( V, mNormal)); 161 162 float3 T = refract(V, mNormal, 0.9); 163 164 RR = R; TT = T; 165 //RR += 0.000001 * lastCenter.x; 166 RR = Hit(mPos, R, DistanceMap); 167 TT = Hit(mPos, T, DistanceMap); 168 169 float4 reflectcolor = readCubeMap(CubeMap, RR ); 170 float4 refractcolor = readCubeMap(CubeMap, TT ); 171 172 float cos_theta = -dot(V, mNormal); 173 float sFresnel = 0.1; 174 float F = (sFresnel + pow(1-cos_theta, 5.0f) * (1-sFresnel)); 175 176 float3 L = normalize(lightPosition - wPos); 177 float3 H = normalize(L+V); 178 float4 lighting = lit(dot(mNormal, L),dot(mNormal, H), 30); 179 Color = (F * reflectcolor + (1-F) * refractcolor) + lighting.z; 180 } 181 182 122 */ 123 124 struct VertOut 125 { 126 float3 wPos : TEXCOORD1; 127 float3 cPos : TEXCOORD3; 128 float2 texCoord : TEXCOORD0; 129 float3 mNormal : TEXCOORD2; 130 float4 hPos : POSITION; 131 }; 132 133 VertOut DefaultVS(float4 position : POSITION, 134 float2 texCoord : TEXCOORD0, 135 float3 normal : NORMAL, 136 uniform float4x4 worldViewProj, 137 uniform float4x4 world, 138 uniform float4x4 worldview, 139 uniform float4x4 worldI ) 140 { 141 VertOut OUT; 142 OUT.hPos = mul(worldViewProj, position); 143 OUT.wPos = mul(world, position).xyz; 144 OUT.cPos = mul(worldview, position).xyz; 145 OUT.mNormal = mul(normal, worldI); 146 //OUT.mNormal = normal; 147 OUT.texCoord = texCoord; 148 return OUT; 149 } 183 150 184 151 ////////////// 185 152 //Metal 186 153 ////////////// 187 void LocalizedMetalPS( float2 texCoord : TEXCOORD0, 188 float3 wPos : TEXCOORD1, 189 float3 mNormal : TEXCOORD2, 154 void Metal1BouncePS( VertOut IN, 190 155 uniform float3 cameraPos, 191 156 uniform samplerCUBE CubeMap : register(s0), … … 198 163 Color = float4(1,1,1,1); 199 164 200 mNormal = normalize(mNormal);165 IN.mNormal = normalize(IN.mNormal); 201 166 float3 newTexCoord; 202 float3 mPos = wPos - lastCenter;203 float3 V = ( wPos - cameraPos);167 float3 mPos = IN.wPos - lastCenter; 168 float3 V = (IN.wPos - cameraPos); 204 169 float cameraDistace = length(V); 205 170 V = normalize(V); 206 float3 R = normalize(reflect( V, mNormal)); 207 208 newTexCoord = R; 209 210 newTexCoord = Hit(mPos, R, DistanceMap); 211 /*if(dot(newTexCoord,newTexCoord) == 0) 212 Color = float4(0.5,0.5,0.5,1); 213 else*/ 214 Color = readCubeMap(CubeMap, newTexCoord ); 215 216 float ctheta_in = dot(mNormal,R); 217 float ctheta_out = dot(mNormal,-V); 171 float3 R = normalize(reflect( V, IN.mNormal)); 172 173 newTexCoord = R + 0.00000001 * lastCenter.x; 174 //newTexCoord = R; 175 //Hit(mPos, R, DistanceMap, newTexCoord); 176 Color = readCubeMap(CubeMap, newTexCoord ); 177 178 float ctheta_in = dot(IN.mNormal,R); 179 float ctheta_out = dot(IN.mNormal,-V); 218 180 219 181 float3 F = 0; … … 229 191 Color = Color * float4(F,1); 230 192 } 231 ////////////// 232 //PhotonMap 233 ////////////// 234 /*void PhotonMapPS( float2 texCoord : TEXCOORD0, 235 float3 wPos : TEXCOORD1, 236 float3 mNormal : TEXCOORD2, 193 194 195 void MetalMultipleBouncePS( VertOut IN, 237 196 uniform float3 cameraPos, 238 uniform samplerCUBE UVMap : register(s0),197 uniform samplerCUBE CubeMap : register(s0), 239 198 uniform samplerCUBE DistanceMap : register(s1), 199 uniform samplerCUBE NormDistMap1 : register(s2), 200 uniform samplerCUBE NormDistMap2 : register(s3), 240 201 uniform float3 lastCenter, 241 202 out float4 Color :COLOR0) … … 244 205 Color = float4(1,1,1,1); 245 206 246 mNormal = normalize(mNormal);207 IN.mNormal = normalize(IN.mNormal); 247 208 float3 newTexCoord; 248 float3 mPos = wPos - lastCenter; 249 float3 V = normalize(wPos - cameraPos); 250 float3 R = normalize(reflect( V, mNormal)); 251 252 newTexCoord = R; 253 254 newTexCoord = Hit(mPos, R, DistanceMap); 255 256 Color = readCubeMap(UVMap, newTexCoord ); 257 //Color = float4(1,0,0,1); 258 }*/ 259 260 float4 PhotonMapCausticPS( float2 texCoord : TEXCOORD0, 261 float3 wPos : TEXCOORD1, 262 float3 mNormal : TEXCOORD2, 263 uniform float3 cameraPos, 264 uniform samplerCUBE DistanceMap : register(s0), 265 uniform float3 lastCenter):COLOR0 266 { 267 268 float4 Color = float4(1,1,1,1); 269 270 mNormal = normalize(mNormal); 271 float3 newTexCoord; 272 float3 mPos = wPos - lastCenter; 273 float3 V = normalize(wPos - cameraPos); 274 275 float3 R = refract(V, mNormal, 0.85); 276 //float3 R = V; 277 newTexCoord = R; 278 279 newTexCoord = Hit(mPos, R, DistanceMap); 280 281 Color = float4(newTexCoord, 1); 282 283 //Color = 0.0001 * Color + float4(0,0,1,1); 284 //Color += 0.0001 * lastCenter.x; 285 if(dot(V,mNormal)>0) 286 { 287 Color = float4(1,0,0,0); 288 } 289 return Color; 290 } 291 292 293 294 ///////////////////// 295 ///// Diffuse 296 /////////////////// 297 298 float4 GetContibution(float3 L, float3 pos, float3 N, float3 V, samplerCUBE SmallEnvMapSampler, samplerCUBE DistanceEnvMapSampler) // Phong-Blinn 299 // L: a hossza lényeges (az egységkocka faláig ér) 300 { 301 REDUCED_CUBEMAP_SIZE = 4; 302 303 float kd = 0.3; // 0.3 304 float ks = 0; // 0.5 305 float shininess = 10; 306 307 float l = length(L); 308 L = normalize(L); 309 310 //dw 311 float dw = 4 / (REDUCED_CUBEMAP_SIZE*REDUCED_CUBEMAP_SIZE*l*l*l + 4/3.1416f); 312 //Lin 313 float4 Lin = readCubeMap(SmallEnvMapSampler, L); 314 //r 315 float doy = readDistanceCubeMap(DistanceEnvMapSampler, L); 316 float dxy = length(L * doy - pos); 317 318 //dws 319 float dws = (doy*doy * dw) / (dxy*dxy*(1 - dw/3.1416f) + doy*doy*dw/3.1416f); // localization: 320 //float dws = dw; 321 322 //L = L * doy - pos; // L: x->y, az objektumtól induljon, ne a középpontból 323 L = normalize(L); 324 float3 H = normalize(L + V); // felezõvektor 325 326 float a = kd * max(dot(N,L),0) + 327 ks * pow(max(dot(N,H),0), shininess); // diffuse + specular 328 329 // 1.: eddigi 330 //return Lin * a * dws; 331 332 float ctheta_in = dot(N,L); 333 float ctheta_out = dot(N,V); 334 335 return Lin * a * dws; 336 } 337 338 void DiffuseVS( float4 position : POSITION, 339 float3 normal : NORMAL, 340 float2 Tex : TEXCOORD0, 341 uniform float4x4 worldViewProj, 342 uniform float4x4 world, 343 //uniform float3 lastCenter, //LI// 344 out float4 hposition : POSITION, 345 out float2 oTex : TEXCOORD0, 346 out float3 Normal : TEXCOORD1, 347 out float3 pos : TEXCOORD2 ) 348 { 349 pos = /*lastCenter + 0.01 * */mul( world, position ).xyz; 350 Normal = normal; 351 oTex = Tex; 352 hposition = mul( worldViewProj, position ); 353 } 354 355 356 float4 DiffusePS( float2 Tex : TEXCOORD0, 357 float3 N : TEXCOORD1, 358 float3 pos : TEXCOORD2, 359 uniform float3 cameraPos, 360 uniform float3 lastCenter, //LI// 361 uniform samplerCUBE SmallEnvMapSampler : register(s0), 362 uniform samplerCUBE DistanceEnvMapSampler : register(s1) 363 ) : COLOR0 364 { 365 REDUCED_CUBEMAP_SIZE = 4; 366 367 //V = /*-*/normalize( V ); 368 float3 V = normalize(pos - cameraPos); // 369 N = normalize( N ); 370 float3 R = reflect(V, N); 371 pos -= lastCenter; 372 373 374 //return float4(N,1); 375 //return float4(V,1); 376 //return float4(R,1); 377 378 //return readCubeMap(SmallEnvMapSampler,R); 379 380 //pos.xy += float2(1.0/LIGHT_TEXTURE_SIZE, -1.0/LIGHT_TEXTURE_SIZE); // eltolás a pixel/texel középpontba 381 // x, y = -1..1 382 // z = 1 383 384 float4 intens = 0; 385 /* 386 intens += GetContibution( R, pos, N, V, SmallEnvMapSampler); 387 intens = readCubeMap(SmallEnvMapSampler, R); 388 return intens;*/ 389 390 for (int x = 0; x < REDUCED_CUBEMAP_SIZE; x++) // az envmap minden texelére 391 for (int y = 0; y < REDUCED_CUBEMAP_SIZE; y++) 392 //int x = 0; // az envmap 1 texelére 393 //int y = 0; 394 //if (x==LIGHT_TEXTURE_SIZE/2 && y==LIGHT_TEXTURE_SIZE/2) 395 { 396 // intenzitás kiolvasása az adott texelbõl 397 398 float2 p, tpos; 399 tpos.x = x/(float)REDUCED_CUBEMAP_SIZE; // 0..1 400 tpos.y = y/(float)REDUCED_CUBEMAP_SIZE; // 0..1 401 tpos.xy += float2(0.5/REDUCED_CUBEMAP_SIZE, 0.5/REDUCED_CUBEMAP_SIZE); // az adott texel középpont uv koordinátái 402 403 p.x = tpos.x; 404 p.y = 1-tpos.y; 405 p.xy = 2*p.xy - 1; // -1..1 // az adott texel középpont pozíciója 406 407 float3 L; 408 409 L = float3(p.x, p.y, 1); 410 intens += GetContibution( L, pos, N, V, SmallEnvMapSampler, DistanceEnvMapSampler); 411 412 L = float3(p.x, p.y, -1); 413 intens += GetContibution( L, pos, N, V, SmallEnvMapSampler, DistanceEnvMapSampler); 414 415 L = float3(p.x, 1, p.y); 416 intens += GetContibution( L, pos, N, V, SmallEnvMapSampler, DistanceEnvMapSampler); 417 418 L = float3(p.x, -1, p.y); 419 intens += GetContibution( L, pos, N, V, SmallEnvMapSampler, DistanceEnvMapSampler); 420 421 L = float3(1, p.x, p.y); 422 intens += GetContibution( L, pos, N, V, SmallEnvMapSampler, DistanceEnvMapSampler); 423 424 L = float3(-1, p.x, p.y); 425 intens += GetContibution( L, pos, N, V, SmallEnvMapSampler, DistanceEnvMapSampler); 426 } 427 428 return intens; 429 } 209 float3 mPos = IN.wPos - lastCenter; 210 float3 V = (IN.wPos - cameraPos); 211 float cameraDistace = length(V); 212 V = normalize(V); 213 float3 R = normalize(reflect( V, IN.mNormal)); 214 215 newTexCoord = R; 216 217 //Color = readCubeMap(NormDistMap1, mPos ); 218 //return; 219 220 float3 newDir1; 221 float d1 = Hit(mPos, R, NormDistMap1, newDir1); 222 float3 normal1 = readCubeMap(NormDistMap1, newDir1); 223 float3 newDir2; 224 float d2 = Hit(mPos, R, NormDistMap2, newDir2); 225 float3 normal2 = readCubeMap(NormDistMap2, newDir2); 226 227 if( dot(newDir2,newDir2) == 0.0 && dot(newDir1,newDir1) == 0.0 ) 228 { 229 Hit(mPos, R, DistanceMap, newTexCoord); 230 Color = readCubeMap(CubeMap, newTexCoord ); 231 } 232 else 233 { 234 float3 newV; 235 float3 newR; 236 float3 newN = normal1; 237 float3 dir = newDir1; 238 float d = d1; 239 float3 newX; 240 //closer hit 241 if(d1 > d2) 242 { 243 dir = newDir2; 244 d = d2; 245 newN = normal2; 246 } 247 newV = R; 248 newX = mPos + R * d; 249 newR = normalize(reflect( newV, newN)); 250 251 Hit(newX, newR, DistanceMap, newTexCoord); 252 Color = readCubeMap(CubeMap, newTexCoord ); 253 } 254 255 //Color = float4(newDir2,1); 256 257 float ctheta_in = dot(IN.mNormal,R); 258 float ctheta_out = dot(IN.mNormal,-V); 259 260 float3 F = 0; 261 262 // F,P,G számítása 263 if ( ctheta_in > 0 && ctheta_out > 0 ) 264 { 265 float3 H = normalize(R - V); // felezõvektor 266 float cbeta = dot(H,R); 267 F = F0 + (1-F0)*pow(1-cbeta,5); 268 } 269 270 Color = Color * float4(F,1); 271 } 272 273 float4 NormalDistancePS( VertOut IN):COLOR 274 { 275 276 float4 Color = float4(0, 0, 0, 0); 277 //return Color; 278 Color = float4(normalize(IN.mNormal), length(IN.cPos)); 279 return Color; 280 }
Note: See TracChangeset
for help on using the changeset viewer.