食人魔3d /合成器相关问题

Ogre3d / Compositor related issue

本文关键字:问题 合成器 3d 食人魔      更新时间:2023-10-16

我花了一整天的时间试图弄清楚为什么下面的代码不起作用:

我有这个 .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:ARCHIVESDEPENDENCIESOGRE_REPOSITORYOgreMainsrcOgreResourceGroupManager.cpp (line 756)

AFAIK rt0不应该是一种资源,因为它是由食人魔"飞行"自动生成的。我错过了什么吗?

任何帮助不胜感激!谢谢!

异常错误是正确的:您没有具有该名称的纹理文件资源,但是 OGRE 将为您创建一个空白纹理。

但是我看到两个问题:

  1. 在合成器文件中,什么是场景?您必须使用 rt0 而不是场景,这是渲染场景的渲染目标,也是您应用材质的位置。
  2. 材料脚本中缺少传递语句。