diff options
| -rw-r--r-- | TODO.md | 2 | ||||
| -rw-r--r-- | src/3d/renderer_pipelines.cc | 71 |
2 files changed, 43 insertions, 30 deletions
@@ -214,7 +214,7 @@ This file tracks prioritized tasks with detailed attack plans. - [ ] **Task #62: Physics Engine Enhancements (PBD & Rotation)**: - [ ] **Task #62.1: Quaternion Rotation**: Implement quaternion-based rotation for `Object3D` and incorporate angular momentum into physics. - [ ] **Task #62.2: Position Based Dynamics (PBD)**: Refactor solver to re-evaluate velocity after resolving all collisions and constraints. -- [ ] **Task #63: Refactor large files**: Split `src/3d/renderer.cc` (currently > 500 lines) into sub-functionalities. +- [ ] **Task #63: Refactor large files**: Split `src/gpu/gpu.cc`, `src/3d/visual_debug.cc` and `src/gpu/effect.cc` into sub-functionalities. (`src/3d/renderer.cc` was also over 500 lines and was taken care of in the past) --- diff --git a/src/3d/renderer_pipelines.cc b/src/3d/renderer_pipelines.cc index d0f1a7b..1fdf30d 100644 --- a/src/3d/renderer_pipelines.cc +++ b/src/3d/renderer_pipelines.cc @@ -41,10 +41,10 @@ WGPURenderPipeline Renderer3D::create_pipeline_impl(bool use_bvh) { // BIND GROUP LAYOUT std::vector<WGPUBindGroupLayoutEntry> bgl_entries; - bgl_entries.push_back({.binding = 0, // B0: uniforms - .visibility = WGPUShaderStage_Vertex | - WGPUShaderStage_Fragment, - .buffer = {.type = WGPUBufferBindingType_Uniform}}); + bgl_entries.push_back( + {.binding = 0, // B0: uniforms + .visibility = WGPUShaderStage_Vertex | WGPUShaderStage_Fragment, + .buffer = {.type = WGPUBufferBindingType_Uniform}}); bgl_entries.push_back( {.binding = 1, // B1: object storage .visibility = WGPUShaderStage_Vertex | WGPUShaderStage_Fragment, @@ -55,19 +55,20 @@ WGPURenderPipeline Renderer3D::create_pipeline_impl(bool use_bvh) { .visibility = WGPUShaderStage_Fragment, .buffer = {.type = WGPUBufferBindingType_ReadOnlyStorage}}); } - bgl_entries.push_back({.binding = 3, // B3: noise texture - .visibility = WGPUShaderStage_Fragment, - .texture = {.sampleType = WGPUTextureSampleType_Float, - .viewDimension = - WGPUTextureViewDimension_2D}}); - bgl_entries.push_back({.binding = 4, // B4: default sampler - .visibility = WGPUShaderStage_Fragment, - .sampler = {.type = WGPUSamplerBindingType_Filtering}}); - bgl_entries.push_back({.binding = 5, // B5: sky texture - .visibility = WGPUShaderStage_Fragment, - .texture = {.sampleType = WGPUTextureSampleType_Float, - .viewDimension = - WGPUTextureViewDimension_2D}}); + bgl_entries.push_back( + {.binding = 3, // B3: noise texture + .visibility = WGPUShaderStage_Fragment, + .texture = {.sampleType = WGPUTextureSampleType_Float, + .viewDimension = WGPUTextureViewDimension_2D}}); + bgl_entries.push_back( + {.binding = 4, // B4: default sampler + .visibility = WGPUShaderStage_Fragment, + .sampler = {.type = WGPUSamplerBindingType_Filtering}}); + bgl_entries.push_back( + {.binding = 5, // B5: sky texture + .visibility = WGPUShaderStage_Fragment, + .texture = {.sampleType = WGPUTextureSampleType_Float, + .viewDimension = WGPUTextureViewDimension_2D}}); WGPUBindGroupLayoutDescriptor bgl_desc = {}; bgl_desc.entryCount = bgl_entries.size(); @@ -139,8 +140,7 @@ void Renderer3D::create_mesh_pipeline() { WGPUShaderModule shader_module = wgpuDeviceCreateShaderModule(device_, &shader_desc); - WGPUBindGroupLayout bgl = - wgpuRenderPipelineGetBindGroupLayout(pipeline_, 0); + WGPUBindGroupLayout bgl = wgpuRenderPipelineGetBindGroupLayout(pipeline_, 0); WGPUPipelineLayoutDescriptor pl_desc = {}; pl_desc.bindGroupLayoutCount = 1; pl_desc.bindGroupLayouts = &bgl; @@ -163,10 +163,16 @@ void Renderer3D::create_mesh_pipeline() { fragment_state.targets = &color_target; WGPUVertexAttribute vert_attrs[3] = {}; - vert_attrs[0] = {.format = WGPUVertexFormat_Float32x3, .offset = offsetof(MeshVertex, p), .shaderLocation = 0}; - vert_attrs[1] = {.format = WGPUVertexFormat_Float32x3, .offset = offsetof(MeshVertex, n), .shaderLocation = 1}; - vert_attrs[2] = {.format = WGPUVertexFormat_Float32x2, .offset = offsetof(MeshVertex, u), .shaderLocation = 2}; - + vert_attrs[0] = {.format = WGPUVertexFormat_Float32x3, + .offset = offsetof(MeshVertex, p), + .shaderLocation = 0}; + vert_attrs[1] = {.format = WGPUVertexFormat_Float32x3, + .offset = offsetof(MeshVertex, n), + .shaderLocation = 1}; + vert_attrs[2] = {.format = WGPUVertexFormat_Float32x2, + .offset = offsetof(MeshVertex, u), + .shaderLocation = 2}; + WGPUVertexBufferLayout vert_buffer_layout = {}; vert_buffer_layout.arrayStride = sizeof(MeshVertex); vert_buffer_layout.stepMode = WGPUVertexStepMode_Vertex; @@ -195,9 +201,9 @@ void Renderer3D::create_skybox_pipeline() { size_t size; const char* shader_code = reinterpret_cast<const char*>( GetAsset(AssetId::ASSET_SHADER_SKYBOX, &size)); - - std::string composed_shader = ShaderComposer::Get().Compose( - {}, std::string(shader_code, size)); + + std::string composed_shader = + ShaderComposer::Get().Compose({}, std::string(shader_code, size)); WGPUShaderSourceWGSL wgsl_src = {}; wgsl_src.chain.sType = WGPUSType_ShaderSourceWGSL; @@ -208,9 +214,16 @@ void Renderer3D::create_skybox_pipeline() { wgpuDeviceCreateShaderModule(device_, &shader_desc); WGPUBindGroupLayoutEntry bgl_entries[3] = {}; - bgl_entries[0] = {.binding=0, .visibility=WGPUShaderStage_Fragment, .texture={.sampleType=WGPUTextureSampleType_Float, .viewDimension=WGPUTextureViewDimension_2D}}; - bgl_entries[1] = {.binding=1, .visibility=WGPUShaderStage_Fragment, .sampler={.type=WGPUSamplerBindingType_Filtering}}; - bgl_entries[2] = {.binding=2, .visibility=WGPUShaderStage_Fragment, .buffer={.type=WGPUBufferBindingType_Uniform}}; + bgl_entries[0] = {.binding = 0, + .visibility = WGPUShaderStage_Fragment, + .texture = {.sampleType = WGPUTextureSampleType_Float, + .viewDimension = WGPUTextureViewDimension_2D}}; + bgl_entries[1] = {.binding = 1, + .visibility = WGPUShaderStage_Fragment, + .sampler = {.type = WGPUSamplerBindingType_Filtering}}; + bgl_entries[2] = {.binding = 2, + .visibility = WGPUShaderStage_Fragment, + .buffer = {.type = WGPUBufferBindingType_Uniform}}; WGPUBindGroupLayoutDescriptor bgl_desc = {}; bgl_desc.entryCount = 3; |
