# Lighting Shader Format

The lighting format is a separate set of uniforms used to handle the lighting system. Implementing the lighting format in your shader allows you to use the [Graphics#renderLights()](https://ci.kingtux.dev/job/Kakara%20Engine%202/job/master/javadoc/org/kakara/engine/render/Graphics.html#renderLights\(org.kakara.engine.scene.Scene,org.kakara.engine.Camera,org.kakara.engine.lighting.LightHandler,org.kakara.engine.render.Shader\)) method.

## Vertex

For the vertex format it is required to have the modelLightView matrix. See the [standard](https://kakara.gitbook.io/engine/render-system/extensible-render-pipeline/standard-shader-format) and the[ voxel](https://kakara.gitbook.io/engine/render-system/chunk-shader-format#vertex) for the uniform names (and a layout).

**Note: That uniform is not set by the Graphics#renderLights() method and is only needed if not using a custom format.**

## Fragment

The following structs are needed by the lighting system:

```c
struct Attenuation
{
    float constant;
    float linear;
    float exponent;
};

struct PointLight
{
    vec3 color;
    vec3 position;
    float intensity;
    Attenuation att;
};

struct SpotLight
{
    PointLight pl;
    vec3 conedir;
    float cutoff;
};

struct DirectionalLight
{
    vec3 color;
    vec3 direction;
    float intensity;
};
struct Fog
{
   int activeFog;
   vec3 color;
   float density;
};
```

Then the following uniforms are required:

```c
const int MAX_POINT_LIGHTS = 5;
const int MAX_SPOT_LIGHTS = 5;

uniform vec3 ambientLight;
uniform float specularPower;

uniform PointLight pointLights[MAX_POINT_LIGHTS];
uniform SpotLight spotLights[MAX_SPOT_LIGHTS];
uniform DirectionalLight directionalLight;

uniform sampler2D shadowMap;
uniform Fog fog;
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://kakara.gitbook.io/engine/render-system/extensible-render-pipeline/lighting-shader-format.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
