Changeset 2062


Ignore:
Timestamp:
01/26/07 14:19:37 (17 years ago)
Author:
szirmay
Message:
 
File:
1 edited

Legend:

Unmodified
Added
Removed
  • GTP/trunk/App/Demos/Illum/EnvMap/EnvMap.fx

    r1672 r2062  
    3737float intensity, shininess, brightness; 
    3838 
    39  
     39float4 readCubeMap(samplerCUBE cm, float3 dir) 
     40{ 
     41 return texCUBElod(cm, float4(dir, 0)); 
     42} 
    4043//-------------------------------------------------------------------------------------- 
    4144// Textures & texture samplers 
     
    165168        // diffuse 
    166169        if (shininess <= 0)      
    167                 return 0.2 * fcos * texCUBE( SmallEnvironmentMapSampler, L); 
     170                return 0.2 * fcos * readCubeMap( SmallEnvironmentMapSampler, L); 
    168171        else 
    169172        { 
    170173                // some ad-hoc formula to avoid darkening 
    171174                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); 
    173176        } 
    174177} 
     
    289292        IN.Normal = normalize( IN.Normal );  
    290293         
    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); 
    292296 
    293297        if (shininess <= 0)     // diffuse 
    294                 return intensity * texCUBE(PreconvolvedEnvironmentMapSampler, IN.Normal) *2;             
     298                return intensity * readCubeMap(PreconvolvedEnvironmentMapSampler, IN.Normal) *2;                 
    295299        else                            // specular 
    296                 return intensity * texCUBE(PreconvolvedEnvironmentMapSampler, R) *2;     
     300                return intensity * readCubeMap(PreconvolvedEnvironmentMapSampler, R) *2;         
    297301} 
    298302 
     
    322326 
    323327        //Lin 
    324         float4 Lin = texCUBE(SmallEnvironmentMapSampler, L); 
     328        float4 Lin = readCubeMap(SmallEnvironmentMapSampler, L); 
    325329 
    326330        //dw 
     
    330334 
    331335        //r 
    332         float doy = texCUBE(SmallEnvironmentMapSampler, L).a; 
     336        float doy = readCubeMap(SmallEnvironmentMapSampler, L).a; 
    333337        float dxy = length(pos - L * doy); 
    334338 
     
    413417/// \brief Calculates diffuse or specular contributions of the 5 "most important" texels of #SmallEnvironmentMap to the current point. 
    414418/// For these texels, function GetContr(int,float3,float3,float3,float3) is called. 
    415  
     419/* 
    416420float4 EnvMapDiffuseLocalized5TexPS( _EnvMapVS_output IN ) : COLOR 
    417421{ 
     
    443447                offset2 = float3(0,0,1);                                                // select x,z 
    444448        }  
     449         
    445450 
    446451        I += GetContr( LR_CUBEMAP_SIZE, q, IN.Position, IN.Normal, IN.View ); 
     
    451456         
    452457        // 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.        
    454459        return intensity * I * LR_CUBEMAP_SIZE / 2;              
    455 } 
     460         
     461}*/ 
    456462 
    457463// Method #3 
     
    462468{ 
    463469        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;  
    466472        L1 = d * normalize(L1); 
    467         d = texCUBE(cubemap, L2).a;      
     473        d = readCubeMap(cubemap, L2).a;  
    468474        L2 = d * normalize(L2); 
    469         d = texCUBE(cubemap, L3).a;      
     475        d = readCubeMap(cubemap, L3).a;  
    470476        L3 = d * normalize(L3); 
    471         d = texCUBE(cubemap, L4).a;      
     477        d = readCubeMap(cubemap, L4).a;  
    472478        L4 = d * normalize(L4); 
    473479                 
     
    520526         
    521527        //return        reference_pos; 
    522         //return  texCUBE(SmallEnvironmentMapSampler, pos);      
     528        //return  readCubeMap(SmallEnvironmentMapSampler, pos);  
    523529                                                                                                 
    524530        float3 N =IN.Normal;                                                                                                                                                             
     
    547553                L4 = float3(p.x, p.y + width2, 1); 
    548554                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); 
    550556                 
    551557                I += 0.5 * Le * GetContibution( L, L1, L2, L3, L4, pos, N, SmallEnvironmentMapSampler);                  
     
    568574                L1 = float3(p.x, p.y + width2, -1); 
    569575                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); 
    571577                 
    572578                I += 0.5 * Le * GetContibution( L, L1, L2, L3, L4, pos, N, SmallEnvironmentMapSampler);                  
     
    588594                L1 = float3(p.x, 1, p.y + width2);                       
    589595                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); 
    591597                 
    592598                I += 0.5 * Le * GetContibution( L, L1, L2, L3, L4, pos, N, SmallEnvironmentMapSampler);                  
     
    608614                L4 = float3(p.x, -1, p.y + width2);                      
    609615                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); 
    611617                 
    612618                I += 0.5 * Le * GetContibution( L, L1, L2, L3, L4, pos, N, SmallEnvironmentMapSampler);                  
     
    628634                L4 = float3(1, p.x, p.y + width2);       
    629635                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); 
    631637                 
    632638                I += 0.5 * Le * GetContibution( L, L1, L2, L3, L4, pos, N, SmallEnvironmentMapSampler);                  
     
    648654                L1 = float3(-1, p.x, p.y + width2);      
    649655                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); 
    651657                 
    652658                I += 0.5 * Le * GetContibution( L, L1, L2, L3, L4, pos, N, SmallEnvironmentMapSampler);                          
     
    659665        Nl = normalize(Nl); 
    660666        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; 
    663669        float3 Lpos = L * d; 
    664670        float3 Ldir = Lpos - pos; 
     
    678684         
    679685        //return        reference_pos; 
    680         //return  texCUBE(SmallEnvironmentMapSampler, pos);      
     686        //return  readCubeMap(SmallEnvironmentMapSampler, pos);  
    681687                                                                                                 
    682688        float3 N =IN.Normal;                                                                                                                                                             
     
    709715} 
    710716 
     717float4 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/* 
    711760float4 EnvMapDiffuseAdaptPS( _EnvMapVS_output IN ) : COLOR                       
    712761{                
     
    718767         
    719768        //return        reference_pos; 
    720         //return  texCUBE(SmallEnvironmentMapSampler, pos);      
     769        //return  readCubeMap(SmallEnvironmentMapSampler, pos);  
    721770                                                                                                 
    722771        float3 N =IN.Normal;                                                                                                                                                             
     
    742791             
    743792            L = float3(p.x + width, p.y + width, 1); 
    744                 Ld = texCUBE(SmallEnvironmentMapSampler, L).a; 
     793                Ld = readCubeMap(SmallEnvironmentMapSampler, L).a; 
    745794                 
    746795                float dist = length(normalize(L) * Ld - pos); 
     
    751800                        L3 = float3(p.x + width2, p.y + width2, 1);      
    752801                        L4 = float3(p.x, p.y + width2, 1); 
    753                         Le = float4(texCUBE(SmallEnvironmentMapSampler, L).rgb, 1); 
     802                        Le = float4(readCubeMap(SmallEnvironmentMapSampler, L).rgb, 1); 
    754803                 
    755804                        I += 0.5 * Le * GetContibution( L, L1, L2, L3, L4, pos, N, SmallEnvironmentMapSampler); 
     
    771820             
    772821            L = float3(p.x + width, p.y + width, -1); 
    773                 Ld = texCUBE(SmallEnvironmentMapSampler, L).a; 
     822                Ld = readCubeMap(SmallEnvironmentMapSampler, L).a; 
    774823                 
    775824                float dist = length(normalize(L) * Ld - pos); 
     
    780829                        L2 = float3(p.x + width2, p.y + width2, -1);     
    781830                        L1 = float3(p.x, p.y + width2, -1); 
    782                         Le = float4(texCUBE(SmallEnvironmentMapSampler, L).rgb, 1); 
     831                        Le = float4(readCubeMap(SmallEnvironmentMapSampler, L).rgb, 1); 
    783832                         
    784833                        I += 0.5 * Le * GetContibution( L, L1, L2, L3, L4, pos, N, SmallEnvironmentMapSampler);                  
     
    799848             
    800849            L = float3(p.x + width, 1, p.y + width); 
    801                 Ld = texCUBE(SmallEnvironmentMapSampler, L).a; 
     850                Ld = readCubeMap(SmallEnvironmentMapSampler, L).a; 
    802851                 
    803852                float dist = length(normalize(L) * Ld - pos); 
     
    808857                        L2 = float3(p.x + width2, 1, p.y + width2);      
    809858                        L1 = float3(p.x, 1, p.y + width2);                       
    810                         Le = float4(texCUBE(SmallEnvironmentMapSampler, L).rgb, 1); 
     859                        Le = float4(readCubeMap(SmallEnvironmentMapSampler, L).rgb, 1); 
    811860                         
    812861                        I += 0.5 * Le * GetContibution( L, L1, L2, L3, L4, pos, N, SmallEnvironmentMapSampler);                  
     
    828877             
    829878            L = float3(p.x + width, -1, p.y + width); 
    830                 Ld = texCUBE(SmallEnvironmentMapSampler, L).a; 
     879                Ld = readCubeMap(SmallEnvironmentMapSampler, L).a; 
    831880                 
    832881                float dist = length(normalize(L) * Ld - pos); 
     
    837886                        L3 = float3(p.x + width2, -1, p.y + width2);     
    838887                        L4 = float3(p.x, -1, p.y + width2);                      
    839                         Le = float4(texCUBE(SmallEnvironmentMapSampler, L).rgb, 1); 
     888                        Le = float4(readCubeMap(SmallEnvironmentMapSampler, L).rgb, 1); 
    840889                         
    841890                        I += 0.5 * Le * GetContibution( L, L1, L2, L3, L4, pos, N, SmallEnvironmentMapSampler);                  
     
    857906             
    858907                L = float3(1, p.x + width, p.y + width); 
    859                 Ld = texCUBE(SmallEnvironmentMapSampler, L).a; 
     908                Ld = readCubeMap(SmallEnvironmentMapSampler, L).a; 
    860909                float dist = length(normalize(L) * Ld - pos); 
    861910                if(dist < 1.0) 
     
    865914                        L3 = float3(1, p.x + width2, p.y + width2);      
    866915                        L4 = float3(1, p.x, p.y + width2);       
    867                         Le = float4(texCUBE(SmallEnvironmentMapSampler, L).rgb, 1); 
     916                        Le = float4(readCubeMap(SmallEnvironmentMapSampler, L).rgb, 1); 
    868917                         
    869918                        I += 0.5 * Le * GetContibution( L, L1, L2, L3, L4, pos, N, SmallEnvironmentMapSampler);                  
     
    885934             
    886935            L = float3(-1, p.x + width, p.y + width); 
    887                 Ld = texCUBE(SmallEnvironmentMapSampler, L).a; 
     936                Ld = readCubeMap(SmallEnvironmentMapSampler, L).a; 
    888937                float dist = length(normalize(L) * Ld - pos); 
    889938                if(dist < 1.0) 
     
    893942                        L2 = float3(-1, p.x + width2, p.y + width2);     
    894943                        L1 = float3(-1, p.x, p.y + width2);      
    895                         Le = float4(texCUBE(SmallEnvironmentMapSampler, L).rgb, 1); 
     944                        Le = float4(readCubeMap(SmallEnvironmentMapSampler, L).rgb, 1); 
    896945                         
    897946                        I += 0.5 * Le * GetContibution( L, L1, L2, L3, L4, pos, N, SmallEnvironmentMapSampler);                          
     
    902951         }                                                                                                                                                               
    903952        return intensity * I;                                                                                                                    
    904 } 
     953}*/ 
    905954//-------------------------------------------------------------------------------------- 
    906955// Shading the environment 
     
    9551004                // if one of the cube maps should be displayed on the walls, 
    9561005                // display it 
    957             color = texCUBE(EnvironmentMapSampler, IN.Position) * intensity; 
     1006            color = readCubeMap(EnvironmentMapSampler, IN.Position) * intensity; 
    9581007    } 
    9591008    else if (brightness>0) 
     
    10011050TechniqueUsingCommonVS( EnvMapDiffuseLocalizedNew ); 
    10021051TechniqueUsingCommonVS( EnvMapDiffuseP2P ); 
    1003 TechniqueUsingCommonVS( EnvMapDiffuseAdapt ); 
     1052//TechniqueUsingCommonVS( EnvMapDiffuseAdapt ); 
    10041053 
    10051054#define ReduceTextureTechnique(M);                                                                      \ 
Note: See TracChangeset for help on using the changeset viewer.