Ignore:
Timestamp:
10/05/06 13:43:54 (18 years ago)
Author:
szirmay
Message:
 
File:
1 edited

Legend:

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

    r1556 r1573  
    459459/// \brief Calculates diffuse or specular contributions of the 5 "most important" texels of #SmallEnvironmentMap to the current point. 
    460460/// For these texels, function GetContr(int,float3,float3,float3,float3) is called. 
    461 float4 GetContibution(float3 L1, float3 L2, float3 L3, float3 L4, float3 pos, float3 N, float d) 
    462 { 
     461float4 GetContibution(float3 L, float3 L1, float3 L2, float3 L3, float3 L4, float3 pos, float3 N, samplerCUBE cubemap) 
     462{ 
     463        float d; 
     464        d = texCUBE(cubemap, L).a;       
     465        //d = texCUBE(cubemap, L1).a;    
    463466        L1 = d * normalize(L1); 
     467        //d = texCUBE(cubemap, L2).a;    
    464468        L2 = d * normalize(L2); 
    465         L3 = d *  normalize(L3); 
    466         L4 = d * normalize(L4);  
     469        //d = texCUBE(cubemap, L3).a;    
     470        L3 = d * normalize(L3); 
     471        //d = texCUBE(cubemap, L4).a;    
     472        L4 = d * normalize(L4); 
     473                 
    467474         
    468475    float3 r1 = normalize(L1 - pos);     
     
    470477    float3 r3 = normalize(L3 - pos); 
    471478    float3 r4 = normalize(L4 - pos); 
    472     
    473      
    474         float kd = 0.3; // 0.3 
    475         /* 
    476         float3 R; 
    477         R = cross(r1, r2); 
    478         float tri1 = asin(length(R)) * dot(R, N); 
    479         R = cross(r2, r3); 
    480         float tri2 = asin(length(R)) * dot(R, N); 
    481         R = cross(r3, r4); 
    482         float tri3 = asin(length(R)) * dot(R, N); 
    483         R = cross(r4, r1); 
    484         float tri4 = asin(length(R)) * dot(R, N); 
    485         */ 
    486          
     479         
    487480        float tri1 = acos(dot(r1, r2)) * dot(cross(r1, r2), N); 
    488481        float tri2 = acos(dot(r2, r3)) * dot(cross(r2, r3), N); 
     
    493486        //return tri1 + tri2 + tri3 + tri4;      
    494487} 
     488 
     489 
     490 
    495491 
    496492float4 EnvMapDiffuseLocalizedNewPS( _EnvMapVS_output IN ) : COLOR                        
     
    511507        float3 L1, L2, L3, L4, L;                                                
    512508        float4 Le;                                                                               
    513         float d;                                                                                 
    514509        float width = 1.0 / M;                                                   
    515          
    516         for (int x = 0; x < M; x++)                      
    517          for (int y = 0; y < M; y++)                                                                                     
     510        float width2 = width * 2; 
     511        float d;  
     512         
     513        for (float x = 0.5; x < M; x++)                  
     514         for (float y = 0.5; y < M; y++)                                                                                         
    518515         {                                                                                                                               
    519516                float2 p, tpos;  
    520             tpos.x = (x + 0.5) * width; // 0..1 
    521             tpos.y = (y + 0.5) * width; // 0..1 
     517            tpos.x = x * width; 
     518            tpos.y = y * width; 
    522519             
    523520            p = tpos.xy;     
     
    530527                L = float3(p.x, p.y, 1); 
    531528                Le = float4(texCUBE(SmallEnvironmentMapSampler, L).rgb, 1); 
    532                 d = texCUBE(SmallEnvironmentMapSampler, L).a;    
    533529                 
    534                 I += 0.5 * Le * GetContibution( L1, L2, L3, L4, pos, N, d);                      
    535                 //I += Le / 16.0; 
    536          }                                                                                                                                                       
     530                I += 0.5 * Le * GetContibution( L, L1, L2, L3, L4, pos, N, SmallEnvironmentMapSampler);                  
    537531                         
    538         for (int x = 0; x < M; x++)                      
    539          for (int y = 0; y < M; y++)                                                                                     
     532        }                                                                                                                                                        
     533         
     534        for (float x = 0; x < M; x++)                    
     535         for (float y = 0; y < M; y++)                                                                                   
    540536         {                                                                                                                               
    541537                float2 p, tpos;  
    542             tpos.x = (x + 0.5) * width; // 0..1 
    543             tpos.y = (y + 0.5) * width; // 0..1 
     538            tpos.x = x * width; // 0..1 
     539            tpos.y = y * width; // 0..1 
    544540             
    545541            p = tpos.xy;     
     
    552548                L = float3(p.x, p.y, -1); 
    553549                Le = float4(texCUBE(SmallEnvironmentMapSampler, L).rgb, 1); 
    554                 d = texCUBE(SmallEnvironmentMapSampler, L).a;    
    555550                 
    556                 I += 0.5 * Le * GetContibution( L1, L2, L3, L4, pos, N, d);                      
    557                 //I += Le / 16.0; 
     551                I += 0.5 * Le * GetContibution( L, L1, L2, L3, L4, pos, N, SmallEnvironmentMapSampler);                  
    558552         }       
    559553          
    560         for (int x = 0; x < M; x++)                      
    561          for (int y = 0; y < M; y++)                                                                                     
     554        for (float x = 0; x < M; x++)                    
     555         for (float y = 0; y < M; y++)                                                                                   
    562556         {                                                                                                                               
    563557                float2 p, tpos;  
    564             tpos.x = (x + 0.5) * width; // 0..1 
    565             tpos.y = (y + 0.5) * width; // 0..1 
     558            tpos.x = x * width; // 0..1 
     559            tpos.y = y * width; // 0..1 
    566560             
    567561            p = tpos.xy;     
     
    574568                L = float3(p.x, 1, p.y); 
    575569                Le = float4(texCUBE(SmallEnvironmentMapSampler, L).rgb, 1); 
    576                 d = texCUBE(SmallEnvironmentMapSampler, L).a;    
    577570                 
    578                 I += 0.5 * Le * GetContibution( L1, L2, L3, L4, pos, N, d);                      
    579                 //I += Le / 16.0; 
     571                I += 0.5 * Le * GetContibution( L, L1, L2, L3, L4, pos, N, SmallEnvironmentMapSampler);                  
    580572         }               
    581573          
    582         for (int x = 0; x < M; x++)                      
    583          for (int y = 0; y < M; y++)                                                                                     
     574        for (float x = 0; x < M; x++)                    
     575         for (float y = 0; y < M; y++)                                                                                   
    584576         {                                                                                                                               
    585577                float2 p, tpos;  
    586             tpos.x = (x + 0.5) * width; // 0..1 
    587             tpos.y = (y + 0.5) * width; // 0..1 
     578            tpos.x = x * width; // 0..1 
     579            tpos.y = y * width; // 0..1 
    588580             
    589581            p = tpos.xy;     
     
    596588                L = float3(p.x, -1, p.y); 
    597589                Le = float4(texCUBE(SmallEnvironmentMapSampler, L).rgb, 1); 
    598                 d = texCUBE(SmallEnvironmentMapSampler, L).a;    
    599590                 
    600                 I += 0.5 * Le * GetContibution( L1, L2, L3, L4, pos, N, d);                      
    601                 //I += Le / 16.0; 
     591                I += 0.5 * Le * GetContibution( L, L1, L2, L3, L4, pos, N, SmallEnvironmentMapSampler);                  
    602592         } 
    603          for (int x = 0; x < M; x++)                     
    604          for (int y = 0; y < M; y++)                                                                                     
    605          {                                                                                                                               
     593          
     594         for (float x = 0; x < M; x++)                   
     595                for (float y = 0; y < M; y++)                                                                                    
     596                {                                                                                                                                
    606597                float2 p, tpos;  
    607             tpos.x = (x + 0.5) * width; // 0..1 
    608             tpos.y = (y + 0.5) * width; // 0..1 
     598            tpos.x = x * width; // 0..1 
     599            tpos.y = y * width; // 0..1 
    609600             
    610601            p = tpos.xy;     
     
    617608                L = float3(1, p.x, p.y); 
    618609                Le = float4(texCUBE(SmallEnvironmentMapSampler, L).rgb, 1); 
    619                 d = texCUBE(SmallEnvironmentMapSampler, L).a;    
    620610                 
    621                 I += 0.5 * Le * GetContibution( L1, L2, L3, L4, pos, N, d);                      
    622                 //I += Le / 16.0; 
    623          } 
     611                I += 0.5 * Le * GetContibution( L, L1, L2, L3, L4, pos, N, SmallEnvironmentMapSampler);                  
     612        } 
    624613          
    625          for (int x = 0; x < M; x++)                     
    626          for (int y = 0; y < M; y++)                                                                                     
     614        for (float x = 0; x < M; x++)                    
     615         for (float y = 0; y < M; y++)                                                                                   
    627616         {                                                                                                                               
    628617                float2 p, tpos;  
    629             tpos.x = (x + 0.5) * width; // 0..1 
    630             tpos.y = (y + 0.5) * width; // 0..1 
     618            tpos.x = x * width; // 0..1 
     619            tpos.y = y * width; // 0..1 
    631620             
    632621            p = tpos.xy;     
     
    639628                L = float3(-1, p.x, p.y); 
    640629                Le = float4(texCUBE(SmallEnvironmentMapSampler, L).rgb, 1); 
    641                 d = texCUBE(SmallEnvironmentMapSampler, L).a;    
    642630                 
    643                 I += 0.5 * Le * GetContibution( L1, L2, L3, L4, pos, N, d);                      
    644                 //I += Le / 16.0; 
    645          }                                                                                                                                                                       
     631                I += 0.5 * Le * GetContibution( L, L1, L2, L3, L4, pos, N, SmallEnvironmentMapSampler);                          
     632         }                                                                                                                                                               
    646633        return intensity * I;                                                                                                                    
    647634} 
    648635 
    649  
     636float4 P2PContr(float3 N, float3 Nl, float3 pos, float3 L, samplerCUBE cubemap) 
     637{ 
     638        Nl = normalize(Nl); 
     639        L = normalize(L); 
     640        float4 Le = float4(texCUBE(cubemap, L).rgb, 1); 
     641        float d = texCUBE(cubemap, L).a; 
     642        float3 Lpos = L * d; 
     643        float3 Ldir = Lpos - pos; 
     644        float dist = dot(Ldir, Ldir); 
     645        Ldir = normalize(Ldir); 
     646         
     647        return Le * max(dot(N, Ldir),0) * dot(Nl, -1 * Ldir) / dist;     
     648} 
     649 
     650float4 EnvMapDiffuseP2PPS( _EnvMapVS_output IN ) : COLOR                         
     651{                
     652        float M = 4.0;                                                                                                                                                   
     653        IN.View = -normalize( IN.View );                                                                                                 
     654        IN.Normal = normalize( IN.Normal );                                                                                              
     655        IN.Position -= reference_pos.xyz;                                
     656        float3 pos = IN.Position.xyz;    
     657         
     658        //return        reference_pos; 
     659        //return  texCUBE(SmallEnvironmentMapSampler, pos);      
     660                                                                                                 
     661        float3 N =IN.Normal;                                                                                                                                                             
     662                                                                                                         
     663    float4 I = 0;                                                                        
     664        float3 L;                                                
     665        float4 Le;                                                                               
     666        float width = 1.0 / M; 
     667        float d;                                                         
     668         
     669        for (float x = 0.5; x < M; x++)                  
     670         for (float y = 0.5; y < M; y++)                                                                                         
     671         {                                                                                                                               
     672                float2 p, tpos;  
     673            tpos.x = x * width; 
     674            tpos.y = y * width; 
     675             
     676            p = tpos.xy;     
     677            p = 2.0 * p - 1.0; //-1..1 
     678                             
     679                I += P2PContr(N, float3(0,0,-1), pos, float3(p.x, p.y, 1), SmallEnvironmentMapSampler); 
     680                I += P2PContr(N, float3(0,0,1), pos, float3(-p.x, p.y, -1), SmallEnvironmentMapSampler); 
     681                I += P2PContr(N, float3(-1,0,0), pos, float3(1, p.y, -p.x), SmallEnvironmentMapSampler); 
     682                I += P2PContr(N, float3(1,0,0), pos, float3(-1, p.y, p.x), SmallEnvironmentMapSampler); 
     683                I += P2PContr(N, float3(0,-1,0), pos, float3(p.x, 1, -p.y), SmallEnvironmentMapSampler); 
     684                I += P2PContr(N, float3(0,1,0), pos, float3(p.x, -1, p.y), SmallEnvironmentMapSampler); 
     685        } 
     686                                                                                                                                                 
     687        return intensity * I;                                                                                                                    
     688} 
    650689//-------------------------------------------------------------------------------------- 
    651690// Shading the environment 
     
    694733float4 IlluminatedScenePS( _IlluminatedSceneVS_output IN ) : COLOR0 
    695734{ 
    696     float3 color = objColor;// * tex2D(DecorationSampler, IN.TexCoord); 
    697     /* 
     735    float3 color = objColor * tex2D(DecorationSampler, IN.TexCoord); 
     736   /*  
    698737    if (iShowCubeMap > 0)  
    699738    { 
     
    710749                color *= abs(pow(dot(L,N), 4)) * brightness; 
    711750        } 
    712         else color *= 0.7; 
    713         */       
     751        else color *= 0.7;*/ 
     752                 
    714753        float dist = length( IN.Position ); 
    715754    return float4(color, dist);  
     
    745784 
    746785TechniqueUsingCommonVS( EnvMapDiffuseLocalizedNew ); 
     786TechniqueUsingCommonVS( EnvMapDiffuseP2P ); 
    747787//TechniqueUsingCommonVS( EnvMapDiffuseLocalizedNew4 ); 
    748788//TechniqueUsingCommonVS( EnvMapDiffuseLocalizedNew8 ); 
Note: See TracChangeset for help on using the changeset viewer.