This repository has been archived on 2023-10-09. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
blender-archive/source/blender/draw/engines/overlay/shaders/outline_prepass_frag.glsl
Antonio Vazquez 29f3af9527 GPencil: Refactor of Draw Engine, Vertex Paint and all internal functions
This commit is a full refactor of the grease pencil modules including Draw Engine, Modifiers, VFX, depsgraph update, improvements in operators and conversion of Sculpt and Weight paint tools to real brushes.

Also, a huge code cleanup has been done at all levels.

Thanks to @fclem for his work and yo @pepeland and @mendio for the testing and help in the development.

Differential Revision: https://developer.blender.org/D6293
2020-03-09 16:27:24 +01:00

47 lines
1.3 KiB
GLSL

uniform vec4 gpDepthPlane;
flat in uint objectId;
/* using uint because 16bit uint can contain more ids than int. */
out uint outId;
vec3 ray_plane_intersection(vec3 ray_ori, vec3 ray_dir, vec4 plane)
{
float d = dot(plane.xyz, ray_dir);
vec3 plane_co = plane.xyz * (-plane.w / dot(plane.xyz, plane.xyz));
vec3 h = ray_ori - plane_co;
float lambda = -dot(plane.xyz, h) / ((abs(d) < 1e-8) ? 1e-8 : d);
return ray_ori + ray_dir * lambda;
}
void main()
{
#ifdef USE_GPENCIL
if (stroke_round_cap_mask(strokePt1, strokePt2, strokeAspect, strokeThickness, strokeHardeness) <
0.001) {
discard;
}
if (depth != -1.0) {
/* Stroke order 2D. */
bool is_persp = ProjectionMatrix[3][3] == 0.0;
vec2 uvs = vec2(gl_FragCoord.xy) * sizeViewportInv;
vec3 pos_ndc = vec3(uvs, gl_FragCoord.z) * 2.0 - 1.0;
vec4 pos_world = ViewProjectionMatrixInverse * vec4(pos_ndc, 1.0);
vec3 pos = pos_world.xyz / pos_world.w;
vec3 ray_ori = pos;
vec3 ray_dir = (is_persp) ? (ViewMatrixInverse[3].xyz - pos) : ViewMatrixInverse[2].xyz;
vec3 isect = ray_plane_intersection(ray_ori, ray_dir, gpDepthPlane);
vec4 ndc = point_world_to_ndc(isect);
gl_FragDepth = (ndc.z / ndc.w) * 0.5 + 0.5;
}
else {
gl_FragDepth = gl_FragCoord.z;
}
#endif
outId = uint(objectId);
}