Skip to content

Commit

Permalink
support base color factor
Browse files Browse the repository at this point in the history
  • Loading branch information
skyfloogle committed Aug 14, 2024
1 parent 15dbc81 commit f84c5b3
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 0 deletions.
12 changes: 12 additions & 0 deletions gm82gltf.gej
Original file line number Diff line number Diff line change
Expand Up @@ -516,6 +516,18 @@
],
"returntype": 2
},
{
"name": "gltf_material_base_color_pointer",
"extname": "",
"calltype": 12,
"helpline": "",
"hidden": false,
"argtypes": [
2,
2
],
"returntype": 2
},
{
"name": "gltf_material_base_texture",
"extname": "",
Expand Down
40 changes: 40 additions & 0 deletions gm82gltf.gml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,38 @@
// stuff on attributes in primitives
globalvar __gm82gltf_primitivebuffers;

globalvar __gm82gltf_shader_pixel; __gm82gltf_shader_pixel=shader_pixel_create_base64("
eJxFj0FqAjEUhr8kUxi6mQsUnGUVWrA9QUcP4ELoViWBloqWsYrLHGGOMPvZeKic
w5RkMprV938/L7wnpfdXP2G2/KieAAtI6b0EQh7ePHhAAIvkVoBK7je5ulofzGy/
3dd0AoUgi/2tW5rz37E2dF2X8Rj90J9+9Lt+OXyttanL6ev0rXz+/N6ZcnPc6a3R
4zAz6tewoC53LprEDXnRisiFBdcEFigL2SWw7H1bgRIUVuAsuWsf4ikp4+yQA0uc
jX/mffYe/gG5WDk3
")

/*
struct PS_INPUT {
float2 texcoord: TEXCOORD0;
float4 color: COLOR0;
};
struct PS_OUTPUT {
float4 color: COLOR0;
};
SamplerState rBaseTexture: register(s0);
float4 rBaseColor: register(c0);
PS_OUTPUT main(PS_INPUT input) {
PS_OUTPUT output;
float4 albedo = tex2D(rBaseTexture, input.texcoord);
output.color = albedo * input.color * rBaseColor;
return output;
}
*/


#define gltf_load
///gltf_load(fn)
Expand Down Expand Up @@ -174,10 +206,16 @@
__unique_mesh_id=__gm82gltf_meshes[argument0,__mesh_id]
__i=0 repeat (gltf_mesh_primitive_count(argument0,__mesh_id)) {
__unique_primitive_id=__gm82gltf_primitives[__unique_mesh_id,__i]

// set up material
__material=gltf_mesh_primitive_material(argument0,__mesh_id,__i)
__texture_id=gltf_material_base_texture(argument0,__material)
if (__texture_id>=0) __texture=__gm82gltf_textures[argument0,__texture_id]
else __texture=background_get_texture(bgWhitePixel)

shader_pixel_set(__gm82gltf_shader_pixel)
__gm82dx9_shader_pixel_uniform_f_buffer(0,gltf_material_base_color_pointer(argument0,__material),16)

// bind vertex buffers
__j=gltf_mesh_primitive_attribute_count(argument0,__mesh_id,__i)-1 repeat (__j) {
vertex_buffer_bind(__gm82gltf_primitivebuffers[__unique_primitive_id,__j],__j)
Expand All @@ -198,6 +236,8 @@
__gm82gltf_meshmodes[__unique_mesh_id,__i],
__texture)
__i+=1

shader_pixel_reset()
}
}

Expand Down
5 changes: 5 additions & 0 deletions src/root.zig
Original file line number Diff line number Diff line change
Expand Up @@ -493,6 +493,11 @@ export fn gltf_material_base_texture(gltf_id: f64, material_id: f64) f64 {
return @floatFromInt(baseColorTexture.index);
}

export fn gltf_material_base_color_pointer(gltf_id: f64, material_id: f64) f64 {
const material = get_material(gltf_id, material_id) orelse return -1;
return @floatFromInt(@intFromPtr(&material.pbrMetallicRoughness.baseColorFactor));
}

export fn gltf_material_base_texcoord(gltf_id: f64, material_id: f64) f64 {
const material = get_material(gltf_id, material_id) orelse return -1;
const baseColorTexture = material.pbrMetallicRoughness.baseColorTexture orelse return -1;
Expand Down

0 comments on commit f84c5b3

Please sign in to comment.