• Hello [name]! Thanks for joining the GMC. Before making any posts in the Tech Support forum, can we suggest you read the forum rules? These are simple guidelines that we ask you to follow so that you can get the best help possible for your issue.

Question - Code HLSL 11 Shaders - Anybody got them working yet?

Hi everybody!
You might know by now that I really like to play around in 3D with GameMaker, and by extension I end up using shaders a lot
However, I'm having some problems adjusting to HLSL 11 - as far as I'm aware, HLSL 9 shaders should no longer work, and need updating.
I have a pretty solid understanding of HLSL 9 shaders, but I can't seem to figure out how to port them to HLSL 11
I always get these two errors - the first appears at compile time:
Code:
Invalid shader (is it marked as incompatible type for this target?) "shader_0":
The second appears at runtime when the shader is set:
Code:
ERROR!!! :: ############################################################################################
FATAL ERROR in Vertex Shader compilation
ShaderName: shader_0

Invalid shader

 at gml_Object_test_Draw_0 (line 4) - shader_set(shader_0);
############################################################################################
Unfortunately, "Invalid Shader" is far from a helpful error message. Sometimes it tells me the error is in Fragment Compilation, so I'm really having a hard time finding the source of the problem

So, here's a HLSL 9 passthrough shader which works perfectly in 1.X:
Vertex
Code:
struct VS_INPUT
{
    float4 vPos   : POSITION;
    //float4 vNormal : NORMAL;
    float4 vColor : COLOR;
    float2 vTexCoord : TEXCOORD0;
 
};

struct PS_INPUT
{
    float4 Position : POSITION;  // interpolated vertex position (system value)
    float4 Color    : COLOR;       // interpolated diffuse color
    float2 TexCoord : TEXCOORD0;
};

PS_INPUT main(VS_INPUT input) // main is the default function name
{
    PS_INPUT Output;


    // Transform the position from object space to homogeneous projection space
    Output.Position = mul(gm_Matrices[MATRIX_WORLD_VIEW_PROJECTION], input.vPos);

    // Just pass through the color data
    Output.Color = input.vColor;
    Output.TexCoord = input.vTexCoord;
 
    return Output;
}
Frag
Code:
struct PS_INPUT
{
    float4 Color    : COLOR;
    float2 TexCoord : TEXCOORD0;
};

struct PS_OUTPUT {
    float4 Color : COLOR;
};


PS_OUTPUT main(PS_INPUT In)
{
    PS_OUTPUT Output;

    Output.Color = In.Color * tex2D(gm_BaseTexture, In.TexCoord);//In.Color;

    return Output;
}

And here's my attempt at updating it to HLSL 11 to use with GMS2:
Vertex
Code:
struct VS_INPUT
{
    float4 vPos   : POSITION;
    //float4 vNormal : NORMAL;
    float4 vColor : COLOR;
    float2 vTexCoord : TEXCOORD0;
 
};

struct PS_INPUT
{
    float4 Position : SV_POSITION;  // interpolated vertex position (system value)
    float4 Color    : COLOR;       // interpolated diffuse color
    float2 TexCoord : TEXCOORD0;
};

PS_INPUT main(VS_INPUT input) // main is the default function name
{
    PS_INPUT Output;


    // Transform the position from object space to homogeneous projection space
    Output.Position = mul(gm_Matrices[MATRIX_WORLD_VIEW_PROJECTION], input.vPos);

    // Just pass through the color data
    Output.Color = input.vColor;
    Output.TexCoord = input.vTexCoord;
 
    return Output;
}
Fragment
Code:
struct PS_INPUT
{
    float4 Color    : COLOR;
    float2 TexCoord : TEXCOORD0;
};

struct PS_OUTPUT {
    float4 Color : SV_TARGET;
};


PS_OUTPUT main(PS_INPUT In)
{
    PS_OUTPUT Output;

    Output.Color = In.Color * tex2D(gm_BaseTexture, In.TexCoord);//In.Color;

    return Output;
}

As far as I can tell from googling, I should just need to update SV_Position and SV_Target, but that doesn't seem to be working - am I doing something totally wrong?
My graphics card uses DirectX 11 (dxdiag confirms this), so I don't think that could be an issue.
I am on Windows 7, which wasn't originally listed as supported in 1.X, could that be the problem? Is this going to be the thing that forces me to update to Windows 10?

My GLSL ES shaders still seem to work fine, but I still can't figure out what I need to name blendweights and indices within the shader (in_BlendWeights, in_Blendweights, in_BlendWeight and in_Blendweight don'y work, neither do respective indices tests - always get a "Could not generate input layout (is there a mismatch between your shader and vertex format?)" error on compile and "Draw failed due to invalid input layout" on draw).
Would be real nice if we got a documentation page telling us what attribute names an ES shader needs to use for each format usage type ;)

Anway, back to the point at hand - is anybody able to explain where I'm going wrong and point me in the right direction? It'd be really appreaciated
 
Last edited:

xygthop3

Member
I can't get them working either, even tho I have a valid HLSL 11 shader that works in other software GMS2 just treats it as an "Invalid Shader". It would be great if a Yoyo Dev was able to show us a pass-through shader example that works with GMS2, then we can do the rest from there :)

*Juju ninja
 

rwkay

YoYo Games Staff
YYG Staff
OK it looks like the current runtime has some issues with HLSL11 shaders, apologies for this as it had not been a testing focus for us - we will fix internally and then decide if we will just wait for the next release or do a runtime release between now and then to fix this.

Russell
 
OK it looks like the current runtime has some issues with HLSL11 shaders, apologies for this as it had not been a testing focus for us - we will fix internally and then decide if we will just wait for the next release or do a runtime release between now and then to fix this.

Russell
Fabulous, thank you!
 

rwkay

YoYo Games Staff
YYG Staff
OK here is a pass through shader and we have fixed things internally but you will not be able to use this when it comes out, but it should work on 1.x on the DX11 targets, namely Win8 and WinPhone, unfortunately while getting this working we realised that 1.x UWP has the same shader issues, but we are fixing that now.

Vertex shader:
Code:
//
// Simple passthrough vertex shader
//
struct VertexShaderInput
{
                float3 pos : POSITION;
                float4 color : COLOR0;
                float2 uv : TEXCOORD0;
};


struct VertexShaderOutput
{
                float4 pos : SV_POSITION;
                float4 color : COLOR0;
                float2 uv : TEXCOORD0;
};


VertexShaderOutput main(VertexShaderInput input)
{

                VertexShaderOutput output;
                float4 pos = float4(input.pos, 1.0f);

                // Transform the vertex position into projected space.
                pos = mul(gm_Matrices[MATRIX_WORLD_VIEW_PROJECTION], pos);
                output.pos = pos;

                // Pass through the color
                output.color = input.color;

                // Pass through uv
                output.uv = input.uv;   

                return output;
}


Pixel shader:

Code:
//
// Simple passthrough fragment shader
//

struct PixelShaderInput
{
                float4 pos : SV_POSITION;
                float4 color : COLOR0;
                float2 uv : TEXCOORD0;
};


float4 main(PixelShaderInput input) : SV_TARGET
{
                float4 vertColour = input.color;
                float4 texelColour = gm_BaseTextureObject.Sample(gm_BaseTexture, input.uv);
                float4 combinedColour = vertColour * texelColour;

                return combinedColour;
}
Russell
 
F

freekshow_kc

Guest
If you have found a bug with GLSL ES shaders then please file it http://www.yoyogames.com/bug2 and we will take a look (remember to attach an example project)

GLSL ES shaders should work the same as 1.x

Russell
thanks for the answer, i will upload a sample project once i get home today ... thats a really handy link to keep for the future :D
with regards kc
 
F

freekshow_kc

Guest
Try a simple "pass through" shader, see if that works, if it does then force the output colour to vec4(1.0,1.0,1.0,1.0) to make sure it's going through it.

I've not had any issues with running as GLSL ES shader. Also remember to check to see if it compiled properly. (http://docs2.yoyogames.com/index.html?page=source/_build/3_scripting/4_gml_reference/shaders/shader_is_compiled.html )
I will try this and also the example Passthrough Shader from GM 1.X (the one from xot , i think its just some community made thing)
Basically my shader does the same just with 4 colors at once.I also need to add the is_compiled check ...

okay i filled a bug report...

this is a similar shader than the one i use : http://gmc.yoyogames.com/index.php?showtopic=589348

Single Color replacement works,
but multi color replacement doesnt !

Check the Example for weird behaviour on multi shading...

maybe its related with arrays...

with regards
 
Last edited by a moderator:
  • Like
Reactions: xot

xot

GMLscripter
GMC Elder
It would not surprise me if there was something strange going on with arrays. I recall arrays being a little screwy when I wrote that shader.

I cannot yet afford to purchase GMS2, so I'm unable to test this shader. Sorry.
 
F

freekshow_kc

Guest
Any update on this issue?
i filled in a bug report weeks ago but cant see it on the bug feed ( http://www.yoyogames.com/bug2 )
is it being adressed at all?
this bug forces me to use GM 1.X while i would love to start deploying with GM 2

I assume since glsl el shader handling is supposed to be exact the same, and GM2 messes up with arrays, thats nothing the community has to fix, or am i wrong? ;)

edit: Its now an official bug and will be fixed in some upcoming release :) Nothing to do from our side except waiting i guess ;)
 
Last edited by a moderator:

xygthop3

Member
This has now been fixed in version 2.0.3.56
Here the shader code I use:

Vertex Shader
Code:
//
// Simple passthrough vertex shader (HLSL 11)
//

struct VertexShaderInput {
    float4 vPosition : POSITION;
    float4 vColor    : COLOR0;
    float2 vTexcoord : TEXCOORD0;
};


struct VertexShaderOutput {
    float4 vPosition : SV_POSITION;
    float4 vColor    : COLOR0;
    float2 vTexcoord : TEXCOORD0;
};

VertexShaderOutput main(VertexShaderInput INPUT) {
    VertexShaderOutput OUTPUT;

    float4 matrixWVP = mul(gm_Matrices[MATRIX_WORLD_VIEW_PROJECTION], INPUT.vPosition);

    OUTPUT.vPosition = matrixWVP;
    OUTPUT.vColor    = INPUT.vColor;
    OUTPUT.vTexcoord = INPUT.vTexcoord; 

    return OUTPUT;
}
Pixel Shader
Code:
//
// Simple passthrough pixel shader (HLSL 11)
//

struct PixelShaderInput {
    float4 vPosition : SV_POSITION;
    float4 vColor    : COLOR0;
    float2 vTexcoord : TEXCOORD0;
};


float4 main(PixelShaderInput INPUT) : SV_TARGET {
    float4 diffuseTexture = gm_BaseTextureObject.Sample(gm_BaseTexture, INPUT.vTexcoord);
  
    return INPUT.vColor * diffuseTexture;
}
 
Awesome! I managed to port my skinning shader across to HLSL 11 now! (it also seems that a crash with "big" vertex buffer submitting was fixed too!)
 
Top