[Solved] Spotlight shows not up in test program (Built with instructions from tutorial) Topic is solved

Problems building or running the engine, queries about how to use features etc.
Post Reply
danielspengler99
Gnoblar
Posts: 16
Joined: Mon Oct 16, 2017 1:47 am
x 2

[Solved] Spotlight shows not up in test program (Built with instructions from tutorial)

Post by danielspengler99 »

Hello together!

Today I tried to code the "Lights, cameras and shadows" part in the Ogre 1.10 tutorial. Everything is working fine as long I have the Ambiantlight turned on. When I set its values to 0 and implement the spotlight I get just a black screen, but I expected a spotlight viewing the ninja. (Note: It doesn't matter which type of light I use. The screen stays black. It also doesn't matter if I use different colors for defuseLight.) I searched the internet for this bug, but couldn't find anything. I also looked at the debug messages, but also without success. I don't know what went wrong there, so I hope you can help me.

One more thing: The tutorial is using sometimes this: Ogre::Vector3::UNIT_Z. Can you explain me what this means? I don't understand the explanation in the tutorial quite well.

Here is my Code:

Code: Select all

#include <Ogre.h>
#include <OgreApplicationContext.h>
#include <iostream>

Ogre::SceneManager* sceneManager;
Ogre::SceneNode* cameraSceneNode;
Ogre::Camera* camera;
Ogre::Viewport* viewport;
Ogre::Entity* ninjaEntity;
Ogre::Entity* groundEntity;
Ogre::Light* spotLight;
Ogre::SceneNode* spotLightSceneNode;

class TestApp : public OgreBites::ApplicationContext, public OgreBites::InputListener
{
public:
  TestApp();
  void setup();
  bool keyPressed(const OgreBites::KeyboardEvent& evt);
};

//! [constructor]
TestApp::TestApp() : OgreBites::ApplicationContext("MyTestApp")
{
  addInputListener(this);

}
//! [constructor]

//! [key_handler]
bool TestApp::keyPressed(const OgreBites::KeyboardEvent& evt)
{
  if (evt.keysym.sym == SDLK_ESCAPE)
  {
    getRoot()->queueEndRendering();
  }
  return true;
}
//! [key_handler]

//! [setup]
void TestApp::setup(void)
{
  //Ogre::LogManager::getSingleton().setLogDetail(Ogre::LL_LOW);
  
  OgreBites::ApplicationContext::setup();
  
  sceneManager = getRoot()->createSceneManager(Ogre::ST_GENERIC);
  sceneManager->setAmbientLight(Ogre::ColourValue(0, 0, 0));
  sceneManager->setShadowTechnique(Ogre::ShadowTechnique::SHADOWTYPE_STENCIL_MODULATIVE);

  cameraSceneNode = sceneManager->getRootSceneNode()->createChildSceneNode();
  camera = sceneManager->createCamera("MainCamera");
  cameraSceneNode->setPosition(200, 300, 400);
  cameraSceneNode->lookAt(Ogre::Vector3(0, 0, 0), Ogre::Node::TransformSpace::TS_WORLD);
  camera->setNearClipDistance(5);
  cameraSceneNode->attachObject(camera);

  viewport = getRenderWindow()->addViewport(camera);
  viewport->setBackgroundColour(Ogre::ColourValue(0, 0, 0));
  camera->setAspectRatio(Ogre::Real(viewport->getActualWidth()) / Ogre::Real(viewport->getActualHeight()));

  ninjaEntity = sceneManager->createEntity("ninja.mesh");
  ninjaEntity->setCastShadows(true);
  sceneManager->getRootSceneNode()->createChildSceneNode()->attachObject(ninjaEntity);

  Ogre::Plane plane(Ogre::Vector3::UNIT_Y, 0);
  
  Ogre::MeshManager::getSingleton().createPlane(
    "ground",
    Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME,
    plane,
    1500, 1500, 20, 20,
    true,
    1, 5, 5,
    Ogre::Vector3::UNIT_Z
  );
  
  groundEntity = sceneManager->createEntity("ground");
  sceneManager->getRootSceneNode()->createChildSceneNode()->attachObject(groundEntity);
  groundEntity->setCastShadows(false);
  
  groundEntity->setMaterialName("Examples/Rockwall");

  spotLight = sceneManager->createLight("spotLight");
  spotLight->setDiffuseColour(1.0, 1.0, 1.0);
  spotLight->setSpecularColour(1.0, 1.0, 1.0);
  spotLight->setType(Ogre::Light::LT_SPOTLIGHT);
  spotLight->setDirection(Ogre::Vector3::NEGATIVE_UNIT_Z);

  spotLightSceneNode = sceneManager->getRootSceneNode()->createChildSceneNode();
  spotLightSceneNode->attachObject(spotLight);
  spotLightSceneNode->setDirection(-1, -1, 0);
  spotLightSceneNode->setPosition(Ogre::Vector3(200, 200, 0));
  spotLight->setSpotlightRange(Ogre::Degree(35), Ogre::Degree(50));
  
}
//! [setup]

//! [main]
int main(int argc, char *argv[])
{
  
  TestApp app;
  app.initApp();
  app.getRoot()->startRendering();
  app.closeApp();
  return 0;
}
//! [main]


And here is the Link to the tutorial: https://ogrecave.github.io/ogre/api/1.1 ... adows.html


Regards,
Daniel
Last edited by danielspengler99 on Wed Oct 18, 2017 5:01 pm, edited 1 time in total.
paroj
OGRE Team Member
OGRE Team Member
Posts: 1994
Joined: Sun Mar 30, 2014 2:51 pm
x 1074
Contact:

Re: Spotlight shows not up in test program (Built with instructions from tutorial)

Post by paroj »

you can find the complete code of that tutorial here:
https://github.com/OGRECave/ogre/blob/m ... orial2.cpp
danielspengler99
Gnoblar
Posts: 16
Joined: Mon Oct 16, 2017 1:47 am
x 2

Re: Spotlight shows not up in test program (Built with instructions from tutorial)

Post by danielspengler99 »

Hello,
I compared my code to the code on git. Unfortunatly I can't find my mistake...
The only difference was that they set the ambiantlight and the shadowtype later. I did this myself and still just get a black screen...

If nobody sees a mistake in my code, can you maybe try to run my code and see if it works for you? I really don't know what is going wrong here since I am not getting a good log entry which could help me.

Thanks for your help in advance!

Regards,
Daniel
danielspengler99
Gnoblar
Posts: 16
Joined: Mon Oct 16, 2017 1:47 am
x 2

Re: Spotlight shows not up in test program (Built with instructions from tutorial)

Post by danielspengler99 »

Hi,
I searched the log again and found something very wierd. Here are the last lines of the ogre log:

13:53:09: GLSL compiled: c362e4e96b7a11f537606c8ce4d90e75_VS
13:53:09: GLSL compiled: FFPLib_Transform_VS
13:53:09: GLSL compiled: FFPLib_Common_VS
13:53:09: GLSL compiled: FFPLib_Lighting_VS
13:53:09: GLSL compiled: FFPLib_Texturing_VS
13:53:09: Vertex Shader: c362e4e96b7a11f537606c8ce4d90e75_VS
Fragment Shader: f6ae55066f9c3cee1da31f639188e916_FS
GLSL program result :
13:53:09: GLSL compiled: f6ae55066f9c3cee1da31f639188e916_FS
13:53:09: GLSL compiled: FFPLib_Common_FS
13:53:09: GLSL compiled: FFPLib_Texturing_FS
13:53:09: Vertex Shader: c362e4e96b7a11f537606c8ce4d90e75_VS
Fragment Shader: f6ae55066f9c3cee1da31f639188e916_FS
GLSL program result :
13:53:09: GLSL compiled: Ogre/ShadowExtrudePointLight
WARNING: 0:3: '' : #version directive missing
13:53:09: Vertex Shader: Ogre/ShadowExtrudePointLight
Fragment Shader: Ogre/ShadowFrgProgram
GLSL program result :
13:53:09: GLSL compiled: Ogre/ShadowFrgProgram
WARNING: 0:2: '' : #version directive missing
13:53:10: Vertex Shader: Ogre/ShadowExtrudePointLight
Fragment Shader: Ogre/ShadowFrgProgram
GLSL program result :
13:53:10: Vertex Shader: Ogre/ShadowExtrudePointLight
Fragment Shader: Ogre/ShadowFrgProgram
GLSL program pipeline validation result:
13:53:10: GLSL compiled: Ogre/ShadowBlendVP
WARNING: 0:1: '' : #version directive missing
13:53:10: Vertex Shader: Ogre/ShadowBlendVP
Fragment Shader: Ogre/ShadowBlendFP
GLSL program result :
13:53:10: GLSL compiled: Ogre/ShadowBlendFP
WARNING: 0:2: '' : #version directive missing
13:53:10: Vertex Shader: Ogre/ShadowBlendVP
Fragment Shader: Ogre/ShadowBlendFP
GLSL program result :
13:53:10: Vertex Shader: Ogre/ShadowBlendVP
Fragment Shader: Ogre/ShadowBlendFP
GLSL program pipeline validation result:


Especialy the last line is wierd for me, because there is "result: " and then nothing.

Is this normal behaviour?

Thanks for the answers already!
danielspengler99
Gnoblar
Posts: 16
Joined: Mon Oct 16, 2017 1:47 am
x 2

Re: Spotlight shows not up in test program (Built with instructions from tutorial)

Post by danielspengler99 »

Hi,
I got the fix:

For all who are just reading the the tutorial:

You need to add a shadersystem to which you are adding your scenemanager.

This are the lines which were missing in my code:

Code: Select all

#include <OgreRTShaderSystem.h> // add to includes!

Ogre::RTShader::ShaderGenerator* shaderGenerator; //Add this to the deffinitions of all the objects

//Add this lines right after you created your scenemanager
shaderGenerator = Ogre::RTShader::ShaderGenerator::getSingletonPtr();
  shaderGenerator->addSceneManager(sceneManager);
Thanks for the answer with the code. I just didn't see that this was missing...

Regards,
Daniel
Post Reply