Problem with PointLight

Hi,

I have been playing about with Xith3D for a couple of days writing a Dungeon Master clone, and I’ve got a tiny problem with using PointLight.

I have a PointLight at the same location as the View eye, which moves with the player (representing a torch carried by the player). I want this to only illuminate a small “pool” of light arround the player, the problem is that far away walls are still being lit brightly looking very odd. See this screenshot for details -
http://www.bencoleman.co.uk/screen1.jpg

Any ideas how to prevent this? I’ve tried adding a BoundingSphere to the light and changing the attenuation but none of this has helped.

BTW - I know the graphics and math theory why this happening but I don’t know how to stop it in Xith3D

Any help very much appreciated, cheers
Ben

Hi,

You should use distance attenuation for your light - this is done exactly for that.

Use PointLight.setAttenuation(Point3f), where x = constant atteniation, y = linear distance, z = quadratic distance attenuation.

The default attenuation is 1, 0, 0, which means it does not depend on distance.

This is strange that attenuation does not work for you. If you feel this is a bug, I request a small (as small as possible) test case and an issue filed in IssueZilla, so I can check if attenuation really works or not.

Yuri

Thanks,

I was simply using the X part (constant attenuation)
I didn’t know Y, Z did anything!

I’ve changed to quadratic distance (Z) and it’s looking a lot better, I need to play about with the values and the ambient light to get it looking 100% as I want.

Here’s a new screen shot
http://www.bencoleman.co.uk/screen2.jpg

Thanks a lot!

The Hawk would REALLY ;D like to see a code exceprt on this. My Point lights have yet to give this effect…arrrggghh. Are you using your own bounds, the default bounds, a boundingleaf, and influencingbounds…??

Hawk,

Just try setAttenuation(new Point3f(1f, 1f, 0f)) on your light.

Default value for attenuation is 1, 0, 0, and this means no distance attenuation.

Equation is:

d = distance;
a = attenuation;
i = light intensity;
R = resulting intensity;

R = i*a.x + i*a.y*d + i*a.z*d*d;

Yuri

Hello

The light intensity must be grow weaker in the distance,
e.g. for (0.0f<=distance<=1.0f)
R = ia.x + ia.yd + ia.z*(dd) is ok, but for
(distance>=1.0f)
R = i
a.x + ia.y/d + ia.z/(d*d) is correct.

Also, there is a difference between ‘java3d’ and ‘xith’
in ‘setAttenuation(new Point3f(1f, 1f, 0f))’.
In ‘java3d’ you can set :
setAttenuation(new Point3f(1f, 0f, 0f)) or
setAttenuation(new Point3f(0f, 1f, 0f)) or
setAttenuation(new Point3f(0f, 0f, 1f))
but not 2 values concurrently, how
setAttenuation(new Point3f(1f, 1f, 0f))

A Problem what i have with a PointLight in xith
is. that i can’t set it corretly.
Normally, under a pointlight, one half from a sphere must be highlighted and the other not.
(There a no reflections from a side, and the own
shininess from the sphere is very low)
My question is:
" How can i set a pointlight correct, so one half from
a sphere is highlighted and the other not???"

Thanks Adi

Hi,

Xith3D sends attenuation to OpenGL as they are, so docs from OpenGL are valid for attenuation factors:

[quote]GL_CONSTANT_ATTENUATION
GL_LINEAR_ATTENUATION
GL_QUADRATIC_ATTENUATION
The params parameter is a single integer or floating-point value that specifies one of the three light attenuation factors. Integer and floating-point values are mapped directly. Only nonnegative values are accepted. If the light is positional, rather than directional, its intensity is attenuated by the reciprocal of the sum of: the constant factor, the linear factor multiplied by the distance between the light and the vertex being lighted, and the quadratic factor multiplied by the square of the same distance. The default attenuation factors are (1,0,0), resulting in no attenuation.
[/quote]
The equation in my previous post is to give an idea of the x, y and z attenuation factor dependencies.

As of PointLight, the statement

[quote]Normally, under a pointlight, one half from a sphere must be highlighted and the other not.
[/quote]
seems to be incorrect.

Both Java3D and Xith3D set cutoff angle of PointLight to 180 deg., resulting in uniform light distribution:

[quote]GL_SPOT_CUTOFF
Effective light intensity is attenuated by the cosine of the angle between the direction of the light and the direction from the light to the vertex being lighted, raised to the power of the spot exponent. Thus, higher spot exponents result in a more focused light source, regardless of the spot cutoff angle (see the following paragraph). The default spot exponent is 0, resulting in uniform light distribution.
The params parameter is a single integer or floating-point value that specifies the maximum spread angle of a light source. Integer and floating-point values are mapped directly. Only values in the range [0,90], and the special value 180, are accepted. If the angle between the direction of the light and the direction from the light to the vertex being lighted is greater than the spot cutoff angle, then the light is completely masked. Otherwise, its intensity is controlled by the spot exponent and the attenuation factors. The default spot cutoff is 180, resulting in uniform light distribution.
[/quote]
You should use SpotLight and set its spread angle to 90 deg. to achieve the effect you want.

Yuri

Hello

Thanks for your help.

Normally, a SpotLight is good, but a sun in a solarsystem shines in all directions,
not in a specific one, how a SpotLight does.

If i have no light integrated, all is highlighted.
Normally, my textured planets cannot be seen, without a lightsource.

I only have one lightsource, (sitting in the center, the sun), but the lightsource is sitting on my position, i think.
When i change my lightsource to red, with a simple rotation, i can see that the color from the lightsource
changes from red to white, but i have only that
red color light.
What can it be???

Bye Adi

Could be a specularity (shiny-ness) problem with (large) white highlights showing over the whole object making them appear white.

Here’s some code for a completely non-specular material


        Material matt_basic = new Material();
        matt_basic.setAmbientColor(1f, 1f, 1f);  ;
        matt_basic.setDiffuseColor(1f, 1f, 1f);             
        matt_basic.setShininess(0.00f);
        matt_basic.setSpecularColor(0.00f, 0.00f, 0.00f);
        matt_basic.setLightingEnable(true); 

Hello

Many thanks for your help.
The ‘shininess’ was the problem.

Bye Adi