Reputation: 1641
I created a shader that seems to work nicely in the VS2012 shader designer. It saves it in DGSL format, which I then exported to HLSL.
I thought I'd be able to use this in an XNA project, but there are two things that are very new to me and I'm hoping someone can point me in the right direction:
1) Every shader I've seen so far had a section like this
technique RibbonShader
{
pass Pass0
{
VertexShader = compile vs_2_0 VertexShader();
PixelShader = compile ps_2_0 PixelShader();
}
}
Unfortunately the HLSL generated by the VS2012 export feature has only a main function, like so:
P2F main(V2P pixel)
{
// lots of stuff
return result;
}
Can someone gently explain what I need to do to get my shader (the one with the 'main' function) that works so well in the designer to be in a format that has the technique/pass format like above?
Upvotes: 3
Views: 668
Reputation: 13532
technique RibbonShader
{
pass Pass0
{
VertexShader = compile vs_2_0 VertexShader();
PixelShader = compile ps_2_0 PixelShader();
}
}
Is the format used for shaders using the effects framework. The shader Visual Studio generates is just a vertex or pixel shader that has a single main function.
To turn it into a effect file you would have to add the technique part and use the effects framework. Something like
V2P mainVS(...)
{
// vertex shader
}
P2F mainPS(V2P pixel)
{
// lots of stuff
return result;
}
technique YourTechniqueName // can be anything you choose.
{
pass Pass0
{
VertexShader = compile vs_2_0 mainVS();
PixelShader = compile ps_2_0 mainPS();
}
// can have other passes
}
If you don't use the effects framework, you can still use the separate vertex/pixel shader files with just one main inside and let Visual Studio compile them into binary shader files and then you can load them in your application.
In Visual Studio 2012 this is done automatically when you add shader files to your project. Also when you right click and go to the properties of a shader files you can change if it is a *.fx(effects file) or vertex/pixel shader along with its shader model version.
Hope that helps.
Upvotes: 2