Repository: playcanvas/engine
File: scripts/esm/gsplat/reveal-radial.mjs (JavaScript)

Code before:
float g_dist;
float g_dotWavePos;
float g_liftTime;
float g_liftWavePos;

void initShared(vec3 center) {
    g_dist = length(center - uCenter);
    g_dotWavePos = uSpeed * uTime + 0.5 * uAcceleration * uTime * uTime;
    g_liftTime = max(0.0, uTime - uDelay);
    g_liftWavePos = uSpeed * g_liftTime + 0.5 * uAcceleration * g_liftTime * g_liftTime;
}

// Hash function for per-splat randomization
float hash(vec3 p) {
    return fract(sin(dot(p, vec3(127.1, 311.7, 74.7))) * 43758.5453);
}

void modifySplatCenter(inout vec3 center) {
    initShared(center);
    
    // Early exit optimization
    if (g_dist > uEndRadius) return;
    
    // Only apply oscillation if lift wave hasn't fully passed
    bool wavesActive = g_liftTime <= 0.0 || g_dist > g_liftWavePos - 1.5;
    if (wavesActive) {
        // Apply oscillation with per-splat phase offset
        float phase = hash(center) * 6.28318;
        center.y += sin(uTime * 3.0 + phase) * uOscillationIntensity * 0.25;
    }
    
    // Apply lift effect near the wave edge
    float distToLiftWave = abs(g_dist - g_liftWavePos);
    if (distToLiftWave < 1.0 && g_liftTime > 0.0) {
        // Create a smooth lift curve (peaks at wave edge)
        // Lift is 0.9x the oscillation intensity (30% of original 3x)
        float liftAmount = (1.0 - distToLiftWave) * sin(distToLiftWave * 3.14159);
        center.y += liftAmount * uOscillationIntensity * 0.9;
    }
}

void modifySplatRotationScale(vec3 originalCenter, vec3 modifiedCenter, inout vec4 rotation, inout vec3 scale) {
    // Early exit for distant splats - hide them
    if (g_dist > uEndRadius) {
        scale = vec3(0.0);
        return;
    }
    
    // Store original scale for shape preservation
    vec3 origScale = scale;
    float origSize = gsplatGetSizeFromScale(scale);

Review comment (suggestion):
That's just a `scalar * scalar `and can be probably shortened by simply `scalar` value that the uniform holds. Save a bit of ALU.

Code after:
// Shared globals (initialized once per vertex)
float g_dist;
float g_dotWavePos;
float g_liftTime;
float g_liftWavePos;

void initShared(vec3 center) {
    g_dist = length(center - uCenter);
    g_dotWavePos = uSpeed * uTime + 0.5 * uAcceleration * uTime * uTime;
    g_liftTime = max(0.0, uTime - uDelay);
    g_liftWavePos = uSpeed * g_liftTime + 0.5 * uAcceleration * g_liftTime * g_liftTime;
}

// Hash function for per-splat randomization
float hash(vec3 p) {
    return fract(sin(dot(p, vec3(127.1, 311.7, 74.7))) * 43758.5453);
}

void modifySplatCenter(inout vec3 center) {
    initShared(center);
    
    // Early exit optimization
    if (g_dist > uEndRadius) return;
    
    // Only apply oscillation if lift wave hasn't fully passed
    bool wavesActive = g_liftTime <= 0.0 || g_dist > g_liftWavePos - 1.5 * uBandWidth;
    if (wavesActive) {
        // Apply oscillation with per-splat phase offset
        float phase = hash(center) * 6.28318;
        center.y += sin(uTime * 3.0 + phase) * uOscillationIntensity * 0.25;
    }
    
    // Apply lift effect near the wave edge
    float distToLiftWave = abs(g_dist - g_liftWavePos);
    if (distToLiftWave < 1.0 * uBandWidth && g_liftTime > 0.0) {
        // Create a smooth lift curve (peaks at wave edge)
        // Lift is 0.9x the oscillation intensity (30% of original 3x)
        float normalizedDist = distToLiftWave / uBandWidth;
        float liftAmount = (1.0 - normalizedDist) * sin(normalizedDist * 3.14159);
        center.y += liftAmount * uOscillationIntensity * 0.9;
    }
}

void modifySplatRotationScale(vec3 originalCenter, vec3 modifiedCenter, inout vec4 rotation, inout vec3 scale) {
    // Early exit for distant splats - hide them
    if (g_dist > uEndRadius) {
        scale = vec3(0.0);
        return;
    }
    
    // Store original scale for shape preservation