12.6 C
New York
Wednesday, November 26, 2025

opengl – Easy methods to correctly implement ‘layered lighting’ with Box2D-Lights


How is Box2D-Lights allowed to have an effect on just one and just one? OrthographicCamera.

After researching I discovered the next reply. This reply particulars the way to stop a digital camera from being illuminated by the RayHandler combining layers of the FBO object. I am undecided if this reply will produce the outcomes I want. If it actually creates the outcomes I want, how can I do it extra merely and elegantly?

For instance:

1) On this picture you may see that the ambient gentle is ready to:

this.rayHandler.setAmbientLight(new Coloration(0.1f, 0.1f, 0.1f, 0.25f));

2) There’s a level of sunshine on the far proper that’s purple.

4) There’s a background of stars in a special place. OrthographicCamera to the opposite objects.

When this picture, you discover that the celebs are brighter close to the planet as a result of level gentle casting gentle on the background. Nonetheless, I want the other. Stars ought to be brighter when they aren’t drowned out by gentle. Figuring out that the background of stars is in one other OrthographicCamera How can I permit the feel to be unaffected by gentle in order that the ambient gentle of the RayHandler it doesn’t obscure them farther from the planet.

The feel used for the celebs accommodates transparency. Black is created utilizing:

Gdx.gl.glClearColor(0f, 0f, 0f, 1);

Ideally, I might like to have the ability to merely place the cameras into two lists, light-affected and light-unaffected. How do I produce the outcomes I want?

I can get the lighting to disregard the star background by rendering it after the RayHandler has been up to date and rendered, nevertheless this clearly causes the star background to principally be drawn like this:

Rocket game example

After attaining this, I remembered the OpenGL depth buffer. I enabled it utilizing Gdx.gl.glEnable(GL20.GL_DEPTH_TEST)then i attempted altering the z coordinate of the spritebatch used within the digital camera for the star background utilizing SpriteBatch.getTransformMatrix().idt().translate(0f, 0f, -1f) Nonetheless, after enjoying with the values ​​of the opposite batches of sprites, I nonetheless cannot get the impact I want.

The above methodology might have really labored, though I am conscious that incorrect use of the depth buffer may cause issues with alpha mixing. Making it appear like my drawback wasn’t solved as a result of the planet turned translucent.

Related Articles

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Latest Articles