From f62203973f16935e55d22a2164eeffc2fba18501 Mon Sep 17 00:00:00 2001 From: Daniel Bross Date: Sat, 26 Jul 2025 01:39:16 +0200 Subject: [PATCH] Custom entity pipeline fixes --- core/mesh_entity.jai | 4 +- physics/physx.jai | 14 ++-- renderer/renderer.jai | 154 ++---------------------------------------- 3 files changed, 10 insertions(+), 162 deletions(-) diff --git a/core/mesh_entity.jai b/core/mesh_entity.jai index 36f2c13..416c29e 100644 --- a/core/mesh_entity.jai +++ b/core/mesh_entity.jai @@ -10,8 +10,8 @@ init_entity :: (e: *Mesh_Entity) { if e.model_path.count > 0 { load_model_into_entity(e, get_or_load_model(e.model_path)); e.flags |= .PHYSICS; - e.physics.type = .BOX; - e.physics.box.half_extent = .{0.5,0.5,0.5}; + e.physics.type = .TRIANGLE_MESH; + //e.physics.box.half_extent = .{0.5,0.5,0.5}; } } diff --git a/physics/physx.jai b/physics/physx.jai index 6c1cf8a..cffff01 100644 --- a/physics/physx.jai +++ b/physics/physx.jai @@ -88,9 +88,6 @@ tick_physx :: (scene: *PhysX_Scene, dt: float) { custom_filter_shader :: (attributes0: *u32, filterData0: *PhysX.PxFilterData, attributes1: *u32, filterData1: *PhysX.PxFilterData, pairFlags: *PhysX.PxPairFlags) -> u16 #c_call { pairFlags.* = PhysX.PxPairFlags.ContactDefault; - push_context { - print("DUDE!\n"); - } return xx PhysX.PxFilterFlags.Default; } @@ -302,7 +299,7 @@ create_physx_actor :: (e: *Entity) { } } } - mesh_desc := PhysX.PxTriangleMeshDesc_new(); + mesh_desc : PhysX.PxTriangleMeshDesc; mesh_desc.points.count = xx points.count; mesh_desc.points.stride = size_of(Vector3); mesh_desc.points.data = points.data; @@ -311,14 +308,11 @@ create_physx_actor :: (e: *Entity) { mesh_desc.triangles.stride = 3 * size_of(u32); mesh_desc.triangles.data = indices.data; - if !PhysX.PxValidateTriangleMesh(*cooking_params, *mesh_desc) { - assert(false); - } + //if !PhysX.PxValidateTriangleMesh(*cooking_params, *mesh_desc) { + // assert(false); + //} - stream : PhysX.PxOutputStream; callback := PhysX.PxGetStandaloneInsertionCallback(); - //read_buffer : PhysX.PxDefaultMemoryInputData_new(; - cond : s32; mesh := PhysX.PxCreateTriangleMesh(*cooking_params, *mesh_desc, callback, null); scale := PhysX.PxMeshScale_new(*e.transform.scale); geo = PhysX.PxTriangleMeshGeometry_new(mesh, *scale, 0); diff --git a/renderer/renderer.jai b/renderer/renderer.jai index cc6e5ed..b4ab49f 100644 --- a/renderer/renderer.jai +++ b/renderer/renderer.jai @@ -730,13 +730,6 @@ init_default_pipelines :: () { // projectile_pipeline = create_pipeline_state2(engine.renderer, vs, ps, blend_type=.OPAQUE); //} - - { - vs := create_vertex_shader_from_source(engine.renderer, "default_entity", DEFAULT_ENTITY_SHADER, "VS", mesh_data_types = .[.POSITION, .NORMAL, .TEXCOORD]); - ps := create_pixel_shader_from_source(engine.renderer, "default_entity", DEFAULT_ENTITY_SHADER, "PS"); - - engine.renderer.default_pipelines.entity_pipeline = create_pipeline_state(engine.renderer, vs, ps, blend_type=.OPAQUE); - } } init_default_meshes :: () { @@ -871,6 +864,10 @@ deinit_renderer :: (renderer: *Renderer) { deinit_backend(engine.renderer.backend); } +set_default_entity_pipeline :: (pipeline: Pipeline_State_Handle) { + engine.renderer.default_pipelines.entity_pipeline = pipeline; +} + get_shader :: (handle: Shader_Handle) -> Shader { assert(handle - 1 < xx engine.renderer.shaders.count); return engine.renderer.shaders[handle-1]; @@ -1782,146 +1779,3 @@ float4 PS(PSInput input) : SV_Target { return float4(1,0,1,1); } DONE - -DEFAULT_ENTITY_SHADER :: #string DONE -cbuffer CameraData : register(b0) -{ - float4x4 projection; - float4x4 view; - float4 camera_position; -}; - -cbuffer Directional_Light_Data : register(b1) -{ - float4 color_and_intensity; - float4 direction; - float4x4 light_matrix; -}; - -cbuffer Transform : register(b2) -{ - float4x4 model; -}; - -cbuffer Material : register(b3) -{ - float4 base_color; -}; - -#ifdef SKINNING - -#define MAX_BONES 128 - -cbuffer Bone_Matrices : register(b4) -{ - float4x4 bone_matrices[MAX_BONES]; -}; -#endif - -struct VSInput { - float3 position : POSITION; - float3 normal : NORMAL; - float2 texcoord : TEXCOORD0; - -#ifdef SKINNING - float4 bone_indices : TEXCOORD1; - float4 bone_weights : TEXCOORD2; -#endif -}; - -struct PSInput { - float4 position : SV_POSITION; - float2 texcoord : TEXCOORD1; - float3 normal : NORMAL; - float2 screen_pos : TEXCOORD0; - float4 light_view_position : TEXCOORD3; -}; - -struct PSOutput { - float4 color : SV_Target0; -}; - -sampler samp : register(s0); -Texture2D shadow_map: register(t0); - -PSInput VS(VSInput input) { - PSInput output; - - float3 position = input.position; -#ifdef SKINNING - float4x4 m = float4x4(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0); - for(int i = 0; i < 4; i++) { - m += bone_matrices[int(input.bone_indices[i])] * input.bone_weights[i]; - } - - output.position = mul(float4(position, 1.0), m); -#else - output.position = mul(float4(position, 1.0), model); -#endif - - output.light_view_position = mul(output.position, light_matrix); - - output.position = mul(output.position, view); - output.position = mul(output.position, projection); - output.screen_pos = output.position.xy / output.position.w; - output.screen_pos = output.screen_pos * 0.5 + 0.5; - output.normal = normalize(mul(input.normal, model)); - output.texcoord = input.texcoord; - - return output; -} - -float calculate_shadow(float2 shadow_coord, float bias, float current_depth) { - if(current_depth > 1.0) - return 0.0; - - float2 texture_size; - shadow_map.GetDimensions(texture_size.x, texture_size.y); - float2 texel_size = 1.0 / texture_size; - float shadow = 0.0; - - for(int x = -1; x <= 1; ++x) - { - for(int y = -1; y <= 1; ++y) - { - float pcf_depth = shadow_map.Sample(samp, shadow_coord + float2(x, y) * texel_size).r; - shadow += current_depth - bias > pcf_depth ? 1.0 : 0.0; - } - } - shadow /= 9.0; - - - return 1.0 - shadow; -} - -PSOutput PS(PSInput input) { - PSOutput output; - float ao = 1.0;//ssao.Sample(samp, float2(input.screen_pos.x, 1.0 - input.screen_pos.y)); - //output.color = float4(ao, ao, ao, 1.0); - //return output; - float3 ambient = 0.1; - - // Diffuse - float3 light_dir = normalize(-direction); - float diffuse_factor = max(0, dot(input.normal, light_dir)); - float3 diffuse = 0.5 * diffuse_factor; - - // Specular - float3 view_dir = normalize(-input.position.xyz); - float3 reflect_dir = reflect(-light_dir, input.normal); - float specular_factor = pow(max(dot(view_dir, reflect_dir), 0), 32.0); - float3 specular = 0.3 * specular_factor; - - float2 shadow_coord; - shadow_coord.x = input.light_view_position.x / input.light_view_position.w * 0.5 + 0.5; - shadow_coord.y = -input.light_view_position.y / input.light_view_position.w * 0.5 + 0.5; - float current_depth = input.light_view_position.z / input.light_view_position.w; - - float shadow_amount = calculate_shadow(shadow_coord, 0.01, current_depth); - - output.color = base_color * color_and_intensity.w * float4(ao*(ambient + diffuse + specular), base_color.a); - output.color *= max(0.2, shadow_amount); - - return output; -} -DONE