reckfellENGINE

Shader style: readability and deliberate edits

Complete example, order, names and formatting versus behavior changes.

On this page

Use one consistent layout so a reviewer can find the shader's inputs, stage work and bounds checks quickly. Formatting conventions do not change execution semantics; changing declaration order, names or hints can.

Complete example

Save as StyledReveal.reckfellshader and assign it through a ShaderMaterial to a visible ColorRect:

Shader
shader_type canvas_item;
render_mode unshaded;

uniform vec4 tint : source_color = vec4(1.0);
uniform float reveal_amount : hint_range(0.0, 1.0) = 1.0;

void fragment() {
    float boundary = clamp(reveal_amount, 0.0, 1.0);
    if (UV.x > boundary) {
        discard;
    }
    COLOR = tint;
}

The default is a full white card. Setting reveal_amount to 0.5 keeps the left half, and changing tint to red changes its color. The code clamps the boundary explicitly because hint_range only configures the Inspector. Negative/above-one values and the visible result are tested.

Order and naming

Keep shader_type/render_mode first, then includes/constants, related uniform groups, varyings/structs, helpers before their callers, and stage functions. Declare locals near first use and initialize them before reading.

Use descriptive snake_case names for functions, parameters and uniforms; UPPER_CASE names for constants and macros. Keep units/domain visible where needed: time_seconds, uv_offset or viewport_size. Renaming a uniform also requires updating C# setters, saved material values and other consumers: this is an API change, not formatting.

Use xy/xyz for geometric coordinates and rgb/rgba for color; avoid switching naming families without purpose. Parenthesize macro arguments and prefer a typed helper function for ordinary reusable calculations.

Layout

  • UTF-8 without BOM, LF line endings and one final newline.
  • One indentation convention per project; these examples use four spaces. Do not mix tabs and spaces within a file.
  • One statement per line, braces for control-flow bodies, spaces around binary operators.
  • Separate input groups and functions with blank lines; wrap long expressions at meaningful operators or arguments.
  • Write floating literals explicitly, such as 0.5; make integer/float intent clear during overload selection.
  • Comments explain coordinate space, ownership, a non-obvious formula or a measured constraint. Remove comments that merely repeat the next statement.

Review changes safely

Compare the diff after autoformatting. A generic C/C++ formatter may not understand shader_type, hints or preprocessing syntax. Preserve directives and continuation backslashes. Do not mix a formatting change with a different blend mode, alpha assignment, source_color hint or renamed public uniform without calling that behavior change out.

Check compilation and a representative rendered result after a semantic change. The example's clamp, discard and tint have actual GPU checks; no visual editor menu or particular formatter integration is assumed by this guide.

Reckfell Engine documentationBack to top ↑
QUICK LINKSGetting startedEntity hierarchyC# & .NET 10Scenes and prefabs
Reckfell guides and full API K
reckfellENGINE
RECKFELL ACCOUNT

Sign in

Sign in to your Reckfell account.

One account for the entire Reckfell platform.