Ignore:
Timestamp:
09/15/08 01:43:13 (16 years ago)
Author:
mattausch
Message:
 
File:
1 edited

Legend:

Unmodified
Added
Removed
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/deferred.cg

    r2944 r2945  
    3535                         uniform float amb) 
    3636{ 
    37         float4 lightDir = float4(0.8f, -1.0f, 0.7f, 0.0f); 
    38         //float4 lightDir = float4(0.0f, 1.0f, 0.0f, 0.0f); 
     37        const float4 lightDir = float4(0.8f, -1.0f, 0.7f, 0.0f); 
     38        const float3 light = normalize(lightDir.xyz); 
     39        const float diffuseLight = saturate(dot(normal, light)); 
     40         
     41        /* 
    3942        float4 lightDir2 = float4(-0.5f, 0.5f, 0.4f, 0.0f); 
     43        float3 light2 = normalize(lightDir2.xyz); 
     44        float diffuseLight2 = saturate(dot(normal, light2)); 
     45*/ 
     46        float diffuse = diffuseLight;// + diffuseLight2; 
    4047 
    4148        // global ambient 
    4249        const float4 ambient = 0.25f; 
    43  
    44         // float3 L = normalize(lightPosition - position); 
    45         float3 light = normalize(lightDir.xyz); 
    46         float3 light2 = normalize(lightDir2.xyz); 
    47  
    48         float diffuseLight = saturate(dot(normal, light)); 
    49         float diffuseLight2 = saturate(dot(normal, light2)); 
    50  
    51         float diffuse = diffuseLight + diffuseLight2; 
     50        //const float4 ambient = 0.0f; 
    5251 
    5352        return (ambient + diffuse) * color * (1.0f - amb) + amb * color; 
     
    7372        float amb = norm.w; 
    7473 
    75         // expand normal 
    76         float3 normal = normalize(norm.xyz);// * 2.0f - float4(1.0f)); 
     74        float3 normal = normalize(norm.xyz); 
    7775 
    7876        float4 col = shade(IN, color, position, normal, amb); 
     
    9593                                         ) 
    9694{ 
    97         float s; 
    98  
    9995        float total_d = 0.0; 
    100         //float total_d = tex2D(shadowMap, lightSpacePos).x; 
    10196 
    10297        for (int i = 0; i < NUM_SAMPLES; ++ i)  
     
    118113                float shadowDepth = tex2D(shadowMap, texcoord).x; 
    119114 
    120                 total_d += step(shadowDepth, depth); 
    121                 //total_d += length(offsetTransformed); 
     115                total_d += step(depth, shadowDepth); 
    122116        } 
    123117 
     
    199193         
    200194        /* 
    201  
     195        // hard shadows 
    202196        float shadowDepth = tex2D(shadowMap, lightSpacePos.xy).x; 
    203197 
     
    212206        return OUT; 
    213207} 
     208 
    214209#else 
     210 
    215211 
    216212pixel main_shadow(fragment IN,  
     
    231227        float4 color = tex2Dlod(colors, float4(IN.texCoord.xy, 0, 0)); 
    232228        float4 position = tex2D(positions, IN.texCoord.xy); 
    233  
    234  
    235         // an ambient color term 
    236         float amb = norm.w; 
    237  
    238         float3 normal = normalize(norm.xyz); 
    239         float4 col = shade(IN, color, position, normal, amb); 
    240          
    241         position *= maxDepth; 
    242         position.w = 1.0f; 
    243          
    244         float4 lightSpacePos = mul(shadowMatrix, position); 
    245         lightSpacePos /= lightSpacePos.w; 
    246  
    247         OUT.color = col; 
    248  
    249         float shadowTerm = CalcShadowTerm(IN, shadowMap, sampleWidth, lightSpacePos.xy, lightSpacePos.z, samples, noiseTexture); 
    250  
    251         if (amb < 0.9f) // hack: prevent shadowing the sky       
    252         { 
    253                 // base lighting 
    254                 const float baseLighting = 0.3f; 
    255                 OUT.color *= baseLighting + (1.0f - baseLighting) * (1.0f - shadowTerm); 
    256         } 
    257          
     229         
     230        const float3 normal = normalize(norm.xyz); 
     231        const float3 lightDir = normalize(float3(0.8f, -1.0f, 0.7f)); 
     232 
     233        // hack: an emmisive color term 
     234        float emmisive = norm.w; 
     235 
     236        // diffuse intensity 
     237        const float angle = saturate(dot(normal, lightDir));  
     238        float diffuse = angle; 
     239 
     240        // calc diffuse illumination + shadow term 
     241        if ((emmisive < 0.95f) // hack: prevent shadowing the sky        
     242                && (angle > 1e-3f) 
     243                ) 
     244        { 
     245                position *= maxDepth; 
     246                position.w = 1.0f; 
     247 
     248                float4 lightSpacePos = mul(shadowMatrix, position); 
     249                lightSpacePos /= lightSpacePos.w; 
     250 
     251                float shadowTerm = CalcShadowTerm(IN, shadowMap, sampleWidth, lightSpacePos.xy, lightSpacePos.z, samples, noiseTexture); 
     252 
     253                diffuse *= shadowTerm; 
     254        } 
     255 
     256        // global ambient 
     257        const float4 ambient = 0.25f; 
     258         
     259        // base lighting 
     260        OUT.color = (ambient + diffuse) * color * (1.0f - emmisive) + emmisive * color; 
     261 
    258262        // also write out depth component 
    259263        OUT.color.w = color.w; 
Note: See TracChangeset for help on using the changeset viewer.