paperstamp.swsl 1.2 KB

1234567891011121314151617181920212223242526272829
  1. // Object position in screen space. Allows the noise to
  2. // have a constant screen-space size, without being
  3. // affected by the widget layout/position.
  4. uniform highp vec2 objCoord;
  5. void fragment() {
  6. // Stamps have orientation, and the texture sampling is nearest
  7. // pixel, so run a bilinear filter to smooth out the edges.
  8. {
  9. highp vec4 tl = texture2D(TEXTURE, UV);
  10. highp vec4 tr = texture2D(TEXTURE, UV + vec2(TEXTURE_PIXEL_SIZE.x, 0.0));
  11. highp vec4 bl = texture2D(TEXTURE, UV + vec2(0.0, TEXTURE_PIXEL_SIZE.y));
  12. highp vec4 br = texture2D(TEXTURE, UV + TEXTURE_PIXEL_SIZE);
  13. highp vec2 textureSize = 1.0 / TEXTURE_PIXEL_SIZE;
  14. highp vec2 f = fract( UV * textureSize );
  15. highp vec4 tA = mix( tl, tr, f.x );
  16. highp vec4 tB = mix( bl, br, f.x );
  17. COLOR = mix( tA, tB, f.y );
  18. }
  19. // Add a bit of noise to mimic imperfect contact with the paper
  20. {
  21. highp float stampNoise = zNoise((FRAGCOORD.xy - objCoord) * vec2(0.03, 0.03)) *
  22. zNoise((FRAGCOORD.xy - objCoord) * vec2(0.08, 0.08));
  23. COLOR.a *= min(0.9, 0.4 + smoothstep(0.05, 0.3, stampNoise));
  24. }
  25. }