Please login or register.

Login with username, password and session length
Advanced search  

News:

For WME related articles and tutorials visit WME Resource Center.

Author Topic: SpotLight ranges are not working?  (Read 2834 times)

0 Members and 1 Guest are viewing this topic.

ErV

  • Occasional poster
  • **
  • Karma: 0
  • Offline Offline
  • Gender: Male
  • Posts: 54
  • I regret nothing!
    • View Profile
SpotLight ranges are not working?
« on: October 19, 2006, 10:03:31 PM »

Hello.
It looks like attenuation doesn't work with spotlights exported from 3dsmax, even if farAttenuation was set. I know that DirectX supports spotlight attenuation. Is this a bug? (I'm talking about decreasing light brightness according to the distance from light, not the "falloff" and "hotspot" parameters)
« Last Edit: October 19, 2006, 10:19:55 PM by ErV »
Logged

Mnemonic

  • WME developer
  • Administrator
  • Addicted to WME forum
  • *
  • Karma: 41
  • Offline Offline
  • Gender: Male
  • Posts: 5683
    • View Profile
    • Dead:Code Site
Re: SpotLight ranges are not working?
« Reply #1 on: October 20, 2006, 08:27:58 AM »

Unfortunately the 3DS file doesn't contain the attenuation info (correct me if I'm wrong).
Logged
Yes, I do have a twitter account
Please don't send me technical questions in private messages, use the forum. ::wave

ErV

  • Occasional poster
  • **
  • Karma: 0
  • Offline Offline
  • Gender: Male
  • Posts: 54
  • I regret nothing!
    • View Profile
Re: SpotLight ranges are not working?
« Reply #2 on: October 20, 2006, 11:13:39 AM »

Unfortunately the 3DS file doesn't contain the attenuation info (correct me if I'm wrong).
Unfortunately, you are wrong.

Lights in 3dsmax has additional parameter - "Far Attenuation". If enabled, this parameter produces two additional subchunks in chunk 0x4600. Those chunks contains "far attenuation inner radius" and "far attenuation outer radius".
The chunks are:
0x465A (outer radius - 4bytes float)
0x4659 (inner radius - 4bytes float)

both chunks contains just a single float, so each is  10 bytes long.

The object will be lit at maximum brightness (original color * 1.0f), if distance <= innerRadius,
and it will not be affected by light at all, if distance >= outerRadius;
So, in 3dsmax attenuation (linear) is calculated this way:
float attenuation =
 (distance >= outerRadius)? 0.0f:
  (distance <= innerRadius)? 1.0f:
   (distance - innerRadius)/(outerRadius - innerRadius);

While it is not possible to implement this attenuation model without writing a vertex shader,
it'll be good to make an approximation at least. For example - you could ignore innerRadius value and make light fade out at outerRadius;

This can be achieved by setting, for example D3DLIGHT8::Attenuation1 to some radius-dependant value.
What value is to be assigned, can be guessed during expirementation, since DirectX attenuation model isn't quite good...

It would be a great thing to do, since the lack of attenuation combined with limited lightRange and vertex lighting produces a quite ugly graphical effect.

There is also additional chunk that controls light's "multiplier" value:
0x465B
As I presume/suppose, light color is supposed to be multiplied by this value to make light look the way it was in 3dsmax.

There are also decay parameter, I think, but I was unable to make my 3dsmax export something unusual except those 3 chunks.

P.S. With the light having attenuation, there will be unlit spots in scene. And they will be black. That's why I asked about global ambient lighting.
« Last Edit: October 20, 2006, 11:28:12 AM by ErV »
Logged
 

Page created in 0.061 seconds with 23 queries.