penumbra icon indicating copy to clipboard operation
penumbra copied to clipboard

[DOC] light origin need more explanations and example

Open InfiniteProductions opened this issue 8 years ago • 3 comments

What "origin" property is supposed to do and to be used ? It is described as a normalized value ( in [0..1] interval only) but how to deal with this using screen coordinates for light position ? Which are valid values ? As the setter doesn't do the normalization itself as opposite to the "documentation" seems to suggest.

For example, using a Vector2(10,0) as Origin for a spotlight make it doesn't shows on the screen (no light). It's unusual to mix values like this and not very easy, a x value of 0.1 make the spotlight away for it's center but how much ? I can't tell unless doing the maths inside light class myself.

InfiniteProductions avatar May 01 '16 06:05 InfiniteProductions

Each light is essentially a quad. Origin is the anchor point which marks the (0; 0) point on that quad (in local space). Depending if you are operating in SpriteBatch's screen space (y-axis runs from top to bottom) origin (0; 0) represents the light quad's top left corner while (1; 1) represents the bottom right corner. The reason its normalized to [0..1] is so that if you change the scale of your light, you wouldn't need to change the origin: an origin (0.5; 0.5) would still mark the center of the light. I see a source of confusion here because SpriteBatch's origin is not normalized. Perhaps an anchor would be a better name...

When it comes to the setter, there is no automatic normalization being done: it is expected to be set in its normalized form. The reason values outside [0..1] range are allowed is that it might be desirable for some weird rotation scenarios, though such usage should be rather uncommon.

Usually, for PointLight and Spotlight the default values are sufficient.

(0.5; 0.5) marks the origin for point light (since it emanates from the quad's center): Point light

(0.0; 0.5) marks the origin for spotlight: Spotlight

Main usage for the property is when you use a TexturedLight with a custom texture where the light may emanate from whichever point on that texture (quad). For example, for the following texture you would set the origin to (0.5; 0.0): Textured light

I hope that helps :) Let me know if anything is still unclear.

discosultan avatar May 01 '16 08:05 discosultan

Thanks, it's clearer now :). I don't think there were any details about how default spotlight are made (not as crystal clear as here at least), so the confusion. I suggest to add some words and rephrasing a bit maybe as from my point of view, origin or anchor is very close to UV coordinates inside the texture. Example(s) with some random textured light, with screen capture of paint program showing light point and origin value used in code may be very helpful. (Also, what could be done with textured light if origin is not on any of the edges).

InfiniteProductions avatar May 01 '16 09:05 InfiniteProductions

origin or anchor is very close to UV coordinates inside the texture

UV coordinates are a good analogy. In case of using the same transform as SpriteBatch (penumbra.SpriteBatchTransformEnabled = true;), they match exactly. Otherwise it depends on the penumbra.Transform being used: if the world's y-coordinate runs from bottom to top, then that is also the case for Origin.

Also, what could be done with textured light if origin is not on any of the edges

I guess you would just need to try out different origins until you find the sweet spot.

discosultan avatar May 02 '16 07:05 discosultan