Reputation: 27338
I'm trying to build pixel shader in a C# class library.
I have added fx file to the project. Since I can't find any suitable build action I tried to manually edit csproj:
<FxCompile Include="MyEffect.fx">
<ShaderType>Pixel</ShaderType>
</FxCompile>
but when I try to locate the ps file, I get System.IO.IOException: Cannot locate resource 'MyEffect.ps'
here is the code that throws error:
public class MyEffect : ShaderEffect
{
public MyEffect(){
this.PixesShader = new Uri("pack://application:,,,/WpfControlLibrary1;component/MyEffect.ps");
}
}
How to setup my project so that I can locate the compiled shader?
All the tutorials I have found are for C++ projects or deals with old tools like custom build task, but I think that is not required since VS2012.
EDIT: Visual Studio does compile .fx files only in C++ projects. In C# projects it does not work. It is mentioneded here: http://blogs.msdn.com/b/chuckw/archive/2012/05/07/hlsl-fxc-and-d3dcompile.aspx
Upvotes: 4
Views: 4548
Reputation: 441
You can set a Postbuild option to compile your fx files with fxc:
fxc /O0 /Fc /Zi /T fx_5_0 /Fo myShader.fxo myShader.fx
But I compile all my shaders at runtime when developing. I'm not sure what C# library you are using but you can do this in both SharpDX and SlimDX:
ShaderBytecode.CompileFromFile(effectFile, "fx_5_0", ShaderFlags.None, EffectFlags.None);
Upvotes: 4