Commits

Frederic De Groef committed 947f6e0

laplace filter

Comments (0)

Files changed (10)

media/ssao/crytek/crytek_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 crytek_ssao_vs(AppData IN, uniform float4x4 wvp, uniform float3 farCorner)
+{
+    VertexOut OUT;
+    OUT.p = mul(wvp, IN.p);
+    // clean up inaccuracies for the UV coords
+    float2 uv = sign(IN.p.xy);
+    OUT.p = float4(uv, 0, 1);
+    
+
+    // convert to image space
+    uv = (float2(uv.x, -uv.y) + 1.0) * 0.5;
+    OUT.pixelPos = uv;
+    
+	return OUT;
+}
+
+
+
+//------------------------------------------------------------------------------
+
+
+#define PI 3.1416
+#define NUM_SAMPLES 32
+#define RADIUS 0.015
+#define MAX_DISTANCE 0.01
+
+
+void crytek_ssao_ps(FragmentInput IN
+    ,uniform float far
+    ,uniform sampler2D geomMap : TEXUNIT0
+	,uniform sampler2D randMap : TEXUNIT1
+    ,out float4 oColor)
+{
+
+       
+    float2 samples[4] = {
+        0, -1,
+        -1,  0,
+        1,  0,
+        0,  1,
+    };
+
+    float pixelSize =  0.0031;
+    float scale =4 ;
+    
+
+    float depth = tex2D(geomMap, IN.pixelPos).r;
+    
+    float laplace = -4 * depth;
+
+    // Sample the neighbor pixels
+    for (int i = 0; i < 4; i++)
+    {
+        float sample = tex2D(geomMap, IN.pixelPos + pixelSize * samples[i]).r;
+    
+
+        laplace += sample;
+    }
+    
+    float occ = 0.5 + scale * laplace;
+    
+    
+    //occ = 1-occ;
+    
+    oColor = float4(occ, occ, occ, 1);
+    
+}

media/ssao/crytek/crytek_ssao.material

+material SSAO/Crytek/ssao
+{
+  technique
+  {
+    pass
+    {
+      vertex_program_ref crytek_ssao_vs
+      {
+      }
+
+      fragment_program_ref crytek_ssao_ps
+      {
+      }
+
+      texture_unit geomMap
+      {
+        tex_address_mode clamp
+        filtering none
+      }
+
+      texture_unit randMap
+      {
+        texture noise.png
+        filtering none
+        tex_coord_set 0
+        tex_address_mode wrap
+      }
+    }
+  }
+}

media/ssao/crytek/crytek_ssao.program

+
+vertex_program crytek_ssao_vs cg
+{
+    source       crytek_ssao.cg
+    profiles     vs_1_1 arbvp1
+    entry_point  crytek_ssao_vs
+    
+    default_params
+    {
+        param_named_auto wvp worldviewproj_matrix
+    }
+}
+
+fragment_program crytek_ssao_ps cg
+{
+    source       crytek_ssao.cg
+    entry_point  crytek_ssao_ps
+    profiles     ps_3_0
+    default_params
+    {
+    }
+}
+

media/ssao/ogre/ogre_ssao.cg

     {
 
         //float3 direction = reflect(RAND_SAMPLES[i], randN) + normal; 
-    float3 direction = RAND_SAMPLES[i+1] + normal; 
+        float3 direction = RAND_SAMPLES[i+1] + normal; 
 
         float4 neighbour_coords = mul(clip_to_image_matrix,  float4(viewPos.xyz + direction * radius, 1));
         neighbour_coords.xy /=  neighbour_coords.w;

media/ssao/ogre/ogre_ssao.material

 
             texture_unit randMap
             {
-                texture random.png
+                texture noise.png
                 filtering none
 				tex_coord_set 0
 				tex_address_mode wrap

media/ssao/ssao_debug.program

+
+vertex_program ssao_debug_vs cg
+{
+    source ssao_debug.cg
+    profiles vs_1_1 arbvp1
+    entry_point ssao_debug_vs
+    default_params
+    {
+        param_named_auto wvp worldviewproj_matrix
+    }
+}
+
+fragment_program ssao_debug_ps cg
+{
+    source ssao_debug.cg
+    entry_point ssao_debug_ps
+    // will run on anything with pixel shader 2.b and up
+    profiles ps_2_x arbfp1
+    default_params
+    {
+    }
+}
+

media/ssao/ssao_with_debug.compositor

                 // our SSAO listener number
                 identifier 42
 
-                material SSAO/Ogre/ssao
+                material SSAO/Crytek/ssao
                 input 0 GBuffer
             }
         }

ogre-ssao/OgreApplication.cpp

     // calculate the far-top-right corner in view-space
     Ogre::Vector3 farCorner = cam->getViewMatrix(true) * cam->getWorldSpaceCorners()[4];
 
-    //{
-    //    const Matrix4 &cameraMatrix = cam->getViewMatrix(true);
-    //    const Ogre::Vector3 *corners =  cam->getWorldSpaceCorners();
-    //                                                                             
-    //    mSSAOLog->logMessage("top right    : " + Ogre::StringConverter::toString(cameraMatrix * corners[4]));
-    //    mSSAOLog->logMessage("top left     : " + Ogre::StringConverter::toString(cameraMatrix * corners[5]));
-    //    mSSAOLog->logMessage("bottom left  : " + Ogre::StringConverter::toString(cameraMatrix * corners[6]));
-    //    mSSAOLog->logMessage("bottom right : " + Ogre::StringConverter::toString(cameraMatrix * corners[7]));
-    //    mSSAOLog->logMessage("");
-    //} 
-
-
 
    // get the pass
     Ogre::Pass *pass = mat->getBestTechnique()->getPass(0);
     // set the camera's far-top-right corner
     if (params->_findNamedConstantDefinition("farCorner"))
         params->setNamedConstant("farCorner", farCorner);
-    else
-        OGRE_EXCEPT(Ogre::Exception::ERR_INVALIDPARAMS
-        , "Could not find parameter farCorner in material " + mat->getName()
-        , "Ogre::Application::notifyMaterialRenderer()");
+    //else
+    //    OGRE_EXCEPT(Ogre::Exception::ERR_INVALIDPARAMS
+    //    , "Could not find parameter farCorner in material " + mat->getName()
+    //    , "Ogre::Application::notifyMaterialRenderer()");
 
 
 
   
     if (params->_findNamedConstantDefinition("clip_to_image_matrix"))
         params->setNamedConstant("clip_to_image_matrix", CLIP_SPACE_TO_IMAGE_SPACE * cam->getProjectionMatrixWithRSDepth());
-    else
-        OGRE_EXCEPT(Ogre::Exception::ERR_INVALIDPARAMS
-                   , "Could not find parameter 'clip_to_image_matrix' in material " + mat->getName()
-                   , "Ogre::Application::notifyMaterialRenderer()");
+    //else
+    //    OGRE_EXCEPT(Ogre::Exception::ERR_INVALIDPARAMS
+    //               , "Could not find parameter 'clip_to_image_matrix' in material " + mat->getName()
+    //               , "Ogre::Application::notifyMaterialRenderer()");
    
 
     if (params->_findNamedConstantDefinition("far"))
         params->setNamedConstant("far", cam->getFarClipDistance());
-    else
-        OGRE_EXCEPT(Ogre::Exception::ERR_INVALIDPARAMS
-                   , "Could not find parameter 'far' in material " + mat->getName()
-                   , "Ogre::Application::notifyMaterialRenderer()");
+    //else
+    //    OGRE_EXCEPT(Ogre::Exception::ERR_INVALIDPARAMS
+    //               , "Could not find parameter 'far' in material " + mat->getName()
+    //               , "Ogre::Application::notifyMaterialRenderer()");
 
 
 }

ogre-ssao/SSAOApp.cpp

 
 //-----------------------------------------------------------------------------
 SSAOApp::SSAOApp()
-    :OgreApplication("ULB_Building_viz", CT_MOUSE)
+    :OgreApplication("SSAO sandbox", CT_MOUSE)
     ,mBBset(NULL)
     ,mLightFlare(NULL)
     ,mLight(NULL)
     _createLight();
     _populate();
 
+
+    mCamera->setPosition(-200, 100, 500);
+    mCamera->lookAt(Ogre::Vector3::ZERO);
+
+
     _createDebugOverlay();
 }
 //-----------------------------------------------------------------------------
     _loadMesh("ogrehead", Vector3(-50, 20, 0));
 
 
-    //_loadMesh("cassini_10", Vector3(-200, 100, 0));
-    //_loadMesh("cassini_11", Vector3(-200, 100, 0));
-    //_loadMesh("cassini_13", Vector3(-200, 100, 0));
-    //_loadMesh("cassini_14", Vector3(-200, 100, 0));
-    //_loadMesh("cassini_15", Vector3(-200, 100, 0));
-    //_loadMesh("cassini_a1", Vector3(-200, 100, 0));
-    //_loadMesh("cassini_a2", Vector3(-200, 100, 0));
-    //_loadMesh("cassini_a4", Vector3(-200, 100, 0));
-    //_loadMesh("cassini_a5", Vector3(-200, 100, 0));
-    //_loadMesh("cassini_a6", Vector3(-200, 100, 0));
-    //_loadMesh("cassini_a7", Vector3(-200, 100, 0));
-    //_loadMesh("cassini_a8", Vector3(-200, 100, 0));
-    //_loadMesh("cassini_as", Vector3(-200, 100, 0));
+    Vector3 cassiniPosition = Vector3(-300, 100, 0);
+    _loadMesh("cassini_10", cassiniPosition);
+    _loadMesh("cassini_11", cassiniPosition);
+    _loadMesh("cassini_13", cassiniPosition);
+    _loadMesh("cassini_14", cassiniPosition);
+    _loadMesh("cassini_15", cassiniPosition);
+    _loadMesh("cassini_a1", cassiniPosition);
+    _loadMesh("cassini_a2", cassiniPosition);
+    _loadMesh("cassini_a4", cassiniPosition);
+    _loadMesh("cassini_a5", cassiniPosition);
+    _loadMesh("cassini_a6", cassiniPosition);
+    _loadMesh("cassini_a7", cassiniPosition);
+    _loadMesh("cassini_a8", cassiniPosition);
+    _loadMesh("cassini_as", cassiniPosition);
 
 
-
-
-    //_loadMesh("athene", Vector3(-150, 70, 0));
-    
-    //Ogre::SceneNode *node = _loadMesh("mikki", Vector3::ZERO);
-    //node->scale(10, 10, 10);
-
+    Ogre::SceneNode *node= _loadMesh("hebemissin", Vector3(0, 0, 200));
+    node->scale(20, 20, 20);
 
 }
 //-----------------------------------------------------------------------------
     Ogre::Entity *ent = mSceneMgr->createEntity(entityName, _name+".mesh");
     Ogre::SceneNode *node = mSceneMgr->getRootSceneNode()->createChildSceneNode(ent->getName()+"Node", _pos);
 
-    //ent->setMaterialName("blue");
+
     ent->setMaterialName("SSAO/DiffuseLight_GBuffer");
     node->attachObject(ent);
 
 //-----------------------------------------------------------------------------
 void SSAOApp::_createLight()
 {
-    //mBBset = mSceneMgr->createBillboardSet("Light BB");
-    //mBBset->setMaterialName("Objects/Flare");
-    //mLightFlare = mBBset->createBillboard(Ogre::Vector3::ZERO);
+    mBBset = mSceneMgr->createBillboardSet("Light BB");
+    mBBset->setMaterialName("Objects/Flare");
+    mLightFlare = mBBset->createBillboard(Ogre::Vector3::ZERO);
 
     mLight = mSceneMgr->createLight("main light");
     mLight->setType(Ogre::Light::LT_POINT);
     mLight->setDiffuseColour(Ogre::ColourValue::White);
-    //mLight->setSpecularColour(Ogre::ColourValue::White);
+    mLight->setSpecularColour(Ogre::ColourValue::White);
 
     mLightNode = mSceneMgr->getRootSceneNode()->createChildSceneNode("light node");
     mLightNode->attachObject(mLight);
-    //mLightNode->attachObject(mBBset);
+    mLightNode->attachObject(mBBset);
 
-    mLightNode->setPosition(Ogre::Vector3(200, 200, 0));
+    mLightNode->setPosition(Ogre::Vector3(0, 200, 500));
 
 }
 //-----------------------------------------------------------------------------

ogre-ssao/ogre-ssao.vcproj

 			<Filter
 				Name="SSAO"
 				>
+				<File
+					RelativePath="..\media\ssao\diffuse_gbuffer.cg"
+					>
+				</File>
+				<File
+					RelativePath="..\media\ssao\diffuse_gbuffer.material"
+					>
+				</File>
+				<File
+					RelativePath="..\media\ssao\diffuse_gbuffer.program"
+					>
+				</File>
+				<File
+					RelativePath="..\media\ssao\ssao.compositor"
+					>
+				</File>
+				<File
+					RelativePath="..\media\ssao\ssao_debug.cg"
+					>
+				</File>
+				<File
+					RelativePath="..\media\ssao\ssao_debug.material"
+					>
+				</File>
+				<File
+					RelativePath="..\media\ssao\ssao_debug.program"
+					>
+				</File>
+				<File
+					RelativePath="..\media\ssao\ssao_with_debug.compositor"
+					>
+				</File>
+				<Filter
+					Name="ogre"
+					>
+					<File
+						RelativePath="..\media\ssao\ogre\noise.png"
+						>
+					</File>
+					<File
+						RelativePath="..\media\ssao\ogre\ogre_ssao.cg"
+						>
+					</File>
+					<File
+						RelativePath="..\media\ssao\ogre\ogre_ssao.material"
+						>
+					</File>
+					<File
+						RelativePath="..\media\ssao\ogre\ogre_ssao.program"
+						>
+					</File>
+				</Filter>
 			</Filter>
 		</Filter>
 		<Filter