smart-fun / smartGL

SmartGL is a Graphic Engine for creating Android Games and Apps. It is based on OpenGL and handles 2D Sprites and 3D Textured Objects.
Apache License 2.0
109 stars 24 forks source link

how can you add light ? #21

Open glebzheglov opened 5 years ago

glebzheglov commented 5 years ago

how can you add light ? I tried to add it through "setLightParallel", but I can't do it

smart-fun commented 5 years ago

Hello Zazolin and thanks for using smartGL.

The light feature is beta and is not documented yet (sorry), but you can use it.

If you look at the smartglapp, you'll see that it is used.

You need to use a shader that handles the lights (SHADER_TEXTURE_LIGHTS) like this:

RenderPassObject3D renderPassObject3D = new RenderPassObject3D(RenderPassObject3D.ShaderType.SHADER_TEXTURE_LIGHTS, true, true);
renderer.addRenderPass(renderPassObject3D);

then you can set 1 Parallel light:

SmartColor lightColor = new SmartColor(1, 0, 1);
Vector3D lightDirection = new Vector3D(0.2f, -1, -1);
LightParallel lightParallel = new LightParallel(lightColor, lightDirection);
renderer.setLightParallel(lightParallel);

and/or an ambient light:

LightAmbiant lightAmbiant = new LightAmbiant(0.3f, 0.3f, 0);
renderer.setLightAmbiant(lightAmbiant);

If your ambient is too much white, probably you won't see the parallel light. Try eventually different light directions.

Arnaud.

glebzheglov commented 5 years ago

thank you ! now I was able to add light to the scene