From 791d2955783df61150473b3f1f46a6874e43bca4 Mon Sep 17 00:00:00 2001 From: Zach Pomerantz Date: Fri, 19 Feb 2016 11:48:44 -0800 Subject: [PATCH] Move paint shader functions to Paint.slh --- libraries/gpu/src/gpu/Paint.slh | 47 +++++++++++++++++++++++++++++ libraries/render-utils/src/grid.slf | 27 +---------------- 2 files changed, 48 insertions(+), 26 deletions(-) create mode 100644 libraries/gpu/src/gpu/Paint.slh diff --git a/libraries/gpu/src/gpu/Paint.slh b/libraries/gpu/src/gpu/Paint.slh new file mode 100644 index 0000000000..5f49b20b30 --- /dev/null +++ b/libraries/gpu/src/gpu/Paint.slh @@ -0,0 +1,47 @@ + +<@if not GPU_PAINT_SLH@> +<@def GPU_PAINT_SLH@> + +float paintStripe(float value, float offset, float scale, float edge) { + float width = fwidth(value); + float normalizedWidth = width * scale; + + float x0 = (value + offset) * scale - normalizedWidth / 2; + float x1 = x0 + normalizedWidth; + + float balance = 1.0 - edge; + float i0 = edge * floor(x0) + max(0.0, fract(x0) - balance); + float i1 = edge * floor(x1) + max(0.0, fract(x1) - balance); + float strip = (i1 - i0) / normalizedWidth; + + return clamp(strip, 0.0, 1.0); +} + +float paintGrid(vec2 value, vec2 offset, vec2 scale, vec2 edge) { + return max( + paintStripe(value.x, offset.x, scale.x, edge.x), + paintStripe(value.y, offset.y, scale.y, edge.y)); +} + +float paintGridMajor(vec2 value, vec2 offset, vec2 scale, vec2 edge) { + return paintGrid(value, offset, scale, edge); +} + +float paintGridMajorMinor(vec2 value, vec4 offset, vec4 scale, vec4 edge) { + return max( + paintGrid(value, offset.xy, scale.xy, edge.xy), + paintGrid(value, offset.zw, scale.zw, edge.zw)); +} + +<@endif@> diff --git a/libraries/render-utils/src/grid.slf b/libraries/render-utils/src/grid.slf index 04e35ac5ca..901d343268 100644 --- a/libraries/render-utils/src/grid.slf +++ b/libraries/render-utils/src/grid.slf @@ -11,32 +11,7 @@ // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // -float paintStripe(float value, float offset, float scale, float edge) { - float width = fwidth(value); - float normalizedWidth = width * scale; - - float x0 = (value + offset) * scale - normalizedWidth / 2; - float x1 = x0 + normalizedWidth; - - float balance = 1.0 - edge; - float i0 = edge * floor(x0) + max(0.0, fract(x0) - balance); - float i1 = edge * floor(x1) + max(0.0, fract(x1) - balance); - float strip = (i1 - i0) / normalizedWidth; - - return clamp(strip, 0.0, 1.0); -} - -float paintGrid(vec2 value, vec2 offset, vec2 scale, vec2 edge) { - return max( - paintStripe(value.x, offset.x, scale.x, edge.x), - paintStripe(value.y, offset.y, scale.y, edge.y)); -} - -float paintGridMajorMinor(vec2 value, vec4 offset, vec4 scale, vec4 edge) { - return max( - paintGrid(value, offset.xy, scale.xy, edge.xy), - paintGrid(value, offset.zw, scale.zw, edge.zw)); -} +<@include gpu/Paint.slh@> struct Grid { vec4 period;