Frederic De Groef avatar Frederic De Groef committed 39560a0

linearizd depth in gbuffer

Comments (0)

Files changed (2)

media/ssao/diffuse_gbuffer.cg

     float4 position : POSITION;
     float3 position_in_view_space : TEXCOORD0;
     float3 normal_in_view_space   : TEXCOORD1;    
-	float  depth_view_space : TEXCOORD2;
 };
 
 
     VertexOut OUT;
 
     OUT.position = mul(worldViewProjMatrix, IN.position);
-    OUT.position_in_view_space = mul(worldViewMatrix, IN.position);
-    OUT.normal_in_view_space = mul(worldViewMatrix, float4(IN.normal, 0));
-
-	OUT.depth_view_space = OUT.position_in_view_space.z;
+    OUT.position_in_view_space = mul(worldViewMatrix, IN.position).xyz;
+    OUT.normal_in_view_space = mul(worldViewMatrix, float4(IN.normal, 0)).xyz;
 
     return OUT;
 }
 {
     float3 position_in_view_space : TEXCOORD0;
     float3 normal_in_view_space   : TEXCOORD1;    
-	float  depth_view_space : TEXCOORD2;
 };
 
 struct FragmentOut
 {
     float4 color : COLOR0;
 };
+									  
 
-
-FragmentOut geom_ps(FragmentInput IN)
+FragmentOut geom_ps(
+	FragmentInput IN        
+    ,uniform float cNearClipDistance
+    ,uniform float cFarClipDistance // !!! might be 0 for infinite view projection.
+)
 {
     FragmentOut OUT;
 
     
     float3 p = IN.position_in_view_space.xyz;
     float3 n = IN.normal_in_view_space.xyz;
+  
+    OUT.color.gba = normalize(n);
+		        
+    float clipDistance = cFarClipDistance - cNearClipDistance;
+    OUT.color.r = (length(p.z) - cNearClipDistance) / clipDistance; // norm to [0, 1]        
     
-    float depth = length(p);
-    float3 normal = normalize(n.xyz);
-    
-    OUT.color = float4(IN.depth_view_space, normal);
 
     return OUT;
 }

media/ssao/diffuse_gbuffer.material

 
         fragment_program_ref gbuffer_ps
         {
+				param_named_auto cNearClipDistance near_clip_distance
+				param_named_auto cFarClipDistance far_clip_distance
         }
     }
   }
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.