[2.1][FIXED] Point lights not working

Discussion area about developing with Ogre-Next (2.1, 2.2 and beyond)


Post Reply
kracejic
Kobold
Posts: 25
Joined: Wed Sep 10, 2014 5:18 pm
x 1

[2.1][FIXED] Point lights not working

Post by kracejic »

Hi, are Point ligths working on 2.1? When I add directional Light it is working fine, but point light is not working at all.

I have checked generated glsl files and its main function looks like this (I have removed all blank lines), so nothing about lighting was generated (only one point light is in the scene). When I use directional light, working code (with lighting) is generated.

Code: Select all

void main()
{
        uint materialId = instance.worldMaterialIdx[inPs.drawId].x & 0x1FFu;
    material = materialArray.m[materialId];
    nNormal = normalize( inPs.normal );

    //Everything's in Camera space, we use Cook-Torrance lighting
    vec3 finalColour = vec3(0);

    //Point lights

    //Spot lights
    //spotParams[0].x = 1.0 / cos( InnerAngle ) - cos( OuterAngle )
    //spotParams[0].y = cos( OuterAngle / 2 )
    //spotParams[0].z = falloff

    outColour.xyz   = finalColour;
    outColour.w     = 1.0;
}
I add the light to the scene with this code:

Code: Select all

    Ogre::Light *light2 = mSceneManager->createLight();
    auto systemNode = mSceneManager->getRootSceneNode( )->createChildSceneNode();
    systemNode->attachObject( light2 );

    light2->setDiffuseColour( 0.8f, 0.4f, 0.2f ); //Warm
    light2->setSpecularColour( 0.8f, 0.4f, 0.2f );
    // light2->setPowerScale( Ogre::Math::PI );
    light2->setCastShadows( false );
    light2->setType( Ogre::Light::LT_POINT );
    light2->setAttenuationBasedOnRadius( 100.0f, 0.00192f );
    systemNode->setPosition(0.1,3,0.1);
I have tested it on W7/Nvidia and Linux/AMD with the same result. Thanks for help. :)
Last edited by kracejic on Mon Jun 08, 2015 9:12 am, edited 3 times in total.
xrgo
OGRE Expert User
OGRE Expert User
Posts: 1148
Joined: Sat Jul 06, 2013 10:59 pm
Location: Chile
x 168

Re: [2.1] Point lights not working?

Post by xrgo »

I think you need to enable forward3D, but that feature is not working for me, and I haven't put much time in that because my scene uses only directional and spotlights
al2950
OGRE Expert User
OGRE Expert User
Posts: 1227
Joined: Thu Dec 11, 2008 7:56 pm
Location: Bristol, UK
x 157

Re: [2.1] Point lights not working?

Post by al2950 »

It depends how you have everything setup, but if you are using the HLMS PBS materials then there are some current limitations, the below text is lifted from the PBS sample
Known issues:
* Point lights aren't working in the desktop PBS implementation.
* Spot lights must be casting shadow to work in the desktop PBS implementation.
* The previous two issues will be fixed when an advanced lighting algorithm is implemented, that will overcome forward lighting limitations.
* Mobile version only supports forward lighting.
**EDIT** NB Those issues were written before the forward 3D algorithm was implemented
kracejic
Kobold
Posts: 25
Joined: Wed Sep 10, 2014 5:18 pm
x 1

Re: [2.1] Point lights not working?

Post by kracejic »

Thanks you both for poining out the direction. :D

So I have tested it and I have discovered that:
1) You need to have forward3D turned ON in order to get Point Lights working
2) Forward3D is not working without Directional Light in the scene (I have got shader compile errors). And this is probably a bug or not yet implemented feature?? :) Am I correct?

So for the time being we can work around it by using Directional light with power 0 if directional light is not desired.

So code snippet which worked for me:

Code: Select all

    //First directional light
    Ogre::Light* light = mSceneManager->createLight();
    Ogre::SceneNode* lightNode = mSceneManager->getRootSceneNode()->createChildSceneNode();
    lightNode->attachObject( light );
    light->setPowerScale( 1.0f );
    light->setType( Ogre::Light::LT_DIRECTIONAL );
    light->setDirection( Ogre::Vector3( -1, -1, -1 ).normalisedCopy() );
    light->setPowerScale( 0 ); //I do not want this light

    //Secon Point light
    Ogre::Light* light2 = mSceneManager->createLight();
    Ogre::SceneNode* light2Node = mSceneManager->getRootSceneNode( )->createChildSceneNode();
    light2Node->attachObject( light2 );
    light2->setDiffuseColour( 0.8f, 0.4f, 0.2f ); //Warm
    light2->setSpecularColour( 0.8f, 0.4f, 0.2f );
    light2->setCastShadows( false );
    light2->setType( Ogre::Light::LT_POINT );
    light2->setAttenuationBasedOnRadius( 100, 0.00192f );
    light2Node->setPosition(0,3,8);

    mSceneManager->setForward3D( true, 4,4,5,96,3,200 );
User avatar
dark_sylinc
OGRE Team Member
OGRE Team Member
Posts: 5299
Joined: Sat Jul 21, 2007 4:55 pm
Location: Buenos Aires, Argentina
x 1279
Contact:

Re: [2.1][BUG found?] Point lights not working?

Post by dark_sylinc »

Hi!

Current status:
  • Non shadow casting point & spot lights require Forward3D to be enabled. This is by design (more implementations will come: Forward+ & Deferred; for now the only one working is F3D).
  • Shadow casting point lights don't work or work poorly. (feature not implemented yet)
  • If you've got PSSM shadow casting enabled, the system requires at least one shadow-casting directional light. I'm working to fix this. It's in my TODO list.
If PSSM is not enabled and you're getting issues when directional lights are off, then tell me. That is a bug.
kracejic
Kobold
Posts: 25
Joined: Wed Sep 10, 2014 5:18 pm
x 1

Re: [2.1][BUG found?] Point lights not working?

Post by kracejic »

Hi dark_sylinc, great, thanks for info. :)

I do not have pssm enabled (if I understood correctly this has to be specified in compositor), so it might be a bug.

This is my compositor.

Code: Select all

compositor_node MySimpleNode
{
    in 0 renderwindow
    target renderwindow
    {
       pass clear
        {
            colour_value 0.2 0.3 0.8 1
        }

        pass render_scene
        {
            rq_first 0
            rq_last max
        }
    }
}

workspace MyOwnWorkspace
{
    connect_output MySimpleNode 0
}
This is Log output: This is on desktop Linux + AMD HD7xxx

Code: Select all

19:56:44.861 INFO  OGRE    : Parsing scripts for resource group General
19:56:44.862 INFO  OGRE    : Parsing script example.material
19:56:44.862 INFO  OGRE    : Parsing script map.material
19:56:44.862 INFO  OGRE    : Texture: loading star.png as star.png
19:56:44.878 INFO  OGRE    : Texture: loading glare.png as glare.png
19:56:44.890 INFO  OGRE    : Parsing script basic.compositor
19:56:44.891 INFO  OGRE    : Parsing script map.compositor
19:56:44.891 INFO  OGRE    : Parsing script SdkTrays.fontdef
19:56:44.891 INFO  OGRE    : Finished parsing scripts for resource group General
19:56:44.891 INFO  OGRE    : Creating resources for group General
19:56:44.891 INFO  OGRE    : All done
19:56:44.891 INFO  OGRE    : Parsing scripts for resource group Internal
19:56:44.891 INFO  OGRE    : Finished parsing scripts for resource group Internal
19:56:44.891 INFO  OGRE    : Creating resources for group Internal
19:56:44.891 INFO  OGRE    : All done
19:56:44.891 INFO  OGRE    : MovableObjectFactory for type 'MovableText' registered.
19:56:44.892 INFO  OGRE    : Mesh: Loading suzanne.mesh.
19:56:44.892 INFO  OGRE    : WARNING: Mesh 'suzanne.mesh' has shared vertices. They're being 'unshared' for importing to v2
19:56:45.081 INFO  OGRE    : GLSL compile log: 536870912PixelShader_ps
19:56:45.081 INFO  OGRE    :   *- Fragment shader failed to compile with the following errors:
19:56:45.081 INFO  OGRE    :   *- ERROR: 0:353: error(#143) Undeclared identifier: viewDir
19:56:45.081 INFO  OGRE    :   *- ERROR: 0:353: error(#143) Undeclared identifier: NdotV
19:56:45.081 INFO  OGRE    :   *- ERROR: 0:353: error(#202) No matching overloaded function found: BRDF
19:56:45.081 INFO  OGRE    :   *- ERROR: 0:353: error(#160) Cannot convert from: "const float" to: "highp 3-component vector of vec3"
19:56:45.081 INFO  OGRE    :   *- ERROR: 0:374: error(#143) Undeclared identifier: viewDir
19:56:45.081 INFO  OGRE    :   *- ERROR: 0:374: error(#143) Undeclared identifier: NdotV
19:56:45.081 INFO  OGRE    :   *- ERROR: 0:374: error(#202) No matching overloaded function found: BRDF
19:56:45.081 INFO  OGRE    :   *- ERROR: 0:374: error(#160) Cannot convert from: "const float" to: "highp 3-component vector of vec3"
19:56:45.081 INFO  OGRE    :   *- ERROR: error(#273) 8 compilation errors.  No code generated
19:56:45.082 ERROR OGRE    : OGRE EXCEPTION(3:RenderingAPIException): Fragment Program 536870912PixelShader_ps failed to compile. See compile log above for details. in GLSLShader::compile at /home/xohnheis/cpp/SDK/ogre2.0/RenderSystems/GL3Plus/src/GLSL/OgreGLSLShader.cpp (line 297)
Used material:

Code: Select all

hlms suzzane pbs
{
    roughness   0.2
    diffuse     0.8 0.7 0.05
    specular    0.8 0.7 0.05
}
Do you need anything else?
User avatar
dark_sylinc
OGRE Team Member
OGRE Team Member
Posts: 5299
Joined: Sat Jul 21, 2007 4:55 pm
Location: Buenos Aires, Argentina
x 1279
Contact:

Re: [2.1][BUG found?] Point lights not working?

Post by dark_sylinc »

Ugh. Yes. It is a bug.

I'll fix it, probably this weekend.
kracejic
Kobold
Posts: 25
Joined: Wed Sep 10, 2014 5:18 pm
x 1

Re: [2.1][BUG found?] Point lights not working?

Post by kracejic »

Great! :)
Thank you
User avatar
dark_sylinc
OGRE Team Member
OGRE Team Member
Posts: 5299
Joined: Sat Jul 21, 2007 4:55 pm
Location: Buenos Aires, Argentina
x 1279
Contact:

Re: [2.1][FIX soon] Point lights not working

Post by dark_sylinc »

Fixed in https://bitbucket.org/sinbad/ogre/commi ... 5a7d5bfd12

(compilation error when PSSM shadow mapping is enabled and there is no directional light is going to take longer)
kracejic
Kobold
Posts: 25
Joined: Wed Sep 10, 2014 5:18 pm
x 1

Re: [2.1][FIXED] Point lights not working

Post by kracejic »

Thanks!

tl;dr

If you want to have POINT lights, you need to use Forward3D lighting, you can enable it by this:

Code: Select all

 mSceneManager->setForward3D( true, 4,4,5,96,3,200 );
For more info check Forward3D sample in Ogre-source/Saples/2.0/Showcase/Forward3D and api reference of setForward3D function at http://www.ogre3d.org/docs/api/2.1/.
Post Reply