Ogre Shader Tiled Window

For help with anything that CEGUI doesn't offer straight out-of-the-box, e.g.:
- Implementation of new features, such as new Core classes, widgets, WindowRenderers, etc. ...
- Modification of any existing features for specific purposes
- Integration of CEGUI in new engines or frameworks and writing of new plugins (Renderer, Parser, ...) or modules

Moderators: CEGUI MVP, CEGUI Team

User avatar
dermont
Quite a regular
Quite a regular
Posts: 75
Joined: Mon Aug 29, 2005 16:15

Ogre Shader Tiled Window

Postby dermont » Wed May 11, 2011 05:57

I have a StaticImage in a FrameWindow and am having a problem trying to create a TiledWindow effect using a RenderEffect and an Ogre shader.

This is my RenderEffect class, the texture co-ords / positions are fudged - I'm still having problems trying to get these correct:

Code: Select all

class MyRenderEffect : public CEGUI::RenderEffect
{
public:
    MyRenderEffect()
    {
    }
    void performPreRenderFunctions(const int pass_num)
    {
        #ifdef CEGUI_GST_USE_OGRE_SHADER
        Ogre::RenderSystem* rys = Ogre::Root::getSingletonPtr()->getRenderSystem();

        CEGUI::OgreRenderer* renderer =
            static_cast<CEGUI::OgreRenderer*>(
                CEGUI::System::getSingleton().getRenderer());

      //rys->_setWorldMatrix(Matrix4::IDENTITY);
      //rys->_setViewMatrix(Matrix4::IDENTITY);
      //rys->_setProjectionMatrix(Matrix4::IDENTITY);

        Ogre::MaterialPtr mOgreVideoMaterial = Ogre::MaterialManager::getSingleton().getByName("MyVideo",Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);

      Ogre::Pass* pass = mOgreVideoMaterial->getTechnique(0)->getPass(0);

      if (pass->hasVertexProgram())
      {
            rys->bindGpuProgram(pass->getVertexProgram()->_getBindingDelegate());
         rys->bindGpuProgramParameters(GPT_VERTEX_PROGRAM,
            pass->getVertexProgramParameters(), GPV_ALL);
      }
      if (pass->hasFragmentProgram())
      {
           rys->bindGpuProgram(pass->getFragmentProgram()->_getBindingDelegate());
         rys->bindGpuProgramParameters(GPT_FRAGMENT_PROGRAM,
            pass->getFragmentProgramParameters(), GPV_ALL);
      }
        #endif

   }

    int getPassCount() const { return 1; }

    void performPostRenderFunctions()
    {
        #ifdef CEGUI_GST_USE_OGRE_SHADER
        Ogre::RenderSystem* rys = Ogre::Root::getSingletonPtr()->getRenderSystem();
        rys->unbindGpuProgram(GPT_FRAGMENT_PROGRAM);
        rys->unbindGpuProgram(GPT_VERTEX_PROGRAM);
       MouseCursor::getSingleton().draw();
        #endif
    }

    // ---------------------------------------------------------------------------
    bool realiseGeometry(CEGUI::RenderingWindow& window,
                               CEGUI::GeometryBuffer& geometry)
   {
       #ifdef CEGUI_GST_USE_OGRE
            nx=1;
            ny=1;
       #else
            nx=6;
            ny=6;
       #endif

        CEGUI::Texture& tex = window.getTextureTarget().getTexture();

        const float tu = window.getSize().d_width *
                ( tex.getTexelScaling().d_x * float(nx));
        const float tv = window.getSize().d_height*
                (tex.getTexelScaling().d_y * float(ny));

        const Rectf tex_rect(window.getTextureTarget().isRenderingInverted() ?
                          //Rectf(0, 0, tu, tv):
                          Rectf(0, tu, 0, 1-tv ) :
                          //Rectf(0, 1, tu, 1 - tv) :
                          Rectf(0, 0, tu, tv));

        const Rectf area = Rectf(-window.getSize().d_width/4.0, -window.getSize().d_height/4.0, window.getSize().d_width/4.0,window.getSize().d_height/4.0 );

        //const Rectf area = Rectf(0, 0, window.getSize().d_width,window.getSize().d_height);

        CEGUI::Colour c(1.0f, 1.0f, 1.0f);

        // vertex 0
        vbuffer[0].position   = Vector3f(area.d_min.d_x, area.d_min.d_y, 0.0f);
        vbuffer[0].colour_val = c;
        vbuffer[0].tex_coords = Vector2f(tex_rect.d_min.d_x, tex_rect.d_min.d_y);

        // vertex 1
        vbuffer[1].position   = Vector3f(area.d_min.d_x, area.d_max.d_y, 0.0f);
        vbuffer[1].colour_val = c;
        vbuffer[1].tex_coords = Vector2f(tex_rect.d_min.d_x, tex_rect.d_max.d_y);

        // vertex 2
        vbuffer[2].position   = Vector3f(area.d_max.d_x, area.d_max.d_y, 0.0f);
        vbuffer[2].colour_val = c;
        vbuffer[2].tex_coords = Vector2f(tex_rect.d_max.d_x, tex_rect.d_max.d_y);

        // vertex 3
        vbuffer[3].position   = Vector3f(area.d_max.d_x, area.d_min.d_y, 0.0f);
        vbuffer[3].colour_val = c;
        vbuffer[3].tex_coords = Vector2f(tex_rect.d_max.d_x, tex_rect.d_min.d_y);

        // vertex 4
        vbuffer[4].position   = Vector3f(area.d_min.d_x, area.d_min.d_y, 0.0f);
        vbuffer[4].colour_val = c;
        vbuffer[4].tex_coords = Vector2f(tex_rect.d_min.d_x, tex_rect.d_min.d_y);

        // vertex 5
        vbuffer[5].position   = Vector3f(area.d_max.d_x, area.d_max.d_y, 0.0f);
        vbuffer[5].colour_val = c;
        vbuffer[5].tex_coords = Vector2f(tex_rect.d_max.d_x, tex_rect.d_max.d_y);

        // give our vertices to the buffer for drawing
        //geometry.setClippingRegion(Rectf(0.0,0.0,500.0,500.0));

        geometry.setActiveTexture(&tex);
        geometry.appendGeometry(vbuffer, 6);
        //window.draw();

        // false, because we do want the default geometry added!
        return false;
    }

    bool update(const float elapsed, CEGUI::RenderingWindow& window)
    {
     window.invalidateGeometry();
      //System::getSingleton().signalRedraw();
      MouseCursor::getSingleton().draw();
     return false;
    }

protected:
    int nx;
    int ny;
    static const int buffsize=6; //*nx*ny;
    CEGUI::Vertex vbuffer[buffsize];
    const CEGUI::Rectf targetRect;

};


This is how I register the effects

Code: Select all

    RenderEffectManager::getSingleton().addEffect<MyRenderEffect>("VideoRenderEffect");
    RenderEffectManager::getSingleton().addEffect<ShaderRenderEffect>("ShaderRenderEffect");


   // Now we make a Falagard mapping for a frame window that uses this effect.
       WindowFactoryManager::getSingleton().addFalagardWindowMapping(
           "WindowsLook/VideoFrameWindow",    // type to create
           "CEGUI/FrameWindow",                // 'base' widget type
           "WindowsLook/FrameWindow",          // WidgetLook to use.
           "Falagard/FrameWindow",             // WindowRenderer to use.
              "VideoRenderEffect");                    // effect to use.
       // Now we make a Falagard mapping for a static Image that uses this effect.
       WindowFactoryManager::getSingleton().addFalagardWindowMapping(
           "WindowsLook/VideoImage",    // type to create
           "DefaultWindow",                // 'base' widget type
           "WindowsLook/StaticImage",          // WidgetLook to use.
           "Falagard/StaticImage",             // WindowRenderer to use.
              "ShaderRenderEffect");                    // effect to use.


This is what I have tried both creating a tiled window using a rendereffect on the FrameWindow/StaticImage:

1) without a shader and simply scaling the texture co-ordinates, this works for OpenGL but I still encounter problems during window resize.
Image

2) ogre without a shader and updating OgreGeometryBuffer - (initialiseTextureStates is called just prior to rendering) defaullt textureAddressingMode to TAM_WRAP the defaullt appears to be TAM_CLAMP. Same problem on resize.

3) with an ogre shader, same problem on resize and window extents not right.
Image

Obviously there is something wrong with how I am defining my texture co-ords / positions. Any advice would be appreciated.

User avatar
CrazyEddie
CEGUI Project Lead
Posts: 6760
Joined: Wed Jan 12, 2005 12:06
Location: England
Contact:

Re: Ogre Shader Tiled Window

Postby CrazyEddie » Wed May 11, 2011 13:01

I don't really understand what I'm looking at :oops: Any change you can post a diagram or mock up of what it's supposed to look like? :)

I probably will not be able to reply again for a few days, so take your time...

CE


Return to “Modifications / Integrations / Customisations”

Who is online

Users browsing this forum: No registered users and 12 guests