Lights and DotScene

Problems building or running the engine, queries about how to use features etc.
User avatar
Xinc
Halfling
Posts: 52
Joined: Sat May 08, 2004 12:55 pm
Location: Toronto, Canada

Lights and DotScene

Post by Xinc »

I was working with 0.14.X till now and didn't have a prolem, recently I upgraded to 0.15 and everything went well. However since then my lights refuse to illuminate the scene. I've tried everything I could to see where the trouble lies, but without anything going wrong it's hard to pin-point. By that I mean, technically the lights get created fine, they get placed perfectly, and if I attach them to the camera, they even move around with me. However I see no "light" in my scene. Not even the AmbientLight. All I see are dark "meshes" which block the sky-box image if I look from behind them. So I know the meshes are being created too. And with the recent physics addition I can even "collide" with the meshes. So I know that they're there. Thus the only thing that are at fault here are the lights. This lead me to believe that maybe my Ogre Code was corrupted. But upon running the "lights" demo/sample I was proven wrong -- as the lighs there work perfectly.

I mean when I upgraded I didn't even change anything, except for the whole deal with Radian, Degrees and AttachLight (which I had to change to AttachObject(LightPtr);).

Anyone encounter anything like this? or know what it could be?
Please help me out. I've tried doing various thing to see if at the very least I can get even a spec of light somehow in the scene.. but alas.. all efforts died in vain.
- Xinc
User avatar
sinbad
OGRE Retired Team Member
OGRE Retired Team Member
Posts: 19269
Joined: Sun Oct 06, 2002 11:19 pm
Location: Guernsey, Channel Islands
x 67

Post by sinbad »

Did you upgrade your meshes at the same time? If so, did you reorganise their vertex buffers using the automatic option? You don't necessarily have to upgrade your meshes (although I highly recommend it), but maybe if you did but reorganised the buffers incorrectly you might have lost the normal data.

Otherwise, the only other change to lighting was to include lights where they would have been culled early before (finding visible lights now includes the bounding sphere of the object as well as the light radius). However, the fact that ambient light is not showing up suggests that it's not that.

Have you tried other materials? Perhaps your material is at fault (there were some changes to transparent material handling in 0.15 which mean that incorrect materials that used to render ok may not do so anymore)
User avatar
sinbad
OGRE Retired Team Member
OGRE Retired Team Member
Posts: 19269
Joined: Sun Oct 06, 2002 11:19 pm
Location: Guernsey, Channel Islands
x 67

Post by sinbad »

I just realised you're talking about DotSceneManager - I have not tested DotSceneManager with 0.15 (it's not an official plugin) so perhaps there is an issue with it that I'm not aware of.
User avatar
bisco
OGRE Contributor
OGRE Contributor
Posts: 235
Joined: Wed Nov 03, 2004 5:01 pm
Location: London, United Kingdom

Post by bisco »

Hi Xinc, I had exactly the same problem (except that my ambient light was working) and just got it solved.
As sinbad suggested there is an error in how the lights are searched. In the SceneOctreeRenderable class you have to correct the getLights function so that the lights are searched using the bounding radius. This means you have to calculate the bounding radius too and use it into the function when you look for lights. I'll post here my code

First I added mBoundingRadius to SceneOctreeRenderable members:

Code: Select all

protected:

	void SetupBoundingBox( unsigned int *IndexArray );

    AxisAlignedBox mBounds;
    Vector3 mCenter;
    Vector3 mScale;

	Real mBoundingRadius;

    int mSize;
    int mWorldSize;

    String mName;
    String mType;

    int MaterialIndex;
	Material *mMaterial;

    bool mInit;
then added a part to setupBoundingBox in the same class, where I calculate the bounding radius:

Code: Select all

void SceneOctreeRenderable::SetupBoundingBox( unsigned int *IndexArray )
{
	// Bounding Box Vars
	int Min[3], Max[3];
	Min[0]=Min[1]=Min[2] =  1000000 ;
	Max[0]=Max[1]=Max[2] = -1000000 ;

	// Grab a pointer to the vertex shadow buffer
	VertexDeclaration* decl = mVertData->vertexDeclaration;
    VertexBufferBinding* bind = mVertData->vertexBufferBinding;

	HardwareVertexBufferSharedPtr vbuf;
	vbuf = bind->getBuffer(POSITION_BINDING);
	Real* pPos = static_cast<Real*>(vbuf->lock(HardwareBuffer::HBL_READ_ONLY));

	for( int index=0; index<numIndices; index++ )
	{
		for( int CurAxis=0; CurAxis<3; CurAxis++ )
		{
			// Update the Bounding Box //
			if( pPos[ (IndexArray[ index ]*3)+CurAxis ] < Min[CurAxis] )
				Min[CurAxis] = pPos[ (IndexArray[ index ]*3)+CurAxis ];

			if( pPos[ (IndexArray[ index ]*3)+CurAxis ] > Max[CurAxis] )
				Max[CurAxis] = pPos[ (IndexArray[ index ]*3)+CurAxis ];
		}
	}
	
	vbuf->unlock();

	// Set the bounding box //
	mBounds.setExtents( Min[0] , Min[1] , Min[2] , Max[0] , Max[1] , Max[2] );
	mCenter = Vector3( (Max[0]+Min[0])/2 , (Max[1]+Min[1])/2 , (Max[2]+Min[2])/2 );

	Real tempX,tempY,tempZ;
	// max (xMax,|xMin|)
	if (abs(Min[0]) > abs(Max[0]))
		tempX = abs(Min[0]);
	else
		tempX = abs(Max[0]);
	// max (yMax,|yMin|)
	if (abs(Min[1]) > abs(Max[1]))
		tempY = abs(Min[1]);
	else
		tempY = abs(Max[1]);
	// max (zMax,|zMin|)
	if (abs(Min[2]) > abs(Max[2]))
		tempZ = abs(Min[2]);
	else
		tempZ = abs(Max[2]);
	// sqrt[ max(xMax,|xMin|)^2 + max(yMax,|yMin|)^2 + max(zMax,|zMin|)^2 ]
	mBoundingRadius = sqrt(tempX*tempX + tempY*tempY + tempZ*tempZ);

	mInit = true;
}
Then finally changed the getLights function in the same class:

Code: Select all

const LightList& SceneOctreeRenderable::getLights(void) const
{
	if ((SceneNode*)mParentNode)
		return ((SceneNode*)mParentNode)->findLights(this->getBoundingRadius());
	else 
		return mParentNode->getLights();
}
And make sure that if you're exporting vertex diffuse colours they're not black.
Hope it works for you too :)
ashleyder
Gnoblar
Posts: 2
Joined: Wed Nov 10, 2004 9:06 am

Post by ashleyder »

Xinc, have you perchance found a fix to the problem because I'm having the same problem (including no ambient light). I tried your fix bisco, but that didn't help at all. Nor did upgrading the mesh help.

Part of the problem seems to be that the dotscene loader does not load any dynamic nodes currently, and this means no lights are loaded from the .scene file. I coded support for this, but the .scene geometry still is unlit.

Ps. I should also mention that fog *does* light the .scene geometry.
User avatar
Xinc
Halfling
Posts: 52
Joined: Sat May 08, 2004 12:55 pm
Location: Toronto, Canada

Post by Xinc »

Thanks bisco, but some how my lights started working automatically after I did a little house-cleaning in the code.

@ashleyder: This problem was pretty random, but this is how I experimented it out.
First of all, I made sure that the .scene contained proper light colours and position.
e.g.

Code: Select all

        <node name="Omni01" id="195">
            <position x="45.7218" y="18.064" z="169.824" />
            <light name="Omni01" id="195" type="point" visible="1" shadow="1">
                <colour_diffuse r="0.5100" g="0.2100" b="0.100" />
            </light>
        </node>
        <node name="Omni02" id="199">
            <position x="-1.56545e-005" y="391.741" z="358.133" />
            <light name="Omni02" id="199" type="point" visible="1" shadow="1">
                <colour_diffuse r="0.100" g="0.100" b="0.100" />
            </light>
        </node>
    </nodes>
Then once you make sure your lights have those values, move in on the code.

In ParseDotScene function, go to the point where the light nodes are parsed from XML.

Mine Looks like this right now:

Code: Select all

			XMLLight = XMLNode->FirstChildElement( "light" );
			if( XMLLight ){
				Ogre::Light *lightRef = LoadLight( XMLLight, mSceneMgr );
				lightRef->setPosition(TempVec);
                                if (atoi(XMLLight->Attribute("visible")) == 1)
				    lightRef->setVisible(true);
                                else
				    lightRef->setVisible(false);
				NewNode->attachObject( lightRef );
			}
*TempVec is from a little up, where the position of the node is determined.



Now in LoadLight, this is what it looks like:

Code: Select all

Light* CLevelLoader::LoadLight( TiXmlElement *XMLLight, Ogre::DotSceneManager *mSceneMgr )
{
	Light* l = mSceneMgr->createLight(XMLLight->Attribute("name"));
	l->setType(GetLightType(XMLLight->Attribute("type")));
        ColourValue Diffuse, Specular;

	TiXmlElement *XMLDiffuse, *XMLSpecular;
	XMLDiffuse = XMLLight->FirstChildElement("colour_diffuse");
	if( XMLDiffuse ){
		Diffuse.r = Ogre::StringConverter::parseReal( XMLDiffuse->Attribute("r") );
		Diffuse.g = Ogre::StringConverter::parseReal( XMLDiffuse->Attribute("g") );
		Diffuse.b = Ogre::StringConverter::parseReal( XMLDiffuse->Attribute("b") );
		Diffuse.a = 1;
	}
	XMLSpecular = XMLLight->FirstChildElement("colour_specular");
	if( XMLSpecular ){
		Specular.r = Ogre::StringConverter::parseReal( XMLSpecular->Attribute("r") );
		Specular.g = Ogre::StringConverter::parseReal( XMLSpecular->Attribute("g") );
		Specular.b = Ogre::StringConverter::parseReal( XMLSpecular->Attribute("b") );
		Specular.a = 1;
	}	


        if (atoi(XMLLight->Attribute("shadow")) == 1)
	    l->setCastShadows(true);
        else
	    l->setCastShadows(false);


        XMLAtten = XMLLight->FirstChildElement("Attenuation");
	l->setDiffuseColour(Diffuse);
	l->setSpecularColour(Specular);

        // For Test purposes
	l->setAttenuation(
                                   8000,
                                   1,
                                   0.0005,
                                   0
                                 );

	return l;
}



This is how the it started to work. I didn't make a log of this problem do I'm not aware of how exactly I solved it, so there might be a few things I forgot about to include in this post.
- Xinc
ashleyder
Gnoblar
Posts: 2
Joined: Wed Nov 10, 2004 9:06 am

Post by ashleyder »

Thanks for the code, but unfortunately that's actually pretty much the same thing I did except that I added it to DotScene Plugin's SceneMain class. However even though the lights get loaded successfully, they're still not lighting the static geometry. Do you have any other thoughts as to what you might have changed?
Tommy
Gnoblar
Posts: 15
Joined: Sun Jan 23, 2005 5:48 pm
Location: Germany

Post by Tommy »

ashleyder wrote:Thanks for the code, but unfortunately that's actually pretty much the same thing I did except that I added it to DotScene Plugin's SceneMain class. However even though the lights get loaded successfully, they're still not lighting the static geometry. Do you have any other thoughts as to what you might have changed?
Hi,

first of all I want to thank all of you for your great work on Ogre! I'm part of a team that's developing a 3D adventure that plays in city and for that the DotSceneManager suits perfectly. However, I also have the problem that my static geometry doesn't get lit. I'm using Ogre 0.15.2 and the MilkshapeExporter as well as the SceneConverterSample to create the octree data. For debugging reasons I added a light and a human model by code:

Code: Select all

Light *pl = mDotSceneMgr->createLight("pointlight1");
pl->setType(Light::LT_POINT);
pl->setPosition(10.0, 6.0, 10.0);

Entity* ePlayer = mDotSceneMgr->createEntity("player", "Modelle/mann.mesh");
mPlayer = mDotSceneMgr->getRootSceneNode()->createChildSceneNode();
mPlayer->attachObject(ePlayer);
The human stands in front of a building and is lit properly, but the building remains dark. I've tried bisco's patch, but that didn't help at all. So it seems I have the same problem like ashleyder. Finally a screenshot:
[img]deleted[/img]

I have absolutely no idea what goes wrong here, so if anyone of you has an idea I would be very glad if he could help me.
Tommy
Gnoblar
Posts: 15
Joined: Sun Jan 23, 2005 5:48 pm
Location: Germany

Post by Tommy »

:oops: Sorry, my fault. I included bisco's patch but didn't copy the new Plugin_DotSceneManager.dll to my working directory :oops: Shame on me. Now I have another problem: The light seems to shine through buildings. Is this a problem of my geometry or does this have to do with the SceneManager?

Edit: Thanks sinbad!
Last edited by Tommy on Mon Jan 24, 2005 5:43 pm, edited 2 times in total.
User avatar
sinbad
OGRE Retired Team Member
OGRE Retired Team Member
Posts: 19269
Joined: Sun Oct 06, 2002 11:19 pm
Location: Guernsey, Channel Islands
x 67

Post by sinbad »

That's just the nature of vertex lighting, it doesn't take account of occlusion. You need to either hide it by adjusting the range and attenuation factors on the light to make it tail off more with distance, or you can try to use shadows to darken occluded areas.