diff options
author | Antonioya <blendergit@gmail.com> | 2018-07-31 11:22:19 +0300 |
---|---|---|
committer | Antonioya <blendergit@gmail.com> | 2018-07-31 11:50:43 +0300 |
commit | 66da2f537ae80ce2b31d1eaf34ad8c03d858938d (patch) | |
tree | 4776b9d2e43e4280d01d6f0b7088e6d4f417db0f /source/blender/draw/engines/gpencil/shaders/fx/gpencil_fx_swirl_frag.glsl | |
parent | 27496cc46bbfd76e98ad3b1ccb8fea534763ffb5 (diff) |
New Grease Pencil object for 2D animation
This commit merge the full development done in greasepencil-object branch and include mainly the following features.
- New grease pencil object.
- New drawing engine.
- New grease pencil modes Draw/Sculpt/Edit and Weight Paint.
- New brushes for grease pencil.
- New modifiers for grease pencil.
- New shaders FX.
- New material system (replace old palettes and colors).
- Split of annotations (old grease pencil) and new grease pencil object.
- UI adapted to blender 2.8.
You can get more info here:
https://code.blender.org/2017/12/drawing-2d-animation-in-blender-2-8/
https://code.blender.org/2018/07/grease-pencil-status-update/
This is the result of nearly two years of development and I want thanks firstly the other members of the grease pencil team: Daniel M. Lara, Matias Mendiola and Joshua Leung for their support, ideas and to keep working in the project all the time, without them this project had been impossible.
Also, I want thanks other Blender developers for their help, advices and to be there always to help me, and specially to Clément Foucault, Dalai Felinto, Pablo Vázquez and Campbell Barton.
Diffstat (limited to 'source/blender/draw/engines/gpencil/shaders/fx/gpencil_fx_swirl_frag.glsl')
-rw-r--r-- | source/blender/draw/engines/gpencil/shaders/fx/gpencil_fx_swirl_frag.glsl | 70 |
1 files changed, 70 insertions, 0 deletions
diff --git a/source/blender/draw/engines/gpencil/shaders/fx/gpencil_fx_swirl_frag.glsl b/source/blender/draw/engines/gpencil/shaders/fx/gpencil_fx_swirl_frag.glsl new file mode 100644 index 00000000000..6ce64350b3d --- /dev/null +++ b/source/blender/draw/engines/gpencil/shaders/fx/gpencil_fx_swirl_frag.glsl @@ -0,0 +1,70 @@ +uniform mat4 ProjectionMatrix; +uniform mat4 ViewMatrix; + +uniform sampler2D strokeColor; +uniform sampler2D strokeDepth; + +uniform vec2 Viewport; +uniform vec3 loc; +uniform int radius; +uniform float angle; +uniform int transparent; + +uniform float pixsize; /* rv3d->pixsize */ +uniform float pixelsize; /* U.pixelsize */ +uniform float pixfactor; + +out vec4 FragColor; + +float defaultpixsize = pixsize * pixelsize * (1000.0 / pixfactor); + +/* 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; +} + +/* This swirl shader is a modified version of original Geeks3d.com code */ +void main() +{ + vec2 uv = vec2(gl_FragCoord.xy); + float stroke_depth; + vec4 outcolor; + + vec4 center3d = ProjectionMatrix * ViewMatrix * vec4(loc.xyz, 1.0); + vec2 center = toScreenSpace(center3d); + vec2 tc = uv - center; + + float dist = length(tc); + float pxradius = (ProjectionMatrix[3][3] == 0.0) ? (radius / (loc.z * defaultpixsize)) : (radius / defaultpixsize); + pxradius = max(pxradius, 1); + + if (dist <= pxradius) { + float percent = (pxradius - dist) / pxradius; + float theta = percent * percent * angle * 8.0; + float s = sin(theta); + float c = cos(theta); + tc = vec2(dot(tc, vec2(c, -s)), dot(tc, vec2(s, c))); + tc += center; + + stroke_depth = texelFetch(strokeDepth, ivec2(tc), 0).r; + outcolor = texelFetch(strokeColor, ivec2(tc), 0); + } + else { + if (transparent == 1) { + discard; + } + stroke_depth = texelFetch(strokeDepth, ivec2(uv), 0).r; + outcolor = texelFetch(strokeColor, ivec2(uv), 0); + } + + gl_FragDepth = stroke_depth; + FragColor = outcolor; +} |