Skip to content

Lighting

SolarLune edited this page Oct 5, 2023 · 5 revisions

Lighting

Lighting has been implemented in Tetra3d as of v0.5, and is done on a per-vertex basis. There's currently no support for shadows.

At some point, it might be better to handle lighting via a fragment shader instead, but that would require rendering the scene to a normal texture, which I have yet to implement.

Light Types

There are four kinds of vertex-based lights in Tetra3D:

Point lights

  • Point lights, similar to light bulbs. They cast light omnidirectionally with a distance falloff. Point lights can have a distance limit (which can improve performance significantly).

Directional Lights

  • Directional lights, similar to the sun. They cast light everywhere in a single direction.

Cube Lights

  • Cube Lights. Cube lights act something like "indoor lights". They are AABB (axis-aligned bounding box) volumes that cast light downwards within a set area in one direction (by default, from the top). Rotating them simply expands their axis-aligned box size, while also rotating the axis on which light is cast. Of course, you can also easily change this light casting axis directly through code.

    You can adjust a CubeLight's light bleed parameter to alter how much light is cast within the volume on the dark sides of objects.

Cube Lights 2

A cube light with 50% light bleed

Cube Lights 3

A cube light with 100% light bleed

  • Lastly, ambient lights, which simply tint all triangles evenly. This can be useful to change the overall mood or light / dark level of a scene.

All Lights implement INode (and so can be considered nodes), which means they can be positioned and parented like any other Node.

By default, Scenes in Tetra3D are lit. To shine lights on a Scene, you'll need to simply add Light nodes to it, either in Blender (ideally exported through the Tetra3D Python addon, existing in the repo or downloadable separately as an asset alongside the latest release), or through code.

In Blender's Eevee renderer, each scene's ambient lighting is, by default, affected by the scene's world color and energy. This being the case, when exporting a scene through the Tetra3D add-on, this world color will automatically become an ambient light present in the Scene's World property. This makes it so that your game in Tetra3D can look somewhat like Blender's render.

Red World

In the above screenshot, in Blender, the world settings are set to have a 0.5 strength red tint, so in Tetra3D, this becomes a 0.5 strength red ambient light, raising the dark level in an attempt to match. While this isn't as accurate as Blender's lighting solution, of course, it's enough to allow you to tweak your lighting to suit a given mood.

LightGroups

A LightGroup is a selection of Lights that you can specify to control which lights influence which Models. This can be very useful to exercise greater control over lighting and spaces, as only the lights in the LightGroup influence the Model. You could, for example, create a variety of LightGroups and then assign them to Models depending on their location or proximity to specific Lights. You can specify the lights that compose the group either on creation of the LightGroup, or add them in later. See the lightgroups example for more information.

Baking

Both lighting and some primitive ambient occlusion can be baked to vertex colors in Tetra3D by using Model.BakeLighting() and Model.BakeAO(), respectively. These options bake to a vertex color channel in the Model's mesh, meaning that other Models that share that same Mesh will have the same lighting or ambient occlusion. Inter-object ambient occlusion is also supported, though it is also relatively primitive. Also note that ambient occlusion is currently relatively slow when baking.

To see an example of this, reference the Baking example.

Ambient occlusion can also, of course, be painted ahead of time. The Dirty Vertex Colors option when Vertex Painting a model in Blender is particularly useful for this; to learn more about it, see the appropriate section in the Materials page.

Clone this wiki locally