Menu

Dev - Create effect

Jeroen Broekhuizen

While adding new types of content to the engine, it is also possible to add new effects. Effects in this context are the hardware shaders used while rendering the content. They live in the fx files.

Currently the effect is still limited to a single vertex- and pixel shader per technique! It is not possible to embed additional methods that are called from a shader. This feature will be added in a later stage.

Structures

You can use the struct to specify input and output of shaders.

struct VertexData
{
    float2 pos;
    float4 tex;
};

Constant Buffers

Constant buffers are used to pass data to the shaders.

cbuffer MVP
{
    float4x4 projection;
    float4x4 view;
    float4x4 model;
};

This buffer passes three matrices

Techniques

technique Basic
{
    vertex = vs_4_0_level_9_3 mainVertex
    pixel  = ps_4_0_level_9_3 mainPixel
}

Shader language

Crafter 2D currently supports HLSL of DirectX and GLSL of OpenGL. Per effect you target one of these languages. You can use the language attribute to tell the compiler what the targeted language is. If this attribute is omitted, the compiler will try to detect the language based on some key type names of GLSL.

GLSL specifics

The implementation of the GLSL shader is slightly different from the standard. In this part the differences will be discussed.

The output of the pixel shader is currently hardcoded as out vec4 frag.

Instead of uniforms, you should use the struct and cbuffer keywords to specify the uniform blocks. The compiler will generate the correct GLSL code. There is also no need to specify a variable name for the uniform. The name of the struct/cbuffer is used and a new hbhg hh

The vertex input data struct is determined by the names of the entries. They should not be supplied as argument of the methods.


Related

Wiki: Dev - Create games

MongoDB Logo MongoDB