Custom shaders documentation

Hi,

Is there any documentation for writing custom shaders and using them on models?

Also is possible to write Tesselation and Compute shaders or engine itself just supports Vertex,Geometry, Pixel shaders?

Thank you,

Martin Pernica

Hello Martin!

Here is the documentation I found for writing a custom shader: http://docs.aws.amazon.com/lumberyard/latest/userguide/mat-shaders-custom-dev-intro.html

Let us know if that has enough information for you. The shader system is complex in what it does and so it is possible that we may have missed a few things in the documentation.

For PC and Console Lumberyard supports compute and tessellation shaders. On mobile Lumberyard only supports vertex and pixel shaders.

Hi, thank you. I will look into those resources.

Is there actually more to it to make a custom shader appear in material editor than the steps described in the doc link? I made an empty named ShaderTest1.ext file and a named ShaderTest1.cfx file with minimal code and added the line to ShaderList.xml:

Is there a log that would show shader compilation errors that would keep the shader from showing up in the material editor?

Any insight would be much appreciated

EDIT: The shader is selectable from inside of a material under /material settings/shader , i wrongly assumed an accordingly named material would be created. I had to create that material myself in /engineassets folder.

Now i gotta get the shader to work correctly which it seems not to so far.


#include "Common.cfi"
#include "ShadeLib.cfi"
// Shader global descriptions
float Script : STANDARDSGLOBAL
<
string Script =
"NoPreview;"
"LocalConstants;"
"ShaderDrawType = Custom;"
"ShaderType = PostProcess;"
>;
struct pixout_test
{
half4 Color : COLOR0;
};
struct vert2frag
{
float4 HPosition : POSITION;
};
#define IN_P float4 Position : POSITION;
#define IN_C0 float4 Color : COLOR;
#define IN_TBASE float2 baseTC : TEXCOORD0;
struct app2vertCloud
{
IN_P
IN_TBASE
IN_C0
};
vert2frag ShaderTest1VS(app2vertCloud IN)
{
vert2frag OUT = (vert2frag)0; // Position in screen space.
float4 vPos = IN.Position;
OUT.Position = _pos_Common(vPos);
OUT.Position.z = OUT.Position.w;
return OUT;
}
pixout_test ShaderTest1PS(vert2frag IN)
{
pixout_test OUT;
OUT.Color.x = 0;
OUT.Color.x = 0;
OUT.Color.z = 255;
OUT.Color.a = 0.4;
return OUT;
}
//========================================================================
technique ShaderTest1
{
pass p0
{
VertexShader = ShaderTest1VS();
ZEnable = true;
ZWriteEnable = true;
CullMode = None;
PixelShader = ShaderTest1PS();
}
}
/////////////////////// eof ///

Nothing jumps out as being wrong in your shader at first glance. In the editor’s console window it should show you that it is compiling the shader and if there are errors in that process print out the errors there.

If there are no errors there but you do see your shader being compiled then you could try using the remote shader compiler on the PC and see if that prints out any warning/error messages when it compiles the shader. To enable the remote shader compiler you will have to edit the system_windows_pc.cfg file and set the r_ShadersRemoteCompiler value to 1. I recommend setting r_ShaderAsyncCompiling to 0 so that shaders will be compiled on at a time and you will be able to see clearly any errors from your shader. Once you have modified the config file open a command window and start the remote shader compiler CrySCompileServer_vc140x64.exe located in dev/Tools/CrySCompileServer\x64\profile. Then start up the editor and see what happens. :slight_smile:

It make take some time to load the editor as the shader compiling will be a little slower. In the command window you should see output for each shader that is being compiled including any errors.

Let us know if that helps or not.

Thanks,
Chris

Hi, @Apard,

I ran your shader and was getting errors. I noticed your STANDARDSGLOBAL is set up as a PostProcess which is a special case. If you wanted a general shader that you could say, apply to a mesh entity component in the world, I was able to get your shader working by changing the STANDARDSGLOBAL to something like…

    float Script: STANDARDSGLOBAL < "ShaderType = General;" >;

Here’s a full .CFX example that might help get the ball rolling…


#include "Common.cfi"
#include "ShadeLib.cfi"
#include "VertexLib.cfi"
// Shader global descriptions
float Script: STANDARDSGLOBAL
<
string Script =
"ShaderType = General;"
>;
//////////////////////////////////////////////////////////////////////
struct app2vertSimpleCustom
{
float4 Position : POSITION;
};
struct vert2FragSimpleCustom
{
float4 Position : POSITION;
};
//////////////////////////////////////////////////////////////////////
vert2FragSimpleCustom SimpleVS(app2vertSimpleCustom IN)
{
vert2FragSimpleCustom OUT = (vert2FragSimpleCustom)0;
OUT.Position = _pos_Common(IN.Position);
return OUT;
}
//////////////////////////////////////////////////////////////////////
pixout SimplePS(vert2FragSimpleCustom IN, float4 pixelCoord : POSITION)
{
pixout OUT = (pixout)0;
OUT.Color = half4(0, 0, 1, 0.4);
return OUT;
}
//////////////////////////////////////////////////////////////////////
technique General
{
pass p0
{
VertexShader = SimpleVS() GeneralVS;
PixelShader = SimplePS() GeneralPS;
ZEnable = true;
ZWriteEnable = true;
CullMode = Back;
AlphaBlendEnable = true;
SrcBlend = SRC_ALPHA;
DestBlend = ONE_MINUS_SRC_ALPHA;
}
}

Hope this helps!