Commits

Frederic De Groef committed cd28e85

new approach, first succesful attempt, hurray

Comments (0)

Files changed (18)

bin/Debug/resources.cfg

 FileSystem=../../media/
 FileSystem=../../media/Grid
 FileSystem=../../media/ssao
-FileSystem=../../media/ssao/ogre
-FileSystem=../../media/ssao/shanmugam
-FileSystem=../../media/ssao/rgba_iq
-FileSystem=../../media/ssao/crytek
-FileSystem=../../media/ssao/crease_detection
+#FileSystem=../../media/ssao/ogre
+#FileSystem=../../media/ssao/shanmugam
+#FileSystem=../../media/ssao/rgba_iq
+#FileSystem=../../media/ssao/crytek
+#FileSystem=../../media/ssao/crease_detection
+FileSystem=../../media/ssao/d3dbook
 FileSystem=../../media/models
 FileSystem=../../media/models/cassini
 FileSystem=../../media/ulb_building

bin/Release/resources.cfg

 FileSystem=../../media/ssao/shanmugam
 FileSystem=../../media/ssao/rgba_iq
 FileSystem=../../media/ssao/crytek
+FileSystem=../../media/ssao/d3dbook
 FileSystem=../../media/ulb_building
 FileSystem=../../media/models
 FileSystem=../../media/models/cassini

media/ssao/crytek/crytek_ssao.cg

 	}
 	
 	// get average value
-	accessibility /= nSampleNum;
+	accessibility /= 16;//nSampleNum;
 
 	// normalize, remove edge hightlighting
 	accessibility *= cEdgeHighlight;

media/ssao/d3dbook/d3dbook_ssao.cg

+struct AppData
+{
+    float4 p   : POSITION;
+    float3 n   : NORMAL;
+    float2 uv  : TEXCOORD0;
+};
+
+struct VertexOut
+{
+    float4 p             : POSITION;
+    float2 pixelPos      : TEXCOORD0;
+};
+
+struct FragmentInput
+{
+    float2 pixelPos      : TEXCOORD0;
+};
+
+//------------------------------------------------------------------------------
+VertexOut d3dbook_ssao_vs(AppData IN, uniform float4x4 wvp)
+{
+    VertexOut OUT;
+    OUT.p = mul(wvp, IN.p);
+
+	//OUT.p  = float4(IN.p.xy, 0, 1);
+    // clean up inaccuracies for the UV coords
+    float2 uv = sign(IN.p.xy);
+    // convert to image space
+    uv = (float2(uv.x, -uv.y) + 1.0) * 0.5;
+	OUT.pixelPos = uv;
+
+	//OUT.pixelPos = IN.uv;
+    
+	return OUT;
+
+}
+
+
+
+#define PI 3.141592653
+
+
+
+void d3dbook_ssao_ps(FragmentInput IN
+					//, uniform float4 cViewportSize
+					, uniform float farClipDistance
+					, uniform float nearClipDistance
+					, uniform float defaultOcclusion // [0, 1]
+					, uniform float kernelRadius     // [0, 5]
+					, uniform float rangeMultiplier   // [0, 5]
+					, uniform float deltaMultiplier   // [0, 1000]
+					, uniform sampler2D geomMap : TEX0      // normalized, linear depth buffer
+                    , uniform sampler2D randMap : TEX1     // random vectors
+					, out float4 oColor
+                   )
+{
+	 const float3 avKernel[8] =
+	{
+		normalize( float3( 1, 1, 1 ) ) * 0.125f,
+		normalize( float3( -1,-1,-1 ) ) * 0.250f,
+		normalize( float3( -1,-1, 1 ) ) * 0.375f,
+		normalize( float3( -1, 1,-1 ) ) * 0.500f,
+		normalize( float3( -1, 1 ,1 ) ) * 0.625f,
+		normalize( float3( 1,-1,-1 ) ) * 0.750f,
+		normalize( float3( 1,-1, 1 ) ) * 0.875f,
+		normalize( float3( 1, 1,-1 ) ) * 1.000f
+	};
+
+
+								
+
+	float fRadius = kernelRadius; 
+	float fPixelDepth = tex2D( geomMap, IN.pixelPos.xy ).r;
+	float fDepth = fPixelDepth * rangeMultiplier;
+
+	float clipDistance = farClipDistance - nearClipDistance;
+	float3 vKernelScale = float3( fRadius / fDepth, fRadius / fDepth, fRadius / clipDistance) ;
+	
+
+	float fOcclusion = 0.0f;
+	 
+	for ( int j = 1; j < 3; j++ )
+	{
+		float3 random = tex2D(randMap, IN.pixelPos.xy * ( 7.0f + (float)j ) ).xyz;
+		random = random * 2.0f - 1.0f;
+	 
+		for ( int i = 0; i < 8; i++ )
+		{
+			float3 vRotatedKernel = reflect( avKernel[i], random ) * vKernelScale;
+			float fSampleDepth = tex2D( geomMap, vRotatedKernel.xy + IN.pixelPos.xy ).r;
+			float fDelta = max( fSampleDepth - fPixelDepth + vRotatedKernel.z, 0 );
+			float fRange = abs( fDelta ) / ( vKernelScale.z * rangeMultiplier);
+	 
+			fOcclusion += lerp( fDelta * deltaMultiplier, defaultOcclusion, saturate( fRange ) );
+		}
+	}
+	
+
+	//fOcclusion += lerp( ( fDelta * deltaMultiplier), defaultOcclusion, saturate( fRange ) );
+
+	fOcclusion = fOcclusion / ( 2.0f * 8.0f );
+ 
+	// Range remapping
+	fOcclusion = lerp( 0.1f, 0.6, saturate( fOcclusion.x ) );
+
+	fOcclusion = 1.0-fOcclusion;
+	oColor = float4(fOcclusion.xxx, 1);
+
+	//OUT.color =	float4(fPixelDepth.xxx, 1);
+}							

media/ssao/d3dbook/d3dbook_ssao.material

+material SSAO/D3DBook/ssao
+{
+  technique
+  {
+    pass
+    {
+        depth_check off
+
+      vertex_program_ref d3dbook_ssao_vs
+      {
+      }
+
+      fragment_program_ref d3dbook_ssao_ps
+      {
+		param_named_auto	cViewportSize		viewport_size
+		param_named_auto	farClipDistance		far_clip_distance
+		param_named_auto	nearClipDistance	near_clip_distance
+
+		param_named			defaultOcclusion    float   0.5
+		param_named         kernelRadius        float   0.01
+		param_named			rangeMultiplier      float   3.0
+		param_named         deltaMultiplier      float   200.0
+      }
+
+      texture_unit geomMap
+      {
+        tex_address_mode clamp
+        filtering trilinear
+      }
+
+	  texture_unit randMap
+	  {
+		texture vector_noise.dds
+        tex_address_mode wrap
+		filtering point point point
+	    
+	  }
+
+    }
+  }
+}
+
+
+
+
+
+
+
+material SSAO/D3DBook/Combine
+{
+    technique
+    {
+        pass
+        {
+            lighting off
+
+            texture_unit
+            {
+                texture white.bmp
+                filtering bilinear
+            }
+
+            texture_unit
+            {
+                texture white.bmp
+                filtering bilinear
+            }
+        }
+    }
+
+
+}

media/ssao/d3dbook/d3dbook_ssao.program

+
+vertex_program d3dbook_ssao_vs cg
+{
+    source       d3dbook_ssao.cg
+    profiles     vs_3_0
+    entry_point  d3dbook_ssao_vs
+    
+    default_params
+    {
+        param_named_auto wvp worldviewproj_matrix
+    }
+}
+
+fragment_program d3dbook_ssao_ps cg
+{
+    source       d3dbook_ssao.cg
+    entry_point  d3dbook_ssao_ps
+    profiles     ps_3_0
+    default_params
+    {
+    }
+}
+

media/ssao/d3dbook/vector_noise.dds

Binary file added.

media/ssao/d3dbook/vector_noise_4x4.dds

Binary file added.

media/ssao/diffuse_gbuffer.cg

 struct AppData
 {
-    float4 position : POSITION;
+    float3 position : POSITION;
     float3 normal : NORMAL;
 };
 
 struct VertexOut
 {
     float4 position : POSITION;
-    float3 position_in_view_space : TEXCOORD0;
+    //float3 position_in_view_space : TEXCOORD0;
+	float viewDepth : TEXCOORD0;
     float3 normal_in_view_space   : TEXCOORD1;    
 };
 
 {
     VertexOut OUT;
 
-    OUT.position = mul(worldViewProjMatrix, IN.position);
-    OUT.position_in_view_space = mul(worldViewMatrix, IN.position).xyz;
-    OUT.normal_in_view_space = mul(worldViewMatrix, float4(IN.normal, 0)).xyz;
+    OUT.position = mul(worldViewProjMatrix, float4(IN.position, 1));
+    float3 viewpos = mul(worldViewMatrix, float4(IN.position, 1)).xyz;
+	OUT.viewDepth = viewpos.z;
+    
+
+	OUT.normal_in_view_space = mul(worldViewMatrix, float4(IN.normal, 0)).xyz;
 
     return OUT;
 }
 //------------------------------------------------------------------------------
 struct FragmentInput
 {
-    float3 position_in_view_space : TEXCOORD0;
+    float viewDepth : TEXCOORD0;
     float3 normal_in_view_space   : TEXCOORD1;    
 };
 
     FragmentOut OUT;
 
     
-    float3 p = IN.position_in_view_space.xyz;
+    //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 clipDistance = cFarClipDistance - cNearClipDistance;
+    //OUT.color.r = (p.z) - cNearClipDistance) / clipDistance; // norm to [0, 1]        
 
-	
+	float clipDistance = cFarClipDistance - cNearClipDistance;
+	float normDepth = IN.viewDepth / clipDistance;
+	OUT.color.r = normDepth; 
 
     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
+			
         }
     }
   }

media/ssao/diffuse_gbuffer.program

 vertex_program gbuffer_vs cg
 {
     source diffuse_gbuffer.cg
-    profiles vs_1_1 arbvp1
+    profiles vs_3_0
     entry_point geom_vs
 
     default_params
 fragment_program gbuffer_ps cg
 {
     source diffuse_gbuffer.cg
-    profiles ps_2_0 arbfp1
+    profiles ps_3_0
     entry_point geom_ps
 
     default_params
     {
-
+		param_named_auto cNearClipDistance near_clip_distance
+		param_named_auto cFarClipDistance far_clip_distance
     }
 }

media/ssao/rgba_iq/rgbaiq_ssao.cg

 
 #define PI 3.141592653
 #define PIXELSIZE 0.0003
-#define RADIUS 0.01
+#define RADIUS 0.001
 
 void rgbaiq_ssao_ps(
      FragmentInput IN

media/ssao/ssao.compositor

                 // our SSAO listener number
                 identifier 42
 
-                material SSAO/Crytek/ssao
+                material SSAO/D3DBook/ssao
                 input 0 GBuffer
             }
         }
             {
                 // just output something, for example, use a modulate
                 // material to just multiply the scene by the ssao
-                material SSAO/Crytek/Combine
+                material SSAO/D3DBook/Combine
                 input 0 scene
                 input 1 ssao
             }

media/ssao/ssao_debug.program

     default_params
     {
         param_named_auto wvp worldviewproj_matrix
+
     }
 }
 

media/ssao/ssao_with_debug.compositor

                 // our SSAO listener number
                 identifier 42
 
-                material SSAO/Crytek/ssao
+                material SSAO/D3DBook/ssao
                 input 0 GBuffer
             }
         }
             {
                 // just output something, for example, use a modulate
                 // material to just multiply the scene by the ssao
-                material SSAO/Crytek/Combine
+                material SSAO/D3DBook/Combine
                 input 0 scene
                 input 1 ssao
             }

ogre-ssao/OgreApplication.cpp

     mCamera = mSceneMgr->createCamera("PlayerCam");
 
 
-    mCamera->setNearClipDistance(0.5);
+    mCamera->setNearClipDistance(0.05);
     mCamera->setFarClipDistance(1500.0);
 }
 //-----------------------------------------------------------------------------
 {
     Ogre::Viewport *viewport = mWindow->getViewport(0);
     assert(viewport);
-    mSSAOCompositor = Ogre::CompositorManager::getSingletonPtr()->addCompositor(viewport, "SSAO/Compositor");
+    mSSAOCompositor = Ogre::CompositorManager::getSingletonPtr()->addCompositor(viewport, "SSAO/DebugCompositor");
  
     if(!mSSAOCompositor)
         OGRE_EXCEPT(Ogre::Exception::ERR_RT_ASSERTION_FAILED, "Failed to create ssao compositor", "OgreApplication::_initSSAO");

ogre-ssao/SSAOApp.cpp

 void SSAOApp::_populate()
 {   
     //_loadSponzaAtrium();
-    //_loadHebeCassini();
+    _loadHebeCassini();
     //_loadULBCampus();
-    _loadOgreMaxScene("../../media/scenes/pleyel/", "amphi.scene");
+    //_loadOgreMaxScene("../../media/scenes/amphimath/", "amphimath.scene");
+    //_loadOgreMaxScene("../../media/scenes/pleyel/", "amphi.scene");
 }
 //-----------------------------------------------------------------------------
 void SSAOApp::_loadHebeCassini()

ogre-ssao/ogre-ssao.vcproj

 						>
 					</File>
 				</Filter>
+				<Filter
+					Name="d3dbook"
+					>
+					<File
+						RelativePath="..\media\ssao\d3dbook\d3dbook_ssao.cg"
+						>
+					</File>
+					<File
+						RelativePath="..\media\ssao\d3dbook\d3dbook_ssao.material"
+						>
+					</File>
+					<File
+						RelativePath="..\media\ssao\d3dbook\d3dbook_ssao.program"
+						>
+					</File>
+				</Filter>
 			</Filter>
 		</Filter>
 		<Filter