Ignore:
Timestamp:
09/25/08 11:05:46 (16 years ago)
Author:
mattausch
Message:
 
Location:
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders
Files:
2 edited

Legend:

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

    r2970 r2973  
    2121 
    2222 
    23 float3 ToneMap(float imageKey, float whiteLum, float middleGrey, float3 color) 
    24 { 
    25         float3 outCol; 
    26         const float pixLum = 0.2125f * color.x + 0.7154f * color.y + 0.0721f * color.z; 
    27          
    28         // adjust to middle gray 
    29         const float lum = middleGrey * pixLum / imageKey; 
    30           
    31         // map to range and calc burnout 
    32         const float burnedLum = lum * (1.0f + lum / whiteLum * whiteLum) / (1.0f + lum); 
    33          
    34         outCol = color * burnedLum / pixLum; 
    35  
    36         /* 
    37         outCol = color; 
    38  
    39         outCol.rgb *= MIDDLE_GRAY /(MIDDLE_GRAY + 0.001f); 
    40     outCol.rgb *= (1.0f + color.rgb / whiteLum); 
    41         outCol.rgb /= (1.0f + color.rgb); 
    42 */ 
    43         //vColor.rgb += 0.6f * vBloom; 
    44          
    45         return outCol; 
    46 } 
    47  
    48  
    4923float4 main(v2p IN,  
    5024                        uniform sampler2D colors, 
    51                         uniform sampler2D normals, 
    52                         uniform float imageKey, 
    53                         uniform float whiteLum, 
    54                         uniform float middleGrey 
     25                        uniform sampler2D normals 
    5526                        ): COLOR 
    5627{ 
     
    12192        //return (s0 + s1 + s2 + s3) * 0.25f; 
    12293 
    123         //return float4(w); 
    124         col.xyz = ToneMap(imageKey, whiteLum, middleGrey, col.xyz); 
    125  
    12694        return col; 
    12795} 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/tonemap.cg

    r2972 r2973  
    77        float4 pos: WPOS; 
    88        float4 texCoord: TEXCOORD0;  
     9 
     10        float2 lt: TEXCOORD1; // left top 
     11        float2 rb: TEXCOORD2; // right bottom 
     12        float2 rt: TEXCOORD3; // right top 
     13        float2 lb: TEXCOORD4; // left bottom 
    914}; 
    1015 
    1116 
    12  
    13 float3 ToneMap(float imageKey, float whiteLum, float middleGrey, float3 color) 
     17struct pixel 
    1418{ 
    15         float3 outCol; 
    16         const float pixLum = 0.2125f * color.x + 0.7154f * color.y + 0.0721f * color.z; 
    17          
    18         // adjust to middle gray 
    19         const float lum = middleGrey * pixLum / imageKey; 
    20           
    21         // map to range and calc burnout 
    22         const float burnedLum = lum * (1.0f + lum / whiteLum * whiteLum) / (1.0f + lum); 
    23          
    24         outCol = color * burnedLum / pixLum; 
    25  
    26         return outCol; 
    27 } 
    28  
     19        float4 col: COLOR0; 
     20}; 
    2921 
    3022 
     
    3729    for(int i = 0; i < 16; ++ i) 
    3830    { 
    39         average += tex2D(colors, IN.texCoord + float2(downSampleOffs[i].x, downSampleOffs[i].y) ); 
     31        average += tex2D(colors, IN.texCoord.xy + downSampleOffs[i]); 
    4032    } 
    4133         
     
    4739 
    4840float4 GreyScaleDownSample(fragment IN, 
    49                                                    uniform sampler2D colors, 
    50                                                    float2 offs[16]): COLOR 
     41                                                   uniform sampler2D colors): COLOR 
    5142{ 
    5243 
     
    5546        float maximum = -1e20; 
    5647 
    57         float4 color = 0.0f; 
    58          
    5948        // the rgb weights 
    6049        const float3 w = float3(0.299f, 0.587f, 0.114f); 
    6150        //float3 w = float3(0.2125f, 0.7154f, 0.0721f); 
    6251 
     52        float4 cols[4]; 
     53 
     54        cols[0] = tex2D(colors, IN.texCoord.xy + IN.lt.xy); 
     55        cols[1] = tex2D(colors, IN.texCoord.xy + IN.lb.xy); 
     56        cols[2] = tex2D(colors, IN.texCoord.xy + IN.rt.xy); 
     57        cols[3] = tex2D(colors, IN.texCoord.xy + IN.rb.xy); 
     58 
     59 
    6360        for (int i = 0; i < 4; ++ i) 
    6461        { 
    65                 color = tex2D(colors, IN.texcoord + float2(offs[i].x, offs[i].y)); 
     62                const float intensity = dot(cols[i].rgb, w); 
    6663 
    67                 const float intensity = dot(color.rgb, W); 
    68  
    69                 maximum = max(maximum, intentsity); 
    70                 average += (0.25f * log(1e-5f + GreyValue)); 
     64                maximum = max(maximum, intensity); 
     65                average += (0.25f * log(1e-5f + intensity)); 
    7166        } 
    7267 
    7368        average = exp(average); 
    7469 
     70        return tex2D(colors, IN.texCoord.xy); 
     71 
    7572        // Output the luminance to the render target 
    7673        return float4(average, maximum, 0.0f, 1.0f); 
    7774} 
     75     
    7876 
    79      
    80      
     77pixel ToneMap(fragment IN, 
     78                          uniform sampler2D colors, 
     79                          uniform float imageKey,  
     80                          uniform float whiteLum,  
     81                          uniform float middleGrey) 
     82{ 
     83        pixel OUT; 
     84        float4 color = tex2D(colors, IN.texCoord.xy); 
     85 
     86        const float pixLum = 0.2125f * color.x + 0.7154f * color.y + 0.0721f * color.z; 
     87         
     88        // adjust to middle gray 
     89        const float lum = middleGrey * pixLum / imageKey; 
     90          
     91        // map to range and calc burnout 
     92        const float scaleLum = lum * (1.0f + lum / whiteLum * whiteLum) / (1.0f + lum); 
     93 
     94        OUT.col = color * scaleLum / pixLum; 
     95        OUT.col.w = color.w; 
     96 
     97        return OUT; 
     98} 
Note: See TracChangeset for help on using the changeset viewer.