Rest In Clean

Context & Concept

Rest In Clean is a technical prototype developed in Unity inspired by the satisfying cleaning game PowerWash Simulator but set in a graveyard. The player steps into the boots of a graveyard caretaker tasked with restoring weathered tombstones, stone altars, and brick monuments to their original condition.

Rather than relying on pre-baked states or simple alpha fading, the prototype was built to explore real-time dynamic texture painting, multi-UV coordinate mapping, and runtime material manipulation using custom HLSL shaders.

Core Mechanics

  • Interactive Surface Washing: Direct, satisfying water-jet cleaning mechanic that progressively removes layers of grime and dirt from 3D cemetery props.
  • First-Person Controller: Responsive movement and camera control built on Unity’s CharacterController and modern Input System, featuring gamepad/mouse auto-detection and custom sensitivity scaling.
  • Particle & Visual Synchronization: Continuous particle spray effects aligned with viewport raycasts and real-time audio-visual feedback when hitting cleanable surfaces.

Technical Implementation

Dual-UV Custom HLSL Surface Shader

To cleanly separate tiling surface details from unique dirt accumulation, the shader uses dual UV sets within Unity’s Universal Render Pipeline (URP):

  • Base Geometry (TEXCOORD0): Samples the high-resolution tiling albedo texture (_BaseMap) of the stone and brick materials.
  • Grime & Mask Channel (TEXCOORD1): Samples the dirt overlay (_DirtMap) and the dynamic runtime mask (_MaskMap) using the non-overlapping secondary UV unwrap (lightmap channel). This prevents pattern repetition and seam artifacts during cleaning.
  • Fragment Blending: The fragment stage blends base color and dirt via a linear interpolation driven by the mask’s red channel:
    half4 color = SAMPLE_TEXTURE2D(_BaseMap, sampler_BaseMap, IN.uv);
    half4 dirt  = SAMPLE_TEXTURE2D(_DirtMap, sampler_DirtMap, IN.lightmap);
    half4 mask  = SAMPLE_TEXTURE2D(_MaskMap, sampler_MaskMap, IN.lightmap);
    
    return lerp(color, dirt, mask.r);

Raycast to UV2 Projection

When spraying, the washer casts a ray from the camera’s viewport center into the physics scene:

  • Queries the hit triangle on the mesh collider to extract hit.textureCoord2 (the secondary UV coordinate set).
  • Passes the normalized UV point directly to the target CleanableObject, ensuring pixel-accurate cleaning regardless of object rotation, position, or scale.

Dynamic Runtime Masking

  • Memory-Efficient Mask: Generates a runtime Texture2D formatted in TextureFormat.R8 (single 8-bit channel) with bilinear filtering and clamped edges, minimizing memory footprint.
  • Progressive Attenuation: Calculates a radial pixel bounding box around the hit UV point and subtracts dirt intensity based on tool strength (cleanStrength), allowing fine, gradual cleaning rather than binary on/off states.
  • Material Instancing: Clones and binds the material instance at runtime so individual props maintain independent cleaning states.

Architecture & Roadmap

While the CPU-side prototype validates the gameplay and shader logic, several architectural evolutions are planned:

  • GPU-Accelerated Mask Painting: Moving mask texture updates from CPU pixel buffers (SetPixels32) to a dedicated Compute Shader, completely eliminating CPU-GPU data transfer overhead.
  • Parallel Compute Shader for Progress Metrics: Calculating real-time cleaning percentages across surface texels via parallel reduction on the GPU.
  • Multi-Layer Weathering: Expanding the shader to support multi-layer splat maps (e.g., blending moss, dampness, and dried grime with distinct physical removal thresholds).