Skip to content

shader_fs_core

The standard Fragment Shader package. Handles texture lookups, sprite/text switching, and basic coloring.


vec4 getTexColor(vec4 bytes, vec2 uv) {
int texIndex = int(bytes.x * 255.0 + 0.5);
vec4 texColor = vec4(1.0);
if (texIndex == 0) {
texColor = texture(sampler2D(uTex, uDefaultSampler), uv);
} else if (texIndex == 1) {
texColor.a = texture(sampler2D(uFontTex, uDefaultSampler), uv).r;
}
return texColor;
}

Retreives the correct pixel color for the current fragment.

This function automatically detects if the primitive is a Sprite or a Text based on the bytes data and samples the correct atlas accordingly.

Arguments:

  • bytes: The vBytes varying passed from the vertex shader.
  • uv: The texture coordinates.

bool hasFlag(int flags, int flag) {
return (flags & flag) != 0;
}

Helper to check if a specific bit is set in an integer bitmask.

Arguments:

  • flags: The integer containing all flags.
  • flag: The specific bit to check.

layout(binding=0) uniform sampler uDefaultSampler;

Binding 0 (Sampler): The default sampler state. Shared by both texture atlases.


layout(binding=1) uniform texture2D uFontTex;

Binding 1 (Texture): The font atlas. Sampled when textureIndex == 1. Stores font data in the Red color channel.


layout(binding=0) uniform texture2D uTex;

Binding 0 (Texture): The main sprite atlas. Sampled when textureIndex == 0.


in vec4 vBytes;

Input: Packed data passed from the vertex attributes.

  • x: Texture index (0 = Sprite, 1 = Font)

in vec4 vColor;

Input: Vertex color (multiplied by sprite color).


in vec4 vColorOverride;

Input: Color override.

  • rgb: The tint color.
  • a: The blend strength (0.0 = off, 1.0 = full override)

in vec2 vLocalUv;

Input: Local UV coordinates relative to the sprite itself.


in vec4 vParams;

Input: Custom parameters passed via Vertex.parameters


in vec3 vPosition;

Input: Interpolated world space position of the fragment. Z position is used for depth.


in vec2 vSize;

Input: World space size of the sprite in pixels.


in vec2 vUv;

Input: Texture coordinates for the atlas.