-
Notifications
You must be signed in to change notification settings - Fork 18
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fixes iOS alpha blending #565
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -60,8 +60,7 @@ rasterFragmentShader(VertexOut in [[stage_in]], | |||||
float3 brightnessMax = float3(styling[0].brightnessMax, styling[0].brightnessMax, styling[0].brightnessMax); | ||||||
|
||||||
float gamma = styling[0].gamma; | ||||||
rgb = pow(rgb, (1.0 / (gamma) )); | ||||||
|
||||||
return float4(mix(brightnessMin, brightnessMax, rgb) * color.a, color.a); | ||||||
|
||||||
rgb = pow(rgb, (1.0 / (gamma))); | ||||||
rgb = mix(brightnessMin, brightnessMax, min(rgb / color.a, float3(1.0))); | ||||||
return float4(rgb * color.a, color.a) * styling[0].opacity; | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The final color is multiplied by - return float4(rgb * color.a, color.a) * styling[0].opacity;
+ return float4(rgb * color.a, color.a); Committable suggestion
Suggested change
|
||||||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The gamma correction logic on line 63 appears to be correct, as it inverses the gamma to adjust the color's luminance. However, the use of
min(rgb / color.a, float3(1.0))
on line 64 is potentially problematic. Dividingrgb
bycolor.a
could lead to incorrect results whencolor.a
is not equal to 1. This is because the RGB values are being scaled by an amount inversely proportional to the alpha value, which is not a standard approach in alpha blending and could lead to colors being incorrectly brightened when the alpha is low.A standard approach would be to premultiply the RGB values by the alpha before applying any blending or gamma correction, ensuring that the transparency affects the color intensity appropriately.
Committable suggestion