[no bug] Light is weird, it looks so rectangular

You discovered a bug in the engine, and you are sure that it is not a problem of your code? Just post it in here. Please read the bug posting guidelines first.
Post Reply
pandaben7890
Posts: 12
Joined: Mon Nov 23, 2009 3:36 pm

[no bug] Light is weird, it looks so rectangular

Post by pandaben7890 »

I think my light is gonna be circle or something that's look more beautiful.

Did i do anything wrong on my code?

Code: Select all

void InitialLight() {
	//------ World Ambient Light--------
	smgr->setAmbientLight(SColorf(0.2,0.2,0.2));

	//------ Set Light Data --------
	SLight data;
	data.AmbientColor = SColorf(1.0f,0.6f,0.7f,0.0f);
	//data.AmbientColor = SColorf(1.0f,1.0f,1.0f,1.0f);
	data.Type = ELT_POINT;
	data.Radius = 1024.0f;
	data.CastShadows = true;

	//------ Add Light --------
	light = smgr->addLightSceneNode();
	light->setLightData(data);

	//------ Attach Billboard to Light --------
	ISceneNode *bill = 0;
	bill = smgr->addBillboardSceneNode(light,dimension2d<f32>(100,100));
	bill->setMaterialFlag(EMF_LIGHTING,false);
	bill->setMaterialType(E_MATERIAL_TYPE::EMT_TRANSPARENT_ALPHA_CHANNEL_REF);
	bill->setMaterialTexture(0,videoDriver->getTexture(PathMedia("fire2.png")));
}
Image
Last edited by pandaben7890 on Sat Nov 28, 2009 8:17 am, edited 2 times in total.
pandaben7890
Posts: 12
Joined: Mon Nov 23, 2009 3:36 pm

Post by pandaben7890 »

Is ELT_POINT worth to use?
Last edited by pandaben7890 on Mon Nov 23, 2009 5:35 pm, edited 2 times in total.
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

No, you need a working image hoster. All your images are broken.
pandaben7890
Posts: 12
Joined: Mon Nov 23, 2009 3:36 pm

Post by pandaben7890 »

I just update a new one with many tris. But not really that circle.
It has a circle-shaped but many edges around.

Ps. Sorry for my bad English TT
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

Could be that your normals are broken or you don't use NORMALIZE_NORMALS wen scaling your mesh. But besides such issues, you'll always get some artifacts without per-pixel lighting.
pandaben7890
Posts: 12
Joined: Mon Nov 23, 2009 3:36 pm

Post by pandaben7890 »

Code: Select all

model.node->setMaterialFlag(E_MATERIAL_FLAG::EMF_NORMALIZE_NORMALS,true);

I try this after you tell me, but nothing changes TT
vitek
Bug Slayer
Posts: 3919
Joined: Mon Jan 16, 2006 10:52 am
Location: Corvallis, OR

Post by vitek »

Read carefully...
hybrid wrote:you'll always get some artifacts without per-pixel lighting.
BlindSide
Admin
Posts: 2821
Joined: Thu Dec 08, 2005 9:09 am
Location: NZ!

Post by BlindSide »

I dont think those are just per-vertex lighting artifacts however, there is absolutely no attenuation (It gets cut off due to radius before getting a chance to attenuate).

I encountered similar issues and solved it by setting attenuation manually after applying radius but I haven't had a chance to take a look at the engine code that might be causing this problem.

EDIT:

Try this:

Code: Select all

lightNode->setRadius(lightRadius);
		lightNode->getLightData().Attenuation = vector3df(1.0f, 1.0f / lightRadius, 1.0f / (lightRadius * lightRadius));
EDIT2:

What's strange is that MSDN does suggest this:
Typically, an application sets Attenuation0 to 0.0, Attenuation1 to a constant value, and Attenuation2 to 0.0.
So if that does indeed fix the problem then I'm at a loss as to why.

EDIT3:

The formula that the GPU uses to calculate the strength of a light at a vertex is:

Code: Select all

Atten = 1/( att0i + att1i * d + att2i * d2)
Now assuming that att0i and att2i == 0, the light radius is 5 and att1i is set to 1/5, at 0 distance we get "1/(1/5 * 0)", which is infinity. As we approach the light's border, at distance 5 we get "1/(1/5 * 5)" which is equal to 1 exactly.

Basically what this means is that the attenuation factor irrlicht is currently using (0, 1/d, 0) would provide a light strength of > 1 everywhere inside the light's radius, leading to the artifacts visible in that screenshot (That being, an instant cutoff).

Surely I am missing something here. Either the MSDN docs are suggesting something ridiculous or there is another cause for this issue.

I am moving this to bug reports as I'm almost certain there is something wrong here.

EDIT4:

Oh yeah, I just noticed that you set the radius using SLightData and not using ILightSceneNode::setRadius (And therefore the attenuation factors did not even get calculated). If this solves your issue then I guess we don't have a problem here.
ShadowMapping for Irrlicht!: Get it here
Need help? Come on the IRC!: #irrlicht on irc://irc.freenode.net
pandaben7890
Posts: 12
Joined: Mon Nov 23, 2009 3:36 pm

Post by pandaben7890 »

Wow! It's work.

Atte makes light as it should to be.

Thank you for your answer, your answer is really perfect.. ^^

"Kop Koon Kub" ^^
BlindSide
Admin
Posts: 2821
Joined: Thu Dec 08, 2005 9:09 am
Location: NZ!

Post by BlindSide »

Ok I guess I need to make a test case for this.

Did you try doing setRadius() on the ILightSceneNode without setAttenuation (Like I said in edit 4)? If that also solves the problem then I guess there is no bug.

Cheers
ShadowMapping for Irrlicht!: Get it here
Need help? Come on the IRC!: #irrlicht on irc://irc.freenode.net
pandaben7890
Posts: 12
Joined: Mon Nov 23, 2009 3:36 pm

Post by pandaben7890 »

yeah i already did test it. I think that use .AddLightSceneNode(blah blah blah) is equal to .AddLightSceneNode() and then set SLight by myselft.

But it's not, it likes .AddLightSceneNode has its own way to calculate many things like "Attenuation" in its function. ^^

Thanks a lot.
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

No, just read the documentation of SLight. You are not supposed to use many of those fields, they are only for internal purpose. There are methods in ILightSceneNode to alter those values.
Post Reply