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;
// The index of the current vertex in the mesh that is being drawn.
/*const*/ uint flw_vertexId;
/*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;Uniforms
In addition to the stage-specific variables above, every stage has access to the following uniforms. All uniforms are included in the prelude and do not have to be manually included.
glsl
vec4 flw_fogColor;
vec2 flw_fogRange;
int flw_fogShape;glsl
struct FrustumPlanes {
vec4 xyX;// <nx.x, px.x, ny.x, py.x>
vec4 xyY;// <nx.y, px.y, ny.y, py.y>
vec4 xyZ;// <nx.z, px.z, ny.z, py.z>
vec4 xyW;// <nx.w, px.w, ny.w, py.w>
vec2 zX;// <nz.x, pz.x>
vec2 zY;// <nz.y, pz.y>
vec2 zZ;// <nz.z, pz.z>
vec2 zW;// <nz.w, pz.w>
};
FrustumPlanes flw_frustumPlanes;
mat4 flw_view;
mat4 flw_viewInverse;
mat4 flw_viewPrev;
mat4 flw_projection;
mat4 flw_projectionInverse;
mat4 flw_projectionPrev;
mat4 flw_viewProjection;
mat4 flw_viewProjectionInverse;
mat4 flw_viewProjectionPrev;
ivec3 flw_renderOrigin;
vec3 flw_cameraPos;
vec3 flw_cameraPosPrev;
vec3 flw_cameraLook;
vec3 flw_cameraLookPrev;
vec2 flw_cameraRot;
vec2 flw_cameraRotPrev;
vec2 flw_viewportSize;
float flw_aspectRatio;
float flw_defaultLineWidth;
float flw_viewDistance;
uint flw_ticks;
float flw_partialTick;
float flw_renderTicks;
float flw_renderSeconds;
float flw_systemSeconds;
uint flw_systemMillis;
/** 0 means no fluid. Use FLW_CAMERA_IN_FLUID_* defines to detect fluid type. */
uint flw_cameraInFluid;
/** 0 means no block. Use FLW_CAMERA_IN_BLOCK_* defines to detect block type. */
uint flw_cameraInBlock;
uint FLW_CAMERA_IN_FLUID_WATER;
uint FLW_CAMERA_IN_FLUID_LAVA;
uint FLW_CAMERA_IN_FLUID_UNKNOWN;
uint FLW_CAMERA_IN_BLOCK_POWDER_SNOW;
uint FLW_CAMERA_IN_BLOCK_UNKNOWN;glsl
vec4 flw_skyColor;
vec4 flw_cloudColor;
vec3 flw_light0Direction;
vec3 flw_light1Direction;
/** The current day number of the level. */
uint flw_levelDay;
/** The current fraction of the current day that has elapsed. */
float flw_timeOfDay;
uint flw_levelHasSkyLight;
float flw_sunAngle;
float flw_moonBrightness;
/** There are normally only 8 moon phases. */
uint flw_moonPhase;
uint flw_isRaining;
float flw_rainLevel;
uint flw_isThundering;
float flw_thunderLevel;
float flw_skyDarken;
uint flw_constantAmbientLight;
/** Use FLW_DIMENSION_* ids to determine the dimension. May eventually be implemented for custom dimensions. */
uint flw_dimension;
uint FLW_DIMENSION_OVERWORLD;
uint FLW_DIMENSION_NETHER;
uint FLW_DIMENSION_END;
uint FLW_DIMENSION_UNKNOWN;glsl
float flw_brightnessOption;
uint flw_fovOption;
float flw_distortionOption;
float flw_glintSpeedOption;
float flw_glintStrengthOption;
uint flw_biomeBlendOption;
uint flw_smoothLightingOption;
uint flw_viewBobbingOption;
uint flw_highContrastOption;
float flw_textBackgroundOpacityOption;
uint flw_textBackgroundForChatOnlyOption;
float flw_darknessPulsingOption;
float flw_damageTiltOption;
uint flw_hideLightningFlashesOption;glsl
vec3 flw_eyePos;
/** Alpha is 1 if any team color is present, 0 otherwise. */
vec4 flw_teamColor;
/** The brightness at the player's eye position. */
vec2 flw_eyeBrightness;
/** Brightness of the brightest light that the player is holding, 0-1. */
float flw_heldLight;
/** 0 means no fluid. Use FLW_PLAYER_EYE_IN_FLUID_* defines to detect fluid type. */
uint flw_playerEyeInFluid;
/** 0 means no block. Use FLW_PLAYER_EYE_IN_BLOCK_* defines to detect block type. */
uint flw_playerEyeInBlock;
uint flw_playerCrouching;
uint flw_playerSleeping;
uint flw_playerSwimming;
uint flw_playerFallFlying;
uint flw_shiftKeyDown;
/** 0 = survival, 1 = creative, 2 = adventure, 3 = spectator. */
uint flw_gameMode;
uint FLW_PLAYER_EYE_IN_FLUID_WATER;
uint FLW_PLAYER_EYE_IN_FLUID_LAVA;
uint FLW_PLAYER_EYE_IN_FLUID_UNKNOWN;
uint FLW_PLAYER_EYE_IN_BLOCK_POWDER_SNOW;
uint FLW_PLAYER_EYE_IN_BLOCK_UNKNOWN;