Ignore:
Timestamp:
09/17/08 19:35:11 (16 years ago)
Author:
mattausch
Message:

implemented sun color

File:
1 edited

Legend:

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

    r2952 r2954  
    3636                         float3 lightDir) 
    3737{ 
    38         const float diffuseLight = saturate(dot(normal, lightDir)); 
    39          
    4038        /* 
    4139        float4 lightDir2 = float4(-0.5f, 0.5f, 0.4f, 0.0f); 
     
    4341        float diffuseLight2 = saturate(dot(normal, light2)); 
    4442*/ 
    45         float diffuse = diffuseLight;// + diffuseLight2; 
     43        // diffuse intensity 
     44        const float angle = saturate(dot(normal, lightDir));  
     45         
     46        float4 lightDiffuse = glstate.light[0].diffuse; 
     47        float4 diffuse = angle * lightDiffuse; 
    4648 
    4749        // global ambient 
    48         const float4 ambient = 0.25f; 
    49         //const float4 ambient = 0.0f; 
    50  
     50        const float4 ambient = glstate.light[0].ambient; 
     51         
    5152        return (ambient + diffuse) * color * (1.0f - amb) + amb * color; 
    5253} 
     
    7677        float4 col = shade(IN, color, position, normal, amb, lightDir); 
    7778         
    78         //OUT.color = float4(1.0f); 
    7979        OUT.color = col; 
    8080        OUT.color.w = color.w; 
     
    9393                                         ) 
    9494{ 
     95        //float shadowDepth = tex2D(shadowMap, lightSpacePos).x; 
     96        //return step(depth, shadowDepth); 
     97 
    9598        float total_d = 0.0; 
    96  
     99         
    97100        for (int i = 0; i < NUM_SAMPLES; ++ i)  
    98101        { 
     
    120123        return total_d; 
    121124} 
    122  
    123  
    124 #if 0 
    125 /** The mrt shader for standard rendering 
    126 */ 
    127 pixel main_shadow(fragment IN,  
    128                                   uniform sampler2D colors, 
    129                                   uniform sampler2D positions, 
    130                                   uniform sampler2D normals,                
    131                                   uniform sampler2D shadowMap, 
    132                                   uniform float4x4 shadowMatrix, 
    133                                   uniform float maxDepth, 
    134                                   uniform float sampleWidth, 
    135                                   uniform float3 lightDir 
    136                                   ) 
    137 { 
    138         pixel OUT; 
    139  
    140         float4 norm = tex2D(normals, IN.texCoord.xy); 
    141         float4 color = tex2Dlod(colors, float4(IN.texCoord.xy, 0, 0)); 
    142         float4 position = tex2D(positions, IN.texCoord.xy); 
    143  
    144  
    145         // an ambient color term 
    146         float amb = norm.w; 
    147  
    148         float3 normal = normalize(norm.xyz); 
    149         float4 col = shade(IN, color, position, normal, amb); 
    150          
    151         position *= maxDepth; 
    152         position.w = 1.0f; 
    153          
    154         float4 lightSpacePos = mul(shadowMatrix, position); 
    155         lightSpacePos /= lightSpacePos.w; 
    156  
    157         OUT.color = col; 
    158  
    159         float shadowDepth[9]; 
    160  
    161         float w = sampleWidth; 
    162  
    163         // pcf sampling using 3 x 3 tab 
    164         shadowDepth[0] = tex2D(shadowMap, lightSpacePos.xy).x; 
    165          
    166         shadowDepth[1] = tex2D(shadowMap, lightSpacePos.xy + float2( w,  w)).x; 
    167         shadowDepth[2] = tex2D(shadowMap, lightSpacePos.xy + float2( w, -w)).x; 
    168         shadowDepth[3] = tex2D(shadowMap, lightSpacePos.xy + float2(-w, -w)).x; 
    169         shadowDepth[4] = tex2D(shadowMap, lightSpacePos.xy + float2(-w,  w)).x; 
    170  
    171         shadowDepth[5] = tex2D(shadowMap, lightSpacePos.xy + float2( w,  0)).x; 
    172         shadowDepth[6] = tex2D(shadowMap, lightSpacePos.xy + float2( 0,  w)).x; 
    173         shadowDepth[7] = tex2D(shadowMap, lightSpacePos.xy + float2(-w,  0)).x; 
    174         shadowDepth[8] = tex2D(shadowMap, lightSpacePos.xy + float2( 0, -w)).x; 
    175  
    176          
    177         float depth = lightSpacePos.z; 
    178  
    179         float d = 0.0f; 
    180  
    181         for (int i = 0; i < 9; ++ i) 
    182         { 
    183                 d += step(shadowDepth[i], depth); 
    184         } 
    185  
    186         d /= 9.0f; 
    187          
    188         if (amb < 0.9f) // hack: prevent shadowing the sky       
    189         { 
    190                 // base lighting 
    191                 const float x = 0.4f; 
    192                 OUT.color *= x + (1.0f - x) * (1.0f - d); 
    193         } 
    194          
    195         /* 
    196         // hard shadows 
    197         float shadowDepth = tex2D(shadowMap, lightSpacePos.xy).x; 
    198  
    199         if ((amb < 0.9f) && // hack: prevent shadowing the sky   
    200                 (lightSpacePos.z > shadowDepth)) 
    201         { 
    202                 OUT.color *= 0.1f; 
    203         }*/ 
    204  
    205         OUT.color.w = color.w; 
    206  
    207         return OUT; 
    208 } 
    209  
    210 #else 
    211125 
    212126 
     
    237151        // diffuse intensity 
    238152        const float angle = saturate(dot(normal, lightDir));  
    239         float diffuse = angle; 
     153        //float4 lightDiffuse = float4(1.0f, 1.0f, 0.9f, 1.0f); 
     154        float4 lightDiffuse = glstate.light[0].diffuse; 
     155        //float4(1.0f, 1.0f, 0.9f, 1.0f); 
     156 
     157        float4 diffuse = lightDiffuse * angle; 
    240158 
    241159        // calc diffuse illumination + shadow term 
     
    256174 
    257175        // global ambient 
    258         const float4 ambient = 0.25f; 
     176        //const float4 ambient = 0.25f; 
     177        const float4 ambient = glstate.light[0].ambient; 
    259178         
    260179        // base lighting 
     
    266185        return OUT; 
    267186} 
    268  
    269 #endif 
Note: See TracChangeset for help on using the changeset viewer.