Skip to content

Commit

Permalink
Switch hello world WinRT shader to primary constructor
Browse files Browse the repository at this point in the history
  • Loading branch information
Sergio0694 committed Nov 21, 2023
1 parent 7cff6f2 commit 49fe56f
Showing 1 changed file with 8 additions and 17 deletions.
25 changes: 8 additions & 17 deletions samples/ComputeSharp.NativeLibrary.WinRT/HelloWorldEffect.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ public sealed partial class HelloWorldEffect : CanvasEffect
/// </summary>
private static readonly EffectNode<PixelShaderEffect<Shader>> EffectNode = new();

/// <inheritdoc cref="Shader.time"/>
/// <summary><inheritdoc cref="Shader(float, Int2)" path="/param[@name='time']/node()"/></summary>
private float time;

/// <inheritdoc cref="Shader.dispatchSize"/>
/// <summary><inheritdoc cref="Shader(float, Int2)" path="/param[@name='dispatchSize']/node()"/></summary>
private Rect dispatchArea;

/// <summary>
Expand Down Expand Up @@ -55,8 +55,10 @@ protected override void ConfigureEffectGraph(EffectGraph effectGraph)
}

/// <summary>
/// The D2D1 shader for <see cref="HelloWorldEffect"/>.
/// A hello world effect that displays a color gradient.
/// </summary>
/// <param name="time">The current time since the start of the application.</param>
/// <param name="dispatchSize">The dispatch size for the current output.</param>
[D2DEffectDisplayName(nameof(HelloWorldEffect))]
[D2DEffectDescription("A hello world effect that displays a color gradient.")]
[D2DEffectCategory("Render")]
Expand All @@ -65,25 +67,14 @@ protected override void ConfigureEffectGraph(EffectGraph effectGraph)
[D2DRequiresScenePosition]
[D2DShaderProfile(D2D1ShaderProfile.PixelShader50)]
[D2DGeneratedPixelShaderDescriptor]
[AutoConstructor]
internal readonly partial struct Shader : ID2D1PixelShader
internal readonly partial struct Shader(float time, int2 dispatchSize) : ID2D1PixelShader
{
/// <summary>
/// The current time since the start of the application.
/// </summary>
private readonly float time;

/// <summary>
/// The dispatch size for the current output.
/// </summary>
private readonly int2 dispatchSize;

/// <inheritdoc/>
public float4 Execute()
{
int2 xy = (int2)D2D.GetScenePosition().XY;
float2 uv = xy / (float2)this.dispatchSize;
float3 color = 0.5f + (0.5f * Hlsl.Cos(this.time + new float3(uv, uv.X) + new float3(0, 2, 4)));
float2 uv = xy / (float2)dispatchSize;
float3 color = 0.5f + (0.5f * Hlsl.Cos(time + new float3(uv, uv.X) + new float3(0, 2, 4)));

return new(color, 1f);
}
Expand Down

0 comments on commit 49fe56f

Please sign in to comment.