[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

Re: [pygame] lighting challenge



On 2015-07-05 19:49, Ian Mallett wrote:
âHi,

I played around with it a bit, but I'm not sure exactly what the problem is, nor do I have time to figure out exactly what you're trying to do about it.

I didn't run through your implementations in detail, but I did notice that you're copying surface(s) in every one. I bet this eats a lot of time.

Certainly, the blits will too. As you observed, a GPU is great for this sort of thing. If you haven't used PyOpenGL before, it might not be as hard as you think to get simple blitting function correct. Actually, I think there are already several projects on PyGame.org that provide it. In any case, GPUs exist to draw things. They're very good at it. It is wise to take them up on the offer.

Lastly, a correct-ish blitting function to use (assuming no SSS or radiosity) in pseudocode:
result = 0
for all surfaces:
ÂÂÂ light_at_surface = light intensity * product_of_alphas_between_light_and_surface
ÂÂÂ result += light_at_surface * surface_reflectance * product_of_surface_alphas_between_surface_and_eye
I bet that can be factored into a 1-pass-per-surface algorithm.

Ianâ

Hi Ian

The general idea was to find a way to simulate lights using pygame (using layers of pygame.Surfaces and the blend operators) for showing day/night or dark rooms. Maybe there are other, simpler or faster ways than what I did. I wanted to give people the possibility to contribute and experiment themselves to find an algorithm that gives some result. I had some fun trying different approaches and I thought maybe other can have fun too (without having to set up all the plumbing code in between). That said, if someone wants to contribute, fine, if not, its fine too.

I know a bit openGL (through PyOpenGL) and I know about the projects about openGL on pygame.org and I know about the huge processing power todays graphic cards have. Still, I wonder what can be done with simple blitting in pygame. I wonder, how to organize it, make it efficient. I guess, this is also applicable to openGL code. And yet, I like this simplicity of blitting pygame.Surfaces.

No offense, openGL is good and results look amazing. I probably will use it in future, but just not now.


About your pseudo-code:

I have been trying to write code according to your algorithm, but I don't understand it. At least not in terms of pygame.Surfaces.

I think the product_of_alphas_between_light_and_surface and product_of_surface_alphas_between_surface_and_eye can be omitted to simplify. Then what is left is like:

result = 0
for all surfaces:
ÂÂÂ light_at_surface = light intensity
ÂÂÂÂÂÂÂÂÂÂÂÂÂÂ result += light_at_surface * surface_reflectance

But even with that I'm not sure what to do about. Not sure how to translate that into blit operations.
Here some questions:

What is surface_reflectance exactly? A number? What range?
What do you mean by 'for all surfaces' ?
Why does it accumulate into one result? This result, is that a pygame.Surface? Or this would be per Pixel?
The operators '+' and '*' are not the blit operation pygame.BLEND_ADDÂ and pygame.BLEND_MULT, are they?

Maybe you could give me some clues so that maybe I'm able to write down code implementing this algorithm.

Help appreciated.
Thanks.

~DR0ID