Multiple cgltf Nodes with base_color_texture Import, Skysphere matrix function#101
Multiple cgltf Nodes with base_color_texture Import, Skysphere matrix function#101TimeTravelerFromNow wants to merge 15 commits into
Conversation
Can handle some basic material conversion to the pbr struct. Needs slot_map implemented for rendering scenes.
We loaded the gltf file and got the index 0 to test placing into scene nodes dyn_array Proof of concept.
Scene renders all the meshes with base color textures.
Also we don't bind the texture every draw call. Didn't seem to change smoothness that much (my computer has decent specs)
gs.hWhat's the incentive behind the sky matrix functions? Just set the position to zero before getting the projection matrix. gs_camera_t tmp_cam = *cam;
tmp_cam.transform.position = gs_v3s(0);
gs_mat4 svp = gs_camera_get_view_projection(&tmp_cam, fbs.x, fbs.y);All of those 60 lines don't do anything useful unless I'm misunderstanding something. gs_gfxt
|
|
Glad to start this discussion on the items brought up. gs.hsky matrix functionsWhy not just set the position column zero? and gs_gfxtgs_gfxt_load_gltf_all_data_from_filestarted with a copy of the original. Didn't know if it was going to deviate a lot from the other gs_gfxt_scene_newYour comment was the idea I needed input on this. If I understand right, scene_new will allow an optional user pipeline file, else it loads_from_memory the vendored default pbr pipeline. And the function example you wrote I'll add that. Can you give me some help on how I would accomplish vendoring the pipeline from memory? gs_gfxt_scene_pbr_draw
gs_gfxt_scene_freeDefinetely. Got some Future ideas after current work is doneImagining what sort of physically-based rendering meshes we can draw will be so sick. Also I did some digging into gltf collision physics extensions, Much appreciated for the review Samdal. |
| } | ||
|
|
||
| gs_inline gs_mat4 | ||
| gs_mat4_sky_look_at(gs_vec3 position, gs_vec3 target, gs_vec3 up) |
There was a problem hiding this comment.
The position argument is redundant. Remove it
| gs_inline gs_mat4 | ||
| gs_mat4_sky_look_at(gs_vec3 position, gs_vec3 target, gs_vec3 up) | ||
| { | ||
| gs_vec3 f = gs_vec3_norm(gs_vec3_sub(target, position)); |
There was a problem hiding this comment.
remove subtraction.
I think target should already be normalized? I'm not completely sure
There was a problem hiding this comment.
Looked around for camera rotation vectors used by gs_camera_forward. They are unit vectors!
| { | ||
| gs_vec3 up = gs_camera_up(cam); | ||
| gs_vec3 forward = gs_camera_forward(cam); | ||
| gs_vec3 target = gs_vec3_add(forward, cam->transform.position); |
There was a problem hiding this comment.
remove this line and provide forward as the target. Addition is redundant.
| gs_vec3 up = gs_camera_up(cam); | ||
| gs_vec3 forward = gs_camera_forward(cam); | ||
| gs_vec3 target = gs_vec3_add(forward, cam->transform.position); | ||
| return gs_mat4_sky_look_at(cam->transform.position, target, up); |
There was a problem hiding this comment.
update to not provide cam->transform.position. Provide forward directly
| GS_API_DECL gs_mat4 gs_camera_get_view(const gs_camera_t* cam); | ||
| GS_API_DECL gs_mat4 gs_camera_get_proj(const gs_camera_t* cam, int32_t view_width, int32_t view_height); | ||
| GS_API_DECL gs_mat4 gs_camera_get_view_projection(const gs_camera_t* cam, int32_t view_width, int32_t view_height); | ||
| GS_API_DECL gs_mat4 gs_camera_get_sky_view_projection(const gs_camera_t* cam, int32_t view_width, int32_t view_height); |
There was a problem hiding this comment.
add comment // Camera position is ignored
You didn't exactly understand what I meant. Your function: GS_API_DECL
gs_gfxt_scene_t gs_gfxt_scene_new()
{
// maybe we can ship this standard pipeline with the gs framework
gs_println("looking for pbr_basic in ./assets/pipelines/pbr_basic.sf");
const char* pbr_basic_path = "./assets/pipelines/pbr_basic.sf";
gs_gfxt_pipeline_t pbr_pip = gs_gfxt_pipeline_load_from_file(pbr_basic_path);
gs_gfxt_scene_t scene = {0};
scene.pbr_pip = pbr_pip;
return scene;
};usage of your function: gs_gfxt_scene_t scene = gs_gfxt_scene_new()my function: // it doesn't existusage of my function: gs_gfxt_scene_t scene = {.pbr_pip = gs_gfxt_pipeline_load_from_file("path/to/pipeline")};If you were to vendor a pipeline in together with gfxt, you should do this GS_API_DECL
gs_gfxt_pipeline_t gs_gfxt_default_pbr_pipeline(void)
{
const char* pip = "/*\n"
" TODO(john): Need a description of the .sf format here\n"
"*/\n"
"\n"
"pipeline {\n"
"\n"
" raster\n"
" {\n"
" primitive: TRIANGLES\n"
" index_buffer_element_size: UINT32\n"
" },\n"
"\n"
" depth\n"
" {\n"
" func: LESS\n"
" },\n"
"\n"
"\n"
" shader {\n"
"\n"
" vertex {\n"
"\n"
" attributes {\n"
"\n"
" /*\n"
" Vertex layout required for this pipeline (for input assembler)\n"
"\n"
" fields:\n"
"\n"
" POSITION: float3\n"
" TEXCOORD: float2\n"
" TEXCOORD[0 - 12]: float2\n"
" COLOR: uint8[4]\n"
" NORMAL: float3\n"
" TANGENT: float4\n"
" JOINT: float4\n"
" WEIGHT: float\n"
" FLOAT: float\n"
" FLOAT2: float2\n"
" FLOAT3: float3\n"
" FLOAT4: float4\n"
" */\n"
"\n"
" POSITION : a_position\n"
" TEXCOORD : a_uv\n"
" COLOR : a_color\n"
" },\n"
"\n"
" uniforms {\n"
" mat4 u_mvp;\n"
" },\n"
"\n"
" out {\n"
" vec2 uv;\n"
" vec3 position;\n"
" },\n"
"\n"
" code {\n"
" void main() {\n"
" gl_Position = u_mvp * vec4(a_position, 1.0);\n"
" uv = a_uv;\n"
" position = a_position;\n"
" }\n"
" }\n"
" },\n"
"\n"
" fragment {\n"
" \n"
" uniforms {\n"
" sampler2D u_base_col_tex;\n"
" vec4 u_base_col_fact;\n"
" },\n"
" \n"
" out {\n"
" vec4 frag_color;\n"
" },\n"
"\n"
" code {\n"
" void main() {\n"
" frag_color = texture(u_base_col_tex, uv); // //\n"
" }\n"
" }\n"
" }\n"
" }\n"
"}\n";
return gs_gfxt_pipeline_load_from_memory(pip, sizeof(pip)-1);
};and then usage of it gs_gfxt_scene_t scene = {.pbr_pip = gs_gfxt_default_pbr_pipeline()}; |
The current PBR pipeline here only does color texture mapping. So it can't really do much in the current state, calling it PBR is a bit misleading to be honest. You'll have to do quite a bit more work for it to be called that, but I'm guessing that's the end goal so it doesn't bother me. |
Merged the load_all_data function. vendor default pbr pipeline
|
Added the free of arrays and merged the material loading logic into the existing I wanted to set fragment uniforms to pass in |
Still learning
|
I would've probably not had |
|
Great, lmk if I should squash the commits |
draw_materials in original state
Sky matrix and cgltf material mapping
This PR expands cgltf loading; pbr basic color texture image url is used to load a texture and is saved in a pbr_textures array. The cgltf node's material pointer is used to map to save a material id on the mesh primitive in gunslinger.
Materials are initialized and a handle to the corresponding material is stored on the pbr_node for rendering the correct material.
Currently this only supports the base_color_texture.
sky matrix
The sky matrix functions are matrix constructors that ignore position calculations, and can be used for skyboxes, skyspheres etc.
Todos copied from the example Pull Request