feat: add transparency handling in GBuffer and enhance ColorTargetState with blend state management#465
Conversation
…te with blend state management
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
📝 WalkthroughWalkthroughGBuffer fragment shader now samples into Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related PRs
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
src/plugin/graphic/src/resource/Shader.hpp (1)
68-85:⚠️ Potential issue | 🟠 MajorRMLUI premultiplied alpha blend is lost due to descriptor not setting blend state.
The local
blendStateconfigured forRMLUI_RENDER_PASS_SHADER(lines 68–78) is unused because line 84 always applies&format.getBlendState()from the descriptor. SinceRmluiRenderPass::CreateShader()never calls.setBlendState()on the descriptor'sColorTargetState, it defaults towgpu::Defaultinstead of the required premultiplied alpha settings (srcFactor=One, dstFactor=OneMinusSrcAlpha).Fix by setting the blend state in the descriptor:
Suggested fix (set blend state in RMLUI descriptor)
auto colorOutput = Graphic::Utils::ColorTargetState("END_RENDER_TEXTURE").setFormat(wgpu::TextureFormat::BGRA8UnormSrgb); + wgpu::BlendState premultipliedAlpha(wgpu::Default); + premultipliedAlpha.color.srcFactor = wgpu::BlendFactor::One; + premultipliedAlpha.color.dstFactor = wgpu::BlendFactor::OneMinusSrcAlpha; + premultipliedAlpha.color.operation = wgpu::BlendOperation::Add; + premultipliedAlpha.alpha.srcFactor = wgpu::BlendFactor::One; + premultipliedAlpha.alpha.dstFactor = wgpu::BlendFactor::OneMinusSrcAlpha; + premultipliedAlpha.alpha.operation = wgpu::BlendOperation::Add; + colorOutput.setBlendState(premultipliedAlpha);Then remove the now-unused local blendState override from Shader.hpp.
🤖 Fix all issues with AI agents
In `@src/plugin/default-pipeline/src/resource/pass/GBuffer.hpp`:
- Around line 98-103: The shader currently discards low-alpha fragments but then
forces output.alpha to 1.0, breaking premultiplied blending; update the write to
output.albedo to preserve the sampled alpha and premultiply RGB by that alpha
(use textureColor and material.diffuse): e.g. compute premultipliedRGB =
textureColor.rgb * material.diffuse.rgb * textureColor.a and set output.albedo =
vec4(premultipliedRGB, textureColor.a) (or multiply textureColor.a by
material.diffuse.a if your material encodes alpha), ensuring you keep the
existing discard and textureSample usage.
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Fix all issues with AI agents
In `@src/plugin/graphic/src/resource/Shader.hpp`:
- Line 68: The local variable declaration `wgpu::BlendState
blendState(wgpu::Default);` in Shader.hpp is dead code after the refactor that
now uses `format.getBlendState()`; remove this unused `blendState` declaration
so there are no unused locals in the function (ensure no other references to
`blendState` remain and rely on `format.getBlendState()` where needed).
|



This pull request introduces improvements to the G-buffer rendering pipeline, focusing on alpha transparency handling and blending. The main changes ensure that fragments with low alpha are discarded and that the albedo output supports alpha blending. Additionally, the blend state management is refactored for better configurability and clarity.
Alpha transparency and blending improvements:
fs_mainshader function, preventing nearly transparent pixels from being rendered.Blend state management refactoring:
ColorTargetStateutility now includes methods to get and set the blend state, allowing for more flexible and explicit blend state configuration per render target.ColorTargetStateis updated to store awgpu::BlendState, improving encapsulation and clarity.Shaderclass now retrieves the blend state from theColorTargetStateinstead of using a separate variable, streamlining the pipeline state setup.Summary by CodeRabbit