Commits

Murat Sari committed b80eba2

SSAO: Add checkbox to enable/disable ssao result modulation with orginal scene

  • Participants
  • Parent commits dad2d33
  • Branches v1-9

Comments (0)

Files changed (5)

File Samples/Media/materials/scripts/SSAO/Modulate.cg

     
     out float4 oColor0 : COLOR0,
 
-    uniform sampler scene: register(s0),
-    uniform sampler occlusion : register(s1)
+    uniform sampler ssao : register(s0),
+	uniform sampler scene: register(s1)
 )
 {
-    oColor0 = float4((tex2D(scene, uv) * tex2D(occlusion, uv)).rgb, 1);
+    oColor0 = float4((tex2D(scene, uv) * tex2D(ssao, uv)).rgb, 1);
 }

File Samples/Media/materials/scripts/SSAO/Modulate.material

     	
 	default_params
 	{
-		param_named scene int 0
-		param_named occlusion int 1
+		param_named ssao int 0
+		param_named scene int 1
 	}
 }
 
 			vertex_program_ref Ogre/Compositor/StdQuad_vp {}
             fragment_program_ref SSAO/Post/Modulate_fp {}
 			
-            texture_unit
+			texture_unit
+            {
+				content_type compositor SSAO/Post/Modulate ssao
+                filtering none
+            }
+			
+			texture_unit
             {
 				content_type compositor SSAO/GBuffer scene
                 filtering bilinear
             }
-
-			texture_unit
-            {
-                content_type compositor SSAO/GBuffer occlusion
-                tex_address_mode clamp
-                filtering bilinear
-            }
         }
     }
 }

File Samples/Media/materials/scripts/SSAO/ModulateFP.glsl

 #version 120
 varying vec2 uv;
 
+uniform sampler2D ssao;
 uniform sampler2D scene;
-uniform sampler2D occlusion;
 	
 void main()
 {
-    gl_FragColor = vec4((texture2D(scene, uv) * texture2D(occlusion, uv)).rgb, 1.0);
+    gl_FragColor = vec4((texture2D(scene, uv) * texture2D(ssao, uv)).rgb, 1.0);
 }

File Samples/Media/materials/scripts/SSAO/SSAOPost.compositor

 {
     technique 
     {
-        target_output
+		texture ssao target_width target_height PF_A8R8G8B8 chain_scope
+        
+	    target ssao
+        {
+            input previous
+        }
+		
+		target_output
         {
             input none
             

File Samples/SSAO/include/SSAO.h

 #define SSAO_CREASE_AVERAGER_NAME "mCreaseAverager"
 #define SSAO_CREASE_KERNELSIZE_NAME "mCreaseKernelsize"
 
+#define SSAO_MODUALTE "mdoulate"
 #define SSAO_SAMPLE_SPACE_NAME "sampleSpace"
 #define SSAO_SAMPLE_LENGTH_SCREENSPACE "sampleScreenSpace"
 #define SSAO_SAMPLE_LENGTH_WORLDSPACE "sampleWorldSpace"
 	
 	std::vector<String> mPostNames;
 	String mCurrentPost;
+	String mCurrentModulateScheme;
 
 	SSAOGBufferSchemeHandler* mGBufSchemeHandler;
     
         mCompositorNames.push_back("SSAO/ShowViewPos");
         
         mPostNames.push_back("SSAO/Post/NoFilter");
-        mPostNames.push_back("SSAO/Post/Modulate");
         mPostNames.push_back("SSAO/Post/CrossBilateralFilter");
         mPostNames.push_back("SSAO/Post/SmartBoxFilter");
         mPostNames.push_back("SSAO/Post/BoxFilter");
                                     0,
                                     10,
                                     101); // snaps ???
-        
         // --- sample length parameter ---
-        mTrayMgr->createSeparator(TL_TOPLEFT, "sep");
+		mTrayMgr->createSeparator(TL_TOPLEFT, "sep");
+
+		mTrayMgr->createCheckBox(TL_TOPLEFT, SSAO_MODUALTE, "Modulate with scene", SSAO_GUI_WIDTH);
+
+        // --- sample length parameter ---
+        mTrayMgr->createSeparator(TL_TOPLEFT, "sep2");
         mTrayMgr->createCheckBox(TL_TOPLEFT, SSAO_SAMPLE_SPACE_NAME, "Sample in Screen Space", SSAO_GUI_WIDTH);
         mTrayMgr->createThickSlider(TL_TOPLEFT,
                                     SSAO_SAMPLE_LENGTH_SCREENSPACE,
     
     void checkBoxToggled(OgreBites::CheckBox *box) 
     {
-        if (box->getName() == SSAO_SAMPLE_SPACE_NAME)
+		if(box->getName() == SSAO_MODUALTE)
+		{
+			if (box->isChecked())
+			{
+				CompositorManager::getSingleton().addCompositor(mViewport, "SSAO/Post/Modulate");
+	            CompositorManager::getSingleton().setCompositorEnabled(mViewport, "SSAO/Post/Modulate", true);
+			}
+			else
+			{  
+                CompositorManager::getSingleton().setCompositorEnabled(mViewport, "SSAO/Post/Modulate", false);
+				CompositorManager::getSingleton().removeCompositor(mViewport, "SSAO/Post/Modulate");
+			}
+		}
+        else if (box->getName() == SSAO_SAMPLE_SPACE_NAME)
         {
             setUniform("SSAO/Crytek", "SSAO/Crytek", "cSampleInScreenspace", box->isChecked(), false, 1);
             setUniform("SSAO/HorizonBased", "SSAO/HorizonBased", "cSampleInScreenspace", box->isChecked(), false, 1);