Skip to content
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

Proper dither re-enabled #1045

Merged
merged 4 commits into from Apr 3, 2017
Merged
Changes from all commits
Commits
File filter...
Filter file types
Jump to…
Jump to file
Failed to load files.

Always

Just for now

@@ -763,8 +763,9 @@ vec4 dither(vec4 color) {
const int matrix_mask = 7;

ivec2 pos = ivec2(gl_FragCoord.xy) & ivec2(matrix_mask);
float noise_factor = 4.0 / 255.0;
float noise = texelFetch(sDither, pos, 0).r * noise_factor;
float noise_normalized = (texelFetch(sDither, pos, 0).r * 255.0 + 0.5) / 64.0;
float noise = (noise_normalized - 0.5) / 256.0; // scale down to the unit length

return color + vec4(noise, noise, noise, 0);
}
#endif //WR_FRAGMENT_SHADER
@@ -12,9 +12,5 @@ void main(void) {
#endif

alpha = min(alpha, do_clip());

// TODO(gw): Re-enable the gradient dither once we get the
// reftests passing.
//oFragColor = dither(vColor * vec4(1.0, 1.0, 1.0, alpha));
oFragColor = vColor * vec4(1.0, 1.0, 1.0, alpha);
oFragColor = dither(vColor * vec4(1.0, 1.0, 1.0, alpha));
}
@@ -197,19 +197,19 @@ pub struct PackedTexel {

impl PackedTexel {
pub fn high_bytes(color: &ColorF) -> PackedTexel {
Self::extract_bytes(color, COLOR_FLOAT_TO_FIXED)
Self::extract_bytes(color, 8)
}

pub fn low_bytes(color: &ColorF) -> PackedTexel {
Self::extract_bytes(color, COLOR_FLOAT_TO_FIXED_WIDE)
Self::extract_bytes(color, 0)
}

fn extract_bytes(color: &ColorF, multiplier: f32) -> PackedTexel {
fn extract_bytes(color: &ColorF, shift_by: i32) -> PackedTexel {
PackedTexel {
b: ((0.5 + color.b * multiplier).floor() as u32 & 0xff) as u8,
g: ((0.5 + color.g * multiplier).floor() as u32 & 0xff) as u8,
r: ((0.5 + color.r * multiplier).floor() as u32 & 0xff) as u8,
a: ((0.5 + color.a * multiplier).floor() as u32 & 0xff) as u8,
b: ((0.5 + color.b * COLOR_FLOAT_TO_FIXED_WIDE).floor() as u32 >> shift_by & 0xff) as u8,
g: ((0.5 + color.g * COLOR_FLOAT_TO_FIXED_WIDE).floor() as u32 >> shift_by & 0xff) as u8,
r: ((0.5 + color.r * COLOR_FLOAT_TO_FIXED_WIDE).floor() as u32 >> shift_by & 0xff) as u8,
a: ((0.5 + color.a * COLOR_FLOAT_TO_FIXED_WIDE).floor() as u32 >> shift_by & 0xff) as u8,
}
}
}
Binary file not shown.
@@ -2,18 +2,18 @@
== premultiplied-angle.yaml blank.yaml
== premultiplied-radial.yaml blank.yaml

fuzzy(1,20000) == linear.yaml linear-ref.png
fuzzy(1,20000) == linear-reverse.yaml linear-ref.png
fuzzy(1,29300) == linear-stops.yaml linear-stops-ref.png
== linear.yaml linear-ref.png
== linear-reverse.yaml linear-ref.png
fuzzy(1,35000) == linear-stops.yaml linear-stops-ref.png

# dithering requires us to fuzz here
fuzzy(1,20000) == linear.yaml linear-ref.yaml
fuzzy(1,20000) == linear-reverse.yaml linear-ref.yaml

== linear-aligned-clip.yaml linear-aligned-clip-ref.yaml

fuzzy(1,5) == radial-circle.yaml radial-circle-ref.png
fuzzy(1,4) == radial-ellipse.yaml radial-ellipse-ref.png
fuzzy(1,80000) == radial-circle.yaml radial-circle-ref.png
fuzzy(1,80000) == radial-ellipse.yaml radial-ellipse-ref.png

!= radial-circle.yaml radial-ellipse.yaml

ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.