2012-11-23 41 views
0

我殺了我整天想弄清楚,爲什麼下面的代碼不工作:OGRE3D /合成器相關的問題

我有這樣的.compositor腳本:

compositor BW 
{ 
    technique 
    { 
     texture rt0 target_width target_height PF_A8R8G8B8 

     target rt0 
     { 
      input previous 
     } 

     target_output 
     { 
      input none 

      pass render_quad 
      { 
       material BlackAndWhite 
       input 0 scene 
      } 
     } 
    } 
} 

。材料腳本:

vertex_program BW_VP cg 
{ 
    source MyShader.cg 
    entry_point BW_VP 
    profiles vs_4_0 vs_2_0 vs_1_1 arbvp1 

    default_params 
    { 
     param_named_auto worldViewProj worldviewproj_matrix 
    } 
} 

fragment_program BW_FP cg 
{ 
    source MyShader.cg 
    entry_point BW_FP 
    profiles ps_4_0 ps_2_0 arbfp1 
} 

material BlackAndWhite 
{ 
    technique 
    { 
     vertex_program_ref BW_VP{} 
     fragment_program_ref BW_FP{} 

     texture_unit 
     { 
      texture rt0 
      tex_coord_set 0 
      tex_address_mode clamp 
      filtering none 
     } 
    } 
} 

和.cg程序:

sampler2D RT : register(s0); 

void BW_VP(in float4 inPos : POSITION, out float4 pos : POSITION, out float2 uv0 : TEXCOORD0, uniform float4x4 worldViewProj) 
{ 
    pos = mul(worldViewProj, inPos); 
    inPos.xy = sign(inPos.xy); 
    uv0 = (float2(inPos.x, -inPos.y) + 1.0f) * 0.5f; 
} 

float4 BW_FP(float4 pos : POSITION, float2 iTexCoord : TEXCOORD0) : COLOR 
{ 
    float3 greyscale = dot(tex2D(RT, iTexCoord).rgb, float3(0.3, 0.59, 0.11)); 
    return float4(greyscale, 1.0); 
} 

我用下面的語句來初始化合成:

Ogre::CompositorManager::getSingleton().addCompositor(mViewport, "BW"); 
Ogre::CompositorManager::getSingleton().setCompositorEnabled(mViewport, "BW", true); 

,我看沒有結果的。我的場景中有幾個燈光和cg着色器 - 它們工作得很好。此外,所有的資源都裝入正確,而且資源組看到每一個需要的文件,但是我得到這個例外在日誌文件中:

OGRE EXCEPTION(6:FileNotFoundException): Cannot locate resource rt0 in resource group Mission 1 : Deliver Tom or any other group. in ResourceGroupManager::openResource at D:\ARCHIVES\DEPENDENCIES\OGRE_REPOSITORY\OgreMain\src\OgreResourceGroupManager.cpp (line 756) 

AFAIK RT0不應該是一種資源,因爲它自動生成「飛行」,由食人魔。我錯過了什麼嗎?

任何幫助表示讚賞!謝謝!

回答

2

異常錯誤是正確:您沒有具有該名稱的紋理文件資源,但OGRE會爲您創建空白紋理。

不過,我看到了兩個問題:

  1. 在合成文件是什麼現場?而不是場景您必須使用rt0,這是渲染場景的渲染目標,您的場景將呈現在哪裏以及應用材質的位置。
  2. 缺少通過材料腳本中的聲明。
+0

你說得對!但不知何故,即使在這種改變之後,排字工具仍然無法使用! –

+0

另外,我將'texture rt0'改爲'content_type compositor BW rt0'但是這沒有什麼區別!它仍然不起作用 –

+0

我剛剛注意到材料腳本中的一個疏忽:_pass_語句在哪裏?我試過你的代碼(添加pass語句)並且它正常工作。 – enigma