So, I'm making the painful move from my beloved XNA to OpenTK, and I'm stuck:
Since I've got a LOT of existing shaders written in HLSL, NVidia's CG compiler seems like a natural way to minimize the impact on my existing code.
I'm confused, however, about how to compile shaders that use techniques and passes rather than separate vertex and fragment shader programs. The cgc compiler seems to require that one specify an entry point for a shader. However, it's unclear what this means in terms of a shader that has multiple potential entry points without a main() function. For instance, the simple CG effect (an off-the-shelf CG effect created in the ever-flakey FX Composer):
/*
% Description of my shader.
% Second line of description for my shader.
keywords: material classic
date: YYMMDD
*/
float4x4 WorldViewProj : WorldViewProjection;
float4 mainVS(float3 pos : POSITION) : POSITION{
return mul(WorldViewProj, float4(pos.xyz, 1.0));
}
float4 mainPS() : COLOR {
return float4(1.0, 0.0, 1.0, 1.0);
}
technique technique0 {
pass p0 {
CullFaceEnable = true;
VertexProgram = compile vp30 mainVS();
FragmentProgram = compile f340 mainPS();
}
}
The only way I can get this to compile with the cgc command line compiler is:
cgc -noentry test.cgfx
And,of course, I get no output other than a statement that the program was compiled without errors.
The NVidia docs say that the CG compiler can output GLSL if the appropriate profile is passed to the compiler. However, all of the profiles I've seen are either vertex- or pixel/fragment-specific, which seems to contradict the idea of having both in a single file, linked by the technique and pass definitions.
What am I missing here?
Note that I've been able to build this effect using the Cg runtime via the Tao.Cg stuff, but using that appears to require including the Cg runtime in my app distribution, and I can't see a way to make that work on OSX and Linux.
Update
I've noticed that by specifying the vertex shader or pixel shader directly as an entry point, and including a -profile glslf' or
-profile glslv`, that I can get GLSL output for either shader, but this obviously doesn't include setting the state or take into account multiple passes or multiple techniques. Do I really have to run the compiler once for each function defined in the shader source?