Spatial shaders

    Values marked as “in” are read-only. Values marked as “out” are for optional writing and will not necessarily contain sensible values. Values marked as “inout” provide a sensible default value, and can optionally be written to. Samplers are not subjects of writing and they are not marked.

    Vertex data (, NORMAL, TANGENT, BITANGENT) are presented in local model space. If not written to, these values will not be modified and be passed through as they came.

    They can optionally be presented in world space by using the world_vertex_coords render mode.

    Users can disable the built-in modelview transform (projection will still happen later) and do it manually with the following code:

    Users can override the modelview and projection transforms using the POSITION built-in. When POSITION is used, the value from VERTEX is ignored and projection does not happen. However, the value passed to the fragment shader still comes from .

    For instancing, the INSTANCE_CUSTOM variable contains the instance custom data. When using particles, this information is usually:

    • x: Rotation angle in radians.
    • z: Animation frame.

    This allows you to easily adjust the shader to a particle system using default particles material. When writing a custom particles shader, this value can be used as desired.

    The default use of a Godot fragment processor function is to set up the material properties of your object and to let the built-in renderer handle the final shading. However, you are not required to use all these properties, and if you don’t write to them, Godot will optimize away the corresponding functionality.

    To write a light function, assign something to DIFFUSE_LIGHT or SPECULAR_LIGHT. Assigning nothing means no light is processed.

    The light function is called for every light in every pixel. It is called within a loop for each light type.

    Below is an example of a custom light function using a Lambertian lighting model:

    1. }

    If you want the lights to add together, add the light contribution to DIFFUSE_LIGHT using +=, rather than overwriting it.