Ecere SDK/eC Forums https://ecere.org/community/ Print view |
|
Light, Euler https://ecere.org/community/viewtopic.php?f=7&t=16 |
Page 1 of 1 |
Author: | sacrebleu [ Wed Jan 20, 2010 12:15 am ] |
Post subject: | Light, Euler |
Please describe in detail including Code: Select all
|
Author: | jerome [ Wed Jan 20, 2010 12:39 pm ] |
Post subject: | Re: Light, Euler |
Ok so I will try to explain how to use lights with the Ecere 3D engine. Lights are set on a Display by calling the Display::SetLight method with a Light structure. Let's take a look at the API: Code: Select all
There are 2 categories of lights. For the simpler one, where lightObject is 'null', only the orientation and the color members (multiplier, diffuse, ambient & specular) are taken into account. It defines a directional light source. Orientation Orientations in the 3D engine are usually specified as Quaternion. Read up that wikipedia article to learn about the advantages of quaternions over Euler angles. They include avoiding Gimbal locks (losing a degree of freedom of rotation), and allow for performing spherical linear interpolation. Euler angles are the familiar notion of orientation from 3 components: yaw (rotation around the y-axis), pitch (rotation around the x-axis) and roll (rotation around the z-axis). Ecere makes it to easy to convert from one to the other using eC's conversion properties: Code: Select all
Colors You can specify how the light source contributes to the lighting model in 3 ways: ambient, diffuse, and specular lighting. Each of these component will react with the material of the objects being drawn accordingly. The 'multiplier' member multiplies all of these 3 components so they can go beyond the 0.0-1.0 range of ColorRGB. Then you have the more complex model, where lightObject points to an insance of the Object class, which will be marked as a light source in its ObjectFlags (Object::flags.light == true). In this model the type of light is controlled by the Light::flags property. There are 2 basic types, omnidirectional or spotlight. Omnidirectional You can set flags.omni to true, although if flags.spot is not set this is the default. Here there is two ways you can specify the light's direction, either through a vector, by setting the 'direction' member, or by filling in the 'orientation' member. The vector 'direction' will be used if all of its 3 components (x,y,z) are 0, otherwise it is assumed that 'orientation' will be used. Note that this is not the case at the moment for the 'simple' light (when lightObject is null). The lightObject is actually not very useful in this case, this particular option of setting the 'direction' through a vector is the only thing you cannot do without a lightObject. Ecere should be fixed to also have that option when lightObject is null. Spotlight By setting flags.spot = true, lightObject becomes more useful and you can make yourself a spot light. Now you can position your light somewhere using lightObject.transform.position. The light can also be attached to a parent object (e.g. which could have a Mesh) using the Object hierarchy and articulation model, and also benefit from Object animation tracks system. You must also specify a 'target' for the light to point towards, which also is an Object instance. Note that the UpdateTransform() method must be called after making modifications to the 'transform' property. Spot lights also have additional parameters to control the angles of the spot: a hotSpot (range - both sides of the center point, in degrees) and a fallOff (also both sides -- so twice the GL_SPOT_CUTOFF). The GL_SPOT_EXPONENT is computed with the formula: Code: Select all
Attenuation Attenuation can be enabled for spot lights by setting flags.attenuation to true. It is then controlled by the 3 members Kc, Kl, and Kq, respectively standing for constant, linear and quadratic attenuation. The attenuation formula is f(d) = 1/(C + Ld + Qd^2 where d is the distance between the point being lit and the light source. Attenuation is loaded from 3DS models using the formula: Code: Select all
A quick way to set up both the Light and its Object lightObject together: Code: Select all
Caveats Only 8 lights (id 0 through 7) can be used in OpenGL due to OpenGL's limitation of 8 lights. Note that at one point calling Display::SetLight before or after the Display::SetCamera had different behavior, whether the light positioning is relative to the viewer's orientation and position or not. I do not remember if that was changed. I noticed that in the Test3DS and ColorSpheres it is set AFTER the camera, whereas in the other smaples it is set before. It would be worthwhile to test if both before and after give the same result, and whether lightObject vs/ no light object changes that behavior. Another major confusion is which sign to give the light vector's z component or which orientation to use to be going behind the screen or coming out of the screen. That remains to be clarified. Note that the support for all these nice Light properties are working well in OpenGL, but lacking in the Direct3D 8/9 drivers. Contributions to finalize its implementation are welcome. Find attached 3 samples using light sources in Ecere. OpenGL lighting: http://linux.die.net/man/3/gllight Direct3D 9 lighting: http://msdn.microsoft.com/en-us/library ... S.85).aspx, http://msdn.microsoft.com/en-us/library ... S.85).aspx |
All times are UTC-05:00 | Page 1 of 1 |
Powered by phpBB® Forum Software © phpBB Limited |