Changeset 1672 for GTP/trunk/App/Demos/Illum/EnvMap/EnvMap.fx
- Timestamp:
- 10/24/06 08:38:56 (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/App/Demos/Illum/EnvMap/EnvMap.fx
r1575 r1672 532 532 float d; 533 533 534 for (float x = 0 .5; x < M; x++)535 for (float y = 0 .5; y < M; y++)534 for (float x = 0; x < M; x++) 535 for (float y = 0; y < M; y++) 536 536 { 537 537 float2 p, tpos; … … 542 542 p = 2.0 * p - 1.0; //-1..1 543 543 544 L1 = float3(p.x - width, p.y - width, 1);545 L2 = float3(p.x + width , p.y - width, 1);546 L3 = float3(p.x + width , p.y + width, 1);547 L4 = float3(p.x - width, p.y + width, 1);548 L = float3(p.x , p.y, 1);544 L1 = float3(p.x, p.y, 1); 545 L2 = float3(p.x + width2, p.y, 1); 546 L3 = float3(p.x + width2, p.y + width2, 1); 547 L4 = float3(p.x, p.y + width2, 1); 548 L = float3(p.x + width, p.y + width, 1); 549 549 Le = float4(texCUBE(SmallEnvironmentMapSampler, L).rgb, 1); 550 550 … … 553 553 } 554 554 555 for (float x = 0 .5; x < M; x++)556 for (float y = 0 .5; y < M; y++)555 for (float x = 0; x < M; x++) 556 for (float y = 0; y < M; y++) 557 557 { 558 558 float2 p, tpos; … … 563 563 p = 2.0 * p - 1.0; //-1..1 564 564 565 L4 = float3(p.x - width, p.y - width, -1);566 L3 = float3(p.x + width , p.y - width, -1);567 L2 = float3(p.x + width , p.y + width, -1);568 L1 = float3(p.x - width, p.y + width, -1);569 L = float3(p.x , p.y, -1);565 L4 = float3(p.x, p.y, -1); 566 L3 = float3(p.x + width2, p.y, -1); 567 L2 = float3(p.x + width2, p.y + width2, -1); 568 L1 = float3(p.x, p.y + width2, -1); 569 L = float3(p.x + width, p.y + width, -1); 570 570 Le = float4(texCUBE(SmallEnvironmentMapSampler, L).rgb, 1); 571 571 … … 573 573 } 574 574 575 for (float x = 0 .5; x < M; x++)576 for (float y = 0 .5; y < M; y++)575 for (float x = 0; x < M; x++) 576 for (float y = 0; y < M; y++) 577 577 { 578 578 float2 p, tpos; … … 583 583 p = 2.0 * p - 1.0; //-1..1 584 584 585 L4 = float3(p.x - width, 1, p.y - width);586 L3 = float3(p.x + width , 1, p.y - width);587 L2 = float3(p.x + width , 1, p.y + width);588 L1 = float3(p.x - width, 1, p.y + width);589 L = float3(p.x , 1, p.y);585 L4 = float3(p.x, 1, p.y); 586 L3 = float3(p.x + width2, 1, p.y); 587 L2 = float3(p.x + width2, 1, p.y + width2); 588 L1 = float3(p.x, 1, p.y + width2); 589 L = float3(p.x + width, 1, p.y + width); 590 590 Le = float4(texCUBE(SmallEnvironmentMapSampler, L).rgb, 1); 591 591 … … 593 593 } 594 594 595 for (float x = 0 .5; x < M; x++)596 for (float y = 0 .5; y < M; y++)595 for (float x = 0; x < M; x++) 596 for (float y = 0; y < M; y++) 597 597 { 598 598 float2 p, tpos; … … 603 603 p = 2.0 * p - 1.0; //-1..1 604 604 605 L1 = float3(p.x - width, -1, p.y - width);606 L2 = float3(p.x + width , -1, p.y - width);607 L3 = float3(p.x + width , -1, p.y + width);608 L4 = float3(p.x - width, -1, p.y + width);609 L = float3(p.x , -1, p.y);605 L1 = float3(p.x, -1, p.y); 606 L2 = float3(p.x + width2, -1, p.y); 607 L3 = float3(p.x + width2, -1, p.y + width2); 608 L4 = float3(p.x, -1, p.y + width2); 609 L = float3(p.x + width, -1, p.y + width); 610 610 Le = float4(texCUBE(SmallEnvironmentMapSampler, L).rgb, 1); 611 611 … … 613 613 } 614 614 615 for (float x = 0 .5; x < M; x++)616 for (float y = 0 .5; y < M; y++)615 for (float x = 0; x < M; x++) 616 for (float y = 0; y < M; y++) 617 617 { 618 618 float2 p, tpos; … … 623 623 p = 2.0 * p - 1.0; //-1..1 624 624 625 L1 = float3(1, p.x - width, p.y - width);626 L2 = float3(1, p.x + width , p.y - width);627 L3 = float3(1, p.x + width , p.y + width);628 L4 = float3(1, p.x - width, p.y + width);629 L = float3(1, p.x , p.y);625 L1 = float3(1, p.x, p.y); 626 L2 = float3(1, p.x + width2, p.y); 627 L3 = float3(1, p.x + width2, p.y + width2); 628 L4 = float3(1, p.x, p.y + width2); 629 L = float3(1, p.x + width, p.y + width); 630 630 Le = float4(texCUBE(SmallEnvironmentMapSampler, L).rgb, 1); 631 631 … … 633 633 } 634 634 635 for (float x = 0 .5; x < M; x++)636 for (float y = 0 .5; y < M; y++)635 for (float x = 0; x < M; x++) 636 for (float y = 0; y < M; y++) 637 637 { 638 638 float2 p, tpos; … … 643 643 p = 2.0 * p - 1.0; //-1..1 644 644 645 L4 = float3(-1, p.x - width, p.y - width);646 L3 = float3(-1, p.x + width , p.y - width);647 L2 = float3(-1, p.x + width , p.y + width);648 L1 = float3(-1, p.x - width, p.y + width);649 L = float3(-1, p.x , p.y);645 L4 = float3(-1, p.x, p.y); 646 L3 = float3(-1, p.x + width2, p.y); 647 L2 = float3(-1, p.x + width2, p.y + width2); 648 L1 = float3(-1, p.x, p.y + width2); 649 L = float3(-1, p.x + width, p.y + width); 650 650 Le = float4(texCUBE(SmallEnvironmentMapSampler, L).rgb, 1); 651 651 … … 706 706 } 707 707 708 return intensity * I; 709 } 710 711 float4 EnvMapDiffuseAdaptPS( _EnvMapVS_output IN ) : COLOR 712 { 713 float M = 4.0; 714 IN.View = -normalize( IN.View ); 715 IN.Normal = normalize( IN.Normal ); 716 IN.Position -= reference_pos.xyz; 717 float3 pos = IN.Position.xyz; 718 719 //return reference_pos; 720 //return texCUBE(SmallEnvironmentMapSampler, pos); 721 722 float3 N =IN.Normal; 723 float3 R = -reflect( IN.View, IN.Normal ); 724 725 float4 I = 0; 726 float3 L1, L2, L3, L4, L; 727 float4 Le; 728 float Ld; 729 float width = 1.0 / M; 730 float width2 = width * 2; 731 float d; 732 733 for (float x = 0; x < M; x++) 734 for (float y = 0; y < M; y++) 735 { 736 float2 p, tpos; 737 tpos.x = x * width; 738 tpos.y = y * width; 739 740 p = tpos.xy; 741 p = 2.0 * p - 1.0; //-1..1 742 743 L = float3(p.x + width, p.y + width, 1); 744 Ld = texCUBE(SmallEnvironmentMapSampler, L).a; 745 746 float dist = length(normalize(L) * Ld - pos); 747 if(dist < 1.0) 748 { 749 L1 = float3(p.x, p.y, 1); 750 L2 = float3(p.x + width2, p.y, 1); 751 L3 = float3(p.x + width2, p.y + width2, 1); 752 L4 = float3(p.x, p.y + width2, 1); 753 Le = float4(texCUBE(SmallEnvironmentMapSampler, L).rgb, 1); 754 755 I += 0.5 * Le * GetContibution( L, L1, L2, L3, L4, pos, N, SmallEnvironmentMapSampler); 756 } 757 else 758 I += P2PContr(N, float3(0,0,-1), pos, L, SmallEnvironmentMapSampler); 759 760 } 761 762 for (float x = 0; x < M; x++) 763 for (float y = 0; y < M; y++) 764 { 765 float2 p, tpos; 766 tpos.x = x * width; // 0..1 767 tpos.y = y * width; // 0..1 768 769 p = tpos.xy; 770 p = 2.0 * p - 1.0; //-1..1 771 772 L = float3(p.x + width, p.y + width, -1); 773 Ld = texCUBE(SmallEnvironmentMapSampler, L).a; 774 775 float dist = length(normalize(L) * Ld - pos); 776 if(dist < 1.0) 777 { 778 L4 = float3(p.x, p.y, -1); 779 L3 = float3(p.x + width2, p.y, -1); 780 L2 = float3(p.x + width2, p.y + width2, -1); 781 L1 = float3(p.x, p.y + width2, -1); 782 Le = float4(texCUBE(SmallEnvironmentMapSampler, L).rgb, 1); 783 784 I += 0.5 * Le * GetContibution( L, L1, L2, L3, L4, pos, N, SmallEnvironmentMapSampler); 785 } 786 else 787 I += P2PContr(N, float3(0,0,1), pos, L, SmallEnvironmentMapSampler); 788 } 789 790 for (float x = 0; x < M; x++) 791 for (float y = 0; y < M; y++) 792 { 793 float2 p, tpos; 794 tpos.x = x * width; // 0..1 795 tpos.y = y * width; // 0..1 796 797 p = tpos.xy; 798 p = 2.0 * p - 1.0; //-1..1 799 800 L = float3(p.x + width, 1, p.y + width); 801 Ld = texCUBE(SmallEnvironmentMapSampler, L).a; 802 803 float dist = length(normalize(L) * Ld - pos); 804 if(dist < 1.0) 805 { 806 L4 = float3(p.x, 1, p.y); 807 L3 = float3(p.x + width2, 1, p.y); 808 L2 = float3(p.x + width2, 1, p.y + width2); 809 L1 = float3(p.x, 1, p.y + width2); 810 Le = float4(texCUBE(SmallEnvironmentMapSampler, L).rgb, 1); 811 812 I += 0.5 * Le * GetContibution( L, L1, L2, L3, L4, pos, N, SmallEnvironmentMapSampler); 813 } 814 else 815 I += P2PContr(N, float3(0,-1,0), pos, L, SmallEnvironmentMapSampler); 816 817 } 818 819 for (float x = 0; x < M; x++) 820 for (float y = 0; y < M; y++) 821 { 822 float2 p, tpos; 823 tpos.x = x * width; // 0..1 824 tpos.y = y * width; // 0..1 825 826 p = tpos.xy; 827 p = 2.0 * p - 1.0; //-1..1 828 829 L = float3(p.x + width, -1, p.y + width); 830 Ld = texCUBE(SmallEnvironmentMapSampler, L).a; 831 832 float dist = length(normalize(L) * Ld - pos); 833 if(dist < 1.0) 834 { 835 L1 = float3(p.x, -1, p.y); 836 L2 = float3(p.x + width2, -1, p.y); 837 L3 = float3(p.x + width2, -1, p.y + width2); 838 L4 = float3(p.x, -1, p.y + width2); 839 Le = float4(texCUBE(SmallEnvironmentMapSampler, L).rgb, 1); 840 841 I += 0.5 * Le * GetContibution( L, L1, L2, L3, L4, pos, N, SmallEnvironmentMapSampler); 842 } 843 else 844 I += P2PContr(N, float3(0,1,0), pos, L, SmallEnvironmentMapSampler); 845 846 } 847 848 for (float x = 0; x < M; x++) 849 for (float y = 0; y < M; y++) 850 { 851 float2 p, tpos; 852 tpos.x = x * width; // 0..1 853 tpos.y = y * width; // 0..1 854 855 p = tpos.xy; 856 p = 2.0 * p - 1.0; //-1..1 857 858 L = float3(1, p.x + width, p.y + width); 859 Ld = texCUBE(SmallEnvironmentMapSampler, L).a; 860 float dist = length(normalize(L) * Ld - pos); 861 if(dist < 1.0) 862 { 863 L1 = float3(1, p.x, p.y); 864 L2 = float3(1, p.x + width2, p.y); 865 L3 = float3(1, p.x + width2, p.y + width2); 866 L4 = float3(1, p.x, p.y + width2); 867 Le = float4(texCUBE(SmallEnvironmentMapSampler, L).rgb, 1); 868 869 I += 0.5 * Le * GetContibution( L, L1, L2, L3, L4, pos, N, SmallEnvironmentMapSampler); 870 } 871 else 872 I += P2PContr(N, float3(-1,0,0), pos, L, SmallEnvironmentMapSampler); 873 874 } 875 876 for (float x = 0; x < M; x++) 877 for (float y = 0; y < M; y++) 878 { 879 float2 p, tpos; 880 tpos.x = x * width; // 0..1 881 tpos.y = y * width; // 0..1 882 883 p = tpos.xy; 884 p = 2.0 * p - 1.0; //-1..1 885 886 L = float3(-1, p.x + width, p.y + width); 887 Ld = texCUBE(SmallEnvironmentMapSampler, L).a; 888 float dist = length(normalize(L) * Ld - pos); 889 if(dist < 1.0) 890 { 891 L4 = float3(-1, p.x, p.y); 892 L3 = float3(-1, p.x + width2, p.y); 893 L2 = float3(-1, p.x + width2, p.y + width2); 894 L1 = float3(-1, p.x, p.y + width2); 895 Le = float4(texCUBE(SmallEnvironmentMapSampler, L).rgb, 1); 896 897 I += 0.5 * Le * GetContibution( L, L1, L2, L3, L4, pos, N, SmallEnvironmentMapSampler); 898 899 } 900 else 901 I += P2PContr(N, float3(1,0,0), pos, L, SmallEnvironmentMapSampler); 902 } 708 903 return intensity * I; 709 904 } … … 806 1001 TechniqueUsingCommonVS( EnvMapDiffuseLocalizedNew ); 807 1002 TechniqueUsingCommonVS( EnvMapDiffuseP2P ); 808 //TechniqueUsingCommonVS( EnvMapDiffuseLocalizedNew4 ); 809 //TechniqueUsingCommonVS( EnvMapDiffuseLocalizedNew8 ); 810 //TechniqueUsingCommonVS( EnvMapDiffuseLocalizedNew16 ); 1003 TechniqueUsingCommonVS( EnvMapDiffuseAdapt ); 811 1004 812 1005 #define ReduceTextureTechnique(M); \
Note: See TracChangeset
for help on using the changeset viewer.