• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

GameMaker Custom Vertex Formats in Custom Vertex Shader

C

ChaosTheory

Guest
I am trying to set up a triangle strip with a custom vertex format in GMS 2.0. I only want position and texture coordinates. It seemed simple enough, but I keep getting:

Could not generate input layout (is there a mismatch between your shader and vertex format?)
Draw failed due to invalid input layout <repeat>

This is not rocket science, but I don't understand what the problem is. I have boiled it down to be as simple as I can, but I get the same message every time.

I have a dirt-simple custom format:

Code:
vertex_format_begin();
vertex_format_add_position_3d();

vertexFormat = vertex_format_end();

Some code that inserts a triangle strip into a vertex buffer:

Code:
vertex_position_3d(vertexBuffer, pX, pY, 0.0);  // in a loop that controls pX and pY, of course.

A dirt-stupid Draw event:

Code:
shader_set(shader);
vertex_submit(vertexBuffer, pr_trianglestrip, dummyTexture);  //  'cause we don't need no stinkin' texture.
shader_reset();

And a dirt-stupid vertex shader:

Code:
attribute vec3 inPosition;                  // (x,y, z)

varying vec3 v_vPosition;

void main()
{
   vec4 object_space_pos = vec4( inPosition.x, inPosition.y, inPosition.z, 1.0);
   gl_Position = gm_Matrices[MATRIX_WORLD_VIEW_PROJECTION] * object_space_pos;
 
   v_vPosition = inPosition;
}

I'm kind of out of ideas here. Any help will be appreciated.
 
M

madcapacity

Guest
Could it be because you are supplying a dummyTexture without having texture coordinates defined in your vertex format? I think you can just use -1 when submitting a vertex buffer with no texture attached.
 
C

ChaosTheory

Guest
Could it be because you are supplying a dummyTexture without having texture coordinates defined in your vertex format? I think you can just use -1 when submitting a vertex buffer with no texture attached.
Well, it failed in the same way when I was still passing texture coordinates as part of the custom format. I yanked the texture coordinates in an attempt to simplify things to something that would work.

I did, at one time, try passing noone for the texture; that crashed the game engine :)

And, I just now tried (-1) for the texture value; same result.
 

xygthop3

Member
I remember @Mike mentioned something like "With DX11 (GMS2.0) you must build a 'Full Fat' vertex buffer" eg; position, color, texcoords must all be in the vertex buffer and shader.
 
C

ChaosTheory

Guest
I remember @Mike mentioned something like "With DX11 (GMS2.0) you must build a 'Full Fat' vertex buffer" eg; position, color, texcoords must all be in the vertex buffer and shader.
Hmmm. YoYo's docs cite being able to remove vertex fields from the format as one good reason for having custom formats in the first place. I can certainly give it a try.
 
Last edited by a moderator:
C

ChaosTheory

Guest
Well, <expletive deleted>! That worked.

Much thanks!

I guess this means that, with DX11 on the back end, we can only add fields, not remove them.
 

zbox

Member
GMC Elder
--annoyedness reserved until i figure something out--
 
Last edited:
Got same issue but clueless to shaders / vertex's etc - currently trailing a marketplace shader but hate my output box being spammed with 'Draw failed due to invalid input layout '.

I remember @Mike mentioned something like "With DX11 (GMS2.0) you must build a 'Full Fat' vertex buffer" eg; position, color, texcoords must all be in the vertex buffer and shader.
I figure this is the solution but I don't know how to implement it with my shader:

GML:
//
// Simple passthrough vertex shader
//
attribute vec3 in_Position;                  // (x,y,z)
//attribute vec3 in_Normal;                  // (x,y,z)     unused in this shader.   
attribute vec4 in_Colour;                    // (r,g,b,a)
attribute vec2 in_TextureCoord;              // (u,v)

varying vec2 v_vTexcoord;
varying vec4 v_vColour;

void main()
{
    vec4 object_space_pos = vec4( in_Position.x, in_Position.y, in_Position.z, 1.0);
    gl_Position = gm_Matrices[MATRIX_WORLD_VIEW_PROJECTION] * object_space_pos;
    
    v_vColour = in_Colour;
    v_vTexcoord = in_TextureCoord;
}
and

GML:
varying vec2 v_vTexcoord;
varying vec4 v_vColour;
uniform float Position;

void main()
{
    vec4 Colour = texture2D( gm_BaseTexture, v_vTexcoord ); // get colour of pixel
    // add brightness to pixel that depends on Position uniform
    Colour.r += Position; // for red channel
    Colour.g += Position; // for green channel
    Colour.b += Position; // for blue channel
    gl_FragColor = v_vColour * Colour;
}
What do I need to put into the vertex part from the fragment part - or am I way off kilter here?
 
Top