Implement HelloWorldEffect for WinRT library sample
このコミットが含まれているのは:
1 親
2d368e46d0
コミット
c424f54de9
3ファイル変更
+103
-10
検索条件に一致するファイルはありません
@@ -1,7 +1,8 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<Platforms>AnyCPU;x64;ARM64</Platforms>
|
||||
<TargetFramework>net8.0-windows10.0.22621.0</TargetFramework>
|
||||
<Platforms>x64;ARM64</Platforms>
|
||||
<RuntimeIdentifiers>win-x64;win-arm64</RuntimeIdentifiers>
|
||||
</PropertyGroup>
|
||||
|
||||
<!-- NativeAOT configuration (same as in ComputeSharp.NativeLibrary, see notes there) -->
|
||||
@@ -21,6 +22,7 @@
|
||||
<ProjectReference Include="..\..\src\ComputeSharp.Core.SourceGenerators\ComputeSharp.Core.SourceGenerators.csproj" OutputItemType="Analyzer" ReferenceOutputAssembly="false" PrivateAssets="contentfiles;build" />
|
||||
<ProjectReference Include="..\..\src\ComputeSharp.Core\ComputeSharp.Core.csproj" />
|
||||
<ProjectReference Include="..\..\src\ComputeSharp.D2D1.SourceGenerators\ComputeSharp.D2D1.SourceGenerators.csproj" OutputItemType="Analyzer" ReferenceOutputAssembly="false" PrivateAssets="contentfiles;build" />
|
||||
<ProjectReference Include="..\..\src\ComputeSharp.D2D1.WinUI\ComputeSharp.D2D1.WinUI.csproj" />
|
||||
<ProjectReference Include="..\..\src\ComputeSharp.D2D1\ComputeSharp.D2D1.csproj" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
@@ -0,0 +1,91 @@
|
||||
using ComputeSharp.D2D1;
|
||||
using ComputeSharp.D2D1.WinUI;
|
||||
using Windows.Foundation;
|
||||
|
||||
namespace ComputeSharp.NativeLibrary.WinRT;
|
||||
|
||||
/// <summary>
|
||||
/// A hello world effect that displays a color gradient.
|
||||
/// </summary>
|
||||
public sealed partial class HelloWorldEffect : CanvasEffect
|
||||
{
|
||||
/// <summary>
|
||||
/// The <see cref="PixelShaderEffect{T}"/> node in use.
|
||||
/// </summary>
|
||||
private static readonly CanvasEffectNode<PixelShaderEffect<Shader>> EffectNode = new();
|
||||
|
||||
/// <inheritdoc cref="Shader.time"/>
|
||||
private float time;
|
||||
|
||||
/// <inheritdoc cref="Shader.dispatchSize"/>
|
||||
private Rect dispatchArea;
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the current time since the start of the application.
|
||||
/// </summary>
|
||||
public float Time
|
||||
{
|
||||
get => this.time;
|
||||
set => SetAndInvalidateEffectGraph(ref this.time, value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the dispatch area for the current output.
|
||||
/// </summary>
|
||||
public Rect DispatchArea
|
||||
{
|
||||
get => this.dispatchArea;
|
||||
set => SetAndInvalidateEffectGraph(ref this.dispatchArea, value);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
protected override void BuildEffectGraph(CanvasEffectGraph effectGraph)
|
||||
{
|
||||
effectGraph.RegisterOutputNode(EffectNode, new PixelShaderEffect<Shader>());
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
protected override void ConfigureEffectGraph(CanvasEffectGraph effectGraph)
|
||||
{
|
||||
effectGraph.GetNode(EffectNode).ConstantBuffer = new Shader(
|
||||
time: this.time,
|
||||
dispatchSize: new int2(
|
||||
x: (int)double.Round(this.dispatchArea.Width),
|
||||
y: (int)double.Round(this.dispatchArea.Height)));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The D2D1 shader for <see cref="HelloWorldEffect"/>.
|
||||
/// </summary>
|
||||
[D2DEffectDisplayName(nameof(HelloWorldEffect))]
|
||||
[D2DEffectDescription("A hello world effect that displays a color gradient.")]
|
||||
[D2DEffectCategory("Render")]
|
||||
[D2DEffectAuthor("ComputeSharp.D2D1")]
|
||||
[D2DInputCount(0)]
|
||||
[D2DRequiresScenePosition]
|
||||
[D2DShaderProfile(D2D1ShaderProfile.PixelShader50)]
|
||||
[D2DGeneratedPixelShaderDescriptor]
|
||||
[AutoConstructor]
|
||||
internal readonly partial struct Shader : 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)));
|
||||
|
||||
return new(color, 1f);
|
||||
}
|
||||
}
|
||||
}
|
||||
新しいイシューから参照
ユーザーをブロックする