Skip to content

Rainfall environment#

Back to shader guides.

Rainfall injects custom HLSL into generated GameCube TEV shaders at runtime. This section covers symbols you see most in fragment mods (prev, input.position, u_time). Vertex mods use model-space locals and state uniforms, see Custom shader mods.

Environment uniforms#

The shader code has access to variables defined in the FSUniforms cbuffer:

u_time (float)#

  • Meaning: seconds since the game started.
  • Purpose: drive animations, waves, and oscillations.
    // One full pulse cycle every 1.0s
    float pulse = sin(u_time * 6.283185f); // 2 * pi * u_time
    

_timePad.x (float)#

  • Meaning: 1.0 / renderWidth
  • Purpose: turn pixel x into a 0–1 UV coordinate.

_timePad.y (float)#

  • Meaning: 1.0 / renderHeight
  • Purpose: turn pixel y into a 0–1 UV coordinate.
    float2 uv = input.position.xy * float2(_timePad.x, _timePad.y);
    

Global fragment registers#

  • prev (float4)
    • Meaning: pixel color from the normal render pipeline before your mod runs (RGBA).
    • Use: tint, grade, or post-process the final color.
      prev.rgb *= float3(0.9f, 1.1f, 0.9f);
      

Screen variables#

  • input.position.xy (float2)
    • Meaning: pixel coordinates from (0, 0) at the top-left to (width, height).
    • Use: screen-space grids, scanlines, and similar effects.
      if (int(input.position.x) % 3 == 0) {
          prev.rgb *= 0.8f;
      }
      
  • input.position.z (float)
    • Meaning: non-linear depth in [0.0, 1.0].
    • Use: avoid this for distance-based effects, and prefer input.position.w for linear depth.
  • input.position.w (float)
    • Meaning: 1.0 / w_clip (reciprocal clip-space depth).
    • Linear depth: camera distance in world units:
      float eyeDepth = 1.0f / input.position.w;
      
    • 2D / HUD guard: HUD, text, and ortho draws use w_clip = 1.0, so they read as input.position.w == 1.0f:
      bool is3D = input.position.w != 1.0f;
      if (is3D) {
          // Apply 3D shader mod here
      }