summaryrefslogtreecommitdiff
path: root/src/3d
diff options
context:
space:
mode:
Diffstat (limited to 'src/3d')
-rw-r--r--src/3d/renderer_pipelines.cc71
1 files changed, 42 insertions, 29 deletions
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;