Changeset View
Changeset View
Standalone View
Standalone View
source/blender/draw/engines/overlay/shaders/paint_weight_frag.glsl
| in vec2 weight_interp; /* (weight, alert) */ | in vec2 weight_interp; /* (weight, alert) */ | ||||
| in float color_fac; | |||||
jbakker: Need to find a better name for this.
It is the factor between showing a hint of the geometry (0. | |||||
| out vec4 fragColor; | out vec4 fragColor; | ||||
| uniform float opacity = 1.0; | uniform float opacity = 1.0; | ||||
| uniform sampler1D colorramp; | uniform sampler1D colorramp; | ||||
| uniform bool useAlphaBlend = false; | |||||
| uniform bool drawContours = false; | uniform bool drawContours = false; | ||||
| float contours(float value, float steps, float width_px, float max_rel_width, float gradient) | float contours(float value, float steps, float width_px, float max_rel_width, float gradient) | ||||
| { | { | ||||
| /* Minimum visible and minimum full strength line width in screen space for fade out. */ | /* Minimum visible and minimum full strength line width in screen space for fade out. */ | ||||
| const float min_width_px = 1.3, fade_width_px = 2.3; | const float min_width_px = 1.3, fade_width_px = 2.3; | ||||
| /* Line is thinner towards the increase in the weight gradient by this factor. */ | /* Line is thinner towards the increase in the weight gradient by this factor. */ | ||||
| const float hi_bias = 2.0; | const float hi_bias = 2.0; | ||||
| ▲ Show 20 Lines • Show All 45 Lines • ▼ Show 20 Lines | vec4 contour_grid(float weight, float weight_gradient) | ||||
| /* White lines for 0.1 and 0.01, and black for 0.001 */ | /* White lines for 0.1 and 0.01, and black for 0.001 */ | ||||
| vec4 grid = vec4(1.0) * max(grid10, grid100); | vec4 grid = vec4(1.0) * max(grid10, grid100); | ||||
| grid.a = max(grid.a, grid1000); | grid.a = max(grid.a, grid1000); | ||||
| return grid * clamp((weight_gradient - flt_eps) / flt_eps, 0.0, 1.0); | return grid * clamp((weight_gradient - flt_eps) / flt_eps, 0.0, 1.0); | ||||
| } | } | ||||
| vec4 apply_color_fac(vec4 color_in) | |||||
Not Done Inline ActionsFind better name. jbakker: Find better name. | |||||
| { | |||||
| vec4 color = color_in; | |||||
| color.rgb = max(vec3(0.005), color_in.rgb) * color_fac; | |||||
| return color; | |||||
| } | |||||
| void main() | void main() | ||||
| { | { | ||||
| float alert = weight_interp.y; | float alert = weight_interp.y; | ||||
| vec4 color; | vec4 color; | ||||
| /* Missing vertex group alert color. Uniform in practice. */ | /* Missing vertex group alert color. Uniform in practice. */ | ||||
| if (alert > 1.1) { | if (alert > 1.1) { | ||||
| color = colorVertexMissingData; | color = apply_color_fac(colorVertexMissingData); | ||||
| } | } | ||||
| /* Weights are available */ | /* Weights are available */ | ||||
| else { | else { | ||||
| float weight = weight_interp.x; | float weight = weight_interp.x; | ||||
| vec4 weight_color = texture(colorramp, weight, 0); | vec4 weight_color = texture(colorramp, weight, 0); | ||||
| weight_color = apply_color_fac(weight_color); | |||||
| /* Contour display */ | /* Contour display */ | ||||
| if (drawContours) { | if (drawContours) { | ||||
| /* This must be executed uniformly for all fragments */ | /* This must be executed uniformly for all fragments */ | ||||
| float weight_gradient = length(vec2(dFdx(weight), dFdy(weight))); | float weight_gradient = length(vec2(dFdx(weight), dFdy(weight))); | ||||
| vec4 grid = contour_grid(weight, weight_gradient); | vec4 grid = contour_grid(weight, weight_gradient); | ||||
| weight_color = grid + weight_color * (1 - grid.a); | weight_color = grid + weight_color * (1 - grid.a); | ||||
| } | } | ||||
| /* Zero weight alert color. Nonlinear blend to reduce impact. */ | /* Zero weight alert color. Nonlinear blend to reduce impact. */ | ||||
| color = mix(weight_color, colorVertexUnreferenced, alert * alert); | vec4 color_unreferenced = apply_color_fac(colorVertexUnreferenced); | ||||
| color = mix(weight_color, color_unreferenced, alert * alert); | |||||
| } | } | ||||
| if (useAlphaBlend) { | |||||
| fragColor = vec4(color.rgb, opacity); | fragColor = vec4(color.rgb, opacity); | ||||
| } | } | ||||
| else { | |||||
| /* mix with 1.0 -> is like opacity when using multiply blend mode */ | |||||
| fragColor = vec4(mix(vec3(1.0), color.rgb, opacity), 1.0); | |||||
| } | |||||
| } | |||||
Need to find a better name for this.
It is the factor between showing a hint of the geometry (0.0) and the weight color (1.0).