[2.1] nothing rendered except default compositor color

Problems building or running the engine, queries about how to use features etc.
Post Reply
jamesmagnus
Gnoblar
Posts: 1
Joined: Mon Jun 12, 2017 12:07 am
Location: Bordeaux FRANCE

[2.1] nothing rendered except default compositor color

Post by jamesmagnus »

Hi
I'm trying to setup OGRE 2.1 but I have some problems: I added a red light to the scene and set the scene manager's ambient light to red but the render remains gray. :(
This is my code :

Code: Select all

#include <cstdlib>
#include <iostream>

#include <Ogre.h>
#include <OgreRenderWindow.h>
#include <Compositor/OgreCompositorManager2.h>
#include <Hlms/Unlit/OgreHlmsUnlit.h>
#include <Hlms/Pbs/OgreHlmsPbs.h>

int main(int argc, char *argv[])
{
    /* Starting OGRE */
    Ogre::Root *root = OGRE_NEW Ogre::Root("plugins.cfg", "ogre.cfg");

    root->restoreConfig() || root->showConfigDialog();
    Ogre::RenderWindow *mainWin = root->initialise(true, "OGRE Tutorial");

    /* Create scene manager */
    Ogre::SceneManagerEnumerator::MetaDataIterator sceneManagerDataIt = Ogre::SceneManagerEnumerator::getSingleton().getMetaDataIterator();
    std::string sceneManagerType = sceneManagerDataIt.getNext()->typeName;
    Ogre::LogManager::getSingleton().getDefaultLog()->logMessage("Creating scene manager type " + sceneManagerType, Ogre::LogMessageLevel::LML_NORMAL);

    Ogre::SceneManager *mainSceneMgr = root->createSceneManager(sceneManagerType, 4, Ogre::InstancingThreadedCullingMethod::INSTANCING_CULLING_THREADED, "main_scene_manager");
    mainSceneMgr->setAmbientLight(Ogre::ColourValue(1.0, 0.0, 0.0), Ogre::ColourValue(1.0, 0.0, 0.0), Ogre::Vector3::UNIT_X);

    /* Create camera */
    Ogre::Camera *mainCam = mainSceneMgr->createCamera("main_camera");
    mainCam->setPosition(Ogre::Vector3(0, 10, 15));
    mainCam->lookAt(Ogre::Vector3(0, 0, 0));
    mainCam->setNearClipDistance(0.2f);
    mainCam->setFarClipDistance(1000.0f);
    mainCam->setAutoAspectRatio(true);

    /* Create workspace */
    const Ogre::String workspaceName("main_workspace");
    Ogre::CompositorManager2 *compositorManager = root->getCompositorManager2();
    if(!compositorManager->hasWorkspaceDefinition(workspaceName))
        compositorManager->createBasicWorkspaceDef(workspaceName, Ogre::ColourValue(0.5f, 0.5f, 0.5f));
    compositorManager->addWorkspace(mainSceneMgr, mainWin, mainCam, workspaceName, true);

    /* Resources and HLMS */
    Ogre::ResourceGroupManager::getSingleton().initialiseAllResourceGroups();
    Ogre::TextureManager::getSingleton().setDefaultNumMipmaps(Ogre::MIP_UNLIMITED);

    Ogre::ConfigFile configF;
    configF.load("resources.cfg");

    Ogre::String dataFolder = configF.getSetting("DoNotUseAsResource", "Hlms", "");

    if(dataFolder.empty())
        dataFolder = "./";
    else if(*(dataFolder.end() - 1) != '/')
        dataFolder += "/";

    Ogre::String shaderSyntax = "GLSL";

    Ogre::Archive *archiveLibrary = Ogre::ArchiveManager::getSingletonPtr()->load(dataFolder + "Hlms/Common/" + shaderSyntax, "FileSystem", true);
    Ogre::Archive *archiveLibraryAny = Ogre::ArchiveManager::getSingletonPtr()->load(dataFolder + "Hlms/Common/Any", "FileSystem", true);
    Ogre::Archive *archivePbsLibraryAny = Ogre::ArchiveManager::getSingletonPtr()->load(dataFolder + "Hlms/Pbs/Any", "FileSystem", true);

    Ogre::ArchiveVec library;
    library.push_back(archiveLibrary);
    library.push_back(archiveLibraryAny);

    Ogre::Archive *archiveUnlit = Ogre::ArchiveManager::getSingletonPtr()->load(dataFolder + "Hlms/Unlit/" + shaderSyntax, "FileSystem", true );

    Ogre::HlmsUnlit *hlmsUnlit = OGRE_NEW Ogre::HlmsUnlit(archiveUnlit, &library);
    Ogre::Root::getSingleton().getHlmsManager()->registerHlms(hlmsUnlit);

    Ogre::Archive *archivePbs = Ogre::ArchiveManager::getSingletonPtr()->load(dataFolder + "Hlms/Pbs/" + shaderSyntax, "FileSystem", true);
    library.push_back(archivePbsLibraryAny);
    Ogre::HlmsPbs *hlmsPbs = OGRE_NEW Ogre::HlmsPbs( archivePbs, &library );
    Ogre::Root::getSingleton().getHlmsManager()->registerHlms(hlmsPbs);


    /* Add a red light */
    Ogre::Light *mainLight = mainSceneMgr->createLight();
    mainLight->setType(Ogre::Light::LightTypes::LT_DIRECTIONAL);
    mainLight->setDiffuseColour(1.0, 0.0, 0.0);
    mainLight->setSpecularColour(1.0, 0.0, 0.0);
    mainLight->setPowerScale(200.0);
    mainSceneMgr->getRootSceneNode()->attachObject(mainLight);
    mainLight->setDirection(Ogre::Vector3::UNIT_X);
    mainLight->setVisible(true);


    /* Rendering loop */
    while (true) {
        Ogre::WindowEventUtilities::messagePump();
        if (!root->renderOneFrame())
            return EXIT_FAILURE;
    }
    
    return EXIT_SUCCESS;
}
Can someone explains me what I am doing wrong ?
Thank you (sorry for my English)
User avatar
dark_sylinc
OGRE Team Member
OGRE Team Member
Posts: 5298
Joined: Sat Jul 21, 2007 4:55 pm
Location: Buenos Aires, Argentina
x 1279
Contact:

Re: [2.1] nothing rendered except default compositor color

Post by dark_sylinc »

Hi!

You did nothing wrong.

You're just seeing the clear colour (also called background colour), which is not linked to ambient light colour or directional light colour.

You're setting the clear colour to grey here:

Code: Select all

    if(!compositorManager->hasWorkspaceDefinition(workspaceName))
        compositorManager->createBasicWorkspaceDef(workspaceName, Ogre::ColourValue(0.5f, 0.5f, 0.5f));
The reason for this behavior is that complex effects may need clear colours set to a specifc value rather than being changed arbitrarily by the SceneManager, thus this value is controlled by the compositor.

Spookyboo wrote a function to change the clear colour of all your passes which will do the job.
If you're doing advanced effects, then you probably want to only affect specific clear passes (which you could identify by using CompositorPassClearDef::mIdentifier)

Cheers
Matias
Post Reply