stride/samples/Graphics/CustomEffect/CustomEffect.Game/Effects/Effect.sdsl
2021-04-19 12:49:55 +09:00

38 lines
1.4 KiB
Text

// Copyright (c) .NET Foundation and Contributors (https://dotnetfoundation.org/ & https://stride3d.net) and Silicon Studio Corp. (https://www.siliconstudio.co.jp)
// Distributed under the MIT license. See the LICENSE.md file in the project root for more information.
shader Effect : SpriteBase
{
stage float2 Center;
stage float Frequency;
stage float Phase;
stage float Spread;
stage float Amplitude;
stage float InvAspectRatio;
stage override float4 Shading()
{
float2 wave;
float2 toPixel = (streams.TexCoord.xy - Center) * float2(1, InvAspectRatio);
float distance = length(toPixel);
float2 direction = normalize(toPixel);
sincos(Frequency * distance + Phase, wave.x, wave.y);
// Clamps the distance between 0 and 1 and squares the value.
float falloff = saturate(1 - distance);
falloff = pow(falloff, 1.0f / Spread);
// Calculates new mapping coordinates based on the frequency, center, and amplitude.
float2 uv2 = streams.TexCoord.xy + (wave.x * falloff * Amplitude) * direction;
float lighting = lerp(1.0f, 1.0f + wave.x * falloff * 0.2f, saturate(Amplitude / 0.015f));
// Resamples the image based on the new coordinates.
float4 color = Texture0.Sample(Sampler, uv2);
color.rgb *= lighting;
return color;
}
};