Skip to content

Commit

Permalink
Fixed anti aliasing shader
Browse files Browse the repository at this point in the history
  • Loading branch information
jobtalle committed May 30, 2023
1 parent 474c0ad commit b49eac5
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ This example sets alpha to either `0` or `1`. Edges can also be anti aliased usi
``` glsl
vec4 pixel = texture(source, uv);
vec4 color = vec4(pixel.rgb, clamp(0.5 - pixel.a * 2.0 / fwidth(pixel.a), 0., 1.)));
vec4 color = vec4(pixel.rgb, clamp((pixel.a - 0.5) * 2.0 / fwidth(pixel.a), 0., 1.)));
```

This example interpolates alpha from `0` to `1` using standard derivatives, creating smooth anti aliased edges.
2 changes: 1 addition & 1 deletion js/gl/shaderPreview.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export class ShaderPreview extends Shader {
mix(
vec3(0.),
pixel.rgb,
clamp(.5 - pixel.a * 2. / fwidth(pixel.a), 0., 1.)),
clamp((pixel.a - .5) * 2. / fwidth(pixel.a), 0., 1.)),
1. - clamp((length(delta) - radius) * radiusPixels, 0., 1.));
}
`;
Expand Down

0 comments on commit b49eac5

Please sign in to comment.