Skip to content
MarkelZ edited this page Oct 2, 2023 · 13 revisions

How do I add lights to a project that already exists?

Check out the wiki entry Adding lights to an existing project.

How to get harder/softer shadows?

Shadow softness is given by the variable shadow_blur_radius in LightingEngine. By default, this variable is set to 5.

  • For softer shadows, increase the value of shadow_blur_radius. Note that increasing the value of this variable also increases the computational cost.

    If you want to have very soft shadows, it is more efficient to instead downscale the resolution of the lightmap when initializing the engine. That is, set the lightmap_res argument to a lower resolution when constructing the lighting engine.

  • For harder shadows, decrease the value of shadow_blur_radius. For fully hard shadows, you want to set it to 1.

    Keep in mind that if the lightmap has a lower resolution than the screen, it will still have some blur due to upscaling.

    If you want pixel-perfect shadows, you need to do the following:

lights_engine.set_aomap_filter((pl2d.NEAREST, pl2d.NEAREST))

How can I use a camera together with the lighting engine?

TODO

Does the alpha value of a light's color matter?

TODO

I have a memory leak, how can I fix it?

One way that memory leaks are commonly introduced with this engine is by forgetting to free the data of a temporary texture.

For example, if you want to render some text onto the screen to show the FPS of the game, you may be doing this:

  1. Use pygame to draw text with the current FPS on a Surface object.
  2. Turn the Surface object into a OpenGL Texture object using this engine's surface_to_texture function.
  3. Render the texture with the engine's render_texture method.

Since you are creating a new texture in every single frame of the game, you will have a memory leak unless you free the data of the temporary textures. To do so, you need to call release on the texture after you render it:

texture.release()