This may seem silly, but I can’t figure out how to use a custom shader. The documentation seems to be sorely lacking information, or flat out wrong. I have been working to have a simple custom shader that outputs the solid color red for five days now, without any luck.
Here are the steps I took:
1) In GameStudio, select Add asset --> Materials --> Material (empty)
You can’t write any custom shader code. You can only manpulate the material settings which magically auto-generate a shader.
2) Following this page
http://doc.xenko.com/1.10/manual/graphics/effects-and-shaders/shading-language/automatic-shader-stage-input-output.html
In VisualStudio, I created a super simple .xksl file with this code:
class Color : ShaderBase
{
stream float4 pos : POSITION;
stream float4 col : COLOR;
override void VSMain()
{
streams.ShadingPosition = streams.pos;
}
override void PSMain()
{
streams.ColorTarget = float4(1, 0, 0, 1);
}
};
This successfully “compiled” and created the corresponding .cs file and the “Effect Shader” asset appears in the Asset view of GameStudio. But I have no idea how I can apply it to a mesh or generate a Material from it. There seems to be no options inside GameStudio for the asset and I can’t find anything in the API to apply a shader to a mesh. So, I figured I had to create an Effect to use the custom shader.
3) Following this page
http://doc.xenko.com/1.10/manual/graphics/effects-and-shaders/effect-language.html
In VisualStudio, I created an .xkfx file with the contents of BasicEffect. However, the .cs file generated by Xenko is invalid as it references the namespace SiliconStudio.Xenko.Effects.Data which doesn’t exist. I had to manually edit the auto-generated code to get it to compile (which is explictly says NOT to do).
4) Following this page
http://doc.xenko.com/1.10/manual/graphics/effects-and-shaders/index.html
I created a C# script and when I tried to load the effect by calling
var myEffect = EffectSystem.LoadEffect("BasicEffect").WaitForResult();
I got an AggregateException.
Confusingly, when I tried loading my .xksl file (Color.xksl), it worked.
var myEffect = EffectSystem.LoadEffect("Color").WaitForResult();
But the documentation then says I need to bind it to the pipeline and points to this page
http://doc.xenko.com/1.10/manual/graphics/low-level-api/pipeline-state.html
The very first code example says to do this to create the pipeline state
var pipelineStateDescription = new PipelineStateDescription();
var pipelineState = PipelineState.New(GraphicsDevice, ref pipelineStateDescription);
But this causes a SharpDX exception to be thrown.
Is there no way to write your own shader from scratch in Xenko?