Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAntonioya <blendergit@gmail.com>2018-09-30 12:19:04 +0300
committerAntonioya <blendergit@gmail.com>2018-09-30 12:49:02 +0300
commitf1afa6f6a71220fefcd3d967f261edd6ad93a43a (patch)
tree0e8fc19a9089a0434fdad495613a5075e92ea315 /source/blender/draw/engines/gpencil/shaders
parentd9f6fdae4b5ae0475f0cbc8114a87b3be21739db (diff)
GP: implement Shadow FX (wip)
Initial implementation of effect to create a drop shadow of the strokes
Diffstat (limited to 'source/blender/draw/engines/gpencil/shaders')
-rw-r--r--source/blender/draw/engines/gpencil/shaders/fx/gpencil_fx_shadow_prepare_frag.glsl122
-rw-r--r--source/blender/draw/engines/gpencil/shaders/fx/gpencil_fx_shadow_resolve_frag.glsl32
2 files changed, 154 insertions, 0 deletions
diff --git a/source/blender/draw/engines/gpencil/shaders/fx/gpencil_fx_shadow_prepare_frag.glsl b/source/blender/draw/engines/gpencil/shaders/fx/gpencil_fx_shadow_prepare_frag.glsl
new file mode 100644
index 00000000000..941b746d494
--- /dev/null
+++ b/source/blender/draw/engines/gpencil/shaders/fx/gpencil_fx_shadow_prepare_frag.glsl
@@ -0,0 +1,122 @@
+uniform mat4 ProjectionMatrix;
+uniform mat4 ViewMatrix;
+
+/* ******************************************************************* */
+/* create shadow */
+/* ******************************************************************* */
+uniform sampler2D strokeColor;
+uniform sampler2D strokeDepth;
+uniform vec2 Viewport;
+
+uniform int offset[2];
+uniform float scale[2];
+uniform float rotation;
+uniform vec4 shadow_color;
+
+uniform float amplitude;
+uniform float period;
+uniform float phase;
+uniform int orientation;
+
+uniform vec3 loc;
+uniform float pixsize; /* rv3d->pixsize */
+uniform float pixelsize; /* U.pixelsize */
+uniform float pixfactor;
+
+#define M_PI 3.1415926535897932384626433832795
+
+#define HORIZONTAL 0
+#define VERTICAL 1
+
+float defaultpixsize = pixsize * pixelsize * (1000.0 / pixfactor);
+vec2 noffset = vec2(offset[0], offset[1]);
+
+out vec4 FragColor;
+
+/* project 3d point to 2d on screen space */
+vec2 toScreenSpace(vec4 vertex)
+{
+ /* need to calculate ndc because this is not done by vertex shader */
+ vec3 ndc = vec3(vertex).xyz / vertex.w;
+
+ vec2 sc;
+ sc.x = ((ndc.x + 1.0) / 2.0) * Viewport.x;
+ sc.y = ((ndc.y + 1.0) / 2.0) * Viewport.y;
+
+ return sc;
+}
+
+void main()
+{
+ vec2 uv = vec2(gl_FragCoord.xy);
+ vec4 nloc = ProjectionMatrix * ViewMatrix * vec4(loc.xyz, 1.0);
+ vec2 loc2d = toScreenSpace(nloc);
+
+ float dx = (ProjectionMatrix[3][3] == 0.0) ? (noffset[0] / (nloc.z * defaultpixsize)) : (noffset[0] / defaultpixsize);
+ float dy = (ProjectionMatrix[3][3] == 0.0) ? (noffset[1] / (nloc.z * defaultpixsize)) : (noffset[1] / defaultpixsize);
+
+ /* move point to new coords system */
+ vec2 tpos = vec2(uv.x, uv.y) - loc2d;
+
+ /* apply offset */
+ tpos = vec2(tpos.x - dx, tpos.y - dy);
+
+ /* apply scale */
+ tpos.x *= 1.0 / scale[0];
+ tpos.y *= 1.0 / scale[1];
+
+ /* rotation */
+ tpos.x = (tpos.x * cos(rotation)) - (tpos.y * sin(rotation));
+ tpos.y = (tpos.x * sin(rotation)) + (tpos.y * cos(rotation));
+
+ /* back to original coords system */
+ vec2 texpos = tpos + loc2d;
+
+ /* wave */
+ float value;
+ if (orientation == HORIZONTAL) {
+ float pval = (uv.x * M_PI) / Viewport[0];
+ value = amplitude * sin((period * pval) + phase);
+ texpos.y += value;
+ }
+ else if (orientation == VERTICAL){
+ float pval = (uv.y * M_PI) / Viewport[1];
+ value = amplitude * sin((period * pval) + phase);
+ texpos.x += value;
+ }
+
+ float stroke_depth = texelFetch(strokeDepth, ivec2(texpos.x, texpos.y), 0).r;
+ vec4 src_pixel= texelFetch(strokeColor, ivec2(texpos.x, texpos.y), 0);
+ vec4 outcolor;
+ outcolor = shadow_color;
+
+ /* is transparent */
+ if (src_pixel.a == 0.0f) {
+ discard;
+ }
+
+
+
+ // /* check inside viewport */
+ // else if ((uv.x - dx < 0) || (uv.x - dx > Viewport[0])) {
+ // discard;
+ // }
+ // else if ((uv.y - dy < 0) || (uv.y - dy > Viewport[1])) {
+ // discard;
+ // }
+ // /* pixel is equal to mask color, keep */
+ // else if (src_pixel.rgb == mask_color.rgb) {
+ // discard;
+ // }
+ // else {
+ // if ((src_pixel.a > 0) && (offset_pixel.a > 0)) {
+ // discard;
+ // }
+ // else {
+ // outcolor = vec4(rim_color, 1.0);
+ // }
+ // }
+
+ gl_FragDepth = stroke_depth;
+ FragColor = outcolor;
+}
diff --git a/source/blender/draw/engines/gpencil/shaders/fx/gpencil_fx_shadow_resolve_frag.glsl b/source/blender/draw/engines/gpencil/shaders/fx/gpencil_fx_shadow_resolve_frag.glsl
new file mode 100644
index 00000000000..633dcf1fd63
--- /dev/null
+++ b/source/blender/draw/engines/gpencil/shaders/fx/gpencil_fx_shadow_resolve_frag.glsl
@@ -0,0 +1,32 @@
+/* ******************************************************************* */
+/* Resolve Shadow pass */
+/* ******************************************************************* */
+uniform sampler2D strokeColor;
+uniform sampler2D strokeDepth;
+uniform sampler2D shadowColor;
+uniform sampler2D shadowDepth;
+
+out vec4 FragColor;
+
+void main()
+{
+ ivec2 uv = ivec2(gl_FragCoord.xy);
+
+ float stroke_depth = texelFetch(strokeDepth, uv.xy, 0).r;
+ float shadow_depth = texelFetch(shadowDepth, uv.xy, 0).r;
+ vec4 stroke_pixel= texelFetch(strokeColor, uv.xy, 0);
+ vec4 shadow_pixel= texelFetch(shadowColor, uv.xy, 0);
+
+ /* copy original pixel */
+ vec4 outcolor = stroke_pixel;
+ float outdepth = stroke_depth;
+
+ /* if stroke is not on top, copy shadow */
+ if ((stroke_pixel.a <= 0.2) && (shadow_pixel.a > 0.0)) {
+ outcolor = shadow_pixel;
+ outdepth = shadow_depth;
+ }
+
+ gl_FragDepth = outdepth;
+ FragColor = outcolor;
+}