Ss14 graphics shaders

From space-sunrise/lust-station · View interactive version

Ss14 graphics shaders is an AI agent skill from the GitHub repository space-sunrise/lust-station. An in-depth practical guide to SS14 and SWSL shaders: syntax, presets, built-in variables/functions, parameters, debugging and architectural solutions. Use it for tasks about shader prototype, uniform, light_mode/blend_mode, stencil, compatibility and GPU effects.

How to use this skill

Skill file

SS14 shaders (SWSL)

This skill covers only the shader part: language, runtime, built-in functions, parameters and debugging :)

If the task is about the lifecycle of overlays, OverlaySpace, render target and primitives, use a separate skill about overlays.

Short decision tree

  1. Do you only need blending/lighting/stencil mode without custom math?
  1. Need a custom vertex (deformation, separate varyings)?
  1. Need full control over vertex transformation without auto-lighting?

Execution model

  1. The shader prototype defines kind and default parameters.
  2. SWSL is parsed into uniform/varying/const/functions + include dependencies.
  3. The engine wraps the code in a default or raw template and adds a common library of functions.
  4. During rendering, ShaderInstance receives parameter values ​​from C# and is applied to the draw-call.

SWSL language: what is supported

Critical:

Built-in variables and functions

Available common uniforms:

Frequently used functions:

Additionally in preset raw:

Example A: basic fullscreen fragment

uniform sampler2D SCREEN_TEXTURE;

void fragment() {
    // We take the current screen taking into account the engine selection rules.
    highp vec4 src = zTextureSpec(SCREEN_TEXTURE, UV);

    // We convert the image to grayscale using the engine function.
    highp float gray = zGrayscale(src.rgb);

    // We return the result with the original alpha.
    COLOR = vec4(vec3(gray), src.a);
}

Example B: vertex deformation via varying

uniform sampler2D displacementMap;
uniform highp float displacementSize;
uniform highp vec4 displacementUV;

varying highp vec2 displacementUVOut;

void vertex() {
    // We pass the UV for the displacement map from the vertex to the fragment.
    displacementUVOut = mix(displacementUV.xy, displacementUV.zw, tCoord2);
}

void fragment() {
    // We read the displacement map and shift the sampling of the main texture.
    highp vec4 disp = texture2D(displacementMap, displacementUVOut);
    highp vec2 offset = (disp.xy - vec2(128.0 / 255.0)) / (1.0 - 128.0 / 255.0);
    COLOR = zTexture(UV + offset * TEXTURE_PIXEL_SIZE * displacementSize * vec2(1.0, -1.0));
    COLOR.a *= disp.a; // The displacement map alpha works like a mask.
}

Example C: working correctly with ShaderInstance in C#

// We take a unique instance to safely change uniforms.
var shader = prototype.Index(shaderId).InstanceUnique();

// We set the effect parameters every frame/tick as needed.
shader.SetParameter("Strength", strength);
shader.SetParameter("SCREEN_TEXTURE", screenTexture);

handle.UseShader(shader);
handle.DrawRect(bounds, Color.White); // A real draw-call where the shader is applied.
handle.UseShader(null);               // Explicit state reset.

Patterns 🙂

Anti-patterns

Mini checklist before use

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.