Reputation: 949
I'm doing a few shadereffects in a wpf_c# project and i don't know and i didn't find how to add the bytecode pixelshader (.ps) as Resource after be compiled by a target/exec. This is my csproj code fragment:
<ItemGroup>
<AvailableItemName Include="PixelShader"/>
</ItemGroup>
<ItemGroup>
<PixelShader Include="Shaders\BlueToneShader.fx" />
bla bla bla other shaders bla bla
</ItemGroup>
<Target Name="PixelShaderCompile" Condition="@(PixelShader)!=''" BeforeTargets="Build">
<Exec Command=""C:\Program Files (x86)\Windows Kits\10\bin\10.0.18362.0\x64\fxc.exe" %(PixelShader.Identity) /T ps_3_0 /E main /Fo%(PixelShader.RelativeDir)%(PixelShader.Filename).ps" />
</Target>
Everything goes fine and the .ps files are correctly generated, as example:
PixelShaderCompile:
"C:\Program Files (x86)\Windows Kits\10\bin\10.0.18362.0\x64\fxc.exe" Shaders\BlueToneShader.fx /T ps_3_0 /E main /FoShaders\BlueToneShader.ps
Microsoft (R) Direct3D Shader Compiler 10.1 Copyright (C) 2013 Microsoft. All rights reserved.
compilation object save succeeded; see "folder"...
But now i dont know how to add that .ps file as 'Resource' during the compilation. Any one knows how? I didn't find any clear documentation.
Upvotes: 1
Views: 509
Reputation: 949
After 3-4 hours of trial-error i found a (i think dirty) way to do it: the msbuild (.csproj) looks like:
<PropertyGroup>
<BuildDependsOn>
PixelShaderCompile
$(BuildDependsOn)
</BuildDependsOn>
</PropertyGroup>
<ItemGroup>
<AvailableItemName Include="PixelShader">
<Visible>true</Visible>
</AvailableItemName>
</ItemGroup>
<ItemGroup>
<PixelShader ... />
...
</ItemGroup>
<Target Name="PixelShaderCompile" Condition="@(PixelShader)!=''" BeforeTargets="BeforeBuild;BeforeRebuild">
<MakeDir Directories="$(IntermediateOutputPath)%(PixelShader.RelativeDir)" Condition="!Exists('$(IntermediateOutputPath)%(PixelShader.RelativeDir)')" />
//You put your fxc.exe command here
<Exec Command=""C:\bla bla bla\fxc.exe" %(PixelShader.Identity) /T ps_3_0 /E PSmain /O3 /Fo$(IntermediateOutputPath)%(PixelShader.RelativeDir)%(PixelShader.Filename).ps" Outputs="$(IntermediateOutputPath)%(PixelShader.RelativeDir)%(PixelShader.Filename).ps">
<Output ItemName="CompiledPixelShader" TaskParameter="Outputs" />
</Exec>
<ItemGroup>
<Resource Include="@(CompiledPixelShader)" />
</ItemGroup>
</Target>
//If you want to clear the .ps generated file
<Target Name="PixelShaderClean" Condition="@(PixelShader)!=''" AfterTargets="AfterBuild;AfterRebuild">
<Delete Files="$(IntermediateOutputPath)%(PixelShader.RelativeDir)%(PixelShader.Filename).ps" />
</Target>
That's it... So hard because there aren't so many made examples of msbuild files.
Upvotes: 1