Ignore:
Timestamp:
10/23/06 23:28:16 (18 years ago)
Author:
szirmay
Message:
 
Location:
GTP/trunk/App/Demos/Illum/Ogre/Media
Files:
6 added
8 edited

Legend:

Unmodified
Added
Removed
  • GTP/trunk/App/Demos/Illum/Ogre/Media/materials/programs/GameTools_DepthShadow.hlsl

    r1638 r1671  
    2727} 
    2828 
     29VS_OUT DepthDistVS(float4 position : POSITION,   
     30                                uniform float4x4 worldViewProj, 
     31                                uniform float4x4 worldView) 
     32{ 
     33   
     34  VS_OUT OUT; 
     35  
     36  OUT.hPosition = mul(worldViewProj, position); 
     37  OUT.Position = mul(worldView, position); 
     38   
     39  return OUT; 
     40} 
     41 
     42float4 DepthDistPS(VS_OUT IN, 
     43                                        uniform float farPlane ):COLOR 
     44{ 
     45        float dist = length(IN.Position.xyz) / farPlane; 
     46        return float4(dist, dist * dist, 1, 1);  
     47        //return farPlane; 
     48} 
     49 
    2950///////////////Shadow 
    3051 
     
    3455        float4 Position         : TEXCOORD0; 
    3556        float4 lPosition        : TEXCOORD1; 
     57        float4 lVPosition       : TEXCOORD2; 
    3658}; 
    3759 
     
    4567  float4 wPos = mul(world, position); 
    4668  OUT.lPosition = mul(lightViewProj, wPos);   
     69  OUT.lVPosition = 0;   
    4770  OUT.Position = position;   
    4871  return OUT; 
    4972} 
    5073 
    51 /* 
     74 
    5275float4 depthShadowPS(VS_OUT_SHADOW IN, 
    5376                                        uniform float4x4 lightViewProj, 
     
    7295                        float4 storedDepth = tex2D(depthShadowMap, pos.xy); 
    7396         
    74                         if(storedDepth.r + bias < pos.z) 
    75                         { 
    76                                 float M1 = storedDepth.r; 
    77                                 float M2 = storedDepth.g; 
    78                                 float v2 = M2 - M1 * M1; 
    79                                 float pmax = v2 / (v2 + pow(M1 - pos.z, 2)); 
    80                                 light = saturate(shadow + (1 - shadow) * pmax); 
    81                         } 
     97                          
     98                        float M1 = storedDepth.r; 
     99                        float M2 = storedDepth.g; 
     100                        float v2 = M2 - M1 * M1; 
     101                        float pmax = v2 / (v2 + pow(M1 - pos.z, 2)); 
     102                        light = saturate(shadow + (1 - shadow) * pmax); 
     103                         
    82104                } 
    83105                 
     
    88110        return light;    
    89111} 
    90 */ 
    91  
    92  
     112 
     113 
     114 
     115VS_OUT_SHADOW distShadowVS(float4 position : POSITION,   
     116                                                        uniform float4x4 worldViewProj, 
     117                                                        uniform float4x4 world, 
     118                                                        uniform float4x4 lightView, 
     119                                                        uniform float4x4 lightViewProj) 
     120{ 
     121  VS_OUT_SHADOW OUT; 
     122  OUT.hPosition = mul(worldViewProj, position); 
     123  float4 wPos = mul(world, position); 
     124  OUT.lPosition = mul(lightViewProj, wPos); 
     125  OUT.lVPosition = mul(lightView, wPos);   
     126  OUT.Position = position;   
     127  return OUT; 
     128} 
     129 
     130 
     131float4 distShadowPS(VS_OUT_SHADOW IN, 
     132                                        uniform float4x4 lightViewProj, 
     133                                        uniform float lightFarPlane, 
     134                                        uniform sampler2D depthShadowMap : register(s0) 
     135                                        ):COLOR 
     136{        
     137        float bias = 0.001; 
     138        float epsilon = 0.001; 
     139        float4 light = float4(1,1,1,1); 
     140        float4 shadow = float4(0.85,0.85,0.85,1); 
     141         
     142        if(IN.lPosition.z > 0.0) 
     143        { 
     144                float4 pos = (IN.lPosition / IN.lPosition.w); 
     145                 
     146                float d = length(pos.xy); 
     147                         
     148                light = saturate((1.0 - d)/0.05); 
     149                 
     150                if(d <= 1.0) 
     151                { 
     152                        float dist = length(IN.lVPosition.xyz) / lightFarPlane; 
     153                        pos.xy = (pos.xy + 1.0) / 2.0; 
     154                        pos.y = 1.0 - pos.y; 
     155                        float4 storedDist = tex2D(depthShadowMap, pos.xy); 
     156                        dist -= bias; 
     157                        float lit_factor = light * (dist <= storedDist.r);       
     158          
     159                        float M1 = storedDist.r; 
     160                        float M2 = storedDist.g; 
     161                        float v2 = min(max(M2 - M1 * M1, 0.0) +  epsilon, 1.0); 
     162                        float m_d = M1 - dist; 
     163                float pmax = v2 / (v2 + m_d * m_d); 
     164                                                 
     165                // Adjust the light color based on the shadow attenuation 
     166                light = max(lit_factor, pmax); 
     167         
     168                } 
     169                 
     170        } 
     171        else 
     172                light = 0;       
     173         
     174        return shadow + (1 - shadow) * light; 
     175} 
     176 
     177 
     178/* 
    93179float4 depthShadowPS(VS_OUT_SHADOW IN, 
    94180                                        uniform float4x4 lightViewProj, 
     
    126212        return light;    
    127213} 
     214*/ 
  • GTP/trunk/App/Demos/Illum/Ogre/Media/materials/programs/GameTools_Diffuse.hlsl

    r1638 r1671  
    272272} 
    273273 
     274struct vertOUTBump 
     275{ 
     276        float4 hPos :POSITION; 
     277        float3 wPos     :TEXCOORD1; 
     278        float2 texCoord :TEXCOORD0; 
     279        float3 mNormal  :TEXCOORD2; 
     280        float3 tangent  :TEXCOORD3; 
     281        float3 binormal :TEXCOORD4; 
     282}; 
     283 
     284vertOUTBump DiffuseBumpVS(float4 position : POSITION, 
     285                float3 normal   : NORMAL, 
     286                half3 tangent   : TEXCOORD1,  
     287                float2 texCoord : TEXCOORD0,                     
     288                uniform float4x4 worldViewProj, 
     289                uniform float4x4 world) 
     290{ 
     291  vertOUTBump OUT; 
     292  OUT.hPos = mul(worldViewProj, position); 
     293  OUT.wPos = mul(world, position).xyz;   
     294  OUT.mNormal = normal; 
     295  OUT.tangent  = tangent; 
     296  OUT.texCoord = texCoord; 
     297  OUT.binormal = cross(tangent, normal); 
     298  return OUT; 
     299} 
     300 
     301float4 DiffuseBumpPS( vertOUTBump IN, 
     302           uniform float3 cameraPos, 
     303           uniform float3 lastCenter,   //LI// 
     304           uniform samplerCUBE SmallEnvMapSampler : register(s0), 
     305           uniform samplerCUBE DistanceEnvMapSampler : register(s1), 
     306           uniform sampler2D NormalMap : register(s2), 
     307           uniform float4x4 worldI 
     308            ) : COLOR0 
     309{ 
     310    float M = 4; 
     311         
     312    float3 N = IN.mNormal; 
     313    N = normalize( N );  
     314    float3x3 TangentToModel = float3x3(IN.tangent, IN.binormal, N); 
     315     
     316    half3 tNormal = tex2D(NormalMap, IN.texCoord).rgb;   
     317     
     318    N = mul(tNormal, TangentToModel );     
     319      
     320    N = normalize( N );  
     321    N = mul(N, worldI); 
     322 
     323    float3 pos = IN.wPos - lastCenter; 
     324     
     325    //return float4(N,1)+ lastCenter.x*0.000001;  
     326  //  return  readCubeMap(SmallEnvMapSampler, pos) + lastCenter.x*0.000001; 
     327     
     328    float4 I = 0;                                                                        
     329        float3 L1, L2, L3, L4, L;                                                
     330        float4 Le;                                                                               
     331        float width = 1.0 / M;                                                   
     332        float width2 = width * 2; 
     333        float d;  
     334         
     335        for (float x = 0.5; x < M; x++)                  
     336         for (float y = 0.5; y < M; y++)                                                                                         
     337         {                                                                                                                               
     338                float2 p, tpos;  
     339            tpos.x = x * width; 
     340            tpos.y = y * width; 
     341             
     342            p = tpos.xy;     
     343            p = 2.0 * p - 1.0; //-1..1 
     344                             
     345                L1 = float3(p.x - width, p.y - width, 1);        
     346                L2 = float3(p.x + width, p.y - width, 1);        
     347                L3 = float3(p.x + width, p.y + width, 1);        
     348                L4 = float3(p.x - width, p.y + width, 1); 
     349                L = float3(p.x, p.y, 1); 
     350                Le = float4(readCubeMap(SmallEnvMapSampler, L).rgb, 1); 
     351                 
     352                I += 0.5 * Le * GetContibution( L, L1, L2, L3, L4, pos, N, DistanceEnvMapSampler);                       
     353                         
     354        }                                                                                                                                                        
     355         
     356        for (float x = 0.5; x < M; x++)                  
     357         for (float y = 0.5; y < M; y++)                                                                                         
     358         {                                                                                                                               
     359                float2 p, tpos;  
     360            tpos.x = x * width; // 0..1 
     361            tpos.y = y * width; // 0..1 
     362             
     363            p = tpos.xy;     
     364            p = 2.0 * p - 1.0; //-1..1 
     365                             
     366                L4 = float3(p.x - width, p.y - width, -1);       
     367                L3 = float3(p.x + width, p.y - width, -1);       
     368                L2 = float3(p.x + width, p.y + width, -1);       
     369                L1 = float3(p.x - width, p.y + width, -1); 
     370                L = float3(p.x, p.y, -1); 
     371                Le = float4(readCubeMap(SmallEnvMapSampler, L).rgb, 1); 
     372                 
     373                I += 0.5 * Le * GetContibution( L, L1, L2, L3, L4, pos, N, DistanceEnvMapSampler);                       
     374         }       
     375          
     376        for (float x = 0.5; x < M; x++)                  
     377         for (float y = 0.5; y < M; y++)                                                                                         
     378         {                                                                                                                               
     379                float2 p, tpos;  
     380            tpos.x = x * width; // 0..1 
     381            tpos.y = y * width; // 0..1 
     382             
     383            p = tpos.xy;     
     384            p = 2.0 * p - 1.0; //-1..1 
     385                             
     386                L4 = float3(p.x - width, 1, p.y - width); 
     387                L3 = float3(p.x + width, 1, p.y - width);        
     388                L2 = float3(p.x + width, 1, p.y + width);        
     389                L1 = float3(p.x - width, 1, p.y + width);                        
     390                L = float3(p.x, 1, p.y); 
     391                Le = float4(readCubeMap(SmallEnvMapSampler, L).rgb, 1); 
     392                 
     393                I += 0.5 * Le * GetContibution( L, L1, L2, L3, L4, pos, N, DistanceEnvMapSampler);                       
     394         }               
     395          
     396        for (float x = 0.5; x < M; x++)                  
     397         for (float y = 0.5; y < M; y++)                                                                                         
     398         {                                                                                                                               
     399                float2 p, tpos;  
     400            tpos.x = x * width; // 0..1 
     401            tpos.y = y * width; // 0..1 
     402             
     403            p = tpos.xy;     
     404            p = 2.0 * p - 1.0; //-1..1 
     405                             
     406                L1 = float3(p.x - width, -1, p.y - width); 
     407                L2 = float3(p.x + width, -1, p.y - width);       
     408                L3 = float3(p.x + width, -1, p.y + width);       
     409                L4 = float3(p.x - width, -1, p.y + width);                       
     410                L = float3(p.x, -1, p.y); 
     411                Le = float4(readCubeMap(SmallEnvMapSampler, L).rgb, 1); 
     412                 
     413                I += 0.5 * Le * GetContibution( L, L1, L2, L3, L4, pos, N, DistanceEnvMapSampler);                       
     414         } 
     415          
     416         for (float x = 0.5; x < M; x++)                         
     417                for (float y = 0.5; y < M; y++)                                                                                  
     418                {                                                                                                                                
     419                float2 p, tpos;  
     420            tpos.x = x * width; // 0..1 
     421            tpos.y = y * width; // 0..1 
     422             
     423            p = tpos.xy;     
     424            p = 2.0 * p - 1.0; //-1..1 
     425                             
     426                L1 = float3(1, p.x - width, p.y - width); 
     427                L2 = float3(1, p.x + width, p.y - width);        
     428                L3 = float3(1, p.x + width, p.y + width);        
     429                L4 = float3(1, p.x - width, p.y + width);        
     430                L = float3(1, p.x, p.y); 
     431                Le = float4(readCubeMap(SmallEnvMapSampler, L).rgb, 1); 
     432                 
     433                I += 0.5 * Le * GetContibution( L, L1, L2, L3, L4, pos, N, DistanceEnvMapSampler);                       
     434        } 
     435          
     436        for (float x = 0.5; x < M; x++)                  
     437         for (float y = 0.5; y < M; y++)                                                                                         
     438         {                                                                                                                               
     439                float2 p, tpos;  
     440            tpos.x = x * width; // 0..1 
     441            tpos.y = y * width; // 0..1 
     442             
     443            p = tpos.xy;     
     444            p = 2.0 * p - 1.0; //-1..1 
     445                             
     446                L4 = float3(-1, p.x - width, p.y - width); 
     447                L3 = float3(-1, p.x + width, p.y - width);       
     448                L2 = float3(-1, p.x + width, p.y + width);       
     449                L1 = float3(-1, p.x - width, p.y + width);       
     450                L = float3(-1, p.x, p.y); 
     451                Le = float4(readCubeMap(SmallEnvMapSampler, L).rgb, 1); 
     452                 
     453                I += 0.5 * Le * GetContibution( L, L1, L2, L3, L4, pos, N, DistanceEnvMapSampler);                               
     454         }       
     455         float kd = 0.3;                                                                                                                                                 
     456        return kd * I; 
     457} 
     458 
    274459float4 P2PContr(float3 N, float3 Nl, float3 pos, float3 L, samplerCUBE cubemap, samplerCUBE distmap) 
    275460{ 
     
    280465        float3 Lpos = L * d; 
    281466        float3 Ldir = Lpos - pos; 
    282         float dist = dot(Ldir, Ldir); 
     467        float dist = 4 * dot(Ldir, Ldir); 
    283468        Ldir = normalize(Ldir); 
    284         dist /= 10000.0; 
    285         return Le * max(dot(N, Ldir),0) * dot(Nl, -1 * Ldir) / dist;     
     469                 
     470        return Le * (max(dot(N, Ldir),0) * dot(Nl, -1 * Ldir)) / dist;   
    286471} 
    287472 
     
    293478        float M = 4.0;   
    294479         
    295         //float3 N = mul( world_IT, float4(IN.mNormal,1)).xyz; 
    296480    float3 N = IN.mNormal; 
    297481    N = normalize( N );  
     
    302486        float4 Le;                                                                               
    303487        float width = 1.0 / M; 
    304         float d;                                                         
    305          
    306         //float vdir = length(pos); 
    307         //return (readDistanceCubeMap(DistanceEnvMapSampler, pos) - vdir); 
    308         //return readCubeMap(SmallEnvMapSampler, pos); 
    309         //return readDistanceCubeMap(DistanceEnvMapSampler, pos); 
     488        float d;         
     489         
     490        float kd = 0.3;                                                                                                                                          
     491         
     492        //return kd * readCubeMap(SmallEnvMapSampler, N) + lastCenter.x * 0.00000001; 
    310493         
    311494        for (float x = 0.5; x < M; x++)                  
     
    327510        } 
    328511                                                                                                                                                 
    329         float kd = 0.8;                                                                                                                                          
    330512        return kd * I;                                                                                                                   
    331513} 
  • GTP/trunk/App/Demos/Illum/Ogre/Media/materials/programs/GameTools_Phong.hlsl

    r1629 r1671  
    209209    float4 I = 0; 
    210210    I = texColor * ambientLight * ambient; 
    211         float maxlightangle = 3.14 / 2.0; 
     211        float maxlightangle = 90.0 / 180.0 * 3.14; 
    212212    for(int i=0; i< M; i++) 
    213213    { 
  • GTP/trunk/App/Demos/Illum/Ogre/Media/materials/scripts/Diffuse.material

    r1638 r1671  
    157157                texture_unit 
    158158                { 
    159                         cubic_texture cubemap.jpg combinedUVW 
    160                         tex_address_mode clamp 
    161                         colour_op replace 
     159                         
    162160                } 
    163161 
     
    165163                texture_unit 
    166164                 { 
    167                    cubic_texture cubemap.jpg combinedUVW 
    168                    tex_address_mode clamp 
    169                    colour_op replace 
     165                   
    170166                 } 
    171167         } 
     
    173169} 
    174170 
     171vertex_program DiffuseBumpVS hlsl 
     172{ 
     173        source GameTools_Diffuse.hlsl 
     174        entry_point DiffuseBumpVS 
     175        target vs_3_0 
     176}  
     177 
     178fragment_program DiffuseBumpPS hlsl 
     179{ 
     180        source GameTools_Diffuse.hlsl 
     181        entry_point DiffuseBumpPS 
     182        target ps_3_0 
     183}  
     184 
     185 
     186 
     187material GameTools/DiffuseBump 
     188{  
     189   technique  
     190   {  
     191      pass  
     192      {  
     193                 
     194                IllumTechniques 
     195                { 
     196                        RenderTechnique DistanceCubeMap 
     197                        { 
     198                                update_interval         1 
     199                                update_all_face         true 
     200                                distance_calc           false 
     201                                face_angle_calc         false 
     202                                resolution                      128                                              
     203                        } 
     204                        RenderTechnique ReducedColorCubeMap 
     205                        { 
     206                                update_interval         1 
     207                                reduced_resolution 4 
     208                                resolution 128 
     209                                distance_calc false 
     210                                face_angle_calc false 
     211                                update_all_face         true 
     212                        } 
     213                } 
     214       
     215 
     216                vertex_program_ref DiffuseBumpVS 
     217                {        
     218                        param_named_auto worldViewProj worldviewproj_matrix  
     219                param_named_auto world world_matrix 
     220         
     221                }  
     222                fragment_program_ref DiffuseBumpPS 
     223                {  
     224                        param_named_auto worldI inverse_world_matrix   
     225                param_named lastCenter float3 0 0 0 
     226                }  
     227                 
     228                //Cube map for reflections and refractions       
     229                texture_unit 
     230                {                        
     231                } 
     232 
     233                //Cube map of distances 
     234                texture_unit 
     235                 { 
     236                      
     237                 } 
     238                 texture_unit 
     239                 { 
     240                        texture atheneNormalMapNew.dds 
     241                 } 
     242         } 
     243   } 
     244} 
    175245 
    176246fragment_program DiffuseP2PPS hlsl 
     
    181251}  
    182252 
    183 material GameTools/Diffuse/use1 
     253material GameTools/DiffuseP2P 
    184254{  
    185255   technique  
     
    193263                        { 
    194264                                update_interval         1 
     265                                resolution 128 
    195266                                distance_calc false      
    196267                                face_angle_calc false 
     
    211282                vertex_program_ref Diffuse2VS 
    212283                {        
    213                  param_named_auto worldViewProj worldviewproj_matrix  
    214                 param_named_auto world world_matrix   
    215          
     284                        param_named_auto worldViewProj worldviewproj_matrix  
     285                param_named_auto worldI inverse_world_matrix   
     286                param_named_auto world world_matrix         
    216287                }  
    217288                fragment_program_ref DiffuseP2PPS 
    218289                {  
    219                         param_named REDUCED_CUBEMAP_SIZE int 4 
    220290                        param_named lastCenter float3 0 0 0                              
    221291                }  
     
    224294                texture_unit 
    225295                { 
    226                         cubic_texture cubemap.jpg combinedUVW 
    227                         tex_address_mode clamp 
    228                         colour_op replace 
     296                         
    229297                } 
    230298 
     
    232300                texture_unit 
    233301                 { 
    234                    cubic_texture cubemap.jpg combinedUVW 
    235                    tex_address_mode clamp 
    236                    colour_op replace 
     302                   
    237303                 } 
    238304         } 
  • GTP/trunk/App/Demos/Illum/Ogre/Media/materials/scripts/GameTools.material

    r1629 r1671  
    221221        {  
    222222                         
     223        } 
     224         
     225       } 
     226    } 
     227} 
     228 
     229material GameTools/ShadowMapDistance 
     230{  
     231 
     232   technique  
     233   {  
     234      scene_blend none 
     235 
     236      pass  
     237      {  
     238                cull_hardware anticlockwise 
     239                //cull_hardware none 
     240                 
     241                vertex_program_ref GameTools/ShadowMap/DistVS 
     242        {        
     243          param_named_auto worldViewProj worldviewproj_matrix 
     244          param_named_auto worldView worldview_matrix           
     245            }  
     246                fragment_program_ref  GameTools/ShadowMap/DistPS 
     247        {  
     248                        param_named_auto farPlane far_clip_distance 
    223249        } 
    224250         
  • GTP/trunk/App/Demos/Illum/Ogre/Media/materials/scripts/GameTools.program

    r1131 r1671  
    252252        target ps_3_0 
    253253 
     254} 
     255 
     256vertex_program GameTools/ShadowMap/DistVS hlsl 
     257{ 
     258        source GameTools_DepthShadow.hlsl 
     259        entry_point DepthDistVS 
     260        target vs_3_0 
     261}  
     262 
     263fragment_program GameTools/ShadowMap/DistPS hlsl 
     264{ 
     265        source GameTools_DepthShadow.hlsl 
     266        entry_point DepthDistPS 
     267        target ps_3_0 
     268 
    254269}  
    255270 
     
    269284}  
    270285 
     286vertex_program GameTools/ShadowMap/ShadowDistVS hlsl 
     287{ 
     288        source GameTools_DepthShadow.hlsl 
     289        entry_point distShadowVS 
     290        target vs_1_1 
     291}  
     292 
     293fragment_program GameTools/ShadowMap/ShadowDistPS hlsl 
     294{ 
     295        source GameTools_DepthShadow.hlsl 
     296        entry_point distShadowPS 
     297        target ps_2_0 
     298 
     299}  
     300 
    271301vertex_program GameTools/UV_VS hlsl 
    272302{ 
  • GTP/trunk/App/Demos/Illum/Ogre/Media/materials/scripts/difflab.material

    r1638 r1671  
    115115                                { 
    116116                                        max_light_count 3 
     117                                        vertex_program_name GameTools/ShadowMap/ShadowDistVS 
     118                                        fragment_program_name GameTools/ShadowMap/ShadowDistPS 
     119                                        set_light_view true 
     120                                        set_light_farplane true 
    117121                                } 
    118122                        } 
     
    136140                                { 
    137141                                        max_light_count 3 
     142                                        vertex_program_name GameTools/ShadowMap/ShadowDistVS 
     143                                        fragment_program_name GameTools/ShadowMap/ShadowDistPS 
     144                                        set_light_view true 
     145                                        set_light_farplane true 
    138146                                } 
    139147                        } 
     
    179187                                { 
    180188                                        max_light_count 3 
     189                                        vertex_program_name GameTools/ShadowMap/ShadowDistVS 
     190                                        fragment_program_name GameTools/ShadowMap/ShadowDistPS 
     191                                        set_light_view true 
     192                                        set_light_farplane true 
    181193                                } 
    182194                        } 
     
    249261                                { 
    250262                                        max_light_count 3 
     263                                        vertex_program_name GameTools/ShadowMap/ShadowDistVS 
     264                                        fragment_program_name GameTools/ShadowMap/ShadowDistPS 
     265                                        set_light_view true 
     266                                        set_light_farplane true 
    251267                                } 
    252268                        } 
  • GTP/trunk/App/Demos/Illum/Ogre/Media/materials/scripts/hangar.material

    r1085 r1671  
    99                                RenderTechnique DepthShadowReciever 
    1010                                { 
     11                                        max_light_count 3 
     12                                        vertex_program_name GameTools/ShadowMap/ShadowDistVS 
     13                                        fragment_program_name                                   GameTools/ShadowMap/ShadowDistPS 
     14                                        set_light_view true 
     15                                        set_light_farplane true 
    1116                                         
    1217                                } 
Note: See TracChangeset for help on using the changeset viewer.