Commits

Frederic De Groef committed 77fe4a7

fixed the bad post process vertex shader that was fucking up pretty much everything

  • Participants
  • Parent commits bae992f

Comments (0)

Files changed (14)

File bin/Debug/Plugins.cfg

 # Define plugins
 Plugin=RenderSystem_Direct3D9_d
 Plugin=RenderSystem_GL_d
-Plugin=Plugin_OctreeSceneManager_d
 Plugin=Plugin_CgProgramManager_d
 
 

File bin/Debug/resources.cfg

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

File media/ssao/crytek/crytek_ssao.cg

     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
     
 
     float ao = 0.0f;
-    float2 rand = normalize(tex2D(randMap, IN.pixelPos/64  ).xy * 2.0f - 1.0f);
+    float2 rand = normalize(tex2D(randMap, IN.pixelPos/1024  ).xy * 2.0f - 1.0f);
     
     
     //float rad = RADIUS * depth;
     for (int i = 0; i < 4; i++)
     {
 
-        float2 coords1 = reflect(vec[i], rand) * rad;
-        //float2 coords1 = rand * rad;
+    //float2 coords1 = reflect(vec[i], rand) * rad;
+        float2 coords1 = rand * rad;
         
         float2 coords2 = float2(coords1.x * 0.707 - coords1.y * 0.707,
                                 coords1.x * 0.707 + coords1.y * 0.707);

File media/ssao/crytek/crytek_ssao.material

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

File media/ssao/crytek/crytek_ssao.program

 {
     source       crytek_ssao.cg
     entry_point  crytek_ssao_ps
-    profiles     ps_3_0
+    profiles     ps_2_x
     default_params
     {
     }

File media/ssao/diffuse_gbuffer.cg

 struct VertexOut
 {
     float4 position : POSITION;
-    float3 position_in_view_space : TEXCOORD0;
+    float4 position_in_view_space : TEXCOORD0;
     float3 normal_in_view_space   : TEXCOORD1;    
 };
 
 
 VertexOut geom_vs(
     AppData IN    
-    ,uniform float4x4 world_view_proj_matrix
-    ,uniform float4x4 world_view_matrix)
+    ,uniform float4x4 worldViewProjMatrix
+    ,uniform float4x4 worldViewMatrix)
 {
     VertexOut OUT;
 
-    OUT.position = mul(world_view_proj_matrix, IN.position);
-    OUT.position_in_view_space = mul(world_view_matrix, IN.position);
-    OUT.normal_in_view_space = mul(world_view_matrix, float4(IN.normal, 0));
+    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));
 
     return OUT;
 }
 //------------------------------------------------------------------------------
 struct FragmentInput
 {
-    float3 position_in_view_space : TEXCOORD0;
-    float3 normal_in_view_space   : TEXCOORD1;    
+    float4 position_in_view_space : TEXCOORD0;
+    float4 normal_in_view_space   : TEXCOORD1;    
 };
 
 struct FragmentOut
 };
 
 
-FragmentOut geom_ps(
-    FragmentInput IN
-    ,uniform float far)
+FragmentOut geom_ps(FragmentInput IN)
 {
     FragmentOut OUT;
 
-    float3 p = IN.position_in_view_space;
-    float3 n = IN.normal_in_view_space;
+    
+    float3 p = IN.position_in_view_space.xyz;
+    float3 n = IN.normal_in_view_space.xyz;
     
     float depth = length(p);
-    float3 normal = normalize(n);
+    float3 normal = normalize(n.xyz);
     
-    OUT.color = float4(depth/far, normal);
+    OUT.color = float4(depth, normal);
 
     return OUT;
 }

File media/ssao/diffuse_gbuffer.program

 
     default_params
     {
-        param_named_auto world_view_proj_matrix  worldviewproj_matrix
-        param_named_auto world_view_matrix       worldview_matrix
+        param_named_auto worldViewProjMatrix  worldviewproj_matrix
+        param_named_auto worldViewMatrix      worldview_matrix
     }
 }
 
 
     default_params
     {
-        param_named_auto far far_clip_distance
+
     }
 }

File media/ssao/rgba_iq/rgbaiq_ssao.cg

 };
 
 //------------------------------------------------------------------------------
-VertexOut rgbaiq_ssao_vs(AppData IN, uniform float4x4 wvp, uniform float3 farCorner)
+VertexOut rgbaiq_ssao_vs(
+    AppData IN
+    ,uniform float4x4 worldViewProj)
 {
     VertexOut OUT;
-    OUT.p = mul(wvp, IN.p);
+    OUT.p = mul( worldViewProj, IN.p);
+    
     // clean up inaccuracies for the UV coords
-    float2 uv = sign(IN.p.xy);
-    OUT.p = float4(uv, 0, 1);
+    float2 uv = sign(IN.p);
+    //    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;
 }
 
 void rgbaiq_ssao_ps(
      FragmentInput IN
     ,uniform sampler2D geomMap : TEXUNIT0
-	,uniform sampler2D randMap : TEXUNIT1
-	,uniform sampler1D colorMap : TEXUNIT2
+    ,uniform float farDistance
     ,out float4 oColor)
 {
 
     float4 sample = tex2D(geomMap, IN.pixelPos);
     float z = sample.r ;
-
+    
 
     float3 P = float3(IN.pixelPos, z);
     
     
     int count = 0;
     
+
+    float2 samples[8] = {
+        float2(1.0, 0.0),
+        float2(0.70710678118654757, 0.70710678118654746),
+        float2(0, 1.0),
+        float2(-0.70710678118654746, 0.70710678118654757),
+        float2(-1.0, 0),
+        float2(-0.70710678118654768, -0.70710678118654746),
+        float2(0, -1.0),
+        float2(0.70710678118654735, -0.70710678118654768)        
+    };
     
-    
+       
     for (int i=0 ; i<8; i++)
     {
         float x, y;
-        sincos(i*PI / 8, x, y);
          
-        float2 coords = z*PIXELSIZE * float2(x, y);
+        float2 coords =   samples[i];
+        
          
-        float2 neighbour_coords = IN.pixelPos + coords;
+        float2 neighbour_coords = IN.pixelPos + coords*0.003;
          
-        float sampled_depth = tex2D(geomMap,  neighbour_coords);
+        float sampled_depth = tex2D(geomMap,  neighbour_coords).r;
          
         float3 Q = float3(neighbour_coords, sampled_depth);
          
          
-        float len = length(P-Q);
-        //float len = abs(z-sampled_depth);
+        //float len = length(P-Q);
+        float len = abs(z-sampled_depth);
         
-        if(sampled_depth < z && len<0.02)
+        if(sampled_depth < z && len < 10)
         {
             count += 1;
         }
         oColor = float4(0, 0, 0, 1);
     else
         oColor = float4(1);
-    
+
+    float2 uv = IN.pixelPos;    
 }

File media/ssao/rgba_iq/rgbaiq_ssao.material

 {
   technique
   {
-    pass
+    pass ambient_occlusion
     {
       vertex_program_ref rgbaiq_ssao_vs
       {
+        param_named_auto worldViewProj worldviewproj_matrix
       }
 
       fragment_program_ref rgbaiq_ssao_ps
       {
-        param_named_auto far far_clip_distance
+      
+
       }
 
       texture_unit geomMap
       {
         tex_address_mode clamp
         filtering none
-      }
-
-      texture_unit randMap
-      {
-        texture noise.dds
-        filtering none
-        tex_coord_set 0
-        tex_address_mode wrap
-      }
-      
-      texture_unit colorMap
-      {
-        texture colormap.bmp
-      }
-      
+      }      
     }
   }
 }

File media/ssao/rgba_iq/rgbaiq_ssao.program

     
     default_params
     {
-        param_named_auto wvp worldviewproj_matrix
+
     }
 }
 
 {
     source       rgbaiq_ssao.cg
     entry_point  rgbaiq_ssao_ps
-    profiles     ps_3_0 arbfp1
+    profiles     ps_2_x arbfp1
     default_params
     {
+        param_named_auto farDistance far_clip_distance
     }
 }
 

File media/ssao/ssao.compositor

 {
     technique
     {
-        texture geom target_width target_height PF_FLOAT32_RGBA
+        texture GBuffer target_width target_height PF_FLOAT32_RGBA
         texture scene target_width target_height PF_R8G8B8A8
-        //texture ssao target_width_scaled 0.5 target_height_scaled 0.5 PF_R8G8B8
 		texture ssao target_width target_height PF_R8G8B8
         texture final target_width target_height PF_R8G8B8A8
 
             input previous
         }
 
-        // the normals + depth render
-        // feel free to play with it
-        // right now it uses a 64-bit "fat" buffer that contains
-        // unnormalized depth and XYZ normals
-        target geom
+        target GBuffer
         {
             input none
             material_scheme geom
                 // our SSAO listener number
                 identifier 42
 
-                material SSAO/Crytek/ssao
-                input 0 geom
+                material SSAO/rgba_iq/ssao
+                input 0 GBuffer
             }
         }
 
    
 
-		target output
+		target_output
 		{
             input none
 

File media/ssao/ssao_debug.cg

 			float depth = tex2D(geomMap, scale * (coords - float2(0.0, VSPLIT))).r;	            
             
 			//oColor = float4(depth, depth, depth, 1.0f); 
-			oColor = tex1D(colorMap, depth);
+			oColor = tex1D(colorMap, depth/far);
 		}
 		// normal buffer
 		else if(coords.x < (2*TOP_HSPLIT))

File media/ssao/ssao_with_debug.compositor

 {
     technique
     {
-        texture GBuffer target_width target_height PF_FLOAT16_RGBA
+        texture GBuffer target_width target_height PF_FLOAT32_RGBA
 
         texture scene target_width target_height PF_R8G8B8A8
 		texture ssao target_width target_height PF_R8G8B8A8
             {
                 // just output something, for example, use a modulate
                 // material to just multiply the scene by the ssao
-                material SSAO/Ogre/Modulate
+                material SSAO/rgba_iq/Combine
                 input 0 scene
                 input 1 ssao
             }

File ogre-ssao/OgreApplication.cpp

 {
     // Initialise, parse scripts etc
     ResourceGroupManager::getSingleton().initialiseAllResourceGroups();
+    Ogre::TextureManager::getSingleton().setDefaultNumMipmaps(5);
 }
 //-----------------------------------------------------------------------------
 void OgreApplication::destroyScene()
         params->setNamedConstant("farCorner", farCorner);
     //else
     //    OGRE_EXCEPT(Ogre::Exception::ERR_INVALIDPARAMS
-    //    , "Could not find parameter farCorner in material " + mat->getName()
+    //    , "Could not find parameter <farCorner> for vertex shader <"+pass->getVertexProgramName()+">in material <" + mat->getName()+">"
     //    , "Ogre::Application::notifyMaterialRenderer()");
 
-
+       
 
     // get the fragment shader parameters
     params = pass->getFragmentProgramParameters();
         0,      0,    0,    1);
 
   
- /*   if (params->_findNamedConstantDefinition("clip_to_image_matrix"))
+    if (params->_findNamedConstantDefinition("clip_to_image_matrix"))
         params->setNamedConstant("clip_to_image_matrix", CLIP_SPACE_TO_IMAGE_SPACE * cam->getProjectionMatrixWithRSDepth());
- */   //else
+    //else
     //    OGRE_EXCEPT(Ogre::Exception::ERR_INVALIDPARAMS
     //               , "Could not find parameter 'clip_to_image_matrix' in material " + mat->getName()
     //               , "Ogre::Application::notifyMaterialRenderer()");
                             
 
     float farDistance = cam->getFarClipDistance();
-  /*  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()");
-
+    if (params->_findNamedConstantDefinition("farDistance"))    
+        params->setNamedConstant("farDistance", farDistance);
+ /*   else
+        OGRE_EXCEPT(Ogre::Exception::ERR_INVALIDPARAMS
+                   , "Could not find parameter <farDistance> for fragment shader <"+pass->getFragmentProgramName()+"> in material <" + mat->getName()+">"
+                   , "Ogre::Application::notifyMaterialRenderer()");
+*/
 
 }
 
 
 
    // mSSAOCompositor->getRenderTarget("ssao")->writeContentsToTimestampedFile("gbuffer_", ".png");
-     mWindow->writeContentsToTimestampedFile("final scene", ".png");
+     //mWindow->writeContentsToTimestampedFile("final scene", ".png");
 
     Ogre::PixelBox gbufferContent(w, h, 1, gbuffer->suggestPixelFormat(), data);
     gbuffer->copyContentsToMemory(gbufferContent);