Question

I killed my whole day trying to figure out, why the code below is not working:

I have this .compositor script:

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
            }
        }
    }
}

.material script:

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
        }
    }
}

and a .cg program:

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);
}

I use statements below to initialize compositor:

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

And i see no results at all. I have couple of lights and cg shaders in my scene - they work perfectly well. Also, all resources are loaded properly, and the resource group sees every needed file, however i get this exception in the log file:

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 shouldnt be a resource due to its automatic generation "on flight" by ogre. Am i missing something?

Any help is appreciated! Thanks!

Was it helpful?

Solution

The exception error is correct: you haven't a texture file resource with that name, however OGRE will create a blank texture for you.

However I see two problems:

  1. In compositor file what is scene? Instead of scene you must use rt0, this is the render target where your scene is rendered and where you go to apply the material.
  2. The lack of pass statement in the material script.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top