Skip to content

Instantly share code, notes, and snippets.

@Doprez
Created November 30, 2024 21:35
Show Gist options
  • Save Doprez/a216881a4db49e2e327258b531e706d2 to your computer and use it in GitHub Desktop.
Save Doprez/a216881a4db49e2e327258b531e706d2 to your computer and use it in GitHub Desktop.
ps3 xmb menu background shader for Stride.
shader RibbonBackgroundShader : SpriteBase
{
stage float3 Top;
stage float3 Bottom;
stage float WidthFactor;
stage float DeltaTime;
stage float Frequency;
stage float Amplitude;
stage float Speed;
stage float Intensity;
// Shading of the sprite
stage override float4 Shading()
{
float2 uv = streams.TexCoord.xy;
float3 color = float3(lerp(Top, Bottom, uv.x * uv.y * 1.1));
color = color + CalcSine(uv, Speed * 0.2f, Frequency * 0.20f, Amplitude * 0.2f, 0.0f, 0.5f, float3(0.3f, 0.3f, 0.3f), 0.1f, 15.0f,false);
color = color + CalcSine(uv, Speed * 0.4f, Frequency * 0.40f, Amplitude * 0.15f, 0.0f, 0.5f, float3(0.3f, 0.3f, 0.3f), 0.1f, 17.0f,false);
color = color + CalcSine(uv, Speed * 0.3f, Frequency * 0.60f, Amplitude * 0.15f, 0.0f, 0.5f, float3(0.3f, 0.3f, 0.3f), 0.05f, 23.0f,false);
color = color + CalcSine(uv, Speed * 0.1f, Frequency * 0.26f, Amplitude * 0.07f, 0.0f, 0.3f, float3(0.3f, 0.3f, 0.3f), 0.1f, 17.0f,true);
color = color + CalcSine(uv, Speed * 0.3f, Frequency * 0.36f, Amplitude * 0.07f, 0.0f, 0.3f, float3(0.3f, 0.3f, 0.3f), 0.1f, 17.0f,true);
color = color + CalcSine(uv, Speed * 0.5f, Frequency * 0.46f, Amplitude * 0.07f, 0.0f, 0.3f, float3(0.3f, 0.3f, 0.3f), 0.05f, 23.0f,true);
color = color + CalcSine(uv, Speed * 0.2f, Frequency * 0.58f, Amplitude * 0.05f, 0.0f, 0.3f, float3(0.3f, 0.3f, 0.3f), 0.2f, 15.0f,true);
return float4(color.x, color.y, color.z, 0.5f) * Intensity;
}
stage float3 CalcSine(float2 uv, float speed, float frequency, float amplitude, float shift, float offset, float3 color, float width, float exponent, bool dir)
{
float angle = DeltaTime * speed * frequency * -1.0f + (shift + uv.x) * 2.0f;
float y = sin(angle) * amplitude + offset;
float clampY = clamp(0.0f, y, y);
float diffY = y - uv.y;
float dsqr = distance(y, uv.y);
float scale = 1.0f;
if(dir && diffY > 0.0f)
{
dsqr = dsqr * 4.0f;
}
else if(!dir && diffY < 0.0f)
{
dsqr = dsqr * 4.0f;
}
scale = pow(smoothstep(width * WidthFactor, 0.0f, dsqr), exponent);
return min(color * scale, color);
}
};
@Doprez
Copy link
Author

Doprez commented Nov 30, 2024

This was converted from the Shader toy example https://www.shadertoy.com/view/7slcWj

@Doprez
Copy link
Author

Doprez commented May 27, 2025

Instead of passing in the Delta time through a SceneRendererBase you can call the var Global.Time that should be available in all SDSL shaders.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment