Blending In Metal with Same Alpha
Clash Royale CLAN TAG#URR8PPP
Blending In Metal with Same Alpha
I am drawing three squares as in the Picture
I am adding color of red with alpha 0.2.
In the overlapping areas also I want the areas to be in the alpha of 0.2. Now It is coming as 0.6. How can I do that suggest. Currently my pipeline Descriptor is
pipelineDescriptor.colorAttachments[0].isBlendingEnabled = true
pipelineDescriptor.colorAttachments[0].rgbBlendOperation = .add
pipelineDescriptor.colorAttachments[0].alphaBlendOperation = .add
pipelineDescriptor.colorAttachments[0].sourceRGBBlendFactor = .one
pipelineDescriptor.colorAttachments[0].sourceAlphaBlendFactor = .one
pipelineDescriptor.colorAttachments[0].destinationRGBBlendFactor = .oneMinusSourceAlpha
pipelineDescriptor.colorAttachments[0].destinationAlphaBlendFactor = .oneMinusSourceAlpha
Do I need to do it in Pipeline Descriptor or In Shader ?
@KenThomases Need is when a finger touches the screen I am drawing three rectangles using the Touch Point. They are overlapping Rectangles as above in Picture. I need to draw them with alpha 0.2 In overlapping Places currently alpha is 0.4. In second touch It can add If the First touch and Second Touch Overlap. If not alpha should be 0.2.
– Ruban4Axis
Aug 9 at 4:20
@KenThomases stackoverflow.com/questions/51741792/…
– Ruban4Axis
Aug 9 at 4:21
1 Answer
1
If you want the final result to have the same alpha as which you are drawing, you need to set them as:
pipelineDescriptor.colorAttachments[0].sourceAlphaBlendFactor = .one
pipelineDescriptor.colorAttachments[0].destinationAlphaBlendFactor = .zero
Which will mean that the final alpha will have no contribution from the target on which you are rendering.
It is not working. For your reference I added the code. github.com/PIRANAVARUBAN/Blend
– Ruban4Axis
Aug 8 at 9:04
From your code, it appears to me that you are trying to draw the rectangles repeatedly on the target with an uniform transparency. For each touch, seems like you want the color of the rectangles to have the same value. But currently it is becoming more and more red with each draw. Is that correct?
– Abix
Aug 8 at 10:04
In a single touch from that point I am drawing three rectangles. If those three rectangles in same Alpha ok for me. If the next touch overlap If it adds It is ok.
– Ruban4Axis
Aug 8 at 10:11
Well in that case the blending of alpha is not relevant. The destination alpha would not matter. One way to achieve this could be to compose the triangle primitives per touch in such a way that they do not overlap. That way for single touch, the color would not get added. But for a overlapping touch, it would. But this will need a lot of code changes for you (to position non-overlapping triangles to compose the same shape).
– Abix
Aug 8 at 11:55
Cannot we do anything in the shader so that overlapping areas getting the constant alpha ?
– Ruban4Axis
Aug 8 at 12:24
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
You need to be clearer about exactly what you want to happen, what you're getting, and how they differ. I thought your question was clear, but the discussion in comments to Abix's answer gives me doubts. Try posting a screenshot of what you're getting and, if possible, an image of what you want (a mock-up or the results from OpenGL if you have that).
– Ken Thomases
Aug 8 at 20:00