Mercurial > games > semicongine
comparison semiconginev2/rendering/shaders.nim @ 1229:5dcb503ef0c0
did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
author | sam <sam@basx.dev> |
---|---|
date | Thu, 18 Jul 2024 21:32:41 +0700 |
parents | 4e465583ea32 |
children | 70f6c1cfe005 |
comparison
equal
deleted
inserted
replaced
1228:4e465583ea32 | 1229:5dcb503ef0c0 |
---|---|
342 addr(result[setNumber]) | 342 addr(result[setNumber]) |
343 ) | 343 ) |
344 inc setNumber | 344 inc setNumber |
345 | 345 |
346 proc CreatePipeline*[TShader]( | 346 proc CreatePipeline*[TShader]( |
347 renderPass: VkRenderPass, | 347 renderPass: RenderPass, |
348 topology: VkPrimitiveTopology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST, | 348 topology: VkPrimitiveTopology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST, |
349 polygonMode: VkPolygonMode = VK_POLYGON_MODE_FILL, | 349 polygonMode: VkPolygonMode = VK_POLYGON_MODE_FILL, |
350 cullMode: VkCullModeFlagBits = VK_CULL_MODE_BACK_BIT, | 350 cullMode: VkCullModeFlagBits = VK_CULL_MODE_BACK_BIT, |
351 frontFace: VkFrontFace = VK_FRONT_FACE_CLOCKWISE, | 351 frontFace: VkFrontFace = VK_FRONT_FACE_CLOCKWISE, |
352 descriptorPoolLimit = 1024, | 352 descriptorPoolLimit = 1024, |
353 samples = VK_SAMPLE_COUNT_1_BIT, | |
354 ): Pipeline[TShader] = | 353 ): Pipeline[TShader] = |
355 # create pipeline | 354 # create pipeline |
356 | 355 |
357 const shader = default(TShader) | 356 const shader = default(TShader) |
358 (result.vertexShaderModule, result.fragmentShaderModule) = CompileShader(shader) | 357 (result.vertexShaderModule, result.fragmentShaderModule) = CompileShader(shader) |
437 depthBiasSlopeFactor: 0.0, | 436 depthBiasSlopeFactor: 0.0, |
438 ) | 437 ) |
439 multisampling = VkPipelineMultisampleStateCreateInfo( | 438 multisampling = VkPipelineMultisampleStateCreateInfo( |
440 sType: VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO, | 439 sType: VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO, |
441 sampleShadingEnable: VK_FALSE, | 440 sampleShadingEnable: VK_FALSE, |
442 rasterizationSamples: samples, | 441 rasterizationSamples: renderPass.samples, |
443 minSampleShading: 1.0, | 442 minSampleShading: 1.0, |
444 pSampleMask: nil, | 443 pSampleMask: nil, |
445 alphaToCoverageEnable: VK_FALSE, | 444 alphaToCoverageEnable: VK_FALSE, |
446 alphaToOneEnable: VK_FALSE, | 445 alphaToOneEnable: VK_FALSE, |
446 ) | |
447 # will only be enabled it the renderpass actually uses a depth buffer | |
448 depthStencil = VkPipelineDepthStencilStateCreateInfo( | |
449 sType: VK_STRUCTURE_TYPE_PIPELINE_DEPTH_STENCIL_STATE_CREATE_INFO, | |
450 depthTestEnable: true, | |
451 depthWriteEnable: true, | |
452 depthCompareOp: VK_COMPARE_OP_LESS, | |
453 depthBoundsTestEnable: false, | |
454 stencilTestEnable: false, | |
455 minDepthBounds: 0'f32, | |
456 maxDepthBounds: 0'f32, | |
447 ) | 457 ) |
448 colorBlendAttachment = VkPipelineColorBlendAttachmentState( | 458 colorBlendAttachment = VkPipelineColorBlendAttachmentState( |
449 colorWriteMask: toBits [VK_COLOR_COMPONENT_R_BIT, VK_COLOR_COMPONENT_G_BIT, VK_COLOR_COMPONENT_B_BIT, VK_COLOR_COMPONENT_A_BIT], | 459 colorWriteMask: toBits [VK_COLOR_COMPONENT_R_BIT, VK_COLOR_COMPONENT_G_BIT, VK_COLOR_COMPONENT_B_BIT, VK_COLOR_COMPONENT_A_BIT], |
450 blendEnable: VK_TRUE, | 460 blendEnable: VK_TRUE, |
451 srcColorBlendFactor: VK_BLEND_FACTOR_SRC_ALPHA, | 461 srcColorBlendFactor: VK_BLEND_FACTOR_SRC_ALPHA, |
474 pVertexInputState: addr(vertexInputInfo), | 484 pVertexInputState: addr(vertexInputInfo), |
475 pInputAssemblyState: addr(inputAssembly), | 485 pInputAssemblyState: addr(inputAssembly), |
476 pViewportState: addr(viewportState), | 486 pViewportState: addr(viewportState), |
477 pRasterizationState: addr(rasterizer), | 487 pRasterizationState: addr(rasterizer), |
478 pMultisampleState: addr(multisampling), | 488 pMultisampleState: addr(multisampling), |
479 pDepthStencilState: nil, | 489 pDepthStencilState: if renderPass.depthBuffer: addr(depthStencil) else: nil, |
480 pColorBlendState: addr(colorBlending), | 490 pColorBlendState: addr(colorBlending), |
481 pDynamicState: addr(dynamicState), | 491 pDynamicState: addr(dynamicState), |
482 layout: result.layout, | 492 layout: result.layout, |
483 renderPass: renderPass, | 493 renderPass: renderPass.vk, |
484 subpass: 0, | 494 subpass: 0, |
485 basePipelineHandle: VkPipeline(0), | 495 basePipelineHandle: VkPipeline(0), |
486 basePipelineIndex: -1, | 496 basePipelineIndex: -1, |
487 ) | 497 ) |
488 checkVkResult vkCreateGraphicsPipelines( | 498 checkVkResult vkCreateGraphicsPipelines( |