diff --git a/TODO.txt b/TODO.txt new file mode 100644 index 0000000..4292813 --- /dev/null +++ b/TODO.txt @@ -0,0 +1,20 @@ +DONE: +- Implement idle orbit thing using the rotation in the level editor camera. (Cool transition effect?) +- Level editor camera movement complete. + +TODO: +- Level format (just a hash map?). Store a matrix so that we can rotate and maybe scale blocks. Scaling will cause problems with RDM, so figure that out. +- Trile color textures. +- Sun lighting and shadowmap for levels. +- A ground plane with customizable material (ground or water or maybe a reflective floor. Think about what part of this should be done with triles and what with textures.) +- Sky editor. +- Level saving +- Trile atlas saving? JSON? + +PLANNED: +- Render distance, sky and fog? +- Load RDMs. Load into the Trile_GFX structure? +- Render RDMs. +- Start working on game port for proof of concept. +- Maybe port tacoma in as a part of the engine in plain Vulkan without nvpro. Would also allow for cool ability to render levels as path traced for screenshots and references. +- Improve the bz4x format, or figure out a pre-existing format. diff --git a/src/editor/level_editor.jai b/src/editor/level_editor.jai index 46c3d1c..374a291 100644 --- a/src/editor/level_editor.jai +++ b/src/editor/level_editor.jai @@ -147,19 +147,21 @@ draw_level_editor :: () { vs_params : Trile_Vs_Params; vs_params.mvp = mvp.floats; - mesh := get_trile_gfx("test"); + trilegfx := get_trile_gfx("test"); sg_apply_pipeline(gPipelines.trile.pipeline); bindings : sg_bindings; - bindings.vertex_buffers[0] = mesh.vertex_buffer; - bindings.vertex_buffers[1] = mesh.normal_buffer; + bindings.vertex_buffers[0] = trilegfx.vertex_buffer; + bindings.vertex_buffers[1] = trilegfx.normal_buffer; + bindings.samplers[0] = gPipelines.trile.bind.samplers[0]; + bindings.images[0] = trilegfx.trixel_colors; sg_apply_bindings(*bindings); sg_apply_uniforms(UB_trile_vs_params, *(sg_range.{ ptr = *vs_params, size = size_of(type_of(vs_params))})); - sg_draw(0, cast(s32) mesh.vertex_count, 1); + sg_draw(0, cast(s32) trilegfx.vertex_count, 1); } diff --git a/src/meshgen.jai b/src/meshgen.jai index 00cd1bd..d167e9a 100644 --- a/src/meshgen.jai +++ b/src/meshgen.jai @@ -436,37 +436,51 @@ generate_trile_gfx_matias :: (trileptr : *Trile) -> Trile_GFX { Pool.reset(*meshgenpool); print("Successfully generated mesh for trile with % triangles.\n", triangleVecs.count / 3 / 3); - return .{ trile_vert_buffer, trile_normal_buffer, triangleVecs.count / 3 }; + + // Create the texture for the trile, from which it gets it's colors for trixels. + + materialdata : [16*16*16*4]u8; + counter : int = 0; + + for x: 0..15 { + for y: 0..15 { + for z: 0..15 { + if trileptr.trixels[x][y][z].empty { + // @ToDo: add some null pattern here to help in shader side. + materialdata[counter + 0] = 0; + materialdata[counter + 1] = 0; + materialdata[counter + 2] = 0; + materialdata[counter + 3] = 0; + counter += 4; + } else { + r,g,b,a := material_to_rgba(trileptr.trixels[x][y][z].material); + materialdata[counter + 0] = r; + materialdata[counter + 1] = g; + materialdata[counter + 2] = b; + materialdata[counter + 3] = a; + counter += 4; + } + } + } + } + + imgdata : sg_image_data; + imgdata.subimage[0][0] = .{materialdata.data, materialdata.count}; + + texdesc : sg_image_desc = .{ + render_target = false, + width = 16, + height = 16*16, + pixel_format = sg_pixel_format.RGBA8, + sample_count = 1, + data = imgdata + }; + + img := sg_make_image(*texdesc); + + state := sg_query_image_state(img); + print("IMG: %\n", state); + + return .{ img, trile_vert_buffer, trile_normal_buffer, triangleVecs.count / 3 }; } } - -/* - -Mesh GenerateMeshMatias(Trile *trileptr){ - std::vector quadVecs; - std::vector triangleVecs; - std::vector quadNorms; - std::vector triangleNorms; - Mesh temp = {}; - - generateOptimizedQuadMesh(trileptr,quadVecs,quadNorms); - - //generateBasicQuadMesh(trileptr,quadVecs,quadNorms); - quadsToTriangles(quadVecs, triangleVecs,quadNorms, triangleNorms); - - temp.vertexCount = triangleVecs.size() / 3; - temp.triangleCount = temp.vertexCount / 3; - - float* vecs = new float[triangleVecs.size()]; - float* norms = new float[triangleNorms.size()]; - for(int i=0; i 0 + Image 'triletex': + Image type: ._2D + Sample type: .FLOAT + Multisampled: false + Bind slot: IMG_triletex => 0 + Sampler 'trilesmp': + Type: .FILTERING + Bind slot: SMP_trilesmp => 0 */ ATTR_trile_position :: 0; ATTR_trile_normal :: 1; UB_trile_vs_params :: 0; +IMG_triletex :: 0; +SMP_trilesmp :: 0; Trile_Vs_Params :: struct { mvp: [16]float; }; @@ -67,27 +77,33 @@ vs_trile_source_glsl430 := u8.[ /* #version 430 + layout(binding = 16) uniform sampler2D triletex_trilesmp; + layout(location = 0) out vec4 frag_color; layout(location = 0) in vec4 fnormal; void main() { - frag_color = vec4((fnormal.xyz + vec3(1.0)) * 0.5, 1.0); + frag_color = texture(triletex_trilesmp, vec2(0.0)); } */ fs_trile_source_glsl430 := u8.[ 0x23,0x76,0x65,0x72,0x73,0x69,0x6f,0x6e,0x20,0x34,0x33,0x30,0x0a,0x0a,0x6c,0x61, - 0x79,0x6f,0x75,0x74,0x28,0x6c,0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20, - 0x30,0x29,0x20,0x6f,0x75,0x74,0x20,0x76,0x65,0x63,0x34,0x20,0x66,0x72,0x61,0x67, - 0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x3b,0x0a,0x6c,0x61,0x79,0x6f,0x75,0x74,0x28,0x6c, - 0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x30,0x29,0x20,0x69,0x6e,0x20, - 0x76,0x65,0x63,0x34,0x20,0x66,0x6e,0x6f,0x72,0x6d,0x61,0x6c,0x3b,0x0a,0x0a,0x76, - 0x6f,0x69,0x64,0x20,0x6d,0x61,0x69,0x6e,0x28,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20, - 0x20,0x66,0x72,0x61,0x67,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3d,0x20,0x76,0x65, - 0x63,0x34,0x28,0x28,0x66,0x6e,0x6f,0x72,0x6d,0x61,0x6c,0x2e,0x78,0x79,0x7a,0x20, - 0x2b,0x20,0x76,0x65,0x63,0x33,0x28,0x31,0x2e,0x30,0x29,0x29,0x20,0x2a,0x20,0x30, - 0x2e,0x35,0x2c,0x20,0x31,0x2e,0x30,0x29,0x3b,0x0a,0x7d,0x0a,0x0a,0x00, + 0x79,0x6f,0x75,0x74,0x28,0x62,0x69,0x6e,0x64,0x69,0x6e,0x67,0x20,0x3d,0x20,0x31, + 0x36,0x29,0x20,0x75,0x6e,0x69,0x66,0x6f,0x72,0x6d,0x20,0x73,0x61,0x6d,0x70,0x6c, + 0x65,0x72,0x32,0x44,0x20,0x74,0x72,0x69,0x6c,0x65,0x74,0x65,0x78,0x5f,0x74,0x72, + 0x69,0x6c,0x65,0x73,0x6d,0x70,0x3b,0x0a,0x0a,0x6c,0x61,0x79,0x6f,0x75,0x74,0x28, + 0x6c,0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x30,0x29,0x20,0x6f,0x75, + 0x74,0x20,0x76,0x65,0x63,0x34,0x20,0x66,0x72,0x61,0x67,0x5f,0x63,0x6f,0x6c,0x6f, + 0x72,0x3b,0x0a,0x6c,0x61,0x79,0x6f,0x75,0x74,0x28,0x6c,0x6f,0x63,0x61,0x74,0x69, + 0x6f,0x6e,0x20,0x3d,0x20,0x30,0x29,0x20,0x69,0x6e,0x20,0x76,0x65,0x63,0x34,0x20, + 0x66,0x6e,0x6f,0x72,0x6d,0x61,0x6c,0x3b,0x0a,0x0a,0x76,0x6f,0x69,0x64,0x20,0x6d, + 0x61,0x69,0x6e,0x28,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x72,0x61,0x67, + 0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3d,0x20,0x74,0x65,0x78,0x74,0x75,0x72,0x65, + 0x28,0x74,0x72,0x69,0x6c,0x65,0x74,0x65,0x78,0x5f,0x74,0x72,0x69,0x6c,0x65,0x73, + 0x6d,0x70,0x2c,0x20,0x76,0x65,0x63,0x32,0x28,0x30,0x2e,0x30,0x29,0x29,0x3b,0x0a, + 0x7d,0x0a,0x0a,0x00, ]; /* #version 300 es @@ -131,12 +147,14 @@ vs_trile_source_glsl300es := u8.[ precision mediump float; precision highp int; + uniform highp sampler2D triletex_trilesmp; + layout(location = 0) out highp vec4 frag_color; in highp vec4 fnormal; void main() { - frag_color = vec4((fnormal.xyz + vec3(1.0)) * 0.5, 1.0); + frag_color = texture(triletex_trilesmp, vec2(0.0)); } */ @@ -144,17 +162,19 @@ fs_trile_source_glsl300es := u8.[ 0x23,0x76,0x65,0x72,0x73,0x69,0x6f,0x6e,0x20,0x33,0x30,0x30,0x20,0x65,0x73,0x0a, 0x70,0x72,0x65,0x63,0x69,0x73,0x69,0x6f,0x6e,0x20,0x6d,0x65,0x64,0x69,0x75,0x6d, 0x70,0x20,0x66,0x6c,0x6f,0x61,0x74,0x3b,0x0a,0x70,0x72,0x65,0x63,0x69,0x73,0x69, - 0x6f,0x6e,0x20,0x68,0x69,0x67,0x68,0x70,0x20,0x69,0x6e,0x74,0x3b,0x0a,0x0a,0x6c, - 0x61,0x79,0x6f,0x75,0x74,0x28,0x6c,0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e,0x20,0x3d, - 0x20,0x30,0x29,0x20,0x6f,0x75,0x74,0x20,0x68,0x69,0x67,0x68,0x70,0x20,0x76,0x65, - 0x63,0x34,0x20,0x66,0x72,0x61,0x67,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x3b,0x0a,0x69, - 0x6e,0x20,0x68,0x69,0x67,0x68,0x70,0x20,0x76,0x65,0x63,0x34,0x20,0x66,0x6e,0x6f, - 0x72,0x6d,0x61,0x6c,0x3b,0x0a,0x0a,0x76,0x6f,0x69,0x64,0x20,0x6d,0x61,0x69,0x6e, - 0x28,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x72,0x61,0x67,0x5f,0x63,0x6f, - 0x6c,0x6f,0x72,0x20,0x3d,0x20,0x76,0x65,0x63,0x34,0x28,0x28,0x66,0x6e,0x6f,0x72, - 0x6d,0x61,0x6c,0x2e,0x78,0x79,0x7a,0x20,0x2b,0x20,0x76,0x65,0x63,0x33,0x28,0x31, - 0x2e,0x30,0x29,0x29,0x20,0x2a,0x20,0x30,0x2e,0x35,0x2c,0x20,0x31,0x2e,0x30,0x29, - 0x3b,0x0a,0x7d,0x0a,0x0a,0x00, + 0x6f,0x6e,0x20,0x68,0x69,0x67,0x68,0x70,0x20,0x69,0x6e,0x74,0x3b,0x0a,0x0a,0x75, + 0x6e,0x69,0x66,0x6f,0x72,0x6d,0x20,0x68,0x69,0x67,0x68,0x70,0x20,0x73,0x61,0x6d, + 0x70,0x6c,0x65,0x72,0x32,0x44,0x20,0x74,0x72,0x69,0x6c,0x65,0x74,0x65,0x78,0x5f, + 0x74,0x72,0x69,0x6c,0x65,0x73,0x6d,0x70,0x3b,0x0a,0x0a,0x6c,0x61,0x79,0x6f,0x75, + 0x74,0x28,0x6c,0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x30,0x29,0x20, + 0x6f,0x75,0x74,0x20,0x68,0x69,0x67,0x68,0x70,0x20,0x76,0x65,0x63,0x34,0x20,0x66, + 0x72,0x61,0x67,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x3b,0x0a,0x69,0x6e,0x20,0x68,0x69, + 0x67,0x68,0x70,0x20,0x76,0x65,0x63,0x34,0x20,0x66,0x6e,0x6f,0x72,0x6d,0x61,0x6c, + 0x3b,0x0a,0x0a,0x76,0x6f,0x69,0x64,0x20,0x6d,0x61,0x69,0x6e,0x28,0x29,0x0a,0x7b, + 0x0a,0x20,0x20,0x20,0x20,0x66,0x72,0x61,0x67,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20, + 0x3d,0x20,0x74,0x65,0x78,0x74,0x75,0x72,0x65,0x28,0x74,0x72,0x69,0x6c,0x65,0x74, + 0x65,0x78,0x5f,0x74,0x72,0x69,0x6c,0x65,0x73,0x6d,0x70,0x2c,0x20,0x76,0x65,0x63, + 0x32,0x28,0x30,0x2e,0x30,0x29,0x29,0x3b,0x0a,0x7d,0x0a,0x0a,0x00, ]; /* #include @@ -235,15 +255,10 @@ vs_trile_source_metal_macos := u8.[ float4 frag_color [[color(0)]]; }; - struct main0_in - { - float4 fnormal [[user(locn0)]]; - }; - - fragment main0_out main0(main0_in in [[stage_in]]) + fragment main0_out main0(texture2d triletex [[texture(0)]], sampler trilesmp [[sampler(0)]]) { main0_out out = {}; - out.frag_color = float4((in.fnormal.xyz + float3(1.0)) * 0.5, 1.0); + out.frag_color = triletex.sample(trilesmp, float2(0.0)); return out; } @@ -257,21 +272,20 @@ fs_trile_source_metal_macos := u8.[ 0x61,0x69,0x6e,0x30,0x5f,0x6f,0x75,0x74,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66, 0x6c,0x6f,0x61,0x74,0x34,0x20,0x66,0x72,0x61,0x67,0x5f,0x63,0x6f,0x6c,0x6f,0x72, 0x20,0x5b,0x5b,0x63,0x6f,0x6c,0x6f,0x72,0x28,0x30,0x29,0x5d,0x5d,0x3b,0x0a,0x7d, - 0x3b,0x0a,0x0a,0x73,0x74,0x72,0x75,0x63,0x74,0x20,0x6d,0x61,0x69,0x6e,0x30,0x5f, - 0x69,0x6e,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20, - 0x66,0x6e,0x6f,0x72,0x6d,0x61,0x6c,0x20,0x5b,0x5b,0x75,0x73,0x65,0x72,0x28,0x6c, - 0x6f,0x63,0x6e,0x30,0x29,0x5d,0x5d,0x3b,0x0a,0x7d,0x3b,0x0a,0x0a,0x66,0x72,0x61, - 0x67,0x6d,0x65,0x6e,0x74,0x20,0x6d,0x61,0x69,0x6e,0x30,0x5f,0x6f,0x75,0x74,0x20, - 0x6d,0x61,0x69,0x6e,0x30,0x28,0x6d,0x61,0x69,0x6e,0x30,0x5f,0x69,0x6e,0x20,0x69, - 0x6e,0x20,0x5b,0x5b,0x73,0x74,0x61,0x67,0x65,0x5f,0x69,0x6e,0x5d,0x5d,0x29,0x0a, - 0x7b,0x0a,0x20,0x20,0x20,0x20,0x6d,0x61,0x69,0x6e,0x30,0x5f,0x6f,0x75,0x74,0x20, - 0x6f,0x75,0x74,0x20,0x3d,0x20,0x7b,0x7d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x6f,0x75, - 0x74,0x2e,0x66,0x72,0x61,0x67,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3d,0x20,0x66, - 0x6c,0x6f,0x61,0x74,0x34,0x28,0x28,0x69,0x6e,0x2e,0x66,0x6e,0x6f,0x72,0x6d,0x61, - 0x6c,0x2e,0x78,0x79,0x7a,0x20,0x2b,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x28,0x31, - 0x2e,0x30,0x29,0x29,0x20,0x2a,0x20,0x30,0x2e,0x35,0x2c,0x20,0x31,0x2e,0x30,0x29, - 0x3b,0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x6f,0x75,0x74, - 0x3b,0x0a,0x7d,0x0a,0x0a,0x00, + 0x3b,0x0a,0x0a,0x66,0x72,0x61,0x67,0x6d,0x65,0x6e,0x74,0x20,0x6d,0x61,0x69,0x6e, + 0x30,0x5f,0x6f,0x75,0x74,0x20,0x6d,0x61,0x69,0x6e,0x30,0x28,0x74,0x65,0x78,0x74, + 0x75,0x72,0x65,0x32,0x64,0x3c,0x66,0x6c,0x6f,0x61,0x74,0x3e,0x20,0x74,0x72,0x69, + 0x6c,0x65,0x74,0x65,0x78,0x20,0x5b,0x5b,0x74,0x65,0x78,0x74,0x75,0x72,0x65,0x28, + 0x30,0x29,0x5d,0x5d,0x2c,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x72,0x20,0x74,0x72, + 0x69,0x6c,0x65,0x73,0x6d,0x70,0x20,0x5b,0x5b,0x73,0x61,0x6d,0x70,0x6c,0x65,0x72, + 0x28,0x30,0x29,0x5d,0x5d,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x6d,0x61,0x69, + 0x6e,0x30,0x5f,0x6f,0x75,0x74,0x20,0x6f,0x75,0x74,0x20,0x3d,0x20,0x7b,0x7d,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x6f,0x75,0x74,0x2e,0x66,0x72,0x61,0x67,0x5f,0x63,0x6f, + 0x6c,0x6f,0x72,0x20,0x3d,0x20,0x74,0x72,0x69,0x6c,0x65,0x74,0x65,0x78,0x2e,0x73, + 0x61,0x6d,0x70,0x6c,0x65,0x28,0x74,0x72,0x69,0x6c,0x65,0x73,0x6d,0x70,0x2c,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x32,0x28,0x30,0x2e,0x30,0x29,0x29,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x6f,0x75,0x74,0x3b,0x0a,0x7d,0x0a, + 0x0a,0x00, ]; trile_shader_desc :: (backend: sg_backend) -> sg_shader_desc { desc: sg_shader_desc; @@ -292,6 +306,16 @@ trile_shader_desc :: (backend: sg_backend) -> sg_shader_desc { desc.uniform_blocks[0].glsl_uniforms[0].type = .FLOAT4; desc.uniform_blocks[0].glsl_uniforms[0].array_count = 4; desc.uniform_blocks[0].glsl_uniforms[0].glsl_name = "trile_vs_params"; + desc.images[0].stage = .FRAGMENT; + desc.images[0].multisampled = false; + desc.images[0].image_type = ._2D; + desc.images[0].sample_type = .FLOAT; + desc.samplers[0].stage = .FRAGMENT; + desc.samplers[0].sampler_type = .FILTERING; + desc.image_sampler_pairs[0].stage = .FRAGMENT; + desc.image_sampler_pairs[0].image_slot = 0; + desc.image_sampler_pairs[0].sampler_slot = 0; + desc.image_sampler_pairs[0].glsl_name = "triletex_trilesmp"; case .GLES3; desc.vertex_func.source = xx *vs_trile_source_glsl300es; desc.vertex_func.entry = "main"; @@ -307,6 +331,16 @@ trile_shader_desc :: (backend: sg_backend) -> sg_shader_desc { desc.uniform_blocks[0].glsl_uniforms[0].type = .FLOAT4; desc.uniform_blocks[0].glsl_uniforms[0].array_count = 4; desc.uniform_blocks[0].glsl_uniforms[0].glsl_name = "trile_vs_params"; + desc.images[0].stage = .FRAGMENT; + desc.images[0].multisampled = false; + desc.images[0].image_type = ._2D; + desc.images[0].sample_type = .FLOAT; + desc.samplers[0].stage = .FRAGMENT; + desc.samplers[0].sampler_type = .FILTERING; + desc.image_sampler_pairs[0].stage = .FRAGMENT; + desc.image_sampler_pairs[0].image_slot = 0; + desc.image_sampler_pairs[0].sampler_slot = 0; + desc.image_sampler_pairs[0].glsl_name = "triletex_trilesmp"; case .METAL_MACOS; desc.vertex_func.source = xx *vs_trile_source_metal_macos; desc.vertex_func.entry = "main0"; @@ -318,6 +352,17 @@ trile_shader_desc :: (backend: sg_backend) -> sg_shader_desc { desc.uniform_blocks[0].layout = .STD140; desc.uniform_blocks[0].size = 64; desc.uniform_blocks[0].msl_buffer_n = 0; + desc.images[0].stage = .FRAGMENT; + desc.images[0].multisampled = false; + desc.images[0].image_type = ._2D; + desc.images[0].sample_type = .FLOAT; + desc.images[0].msl_texture_n = 0; + desc.samplers[0].stage = .FRAGMENT; + desc.samplers[0].sampler_type = .FILTERING; + desc.samplers[0].msl_sampler_n = 0; + desc.image_sampler_pairs[0].stage = .FRAGMENT; + desc.image_sampler_pairs[0].image_slot = 0; + desc.image_sampler_pairs[0].sampler_slot = 0; } return desc; } diff --git a/src/shaders/shader_trile.glsl b/src/shaders/shader_trile.glsl index c861258..a321aac 100644 --- a/src/shaders/shader_trile.glsl +++ b/src/shaders/shader_trile.glsl @@ -1,5 +1,3 @@ -@module bla - @vs vs_trile in vec4 position; @@ -23,9 +21,12 @@ void main() { in vec4 fnormal; out vec4 frag_color; +layout(binding = 0) uniform texture2D triletex; +layout(binding = 0) uniform sampler trilesmp; void main() { - frag_color = vec4((fnormal.xyz + vec3(1.0, 1.0, 1.0)) * 0.5, 1.0); + //frag_color = vec4((fnormal.xyz + vec3(1.0, 1.0, 1.0)) * 0.5, 1.0); + frag_color = texture(sampler2D(triletex, trilesmp), vec2(0.0)); } @end diff --git a/src/trile.jai b/src/trile.jai index 077b21c..13af734 100644 --- a/src/trile.jai +++ b/src/trile.jai @@ -8,6 +8,7 @@ trile_table : Table(string, Trile); #scope_export Trile_GFX :: struct { + trixel_colors : sg_image; vertex_buffer : sg_buffer; normal_buffer : sg_buffer; vertex_count : s64; @@ -74,3 +75,11 @@ Trixel :: struct { Trile :: struct { trixels : [16][16][16] Trixel; }; + +material_to_rgba :: (mat: Material) -> (r: u8, g: u8, b: u8, a: u8) { + r : u8 = cast(u8) (mat.color.x * 255.0); + g : u8 = cast(u8) (mat.color.y * 255.0); + b : u8 = cast(u8) (mat.color.z * 255.0); + a : u8 = 255; // @ToDo: Do actual material value encode here. + return r,g,b,a; +}