Changeset 2062
- Timestamp:
- 01/26/07 14:19:37 (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/App/Demos/Illum/EnvMap/EnvMap.fx
r1672 r2062 37 37 float intensity, shininess, brightness; 38 38 39 39 float4 readCubeMap(samplerCUBE cm, float3 dir) 40 { 41 return texCUBElod(cm, float4(dir, 0)); 42 } 40 43 //-------------------------------------------------------------------------------------- 41 44 // Textures & texture samplers … … 165 168 // diffuse 166 169 if (shininess <= 0) 167 return 0.2 * fcos * texCUBE( SmallEnvironmentMapSampler, L);170 return 0.2 * fcos * readCubeMap( SmallEnvironmentMapSampler, L); 168 171 else 169 172 { 170 173 // some ad-hoc formula to avoid darkening 171 174 float brightness = (pow(shininess,0.8)*0.2); 172 return brightness * pow(fcos, shininess) * texCUBE( SmallEnvironmentMapSampler, L);175 return brightness * pow(fcos, shininess) * readCubeMap( SmallEnvironmentMapSampler, L); 173 176 } 174 177 } … … 289 292 IN.Normal = normalize( IN.Normal ); 290 293 291 float3 R = reflect(IN.View, IN.Normal); 294 //float3 R = reflect(IN.View, IN.Normal); 295 float3 R = refract(IN.View, IN.Normal, 1); 292 296 293 297 if (shininess <= 0) // diffuse 294 return intensity * texCUBE(PreconvolvedEnvironmentMapSampler, IN.Normal) *2;298 return intensity * readCubeMap(PreconvolvedEnvironmentMapSampler, IN.Normal) *2; 295 299 else // specular 296 return intensity * texCUBE(PreconvolvedEnvironmentMapSampler, R) *2;300 return intensity * readCubeMap(PreconvolvedEnvironmentMapSampler, R) *2; 297 301 } 298 302 … … 322 326 323 327 //Lin 324 float4 Lin = texCUBE(SmallEnvironmentMapSampler, L);328 float4 Lin = readCubeMap(SmallEnvironmentMapSampler, L); 325 329 326 330 //dw … … 330 334 331 335 //r 332 float doy = texCUBE(SmallEnvironmentMapSampler, L).a;336 float doy = readCubeMap(SmallEnvironmentMapSampler, L).a; 333 337 float dxy = length(pos - L * doy); 334 338 … … 413 417 /// \brief Calculates diffuse or specular contributions of the 5 "most important" texels of #SmallEnvironmentMap to the current point. 414 418 /// For these texels, function GetContr(int,float3,float3,float3,float3) is called. 415 419 /* 416 420 float4 EnvMapDiffuseLocalized5TexPS( _EnvMapVS_output IN ) : COLOR 417 421 { … … 443 447 offset2 = float3(0,0,1); // select x,z 444 448 } 449 445 450 446 451 I += GetContr( LR_CUBEMAP_SIZE, q, IN.Position, IN.Normal, IN.View ); … … 451 456 452 457 // since only 5 texels are considered, the result gets darker. 453 // LR_CUBEMAP_SIZE is present to compensate this. 458 // LR_CUBEMAP_SIZE is present to compensate this. 454 459 return intensity * I * LR_CUBEMAP_SIZE / 2; 455 } 460 461 }*/ 456 462 457 463 // Method #3 … … 462 468 { 463 469 float d; 464 //d = texCUBE(cubemap, L).a;465 d = texCUBE(cubemap, L1).a;470 //d = readCubeMap(cubemap, L).a; 471 d = readCubeMap(cubemap, L1).a; 466 472 L1 = d * normalize(L1); 467 d = texCUBE(cubemap, L2).a;473 d = readCubeMap(cubemap, L2).a; 468 474 L2 = d * normalize(L2); 469 d = texCUBE(cubemap, L3).a;475 d = readCubeMap(cubemap, L3).a; 470 476 L3 = d * normalize(L3); 471 d = texCUBE(cubemap, L4).a;477 d = readCubeMap(cubemap, L4).a; 472 478 L4 = d * normalize(L4); 473 479 … … 520 526 521 527 //return reference_pos; 522 //return texCUBE(SmallEnvironmentMapSampler, pos);528 //return readCubeMap(SmallEnvironmentMapSampler, pos); 523 529 524 530 float3 N =IN.Normal; … … 547 553 L4 = float3(p.x, p.y + width2, 1); 548 554 L = float3(p.x + width, p.y + width, 1); 549 Le = float4( texCUBE(SmallEnvironmentMapSampler, L).rgb, 1);555 Le = float4(readCubeMap(SmallEnvironmentMapSampler, L).rgb, 1); 550 556 551 557 I += 0.5 * Le * GetContibution( L, L1, L2, L3, L4, pos, N, SmallEnvironmentMapSampler); … … 568 574 L1 = float3(p.x, p.y + width2, -1); 569 575 L = float3(p.x + width, p.y + width, -1); 570 Le = float4( texCUBE(SmallEnvironmentMapSampler, L).rgb, 1);576 Le = float4(readCubeMap(SmallEnvironmentMapSampler, L).rgb, 1); 571 577 572 578 I += 0.5 * Le * GetContibution( L, L1, L2, L3, L4, pos, N, SmallEnvironmentMapSampler); … … 588 594 L1 = float3(p.x, 1, p.y + width2); 589 595 L = float3(p.x + width, 1, p.y + width); 590 Le = float4( texCUBE(SmallEnvironmentMapSampler, L).rgb, 1);596 Le = float4(readCubeMap(SmallEnvironmentMapSampler, L).rgb, 1); 591 597 592 598 I += 0.5 * Le * GetContibution( L, L1, L2, L3, L4, pos, N, SmallEnvironmentMapSampler); … … 608 614 L4 = float3(p.x, -1, p.y + width2); 609 615 L = float3(p.x + width, -1, p.y + width); 610 Le = float4( texCUBE(SmallEnvironmentMapSampler, L).rgb, 1);616 Le = float4(readCubeMap(SmallEnvironmentMapSampler, L).rgb, 1); 611 617 612 618 I += 0.5 * Le * GetContibution( L, L1, L2, L3, L4, pos, N, SmallEnvironmentMapSampler); … … 628 634 L4 = float3(1, p.x, p.y + width2); 629 635 L = float3(1, p.x + width, p.y + width); 630 Le = float4( texCUBE(SmallEnvironmentMapSampler, L).rgb, 1);636 Le = float4(readCubeMap(SmallEnvironmentMapSampler, L).rgb, 1); 631 637 632 638 I += 0.5 * Le * GetContibution( L, L1, L2, L3, L4, pos, N, SmallEnvironmentMapSampler); … … 648 654 L1 = float3(-1, p.x, p.y + width2); 649 655 L = float3(-1, p.x + width, p.y + width); 650 Le = float4( texCUBE(SmallEnvironmentMapSampler, L).rgb, 1);656 Le = float4(readCubeMap(SmallEnvironmentMapSampler, L).rgb, 1); 651 657 652 658 I += 0.5 * Le * GetContibution( L, L1, L2, L3, L4, pos, N, SmallEnvironmentMapSampler); … … 659 665 Nl = normalize(Nl); 660 666 L = normalize(L); 661 float4 Le = float4( texCUBE(cubemap, L).rgb, 1);662 float d = texCUBE(cubemap, L).a;667 float4 Le = float4(readCubeMap(cubemap, L).rgb, 1); 668 float d = readCubeMap(cubemap, L).a; 663 669 float3 Lpos = L * d; 664 670 float3 Ldir = Lpos - pos; … … 678 684 679 685 //return reference_pos; 680 //return texCUBE(SmallEnvironmentMapSampler, pos);686 //return readCubeMap(SmallEnvironmentMapSampler, pos); 681 687 682 688 float3 N =IN.Normal; … … 709 715 } 710 716 717 float4 EnvMapDiffuseLocalized5TexPS( _EnvMapVS_output IN ) : COLOR 718 { 719 IN.View = -normalize( IN.View ); 720 IN.Normal = normalize( IN.Normal ); 721 // translate reference point to the origin 722 IN.Position -= reference_pos.xyz; 723 724 float3 R = -reflect( IN.View, IN.Normal ); // reflection direction 725 726 float4 I = 0; 727 728 float3 q; 729 if ( shininess <= 0 ) 730 q = IN.Normal; // diffuse 731 else 732 q = R; 733 734 float rr = max( max(abs(q.x), abs(q.y)), abs(q.z) ); // select the largest component 735 q /= rr; // scale the largest component to value +/-1 736 737 float3 offset1 = float3(1,0,0); // default: largest: z 738 float3 offset2 = float3(0,1,0); // select: x,y 739 740 if (abs(q.x) > abs(q.y) && abs(q.x) > abs(q.z)) { // largest: x 741 offset1 = float3(0,0,1); // select y,z 742 } 743 if (abs(q.y) > abs(q.x) && abs(q.y) > abs(q.z)) { // largest: y 744 offset2 = float3(0,0,1); // select x,z 745 } 746 747 748 I += GetContr( LR_CUBEMAP_SIZE, q, IN.Position, IN.Normal, IN.View ); 749 I += GetContr( LR_CUBEMAP_SIZE, q + offset1*(2.0/LR_CUBEMAP_SIZE), IN.Position, IN.Normal, IN.View ); 750 I += GetContr( LR_CUBEMAP_SIZE, q - offset1*(2.0/LR_CUBEMAP_SIZE), IN.Position, IN.Normal, IN.View ); 751 I += GetContr( LR_CUBEMAP_SIZE, q + offset2*(2.0/LR_CUBEMAP_SIZE), IN.Position, IN.Normal, IN.View ); 752 I += GetContr( LR_CUBEMAP_SIZE, q - offset2*(2.0/LR_CUBEMAP_SIZE), IN.Position, IN.Normal, IN.View ); 753 754 // since only 5 texels are considered, the result gets darker. 755 // LR_CUBEMAP_SIZE is present to compensate this. 756 return intensity * I * LR_CUBEMAP_SIZE / 2; 757 758 } 759 /* 711 760 float4 EnvMapDiffuseAdaptPS( _EnvMapVS_output IN ) : COLOR 712 761 { … … 718 767 719 768 //return reference_pos; 720 //return texCUBE(SmallEnvironmentMapSampler, pos);769 //return readCubeMap(SmallEnvironmentMapSampler, pos); 721 770 722 771 float3 N =IN.Normal; … … 742 791 743 792 L = float3(p.x + width, p.y + width, 1); 744 Ld = texCUBE(SmallEnvironmentMapSampler, L).a;793 Ld = readCubeMap(SmallEnvironmentMapSampler, L).a; 745 794 746 795 float dist = length(normalize(L) * Ld - pos); … … 751 800 L3 = float3(p.x + width2, p.y + width2, 1); 752 801 L4 = float3(p.x, p.y + width2, 1); 753 Le = float4( texCUBE(SmallEnvironmentMapSampler, L).rgb, 1);802 Le = float4(readCubeMap(SmallEnvironmentMapSampler, L).rgb, 1); 754 803 755 804 I += 0.5 * Le * GetContibution( L, L1, L2, L3, L4, pos, N, SmallEnvironmentMapSampler); … … 771 820 772 821 L = float3(p.x + width, p.y + width, -1); 773 Ld = texCUBE(SmallEnvironmentMapSampler, L).a;822 Ld = readCubeMap(SmallEnvironmentMapSampler, L).a; 774 823 775 824 float dist = length(normalize(L) * Ld - pos); … … 780 829 L2 = float3(p.x + width2, p.y + width2, -1); 781 830 L1 = float3(p.x, p.y + width2, -1); 782 Le = float4( texCUBE(SmallEnvironmentMapSampler, L).rgb, 1);831 Le = float4(readCubeMap(SmallEnvironmentMapSampler, L).rgb, 1); 783 832 784 833 I += 0.5 * Le * GetContibution( L, L1, L2, L3, L4, pos, N, SmallEnvironmentMapSampler); … … 799 848 800 849 L = float3(p.x + width, 1, p.y + width); 801 Ld = texCUBE(SmallEnvironmentMapSampler, L).a;850 Ld = readCubeMap(SmallEnvironmentMapSampler, L).a; 802 851 803 852 float dist = length(normalize(L) * Ld - pos); … … 808 857 L2 = float3(p.x + width2, 1, p.y + width2); 809 858 L1 = float3(p.x, 1, p.y + width2); 810 Le = float4( texCUBE(SmallEnvironmentMapSampler, L).rgb, 1);859 Le = float4(readCubeMap(SmallEnvironmentMapSampler, L).rgb, 1); 811 860 812 861 I += 0.5 * Le * GetContibution( L, L1, L2, L3, L4, pos, N, SmallEnvironmentMapSampler); … … 828 877 829 878 L = float3(p.x + width, -1, p.y + width); 830 Ld = texCUBE(SmallEnvironmentMapSampler, L).a;879 Ld = readCubeMap(SmallEnvironmentMapSampler, L).a; 831 880 832 881 float dist = length(normalize(L) * Ld - pos); … … 837 886 L3 = float3(p.x + width2, -1, p.y + width2); 838 887 L4 = float3(p.x, -1, p.y + width2); 839 Le = float4( texCUBE(SmallEnvironmentMapSampler, L).rgb, 1);888 Le = float4(readCubeMap(SmallEnvironmentMapSampler, L).rgb, 1); 840 889 841 890 I += 0.5 * Le * GetContibution( L, L1, L2, L3, L4, pos, N, SmallEnvironmentMapSampler); … … 857 906 858 907 L = float3(1, p.x + width, p.y + width); 859 Ld = texCUBE(SmallEnvironmentMapSampler, L).a;908 Ld = readCubeMap(SmallEnvironmentMapSampler, L).a; 860 909 float dist = length(normalize(L) * Ld - pos); 861 910 if(dist < 1.0) … … 865 914 L3 = float3(1, p.x + width2, p.y + width2); 866 915 L4 = float3(1, p.x, p.y + width2); 867 Le = float4( texCUBE(SmallEnvironmentMapSampler, L).rgb, 1);916 Le = float4(readCubeMap(SmallEnvironmentMapSampler, L).rgb, 1); 868 917 869 918 I += 0.5 * Le * GetContibution( L, L1, L2, L3, L4, pos, N, SmallEnvironmentMapSampler); … … 885 934 886 935 L = float3(-1, p.x + width, p.y + width); 887 Ld = texCUBE(SmallEnvironmentMapSampler, L).a;936 Ld = readCubeMap(SmallEnvironmentMapSampler, L).a; 888 937 float dist = length(normalize(L) * Ld - pos); 889 938 if(dist < 1.0) … … 893 942 L2 = float3(-1, p.x + width2, p.y + width2); 894 943 L1 = float3(-1, p.x, p.y + width2); 895 Le = float4( texCUBE(SmallEnvironmentMapSampler, L).rgb, 1);944 Le = float4(readCubeMap(SmallEnvironmentMapSampler, L).rgb, 1); 896 945 897 946 I += 0.5 * Le * GetContibution( L, L1, L2, L3, L4, pos, N, SmallEnvironmentMapSampler); … … 902 951 } 903 952 return intensity * I; 904 } 953 }*/ 905 954 //-------------------------------------------------------------------------------------- 906 955 // Shading the environment … … 955 1004 // if one of the cube maps should be displayed on the walls, 956 1005 // display it 957 color = texCUBE(EnvironmentMapSampler, IN.Position) * intensity;1006 color = readCubeMap(EnvironmentMapSampler, IN.Position) * intensity; 958 1007 } 959 1008 else if (brightness>0) … … 1001 1050 TechniqueUsingCommonVS( EnvMapDiffuseLocalizedNew ); 1002 1051 TechniqueUsingCommonVS( EnvMapDiffuseP2P ); 1003 TechniqueUsingCommonVS( EnvMapDiffuseAdapt );1052 //TechniqueUsingCommonVS( EnvMapDiffuseAdapt ); 1004 1053 1005 1054 #define ReduceTextureTechnique(M); \
Note: See TracChangeset
for help on using the changeset viewer.