Skip to content

GLSL API

Flywheel backends expect user-authored shaders to follow a specific format.

Prelude

The Prelude is included by default for all shaders compiled by Flywheel backends.

Some functions/variables are only available for specific shader stages.

glsl
struct FlwLightAo {
    vec2 light;
    float ao;
};

/// Get the light at the given world position.
/// This may be interpolated for smooth lighting.
bool flw_light(vec3 worldPos, vec3 normal, out FlwLightAo light);

/// Fetches the light value at the given block position.
/// Returns false if the light for the given block is not available.
bool flw_lightFetch(ivec3 blockPos, out vec2 light);
glsl
const uint FLW_MAT_DEPTH_TEST_OFF = 0u;
const uint FLW_MAT_DEPTH_TEST_NEVER = 1u;
const uint FLW_MAT_DEPTH_TEST_LESS = 2u;
const uint FLW_MAT_DEPTH_TEST_EQUAL = 3u;
const uint FLW_MAT_DEPTH_TEST_LEQUAL = 4u;
const uint FLW_MAT_DEPTH_TEST_GREATER = 5u;
const uint FLW_MAT_DEPTH_TEST_NOTEQUAL = 6u;
const uint FLW_MAT_DEPTH_TEST_GEQUAL = 7u;
const uint FLW_MAT_DEPTH_TEST_ALWAYS = 8u;

const uint FLW_MAT_TRANSPARENCY_OPAQUE = 0u;
const uint FLW_MAT_TRANSPARENCY_ADDITIVE = 1u;
const uint FLW_MAT_TRANSPARENCY_LIGHTNING = 2u;
const uint FLW_MAT_TRANSPARENCY_GLINT = 3u;
const uint FLW_MAT_TRANSPARENCY_CRUMBLING = 4u;
const uint FLW_MAT_TRANSPARENCY_TRANSLUCENT = 5u;

const uint FLW_MAT_WRITE_MASK_COLOR_DEPTH = 0u;
const uint FLW_MAT_WRITE_MASK_COLOR = 1u;
const uint FLW_MAT_WRITE_MASK_DEPTH = 2u;

const uint FLW_MAT_CARDINAL_LIGHTING_MODE_OFF = 0u;
const uint FLW_MAT_CARDINAL_LIGHTING_MODE_CHUNK = 1u;
const uint FLW_MAT_CARDINAL_LIGHTING_MODE_ENTITY = 2u;

struct FlwMaterial {
    bool blur;
    bool mipmap;
    bool backfaceCulling;
    bool polygonOffset;
    uint depthTest;
    uint transparency;
    uint writeMask;
    bool useOverlay;
    bool useLight;
    uint cardinalLightingMode;
};
glsl
#include "flywheel:api/material.glsl"
#include "flywheel:api/common.glsl"

vec4 flw_vertexPos;
vec4 flw_vertexColor;
vec2 flw_vertexTexCoord;
ivec2 flw_vertexOverlay;
vec2 flw_vertexLight;
vec3 flw_vertexNormal;

/*const*/ FlwMaterial flw_material;

// To be implemented by the instance shader.
void flw_instanceVertex(FlwInstance i);

// To be implemented by the instance cull shader.
void flw_transformBoundingSphere(in FlwInstance i, inout vec3 center, inout float radius);

// To be implemented by the material vertex shader.
void flw_materialVertex();
glsl
#include "flywheel:api/material.glsl"
#include "flywheel:api/common.glsl"

/*const*/ vec4 flw_vertexPos;
/*const*/ vec4 flw_vertexColor;
/*const*/ vec2 flw_vertexTexCoord;
/*const*/ ivec2 flw_vertexOverlay;
/*const*/ vec2 flw_vertexLight;
/*const*/ vec3 flw_vertexNormal;

/*const*/ FlwMaterial flw_material;

/*const*/ vec4 flw_sampleColor;

/*const*/ float flw_distance;

vec4 flw_fragColor;
ivec2 flw_fragOverlay;
vec2 flw_fragLight;

// To be implemented by the material fragment shader.
void flw_materialFragment();
// To be implement by fog shaders.
vec4 flw_fogFilter(vec4 color);
// To be implemented by discard shaders.
bool flw_discardPredicate(vec4 finalColor);

sampler2D flw_diffuseTex;
sampler2D flw_overlayTex;
sampler2D flw_lightTex;