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

worked on deferred shading

File:
1 edited

Legend:

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

    r2817 r2818  
    6060           uniform sampler2D positions, 
    6161           uniform sampler2D normals, 
    62            const uniform float4x4 ProjTrafo, 
    6362           uniform sampler2D noiseTexture                                
    6463           ) 
    6564{ 
    6665  // the current world position 
    67   float4 centerPositionW = tex2D(positions, IN.texCoord.xy); 
    68   float3 centerPosition = centerPositionW.xyz; 
     66  float4 centerPosition = tex2D(positions, IN.texCoord.xy); 
     67  // the w coordinate from the persp. projection 
     68  float w = centerPosition.w; 
    6969 
    7070  // the normal on the current position 
     
    8787    //sample noisetex; r stores costheta, g stores sintheta 
    8888    float3 noise = tex2D(noiseTexture, IN.texCoord.xy).xyz * 2.0f - 1.0f; 
    89  
    90     //float2 offsetTransformed = offset;//reflect(offset, noise.xy); 
     89         
     90    // rotation 
     91    //float2 offsetTransformed = offset; 
    9192    float2 offsetTransformed; 
    9293    offsetTransformed.x = noise.r * offset.x - noise.g * offset.y; 
     
    9495                 
    9596    // weight with projected coordinate to reach similar kernel size for near and far 
    96     float2 texcoord = IN.texCoord.xy + offsetTransformed * areaSize * centerPositionW.w; 
     97    float2 texcoord = IN.texCoord.xy + offsetTransformed * areaSize * w; 
    9798     
    9899    float3 sample_position = tex2D(positions, texcoord).xyz; 
    99100     
    100     float3 vector_to_sample = sample_position - centerPosition; 
     101    float3 vector_to_sample = sample_position - centerPosition.xyz; 
    101102    float length_to_sample = length(vector_to_sample); 
    102103    float3 direction_to_sample = vector_to_sample / (length_to_sample + 1e-9f); 
     
    125126           uniform sampler2D positions, 
    126127           uniform sampler2D normals, 
    127            const uniform float4x4 ProjTrafo, 
    128128           uniform sampler2D noiseTexture) 
    129129{ 
     
    137137 
    138138  // expand normal 
    139   normal = normal * 2.0f - 1.0f; 
     139  normal = normalize(normal * 2.0f - 1.0f); 
    140140 
    141141  float4 position = tex2D(positions, IN.texCoord.xy); 
     
    146146  float3 light = normalize(lightDir.xyz); 
    147147  float3 light2 = normalize(lightDir2.xyz); 
    148  
     148  
    149149  float diffuseLight = max(dot(normal, light), 0.0f); 
    150150  float diffuseLight2 = max(dot(normal, light2), 0.0f); 
     
    152152  float diffuse = diffuseLight + diffuseLight2; 
    153153 
    154   float ao = ssao(IN, positions, normals, ProjTrafo, noiseTexture); 
     154  float ao = ssao(IN, positions, normals, noiseTexture); 
    155155  //OUT.color = ao;  
    156156  OUT.color = ao * (ambient + diffuse) * color; 
    157 //OUT.color = (ambient + diffuse) * color; 
    158  
    159   //float4 currentPos = tex2D(normals, IN.texCoord.xy) * 0.5f + 0.5f; 
    160   //float4 currentPos = tex2D(normals, IN.texCoord.xy); 
    161   //OUT.color = currentPos; 
     157  //OUT.color = (ambient + diffuse) * color; 
    162158       
    163159  return OUT; 
Note: See TracChangeset for help on using the changeset viewer.