2012年7月24日 星期二

所以我的折射程式...

進入正題,

我的折射程式經調查之後, 應該是留在程式裏...
它變成了 Ripple Compositor, 也就是水波紋程式

我把它複製起來, 改了一個名字叫 SSD, Screen Space Distortion
我們來看看要怎麼改回 折射的程式
首先, 我想到兩個問題,
第一個: 如何製作折射程度圖, 在畫折射圖的時候, 其他的東西都不要畫上去
第二個: 如何將折射圖放入折射Compositor 的 Material

一直到下班前, 大概的進度如下:
用程式產生 一個叫 RzSSD的Compositor, 最後一個OutputTargetPass為

CompositionTargetPass* output = technique->getOutputTargetPass();
{
 CompositionPass* pass = output->createPass();
 pass->setType(Ogre::CompositionPass::PT_RENDERQUAD);
 pass->setIdentifier(OutputTargetPass);
 pass->setMaterialName("Rz/Compositor/SpaceDistortPass");
 pass->setInput(0, "rt0");
 //pass->setInput(1, "rt1");
}

其中 material Rz/Compositor/SpaceDistortPass 長這個樣子


material Rz/Compositor/SpaceDistortPass
{
 technique Best
 {
  pass
  {
   depth_check off

   vertex_program_ref Ogre/Compositor/StdQuad_Cg_vp
   {
   }

   fragment_program_ref Rz/Compositor/SpaceDistortFP
   {
   }

   texture_unit RT
   {
                                tex_coord_set 0
    tex_address_mode clamp
    filtering linear linear linear
   }

   texture_unit Water
   {
    texture WaterNormal1.tga 2d
                                tex_coord_set 1
    //tex_address_mode clamp
    filtering linear linear linear
   }   

   texture_unit SSD_Normal
   {
    //texture SSD_Normal
                                tex_coord_set 1
    //tex_address_mode clamp
    filtering linear linear linear
   }
  }
 }
}

原本應該是Normal圖的地方 變成了 Water圖
fragment_program Rz/Compositor/SpaceDistortFP長這個樣子:
float4 SpaceDistort_FP( 
    float2 iTexCoord : TEXCOORD0
   ,uniform float  Distortion
   ,uniform float  ColorAdd
        ) : COLOR
{
 float4 CompressNormal = tex2D(NormalMap, iTexCoord);
 float4 Normal = CompressNormal *2.0 - 1.0;
 //float4 reflect
 
 float2 UV = clamp(iTexCoord + Normal.xy* Distortion,0.01,1.0);
 Normal.z = 0;
 
 return tex2D(RT, UV) + Normal * ColorAdd;
}

所以程式執行起來就像是被Water圖扭曲過一樣

失敗的是原本用來當做扭曲Normal的OgreHead沒有消失, 也不知道怎麼畫在Normal圖上
明天繼續奮鬥

沒有留言:

張貼留言