2

Currently I am working on a C# WPF project which involves ShaderEffect.

In the tutorials online regarding the use of this class, the HLSL shader code is either built manually using fxc.exe (i.e. importing the shader object directly into the project), or compiled at runtime using DirectX wrappers like SharpDX.

I want to compile the shader code at build time as one of the build tasks handled by MSBuild, so I can both (1) easily incorporate the shader code into version control and (2) prevent the project from bloating up.

Apparently there are two ways to achieve this, although both of them are incomplete.

  1. Packaging the shader code in a separate C++ project

The shader code could be included in a separate C++ project for which MSBuild supports HLSL compilation at build time. The sample project bundled with SharpDX is built this way.

However this sounds too roundabout to me. Why do I need a C++ project for a solution that contains absolutely zero lines of C++ code?

  1. Using Microsoft.HLSL.CSharpVB

Microsoft.HLSL.CSharpVB is a (seemingly abandoned) NuGet package from Microsoft that adds build actions for HLSL files. I could confirm that the HLSL compiler is actually invoked when the build action is applied, but it does not work with WPF because WPF expects SM3.0 (or below?) and apparently I cannot change the target SM from the latest one (SM5.0 on my system) with this package.

It is barely believable that nobody else has encountered this problem before since ShaderEffect has been around for a decade now.

Are there any clever ways to achieve what I want (HLSL compilation for WPF using MSBuild)?

Thank you in advance.

  • It gets much easier if you find a working download link for 'Shazzam Shader Editor v1.4". This is a free WPF helper utility (no ads, etc.), where you write the HLSL in a WYSIWYG style and the program generates the *.fx file as well as a *cs file (implementation of ShaderEffect, which loads the shader and binds the relevant variables). Trust me, it may be out of date software but it is a wonderful playground for writing image effects. – shadow32 Aug 03 '19 at 10:56
  • @shadow32 Using a WYSIWYG shader editor does not directly address my problem, but nevertheless the software you recommended is a masterpiece and it does help me! It's sad the software has long been abandoned... Thank you for sharing the valuable info. – Shenpai Yajulight Aug 03 '19 at 12:10
  • You're welcome! Btw, have you found a way to apply multiple effects on the same Image element, without wrapping the image in several Border elements and applying the effects on them? It would have been great if the API allowed for chaining effects instead of increasing the depth of the visual tree and thus reducing performance. – shadow32 Aug 03 '19 at 12:47
  • Maybe you can get some help from [this thread](https://stackoverflow.com/a/17512424/10910450). – LoLance Aug 05 '19 at 08:58
  • Could you try Shazzam Shader Editor ? https://github.com/JohanLarsson/Shazzam – lindexi Aug 25 '20 at 00:38

0 Answers0