3D [SOLVED] Custom vertex format gives weird results

Kentae

Member
So I've got this custom vertex format.
It's set up like this:
Code:
vertex_format_begin();
vertex_format_add_position_3d();
vertex_format_add_normal();
vertex_format_add_colour();
vertex_format_add_textcoord();
vertex_format_add_custom( vertex_type_float3, vertex_usage_tangent );
global.model_format_ktm = vertex_format_end();
And when I build a model with it I use this script:
Code:
vertex_begin( main_model, global.model_format_ktm );

for ( xx = 0; xx < ds_grid_width( grid_vertex ); xx++; )
    {
    vertex_position_3d( main_model,
                        ds_grid_get( grid_vertex, xx, 0 ),
                        ds_grid_get( grid_vertex, xx, 1 ),
                        ds_grid_get( grid_vertex, xx, 2 ) );
    vertex_normal(      main_model,
                        ds_grid_get( grid_normal, xx, 0 ),
                        ds_grid_get( grid_normal, xx, 1 ),
                        ds_grid_get( grid_normal, xx, 2 ) );
    vertex_colour(      main_model,
                        c_white, 1 );
    vertex_texcoord(    main_model,
                        ds_grid_get( grid_texCoord, xx, 0 ),
                        ds_grid_get( grid_texCoord, xx, 1 ) );
    vertex_float3(      main_model,
                        ds_grid_get( grid_tangent, xx, 0 ),
                        ds_grid_get( grid_tangent, xx, 1 ),
                        ds_grid_get( grid_tangent, xx, 2 ) );
    }
    
vertex_end( main_model );
vertex_freeze( main_model );
The vertex buffer is created elsewhere wich is why you can't see it here.
That's not the problem though. The model builds and renders the way it should... with the exception of the texture. For some reason my model turns out a mint green kind of colour. This makes no sense to me :S

When I use a more standard format like this:
Code:
vertex_format_begin();
vertex_format_add_position_3d();
vertex_format_add_normal();
vertex_format_add_colour();
vertex_format_add_textcoord();
global.model_format_default = vertex_format_end();
Without any custom values, it renders correctly, texture and everything. (obviously I change my model build script to match the format)

I tried changing "vertex_format_add_custom( vertex_type_float3, vertex_usage_tangent );"
to "vertex_format_add_custom( vertex_type_float3, vertex_usage_textcoord );" and a few others but only the one I mentioned now let my texture draw again. However the texture is kind of double at this point, with a second, slightly faded, texture that is offset a bit drawing as well.

Can anyone here make sense of this?
Am I adding custom values to my format wrong?

I use GMS 1.4.9999.
 
I don't believe you can access "tangent" attributes in gamemaker. What you can do instead is add a second one of the other attributes. I forget which ones exactly can have duplicates. I know the texture attribute can, so I'll give an example of that.

random example:

vertex_format_add_custom(vertex_type_float2,vertex_usage_textcoord);
vertex_format_add_custom(vertex_type_float2,vertex_usage_textcoord);
...
attribute vec2 in_TextureCoord0;
attribute vec2 in_TextureCoord1;
 

Kentae

Member
Hmm, That makes sense I suppose. A bit weird that it's an option at all though :S
I tried with vertex_usage_position and vertex_usage_normal too but those give the same results, so I suppose those won't do :S
 
You can make it whatever you want, float1, float2, float3, float4. Don't know if the ubyte4 works though.

vertex_format_add_custom(vertex_type_float3,vertex_usage_textcoord);

attribute vec3 in_TextureCoord1;
 

Kentae

Member
Well I tested it out and... it... works... perfectly! Thank you so much for your help :D
Now I finally have normal mapping working in my project ^^
 
Top