Ignore:
Timestamp:
07/08/08 03:35:16 (16 years ago)
Author:
mattausch
Message:

worked on deferred shading

Location:
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders
Files:
2 edited

Legend:

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

    r2821 r2822  
    1 #define NUM_SAMPLES 8 
    2 #define SAMPLE_INTENSITY 0.5f 
    3 //#define SAMPLE_INTENSITY 0.2f 
    4 #define AREA_SIZE 3e-1f 
     1#define NUM_SAMPLES 12 
     2//#define SAMPLE_INTENSITY 0.4f 
     3#define SAMPLE_INTENSITY 0.7f 
     4#define AREA_SIZE 5e-1f 
    55 
    66// kustls magic sample positions 
     
    7272float ssao(fragment IN, 
    7373           uniform sampler2D positions, 
    74            uniform sampler2D normals, 
    7574           uniform sampler2D noiseTexture, 
    76            uniform float2 samples[NUM_SAMPLES] 
     75           uniform float2 samples[NUM_SAMPLES], 
     76           uniform float3 currentNormal 
    7777           ) 
    7878{ 
     
    8282  float w = centerPosition.w; 
    8383 
    84   // the normal on the current position 
    85   float3 centerNormal = tex2D(normals, IN.texCoord.xy).xyz; 
    86   //normalize(centerNormal); 
    87    
    8884  // Check in a circular area around the current position. 
    8985  // Shoot vectors to the positions there, and check the angle to these positions. 
     
    120116     
    121117    // Angle between current normal and direction to sample controls AO intensity. 
    122     float cos_angle = dot(direction_to_sample, centerNormal); 
     118    float cos_angle = dot(direction_to_sample, currentNormal); 
    123119    cos_angle = max(cos_angle, 0.0f); 
    124120     
    125121    // distance between current position and sample position controls AO intensity. 
     122    //const float maxdist = 2e-1f; 
    126123    const float maxdist = 5e-1f; 
    127     //const float scale = 50.0f; 
    128  
     124     
    129125    float distance_intensity = maxdist - length_to_sample; 
     126    //float distance_intensity = 0.5f / (1.0f + length_to_sample * length_to_sample); 
    130127    distance_intensity = max(distance_intensity, 0.0f); 
    131128    // quadratic influence 
     
    142139             uniform sampler2D colors, 
    143140             uniform sampler2D positions, 
    144              uniform sampler2D normals) 
     141             uniform float3 normal, 
     142             uniform float amb) 
    145143{ 
    146144  float4 lightDir = float4(0.8f, -1.0f, 0.7f, 0.0f); 
     
    148146   
    149147  float4 color = tex2D(colors, IN.texCoord.xy); 
    150   float3 normal = tex2D(normals, IN.texCoord.xy).xyz; 
    151  
    152   // expand normal 
    153   normal = normalize(normal * 2.0f - 1.0f); 
    154  
     148  
    155149  float4 position = tex2D(positions, IN.texCoord.xy); 
    156150 
    157   float4 ambient = float4(0.3f); 
     151  float4 ambient = 0.3f; 
    158152 
    159153  // float3 L = normalize(lightPosition - position); 
     
    166160  float diffuse = diffuseLight + diffuseLight2; 
    167161 
    168   return (ambient + diffuse) * color; 
     162  return (ambient + diffuse) * color * (1.0f - amb) + amb * color; 
    169163} 
    170164 
     
    179173  pixel OUT; 
    180174 
    181   float4 col = shade(IN, colors, positions, normals); 
    182   float ao = ssao(IN, positions, normals, noiseTexture, samples); 
     175  float4 normal = tex2D(normals, IN.texCoord.xy); 
     176  float amb = normal.w; 
     177 
     178  // expand normal 
     179  normal = normalize(normal * 2.0f - 1.0f); 
     180 
     181  float4 col = shade(IN, colors, positions, normal, amb); 
     182  float ao = ssao(IN, positions, noiseTexture, samples, normal); 
    183183   
    184184  //OUT.color = tex2D(positions, IN.texCoord.xy); 
    185185  //OUT.color = ao; 
    186   //OUT.color =  col; 
     186  //OUT.color = col; 
    187187  OUT.color = ao * col; 
    188188 
     
    197197{ 
    198198  pixel OUT; 
    199  
    200   float4 col = shade(IN, colors, positions, normals); 
     199   
     200  float4 normal = tex2D(normals, IN.texCoord.xy); 
     201  float amb = normal.w; 
     202 
     203  // expand normal 
     204  normal = normalize(normal * 2.0f - 1.0f); 
     205   
     206  float4 col = shade(IN, colors, positions, normal.xyz, amb); 
    201207  OUT.color = col; 
    202208 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/mrt.cg

    r2821 r2822  
    3737  float4 col: COLOR0; 
    3838  float4 pos: COLOR1; 
    39   float3 norm: COLOR2; 
     39  float4 norm: COLOR2; 
    4040}; 
    4141 
     
    6262 
    6363 
    64 pixel fragtex(fragin IN, uniform sampler2D tex, uniform float maxDepth, uniform float4 diffuse) 
     64pixel fragtex(fragin IN,  
     65              uniform sampler2D tex,  
     66              uniform float maxDepth,  
     67              uniform float4 ambient,  
     68              uniform float4 diffuse) 
    6569{ 
    6670  pixel pix; 
    6771       
    68   pix.col = diffuse * tex2D(tex, IN.texCoord.xy); 
     72  pix.col = (ambient + diffuse) * tex2D(tex, IN.texCoord.xy); 
    6973  pix.pos = IN.worldPos * maxDepth; 
    70   pix.norm = IN.normal; 
     74  pix.norm.xyz = IN.normal * 0.5f + 0.5f; 
     75  // hack: squeeze some information about ambient into the texture 
     76  pix.norm.w = ambient.x; 
     77  // hack: store projection coordinate for scaling ssao 
    7178  pix.pos.w = IN.projPos.w; 
    7279 
     
    7582 
    7683 
    77 pixel frag(fragin IN, uniform float maxDepth, uniform float4 diffuse) 
     84pixel frag(fragin IN,  
     85           uniform float maxDepth,  
     86           uniform float4 ambient,  
     87           uniform float4 diffuse) 
    7888{ 
    7989  pixel pix; 
     
    8191  pix.col = diffuse; 
    8292  pix.pos = IN.worldPos * maxDepth; 
    83   pix.norm = IN.normal; 
     93  pix.norm.xyz = IN.normal * 0.5f + 0.5f; 
     94  // hack: squeeze some information about ambient into the texture 
     95  pix.norm.w = ambient.x; 
    8496  pix.pos.w = IN.projPos.w; 
    8597 
Note: See TracChangeset for help on using the changeset viewer.