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:
authorCampbell Barton <ideasman42@gmail.com>2019-04-17 07:17:24 +0300
committerCampbell Barton <ideasman42@gmail.com>2019-04-17 07:21:24 +0300
commite12c08e8d170b7ca40f204a5b0423c23a9fbc2c1 (patch)
tree8cf3453d12edb177a218ef8009357518ec6cab6a /source/blender/gpu/shaders
parentb3dabc200a4b0399ec6b81f2ff2730d07b44fcaa (diff)
ClangFormat: apply to source, most of intern
Apply clang format as proposed in T53211. For details on usage and instructions for migrating branches without conflicts, see: https://wiki.blender.org/wiki/Tools/ClangFormat
Diffstat (limited to 'source/blender/gpu/shaders')
-rw-r--r--source/blender/gpu/shaders/gpu_shader_2D_area_borders_frag.glsl8
-rw-r--r--source/blender/gpu/shaders/gpu_shader_2D_area_borders_vert.glsl45
-rw-r--r--source/blender/gpu/shaders/gpu_shader_2D_edituvs_edges_vert.glsl12
-rw-r--r--source/blender/gpu/shaders/gpu_shader_2D_edituvs_facedots_vert.glsl6
-rw-r--r--source/blender/gpu/shaders/gpu_shader_2D_edituvs_faces_vert.glsl14
-rw-r--r--source/blender/gpu/shaders/gpu_shader_2D_edituvs_points_vert.glsl36
-rw-r--r--source/blender/gpu/shaders/gpu_shader_2D_edituvs_stretch_vert.glsl88
-rw-r--r--source/blender/gpu/shaders/gpu_shader_2D_flat_color_vert.glsl4
-rw-r--r--source/blender/gpu/shaders/gpu_shader_2D_image_multi_rect_vert.glsl67
-rw-r--r--source/blender/gpu/shaders/gpu_shader_2D_image_rect_vert.glsl40
-rw-r--r--source/blender/gpu/shaders/gpu_shader_2D_image_vert.glsl6
-rw-r--r--source/blender/gpu/shaders/gpu_shader_2D_line_dashed_frag.glsl62
-rw-r--r--source/blender/gpu/shaders/gpu_shader_2D_line_dashed_geom.glsl55
-rw-r--r--source/blender/gpu/shaders/gpu_shader_2D_line_dashed_uniform_color_vert.glsl4
-rw-r--r--source/blender/gpu/shaders/gpu_shader_2D_line_dashed_width_geom.glsl62
-rw-r--r--source/blender/gpu/shaders/gpu_shader_2D_nodelink_frag.glsl7
-rw-r--r--source/blender/gpu/shaders/gpu_shader_2D_nodelink_vert.glsl121
-rw-r--r--source/blender/gpu/shaders/gpu_shader_2D_point_uniform_size_aa_vert.glsl21
-rw-r--r--source/blender/gpu/shaders/gpu_shader_2D_point_uniform_size_outline_aa_vert.glsl25
-rw-r--r--source/blender/gpu/shaders/gpu_shader_2D_point_uniform_size_varying_color_outline_aa_vert.glsl27
-rw-r--r--source/blender/gpu/shaders/gpu_shader_2D_point_varying_size_varying_color_vert.glsl6
-rw-r--r--source/blender/gpu/shaders/gpu_shader_2D_smooth_color_dithered_frag.glsl18
-rw-r--r--source/blender/gpu/shaders/gpu_shader_2D_smooth_color_frag.glsl2
-rw-r--r--source/blender/gpu/shaders/gpu_shader_2D_smooth_color_vert.glsl4
-rw-r--r--source/blender/gpu/shaders/gpu_shader_2D_vert.glsl2
-rw-r--r--source/blender/gpu/shaders/gpu_shader_2D_widget_base_frag.glsl42
-rw-r--r--source/blender/gpu/shaders/gpu_shader_2D_widget_base_vert.glsl320
-rw-r--r--source/blender/gpu/shaders/gpu_shader_2D_widget_shadow_frag.glsl6
-rw-r--r--source/blender/gpu/shaders/gpu_shader_2D_widget_shadow_vert.glsl88
-rw-r--r--source/blender/gpu/shaders/gpu_shader_3D_clipped_uniform_color_vert.glsl4
-rw-r--r--source/blender/gpu/shaders/gpu_shader_3D_flat_color_vert.glsl17
-rw-r--r--source/blender/gpu/shaders/gpu_shader_3D_groundline_geom.glsl16
-rw-r--r--source/blender/gpu/shaders/gpu_shader_3D_groundpoint_vert.glsl8
-rw-r--r--source/blender/gpu/shaders/gpu_shader_3D_image_vert.glsl4
-rw-r--r--source/blender/gpu/shaders/gpu_shader_3D_line_dashed_uniform_color_legacy_vert.glsl8
-rw-r--r--source/blender/gpu/shaders/gpu_shader_3D_line_dashed_uniform_color_vert.glsl8
-rw-r--r--source/blender/gpu/shaders/gpu_shader_3D_normal_smooth_color_vert.glsl6
-rw-r--r--source/blender/gpu/shaders/gpu_shader_3D_normal_vert.glsl4
-rw-r--r--source/blender/gpu/shaders/gpu_shader_3D_passthrough_vert.glsl6
-rw-r--r--source/blender/gpu/shaders/gpu_shader_3D_point_fixed_size_varying_color_vert.glsl4
-rw-r--r--source/blender/gpu/shaders/gpu_shader_3D_point_uniform_size_aa_vert.glsl25
-rw-r--r--source/blender/gpu/shaders/gpu_shader_3D_point_uniform_size_outline_aa_vert.glsl29
-rw-r--r--source/blender/gpu/shaders/gpu_shader_3D_point_varying_size_varying_color_vert.glsl6
-rw-r--r--source/blender/gpu/shaders/gpu_shader_3D_point_varying_size_vert.glsl4
-rw-r--r--source/blender/gpu/shaders/gpu_shader_3D_selection_id_vert.glsl10
-rw-r--r--source/blender/gpu/shaders/gpu_shader_3D_smooth_color_frag.glsl2
-rw-r--r--source/blender/gpu/shaders/gpu_shader_3D_smooth_color_vert.glsl6
-rw-r--r--source/blender/gpu/shaders/gpu_shader_3D_vert.glsl4
-rw-r--r--source/blender/gpu/shaders/gpu_shader_cfg_world_clip_lib.glsl34
-rw-r--r--source/blender/gpu/shaders/gpu_shader_checker_frag.glsl16
-rw-r--r--source/blender/gpu/shaders/gpu_shader_depth_only_frag.glsl4
-rw-r--r--source/blender/gpu/shaders/gpu_shader_diag_stripes_frag.glsl15
-rw-r--r--source/blender/gpu/shaders/gpu_shader_edges_front_back_ortho_vert.glsl42
-rw-r--r--source/blender/gpu/shaders/gpu_shader_edges_front_back_persp_geom.glsl46
-rw-r--r--source/blender/gpu/shaders/gpu_shader_edges_front_back_persp_legacy_vert.glsl38
-rw-r--r--source/blender/gpu/shaders/gpu_shader_edges_front_back_persp_vert.glsl24
-rw-r--r--source/blender/gpu/shaders/gpu_shader_edges_overlay_frag.glsl11
-rw-r--r--source/blender/gpu/shaders/gpu_shader_edges_overlay_geom.glsl83
-rw-r--r--source/blender/gpu/shaders/gpu_shader_edges_overlay_simple_geom.glsl64
-rw-r--r--source/blender/gpu/shaders/gpu_shader_edges_overlay_vert.glsl7
-rw-r--r--source/blender/gpu/shaders/gpu_shader_flat_color_alpha_test_0_frag.glsl8
-rw-r--r--source/blender/gpu/shaders/gpu_shader_flat_color_frag.glsl2
-rw-r--r--source/blender/gpu/shaders/gpu_shader_flat_id_frag.glsl2
-rw-r--r--source/blender/gpu/shaders/gpu_shader_geometry.glsl140
-rw-r--r--source/blender/gpu/shaders/gpu_shader_gpencil_fill_frag.glsl270
-rw-r--r--source/blender/gpu/shaders/gpu_shader_gpencil_fill_vert.glsl4
-rw-r--r--source/blender/gpu/shaders/gpu_shader_gpencil_stroke_frag.glsl24
-rw-r--r--source/blender/gpu/shaders/gpu_shader_gpencil_stroke_geom.glsl362
-rw-r--r--source/blender/gpu/shaders/gpu_shader_gpencil_stroke_vert.glsl21
-rw-r--r--source/blender/gpu/shaders/gpu_shader_image_alpha_color_frag.glsl8
-rw-r--r--source/blender/gpu/shaders/gpu_shader_image_color_frag.glsl2
-rw-r--r--source/blender/gpu/shaders/gpu_shader_image_depth_copy_frag.glsl6
-rw-r--r--source/blender/gpu/shaders/gpu_shader_image_depth_linear_frag.glsl8
-rw-r--r--source/blender/gpu/shaders/gpu_shader_image_desaturate_frag.glsl6
-rw-r--r--source/blender/gpu/shaders/gpu_shader_image_frag.glsl2
-rw-r--r--source/blender/gpu/shaders/gpu_shader_image_interlace_frag.glsl35
-rw-r--r--source/blender/gpu/shaders/gpu_shader_image_linear_frag.glsl23
-rw-r--r--source/blender/gpu/shaders/gpu_shader_image_mask_uniform_color_frag.glsl4
-rw-r--r--source/blender/gpu/shaders/gpu_shader_image_modulate_alpha_frag.glsl4
-rw-r--r--source/blender/gpu/shaders/gpu_shader_image_multisample_resolve_frag.glsl144
-rw-r--r--source/blender/gpu/shaders/gpu_shader_image_shuffle_color_frag.glsl9
-rw-r--r--source/blender/gpu/shaders/gpu_shader_image_varying_color_frag.glsl2
-rw-r--r--source/blender/gpu/shaders/gpu_shader_instance_camera_vert.glsl66
-rw-r--r--source/blender/gpu/shaders/gpu_shader_instance_distance_line_vert.glsl14
-rw-r--r--source/blender/gpu/shaders/gpu_shader_instance_edges_variying_color_geom.glsl48
-rw-r--r--source/blender/gpu/shaders/gpu_shader_instance_edges_variying_color_vert.glsl48
-rw-r--r--source/blender/gpu/shaders/gpu_shader_instance_objectspace_variying_color_vert.glsl14
-rw-r--r--source/blender/gpu/shaders/gpu_shader_instance_screen_aligned_vert.glsl26
-rw-r--r--source/blender/gpu/shaders/gpu_shader_instance_screenspace_variying_color_vert.glsl15
-rw-r--r--source/blender/gpu/shaders/gpu_shader_instance_variying_size_variying_color_vert.glsl8
-rw-r--r--source/blender/gpu/shaders/gpu_shader_instance_variying_size_variying_id_vert.glsl4
-rw-r--r--source/blender/gpu/shaders/gpu_shader_instance_vert.glsl2
-rw-r--r--source/blender/gpu/shaders/gpu_shader_keyframe_diamond_frag.glsl142
-rw-r--r--source/blender/gpu/shaders/gpu_shader_keyframe_diamond_vert.glsl85
-rw-r--r--source/blender/gpu/shaders/gpu_shader_material.glsl4304
-rw-r--r--source/blender/gpu/shaders/gpu_shader_point_uniform_color_aa_frag.glsl29
-rw-r--r--source/blender/gpu/shaders/gpu_shader_point_uniform_color_frag.glsl14
-rw-r--r--source/blender/gpu/shaders/gpu_shader_point_uniform_color_outline_aa_frag.glsl49
-rw-r--r--source/blender/gpu/shaders/gpu_shader_point_varying_color_frag.glsl14
-rw-r--r--source/blender/gpu/shaders/gpu_shader_point_varying_color_outline_aa_frag.glsl41
-rw-r--r--source/blender/gpu/shaders/gpu_shader_point_varying_color_varying_outline_aa_frag.glsl41
-rw-r--r--source/blender/gpu/shaders/gpu_shader_selection_id_frag.glsl2
-rw-r--r--source/blender/gpu/shaders/gpu_shader_simple_lighting_frag.glsl4
-rw-r--r--source/blender/gpu/shaders/gpu_shader_simple_lighting_smooth_color_alpha_frag.glsl4
-rw-r--r--source/blender/gpu/shaders/gpu_shader_simple_lighting_smooth_color_frag.glsl2
-rw-r--r--source/blender/gpu/shaders/gpu_shader_text_frag.glsl110
-rw-r--r--source/blender/gpu/shaders/gpu_shader_text_geom.glsl30
-rw-r--r--source/blender/gpu/shaders/gpu_shader_text_simple_geom.glsl32
-rw-r--r--source/blender/gpu/shaders/gpu_shader_text_simple_vert.glsl12
-rw-r--r--source/blender/gpu/shaders/gpu_shader_text_vert.glsl6
-rw-r--r--source/blender/gpu/shaders/gpu_shader_uniform_color_frag.glsl13
111 files changed, 4225 insertions, 3793 deletions
diff --git a/source/blender/gpu/shaders/gpu_shader_2D_area_borders_frag.glsl b/source/blender/gpu/shaders/gpu_shader_2D_area_borders_frag.glsl
index 620568db500..5a36b414229 100644
--- a/source/blender/gpu/shaders/gpu_shader_2D_area_borders_frag.glsl
+++ b/source/blender/gpu/shaders/gpu_shader_2D_area_borders_frag.glsl
@@ -8,9 +8,9 @@ out vec4 fragColor;
void main()
{
- /* Should be 0.8 but minimize the AA on the edges. */
- float dist = (length(uv) - 0.78) * scale;
+ /* Should be 0.8 but minimize the AA on the edges. */
+ float dist = (length(uv) - 0.78) * scale;
- fragColor = color;
- fragColor.a *= smoothstep(-0.09, 1.09, dist);
+ fragColor = color;
+ fragColor.a *= smoothstep(-0.09, 1.09, dist);
}
diff --git a/source/blender/gpu/shaders/gpu_shader_2D_area_borders_vert.glsl b/source/blender/gpu/shaders/gpu_shader_2D_area_borders_vert.glsl
index 816e12342a1..d20ddcd27c0 100644
--- a/source/blender/gpu/shaders/gpu_shader_2D_area_borders_vert.glsl
+++ b/source/blender/gpu/shaders/gpu_shader_2D_area_borders_vert.glsl
@@ -9,29 +9,28 @@ in vec2 pos;
out vec2 uv;
-
void main()
{
- int corner_id = (gl_VertexID / cornerLen) % 4;
-
- vec2 final_pos = pos * scale;
-
- if (corner_id == 0) {
- uv = pos + vec2(1.0, 1.0);
- final_pos += rect.yw; /* top right */
- }
- else if (corner_id == 1) {
- uv = pos + vec2(-1.0, 1.0);
- final_pos += rect.xw; /* top left */
- }
- else if (corner_id == 2) {
- uv = pos + vec2(-1.0, -1.0);
- final_pos += rect.xz; /* bottom left */
- }
- else {
- uv = pos + vec2(1.0, -1.0);
- final_pos += rect.yz; /* bottom right */
- }
-
- gl_Position = (ModelViewProjectionMatrix * vec4(final_pos, 0.0, 1.0));
+ int corner_id = (gl_VertexID / cornerLen) % 4;
+
+ vec2 final_pos = pos * scale;
+
+ if (corner_id == 0) {
+ uv = pos + vec2(1.0, 1.0);
+ final_pos += rect.yw; /* top right */
+ }
+ else if (corner_id == 1) {
+ uv = pos + vec2(-1.0, 1.0);
+ final_pos += rect.xw; /* top left */
+ }
+ else if (corner_id == 2) {
+ uv = pos + vec2(-1.0, -1.0);
+ final_pos += rect.xz; /* bottom left */
+ }
+ else {
+ uv = pos + vec2(1.0, -1.0);
+ final_pos += rect.yz; /* bottom right */
+ }
+
+ gl_Position = (ModelViewProjectionMatrix * vec4(final_pos, 0.0, 1.0));
}
diff --git a/source/blender/gpu/shaders/gpu_shader_2D_edituvs_edges_vert.glsl b/source/blender/gpu/shaders/gpu_shader_2D_edituvs_edges_vert.glsl
index 0fddbddddc5..5c6b8f0a1a1 100644
--- a/source/blender/gpu/shaders/gpu_shader_2D_edituvs_edges_vert.glsl
+++ b/source/blender/gpu/shaders/gpu_shader_2D_edituvs_edges_vert.glsl
@@ -14,18 +14,18 @@ flat out vec4 finalColor;
/* TODO: Port drawing to draw manager and
* remove constants duplications. */
-#define VERT_UV_SELECT (1 << 3)
-#define EDGE_UV_SELECT (1 << 5)
+#define VERT_UV_SELECT (1 << 3)
+#define EDGE_UV_SELECT (1 << 5)
void main()
{
- gl_Position = ModelViewProjectionMatrix * vec4(pos, 0.0, 1.0);
+ gl_Position = ModelViewProjectionMatrix * vec4(pos, 0.0, 1.0);
#ifdef SMOOTH_COLOR
- bool is_select = (flag & VERT_UV_SELECT) != 0;
+ bool is_select = (flag & VERT_UV_SELECT) != 0;
#else
- bool is_select = (flag & EDGE_UV_SELECT) != 0;
+ bool is_select = (flag & EDGE_UV_SELECT) != 0;
#endif
- finalColor = (is_select) ? selectColor : edgeColor;
+ finalColor = (is_select) ? selectColor : edgeColor;
}
diff --git a/source/blender/gpu/shaders/gpu_shader_2D_edituvs_facedots_vert.glsl b/source/blender/gpu/shaders/gpu_shader_2D_edituvs_facedots_vert.glsl
index e0d168e8095..7a94fc088c4 100644
--- a/source/blender/gpu/shaders/gpu_shader_2D_edituvs_facedots_vert.glsl
+++ b/source/blender/gpu/shaders/gpu_shader_2D_edituvs_facedots_vert.glsl
@@ -10,10 +10,10 @@ out vec4 finalColor;
/* TODO: Port drawing to draw manager and
* remove constants duplications. */
-#define FACE_UV_SELECT (1 << 7)
+#define FACE_UV_SELECT (1 << 7)
void main()
{
- gl_Position = ModelViewProjectionMatrix * vec4(pos, 0.0, 1.0);
- finalColor = ((flag & FACE_UV_SELECT) != 0) ? selectColor : vertColor;
+ gl_Position = ModelViewProjectionMatrix * vec4(pos, 0.0, 1.0);
+ finalColor = ((flag & FACE_UV_SELECT) != 0) ? selectColor : vertColor;
}
diff --git a/source/blender/gpu/shaders/gpu_shader_2D_edituvs_faces_vert.glsl b/source/blender/gpu/shaders/gpu_shader_2D_edituvs_faces_vert.glsl
index 1d25c8fe345..6fc41271cf5 100644
--- a/source/blender/gpu/shaders/gpu_shader_2D_edituvs_faces_vert.glsl
+++ b/source/blender/gpu/shaders/gpu_shader_2D_edituvs_faces_vert.glsl
@@ -11,16 +11,16 @@ flat out vec4 finalColor;
/* TODO: Port drawing to draw manager and
* remove constants duplications. */
-#define FACE_UV_ACTIVE (1 << 6)
-#define FACE_UV_SELECT (1 << 7)
+#define FACE_UV_ACTIVE (1 << 6)
+#define FACE_UV_SELECT (1 << 7)
void main()
{
- gl_Position = ModelViewProjectionMatrix * vec4(pos, 0.0, 1.0);
+ gl_Position = ModelViewProjectionMatrix * vec4(pos, 0.0, 1.0);
- bool is_selected = (flag & FACE_UV_SELECT) != 0;
- bool is_active = (flag & FACE_UV_ACTIVE) != 0;
+ bool is_selected = (flag & FACE_UV_SELECT) != 0;
+ bool is_active = (flag & FACE_UV_ACTIVE) != 0;
- finalColor = (is_selected) ? selectColor : faceColor;
- finalColor = (is_active) ? activeColor : finalColor;
+ finalColor = (is_selected) ? selectColor : faceColor;
+ finalColor = (is_active) ? activeColor : finalColor;
}
diff --git a/source/blender/gpu/shaders/gpu_shader_2D_edituvs_points_vert.glsl b/source/blender/gpu/shaders/gpu_shader_2D_edituvs_points_vert.glsl
index 50166bc4e95..3f3bfa5410c 100644
--- a/source/blender/gpu/shaders/gpu_shader_2D_edituvs_points_vert.glsl
+++ b/source/blender/gpu/shaders/gpu_shader_2D_edituvs_points_vert.glsl
@@ -15,30 +15,30 @@ out vec4 radii;
/* TODO: Port drawing to draw manager and
* remove constants duplications. */
-#define VERT_UV_SELECT (1 << 3)
-#define VERT_UV_PINNED (1 << 4)
+#define VERT_UV_SELECT (1 << 3)
+#define VERT_UV_PINNED (1 << 4)
void main()
{
- gl_Position = ModelViewProjectionMatrix * vec4(pos, 0.0, 1.0);
- gl_PointSize = pointSize;
+ gl_Position = ModelViewProjectionMatrix * vec4(pos, 0.0, 1.0);
+ gl_PointSize = pointSize;
- bool is_selected = (flag & VERT_UV_SELECT) != 0;
- bool is_pinned = (flag & VERT_UV_PINNED) != 0;
+ bool is_selected = (flag & VERT_UV_SELECT) != 0;
+ bool is_pinned = (flag & VERT_UV_PINNED) != 0;
- vec4 deselect_col = (is_pinned) ? pinnedColor : vertColor;
- fillColor = (is_selected) ? selectColor : deselect_col;
- outlineColor = (is_pinned) ? pinnedColor : vec4(fillColor.rgb, 0.0);
+ vec4 deselect_col = (is_pinned) ? pinnedColor : vertColor;
+ fillColor = (is_selected) ? selectColor : deselect_col;
+ outlineColor = (is_pinned) ? pinnedColor : vec4(fillColor.rgb, 0.0);
- // calculate concentric radii in pixels
- float radius = 0.5 * pointSize;
+ // calculate concentric radii in pixels
+ float radius = 0.5 * pointSize;
- // start at the outside and progress toward the center
- radii[0] = radius;
- radii[1] = radius - 1.0;
- radii[2] = radius - outlineWidth;
- radii[3] = radius - outlineWidth - 1.0;
+ // start at the outside and progress toward the center
+ radii[0] = radius;
+ radii[1] = radius - 1.0;
+ radii[2] = radius - outlineWidth;
+ radii[3] = radius - outlineWidth - 1.0;
- // convert to PointCoord units
- radii /= pointSize;
+ // convert to PointCoord units
+ radii /= pointSize;
}
diff --git a/source/blender/gpu/shaders/gpu_shader_2D_edituvs_stretch_vert.glsl b/source/blender/gpu/shaders/gpu_shader_2D_edituvs_stretch_vert.glsl
index c575e06ed3b..810784e2fbc 100644
--- a/source/blender/gpu/shaders/gpu_shader_2D_edituvs_stretch_vert.glsl
+++ b/source/blender/gpu/shaders/gpu_shader_2D_edituvs_stretch_vert.glsl
@@ -16,64 +16,64 @@ noperspective out vec4 finalColor;
vec3 weight_to_rgb(float weight)
{
- vec3 r_rgb;
- float blend = ((weight / 2.0) + 0.5);
+ vec3 r_rgb;
+ float blend = ((weight / 2.0) + 0.5);
- if (weight <= 0.25) { /* blue->cyan */
- r_rgb[0] = 0.0;
- r_rgb[1] = blend * weight * 4.0;
- r_rgb[2] = blend;
- }
- else if (weight <= 0.50) { /* cyan->green */
- r_rgb[0] = 0.0;
- r_rgb[1] = blend;
- r_rgb[2] = blend * (1.0 - ((weight - 0.25) * 4.0));
- }
- else if (weight <= 0.75) { /* green->yellow */
- r_rgb[0] = blend * ((weight - 0.50) * 4.0);
- r_rgb[1] = blend;
- r_rgb[2] = 0.0;
- }
- else if (weight <= 1.0) { /* yellow->red */
- r_rgb[0] = blend;
- r_rgb[1] = blend * (1.0 - ((weight - 0.75) * 4.0));
- r_rgb[2] = 0.0;
- }
- else {
- /* exceptional value, unclamped or nan,
- * avoid uninitialized memory use */
- r_rgb[0] = 1.0;
- r_rgb[1] = 0.0;
- r_rgb[2] = 1.0;
- }
+ if (weight <= 0.25) { /* blue->cyan */
+ r_rgb[0] = 0.0;
+ r_rgb[1] = blend * weight * 4.0;
+ r_rgb[2] = blend;
+ }
+ else if (weight <= 0.50) { /* cyan->green */
+ r_rgb[0] = 0.0;
+ r_rgb[1] = blend;
+ r_rgb[2] = blend * (1.0 - ((weight - 0.25) * 4.0));
+ }
+ else if (weight <= 0.75) { /* green->yellow */
+ r_rgb[0] = blend * ((weight - 0.50) * 4.0);
+ r_rgb[1] = blend;
+ r_rgb[2] = 0.0;
+ }
+ else if (weight <= 1.0) { /* yellow->red */
+ r_rgb[0] = blend;
+ r_rgb[1] = blend * (1.0 - ((weight - 0.75) * 4.0));
+ r_rgb[2] = 0.0;
+ }
+ else {
+ /* exceptional value, unclamped or nan,
+ * avoid uninitialized memory use */
+ r_rgb[0] = 1.0;
+ r_rgb[1] = 0.0;
+ r_rgb[2] = 1.0;
+ }
- return r_rgb;
+ return r_rgb;
}
-#define M_PI 3.1415926535897932
+#define M_PI 3.1415926535897932
/* Adapted from BLI_math_vector.h */
float angle_normalized_v2v2(vec2 v1, vec2 v2)
{
- v1 = normalize(v1 * aspect);
- v2 = normalize(v2 * aspect);
- /* this is the same as acos(dot_v3v3(v1, v2)), but more accurate */
- bool q = (dot(v1, v2) >= 0.0);
- vec2 v = (q) ? (v1 - v2) : (v1 + v2);
- float a = 2.0 * asin(length(v) / 2.0);
- return (q) ? a : M_PI - a;
+ v1 = normalize(v1 * aspect);
+ v2 = normalize(v2 * aspect);
+ /* this is the same as acos(dot_v3v3(v1, v2)), but more accurate */
+ bool q = (dot(v1, v2) >= 0.0);
+ vec2 v = (q) ? (v1 - v2) : (v1 + v2);
+ float a = 2.0 * asin(length(v) / 2.0);
+ return (q) ? a : M_PI - a;
}
void main()
{
- gl_Position = ModelViewProjectionMatrix * vec4(pos, 0.0, 1.0);
+ gl_Position = ModelViewProjectionMatrix * vec4(pos, 0.0, 1.0);
#ifdef STRETCH_ANGLE
- float uv_angle = angle_normalized_v2v2(uv_adj.xy, uv_adj.zw) / M_PI;
- float stretch = 1.0 - abs(uv_angle - angle);
- stretch = stretch;
- stretch = 1.0 - stretch * stretch;
+ float uv_angle = angle_normalized_v2v2(uv_adj.xy, uv_adj.zw) / M_PI;
+ float stretch = 1.0 - abs(uv_angle - angle);
+ stretch = stretch;
+ stretch = 1.0 - stretch * stretch;
#endif
- finalColor = vec4(weight_to_rgb(stretch), 1.0);
+ finalColor = vec4(weight_to_rgb(stretch), 1.0);
}
diff --git a/source/blender/gpu/shaders/gpu_shader_2D_flat_color_vert.glsl b/source/blender/gpu/shaders/gpu_shader_2D_flat_color_vert.glsl
index 769e2b0e37c..df2507c0dc9 100644
--- a/source/blender/gpu/shaders/gpu_shader_2D_flat_color_vert.glsl
+++ b/source/blender/gpu/shaders/gpu_shader_2D_flat_color_vert.glsl
@@ -8,6 +8,6 @@ flat out vec4 finalColor;
void main()
{
- gl_Position = ModelViewProjectionMatrix * vec4(pos, 0.0, 1.0);
- finalColor = color;
+ gl_Position = ModelViewProjectionMatrix * vec4(pos, 0.0, 1.0);
+ finalColor = color;
}
diff --git a/source/blender/gpu/shaders/gpu_shader_2D_image_multi_rect_vert.glsl b/source/blender/gpu/shaders/gpu_shader_2D_image_multi_rect_vert.glsl
index a64f9c375c0..036fc0aaeec 100644
--- a/source/blender/gpu/shaders/gpu_shader_2D_image_multi_rect_vert.glsl
+++ b/source/blender/gpu/shaders/gpu_shader_2D_image_multi_rect_vert.glsl
@@ -13,36 +13,39 @@ flat out vec4 finalColor;
void main()
{
- /* Rendering 2 triangle per icon. */
- int i = gl_VertexID / 6;
- int v = gl_VertexID % 6;
-
- vec4 pos = calls_data[i*3];
- vec4 tex = calls_data[i*3+1];
- finalColor = calls_data[i*3+2];
-
- /* TODO Remove this */
- if (v == 2) v = 4;
- else if (v == 3) v = 0;
- else if (v == 5) v = 2;
-
- if (v == 0) {
- pos.xy = pos.xw;
- tex.xy = tex.xw;
- }
- else if (v == 1) {
- pos.xy = pos.xz;
- tex.xy = tex.xz;
- }
- else if (v == 2) {
- pos.xy = pos.yw;
- tex.xy = tex.yw;
- }
- else {
- pos.xy = pos.yz;
- tex.xy = tex.yz;
- }
-
- gl_Position = vec4(pos.xy, 0.0f, 1.0f);
- texCoord_interp = tex.xy;
+ /* Rendering 2 triangle per icon. */
+ int i = gl_VertexID / 6;
+ int v = gl_VertexID % 6;
+
+ vec4 pos = calls_data[i * 3];
+ vec4 tex = calls_data[i * 3 + 1];
+ finalColor = calls_data[i * 3 + 2];
+
+ /* TODO Remove this */
+ if (v == 2)
+ v = 4;
+ else if (v == 3)
+ v = 0;
+ else if (v == 5)
+ v = 2;
+
+ if (v == 0) {
+ pos.xy = pos.xw;
+ tex.xy = tex.xw;
+ }
+ else if (v == 1) {
+ pos.xy = pos.xz;
+ tex.xy = tex.xz;
+ }
+ else if (v == 2) {
+ pos.xy = pos.yw;
+ tex.xy = tex.yw;
+ }
+ else {
+ pos.xy = pos.yz;
+ tex.xy = tex.yz;
+ }
+
+ gl_Position = vec4(pos.xy, 0.0f, 1.0f);
+ texCoord_interp = tex.xy;
}
diff --git a/source/blender/gpu/shaders/gpu_shader_2D_image_rect_vert.glsl b/source/blender/gpu/shaders/gpu_shader_2D_image_rect_vert.glsl
index 015082186b5..fcd877a37eb 100644
--- a/source/blender/gpu/shaders/gpu_shader_2D_image_rect_vert.glsl
+++ b/source/blender/gpu/shaders/gpu_shader_2D_image_rect_vert.glsl
@@ -11,25 +11,25 @@ out vec2 texCoord_interp;
void main()
{
- vec2 uv;
- vec2 co;
- if (gl_VertexID == 0) {
- co = rect_geom.xw;
- uv = rect_icon.xw;
- }
- else if (gl_VertexID == 1) {
- co = rect_geom.xy;
- uv = rect_icon.xy;
- }
- else if (gl_VertexID == 2) {
- co = rect_geom.zw;
- uv = rect_icon.zw;
- }
- else {
- co = rect_geom.zy;
- uv = rect_icon.zy;
- }
+ vec2 uv;
+ vec2 co;
+ if (gl_VertexID == 0) {
+ co = rect_geom.xw;
+ uv = rect_icon.xw;
+ }
+ else if (gl_VertexID == 1) {
+ co = rect_geom.xy;
+ uv = rect_icon.xy;
+ }
+ else if (gl_VertexID == 2) {
+ co = rect_geom.zw;
+ uv = rect_icon.zw;
+ }
+ else {
+ co = rect_geom.zy;
+ uv = rect_icon.zy;
+ }
- gl_Position = ModelViewProjectionMatrix * vec4(co, 0.0f, 1.0f);
- texCoord_interp = uv;
+ gl_Position = ModelViewProjectionMatrix * vec4(co, 0.0f, 1.0f);
+ texCoord_interp = uv;
}
diff --git a/source/blender/gpu/shaders/gpu_shader_2D_image_vert.glsl b/source/blender/gpu/shaders/gpu_shader_2D_image_vert.glsl
index 0881f2b150f..cdb066c9c52 100644
--- a/source/blender/gpu/shaders/gpu_shader_2D_image_vert.glsl
+++ b/source/blender/gpu/shaders/gpu_shader_2D_image_vert.glsl
@@ -8,7 +8,7 @@ out vec2 texCoord_interp;
void main()
{
- gl_Position = ModelViewProjectionMatrix * vec4(pos.xy, 0.0f, 1.0f);
- gl_Position.z = 1.0;
- texCoord_interp = texCoord;
+ gl_Position = ModelViewProjectionMatrix * vec4(pos.xy, 0.0f, 1.0f);
+ gl_Position.z = 1.0;
+ texCoord_interp = texCoord;
}
diff --git a/source/blender/gpu/shaders/gpu_shader_2D_line_dashed_frag.glsl b/source/blender/gpu/shaders/gpu_shader_2D_line_dashed_frag.glsl
index 3c5b0d1ca0a..185a4c8c59f 100644
--- a/source/blender/gpu/shaders/gpu_shader_2D_line_dashed_frag.glsl
+++ b/source/blender/gpu/shaders/gpu_shader_2D_line_dashed_frag.glsl
@@ -8,11 +8,11 @@
uniform float dash_width;
/* Simple mode, discarding non-dash parts (so no need for blending at all). */
-uniform float dash_factor; /* if > 1.0, solid line. */
+uniform float dash_factor; /* if > 1.0, solid line. */
/* More advanced mode, allowing for complex, multi-colored patterns. Enabled when colors_len > 0. */
/* Note: max number of steps/colors in pattern is 32! */
-uniform int colors_len; /* Enabled if > 0, 1 for solid line. */
+uniform int colors_len; /* Enabled if > 0, 1 for solid line. */
uniform vec4 colors[32];
noperspective in float distance_along_line;
@@ -22,33 +22,33 @@ out vec4 fragColor;
void main()
{
- /* Multi-color option. */
- if (colors_len > 0) {
- /* Solid line case, simple. */
- if (colors_len == 1) {
- fragColor = colors[0];
- }
- /* Actually dashed line... */
- else {
- float normalized_distance = fract(distance_along_line / dash_width);
- fragColor = colors[int(normalized_distance * colors_len)];
- }
- }
- /* Single color option. */
- else {
- /* Solid line case, simple. */
- if (dash_factor >= 1.0f) {
- fragColor = color_geom;
- }
- /* Actually dashed line... */
- else {
- float normalized_distance = fract(distance_along_line / dash_width);
- if (normalized_distance <= dash_factor) {
- fragColor = color_geom;
- }
- else {
- discard;
- }
- }
- }
+ /* Multi-color option. */
+ if (colors_len > 0) {
+ /* Solid line case, simple. */
+ if (colors_len == 1) {
+ fragColor = colors[0];
+ }
+ /* Actually dashed line... */
+ else {
+ float normalized_distance = fract(distance_along_line / dash_width);
+ fragColor = colors[int(normalized_distance * colors_len)];
+ }
+ }
+ /* Single color option. */
+ else {
+ /* Solid line case, simple. */
+ if (dash_factor >= 1.0f) {
+ fragColor = color_geom;
+ }
+ /* Actually dashed line... */
+ else {
+ float normalized_distance = fract(distance_along_line / dash_width);
+ if (normalized_distance <= dash_factor) {
+ fragColor = color_geom;
+ }
+ else {
+ discard;
+ }
+ }
+ }
}
diff --git a/source/blender/gpu/shaders/gpu_shader_2D_line_dashed_geom.glsl b/source/blender/gpu/shaders/gpu_shader_2D_line_dashed_geom.glsl
index 1e5a75c37b8..11f67172e89 100644
--- a/source/blender/gpu/shaders/gpu_shader_2D_line_dashed_geom.glsl
+++ b/source/blender/gpu/shaders/gpu_shader_2D_line_dashed_geom.glsl
@@ -5,14 +5,13 @@
* Dashed is performed in screen space.
*/
-
/* Make to be used with dynamic batching so no Model Matrix needed */
uniform mat4 ModelViewProjectionMatrix;
uniform vec2 viewport_size;
/* Uniforms from fragment shader, used here to optimize out useless computation in case of solid line. */
-uniform float dash_factor; /* if > 1.0, solid line. */
-uniform int colors_len; /* Enabled if > 0, 1 for solid line. */
+uniform float dash_factor; /* if > 1.0, solid line. */
+uniform int colors_len; /* Enabled if > 0, 1 for solid line. */
layout(lines) in;
@@ -24,41 +23,41 @@ noperspective out vec4 color_geom;
void main()
{
- vec4 v1 = gl_in[0].gl_Position;
- vec4 v2 = gl_in[1].gl_Position;
+ vec4 v1 = gl_in[0].gl_Position;
+ vec4 v2 = gl_in[1].gl_Position;
- gl_Position = v1;
- color_geom = color_vert[0];
- distance_along_line = 0.0f;
+ gl_Position = v1;
+ color_geom = color_vert[0];
+ distance_along_line = 0.0f;
#ifdef USE_WORLD_CLIP_PLANES
- world_clip_planes_set_clip_distance(gl_in[0].gl_ClipDistance);
+ world_clip_planes_set_clip_distance(gl_in[0].gl_ClipDistance);
#endif
- EmitVertex();
+ EmitVertex();
- gl_Position = v2;
- color_geom = color_vert[1];
- if ((colors_len == 1) || (dash_factor >= 1.0f)) {
- /* Solid line, optimize out distance computation! */
- distance_along_line = 0.0f;
- }
- else {
- vec2 p1 = (v1.xy / v1.w) * 0.5 + 0.5; // <- device coordinates in [0..1] range.
- p1 = p1 * viewport_size; // <- 'virtual' screen coordinates.
+ gl_Position = v2;
+ color_geom = color_vert[1];
+ if ((colors_len == 1) || (dash_factor >= 1.0f)) {
+ /* Solid line, optimize out distance computation! */
+ distance_along_line = 0.0f;
+ }
+ else {
+ vec2 p1 = (v1.xy / v1.w) * 0.5 + 0.5; // <- device coordinates in [0..1] range.
+ p1 = p1 * viewport_size; // <- 'virtual' screen coordinates.
- vec2 p2 = (v2.xy / v2.w) * 0.5 + 0.5; // <- device coordinates in [0..1] range.
- p2 = p2 * viewport_size; // <- 'virtual' screen coordinates.
+ vec2 p2 = (v2.xy / v2.w) * 0.5 + 0.5; // <- device coordinates in [0..1] range.
+ p2 = p2 * viewport_size; // <- 'virtual' screen coordinates.
- distance_along_line = distance(p1, p2);
- }
+ distance_along_line = distance(p1, p2);
+ }
#ifdef USE_WORLD_CLIP_PLANES
- world_clip_planes_set_clip_distance(gl_in[1].gl_ClipDistance);
+ world_clip_planes_set_clip_distance(gl_in[1].gl_ClipDistance);
#endif
- EmitVertex();
+ EmitVertex();
- EndPrimitive();
+ EndPrimitive();
- /* Note: we could also use similar approach as diag_stripes_frag, but this would give us dashed 'anchored'
- * to the screen, and not to one end of the line... */
+ /* Note: we could also use similar approach as diag_stripes_frag, but this would give us dashed 'anchored'
+ * to the screen, and not to one end of the line... */
}
diff --git a/source/blender/gpu/shaders/gpu_shader_2D_line_dashed_uniform_color_vert.glsl b/source/blender/gpu/shaders/gpu_shader_2D_line_dashed_uniform_color_vert.glsl
index f5c611586aa..933a0976c6e 100644
--- a/source/blender/gpu/shaders/gpu_shader_2D_line_dashed_uniform_color_vert.glsl
+++ b/source/blender/gpu/shaders/gpu_shader_2D_line_dashed_uniform_color_vert.glsl
@@ -16,6 +16,6 @@ out vec4 color_vert;
void main()
{
- gl_Position = ModelViewProjectionMatrix * vec4(pos, 0.0, 1.0);
- color_vert = color;
+ gl_Position = ModelViewProjectionMatrix * vec4(pos, 0.0, 1.0);
+ color_vert = color;
}
diff --git a/source/blender/gpu/shaders/gpu_shader_2D_line_dashed_width_geom.glsl b/source/blender/gpu/shaders/gpu_shader_2D_line_dashed_width_geom.glsl
index 5a4da5cc9d4..434917f8052 100644
--- a/source/blender/gpu/shaders/gpu_shader_2D_line_dashed_width_geom.glsl
+++ b/source/blender/gpu/shaders/gpu_shader_2D_line_dashed_width_geom.glsl
@@ -6,11 +6,11 @@ uniform mat4 ModelViewProjectionMatrix;
uniform vec2 viewport_size;
/* Width of the generated 'line'. */
-uniform float width; /* in pixels, screen space. */
+uniform float width; /* in pixels, screen space. */
/* Uniforms from fragment shader, used here to optimize out useless computation in case of solid line. */
-uniform float dash_factor; /* if > 1.0, solid line. */
-uniform int colors_len; /* Enabled if > 0, 1 for solid line. */
+uniform float dash_factor; /* if > 1.0, solid line. */
+uniform int colors_len; /* Enabled if > 0, 1 for solid line. */
layout(lines) in;
@@ -19,41 +19,41 @@ noperspective out float distance_along_line;
void main()
{
- vec4 v1 = gl_in[0].gl_Position;
- vec4 v2 = gl_in[1].gl_Position;
+ vec4 v1 = gl_in[0].gl_Position;
+ vec4 v2 = gl_in[1].gl_Position;
- /* Width, from 2D screen space in pixels, to ModelViewProjection space of each input vertices. */
- float w1 = (width / viewport_size) * v1.w * 2.0;
- float w2 = (width / viewport_size) * v2.w * 2.0;
+ /* Width, from 2D screen space in pixels, to ModelViewProjection space of each input vertices. */
+ float w1 = (width / viewport_size) * v1.w * 2.0;
+ float w2 = (width / viewport_size) * v2.w * 2.0;
- /* Normalized vector parallel to screen and orthogonal to line. */
- vec4 wdir = normalize(vec4(v1.y - v2.y, v2.x - v1.x, 0.0, 0.0))
+ /* Normalized vector parallel to screen and orthogonal to line. */
+ vec4 wdir = normalize(vec4(v1.y - v2.y, v2.x - v1.x, 0.0, 0.0))
- distance_along_line = 0.0f;
- gl_Position = v1 + (wdir * w1);
- EmitVertex();
+ distance_along_line = 0.0f;
+ gl_Position = v1 + (wdir * w1);
+ EmitVertex();
- gl_Position = v1 - (wdir * w1);
- EmitVertex();
+ gl_Position = v1 - (wdir * w1);
+ EmitVertex();
- if ((colors_len == 1) || (dash_factor >= 1.0f)) {
- /* Solid line, optimize out distance computation! */
- distance_along_line = 0.0f;
- }
- else {
- vec2 p1 = (v1.xy / v1.w) * 0.5 + 0.5; // <- device coordinates in [0..1] range.
- p1 = p1 * viewport_size; // <- 'virtual' screen coordinates.
+ if ((colors_len == 1) || (dash_factor >= 1.0f)) {
+ /* Solid line, optimize out distance computation! */
+ distance_along_line = 0.0f;
+ }
+ else {
+ vec2 p1 = (v1.xy / v1.w) * 0.5 + 0.5; // <- device coordinates in [0..1] range.
+ p1 = p1 * viewport_size; // <- 'virtual' screen coordinates.
- vec2 p2 = (v2.xy / v2.w) * 0.5 + 0.5; // <- device coordinates in [0..1] range.
- p2 = p2 * viewport_size; // <- 'virtual' screen coordinates.
+ vec2 p2 = (v2.xy / v2.w) * 0.5 + 0.5; // <- device coordinates in [0..1] range.
+ p2 = p2 * viewport_size; // <- 'virtual' screen coordinates.
- distance_along_line = distance(p1, p2);
- }
- gl_Position = v2 + (wdir * w2);
- EmitVertex();
+ distance_along_line = distance(p1, p2);
+ }
+ gl_Position = v2 + (wdir * w2);
+ EmitVertex();
- gl_Position = v2 - (wdir * w2);
- EmitVertex();
+ gl_Position = v2 - (wdir * w2);
+ EmitVertex();
- EndPrimitive();
+ EndPrimitive();
}
diff --git a/source/blender/gpu/shaders/gpu_shader_2D_nodelink_frag.glsl b/source/blender/gpu/shaders/gpu_shader_2D_nodelink_frag.glsl
index 1497f9eeeb1..f07bd7f1d6f 100644
--- a/source/blender/gpu/shaders/gpu_shader_2D_nodelink_frag.glsl
+++ b/source/blender/gpu/shaders/gpu_shader_2D_nodelink_frag.glsl
@@ -4,7 +4,8 @@ in vec4 finalColor;
out vec4 fragColor;
-void main() {
- fragColor = finalColor;
- fragColor.a *= smoothstep(1.0, 0.1, abs(colorGradient));
+void main()
+{
+ fragColor = finalColor;
+ fragColor.a *= smoothstep(1.0, 0.1, abs(colorGradient));
}
diff --git a/source/blender/gpu/shaders/gpu_shader_2D_nodelink_vert.glsl b/source/blender/gpu/shaders/gpu_shader_2D_nodelink_vert.glsl
index 220adba817a..4567429f645 100644
--- a/source/blender/gpu/shaders/gpu_shader_2D_nodelink_vert.glsl
+++ b/source/blender/gpu/shaders/gpu_shader_2D_nodelink_vert.glsl
@@ -20,26 +20,26 @@ in ivec4 colid_doarrow;
uniform vec4 colors[6];
-#define colStart colors[colid_doarrow[0]]
-#define colEnd colors[colid_doarrow[1]]
-#define colShadow colors[colid_doarrow[2]]
-#define doArrow (colid_doarrow[3] != 0)
+# define colStart colors[colid_doarrow[0]]
+# define colEnd colors[colid_doarrow[1]]
+# define colShadow colors[colid_doarrow[2]]
+# define doArrow (colid_doarrow[3] != 0)
#else
/* Single curve drawcall, use uniform. */
uniform vec2 bezierPts[4];
-#define P0 bezierPts[0]
-#define P1 bezierPts[1]
-#define P2 bezierPts[2]
-#define P3 bezierPts[3]
+# define P0 bezierPts[0]
+# define P1 bezierPts[1]
+# define P2 bezierPts[2]
+# define P3 bezierPts[3]
uniform vec4 colors[3];
uniform bool doArrow;
-#define colShadow colors[0]
-#define colStart colors[1]
-#define colEnd colors[2]
+# define colShadow colors[0]
+# define colStart colors[1]
+# define colEnd colors[2]
#endif
@@ -52,56 +52,51 @@ out vec4 finalColor;
void main(void)
{
- float t = uv.x;
- float t2 = t * t;
- float t2_3 = 3.0 * t2;
- float one_minus_t = 1.0 - t;
- float one_minus_t2 = one_minus_t * one_minus_t;
- float one_minus_t2_3 = 3.0 * one_minus_t2;
-
- vec2 point = (P0 * one_minus_t2 * one_minus_t +
- P1 * one_minus_t2_3 * t +
- P2 * t2_3 * one_minus_t +
- P3 * t2 * t);
-
- vec2 tangent = ((P1 - P0) * one_minus_t2_3 +
- (P2 - P1) * 6.0 * (t - t2) +
- (P3 - P2) * t2_3);
-
- /* tangent space at t */
- tangent = normalize(tangent);
- vec2 normal = tangent.yx * vec2(-1.0, 1.0);
-
- /* Position vertex on the curve tangent space */
- point += (pos.x * tangent + pos.y * normal) * arrowSize;
-
- gl_Position = ModelViewProjectionMatrix * vec4(point, 0.0, 1.0);
-
- vec2 exp_axis = expand.x * tangent + expand.y * normal;
-
- /* rotate & scale the expand axis */
- exp_axis = ModelViewProjectionMatrix[0].xy * exp_axis.xx +
- ModelViewProjectionMatrix[1].xy * exp_axis.yy;
-
-
- float expand_dist = (uv.y * 2.0 - 1.0);
- colorGradient = expand_dist;
-
- if (gl_VertexID < MID_VERTEX) {
- /* Shadow pass */
- finalColor = colShadow;
- }
- else {
- /* Second pass */
- finalColor = mix(colStart, colEnd, uv.x);
- expand_dist *= 0.5;
- }
-
- /* Expand into a line */
- gl_Position.xy += exp_axis * expandSize * expand_dist;
-
- /* if arrow */
- if (expand.y != 1.0 && !doArrow) {
- gl_Position.xy *= 0.0;
- }
+ float t = uv.x;
+ float t2 = t * t;
+ float t2_3 = 3.0 * t2;
+ float one_minus_t = 1.0 - t;
+ float one_minus_t2 = one_minus_t * one_minus_t;
+ float one_minus_t2_3 = 3.0 * one_minus_t2;
+
+ vec2 point = (P0 * one_minus_t2 * one_minus_t + P1 * one_minus_t2_3 * t +
+ P2 * t2_3 * one_minus_t + P3 * t2 * t);
+
+ vec2 tangent = ((P1 - P0) * one_minus_t2_3 + (P2 - P1) * 6.0 * (t - t2) + (P3 - P2) * t2_3);
+
+ /* tangent space at t */
+ tangent = normalize(tangent);
+ vec2 normal = tangent.yx * vec2(-1.0, 1.0);
+
+ /* Position vertex on the curve tangent space */
+ point += (pos.x * tangent + pos.y * normal) * arrowSize;
+
+ gl_Position = ModelViewProjectionMatrix * vec4(point, 0.0, 1.0);
+
+ vec2 exp_axis = expand.x * tangent + expand.y * normal;
+
+ /* rotate & scale the expand axis */
+ exp_axis = ModelViewProjectionMatrix[0].xy * exp_axis.xx +
+ ModelViewProjectionMatrix[1].xy * exp_axis.yy;
+
+ float expand_dist = (uv.y * 2.0 - 1.0);
+ colorGradient = expand_dist;
+
+ if (gl_VertexID < MID_VERTEX) {
+ /* Shadow pass */
+ finalColor = colShadow;
+ }
+ else {
+ /* Second pass */
+ finalColor = mix(colStart, colEnd, uv.x);
+ expand_dist *= 0.5;
+ }
+
+ /* Expand into a line */
+ gl_Position.xy += exp_axis * expandSize * expand_dist;
+
+ /* if arrow */
+ if (expand.y != 1.0 && !doArrow) {
+ gl_Position.xy *= 0.0;
+ }
}
diff --git a/source/blender/gpu/shaders/gpu_shader_2D_point_uniform_size_aa_vert.glsl b/source/blender/gpu/shaders/gpu_shader_2D_point_uniform_size_aa_vert.glsl
index 1f833cfb7be..a7681353d49 100644
--- a/source/blender/gpu/shaders/gpu_shader_2D_point_uniform_size_aa_vert.glsl
+++ b/source/blender/gpu/shaders/gpu_shader_2D_point_uniform_size_aa_vert.glsl
@@ -5,17 +5,18 @@ uniform float size;
in vec2 pos;
out vec2 radii;
-void main() {
- gl_Position = ModelViewProjectionMatrix * vec4(pos, 0.0, 1.0);
- gl_PointSize = size;
+void main()
+{
+ gl_Position = ModelViewProjectionMatrix * vec4(pos, 0.0, 1.0);
+ gl_PointSize = size;
- // calculate concentric radii in pixels
- float radius = 0.5 * size;
+ // calculate concentric radii in pixels
+ float radius = 0.5 * size;
- // start at the outside and progress toward the center
- radii[0] = radius;
- radii[1] = radius - 1.0;
+ // start at the outside and progress toward the center
+ radii[0] = radius;
+ radii[1] = radius - 1.0;
- // convert to PointCoord units
- radii /= size;
+ // convert to PointCoord units
+ radii /= size;
}
diff --git a/source/blender/gpu/shaders/gpu_shader_2D_point_uniform_size_outline_aa_vert.glsl b/source/blender/gpu/shaders/gpu_shader_2D_point_uniform_size_outline_aa_vert.glsl
index 99bdeb22904..a3439ebe3c4 100644
--- a/source/blender/gpu/shaders/gpu_shader_2D_point_uniform_size_outline_aa_vert.glsl
+++ b/source/blender/gpu/shaders/gpu_shader_2D_point_uniform_size_outline_aa_vert.glsl
@@ -6,19 +6,20 @@ uniform float outlineWidth;
in vec2 pos;
out vec4 radii;
-void main() {
- gl_Position = ModelViewProjectionMatrix * vec4(pos, 0.0, 1.0);
- gl_PointSize = size;
+void main()
+{
+ gl_Position = ModelViewProjectionMatrix * vec4(pos, 0.0, 1.0);
+ gl_PointSize = size;
- // calculate concentric radii in pixels
- float radius = 0.5 * size;
+ // calculate concentric radii in pixels
+ float radius = 0.5 * size;
- // start at the outside and progress toward the center
- radii[0] = radius;
- radii[1] = radius - 1.0;
- radii[2] = radius - outlineWidth;
- radii[3] = radius - outlineWidth - 1.0;
+ // start at the outside and progress toward the center
+ radii[0] = radius;
+ radii[1] = radius - 1.0;
+ radii[2] = radius - outlineWidth;
+ radii[3] = radius - outlineWidth - 1.0;
- // convert to PointCoord units
- radii /= size;
+ // convert to PointCoord units
+ radii /= size;
}
diff --git a/source/blender/gpu/shaders/gpu_shader_2D_point_uniform_size_varying_color_outline_aa_vert.glsl b/source/blender/gpu/shaders/gpu_shader_2D_point_uniform_size_varying_color_outline_aa_vert.glsl
index 5fad95236df..287bd351534 100644
--- a/source/blender/gpu/shaders/gpu_shader_2D_point_uniform_size_varying_color_outline_aa_vert.glsl
+++ b/source/blender/gpu/shaders/gpu_shader_2D_point_uniform_size_varying_color_outline_aa_vert.glsl
@@ -8,20 +8,21 @@ in vec4 color;
out vec4 radii;
out vec4 fillColor;
-void main() {
- gl_Position = ModelViewProjectionMatrix * vec4(pos, 0.0, 1.0);
- gl_PointSize = size;
- fillColor = color;
+void main()
+{
+ gl_Position = ModelViewProjectionMatrix * vec4(pos, 0.0, 1.0);
+ gl_PointSize = size;
+ fillColor = color;
- // calculate concentric radii in pixels
- float radius = 0.5 * size;
+ // calculate concentric radii in pixels
+ float radius = 0.5 * size;
- // start at the outside and progress toward the center
- radii[0] = radius;
- radii[1] = radius - 1.0;
- radii[2] = radius - outlineWidth;
- radii[3] = radius - outlineWidth - 1.0;
+ // start at the outside and progress toward the center
+ radii[0] = radius;
+ radii[1] = radius - 1.0;
+ radii[2] = radius - outlineWidth;
+ radii[3] = radius - outlineWidth - 1.0;
- // convert to PointCoord units
- radii /= size;
+ // convert to PointCoord units
+ radii /= size;
}
diff --git a/source/blender/gpu/shaders/gpu_shader_2D_point_varying_size_varying_color_vert.glsl b/source/blender/gpu/shaders/gpu_shader_2D_point_varying_size_varying_color_vert.glsl
index d6aacf0cdc5..469370b9173 100644
--- a/source/blender/gpu/shaders/gpu_shader_2D_point_varying_size_varying_color_vert.glsl
+++ b/source/blender/gpu/shaders/gpu_shader_2D_point_varying_size_varying_color_vert.glsl
@@ -8,7 +8,7 @@ out vec4 finalColor;
void main()
{
- gl_Position = ModelViewProjectionMatrix * vec4(pos, 0.0, 1.0);
- gl_PointSize = size;
- finalColor = color;
+ gl_Position = ModelViewProjectionMatrix * vec4(pos, 0.0, 1.0);
+ gl_PointSize = size;
+ finalColor = color;
}
diff --git a/source/blender/gpu/shaders/gpu_shader_2D_smooth_color_dithered_frag.glsl b/source/blender/gpu/shaders/gpu_shader_2D_smooth_color_dithered_frag.glsl
index 145ed16248a..181b1bf3fad 100644
--- a/source/blender/gpu/shaders/gpu_shader_2D_smooth_color_dithered_frag.glsl
+++ b/source/blender/gpu/shaders/gpu_shader_2D_smooth_color_dithered_frag.glsl
@@ -4,17 +4,15 @@ out vec4 fragColor;
/* 4x4 bayer matrix prepared for 8bit UNORM precision error. */
#define P(x) (((x + 0.5) * (1.0 / 16.0) - 0.5) * (1.0 / 255.0))
-const vec4 dither_mat4x4[4] = vec4[4](
- vec4( P(0.0), P(8.0), P(2.0), P(10.0)),
- vec4(P(12.0), P(4.0), P(14.0), P(6.0)),
- vec4( P(3.0), P(11.0), P(1.0), P(9.0)),
- vec4(P(15.0), P(7.0), P(13.0), P(5.0))
-);
+const vec4 dither_mat4x4[4] = vec4[4](vec4(P(0.0), P(8.0), P(2.0), P(10.0)),
+ vec4(P(12.0), P(4.0), P(14.0), P(6.0)),
+ vec4(P(3.0), P(11.0), P(1.0), P(9.0)),
+ vec4(P(15.0), P(7.0), P(13.0), P(5.0)));
void main()
{
- ivec2 tx1 = ivec2(gl_FragCoord.xy) % 4;
- ivec2 tx2 = ivec2(gl_FragCoord.xy) % 2;
- float dither_noise = dither_mat4x4[tx1.x][tx1.y];
- fragColor = finalColor + dither_noise;
+ ivec2 tx1 = ivec2(gl_FragCoord.xy) % 4;
+ ivec2 tx2 = ivec2(gl_FragCoord.xy) % 2;
+ float dither_noise = dither_mat4x4[tx1.x][tx1.y];
+ fragColor = finalColor + dither_noise;
}
diff --git a/source/blender/gpu/shaders/gpu_shader_2D_smooth_color_frag.glsl b/source/blender/gpu/shaders/gpu_shader_2D_smooth_color_frag.glsl
index 4a4bfb6a616..4f275c5b220 100644
--- a/source/blender/gpu/shaders/gpu_shader_2D_smooth_color_frag.glsl
+++ b/source/blender/gpu/shaders/gpu_shader_2D_smooth_color_frag.glsl
@@ -4,5 +4,5 @@ out vec4 fragColor;
void main()
{
- fragColor = finalColor;
+ fragColor = finalColor;
}
diff --git a/source/blender/gpu/shaders/gpu_shader_2D_smooth_color_vert.glsl b/source/blender/gpu/shaders/gpu_shader_2D_smooth_color_vert.glsl
index fe91f4d0902..fcf436d50af 100644
--- a/source/blender/gpu/shaders/gpu_shader_2D_smooth_color_vert.glsl
+++ b/source/blender/gpu/shaders/gpu_shader_2D_smooth_color_vert.glsl
@@ -8,6 +8,6 @@ noperspective out vec4 finalColor;
void main()
{
- gl_Position = ModelViewProjectionMatrix * vec4(pos, 0.0, 1.0);
- finalColor = color;
+ gl_Position = ModelViewProjectionMatrix * vec4(pos, 0.0, 1.0);
+ finalColor = color;
}
diff --git a/source/blender/gpu/shaders/gpu_shader_2D_vert.glsl b/source/blender/gpu/shaders/gpu_shader_2D_vert.glsl
index b3b897da3c6..de6547715f3 100644
--- a/source/blender/gpu/shaders/gpu_shader_2D_vert.glsl
+++ b/source/blender/gpu/shaders/gpu_shader_2D_vert.glsl
@@ -10,5 +10,5 @@ in vec2 pos;
void main()
{
- gl_Position = ModelViewProjectionMatrix * vec4(pos, 0.0, 1.0);
+ gl_Position = ModelViewProjectionMatrix * vec4(pos, 0.0, 1.0);
}
diff --git a/source/blender/gpu/shaders/gpu_shader_2D_widget_base_frag.glsl b/source/blender/gpu/shaders/gpu_shader_2D_widget_base_frag.glsl
index a356014d025..18f58d52f32 100644
--- a/source/blender/gpu/shaders/gpu_shader_2D_widget_base_frag.glsl
+++ b/source/blender/gpu/shaders/gpu_shader_2D_widget_base_frag.glsl
@@ -8,33 +8,31 @@ out vec4 fragColor;
vec4 do_checkerboard()
{
- float size = checkerColorAndSize.z;
- vec2 phase = mod(gl_FragCoord.xy, size * 2.0);
-
- if ((phase.x > size && phase.y < size) ||
- (phase.x < size && phase.y > size))
- {
- return vec4(checkerColorAndSize.xxx, 1.0);
- }
- else {
- return vec4(checkerColorAndSize.yyy, 1.0);
- }
+ float size = checkerColorAndSize.z;
+ vec2 phase = mod(gl_FragCoord.xy, size * 2.0);
+
+ if ((phase.x > size && phase.y < size) || (phase.x < size && phase.y > size)) {
+ return vec4(checkerColorAndSize.xxx, 1.0);
+ }
+ else {
+ return vec4(checkerColorAndSize.yyy, 1.0);
+ }
}
void main()
{
- if (min(1.0, -butCo) > discardFac) {
- discard;
- }
+ if (min(1.0, -butCo) > discardFac) {
+ discard;
+ }
- fragColor = finalColor;
+ fragColor = finalColor;
- if (butCo > 0.5) {
- vec4 checker = do_checkerboard();
- fragColor = mix(checker, fragColor, fragColor.a);
- }
+ if (butCo > 0.5) {
+ vec4 checker = do_checkerboard();
+ fragColor = mix(checker, fragColor, fragColor.a);
+ }
- if (butCo > 0.0) {
- fragColor.a = 1.0;
- }
+ if (butCo > 0.0) {
+ fragColor.a = 1.0;
+ }
}
diff --git a/source/blender/gpu/shaders/gpu_shader_2D_widget_base_vert.glsl b/source/blender/gpu/shaders/gpu_shader_2D_widget_base_vert.glsl
index ff51e0266d7..e17c5cda000 100644
--- a/source/blender/gpu/shaders/gpu_shader_2D_widget_base_vert.glsl
+++ b/source/blender/gpu/shaders/gpu_shader_2D_widget_base_vert.glsl
@@ -12,38 +12,70 @@
/* 4bits for corner id */
#define CORNER_VEC_OFS 2u
#define CORNER_VEC_RANGE BIT_RANGE(4)
-const vec2 cornervec[36] = vec2[36](
- vec2(0.0, 1.0), vec2(0.02, 0.805), vec2(0.067, 0.617), vec2(0.169, 0.45), vec2(0.293, 0.293), vec2(0.45, 0.169), vec2(0.617, 0.076), vec2(0.805, 0.02), vec2(1.0, 0.0),
- vec2(-1.0, 0.0), vec2(-0.805, 0.02), vec2(-0.617, 0.067), vec2(-0.45, 0.169), vec2(-0.293, 0.293), vec2(-0.169, 0.45), vec2(-0.076, 0.617), vec2(-0.02, 0.805), vec2(0.0, 1.0),
- vec2(0.0, -1.0), vec2(-0.02, -0.805), vec2(-0.067, -0.617), vec2(-0.169, -0.45), vec2(-0.293, -0.293), vec2(-0.45, -0.169), vec2(-0.617, -0.076), vec2(-0.805, -0.02), vec2(-1.0, 0.0),
- vec2(1.0, 0.0), vec2(0.805, -0.02), vec2(0.617, -0.067), vec2(0.45, -0.169), vec2(0.293, -0.293), vec2(0.169, -0.45), vec2(0.076, -0.617), vec2(0.02, -0.805), vec2(0.0, -1.0)
-);
+const vec2 cornervec[36] = vec2[36](vec2(0.0, 1.0),
+ vec2(0.02, 0.805),
+ vec2(0.067, 0.617),
+ vec2(0.169, 0.45),
+ vec2(0.293, 0.293),
+ vec2(0.45, 0.169),
+ vec2(0.617, 0.076),
+ vec2(0.805, 0.02),
+ vec2(1.0, 0.0),
+ vec2(-1.0, 0.0),
+ vec2(-0.805, 0.02),
+ vec2(-0.617, 0.067),
+ vec2(-0.45, 0.169),
+ vec2(-0.293, 0.293),
+ vec2(-0.169, 0.45),
+ vec2(-0.076, 0.617),
+ vec2(-0.02, 0.805),
+ vec2(0.0, 1.0),
+ vec2(0.0, -1.0),
+ vec2(-0.02, -0.805),
+ vec2(-0.067, -0.617),
+ vec2(-0.169, -0.45),
+ vec2(-0.293, -0.293),
+ vec2(-0.45, -0.169),
+ vec2(-0.617, -0.076),
+ vec2(-0.805, -0.02),
+ vec2(-1.0, 0.0),
+ vec2(1.0, 0.0),
+ vec2(0.805, -0.02),
+ vec2(0.617, -0.067),
+ vec2(0.45, -0.169),
+ vec2(0.293, -0.293),
+ vec2(0.169, -0.45),
+ vec2(0.076, -0.617),
+ vec2(0.02, -0.805),
+ vec2(0.0, -1.0));
/* 4bits for jitter id */
#define JIT_OFS 6u
#define JIT_RANGE BIT_RANGE(4)
-const vec2 jit[9] = vec2[9](
- vec2( 0.468813, -0.481430), vec2(-0.155755, -0.352820),
- vec2( 0.219306, -0.238501), vec2(-0.393286, -0.110949),
- vec2(-0.024699, 0.013908), vec2( 0.343805, 0.147431),
- vec2(-0.272855, 0.269918), vec2( 0.095909, 0.388710),
- vec2( 0.0, 0.0)
-);
+const vec2 jit[9] = vec2[9](vec2(0.468813, -0.481430),
+ vec2(-0.155755, -0.352820),
+ vec2(0.219306, -0.238501),
+ vec2(-0.393286, -0.110949),
+ vec2(-0.024699, 0.013908),
+ vec2(0.343805, 0.147431),
+ vec2(-0.272855, 0.269918),
+ vec2(0.095909, 0.388710),
+ vec2(0.0, 0.0));
/* 2bits for other flags */
-#define INNER_FLAG uint(1 << 10) /* is inner vert */
-#define EMBOSS_FLAG uint(1 << 11) /* is emboss vert */
+#define INNER_FLAG uint(1 << 10) /* is inner vert */
+#define EMBOSS_FLAG uint(1 << 11) /* is emboss vert */
/* 2bits for color */
#define COLOR_OFS 12u
#define COLOR_RANGE BIT_RANGE(2)
-#define COLOR_INNER 0u
-#define COLOR_EDGE 1u
-#define COLOR_EMBOSS 2u
+#define COLOR_INNER 0u
+#define COLOR_EDGE 1u
+#define COLOR_EMBOSS 2u
/* 2bits for trias type */
-#define TRIA_FLAG uint(1 << 14) /* is tria vert */
-#define TRIA_FIRST INNER_FLAG /* is first tria (reuse INNER_FLAG) */
+#define TRIA_FLAG uint(1 << 14) /* is tria vert */
+#define TRIA_FIRST INNER_FLAG /* is first tria (reuse INNER_FLAG) */
/* We can reuse the CORNER_* bits for tria */
#define TRIA_VEC_RANGE BIT_RANGE(6)
@@ -53,36 +85,62 @@ const vec2 jit[9] = vec2[9](
* (The array is still stored in the registry, but indexing is done in the uniform buffer.) */
uniform vec2 triavec[43] = vec2[43](
- /* ROUNDBOX_TRIA_ARROWS */
- vec2(-0.170000, 0.400000), vec2(-0.050000, 0.520000), vec2( 0.250000, 0.000000), vec2( 0.470000, -0.000000), vec2(-0.170000, -0.400000), vec2(-0.050000, -0.520000),
- vec2( 0.170000, 0.400000), vec2( 0.050000, 0.520000), vec2(-0.250000, 0.000000), vec2(-0.470000, -0.000000), vec2( 0.170000, -0.400000), vec2( 0.050000, -0.520000),
-
- /* ROUNDBOX_TRIA_SCROLL - circle tria (triangle strip) */
- vec2(0.000000, 1.000000),
- vec2(0.382684, 0.923879), vec2(-0.382683, 0.923880),
- vec2(0.707107, 0.707107), vec2(-0.707107, 0.707107),
- vec2(0.923879, 0.382684), vec2(-0.923879, 0.382684),
- vec2(1.000000, 0.000000), vec2(-1.000000, 0.000000),
- vec2(0.923879, -0.382684), vec2(-0.923879, -0.382684),
- vec2(0.707107, -0.707107), vec2(-0.707107, -0.707107),
- vec2(0.382684, -0.923879), vec2(-0.382683, -0.923880),
- vec2(0.000000, -1.000000),
-
- /* ROUNDBOX_TRIA_MENU - menu arrows */
- vec2(-0.51, 0.07), vec2(-0.4, 0.18), vec2(-0.05, -0.39),
- vec2(-0.05, -0.17), vec2(0.41, 0.07), vec2(0.3, 0.18),
-
-
- /* ROUNDBOX_TRIA_CHECK - check mark */
- vec2(-0.67000, 0.020000), vec2(-0.500000, 0.190000), vec2(-0.130000, -0.520000),
- vec2(-0.130000, -0.170000), vec2(0.720000, 0.430000), vec2(0.530000, 0.590000),
-
- /* ROUNDBOX_TRIA_HOLD_ACTION_ARROW - hold action arrows */
+ /* ROUNDBOX_TRIA_ARROWS */
+ vec2(-0.170000, 0.400000),
+ vec2(-0.050000, 0.520000),
+ vec2(0.250000, 0.000000),
+ vec2(0.470000, -0.000000),
+ vec2(-0.170000, -0.400000),
+ vec2(-0.050000, -0.520000),
+ vec2(0.170000, 0.400000),
+ vec2(0.050000, 0.520000),
+ vec2(-0.250000, 0.000000),
+ vec2(-0.470000, -0.000000),
+ vec2(0.170000, -0.400000),
+ vec2(0.050000, -0.520000),
+
+ /* ROUNDBOX_TRIA_SCROLL - circle tria (triangle strip) */
+ vec2(0.000000, 1.000000),
+ vec2(0.382684, 0.923879),
+ vec2(-0.382683, 0.923880),
+ vec2(0.707107, 0.707107),
+ vec2(-0.707107, 0.707107),
+ vec2(0.923879, 0.382684),
+ vec2(-0.923879, 0.382684),
+ vec2(1.000000, 0.000000),
+ vec2(-1.000000, 0.000000),
+ vec2(0.923879, -0.382684),
+ vec2(-0.923879, -0.382684),
+ vec2(0.707107, -0.707107),
+ vec2(-0.707107, -0.707107),
+ vec2(0.382684, -0.923879),
+ vec2(-0.382683, -0.923880),
+ vec2(0.000000, -1.000000),
+
+ /* ROUNDBOX_TRIA_MENU - menu arrows */
+ vec2(-0.51, 0.07),
+ vec2(-0.4, 0.18),
+ vec2(-0.05, -0.39),
+ vec2(-0.05, -0.17),
+ vec2(0.41, 0.07),
+ vec2(0.3, 0.18),
+
+ /* ROUNDBOX_TRIA_CHECK - check mark */
+ vec2(-0.67000, 0.020000),
+ vec2(-0.500000, 0.190000),
+ vec2(-0.130000, -0.520000),
+ vec2(-0.130000, -0.170000),
+ vec2(0.720000, 0.430000),
+ vec2(0.530000, 0.590000),
+
+/* ROUNDBOX_TRIA_HOLD_ACTION_ARROW - hold action arrows */
#define OX (-0.32)
#define OY (0.1)
#define SC (0.35 * 2)
-// vec2(-0.5 + SC, 1.0 + OY), vec2( 0.5, 1.0 + OY), vec2( 0.5, 0.0 + OY + SC),
- vec2((0.5 - SC) + OX, 1.0 + OY), vec2(-0.5 + OX, 1.0 + OY), vec2(-0.5 + OX, SC + OY)
+ // vec2(-0.5 + SC, 1.0 + OY), vec2( 0.5, 1.0 + OY), vec2( 0.5, 0.0 + OY + SC),
+ vec2((0.5 - SC) + OX, 1.0 + OY),
+ vec2(-0.5 + OX, 1.0 + OY),
+ vec2(-0.5 + OX, SC + OY)
#undef OX
#undef OY
#undef SC
@@ -92,30 +150,30 @@ uniform mat4 ModelViewProjectionMatrix;
#define MAX_PARAM 11
#ifdef USE_INSTANCE
-#define MAX_INSTANCE 6
+# define MAX_INSTANCE 6
uniform vec4 parameters[MAX_PARAM * MAX_INSTANCE];
#else
uniform vec4 parameters[MAX_PARAM];
#endif
/* gl_InstanceID is 0 if not drawing instances. */
-#define recti parameters[gl_InstanceID * MAX_PARAM + 0]
-#define rect parameters[gl_InstanceID * MAX_PARAM + 1]
-#define radsi parameters[gl_InstanceID * MAX_PARAM + 2].x
-#define rads parameters[gl_InstanceID * MAX_PARAM + 2].y
-#define faci parameters[gl_InstanceID * MAX_PARAM + 2].zw
-#define roundCorners parameters[gl_InstanceID * MAX_PARAM + 3]
-#define colorInner1 parameters[gl_InstanceID * MAX_PARAM + 4]
-#define colorInner2 parameters[gl_InstanceID * MAX_PARAM + 5]
-#define colorEdge parameters[gl_InstanceID * MAX_PARAM + 6]
-#define colorEmboss parameters[gl_InstanceID * MAX_PARAM + 7]
-#define colorTria parameters[gl_InstanceID * MAX_PARAM + 8]
-#define tria1Center parameters[gl_InstanceID * MAX_PARAM + 9].xy
-#define tria2Center parameters[gl_InstanceID * MAX_PARAM + 9].zw
-#define tria1Size parameters[gl_InstanceID * MAX_PARAM + 10].x
-#define tria2Size parameters[gl_InstanceID * MAX_PARAM + 10].y
-#define shadeDir parameters[gl_InstanceID * MAX_PARAM + 10].z
-#define alphaDiscard parameters[gl_InstanceID * MAX_PARAM + 10].w
+#define recti parameters[gl_InstanceID * MAX_PARAM + 0]
+#define rect parameters[gl_InstanceID * MAX_PARAM + 1]
+#define radsi parameters[gl_InstanceID * MAX_PARAM + 2].x
+#define rads parameters[gl_InstanceID * MAX_PARAM + 2].y
+#define faci parameters[gl_InstanceID * MAX_PARAM + 2].zw
+#define roundCorners parameters[gl_InstanceID * MAX_PARAM + 3]
+#define colorInner1 parameters[gl_InstanceID * MAX_PARAM + 4]
+#define colorInner2 parameters[gl_InstanceID * MAX_PARAM + 5]
+#define colorEdge parameters[gl_InstanceID * MAX_PARAM + 6]
+#define colorEmboss parameters[gl_InstanceID * MAX_PARAM + 7]
+#define colorTria parameters[gl_InstanceID * MAX_PARAM + 8]
+#define tria1Center parameters[gl_InstanceID * MAX_PARAM + 9].xy
+#define tria2Center parameters[gl_InstanceID * MAX_PARAM + 9].zw
+#define tria1Size parameters[gl_InstanceID * MAX_PARAM + 10].x
+#define tria2Size parameters[gl_InstanceID * MAX_PARAM + 10].y
+#define shadeDir parameters[gl_InstanceID * MAX_PARAM + 10].z
+#define alphaDiscard parameters[gl_InstanceID * MAX_PARAM + 10].w
/* We encode alpha check and discard factor together. */
#define doAlphaCheck (alphaDiscard < 0.0)
@@ -129,86 +187,86 @@ flat out float discardFac;
vec2 do_widget(void)
{
- uint cflag = vflag & CNR_FLAG_RANGE;
- uint vofs = (vflag >> CORNER_VEC_OFS) & CORNER_VEC_RANGE;
-
- vec2 v = cornervec[cflag * 9u + vofs];
-
- bool is_inner = (vflag & INNER_FLAG) != 0u;
-
- /* Scale by corner radius */
- v *= roundCorners[cflag] * ((is_inner) ? radsi : rads);
-
- /* Position to corner */
- vec4 rct = (is_inner) ? recti : rect;
- if (cflag == BOTTOM_LEFT)
- v += rct.xz;
- else if (cflag == BOTTOM_RIGHT)
- v += rct.yz;
- else if (cflag == TOP_RIGHT)
- v += rct.yw;
- else /* (cflag == TOP_LEFT) */
- v += rct.xw;
-
- vec2 uv = faci * (v - recti.xz);
-
- /* compute uv and color gradient */
- uint color_id = (vflag >> COLOR_OFS) & COLOR_RANGE;
- if (color_id == COLOR_INNER) {
- float fac = clamp((shadeDir > 0.0) ? uv.y : uv.x, 0.0, 1.0);
-
- if (doAlphaCheck) {
- finalColor = colorInner1;
- butCo = uv.x;
- }
- else {
- finalColor = mix(colorInner2, colorInner1, fac);
- butCo = -abs(uv.x);
- }
- }
- else if (color_id == COLOR_EDGE) {
- finalColor = colorEdge;
- butCo = -abs(uv.x);
- }
- else /* (color_id == COLOR_EMBOSS) */ {
- finalColor = colorEmboss;
- butCo = -abs(uv.x);
- }
-
- bool is_emboss = (vflag & EMBOSS_FLAG) != 0u;
- v.y -= (is_emboss) ? 1.0f : 0.0;
-
- return v;
+ uint cflag = vflag & CNR_FLAG_RANGE;
+ uint vofs = (vflag >> CORNER_VEC_OFS) & CORNER_VEC_RANGE;
+
+ vec2 v = cornervec[cflag * 9u + vofs];
+
+ bool is_inner = (vflag & INNER_FLAG) != 0u;
+
+ /* Scale by corner radius */
+ v *= roundCorners[cflag] * ((is_inner) ? radsi : rads);
+
+ /* Position to corner */
+ vec4 rct = (is_inner) ? recti : rect;
+ if (cflag == BOTTOM_LEFT)
+ v += rct.xz;
+ else if (cflag == BOTTOM_RIGHT)
+ v += rct.yz;
+ else if (cflag == TOP_RIGHT)
+ v += rct.yw;
+ else /* (cflag == TOP_LEFT) */
+ v += rct.xw;
+
+ vec2 uv = faci * (v - recti.xz);
+
+ /* compute uv and color gradient */
+ uint color_id = (vflag >> COLOR_OFS) & COLOR_RANGE;
+ if (color_id == COLOR_INNER) {
+ float fac = clamp((shadeDir > 0.0) ? uv.y : uv.x, 0.0, 1.0);
+
+ if (doAlphaCheck) {
+ finalColor = colorInner1;
+ butCo = uv.x;
+ }
+ else {
+ finalColor = mix(colorInner2, colorInner1, fac);
+ butCo = -abs(uv.x);
+ }
+ }
+ else if (color_id == COLOR_EDGE) {
+ finalColor = colorEdge;
+ butCo = -abs(uv.x);
+ }
+ else /* (color_id == COLOR_EMBOSS) */ {
+ finalColor = colorEmboss;
+ butCo = -abs(uv.x);
+ }
+
+ bool is_emboss = (vflag & EMBOSS_FLAG) != 0u;
+ v.y -= (is_emboss) ? 1.0f : 0.0;
+
+ return v;
}
vec2 do_tria()
{
- uint vofs = vflag & TRIA_VEC_RANGE;
+ uint vofs = vflag & TRIA_VEC_RANGE;
- vec2 v = triavec[vofs];
+ vec2 v = triavec[vofs];
- finalColor = colorTria;
- butCo = -1.0;
+ finalColor = colorTria;
+ butCo = -1.0;
- bool is_tria_first = (vflag & TRIA_FIRST) != 0u;
+ bool is_tria_first = (vflag & TRIA_FIRST) != 0u;
- if (is_tria_first)
- v = v * tria1Size + tria1Center;
- else
- v = v * tria2Size + tria2Center;
+ if (is_tria_first)
+ v = v * tria1Size + tria1Center;
+ else
+ v = v * tria2Size + tria2Center;
- return v;
+ return v;
}
void main()
{
- discardFac = discardFactor;
- bool is_tria = (vflag & TRIA_FLAG) != 0u;
+ discardFac = discardFactor;
+ bool is_tria = (vflag & TRIA_FLAG) != 0u;
- vec2 v = (is_tria) ? do_tria() : do_widget();
+ vec2 v = (is_tria) ? do_tria() : do_widget();
- /* Antialiasing offset */
- v += jit[(vflag >> JIT_OFS) & JIT_RANGE];
+ /* Antialiasing offset */
+ v += jit[(vflag >> JIT_OFS) & JIT_RANGE];
- gl_Position = ModelViewProjectionMatrix * vec4(v, 0.0, 1.0);
+ gl_Position = ModelViewProjectionMatrix * vec4(v, 0.0, 1.0);
}
diff --git a/source/blender/gpu/shaders/gpu_shader_2D_widget_shadow_frag.glsl b/source/blender/gpu/shaders/gpu_shader_2D_widget_shadow_frag.glsl
index fc4d055a903..e8a6a43191e 100644
--- a/source/blender/gpu/shaders/gpu_shader_2D_widget_shadow_frag.glsl
+++ b/source/blender/gpu/shaders/gpu_shader_2D_widget_shadow_frag.glsl
@@ -7,7 +7,7 @@ uniform float alpha;
void main()
{
- fragColor = vec4(0.0);
- /* Manual curve fit of the falloff curve of previous drawing method. */
- fragColor.a = alpha * (shadowFalloff * shadowFalloff * 0.722 + shadowFalloff * 0.277);
+ fragColor = vec4(0.0);
+ /* Manual curve fit of the falloff curve of previous drawing method. */
+ fragColor.a = alpha * (shadowFalloff * shadowFalloff * 0.722 + shadowFalloff * 0.277);
}
diff --git a/source/blender/gpu/shaders/gpu_shader_2D_widget_shadow_vert.glsl b/source/blender/gpu/shaders/gpu_shader_2D_widget_shadow_vert.glsl
index f6be496ac4f..99f80f6a7f2 100644
--- a/source/blender/gpu/shaders/gpu_shader_2D_widget_shadow_vert.glsl
+++ b/source/blender/gpu/shaders/gpu_shader_2D_widget_shadow_vert.glsl
@@ -12,23 +12,53 @@
/* 4bits for corner id */
#define CORNER_VEC_OFS 2u
#define CORNER_VEC_RANGE BIT_RANGE(4)
-const vec2 cornervec[36] = vec2[36](
- vec2(0.0, 1.0), vec2(0.02, 0.805), vec2(0.067, 0.617), vec2(0.169, 0.45), vec2(0.293, 0.293), vec2(0.45, 0.169), vec2(0.617, 0.076), vec2(0.805, 0.02), vec2(1.0, 0.0),
- vec2(-1.0, 0.0), vec2(-0.805, 0.02), vec2(-0.617, 0.067), vec2(-0.45, 0.169), vec2(-0.293, 0.293), vec2(-0.169, 0.45), vec2(-0.076, 0.617), vec2(-0.02, 0.805), vec2(0.0, 1.0),
- vec2(0.0, -1.0), vec2(-0.02, -0.805), vec2(-0.067, -0.617), vec2(-0.169, -0.45), vec2(-0.293, -0.293), vec2(-0.45, -0.169), vec2(-0.617, -0.076), vec2(-0.805, -0.02), vec2(-1.0, 0.0),
- vec2(1.0, 0.0), vec2(0.805, -0.02), vec2(0.617, -0.067), vec2(0.45, -0.169), vec2(0.293, -0.293), vec2(0.169, -0.45), vec2(0.076, -0.617), vec2(0.02, -0.805), vec2(0.0, -1.0)
-);
+const vec2 cornervec[36] = vec2[36](vec2(0.0, 1.0),
+ vec2(0.02, 0.805),
+ vec2(0.067, 0.617),
+ vec2(0.169, 0.45),
+ vec2(0.293, 0.293),
+ vec2(0.45, 0.169),
+ vec2(0.617, 0.076),
+ vec2(0.805, 0.02),
+ vec2(1.0, 0.0),
+ vec2(-1.0, 0.0),
+ vec2(-0.805, 0.02),
+ vec2(-0.617, 0.067),
+ vec2(-0.45, 0.169),
+ vec2(-0.293, 0.293),
+ vec2(-0.169, 0.45),
+ vec2(-0.076, 0.617),
+ vec2(-0.02, 0.805),
+ vec2(0.0, 1.0),
+ vec2(0.0, -1.0),
+ vec2(-0.02, -0.805),
+ vec2(-0.067, -0.617),
+ vec2(-0.169, -0.45),
+ vec2(-0.293, -0.293),
+ vec2(-0.45, -0.169),
+ vec2(-0.617, -0.076),
+ vec2(-0.805, -0.02),
+ vec2(-1.0, 0.0),
+ vec2(1.0, 0.0),
+ vec2(0.805, -0.02),
+ vec2(0.617, -0.067),
+ vec2(0.45, -0.169),
+ vec2(0.293, -0.293),
+ vec2(0.169, -0.45),
+ vec2(0.076, -0.617),
+ vec2(0.02, -0.805),
+ vec2(0.0, -1.0));
-#define INNER_FLAG uint(1 << 10) /* is inner vert */
+#define INNER_FLAG uint(1 << 10) /* is inner vert */
uniform mat4 ModelViewProjectionMatrix;
uniform vec4 parameters[4];
/* radi and rad per corner */
-#define recti parameters[0]
-#define rect parameters[1]
-#define radsi parameters[2].x
-#define rads parameters[2].y
+#define recti parameters[0]
+#define rect parameters[1]
+#define radsi parameters[2].x
+#define rads parameters[2].y
#define roundCorners parameters[3]
in uint vflag;
@@ -37,28 +67,28 @@ out float shadowFalloff;
void main()
{
- uint cflag = vflag & CNR_FLAG_RANGE;
- uint vofs = (vflag >> CORNER_VEC_OFS) & CORNER_VEC_RANGE;
+ uint cflag = vflag & CNR_FLAG_RANGE;
+ uint vofs = (vflag >> CORNER_VEC_OFS) & CORNER_VEC_RANGE;
- vec2 v = cornervec[cflag * 9u + vofs];
+ vec2 v = cornervec[cflag * 9u + vofs];
- bool is_inner = (vflag & INNER_FLAG) != 0u;
+ bool is_inner = (vflag & INNER_FLAG) != 0u;
- shadowFalloff = (is_inner) ? 1.0 : 0.0;
+ shadowFalloff = (is_inner) ? 1.0 : 0.0;
- /* Scale by corner radius */
- v *= roundCorners[cflag] * ((is_inner) ? radsi : rads);
+ /* Scale by corner radius */
+ v *= roundCorners[cflag] * ((is_inner) ? radsi : rads);
- /* Position to corner */
- vec4 rct = (is_inner) ? recti : rect;
- if (cflag == BOTTOM_LEFT)
- v += rct.xz;
- else if (cflag == BOTTOM_RIGHT)
- v += rct.yz;
- else if (cflag == TOP_RIGHT)
- v += rct.yw;
- else /* (cflag == TOP_LEFT) */
- v += rct.xw;
+ /* Position to corner */
+ vec4 rct = (is_inner) ? recti : rect;
+ if (cflag == BOTTOM_LEFT)
+ v += rct.xz;
+ else if (cflag == BOTTOM_RIGHT)
+ v += rct.yz;
+ else if (cflag == TOP_RIGHT)
+ v += rct.yw;
+ else /* (cflag == TOP_LEFT) */
+ v += rct.xw;
- gl_Position = ModelViewProjectionMatrix * vec4(v, 0.0, 1.0);
+ gl_Position = ModelViewProjectionMatrix * vec4(v, 0.0, 1.0);
}
diff --git a/source/blender/gpu/shaders/gpu_shader_3D_clipped_uniform_color_vert.glsl b/source/blender/gpu/shaders/gpu_shader_3D_clipped_uniform_color_vert.glsl
index 84e44837264..16424ece2b6 100644
--- a/source/blender/gpu/shaders/gpu_shader_3D_clipped_uniform_color_vert.glsl
+++ b/source/blender/gpu/shaders/gpu_shader_3D_clipped_uniform_color_vert.glsl
@@ -7,6 +7,6 @@ in vec3 pos;
void main()
{
- gl_Position = ModelViewProjectionMatrix * vec4(pos, 1.0);
- gl_ClipDistance[0] = dot(ModelMatrix * vec4(pos, 1.0), ClipPlane);
+ gl_Position = ModelViewProjectionMatrix * vec4(pos, 1.0);
+ gl_ClipDistance[0] = dot(ModelMatrix * vec4(pos, 1.0), ClipPlane);
}
diff --git a/source/blender/gpu/shaders/gpu_shader_3D_flat_color_vert.glsl b/source/blender/gpu/shaders/gpu_shader_3D_flat_color_vert.glsl
index d4e6f697936..5b6a890ccc8 100644
--- a/source/blender/gpu/shaders/gpu_shader_3D_flat_color_vert.glsl
+++ b/source/blender/gpu/shaders/gpu_shader_3D_flat_color_vert.glsl
@@ -15,20 +15,19 @@ flat out vec4 finalColor;
void main()
{
- vec4 pos_4d = vec4(pos, 1.0);
- gl_Position = ModelViewProjectionMatrix * pos_4d;
+ vec4 pos_4d = vec4(pos, 1.0);
+ gl_Position = ModelViewProjectionMatrix * pos_4d;
#if defined(USE_COLOR_U32)
- finalColor = vec4(
- ((color ) & uint(0xFF)) * (1.0f / 255.0f),
- ((color >> 8) & uint(0xFF)) * (1.0f / 255.0f),
- ((color >> 16) & uint(0xFF)) * (1.0f / 255.0f),
- ((color >> 24) ) * (1.0f / 255.0f));
+ finalColor = vec4(((color)&uint(0xFF)) * (1.0f / 255.0f),
+ ((color >> 8) & uint(0xFF)) * (1.0f / 255.0f),
+ ((color >> 16) & uint(0xFF)) * (1.0f / 255.0f),
+ ((color >> 24)) * (1.0f / 255.0f));
#else
- finalColor = color;
+ finalColor = color;
#endif
#ifdef USE_WORLD_CLIP_PLANES
- world_clip_planes_calc_clip_distance((ModelMatrix * pos_4d).xyz);
+ world_clip_planes_calc_clip_distance((ModelMatrix * pos_4d).xyz);
#endif
}
diff --git a/source/blender/gpu/shaders/gpu_shader_3D_groundline_geom.glsl b/source/blender/gpu/shaders/gpu_shader_3D_groundline_geom.glsl
index 29bdd03f7e3..03bee1b4e06 100644
--- a/source/blender/gpu/shaders/gpu_shader_3D_groundline_geom.glsl
+++ b/source/blender/gpu/shaders/gpu_shader_3D_groundline_geom.glsl
@@ -7,19 +7,19 @@ layout(line_strip, max_vertices = 2) out;
void main()
{
- vec3 vert = gl_in[0].gl_Position.xyz;
+ vec3 vert = gl_in[0].gl_Position.xyz;
- gl_Position = ViewProjectionMatrix * vec4(vert.xyz, 1.0);
+ gl_Position = ViewProjectionMatrix * vec4(vert.xyz, 1.0);
#ifdef USE_WORLD_CLIP_PLANES
- world_clip_planes_set_clip_distance(gl_in[0].gl_ClipDistance);
+ world_clip_planes_set_clip_distance(gl_in[0].gl_ClipDistance);
#endif
- EmitVertex();
+ EmitVertex();
- gl_Position = ViewProjectionMatrix * vec4(vert.xy, 0.0, 1.0);
+ gl_Position = ViewProjectionMatrix * vec4(vert.xy, 0.0, 1.0);
#ifdef USE_WORLD_CLIP_PLANES
- world_clip_planes_calc_clip_distance(vec3(vert.xy, 0.0));
+ world_clip_planes_calc_clip_distance(vec3(vert.xy, 0.0));
#endif
- EmitVertex();
+ EmitVertex();
- EndPrimitive();
+ EndPrimitive();
}
diff --git a/source/blender/gpu/shaders/gpu_shader_3D_groundpoint_vert.glsl b/source/blender/gpu/shaders/gpu_shader_3D_groundpoint_vert.glsl
index b08d87cdfa6..6786b7b7405 100644
--- a/source/blender/gpu/shaders/gpu_shader_3D_groundpoint_vert.glsl
+++ b/source/blender/gpu/shaders/gpu_shader_3D_groundpoint_vert.glsl
@@ -6,11 +6,11 @@ in vec3 pos;
void main()
{
- vec4 pos_4d = vec4(pos.xy, 0.0, 1.0);
- gl_Position = ViewProjectionMatrix * pos_4d;
- gl_PointSize = 2.0;
+ vec4 pos_4d = vec4(pos.xy, 0.0, 1.0);
+ gl_Position = ViewProjectionMatrix * pos_4d;
+ gl_PointSize = 2.0;
#ifdef USE_WORLD_CLIP_PLANES
- world_clip_planes_calc_clip_distance(pos_4d.xyz);
+ world_clip_planes_calc_clip_distance(pos_4d.xyz);
#endif
}
diff --git a/source/blender/gpu/shaders/gpu_shader_3D_image_vert.glsl b/source/blender/gpu/shaders/gpu_shader_3D_image_vert.glsl
index eb877ab20b6..0fb8d06e317 100644
--- a/source/blender/gpu/shaders/gpu_shader_3D_image_vert.glsl
+++ b/source/blender/gpu/shaders/gpu_shader_3D_image_vert.glsl
@@ -7,6 +7,6 @@ out vec2 texCoord_interp;
void main()
{
- gl_Position = ModelViewProjectionMatrix * vec4(pos.xyz, 1.0f);
- texCoord_interp = texCoord;
+ gl_Position = ModelViewProjectionMatrix * vec4(pos.xyz, 1.0f);
+ texCoord_interp = texCoord;
}
diff --git a/source/blender/gpu/shaders/gpu_shader_3D_line_dashed_uniform_color_legacy_vert.glsl b/source/blender/gpu/shaders/gpu_shader_3D_line_dashed_uniform_color_legacy_vert.glsl
index 84fbf977846..9fe63c65054 100644
--- a/source/blender/gpu/shaders/gpu_shader_3D_line_dashed_uniform_color_legacy_vert.glsl
+++ b/source/blender/gpu/shaders/gpu_shader_3D_line_dashed_uniform_color_legacy_vert.glsl
@@ -17,10 +17,10 @@ noperspective out vec4 color_geom;
void main()
{
- gl_Position = ModelViewProjectionMatrix * vec4(pos, 1.0);
+ gl_Position = ModelViewProjectionMatrix * vec4(pos, 1.0);
- /* Hack - prevent stupid GLSL compiler to optimize out unused viewport_size uniform, which gives crash! */
- distance_along_line = viewport_size.x * 0.000001f - viewport_size.x * 0.0000009f;
+ /* Hack - prevent stupid GLSL compiler to optimize out unused viewport_size uniform, which gives crash! */
+ distance_along_line = viewport_size.x * 0.000001f - viewport_size.x * 0.0000009f;
- color_geom = color;
+ color_geom = color;
}
diff --git a/source/blender/gpu/shaders/gpu_shader_3D_line_dashed_uniform_color_vert.glsl b/source/blender/gpu/shaders/gpu_shader_3D_line_dashed_uniform_color_vert.glsl
index 791f634c6cd..47ca09b5e72 100644
--- a/source/blender/gpu/shaders/gpu_shader_3D_line_dashed_uniform_color_vert.glsl
+++ b/source/blender/gpu/shaders/gpu_shader_3D_line_dashed_uniform_color_vert.glsl
@@ -20,10 +20,10 @@ out vec4 color_vert;
void main()
{
- vec4 pos_4d = vec4(pos, 1.0);
- gl_Position = ModelViewProjectionMatrix * pos_4d;
- color_vert = color;
+ vec4 pos_4d = vec4(pos, 1.0);
+ gl_Position = ModelViewProjectionMatrix * pos_4d;
+ color_vert = color;
#ifdef USE_WORLD_CLIP_PLANES
- world_clip_planes_calc_clip_distance((ModelMatrix * pos_4d).xyz);
+ world_clip_planes_calc_clip_distance((ModelMatrix * pos_4d).xyz);
#endif
}
diff --git a/source/blender/gpu/shaders/gpu_shader_3D_normal_smooth_color_vert.glsl b/source/blender/gpu/shaders/gpu_shader_3D_normal_smooth_color_vert.glsl
index e6b8fed7265..7fa571343a2 100644
--- a/source/blender/gpu/shaders/gpu_shader_3D_normal_smooth_color_vert.glsl
+++ b/source/blender/gpu/shaders/gpu_shader_3D_normal_smooth_color_vert.glsl
@@ -16,7 +16,7 @@ out vec4 finalColor;
void main()
{
- normal = normalize(NormalMatrix * nor);
- gl_Position = ModelViewProjectionMatrix * vec4(pos, 1.0);
- finalColor = color;
+ normal = normalize(NormalMatrix * nor);
+ gl_Position = ModelViewProjectionMatrix * vec4(pos, 1.0);
+ finalColor = color;
}
diff --git a/source/blender/gpu/shaders/gpu_shader_3D_normal_vert.glsl b/source/blender/gpu/shaders/gpu_shader_3D_normal_vert.glsl
index a3f447a85f9..252fee87015 100644
--- a/source/blender/gpu/shaders/gpu_shader_3D_normal_vert.glsl
+++ b/source/blender/gpu/shaders/gpu_shader_3D_normal_vert.glsl
@@ -8,6 +8,6 @@ out vec3 normal;
void main()
{
- normal = normalize(NormalMatrix * nor);
- gl_Position = ModelViewProjectionMatrix * vec4(pos, 1.0);
+ normal = normalize(NormalMatrix * nor);
+ gl_Position = ModelViewProjectionMatrix * vec4(pos, 1.0);
}
diff --git a/source/blender/gpu/shaders/gpu_shader_3D_passthrough_vert.glsl b/source/blender/gpu/shaders/gpu_shader_3D_passthrough_vert.glsl
index 4196dbbad02..12594b04da9 100644
--- a/source/blender/gpu/shaders/gpu_shader_3D_passthrough_vert.glsl
+++ b/source/blender/gpu/shaders/gpu_shader_3D_passthrough_vert.glsl
@@ -7,10 +7,10 @@ in vec3 pos;
void main()
{
- vec4 pos_4d = vec4(pos, 1.0);
- gl_Position = pos_4d;
+ vec4 pos_4d = vec4(pos, 1.0);
+ gl_Position = pos_4d;
#ifdef USE_WORLD_CLIP_PLANES
- world_clip_planes_calc_clip_distance((ModelMatrix * pos_4d).xyz);
+ world_clip_planes_calc_clip_distance((ModelMatrix * pos_4d).xyz);
#endif
}
diff --git a/source/blender/gpu/shaders/gpu_shader_3D_point_fixed_size_varying_color_vert.glsl b/source/blender/gpu/shaders/gpu_shader_3D_point_fixed_size_varying_color_vert.glsl
index 2fe9c0623fa..776656fc2df 100644
--- a/source/blender/gpu/shaders/gpu_shader_3D_point_fixed_size_varying_color_vert.glsl
+++ b/source/blender/gpu/shaders/gpu_shader_3D_point_fixed_size_varying_color_vert.glsl
@@ -7,6 +7,6 @@ out vec4 finalColor;
void main()
{
- gl_Position = ModelViewProjectionMatrix * vec4(pos, 1.0);
- finalColor = color;
+ gl_Position = ModelViewProjectionMatrix * vec4(pos, 1.0);
+ finalColor = color;
}
diff --git a/source/blender/gpu/shaders/gpu_shader_3D_point_uniform_size_aa_vert.glsl b/source/blender/gpu/shaders/gpu_shader_3D_point_uniform_size_aa_vert.glsl
index f39c10e8310..f5b6d2ea3ed 100644
--- a/source/blender/gpu/shaders/gpu_shader_3D_point_uniform_size_aa_vert.glsl
+++ b/source/blender/gpu/shaders/gpu_shader_3D_point_uniform_size_aa_vert.glsl
@@ -8,22 +8,23 @@ uniform float size;
in vec3 pos;
out vec2 radii;
-void main() {
- vec4 pos_4d = vec4(pos, 1.0);
- gl_Position = ModelViewProjectionMatrix * pos_4d;
- gl_PointSize = size;
+void main()
+{
+ vec4 pos_4d = vec4(pos, 1.0);
+ gl_Position = ModelViewProjectionMatrix * pos_4d;
+ gl_PointSize = size;
- // calculate concentric radii in pixels
- float radius = 0.5 * size;
+ // calculate concentric radii in pixels
+ float radius = 0.5 * size;
- // start at the outside and progress toward the center
- radii[0] = radius;
- radii[1] = radius - 1.0;
+ // start at the outside and progress toward the center
+ radii[0] = radius;
+ radii[1] = radius - 1.0;
- // convert to PointCoord units
- radii /= size;
+ // convert to PointCoord units
+ radii /= size;
#ifdef USE_WORLD_CLIP_PLANES
- world_clip_planes_calc_clip_distance((ModelMatrix * pos_4d).xyz);
+ world_clip_planes_calc_clip_distance((ModelMatrix * pos_4d).xyz);
#endif
}
diff --git a/source/blender/gpu/shaders/gpu_shader_3D_point_uniform_size_outline_aa_vert.glsl b/source/blender/gpu/shaders/gpu_shader_3D_point_uniform_size_outline_aa_vert.glsl
index e14032a9694..8bd344ed0e7 100644
--- a/source/blender/gpu/shaders/gpu_shader_3D_point_uniform_size_outline_aa_vert.glsl
+++ b/source/blender/gpu/shaders/gpu_shader_3D_point_uniform_size_outline_aa_vert.glsl
@@ -9,24 +9,25 @@ uniform float outlineWidth;
in vec3 pos;
out vec4 radii;
-void main() {
- vec4 pos_4d = vec4(pos, 1.0);
- gl_Position = ModelViewProjectionMatrix * pos_4d;
- gl_PointSize = size;
+void main()
+{
+ vec4 pos_4d = vec4(pos, 1.0);
+ gl_Position = ModelViewProjectionMatrix * pos_4d;
+ gl_PointSize = size;
- // calculate concentric radii in pixels
- float radius = 0.5 * size;
+ // calculate concentric radii in pixels
+ float radius = 0.5 * size;
- // start at the outside and progress toward the center
- radii[0] = radius;
- radii[1] = radius - 1.0;
- radii[2] = radius - outlineWidth;
- radii[3] = radius - outlineWidth - 1.0;
+ // start at the outside and progress toward the center
+ radii[0] = radius;
+ radii[1] = radius - 1.0;
+ radii[2] = radius - outlineWidth;
+ radii[3] = radius - outlineWidth - 1.0;
- // convert to PointCoord units
- radii /= size;
+ // convert to PointCoord units
+ radii /= size;
#ifdef USE_WORLD_CLIP_PLANES
- world_clip_planes_calc_clip_distance((ModelMatrix * pos_4d).xyz);
+ world_clip_planes_calc_clip_distance((ModelMatrix * pos_4d).xyz);
#endif
}
diff --git a/source/blender/gpu/shaders/gpu_shader_3D_point_varying_size_varying_color_vert.glsl b/source/blender/gpu/shaders/gpu_shader_3D_point_varying_size_varying_color_vert.glsl
index e14b9535c89..3bc72535266 100644
--- a/source/blender/gpu/shaders/gpu_shader_3D_point_varying_size_varying_color_vert.glsl
+++ b/source/blender/gpu/shaders/gpu_shader_3D_point_varying_size_varying_color_vert.glsl
@@ -8,7 +8,7 @@ out vec4 finalColor;
void main()
{
- gl_Position = ModelViewProjectionMatrix * vec4(pos, 1.0);
- gl_PointSize = size;
- finalColor = color;
+ gl_Position = ModelViewProjectionMatrix * vec4(pos, 1.0);
+ gl_PointSize = size;
+ finalColor = color;
}
diff --git a/source/blender/gpu/shaders/gpu_shader_3D_point_varying_size_vert.glsl b/source/blender/gpu/shaders/gpu_shader_3D_point_varying_size_vert.glsl
index e4f173ab617..fc61be936fe 100644
--- a/source/blender/gpu/shaders/gpu_shader_3D_point_varying_size_vert.glsl
+++ b/source/blender/gpu/shaders/gpu_shader_3D_point_varying_size_vert.glsl
@@ -6,6 +6,6 @@ in float size;
void main()
{
- gl_Position = ModelViewProjectionMatrix * vec4(pos, 1.0);
- gl_PointSize = size;
+ gl_Position = ModelViewProjectionMatrix * vec4(pos, 1.0);
+ gl_PointSize = size;
}
diff --git a/source/blender/gpu/shaders/gpu_shader_3D_selection_id_vert.glsl b/source/blender/gpu/shaders/gpu_shader_3D_selection_id_vert.glsl
index bdb26981399..0d58909efd8 100644
--- a/source/blender/gpu/shaders/gpu_shader_3D_selection_id_vert.glsl
+++ b/source/blender/gpu/shaders/gpu_shader_3D_selection_id_vert.glsl
@@ -13,14 +13,14 @@ flat out uint id;
void main()
{
#ifndef UNIFORM_ID
- id = offset + color;
+ id = offset + color;
#endif
- vec4 pos_4d = vec4(pos, 1.0);
- gl_Position = ModelViewProjectionMatrix * pos_4d;
+ vec4 pos_4d = vec4(pos, 1.0);
+ gl_Position = ModelViewProjectionMatrix * pos_4d;
#ifdef USE_WORLD_CLIP_PLANES
- /* Warning: ModelMatrix is typically used but select drawing is different. */
- world_clip_planes_calc_clip_distance(pos);
+ /* Warning: ModelMatrix is typically used but select drawing is different. */
+ world_clip_planes_calc_clip_distance(pos);
#endif
}
diff --git a/source/blender/gpu/shaders/gpu_shader_3D_smooth_color_frag.glsl b/source/blender/gpu/shaders/gpu_shader_3D_smooth_color_frag.glsl
index 41fdefd22e8..7bd44ba9b88 100644
--- a/source/blender/gpu/shaders/gpu_shader_3D_smooth_color_frag.glsl
+++ b/source/blender/gpu/shaders/gpu_shader_3D_smooth_color_frag.glsl
@@ -4,5 +4,5 @@ out vec4 fragColor;
void main()
{
- fragColor = finalColor;
+ fragColor = finalColor;
}
diff --git a/source/blender/gpu/shaders/gpu_shader_3D_smooth_color_vert.glsl b/source/blender/gpu/shaders/gpu_shader_3D_smooth_color_vert.glsl
index 955ce07780c..4eafb7b7be3 100644
--- a/source/blender/gpu/shaders/gpu_shader_3D_smooth_color_vert.glsl
+++ b/source/blender/gpu/shaders/gpu_shader_3D_smooth_color_vert.glsl
@@ -12,10 +12,10 @@ out vec4 finalColor;
void main()
{
- gl_Position = ModelViewProjectionMatrix * vec4(pos, 1.0);
- finalColor = color;
+ gl_Position = ModelViewProjectionMatrix * vec4(pos, 1.0);
+ finalColor = color;
#ifdef USE_WORLD_CLIP_PLANES
- world_clip_planes_calc_clip_distance((ModelMatrix * vec4(pos, 1.0)).xyz);
+ world_clip_planes_calc_clip_distance((ModelMatrix * vec4(pos, 1.0)).xyz);
#endif
}
diff --git a/source/blender/gpu/shaders/gpu_shader_3D_vert.glsl b/source/blender/gpu/shaders/gpu_shader_3D_vert.glsl
index 9fc748b292b..70bb881ffea 100644
--- a/source/blender/gpu/shaders/gpu_shader_3D_vert.glsl
+++ b/source/blender/gpu/shaders/gpu_shader_3D_vert.glsl
@@ -9,9 +9,9 @@ in vec3 pos;
void main()
{
- gl_Position = ModelViewProjectionMatrix * vec4(pos, 1.0);
+ gl_Position = ModelViewProjectionMatrix * vec4(pos, 1.0);
#ifdef USE_WORLD_CLIP_PLANES
- world_clip_planes_calc_clip_distance((ModelMatrix * vec4(pos, 1.0)).xyz);
+ world_clip_planes_calc_clip_distance((ModelMatrix * vec4(pos, 1.0)).xyz);
#endif
}
diff --git a/source/blender/gpu/shaders/gpu_shader_cfg_world_clip_lib.glsl b/source/blender/gpu/shaders/gpu_shader_cfg_world_clip_lib.glsl
index 6964b2a0c39..e34b86ac1ce 100644
--- a/source/blender/gpu/shaders/gpu_shader_cfg_world_clip_lib.glsl
+++ b/source/blender/gpu/shaders/gpu_shader_cfg_world_clip_lib.glsl
@@ -1,25 +1,25 @@
#ifdef USE_WORLD_CLIP_PLANES
-#if defined(GPU_VERTEX_SHADER) || defined(GPU_GEOMETRY_SHADER)
+# if defined(GPU_VERTEX_SHADER) || defined(GPU_GEOMETRY_SHADER)
uniform vec4 WorldClipPlanes[6];
void world_clip_planes_calc_clip_distance(vec3 wpos)
{
- gl_ClipDistance[0] = dot(WorldClipPlanes[0].xyz, wpos) + WorldClipPlanes[0].w;
- gl_ClipDistance[1] = dot(WorldClipPlanes[1].xyz, wpos) + WorldClipPlanes[1].w;
- gl_ClipDistance[2] = dot(WorldClipPlanes[2].xyz, wpos) + WorldClipPlanes[2].w;
- gl_ClipDistance[3] = dot(WorldClipPlanes[3].xyz, wpos) + WorldClipPlanes[3].w;
- gl_ClipDistance[4] = dot(WorldClipPlanes[4].xyz, wpos) + WorldClipPlanes[4].w;
- gl_ClipDistance[5] = dot(WorldClipPlanes[5].xyz, wpos) + WorldClipPlanes[5].w;
+ gl_ClipDistance[0] = dot(WorldClipPlanes[0].xyz, wpos) + WorldClipPlanes[0].w;
+ gl_ClipDistance[1] = dot(WorldClipPlanes[1].xyz, wpos) + WorldClipPlanes[1].w;
+ gl_ClipDistance[2] = dot(WorldClipPlanes[2].xyz, wpos) + WorldClipPlanes[2].w;
+ gl_ClipDistance[3] = dot(WorldClipPlanes[3].xyz, wpos) + WorldClipPlanes[3].w;
+ gl_ClipDistance[4] = dot(WorldClipPlanes[4].xyz, wpos) + WorldClipPlanes[4].w;
+ gl_ClipDistance[5] = dot(WorldClipPlanes[5].xyz, wpos) + WorldClipPlanes[5].w;
}
-#endif
+# endif
-#define world_clip_planes_set_clip_distance(c) \
-{ \
- gl_ClipDistance[0] = (c)[0]; \
- gl_ClipDistance[1] = (c)[1]; \
- gl_ClipDistance[2] = (c)[2]; \
- gl_ClipDistance[3] = (c)[3]; \
- gl_ClipDistance[4] = (c)[4]; \
- gl_ClipDistance[5] = (c)[5]; \
-}
+# define world_clip_planes_set_clip_distance(c) \
+ { \
+ gl_ClipDistance[0] = (c)[0]; \
+ gl_ClipDistance[1] = (c)[1]; \
+ gl_ClipDistance[2] = (c)[2]; \
+ gl_ClipDistance[3] = (c)[3]; \
+ gl_ClipDistance[4] = (c)[4]; \
+ gl_ClipDistance[5] = (c)[5]; \
+ }
#endif
diff --git a/source/blender/gpu/shaders/gpu_shader_checker_frag.glsl b/source/blender/gpu/shaders/gpu_shader_checker_frag.glsl
index 545f6d19e21..156b6cb75ab 100644
--- a/source/blender/gpu/shaders/gpu_shader_checker_frag.glsl
+++ b/source/blender/gpu/shaders/gpu_shader_checker_frag.glsl
@@ -7,14 +7,12 @@ out vec4 fragColor;
void main()
{
- vec2 phase = mod(gl_FragCoord.xy, (size*2));
+ vec2 phase = mod(gl_FragCoord.xy, (size * 2));
- if ((phase.x > size && phase.y < size) ||
- (phase.x < size && phase.y > size))
- {
- fragColor = color1;
- }
- else {
- fragColor = color2;
- }
+ if ((phase.x > size && phase.y < size) || (phase.x < size && phase.y > size)) {
+ fragColor = color1;
+ }
+ else {
+ fragColor = color2;
+ }
}
diff --git a/source/blender/gpu/shaders/gpu_shader_depth_only_frag.glsl b/source/blender/gpu/shaders/gpu_shader_depth_only_frag.glsl
index 60e71e19004..1b9fd48c77a 100644
--- a/source/blender/gpu/shaders/gpu_shader_depth_only_frag.glsl
+++ b/source/blender/gpu/shaders/gpu_shader_depth_only_frag.glsl
@@ -1,6 +1,6 @@
void main()
{
- // no color output, only depth (line below is implicit)
- // gl_FragDepth = gl_FragCoord.z;
+ // no color output, only depth (line below is implicit)
+ // gl_FragDepth = gl_FragCoord.z;
}
diff --git a/source/blender/gpu/shaders/gpu_shader_diag_stripes_frag.glsl b/source/blender/gpu/shaders/gpu_shader_diag_stripes_frag.glsl
index beb71c58100..48979af4ad0 100644
--- a/source/blender/gpu/shaders/gpu_shader_diag_stripes_frag.glsl
+++ b/source/blender/gpu/shaders/gpu_shader_diag_stripes_frag.glsl
@@ -8,13 +8,12 @@ out vec4 fragColor;
void main()
{
- float phase = mod((gl_FragCoord.x + gl_FragCoord.y), (size1 + size2));
+ float phase = mod((gl_FragCoord.x + gl_FragCoord.y), (size1 + size2));
- if (phase < size1)
- {
- fragColor = color1;
- }
- else {
- fragColor = color2;
- }
+ if (phase < size1) {
+ fragColor = color1;
+ }
+ else {
+ fragColor = color2;
+ }
}
diff --git a/source/blender/gpu/shaders/gpu_shader_edges_front_back_ortho_vert.glsl b/source/blender/gpu/shaders/gpu_shader_edges_front_back_ortho_vert.glsl
index 4ed7ed56c11..a71dfba575b 100644
--- a/source/blender/gpu/shaders/gpu_shader_edges_front_back_ortho_vert.glsl
+++ b/source/blender/gpu/shaders/gpu_shader_edges_front_back_ortho_vert.glsl
@@ -11,7 +11,7 @@ uniform vec4 frontColor;
uniform vec4 backColor;
uniform vec4 silhouetteColor;
-uniform vec3 eye; // direction we are looking
+uniform vec3 eye; // direction we are looking
uniform mat4 ModelViewProjectionMatrix;
@@ -31,24 +31,24 @@ const vec4 nowhere = vec4(vec3(0.0), 1.0);
void main()
{
- bool face_1_front = dot(N1, eye) > 0.0;
- bool face_2_front = dot(N2, eye) > 0.0;
-
- vec4 position = ModelViewProjectionMatrix * vec4(pos, 1.0);
-
- if (face_1_front && face_2_front) {
- // front-facing edge
- gl_Position = drawFront ? position : nowhere;
- finalColor = frontColor;
- }
- else if (face_1_front || face_2_front) {
- // exactly one face is front-facing, silhouette edge
- gl_Position = drawSilhouette ? position : nowhere;
- finalColor = silhouetteColor;
- }
- else {
- // back-facing edge
- gl_Position = drawBack ? position : nowhere;
- finalColor = backColor;
- }
+ bool face_1_front = dot(N1, eye) > 0.0;
+ bool face_2_front = dot(N2, eye) > 0.0;
+
+ vec4 position = ModelViewProjectionMatrix * vec4(pos, 1.0);
+
+ if (face_1_front && face_2_front) {
+ // front-facing edge
+ gl_Position = drawFront ? position : nowhere;
+ finalColor = frontColor;
+ }
+ else if (face_1_front || face_2_front) {
+ // exactly one face is front-facing, silhouette edge
+ gl_Position = drawSilhouette ? position : nowhere;
+ finalColor = silhouetteColor;
+ }
+ else {
+ // back-facing edge
+ gl_Position = drawBack ? position : nowhere;
+ finalColor = backColor;
+ }
}
diff --git a/source/blender/gpu/shaders/gpu_shader_edges_front_back_persp_geom.glsl b/source/blender/gpu/shaders/gpu_shader_edges_front_back_persp_geom.glsl
index e7632fcad15..3de14704781 100644
--- a/source/blender/gpu/shaders/gpu_shader_edges_front_back_persp_geom.glsl
+++ b/source/blender/gpu/shaders/gpu_shader_edges_front_back_persp_geom.glsl
@@ -30,31 +30,31 @@ flat out vec4 finalColor;
void emitLine(vec4 color)
{
- gl_Position = ProjectionMatrix * MV_pos[0];
- EmitVertex();
- gl_Position = ProjectionMatrix * MV_pos[1];
- finalColor = color;
- EmitVertex();
- EndPrimitive();
+ gl_Position = ProjectionMatrix * MV_pos[0];
+ EmitVertex();
+ gl_Position = ProjectionMatrix * MV_pos[1];
+ finalColor = color;
+ EmitVertex();
+ EndPrimitive();
}
void main()
{
- float finalEdgeClass = max(edgeClass[0], edgeClass[1]);
-
- if (finalEdgeClass > 0.0f) {
- // front-facing edge
- if (drawFront)
- emitLine(frontColor);
- }
- else if (finalEdgeClass < 0.0f) {
- // back-facing edge
- if (drawBack)
- emitLine(backColor);
- }
- else {
- // exactly one face is front-facing, silhouette edge
- if (drawSilhouette)
- emitLine(silhouetteColor);
- }
+ float finalEdgeClass = max(edgeClass[0], edgeClass[1]);
+
+ if (finalEdgeClass > 0.0f) {
+ // front-facing edge
+ if (drawFront)
+ emitLine(frontColor);
+ }
+ else if (finalEdgeClass < 0.0f) {
+ // back-facing edge
+ if (drawBack)
+ emitLine(backColor);
+ }
+ else {
+ // exactly one face is front-facing, silhouette edge
+ if (drawSilhouette)
+ emitLine(silhouetteColor);
+ }
}
diff --git a/source/blender/gpu/shaders/gpu_shader_edges_front_back_persp_legacy_vert.glsl b/source/blender/gpu/shaders/gpu_shader_edges_front_back_persp_legacy_vert.glsl
index 30b3bdb890d..ffd52a0a225 100644
--- a/source/blender/gpu/shaders/gpu_shader_edges_front_back_persp_legacy_vert.glsl
+++ b/source/blender/gpu/shaders/gpu_shader_edges_front_back_persp_legacy_vert.glsl
@@ -42,27 +42,27 @@ const vec4 invisible = vec4(0.0);
bool front(vec3 N)
{
- vec4 xformed = ModelViewMatrix * vec4(pos, 1.0);
- return dot(NormalMatrix * N, normalize(-xformed.xyz)) > 0.0;
+ vec4 xformed = ModelViewMatrix * vec4(pos, 1.0);
+ return dot(NormalMatrix * N, normalize(-xformed.xyz)) > 0.0;
}
void main()
{
- bool face_1_front = front(N1);
- bool face_2_front = front(N2);
-
- gl_Position = ModelViewProjectionMatrix * vec4(pos, 1.0);
-
- if (face_1_front && face_2_front) {
- // front-facing edge
- finalColor = drawFront ? frontColor : invisible;
- }
- else if (face_1_front || face_2_front) {
- // exactly one face is front-facing, silhouette edge
- finalColor = drawSilhouette ? silhouetteColor : invisible;
- }
- else {
- // back-facing edge
- finalColor = drawBack ? backColor : invisible;
- }
+ bool face_1_front = front(N1);
+ bool face_2_front = front(N2);
+
+ gl_Position = ModelViewProjectionMatrix * vec4(pos, 1.0);
+
+ if (face_1_front && face_2_front) {
+ // front-facing edge
+ finalColor = drawFront ? frontColor : invisible;
+ }
+ else if (face_1_front || face_2_front) {
+ // exactly one face is front-facing, silhouette edge
+ finalColor = drawSilhouette ? silhouetteColor : invisible;
+ }
+ else {
+ // back-facing edge
+ finalColor = drawBack ? backColor : invisible;
+ }
}
diff --git a/source/blender/gpu/shaders/gpu_shader_edges_front_back_persp_vert.glsl b/source/blender/gpu/shaders/gpu_shader_edges_front_back_persp_vert.glsl
index e1fb78dd1a9..c8b722e1d7e 100644
--- a/source/blender/gpu/shaders/gpu_shader_edges_front_back_persp_vert.glsl
+++ b/source/blender/gpu/shaders/gpu_shader_edges_front_back_persp_vert.glsl
@@ -14,7 +14,7 @@ uniform mat4 ModelViewMatrix;
uniform mat3 NormalMatrix;
in vec3 pos;
-in vec3 N1, N2; // normals of faces this edge joins (object coords)
+in vec3 N1, N2; // normals of faces this edge joins (object coords)
out vec4 MV_pos;
out float edgeClass;
@@ -23,22 +23,22 @@ out float edgeClass;
bool front(vec3 N, vec3 eye)
{
- return dot(NormalMatrix * N, eye) > 0.0;
+ return dot(NormalMatrix * N, eye) > 0.0;
}
void main()
{
- MV_pos = ModelViewMatrix * vec4(pos, 1.0);
+ MV_pos = ModelViewMatrix * vec4(pos, 1.0);
- vec3 eye = normalize(-MV_pos.xyz);
+ vec3 eye = normalize(-MV_pos.xyz);
- bool face_1_front = front(N1, eye);
- bool face_2_front = front(N2, eye);
+ bool face_1_front = front(N1, eye);
+ bool face_2_front = front(N2, eye);
- if (face_1_front && face_2_front)
- edgeClass = 1.0; // front-facing edge
- else if (face_1_front || face_2_front)
- edgeClass = 0.0; // exactly one face is front-facing, silhouette edge
- else
- edgeClass = -1.0; // back-facing edge
+ if (face_1_front && face_2_front)
+ edgeClass = 1.0; // front-facing edge
+ else if (face_1_front || face_2_front)
+ edgeClass = 0.0; // exactly one face is front-facing, silhouette edge
+ else
+ edgeClass = -1.0; // back-facing edge
}
diff --git a/source/blender/gpu/shaders/gpu_shader_edges_overlay_frag.glsl b/source/blender/gpu/shaders/gpu_shader_edges_overlay_frag.glsl
index 0538c037dcf..7b35f67dd54 100644
--- a/source/blender/gpu/shaders/gpu_shader_edges_overlay_frag.glsl
+++ b/source/blender/gpu/shaders/gpu_shader_edges_overlay_frag.glsl
@@ -4,17 +4,18 @@
const float transitionWidth = 1.0;
uniform vec4 fillColor = vec4(0);
-uniform vec4 outlineColor = vec4(0,0,0,1);
+uniform vec4 outlineColor = vec4(0, 0, 0, 1);
noperspective in vec3 distanceToOutline;
out vec4 FragColor;
-void main() {
- float edgeness = min(min(distanceToOutline.x, distanceToOutline.y), distanceToOutline.z);
+void main()
+{
+ float edgeness = min(min(distanceToOutline.x, distanceToOutline.y), distanceToOutline.z);
#if SMOOTH
- FragColor = mix(outlineColor, fillColor, smoothstep(0, transitionWidth, edgeness));
+ FragColor = mix(outlineColor, fillColor, smoothstep(0, transitionWidth, edgeness));
#else
- FragColor = (edgeness <= 0) ? outlineColor : fillColor;
+ FragColor = (edgeness <= 0) ? outlineColor : fillColor;
#endif
}
diff --git a/source/blender/gpu/shaders/gpu_shader_edges_overlay_geom.glsl b/source/blender/gpu/shaders/gpu_shader_edges_overlay_geom.glsl
index ad0dccb6c81..48fff1629fd 100644
--- a/source/blender/gpu/shaders/gpu_shader_edges_overlay_geom.glsl
+++ b/source/blender/gpu/shaders/gpu_shader_edges_overlay_geom.glsl
@@ -1,5 +1,5 @@
layout(triangles) in;
-layout(triangle_strip, max_vertices=3) out;
+layout(triangle_strip, max_vertices = 3) out;
uniform float outlineWidth = 1.0;
uniform vec2 viewportSize;
@@ -10,58 +10,63 @@ in float widthModulator[];
noperspective out vec3 distanceToOutline;
// project to screen space
-vec2 proj(int axis) {
- vec4 pos = pos_xformed[axis];
- return (0.5 * (pos.xy / pos.w) + 0.5) * viewportSize;
+vec2 proj(int axis)
+{
+ vec4 pos = pos_xformed[axis];
+ return (0.5 * (pos.xy / pos.w) + 0.5) * viewportSize;
}
-float dist(vec2 pos[3], int v) {
- // current vertex position
- vec2 vpos = pos[v];
- // endpoints of opposite edge
- vec2 e1 = pos[(v + 1) % 3];
- vec2 e2 = pos[(v + 2) % 3];
+float dist(vec2 pos[3], int v)
+{
+ // current vertex position
+ vec2 vpos = pos[v];
+ // endpoints of opposite edge
+ vec2 e1 = pos[(v + 1) % 3];
+ vec2 e2 = pos[(v + 2) % 3];
- float abs_det = length(cross(vec3(vpos - e1, 0), vec3(vpos - e2, 0))); // could simplify
- return abs_det / distance(e2, e1);
+ float abs_det = length(cross(vec3(vpos - e1, 0), vec3(vpos - e2, 0))); // could simplify
+ return abs_det / distance(e2, e1);
}
vec3 distance[3];
-void clearEdge(int v) {
- float distant = 10 * outlineWidth;
- for (int i = 0; i < 3; ++i)
- distance[i][v] += distant;
+void clearEdge(int v)
+{
+ float distant = 10 * outlineWidth;
+ for (int i = 0; i < 3; ++i)
+ distance[i][v] += distant;
}
-void modulateEdge(int v) {
- float offset = min(widthModulator[v],1) * outlineWidth;
- for (int i = 0; i < 3; ++i)
- distance[i][v] -= offset;
+void modulateEdge(int v)
+{
+ float offset = min(widthModulator[v], 1) * outlineWidth;
+ for (int i = 0; i < 3; ++i)
+ distance[i][v] -= offset;
}
-void main() {
- vec2 pos[3] = vec2[3](proj(0), proj(1), proj(2));
+void main()
+{
+ vec2 pos[3] = vec2[3](proj(0), proj(1), proj(2));
- for (int v = 0; v < 3; ++v)
- distance[v] = vec3(0);
+ for (int v = 0; v < 3; ++v)
+ distance[v] = vec3(0);
- for (int v = 0; v < 3; ++v) {
- if (widthModulator[v] > 0) {
- distance[v][v] = dist(pos, v);
- modulateEdge(v);
- }
- }
+ for (int v = 0; v < 3; ++v) {
+ if (widthModulator[v] > 0) {
+ distance[v][v] = dist(pos, v);
+ modulateEdge(v);
+ }
+ }
- for (int v = 0; v < 3; ++v)
- if (widthModulator[v] <= 0)
- clearEdge(v);
+ for (int v = 0; v < 3; ++v)
+ if (widthModulator[v] <= 0)
+ clearEdge(v);
- for (int v = 0; v < 3; ++v) {
- gl_Position = pos_xformed[v];
- distanceToOutline = distance[v];
- EmitVertex();
- }
+ for (int v = 0; v < 3; ++v) {
+ gl_Position = pos_xformed[v];
+ distanceToOutline = distance[v];
+ EmitVertex();
+ }
- EndPrimitive();
+ EndPrimitive();
}
diff --git a/source/blender/gpu/shaders/gpu_shader_edges_overlay_simple_geom.glsl b/source/blender/gpu/shaders/gpu_shader_edges_overlay_simple_geom.glsl
index ec692e210c2..12f5a2c7811 100644
--- a/source/blender/gpu/shaders/gpu_shader_edges_overlay_simple_geom.glsl
+++ b/source/blender/gpu/shaders/gpu_shader_edges_overlay_simple_geom.glsl
@@ -1,5 +1,5 @@
layout(triangles) in;
-layout(triangle_strip, max_vertices=3) out;
+layout(triangle_strip, max_vertices = 3) out;
uniform float outlineWidth = 1.0;
uniform vec2 viewportSize;
@@ -7,46 +7,50 @@ uniform vec2 viewportSize;
noperspective out vec3 distanceToOutline;
// project to screen space
-vec2 proj(int axis) {
- vec4 pos = gl_in[axis].gl_Position;
- return (0.5 * (pos.xy / pos.w) + 0.5) * viewportSize;
+vec2 proj(int axis)
+{
+ vec4 pos = gl_in[axis].gl_Position;
+ return (0.5 * (pos.xy / pos.w) + 0.5) * viewportSize;
}
-float dist(vec2 pos[3], int v) {
- // current vertex position
- vec2 vpos = pos[v];
- // endpoints of opposite edge
- vec2 e1 = pos[(v + 1) % 3];
- vec2 e2 = pos[(v + 2) % 3];
+float dist(vec2 pos[3], int v)
+{
+ // current vertex position
+ vec2 vpos = pos[v];
+ // endpoints of opposite edge
+ vec2 e1 = pos[(v + 1) % 3];
+ vec2 e2 = pos[(v + 2) % 3];
- float abs_det = length(cross(vec3(vpos - e1, 0), vec3(vpos - e2, 0))); // could simplify
- return abs_det / distance(e2, e1);
+ float abs_det = length(cross(vec3(vpos - e1, 0), vec3(vpos - e2, 0))); // could simplify
+ return abs_det / distance(e2, e1);
}
vec3 distance[3];
-void modulateEdge(int v) {
- float offset = 0.5 * outlineWidth;
- for (int i = 0; i < 3; ++i)
- distance[i][v] -= offset;
+void modulateEdge(int v)
+{
+ float offset = 0.5 * outlineWidth;
+ for (int i = 0; i < 3; ++i)
+ distance[i][v] -= offset;
}
-void main() {
- vec2 pos[3] = vec2[3](proj(0), proj(1), proj(2));
+void main()
+{
+ vec2 pos[3] = vec2[3](proj(0), proj(1), proj(2));
- for (int v = 0; v < 3; ++v)
- distance[v] = vec3(0);
+ for (int v = 0; v < 3; ++v)
+ distance[v] = vec3(0);
- for (int v = 0; v < 3; ++v) {
- distance[v][v] = dist(pos, v);
- modulateEdge(v);
- }
+ for (int v = 0; v < 3; ++v) {
+ distance[v][v] = dist(pos, v);
+ modulateEdge(v);
+ }
- for (int v = 0; v < 3; ++v) {
- gl_Position = gl_in[v].gl_Position;
- distanceToOutline = distance[v];
- EmitVertex();
- }
+ for (int v = 0; v < 3; ++v) {
+ gl_Position = gl_in[v].gl_Position;
+ distanceToOutline = distance[v];
+ EmitVertex();
+ }
- EndPrimitive();
+ EndPrimitive();
}
diff --git a/source/blender/gpu/shaders/gpu_shader_edges_overlay_vert.glsl b/source/blender/gpu/shaders/gpu_shader_edges_overlay_vert.glsl
index fb1d0aafe05..33615ac36e5 100644
--- a/source/blender/gpu/shaders/gpu_shader_edges_overlay_vert.glsl
+++ b/source/blender/gpu/shaders/gpu_shader_edges_overlay_vert.glsl
@@ -7,7 +7,8 @@ in float edgeWidthModulator;
out vec4 pos_xformed;
out float widthModulator;
-void main() {
- pos_xformed = ModelViewProjectionMatrix * vec4(pos, 1.0);
- widthModulator = edgeWidthModulator;
+void main()
+{
+ pos_xformed = ModelViewProjectionMatrix * vec4(pos, 1.0);
+ widthModulator = edgeWidthModulator;
}
diff --git a/source/blender/gpu/shaders/gpu_shader_flat_color_alpha_test_0_frag.glsl b/source/blender/gpu/shaders/gpu_shader_flat_color_alpha_test_0_frag.glsl
index cefae1021d2..d1a36c3ee38 100644
--- a/source/blender/gpu/shaders/gpu_shader_flat_color_alpha_test_0_frag.glsl
+++ b/source/blender/gpu/shaders/gpu_shader_flat_color_alpha_test_0_frag.glsl
@@ -4,8 +4,8 @@ out vec4 fragColor;
void main()
{
- if (finalColor.a > 0.0)
- fragColor = finalColor;
- else
- discard;
+ if (finalColor.a > 0.0)
+ fragColor = finalColor;
+ else
+ discard;
}
diff --git a/source/blender/gpu/shaders/gpu_shader_flat_color_frag.glsl b/source/blender/gpu/shaders/gpu_shader_flat_color_frag.glsl
index d738ed5ddb2..6c214534812 100644
--- a/source/blender/gpu/shaders/gpu_shader_flat_color_frag.glsl
+++ b/source/blender/gpu/shaders/gpu_shader_flat_color_frag.glsl
@@ -4,5 +4,5 @@ out vec4 fragColor;
void main()
{
- fragColor = finalColor;
+ fragColor = finalColor;
}
diff --git a/source/blender/gpu/shaders/gpu_shader_flat_id_frag.glsl b/source/blender/gpu/shaders/gpu_shader_flat_id_frag.glsl
index aa6f30531ae..8e1287c483a 100644
--- a/source/blender/gpu/shaders/gpu_shader_flat_id_frag.glsl
+++ b/source/blender/gpu/shaders/gpu_shader_flat_id_frag.glsl
@@ -4,5 +4,5 @@ out uint fragId;
void main()
{
- fragId = finalId;
+ fragId = finalId;
}
diff --git a/source/blender/gpu/shaders/gpu_shader_geometry.glsl b/source/blender/gpu/shaders/gpu_shader_geometry.glsl
index 705b79cbf56..f62040589e5 100644
--- a/source/blender/gpu/shaders/gpu_shader_geometry.glsl
+++ b/source/blender/gpu/shaders/gpu_shader_geometry.glsl
@@ -7,9 +7,11 @@ uniform int osd_active_uv_offset;
layout(lines_adjacency) in;
layout(triangle_strip, max_vertices = 4) out;
-in block {
- VertexData v;
-} inpt[];
+in block
+{
+ VertexData v;
+}
+inpt[];
/* compatibility */
out vec3 varnormal;
@@ -18,98 +20,98 @@ out vec3 varposition;
uniform bool osd_flat_shading;
uniform int osd_fvar_count;
-#define INTERP_FACE_VARYING_2(result, fvarOffset, tessCoord) \
- { \
- vec2 v[4]; \
- int primOffset = (gl_PrimitiveID + PrimitiveIdBase) * 4; \
- for (int i = 0; i < 4; ++i) { \
- int index = (primOffset + i) * osd_fvar_count + fvarOffset; \
- v[i] = vec2(texelFetch(FVarDataBuffer, index).s, \
- texelFetch(FVarDataBuffer, index + 1).s); \
- } \
- result = mix(mix(v[0], v[1], tessCoord.s), \
- mix(v[3], v[2], tessCoord.s), \
- tessCoord.t); \
- }
-
-# define INTERP_FACE_VARYING_ATT_2(result, fvarOffset, tessCoord) \
- { \
- vec2 tmp; \
- INTERP_FACE_VARYING_2(tmp, fvarOffset, tessCoord); \
- result = vec3(tmp, 0); \
- }
+#define INTERP_FACE_VARYING_2(result, fvarOffset, tessCoord) \
+ { \
+ vec2 v[4]; \
+ int primOffset = (gl_PrimitiveID + PrimitiveIdBase) * 4; \
+ for (int i = 0; i < 4; ++i) { \
+ int index = (primOffset + i) * osd_fvar_count + fvarOffset; \
+ v[i] = vec2(texelFetch(FVarDataBuffer, index).s, texelFetch(FVarDataBuffer, index + 1).s); \
+ } \
+ result = mix(mix(v[0], v[1], tessCoord.s), mix(v[3], v[2], tessCoord.s), tessCoord.t); \
+ }
+
+#define INTERP_FACE_VARYING_ATT_2(result, fvarOffset, tessCoord) \
+ { \
+ vec2 tmp; \
+ INTERP_FACE_VARYING_2(tmp, fvarOffset, tessCoord); \
+ result = vec3(tmp, 0); \
+ }
uniform samplerBuffer FVarDataBuffer;
uniform isamplerBuffer FVarDataOffsetBuffer;
-out block {
- VertexData v;
-} outpt;
+out block
+{
+ VertexData v;
+}
+outpt;
void set_mtface_vertex_attrs(vec2 st);
void emit_flat(int index, vec3 normal)
{
- outpt.v.position = inpt[index].v.position;
- outpt.v.normal = normal;
+ outpt.v.position = inpt[index].v.position;
+ outpt.v.normal = normal;
- /* Compatibility */
- varnormal = outpt.v.normal;
- varposition = outpt.v.position.xyz;
+ /* Compatibility */
+ varnormal = outpt.v.normal;
+ varposition = outpt.v.position.xyz;
- /* TODO(sergey): Only uniform subdivisions atm. */
- vec2 quadst[4] = vec2[](vec2(0, 0), vec2(1, 0), vec2(1, 1), vec2(0, 1));
- vec2 st = quadst[index];
+ /* TODO(sergey): Only uniform subdivisions atm. */
+ vec2 quadst[4] = vec2[](vec2(0, 0), vec2(1, 0), vec2(1, 1), vec2(0, 1));
+ vec2 st = quadst[index];
- INTERP_FACE_VARYING_2(outpt.v.uv, osd_active_uv_offset, st);
+ INTERP_FACE_VARYING_2(outpt.v.uv, osd_active_uv_offset, st);
- set_mtface_vertex_attrs(st);
+ set_mtface_vertex_attrs(st);
- gl_Position = ProjectionMatrix * inpt[index].v.position;
- EmitVertex();
+ gl_Position = ProjectionMatrix * inpt[index].v.position;
+ EmitVertex();
}
void emit_smooth(int index)
{
- outpt.v.position = inpt[index].v.position;
- outpt.v.normal = inpt[index].v.normal;
+ outpt.v.position = inpt[index].v.position;
+ outpt.v.normal = inpt[index].v.normal;
- /* Compatibility */
- varnormal = outpt.v.normal;
- varposition = outpt.v.position.xyz;
+ /* Compatibility */
+ varnormal = outpt.v.normal;
+ varposition = outpt.v.position.xyz;
- /* TODO(sergey): Only uniform subdivisions atm. */
- vec2 quadst[4] = vec2[](vec2(0, 0), vec2(1, 0), vec2(1, 1), vec2(0, 1));
- vec2 st = quadst[index];
+ /* TODO(sergey): Only uniform subdivisions atm. */
+ vec2 quadst[4] = vec2[](vec2(0, 0), vec2(1, 0), vec2(1, 1), vec2(0, 1));
+ vec2 st = quadst[index];
- INTERP_FACE_VARYING_2(outpt.v.uv, osd_active_uv_offset, st);
+ INTERP_FACE_VARYING_2(outpt.v.uv, osd_active_uv_offset, st);
- set_mtface_vertex_attrs(st);
+ set_mtface_vertex_attrs(st);
- gl_Position = ProjectionMatrix * inpt[index].v.position;
- EmitVertex();
+ gl_Position = ProjectionMatrix * inpt[index].v.position;
+ EmitVertex();
}
void main()
{
- gl_PrimitiveID = gl_PrimitiveIDIn;
-
- if (osd_flat_shading) {
- vec3 A = (inpt[0].v.position - inpt[1].v.position).xyz;
- vec3 B = (inpt[3].v.position - inpt[1].v.position).xyz;
- vec3 flat_normal = normalize(cross(B, A));
- emit_flat(0, flat_normal);
- emit_flat(1, flat_normal);
- emit_flat(3, flat_normal);
- emit_flat(2, flat_normal);
- }
- else {
- emit_smooth(0);
- emit_smooth(1);
- emit_smooth(3);
- emit_smooth(2);
- }
- EndPrimitive();
+ gl_PrimitiveID = gl_PrimitiveIDIn;
+
+ if (osd_flat_shading) {
+ vec3 A = (inpt[0].v.position - inpt[1].v.position).xyz;
+ vec3 B = (inpt[3].v.position - inpt[1].v.position).xyz;
+ vec3 flat_normal = normalize(cross(B, A));
+ emit_flat(0, flat_normal);
+ emit_flat(1, flat_normal);
+ emit_flat(3, flat_normal);
+ emit_flat(2, flat_normal);
+ }
+ else {
+ emit_smooth(0);
+ emit_smooth(1);
+ emit_smooth(3);
+ emit_smooth(2);
+ }
+ EndPrimitive();
}
-void set_mtface_vertex_attrs(vec2 st) {
+void set_mtface_vertex_attrs(vec2 st)
+{
diff --git a/source/blender/gpu/shaders/gpu_shader_gpencil_fill_frag.glsl b/source/blender/gpu/shaders/gpu_shader_gpencil_fill_frag.glsl
index 328fbbe26a1..946fc752e17 100644
--- a/source/blender/gpu/shaders/gpu_shader_gpencil_fill_frag.glsl
+++ b/source/blender/gpu/shaders/gpu_shader_gpencil_fill_frag.glsl
@@ -29,138 +29,152 @@ in vec2 texCoord_interp;
out vec4 fragColor;
#define texture2D texture
-void set_color(in vec4 color, in vec4 color2, in vec4 tcolor, in float mixv, in float factor,
- in int tmix, in int flip, out vec4 ocolor)
+void set_color(in vec4 color,
+ in vec4 color2,
+ in vec4 tcolor,
+ in float mixv,
+ in float factor,
+ in int tmix,
+ in int flip,
+ out vec4 ocolor)
{
- /* full color A */
- if (mixv == 1.0) {
- if (tmix == 1) {
- if (flip == 0) {
- ocolor = color;
- }
- else {
- ocolor = tcolor;
- }
- }
- else {
- if (flip == 0) {
- ocolor = color;
- }
- else {
- ocolor = color2;
- }
- }
- }
- /* full color B */
- else if (mixv == 0.0) {
- if (tmix == 1) {
- if (flip == 0) {
- ocolor = tcolor;
- }
- else {
- ocolor = color;
- }
- }
- else {
- if (flip == 0) {
- ocolor = color2;
- }
- else {
- ocolor = color;
- }
- }
- }
- /* mix of colors */
- else {
- if (tmix == 1) {
- if (flip == 0) {
- ocolor = mix(color, tcolor, factor);
- }
- else {
- ocolor = mix(tcolor, color, factor);
- }
- }
- else {
- if (flip == 0) {
- ocolor = mix(color, color2, factor);
- }
- else {
- ocolor = mix(color2, color, factor);
- }
- }
- }
+ /* full color A */
+ if (mixv == 1.0) {
+ if (tmix == 1) {
+ if (flip == 0) {
+ ocolor = color;
+ }
+ else {
+ ocolor = tcolor;
+ }
+ }
+ else {
+ if (flip == 0) {
+ ocolor = color;
+ }
+ else {
+ ocolor = color2;
+ }
+ }
+ }
+ /* full color B */
+ else if (mixv == 0.0) {
+ if (tmix == 1) {
+ if (flip == 0) {
+ ocolor = tcolor;
+ }
+ else {
+ ocolor = color;
+ }
+ }
+ else {
+ if (flip == 0) {
+ ocolor = color2;
+ }
+ else {
+ ocolor = color;
+ }
+ }
+ }
+ /* mix of colors */
+ else {
+ if (tmix == 1) {
+ if (flip == 0) {
+ ocolor = mix(color, tcolor, factor);
+ }
+ else {
+ ocolor = mix(tcolor, color, factor);
+ }
+ }
+ else {
+ if (flip == 0) {
+ ocolor = mix(color, color2, factor);
+ }
+ else {
+ ocolor = mix(color2, color, factor);
+ }
+ }
+ }
}
void main()
{
- vec2 t_center = vec2(0.5, 0.5);
- mat2 matrot_tex = mat2(cos(t_angle), -sin(t_angle), sin(t_angle), cos(t_angle));
- vec2 rot_tex = (matrot_tex * (texCoord_interp - t_center)) + t_center + t_offset;
- vec4 tmp_color = texture2D(myTexture, rot_tex * t_scale);
- vec4 text_color = vec4(tmp_color[0], tmp_color[1], tmp_color[2], tmp_color[3] * t_opacity);
- vec4 chesscolor;
+ vec2 t_center = vec2(0.5, 0.5);
+ mat2 matrot_tex = mat2(cos(t_angle), -sin(t_angle), sin(t_angle), cos(t_angle));
+ vec2 rot_tex = (matrot_tex * (texCoord_interp - t_center)) + t_center + t_offset;
+ vec4 tmp_color = texture2D(myTexture, rot_tex * t_scale);
+ vec4 text_color = vec4(tmp_color[0], tmp_color[1], tmp_color[2], tmp_color[3] * t_opacity);
+ vec4 chesscolor;
- /* solid fill */
- if (fill_type == SOLID) {
- if (t_mix == 1) {
- fragColor = mix(color, text_color, mix_factor);
- }
- else {
- fragColor = color;
- }
- }
- else {
- vec2 center = vec2(0.5, 0.5) + g_shift;
- mat2 matrot = mat2(cos(g_angle), -sin(g_angle), sin(g_angle), cos(g_angle));
- vec2 rot = (((matrot * (texCoord_interp - center)) + center) * g_scale) + g_shift;
- /* gradient */
- if (fill_type == GRADIENT) {
- set_color(color, color2, text_color, mix_factor, rot.x - mix_factor + 0.5, t_mix, t_flip, fragColor);
- }
- /* radial gradient */
- if (fill_type == RADIAL) {
- float in_rad = g_radius * mix_factor;
- float ex_rad = g_radius - in_rad;
- float intensity = 0;
- float distance = length((center - texCoord_interp) * g_scale);
- if (distance > g_radius) {
- discard;
- }
- if (distance > in_rad) {
- intensity = clamp(((distance - in_rad) / ex_rad), 0.0, 1.0);
- }
- set_color(color, color2, text_color, mix_factor, intensity, t_mix, t_flip, fragColor);
- }
- /* chessboard */
- if (fill_type == CHESS) {
- vec2 pos = rot / g_boxsize;
- if ((fract(pos.x) < 0.5 && fract(pos.y) < 0.5) || (fract(pos.x) > 0.5 && fract(pos.y) > 0.5)) {
- if (t_flip == 0) {
- chesscolor = color;
- }
- else {
- chesscolor = color2;
- }
- }
- else {
- if (t_flip == 0) {
- chesscolor = color2;
- }
- else {
- chesscolor = color;
- }
- }
- /* mix with texture */
- if (t_mix == 1) {
- fragColor = mix(chesscolor, text_color, mix_factor);
- }
- else {
- fragColor = chesscolor;
- }
- }
- /* texture */
- if (fill_type == TEXTURE) {
- fragColor = text_color;
- }
- }
+ /* solid fill */
+ if (fill_type == SOLID) {
+ if (t_mix == 1) {
+ fragColor = mix(color, text_color, mix_factor);
+ }
+ else {
+ fragColor = color;
+ }
+ }
+ else {
+ vec2 center = vec2(0.5, 0.5) + g_shift;
+ mat2 matrot = mat2(cos(g_angle), -sin(g_angle), sin(g_angle), cos(g_angle));
+ vec2 rot = (((matrot * (texCoord_interp - center)) + center) * g_scale) + g_shift;
+ /* gradient */
+ if (fill_type == GRADIENT) {
+ set_color(color,
+ color2,
+ text_color,
+ mix_factor,
+ rot.x - mix_factor + 0.5,
+ t_mix,
+ t_flip,
+ fragColor);
+ }
+ /* radial gradient */
+ if (fill_type == RADIAL) {
+ float in_rad = g_radius * mix_factor;
+ float ex_rad = g_radius - in_rad;
+ float intensity = 0;
+ float distance = length((center - texCoord_interp) * g_scale);
+ if (distance > g_radius) {
+ discard;
+ }
+ if (distance > in_rad) {
+ intensity = clamp(((distance - in_rad) / ex_rad), 0.0, 1.0);
+ }
+ set_color(color, color2, text_color, mix_factor, intensity, t_mix, t_flip, fragColor);
+ }
+ /* chessboard */
+ if (fill_type == CHESS) {
+ vec2 pos = rot / g_boxsize;
+ if ((fract(pos.x) < 0.5 && fract(pos.y) < 0.5) ||
+ (fract(pos.x) > 0.5 && fract(pos.y) > 0.5)) {
+ if (t_flip == 0) {
+ chesscolor = color;
+ }
+ else {
+ chesscolor = color2;
+ }
+ }
+ else {
+ if (t_flip == 0) {
+ chesscolor = color2;
+ }
+ else {
+ chesscolor = color;
+ }
+ }
+ /* mix with texture */
+ if (t_mix == 1) {
+ fragColor = mix(chesscolor, text_color, mix_factor);
+ }
+ else {
+ fragColor = chesscolor;
+ }
+ }
+ /* texture */
+ if (fill_type == TEXTURE) {
+ fragColor = text_color;
+ }
+ }
}
diff --git a/source/blender/gpu/shaders/gpu_shader_gpencil_fill_vert.glsl b/source/blender/gpu/shaders/gpu_shader_gpencil_fill_vert.glsl
index 2bc381a3689..5e469fec42e 100644
--- a/source/blender/gpu/shaders/gpu_shader_gpencil_fill_vert.glsl
+++ b/source/blender/gpu/shaders/gpu_shader_gpencil_fill_vert.glsl
@@ -6,6 +6,6 @@ out vec2 texCoord_interp;
void main(void)
{
- gl_Position = ModelViewProjectionMatrix * vec4( pos, 1.0 );
- texCoord_interp = texCoord;
+ gl_Position = ModelViewProjectionMatrix * vec4(pos, 1.0);
+ texCoord_interp = texCoord;
}
diff --git a/source/blender/gpu/shaders/gpu_shader_gpencil_stroke_frag.glsl b/source/blender/gpu/shaders/gpu_shader_gpencil_stroke_frag.glsl
index 7bb7693d202..fc3f47c0aaa 100644
--- a/source/blender/gpu/shaders/gpu_shader_gpencil_stroke_frag.glsl
+++ b/source/blender/gpu/shaders/gpu_shader_gpencil_stroke_frag.glsl
@@ -5,16 +5,16 @@ out vec4 fragColor;
void main()
{
- const vec2 center = vec2(0, 0.5);
- vec4 tColor = vec4(mColor);
- /* if alpha < 0, then encap */
- if (mColor.a < 0) {
- tColor.a = tColor.a * -1.0;
- float dist = length(mTexCoord - center);
- if (dist > 0.25) {
- discard;
- }
- }
- /* Solid */
- fragColor = tColor;
+ const vec2 center = vec2(0, 0.5);
+ vec4 tColor = vec4(mColor);
+ /* if alpha < 0, then encap */
+ if (mColor.a < 0) {
+ tColor.a = tColor.a * -1.0;
+ float dist = length(mTexCoord - center);
+ if (dist > 0.25) {
+ discard;
+ }
+ }
+ /* Solid */
+ fragColor = tColor;
}
diff --git a/source/blender/gpu/shaders/gpu_shader_gpencil_stroke_geom.glsl b/source/blender/gpu/shaders/gpu_shader_gpencil_stroke_geom.glsl
index 6c7e2d17e06..fcef4c266e8 100644
--- a/source/blender/gpu/shaders/gpu_shader_gpencil_stroke_geom.glsl
+++ b/source/blender/gpu/shaders/gpu_shader_gpencil_stroke_geom.glsl
@@ -16,203 +16,211 @@ out vec2 mTexCoord;
#define GP_XRAY_FRONT 0
#define GP_XRAY_3DSPACE 1
-#define GP_XRAY_BACK 2
+#define GP_XRAY_BACK 2
#define GPENCIL_FLATCAP 1
/* project 3d point to 2d on screen space */
vec2 toScreenSpace(vec4 vertex)
{
- return vec2(vertex.xy / vertex.w) * Viewport;
+ return vec2(vertex.xy / vertex.w) * Viewport;
}
/* get zdepth value */
float getZdepth(vec4 point)
{
- if (xraymode == GP_XRAY_FRONT) {
- return 0.0;
- }
- if (xraymode == GP_XRAY_3DSPACE) {
- return (point.z / point.w);
- }
- if (xraymode == GP_XRAY_BACK) {
- return 1.0;
- }
-
- /* in front by default */
- return 0.0;
+ if (xraymode == GP_XRAY_FRONT) {
+ return 0.0;
+ }
+ if (xraymode == GP_XRAY_3DSPACE) {
+ return (point.z / point.w);
+ }
+ if (xraymode == GP_XRAY_BACK) {
+ return 1.0;
+ }
+
+ /* in front by default */
+ return 0.0;
}
/* check equality but with a small tolerance */
bool is_equal(vec4 p1, vec4 p2)
{
- float limit = 0.0001;
- float x = abs(p1.x - p2.x);
- float y = abs(p1.y - p2.y);
- float z = abs(p1.z - p2.z);
+ float limit = 0.0001;
+ float x = abs(p1.x - p2.x);
+ float y = abs(p1.y - p2.y);
+ float z = abs(p1.z - p2.z);
- if ((x < limit) && (y < limit) && (z < limit)) {
- return true;
- }
+ if ((x < limit) && (y < limit) && (z < limit)) {
+ return true;
+ }
- return false;
+ return false;
}
void main(void)
{
- float MiterLimit = 0.75;
-
- /* receive 4 points */
- vec4 P0 = gl_in[0].gl_Position;
- vec4 P1 = gl_in[1].gl_Position;
- vec4 P2 = gl_in[2].gl_Position;
- vec4 P3 = gl_in[3].gl_Position;
-
- /* get the four vertices passed to the shader */
- vec2 sp0 = toScreenSpace(P0); // start of previous segment
- vec2 sp1 = toScreenSpace(P1); // end of previous segment, start of current segment
- vec2 sp2 = toScreenSpace(P2); // end of current segment, start of next segment
- vec2 sp3 = toScreenSpace(P3); // end of next segment
-
- /* culling outside viewport */
- vec2 area = Viewport * 4.0;
- if (sp1.x < -area.x || sp1.x > area.x) return;
- if (sp1.y < -area.y || sp1.y > area.y) return;
- if (sp2.x < -area.x || sp2.x > area.x) return;
- if (sp2.y < -area.y || sp2.y > area.y) return;
-
- /* determine the direction of each of the 3 segments (previous, current, next) */
- vec2 v0 = normalize(sp1 - sp0);
- vec2 v1 = normalize(sp2 - sp1);
- vec2 v2 = normalize(sp3 - sp2);
-
- /* determine the normal of each of the 3 segments (previous, current, next) */
- vec2 n0 = vec2(-v0.y, v0.x);
- vec2 n1 = vec2(-v1.y, v1.x);
- vec2 n2 = vec2(-v2.y, v2.x);
-
- /* determine miter lines by averaging the normals of the 2 segments */
- vec2 miter_a = normalize(n0 + n1); // miter at start of current segment
- vec2 miter_b = normalize(n1 + n2); // miter at end of current segment
-
- /* determine the length of the miter by projecting it onto normal and then inverse it */
- float an1 = dot(miter_a, n1);
- float bn1 = dot(miter_b, n2);
- if (an1 == 0) an1 = 1;
- if (bn1 == 0) bn1 = 1;
- float length_a = finalThickness[1] / an1;
- float length_b = finalThickness[2] / bn1;
- if (length_a <= 0.0) length_a = 0.01;
- if (length_b <= 0.0) length_b = 0.01;
-
- /* prevent excessively long miters at sharp corners */
- if (dot(v0, v1) < -MiterLimit) {
- miter_a = n1;
- length_a = finalThickness[1];
-
- /* close the gap */
- if (dot(v0, n1) > 0) {
- mTexCoord = vec2(0, 0);
- mColor = finalColor[1];
- gl_Position = vec4((sp1 + finalThickness[1] * n0) / Viewport, getZdepth(P1), 1.0);
- EmitVertex();
-
- mTexCoord = vec2(0, 0);
- mColor = finalColor[1];
- gl_Position = vec4((sp1 + finalThickness[1] * n1) / Viewport, getZdepth(P1), 1.0);
- EmitVertex();
-
- mTexCoord = vec2(0, 0.5);
- mColor = finalColor[1];
- gl_Position = vec4(sp1 / Viewport, getZdepth(P1), 1.0);
- EmitVertex();
-
- EndPrimitive();
- }
- else {
- mTexCoord = vec2(0, 1);
- mColor = finalColor[1];
- gl_Position = vec4((sp1 - finalThickness[1] * n1) / Viewport, getZdepth(P1), 1.0);
- EmitVertex();
-
- mTexCoord = vec2(0, 1);
- mColor = finalColor[1];
- gl_Position = vec4((sp1 - finalThickness[1] * n0) / Viewport, getZdepth(P1), 1.0);
- EmitVertex();
-
- mTexCoord = vec2(0, 0.5);
- mColor = finalColor[1];
- gl_Position = vec4(sp1 / Viewport, getZdepth(P1), 1.0);
- EmitVertex();
-
- EndPrimitive();
- }
- }
-
- if (dot(v1, v2) < -MiterLimit) {
- miter_b = n1;
- length_b = finalThickness[2];
- }
-
- /* generate the start endcap (alpha < 0 used as endcap flag)*/
- float extend = (fill_stroke > 0) ? 2 : 1 ;
- if ((caps_start != GPENCIL_FLATCAP) && is_equal(P0,P2)) {
- mTexCoord = vec2(1, 0.5);
- mColor = vec4(finalColor[1].rgb, finalColor[1].a * -1.0) ;
- vec2 svn1 = normalize(sp1 - sp2) * length_a * 4.0 * extend;
- gl_Position = vec4((sp1 + svn1) / Viewport, getZdepth(P1), 1.0);
- EmitVertex();
-
- mTexCoord = vec2(0, 0);
- mColor = vec4(finalColor[1].rgb, finalColor[1].a * -1.0) ;
- gl_Position = vec4((sp1 - (length_a * 2.0) * miter_a) / Viewport, getZdepth(P1), 1.0);
- EmitVertex();
-
- mTexCoord = vec2(0, 1);
- mColor = vec4(finalColor[1].rgb, finalColor[1].a * -1.0) ;
- gl_Position = vec4((sp1 + (length_a * 2.0) * miter_a) / Viewport, getZdepth(P1), 1.0);
- EmitVertex();
- }
-
- /* generate the triangle strip */
- mTexCoord = vec2(0, 0);
- mColor = finalColor[1];
- gl_Position = vec4((sp1 + length_a * miter_a) / Viewport, getZdepth(P1), 1.0);
- EmitVertex();
-
- mTexCoord = vec2(0, 1);
- mColor = finalColor[1];
- gl_Position = vec4((sp1 - length_a * miter_a) / Viewport, getZdepth(P1), 1.0);
- EmitVertex();
-
- mTexCoord = vec2(0, 0);
- mColor = finalColor[2];
- gl_Position = vec4((sp2 + length_b * miter_b) / Viewport, getZdepth(P2), 1.0);
- EmitVertex();
-
- mTexCoord = vec2(0, 1);
- mColor = finalColor[2];
- gl_Position = vec4((sp2 - length_b * miter_b) / Viewport, getZdepth(P2), 1.0);
- EmitVertex();
-
- /* generate the end endcap (alpha < 0 used as endcap flag)*/
- if ((caps_end != GPENCIL_FLATCAP) && is_equal(P1,P3)) {
- mTexCoord = vec2(0, 1);
- mColor = vec4(finalColor[2].rgb, finalColor[2].a * -1.0) ;
- gl_Position = vec4((sp2 + (length_b * 2.0) * miter_b) / Viewport, getZdepth(P2), 1.0);
- EmitVertex();
-
- mTexCoord = vec2(0, 0);
- mColor = vec4(finalColor[2].rgb, finalColor[2].a * -1.0) ;
- gl_Position = vec4((sp2 - (length_b * 2.0) * miter_b) / Viewport, getZdepth(P2), 1.0);
- EmitVertex();
-
- mTexCoord = vec2(1, 0.5);
- mColor = vec4(finalColor[2].rgb, finalColor[2].a * -1.0) ;
- vec2 svn2 = normalize(sp2 - sp1) * length_b * 4.0 * extend;
- gl_Position = vec4((sp2 + svn2) / Viewport, getZdepth(P2), 1.0);
- EmitVertex();
- }
-
- EndPrimitive();
+ float MiterLimit = 0.75;
+
+ /* receive 4 points */
+ vec4 P0 = gl_in[0].gl_Position;
+ vec4 P1 = gl_in[1].gl_Position;
+ vec4 P2 = gl_in[2].gl_Position;
+ vec4 P3 = gl_in[3].gl_Position;
+
+ /* get the four vertices passed to the shader */
+ vec2 sp0 = toScreenSpace(P0); // start of previous segment
+ vec2 sp1 = toScreenSpace(P1); // end of previous segment, start of current segment
+ vec2 sp2 = toScreenSpace(P2); // end of current segment, start of next segment
+ vec2 sp3 = toScreenSpace(P3); // end of next segment
+
+ /* culling outside viewport */
+ vec2 area = Viewport * 4.0;
+ if (sp1.x < -area.x || sp1.x > area.x)
+ return;
+ if (sp1.y < -area.y || sp1.y > area.y)
+ return;
+ if (sp2.x < -area.x || sp2.x > area.x)
+ return;
+ if (sp2.y < -area.y || sp2.y > area.y)
+ return;
+
+ /* determine the direction of each of the 3 segments (previous, current, next) */
+ vec2 v0 = normalize(sp1 - sp0);
+ vec2 v1 = normalize(sp2 - sp1);
+ vec2 v2 = normalize(sp3 - sp2);
+
+ /* determine the normal of each of the 3 segments (previous, current, next) */
+ vec2 n0 = vec2(-v0.y, v0.x);
+ vec2 n1 = vec2(-v1.y, v1.x);
+ vec2 n2 = vec2(-v2.y, v2.x);
+
+ /* determine miter lines by averaging the normals of the 2 segments */
+ vec2 miter_a = normalize(n0 + n1); // miter at start of current segment
+ vec2 miter_b = normalize(n1 + n2); // miter at end of current segment
+
+ /* determine the length of the miter by projecting it onto normal and then inverse it */
+ float an1 = dot(miter_a, n1);
+ float bn1 = dot(miter_b, n2);
+ if (an1 == 0)
+ an1 = 1;
+ if (bn1 == 0)
+ bn1 = 1;
+ float length_a = finalThickness[1] / an1;
+ float length_b = finalThickness[2] / bn1;
+ if (length_a <= 0.0)
+ length_a = 0.01;
+ if (length_b <= 0.0)
+ length_b = 0.01;
+
+ /* prevent excessively long miters at sharp corners */
+ if (dot(v0, v1) < -MiterLimit) {
+ miter_a = n1;
+ length_a = finalThickness[1];
+
+ /* close the gap */
+ if (dot(v0, n1) > 0) {
+ mTexCoord = vec2(0, 0);
+ mColor = finalColor[1];
+ gl_Position = vec4((sp1 + finalThickness[1] * n0) / Viewport, getZdepth(P1), 1.0);
+ EmitVertex();
+
+ mTexCoord = vec2(0, 0);
+ mColor = finalColor[1];
+ gl_Position = vec4((sp1 + finalThickness[1] * n1) / Viewport, getZdepth(P1), 1.0);
+ EmitVertex();
+
+ mTexCoord = vec2(0, 0.5);
+ mColor = finalColor[1];
+ gl_Position = vec4(sp1 / Viewport, getZdepth(P1), 1.0);
+ EmitVertex();
+
+ EndPrimitive();
+ }
+ else {
+ mTexCoord = vec2(0, 1);
+ mColor = finalColor[1];
+ gl_Position = vec4((sp1 - finalThickness[1] * n1) / Viewport, getZdepth(P1), 1.0);
+ EmitVertex();
+
+ mTexCoord = vec2(0, 1);
+ mColor = finalColor[1];
+ gl_Position = vec4((sp1 - finalThickness[1] * n0) / Viewport, getZdepth(P1), 1.0);
+ EmitVertex();
+
+ mTexCoord = vec2(0, 0.5);
+ mColor = finalColor[1];
+ gl_Position = vec4(sp1 / Viewport, getZdepth(P1), 1.0);
+ EmitVertex();
+
+ EndPrimitive();
+ }
+ }
+
+ if (dot(v1, v2) < -MiterLimit) {
+ miter_b = n1;
+ length_b = finalThickness[2];
+ }
+
+ /* generate the start endcap (alpha < 0 used as endcap flag)*/
+ float extend = (fill_stroke > 0) ? 2 : 1;
+ if ((caps_start != GPENCIL_FLATCAP) && is_equal(P0, P2)) {
+ mTexCoord = vec2(1, 0.5);
+ mColor = vec4(finalColor[1].rgb, finalColor[1].a * -1.0);
+ vec2 svn1 = normalize(sp1 - sp2) * length_a * 4.0 * extend;
+ gl_Position = vec4((sp1 + svn1) / Viewport, getZdepth(P1), 1.0);
+ EmitVertex();
+
+ mTexCoord = vec2(0, 0);
+ mColor = vec4(finalColor[1].rgb, finalColor[1].a * -1.0);
+ gl_Position = vec4((sp1 - (length_a * 2.0) * miter_a) / Viewport, getZdepth(P1), 1.0);
+ EmitVertex();
+
+ mTexCoord = vec2(0, 1);
+ mColor = vec4(finalColor[1].rgb, finalColor[1].a * -1.0);
+ gl_Position = vec4((sp1 + (length_a * 2.0) * miter_a) / Viewport, getZdepth(P1), 1.0);
+ EmitVertex();
+ }
+
+ /* generate the triangle strip */
+ mTexCoord = vec2(0, 0);
+ mColor = finalColor[1];
+ gl_Position = vec4((sp1 + length_a * miter_a) / Viewport, getZdepth(P1), 1.0);
+ EmitVertex();
+
+ mTexCoord = vec2(0, 1);
+ mColor = finalColor[1];
+ gl_Position = vec4((sp1 - length_a * miter_a) / Viewport, getZdepth(P1), 1.0);
+ EmitVertex();
+
+ mTexCoord = vec2(0, 0);
+ mColor = finalColor[2];
+ gl_Position = vec4((sp2 + length_b * miter_b) / Viewport, getZdepth(P2), 1.0);
+ EmitVertex();
+
+ mTexCoord = vec2(0, 1);
+ mColor = finalColor[2];
+ gl_Position = vec4((sp2 - length_b * miter_b) / Viewport, getZdepth(P2), 1.0);
+ EmitVertex();
+
+ /* generate the end endcap (alpha < 0 used as endcap flag)*/
+ if ((caps_end != GPENCIL_FLATCAP) && is_equal(P1, P3)) {
+ mTexCoord = vec2(0, 1);
+ mColor = vec4(finalColor[2].rgb, finalColor[2].a * -1.0);
+ gl_Position = vec4((sp2 + (length_b * 2.0) * miter_b) / Viewport, getZdepth(P2), 1.0);
+ EmitVertex();
+
+ mTexCoord = vec2(0, 0);
+ mColor = vec4(finalColor[2].rgb, finalColor[2].a * -1.0);
+ gl_Position = vec4((sp2 - (length_b * 2.0) * miter_b) / Viewport, getZdepth(P2), 1.0);
+ EmitVertex();
+
+ mTexCoord = vec2(1, 0.5);
+ mColor = vec4(finalColor[2].rgb, finalColor[2].a * -1.0);
+ vec2 svn2 = normalize(sp2 - sp1) * length_b * 4.0 * extend;
+ gl_Position = vec4((sp2 + svn2) / Viewport, getZdepth(P2), 1.0);
+ EmitVertex();
+ }
+
+ EndPrimitive();
}
diff --git a/source/blender/gpu/shaders/gpu_shader_gpencil_stroke_vert.glsl b/source/blender/gpu/shaders/gpu_shader_gpencil_stroke_vert.glsl
index 968f913d4e4..07b4ae52110 100644
--- a/source/blender/gpu/shaders/gpu_shader_gpencil_stroke_vert.glsl
+++ b/source/blender/gpu/shaders/gpu_shader_gpencil_stroke_vert.glsl
@@ -1,7 +1,7 @@
uniform mat4 ModelViewProjectionMatrix;
uniform mat4 ProjectionMatrix;
-uniform float pixsize; /* rv3d->pixsize */
+uniform float pixsize; /* rv3d->pixsize */
uniform int keep_size;
uniform float objscale;
uniform float pixfactor;
@@ -19,14 +19,15 @@ float defaultpixsize = pixsize * (1000.0 / pixfactor);
void main(void)
{
- gl_Position = ModelViewProjectionMatrix * vec4( pos, 1.0 );
- finalColor = color;
+ gl_Position = ModelViewProjectionMatrix * vec4(pos, 1.0);
+ finalColor = color;
- if (keep_size == TRUE) {
- finalThickness = thickness;
- }
- else {
- float size = (ProjectionMatrix[3][3] == 0.0) ? (thickness / (gl_Position.z * defaultpixsize)) : (thickness / defaultpixsize);
- finalThickness = max(size * objscale, 1.0);
- }
+ if (keep_size == TRUE) {
+ finalThickness = thickness;
+ }
+ else {
+ float size = (ProjectionMatrix[3][3] == 0.0) ? (thickness / (gl_Position.z * defaultpixsize)) :
+ (thickness / defaultpixsize);
+ finalThickness = max(size * objscale, 1.0);
+ }
}
diff --git a/source/blender/gpu/shaders/gpu_shader_image_alpha_color_frag.glsl b/source/blender/gpu/shaders/gpu_shader_image_alpha_color_frag.glsl
index e2af83ec529..cf71d4ac0c5 100644
--- a/source/blender/gpu/shaders/gpu_shader_image_alpha_color_frag.glsl
+++ b/source/blender/gpu/shaders/gpu_shader_image_alpha_color_frag.glsl
@@ -7,8 +7,8 @@ uniform sampler2D image;
void main()
{
- fragColor = texture(image, texCoord_interp).r * color.rgba;
- /* Premul by alpha (not texture alpha)
- * Use blending function GPU_blend_set_func(GPU_ONE, GPU_ONE_MINUS_SRC_ALPHA); */
- fragColor.rgb *= color.a;
+ fragColor = texture(image, texCoord_interp).r * color.rgba;
+ /* Premul by alpha (not texture alpha)
+ * Use blending function GPU_blend_set_func(GPU_ONE, GPU_ONE_MINUS_SRC_ALPHA); */
+ fragColor.rgb *= color.a;
}
diff --git a/source/blender/gpu/shaders/gpu_shader_image_color_frag.glsl b/source/blender/gpu/shaders/gpu_shader_image_color_frag.glsl
index ef8935cc7ba..6dc7a1618e1 100644
--- a/source/blender/gpu/shaders/gpu_shader_image_color_frag.glsl
+++ b/source/blender/gpu/shaders/gpu_shader_image_color_frag.glsl
@@ -7,5 +7,5 @@ uniform sampler2D image;
void main()
{
- fragColor = texture(image, texCoord_interp) * color;
+ fragColor = texture(image, texCoord_interp) * color;
}
diff --git a/source/blender/gpu/shaders/gpu_shader_image_depth_copy_frag.glsl b/source/blender/gpu/shaders/gpu_shader_image_depth_copy_frag.glsl
index 10f4dfd5a87..0f2749362b9 100644
--- a/source/blender/gpu/shaders/gpu_shader_image_depth_copy_frag.glsl
+++ b/source/blender/gpu/shaders/gpu_shader_image_depth_copy_frag.glsl
@@ -6,7 +6,7 @@ uniform sampler2D image;
void main()
{
- float depth = texture(image, texCoord_interp).r;
- fragColor = vec4(depth);
- gl_FragDepth = depth;
+ float depth = texture(image, texCoord_interp).r;
+ fragColor = vec4(depth);
+ gl_FragDepth = depth;
}
diff --git a/source/blender/gpu/shaders/gpu_shader_image_depth_linear_frag.glsl b/source/blender/gpu/shaders/gpu_shader_image_depth_linear_frag.glsl
index bcbe1f577fd..017b21076c8 100644
--- a/source/blender/gpu/shaders/gpu_shader_image_depth_linear_frag.glsl
+++ b/source/blender/gpu/shaders/gpu_shader_image_depth_linear_frag.glsl
@@ -8,9 +8,9 @@ uniform sampler2D image;
void main()
{
- float depth = texture(image, texCoord_interp).r;
+ float depth = texture(image, texCoord_interp).r;
- /* normalize */
- fragColor.rgb = vec3((2.0f * znear) / (zfar + znear - (depth * (zfar - znear))));
- fragColor.a = 1.0f;
+ /* normalize */
+ fragColor.rgb = vec3((2.0f * znear) / (zfar + znear - (depth * (zfar - znear))));
+ fragColor.a = 1.0f;
}
diff --git a/source/blender/gpu/shaders/gpu_shader_image_desaturate_frag.glsl b/source/blender/gpu/shaders/gpu_shader_image_desaturate_frag.glsl
index 1ac0d68b35f..dfbaaeda7b5 100644
--- a/source/blender/gpu/shaders/gpu_shader_image_desaturate_frag.glsl
+++ b/source/blender/gpu/shaders/gpu_shader_image_desaturate_frag.glsl
@@ -8,7 +8,7 @@ uniform sampler2D image;
void main()
{
- vec4 tex = texture(image, texCoord_interp);
- tex.rgb = ((0.3333333 * factor) * vec3(tex.r + tex.g + tex.b)) + (tex.rgb * (1.0 - factor));
- fragColor = tex * color;
+ vec4 tex = texture(image, texCoord_interp);
+ tex.rgb = ((0.3333333 * factor) * vec3(tex.r + tex.g + tex.b)) + (tex.rgb * (1.0 - factor));
+ fragColor = tex * color;
}
diff --git a/source/blender/gpu/shaders/gpu_shader_image_frag.glsl b/source/blender/gpu/shaders/gpu_shader_image_frag.glsl
index 6eeab8ca7e8..aff6ddf01bf 100644
--- a/source/blender/gpu/shaders/gpu_shader_image_frag.glsl
+++ b/source/blender/gpu/shaders/gpu_shader_image_frag.glsl
@@ -6,5 +6,5 @@ uniform sampler2D image;
void main()
{
- fragColor = texture(image, texCoord_interp);
+ fragColor = texture(image, texCoord_interp);
}
diff --git a/source/blender/gpu/shaders/gpu_shader_image_interlace_frag.glsl b/source/blender/gpu/shaders/gpu_shader_image_interlace_frag.glsl
index d95645f58e5..9b9d8149e09 100644
--- a/source/blender/gpu/shaders/gpu_shader_image_interlace_frag.glsl
+++ b/source/blender/gpu/shaders/gpu_shader_image_interlace_frag.glsl
@@ -1,8 +1,8 @@
/* Keep these in sync with GPU_shader.h */
-#define INTERLACE_ROW 0
-#define INTERLACE_COLUMN 1
-#define INTERLACE_CHECKERBOARD 2
+#define INTERLACE_ROW 0
+#define INTERLACE_COLUMN 1
+#define INTERLACE_CHECKERBOARD 2
in vec2 texCoord_interp;
out vec4 fragColor;
@@ -13,22 +13,23 @@ uniform sampler2D image_b;
bool interlace()
{
- if (interlace_id == INTERLACE_CHECKERBOARD) {
- return (int(gl_FragCoord.x + gl_FragCoord.y) & 1) != 0;
- }
- else if (interlace_id == INTERLACE_ROW) {
- return (int(gl_FragCoord.y) & 1) != 0;
- }
- else if (interlace_id == INTERLACE_COLUMN) {
- return (int(gl_FragCoord.x) & 1) != 0;
- }
+ if (interlace_id == INTERLACE_CHECKERBOARD) {
+ return (int(gl_FragCoord.x + gl_FragCoord.y) & 1) != 0;
+ }
+ else if (interlace_id == INTERLACE_ROW) {
+ return (int(gl_FragCoord.y) & 1) != 0;
+ }
+ else if (interlace_id == INTERLACE_COLUMN) {
+ return (int(gl_FragCoord.x) & 1) != 0;
+ }
}
void main()
{
- if (interlace()) {
- fragColor = texture(image_a, texCoord_interp);
- } else {
- fragColor = texture(image_b, texCoord_interp);
- }
+ if (interlace()) {
+ fragColor = texture(image_a, texCoord_interp);
+ }
+ else {
+ fragColor = texture(image_b, texCoord_interp);
+ }
}
diff --git a/source/blender/gpu/shaders/gpu_shader_image_linear_frag.glsl b/source/blender/gpu/shaders/gpu_shader_image_linear_frag.glsl
index 97eb3afc177..d843550cd9a 100644
--- a/source/blender/gpu/shaders/gpu_shader_image_linear_frag.glsl
+++ b/source/blender/gpu/shaders/gpu_shader_image_linear_frag.glsl
@@ -9,22 +9,23 @@ out vec4 fragColor;
float linearrgb_to_srgb(float c)
{
- if (c < 0.0031308)
- return (c < 0.0) ? 0.0 : c * 12.92;
- else
- return 1.055 * pow(c, 1.0 / 2.4) - 0.055;
+ if (c < 0.0031308)
+ return (c < 0.0) ? 0.0 : c * 12.92;
+ else
+ return 1.055 * pow(c, 1.0 / 2.4) - 0.055;
}
void linearrgb_to_srgb(vec4 col_from, out vec4 col_to)
{
- col_to.r = linearrgb_to_srgb(col_from.r);
- col_to.g = linearrgb_to_srgb(col_from.g);
- col_to.b = linearrgb_to_srgb(col_from.b);
- col_to.a = col_from.a;
+ col_to.r = linearrgb_to_srgb(col_from.r);
+ col_to.g = linearrgb_to_srgb(col_from.g);
+ col_to.b = linearrgb_to_srgb(col_from.b);
+ col_to.a = col_from.a;
}
-void main() {
- fragColor = texture(image, texCoord_interp.st);
+void main()
+{
+ fragColor = texture(image, texCoord_interp.st);
- linearrgb_to_srgb(fragColor, fragColor);
+ linearrgb_to_srgb(fragColor, fragColor);
}
diff --git a/source/blender/gpu/shaders/gpu_shader_image_mask_uniform_color_frag.glsl b/source/blender/gpu/shaders/gpu_shader_image_mask_uniform_color_frag.glsl
index 4a45d03175e..e5078d722b4 100644
--- a/source/blender/gpu/shaders/gpu_shader_image_mask_uniform_color_frag.glsl
+++ b/source/blender/gpu/shaders/gpu_shader_image_mask_uniform_color_frag.glsl
@@ -7,6 +7,6 @@ uniform vec4 color;
void main()
{
- fragColor.a = texture(image, texCoord_interp).a * color.a;
- fragColor.rgb = color.rgb;
+ fragColor.a = texture(image, texCoord_interp).a * color.a;
+ fragColor.rgb = color.rgb;
}
diff --git a/source/blender/gpu/shaders/gpu_shader_image_modulate_alpha_frag.glsl b/source/blender/gpu/shaders/gpu_shader_image_modulate_alpha_frag.glsl
index 51092d56e5e..613352b4ac8 100644
--- a/source/blender/gpu/shaders/gpu_shader_image_modulate_alpha_frag.glsl
+++ b/source/blender/gpu/shaders/gpu_shader_image_modulate_alpha_frag.glsl
@@ -7,6 +7,6 @@ uniform sampler2D image;
void main()
{
- fragColor = texture(image, texCoord_interp);
- fragColor.a *= alpha;
+ fragColor = texture(image, texCoord_interp);
+ fragColor.a *= alpha;
}
diff --git a/source/blender/gpu/shaders/gpu_shader_image_multisample_resolve_frag.glsl b/source/blender/gpu/shaders/gpu_shader_image_multisample_resolve_frag.glsl
index f763b491b59..ca425374a1b 100644
--- a/source/blender/gpu/shaders/gpu_shader_image_multisample_resolve_frag.glsl
+++ b/source/blender/gpu/shaders/gpu_shader_image_multisample_resolve_frag.glsl
@@ -5,115 +5,115 @@ uniform sampler2DMS colorMulti;
out vec4 fragColor;
#if SAMPLES > 16
-#error "Too many samples"
+# error "Too many samples"
#endif
void main()
{
- ivec2 texel = ivec2(gl_FragCoord.xy);
+ ivec2 texel = ivec2(gl_FragCoord.xy);
- bvec4 b1, b2, b3, b4;
- vec4 w1, w2, w3, w4;
- vec4 d1, d2, d3, d4;
- vec4 c1, c2, c3, c4, c5, c6, c7, c8;
- vec4 c9, c10, c11, c12, c13, c14, c15, c16;
- d1 = d2 = d3 = d4 = vec4(0.5);
- w1 = w2 = w3 = w4 = vec4(0.0);
- c1 = c2 = c3 = c4 = c5 = c6 = c7 = c8 = vec4(0.0);
- c9 = c10 = c11 = c12 = c13 = c14 = c15 = c16 = vec4(0.0);
+ bvec4 b1, b2, b3, b4;
+ vec4 w1, w2, w3, w4;
+ vec4 d1, d2, d3, d4;
+ vec4 c1, c2, c3, c4, c5, c6, c7, c8;
+ vec4 c9, c10, c11, c12, c13, c14, c15, c16;
+ d1 = d2 = d3 = d4 = vec4(0.5);
+ w1 = w2 = w3 = w4 = vec4(0.0);
+ c1 = c2 = c3 = c4 = c5 = c6 = c7 = c8 = vec4(0.0);
+ c9 = c10 = c11 = c12 = c13 = c14 = c15 = c16 = vec4(0.0);
#ifdef USE_DEPTH
- /* Depth */
- d1.x = texelFetch(depthMulti, texel, 0).r;
- d1.y = texelFetch(depthMulti, texel, 1).r;
+ /* Depth */
+ d1.x = texelFetch(depthMulti, texel, 0).r;
+ d1.y = texelFetch(depthMulti, texel, 1).r;
# if SAMPLES > 2
- d1.z = texelFetch(depthMulti, texel, 2).r;
- d1.w = texelFetch(depthMulti, texel, 3).r;
+ d1.z = texelFetch(depthMulti, texel, 2).r;
+ d1.w = texelFetch(depthMulti, texel, 3).r;
# endif
# if SAMPLES > 4
- d2.x = texelFetch(depthMulti, texel, 4).r;
- d2.y = texelFetch(depthMulti, texel, 5).r;
- d2.z = texelFetch(depthMulti, texel, 6).r;
- d2.w = texelFetch(depthMulti, texel, 7).r;
+ d2.x = texelFetch(depthMulti, texel, 4).r;
+ d2.y = texelFetch(depthMulti, texel, 5).r;
+ d2.z = texelFetch(depthMulti, texel, 6).r;
+ d2.w = texelFetch(depthMulti, texel, 7).r;
# endif
# if SAMPLES > 8
- d3.x = texelFetch(depthMulti, texel, 8).r;
- d3.y = texelFetch(depthMulti, texel, 9).r;
- d3.z = texelFetch(depthMulti, texel, 10).r;
- d3.w = texelFetch(depthMulti, texel, 11).r;
- d4.x = texelFetch(depthMulti, texel, 12).r;
- d4.y = texelFetch(depthMulti, texel, 13).r;
- d4.z = texelFetch(depthMulti, texel, 14).r;
- d4.w = texelFetch(depthMulti, texel, 15).r;
+ d3.x = texelFetch(depthMulti, texel, 8).r;
+ d3.y = texelFetch(depthMulti, texel, 9).r;
+ d3.z = texelFetch(depthMulti, texel, 10).r;
+ d3.w = texelFetch(depthMulti, texel, 11).r;
+ d4.x = texelFetch(depthMulti, texel, 12).r;
+ d4.y = texelFetch(depthMulti, texel, 13).r;
+ d4.z = texelFetch(depthMulti, texel, 14).r;
+ d4.w = texelFetch(depthMulti, texel, 15).r;
# endif
#endif
- /* COLOR */
- b1 = notEqual(d1, vec4(1.0));
- if (any(b1)) {
- c1 = texelFetch(colorMulti, texel, 0);
- c2 = texelFetch(colorMulti, texel, 1);
+ /* COLOR */
+ b1 = notEqual(d1, vec4(1.0));
+ if (any(b1)) {
+ c1 = texelFetch(colorMulti, texel, 0);
+ c2 = texelFetch(colorMulti, texel, 1);
#if SAMPLES > 2
- c3 = texelFetch(colorMulti, texel, 2);
- c4 = texelFetch(colorMulti, texel, 3);
+ c3 = texelFetch(colorMulti, texel, 2);
+ c4 = texelFetch(colorMulti, texel, 3);
#endif
- w1 = vec4(b1);
- }
+ w1 = vec4(b1);
+ }
#if SAMPLES > 4
- b2 = notEqual(d2, vec4(1.0));
- if (any(b2)) {
- c5 = texelFetch(colorMulti, texel, 4);
- c6 = texelFetch(colorMulti, texel, 5);
- c7 = texelFetch(colorMulti, texel, 6);
- c8 = texelFetch(colorMulti, texel, 7);
- w2 = vec4(b2);
- }
+ b2 = notEqual(d2, vec4(1.0));
+ if (any(b2)) {
+ c5 = texelFetch(colorMulti, texel, 4);
+ c6 = texelFetch(colorMulti, texel, 5);
+ c7 = texelFetch(colorMulti, texel, 6);
+ c8 = texelFetch(colorMulti, texel, 7);
+ w2 = vec4(b2);
+ }
#endif
#if SAMPLES > 8
- b3 = notEqual(d3, vec4(1.0));
- if (any(b3)) {
- c9 = texelFetch(colorMulti, texel, 8);
- c10 = texelFetch(colorMulti, texel, 9);
- c11 = texelFetch(colorMulti, texel, 10);
- c12 = texelFetch(colorMulti, texel, 11);
- w3 = vec4(b3);
- }
- b4 = notEqual(d4, vec4(1.0));
- if (any(b4)) {
- c13 = texelFetch(colorMulti, texel, 12);
- c14 = texelFetch(colorMulti, texel, 13);
- c15 = texelFetch(colorMulti, texel, 14);
- c16 = texelFetch(colorMulti, texel, 15);
- w4 = vec4(b4);
- }
+ b3 = notEqual(d3, vec4(1.0));
+ if (any(b3)) {
+ c9 = texelFetch(colorMulti, texel, 8);
+ c10 = texelFetch(colorMulti, texel, 9);
+ c11 = texelFetch(colorMulti, texel, 10);
+ c12 = texelFetch(colorMulti, texel, 11);
+ w3 = vec4(b3);
+ }
+ b4 = notEqual(d4, vec4(1.0));
+ if (any(b4)) {
+ c13 = texelFetch(colorMulti, texel, 12);
+ c14 = texelFetch(colorMulti, texel, 13);
+ c15 = texelFetch(colorMulti, texel, 14);
+ c16 = texelFetch(colorMulti, texel, 15);
+ w4 = vec4(b4);
+ }
#endif
#ifdef USE_DEPTH
# if SAMPLES > 8
- d1 = min(d1, min(d3, d4));
+ d1 = min(d1, min(d3, d4));
# endif
# if SAMPLES > 4
- d1 = min(d1, d2);
- d1 = min(d1, d2);
+ d1 = min(d1, d2);
+ d1 = min(d1, d2);
# endif
# if SAMPLES > 2
- d1.xy = min(d1.xy, d1.zw);
+ d1.xy = min(d1.xy, d1.zw);
# endif
- gl_FragDepth = min(d1.x, d1.y);
+ gl_FragDepth = min(d1.x, d1.y);
#endif
- c1 = c1 + c2;
+ c1 = c1 + c2;
#if SAMPLES > 2
- c1 += c3 + c4;
+ c1 += c3 + c4;
#endif
#if SAMPLES > 4
- c1 += c5 + c6 + c7 + c8;
+ c1 += c5 + c6 + c7 + c8;
#endif
#if SAMPLES > 8
- c1 += c9 + c10 + c11 + c12 + c13 + c14 + c15 + c16;
+ c1 += c9 + c10 + c11 + c12 + c13 + c14 + c15 + c16;
#endif
- const float inv_samples = 1.0 / float(SAMPLES);
+ const float inv_samples = 1.0 / float(SAMPLES);
- fragColor = c1 * inv_samples;
+ fragColor = c1 * inv_samples;
}
diff --git a/source/blender/gpu/shaders/gpu_shader_image_shuffle_color_frag.glsl b/source/blender/gpu/shaders/gpu_shader_image_shuffle_color_frag.glsl
index 64662247d69..ed69184ef14 100644
--- a/source/blender/gpu/shaders/gpu_shader_image_shuffle_color_frag.glsl
+++ b/source/blender/gpu/shaders/gpu_shader_image_shuffle_color_frag.glsl
@@ -8,9 +8,8 @@ uniform vec4 shuffle;
void main()
{
- vec4 sample = texture(image, texCoord_interp);
- fragColor = vec4(sample.r * shuffle.r +
- sample.g * shuffle.g +
- sample.b * shuffle.b +
- sample.a * shuffle.a) * color;
+ vec4 sample = texture(image, texCoord_interp);
+ fragColor = vec4(sample.r * shuffle.r + sample.g * shuffle.g + sample.b * shuffle.b +
+ sample.a * shuffle.a) *
+ color;
}
diff --git a/source/blender/gpu/shaders/gpu_shader_image_varying_color_frag.glsl b/source/blender/gpu/shaders/gpu_shader_image_varying_color_frag.glsl
index 37686092700..becf0fbd133 100644
--- a/source/blender/gpu/shaders/gpu_shader_image_varying_color_frag.glsl
+++ b/source/blender/gpu/shaders/gpu_shader_image_varying_color_frag.glsl
@@ -7,5 +7,5 @@ uniform sampler2D image;
void main()
{
- fragColor = texture(image, texCoord_interp) * finalColor;
+ fragColor = texture(image, texCoord_interp) * finalColor;
}
diff --git a/source/blender/gpu/shaders/gpu_shader_instance_camera_vert.glsl b/source/blender/gpu/shaders/gpu_shader_instance_camera_vert.glsl
index 6a6da3dd104..31b359dbe6d 100644
--- a/source/blender/gpu/shaders/gpu_shader_instance_camera_vert.glsl
+++ b/source/blender/gpu/shaders/gpu_shader_instance_camera_vert.glsl
@@ -18,40 +18,40 @@ flat out vec4 finalColor;
void main()
{
- vec3 pPos;
-
- if (pos == 1.0) {
- pPos = vec3(corners[0].xy, depth);
- }
- else if (pos == 2.0) {
- pPos = vec3(corners[0].zw, depth);
- }
- else if (pos == 3.0) {
- pPos = vec3(corners[1].xy, depth);
- }
- else if (pos == 4.0) {
- pPos = vec3(corners[1].zw, depth);
- }
- else if (pos == 5.0) {
- pPos = vec3(tria.xy, depth);
- }
- else if (pos == 6.0) {
- vec2 ofs = tria.xy - corners[0].xy;
- ofs.x = -ofs.x;
- pPos = vec3(corners[1].zw + ofs, depth);
- }
- else if (pos == 7.0) {
- pPos = vec3(tria.zw, depth);
- }
- else {
- pPos = vec3(0.0);
- }
-
- gl_Position = ViewProjectionMatrix * InstanceModelMatrix * vec4(pPos, 1.0);
-
- finalColor = vec4(color, 1.0);
+ vec3 pPos;
+
+ if (pos == 1.0) {
+ pPos = vec3(corners[0].xy, depth);
+ }
+ else if (pos == 2.0) {
+ pPos = vec3(corners[0].zw, depth);
+ }
+ else if (pos == 3.0) {
+ pPos = vec3(corners[1].xy, depth);
+ }
+ else if (pos == 4.0) {
+ pPos = vec3(corners[1].zw, depth);
+ }
+ else if (pos == 5.0) {
+ pPos = vec3(tria.xy, depth);
+ }
+ else if (pos == 6.0) {
+ vec2 ofs = tria.xy - corners[0].xy;
+ ofs.x = -ofs.x;
+ pPos = vec3(corners[1].zw + ofs, depth);
+ }
+ else if (pos == 7.0) {
+ pPos = vec3(tria.zw, depth);
+ }
+ else {
+ pPos = vec3(0.0);
+ }
+
+ gl_Position = ViewProjectionMatrix * InstanceModelMatrix * vec4(pPos, 1.0);
+
+ finalColor = vec4(color, 1.0);
#ifdef USE_WORLD_CLIP_PLANES
- world_clip_planes_calc_clip_distance((ModelMatrix * InstanceModelMatrix * vec4(pPos, 1.0)).xyz);
+ world_clip_planes_calc_clip_distance((ModelMatrix * InstanceModelMatrix * vec4(pPos, 1.0)).xyz);
#endif
}
diff --git a/source/blender/gpu/shaders/gpu_shader_instance_distance_line_vert.glsl b/source/blender/gpu/shaders/gpu_shader_instance_distance_line_vert.glsl
index 2097b900666..d9a0ffbbdac 100644
--- a/source/blender/gpu/shaders/gpu_shader_instance_distance_line_vert.glsl
+++ b/source/blender/gpu/shaders/gpu_shader_instance_distance_line_vert.glsl
@@ -16,15 +16,15 @@ flat out vec4 finalColor;
void main()
{
- float len = end - start;
- vec3 sta = vec3(0.0, 0.0, -start);
- vec4 pos_4d = vec4(pos * -len + sta, 1.0);
+ float len = end - start;
+ vec3 sta = vec3(0.0, 0.0, -start);
+ vec4 pos_4d = vec4(pos * -len + sta, 1.0);
- gl_Position = ViewProjectionMatrix * InstanceModelMatrix * pos_4d;
- gl_PointSize = size;
- finalColor = vec4(color, 1.0);
+ gl_Position = ViewProjectionMatrix * InstanceModelMatrix * pos_4d;
+ gl_PointSize = size;
+ finalColor = vec4(color, 1.0);
#ifdef USE_WORLD_CLIP_PLANES
- world_clip_planes_calc_clip_distance((InstanceModelMatrix * pos_4d).xyz);
+ world_clip_planes_calc_clip_distance((InstanceModelMatrix * pos_4d).xyz);
#endif
}
diff --git a/source/blender/gpu/shaders/gpu_shader_instance_edges_variying_color_geom.glsl b/source/blender/gpu/shaders/gpu_shader_instance_edges_variying_color_geom.glsl
index c19598ea8ab..f3bda2cf27d 100644
--- a/source/blender/gpu/shaders/gpu_shader_instance_edges_variying_color_geom.glsl
+++ b/source/blender/gpu/shaders/gpu_shader_instance_edges_variying_color_geom.glsl
@@ -27,39 +27,39 @@ flat out vec4 finalColor;
void emitLine(vec4 color)
{
- gl_Position = ProjectionMatrix * MV_pos[0];
+ gl_Position = ProjectionMatrix * MV_pos[0];
#ifdef USE_WORLD_CLIP_PLANES
- world_clip_planes_set_clip_distance(gl_in[0].gl_ClipDistance);
+ world_clip_planes_set_clip_distance(gl_in[0].gl_ClipDistance);
#endif
- EmitVertex();
+ EmitVertex();
- gl_Position = ProjectionMatrix * MV_pos[1];
+ gl_Position = ProjectionMatrix * MV_pos[1];
#ifdef USE_WORLD_CLIP_PLANES
- world_clip_planes_set_clip_distance(gl_in[1].gl_ClipDistance);
+ world_clip_planes_set_clip_distance(gl_in[1].gl_ClipDistance);
#endif
- finalColor = color;
- EmitVertex();
+ finalColor = color;
+ EmitVertex();
- EndPrimitive();
+ EndPrimitive();
}
void main()
{
- float finalEdgeClass = max(edgeClass[0], edgeClass[1]);
+ float finalEdgeClass = max(edgeClass[0], edgeClass[1]);
- if (finalEdgeClass > 0.0f) {
- // front-facing edge
- if (drawFront)
- emitLine(vec4(fCol[0], 0.75));
- }
- else if (finalEdgeClass < 0.0f) {
- // back-facing edge
- if (drawBack)
- emitLine(vec4(fCol[0], 0.5));
- }
- else {
- // exactly one face is front-facing, silhouette edge
- if (drawSilhouette)
- emitLine(vec4(fCol[0], 1.0));
- }
+ if (finalEdgeClass > 0.0f) {
+ // front-facing edge
+ if (drawFront)
+ emitLine(vec4(fCol[0], 0.75));
+ }
+ else if (finalEdgeClass < 0.0f) {
+ // back-facing edge
+ if (drawBack)
+ emitLine(vec4(fCol[0], 0.5));
+ }
+ else {
+ // exactly one face is front-facing, silhouette edge
+ if (drawSilhouette)
+ emitLine(vec4(fCol[0], 1.0));
+ }
}
diff --git a/source/blender/gpu/shaders/gpu_shader_instance_edges_variying_color_vert.glsl b/source/blender/gpu/shaders/gpu_shader_instance_edges_variying_color_vert.glsl
index 3877c63d00a..d9e73f81c45 100644
--- a/source/blender/gpu/shaders/gpu_shader_instance_edges_variying_color_vert.glsl
+++ b/source/blender/gpu/shaders/gpu_shader_instance_edges_variying_color_vert.glsl
@@ -14,7 +14,7 @@ uniform mat4 ViewMatrix;
uniform mat4 ProjectionMatrix;
in vec3 pos;
-in vec3 N1, N2; // normals of faces this edge joins (object coords)
+in vec3 N1, N2; // normals of faces this edge joins (object coords)
/* Instance attrs */
in vec3 color;
@@ -28,41 +28,41 @@ out vec3 fCol;
bool front(mat3 NormalMatrix, vec3 N, vec3 eye)
{
- return dot(NormalMatrix * N, eye) > 0.0;
+ return dot(NormalMatrix * N, eye) > 0.0;
}
void main()
{
- vec3 eye;
+ vec3 eye;
- mat4 ModelViewMatrix = ViewMatrix * InstanceModelMatrix;
+ mat4 ModelViewMatrix = ViewMatrix * InstanceModelMatrix;
- vec4 pos_4d = vec4(pos, 1.0);
- MV_pos = ModelViewMatrix * pos_4d;
+ vec4 pos_4d = vec4(pos, 1.0);
+ MV_pos = ModelViewMatrix * pos_4d;
- mat3 NormalMatrix = transpose(inverse(mat3(ModelViewMatrix)));
+ mat3 NormalMatrix = transpose(inverse(mat3(ModelViewMatrix)));
- /* if persp */
- if (ProjectionMatrix[3][3] == 0.0) {
- eye = normalize(-MV_pos.xyz);
- }
- else {
- eye = vec3(0.0, 0.0, 1.0);
- }
+ /* if persp */
+ if (ProjectionMatrix[3][3] == 0.0) {
+ eye = normalize(-MV_pos.xyz);
+ }
+ else {
+ eye = vec3(0.0, 0.0, 1.0);
+ }
- bool face_1_front = front(NormalMatrix, N1, eye);
- bool face_2_front = front(NormalMatrix, N2, eye);
+ bool face_1_front = front(NormalMatrix, N1, eye);
+ bool face_2_front = front(NormalMatrix, N2, eye);
- if (face_1_front && face_2_front)
- edgeClass = 1.0; // front-facing edge
- else if (face_1_front || face_2_front)
- edgeClass = 0.0; // exactly one face is front-facing, silhouette edge
- else
- edgeClass = -1.0; // back-facing edge
+ if (face_1_front && face_2_front)
+ edgeClass = 1.0; // front-facing edge
+ else if (face_1_front || face_2_front)
+ edgeClass = 0.0; // exactly one face is front-facing, silhouette edge
+ else
+ edgeClass = -1.0; // back-facing edge
- fCol = color;
+ fCol = color;
#ifdef USE_WORLD_CLIP_PLANES
- world_clip_planes_calc_clip_distance((InstanceModelMatrix * vec4(pos, 1.0)).xyz);
+ world_clip_planes_calc_clip_distance((InstanceModelMatrix * vec4(pos, 1.0)).xyz);
#endif
}
diff --git a/source/blender/gpu/shaders/gpu_shader_instance_objectspace_variying_color_vert.glsl b/source/blender/gpu/shaders/gpu_shader_instance_objectspace_variying_color_vert.glsl
index 087fec80537..9b1a08d8d86 100644
--- a/source/blender/gpu/shaders/gpu_shader_instance_objectspace_variying_color_vert.glsl
+++ b/source/blender/gpu/shaders/gpu_shader_instance_objectspace_variying_color_vert.glsl
@@ -15,13 +15,13 @@ flat out vec4 finalColor;
void main()
{
- mat4 ModelViewProjectionMatrix = ViewProjectionMatrix * InstanceModelMatrix;
- /* This is slow and run per vertex, but it's still faster than
- * doing it per instance on CPU and sending it on via instance attr. */
- mat3 NormalMatrix = transpose(inverse(mat3(ViewMatrix * InstanceModelMatrix)));
+ mat4 ModelViewProjectionMatrix = ViewProjectionMatrix * InstanceModelMatrix;
+ /* This is slow and run per vertex, but it's still faster than
+ * doing it per instance on CPU and sending it on via instance attr. */
+ mat3 NormalMatrix = transpose(inverse(mat3(ViewMatrix * InstanceModelMatrix)));
- gl_Position = ModelViewProjectionMatrix * vec4(pos, 1.0);
- normal = NormalMatrix * nor;
+ gl_Position = ModelViewProjectionMatrix * vec4(pos, 1.0);
+ normal = NormalMatrix * nor;
- finalColor = color;
+ finalColor = color;
}
diff --git a/source/blender/gpu/shaders/gpu_shader_instance_screen_aligned_vert.glsl b/source/blender/gpu/shaders/gpu_shader_instance_screen_aligned_vert.glsl
index 17799281f32..13c4a7a310e 100644
--- a/source/blender/gpu/shaders/gpu_shader_instance_screen_aligned_vert.glsl
+++ b/source/blender/gpu/shaders/gpu_shader_instance_screen_aligned_vert.glsl
@@ -17,24 +17,24 @@ flat out vec4 finalColor;
void main()
{
- vec3 offset = vec3(0.0);
+ vec3 offset = vec3(0.0);
#ifdef AXIS_NAME
- if (pos.z == 0.0)
- offset = vec3(1.125, 0.0, 0.0);
- else if (pos.z == 1.0)
- offset = vec3(0.0, 1.125, 0.0);
- else
- offset = vec3(0.0, 0.0, 1.125);
- offset *= size;
+ if (pos.z == 0.0)
+ offset = vec3(1.125, 0.0, 0.0);
+ else if (pos.z == 1.0)
+ offset = vec3(0.0, 1.125, 0.0);
+ else
+ offset = vec3(0.0, 0.0, 1.125);
+ offset *= size;
#endif
- vec3 screen_pos = screen_vecs[0].xyz * pos.x + screen_vecs[1].xyz * pos.y;
- vec4 pos_4d = InstanceModelMatrix * vec4(offset, 1.0) + vec4(screen_pos * size, 0.0);
- gl_Position = ViewProjectionMatrix * pos_4d;
- finalColor = vec4(color, 1.0);
+ vec3 screen_pos = screen_vecs[0].xyz * pos.x + screen_vecs[1].xyz * pos.y;
+ vec4 pos_4d = InstanceModelMatrix * vec4(offset, 1.0) + vec4(screen_pos * size, 0.0);
+ gl_Position = ViewProjectionMatrix * pos_4d;
+ finalColor = vec4(color, 1.0);
#ifdef USE_WORLD_CLIP_PLANES
- world_clip_planes_calc_clip_distance((ModelMatrix * pos_4d).xyz);
+ world_clip_planes_calc_clip_distance((ModelMatrix * pos_4d).xyz);
#endif
}
diff --git a/source/blender/gpu/shaders/gpu_shader_instance_screenspace_variying_color_vert.glsl b/source/blender/gpu/shaders/gpu_shader_instance_screenspace_variying_color_vert.glsl
index d2b85976d73..c7368f78890 100644
--- a/source/blender/gpu/shaders/gpu_shader_instance_screenspace_variying_color_vert.glsl
+++ b/source/blender/gpu/shaders/gpu_shader_instance_screenspace_variying_color_vert.glsl
@@ -15,19 +15,18 @@ flat out vec4 finalColor;
float mul_project_m4_v3_zfac(in vec3 co)
{
- return (ViewProjectionMatrix[0][3] * co.x) +
- (ViewProjectionMatrix[1][3] * co.y) +
- (ViewProjectionMatrix[2][3] * co.z) + ViewProjectionMatrix[3][3];
+ return (ViewProjectionMatrix[0][3] * co.x) + (ViewProjectionMatrix[1][3] * co.y) +
+ (ViewProjectionMatrix[2][3] * co.z) + ViewProjectionMatrix[3][3];
}
void main()
{
- float pix_size = mul_project_m4_v3_zfac(world_pos) * pixel_size;
- vec3 screen_pos = screen_vecs[0].xyz * pos.x + screen_vecs[1].xyz * pos.y;
- gl_Position = ViewProjectionMatrix * vec4(world_pos + screen_pos * size * pix_size, 1.0);
- finalColor = vec4(color, 1.0);
+ float pix_size = mul_project_m4_v3_zfac(world_pos) * pixel_size;
+ vec3 screen_pos = screen_vecs[0].xyz * pos.x + screen_vecs[1].xyz * pos.y;
+ gl_Position = ViewProjectionMatrix * vec4(world_pos + screen_pos * size * pix_size, 1.0);
+ finalColor = vec4(color, 1.0);
#ifdef USE_WORLD_CLIP_PLANES
- world_clip_planes_calc_clip_distance(world_pos);
+ world_clip_planes_calc_clip_distance(world_pos);
#endif
}
diff --git a/source/blender/gpu/shaders/gpu_shader_instance_variying_size_variying_color_vert.glsl b/source/blender/gpu/shaders/gpu_shader_instance_variying_size_variying_color_vert.glsl
index 6a55684c93c..3e52e43beae 100644
--- a/source/blender/gpu/shaders/gpu_shader_instance_variying_size_variying_color_vert.glsl
+++ b/source/blender/gpu/shaders/gpu_shader_instance_variying_size_variying_color_vert.glsl
@@ -18,12 +18,12 @@ flat out vec4 finalColor;
void main()
{
- finalColor = color;
+ finalColor = color;
- vec4 pos_4d = vec4(pos * size, 1.0);
- gl_Position = ViewProjectionMatrix * InstanceModelMatrix * pos_4d;
+ vec4 pos_4d = vec4(pos * size, 1.0);
+ gl_Position = ViewProjectionMatrix * InstanceModelMatrix * pos_4d;
#ifdef USE_WORLD_CLIP_PLANES
- world_clip_planes_calc_clip_distance((ModelMatrix * InstanceModelMatrix * pos_4d).xyz);
+ world_clip_planes_calc_clip_distance((ModelMatrix * InstanceModelMatrix * pos_4d).xyz);
#endif
}
diff --git a/source/blender/gpu/shaders/gpu_shader_instance_variying_size_variying_id_vert.glsl b/source/blender/gpu/shaders/gpu_shader_instance_variying_size_variying_id_vert.glsl
index 777c1498eec..edcff5e5d87 100644
--- a/source/blender/gpu/shaders/gpu_shader_instance_variying_size_variying_id_vert.glsl
+++ b/source/blender/gpu/shaders/gpu_shader_instance_variying_size_variying_id_vert.glsl
@@ -18,6 +18,6 @@ flat out uint finalId;
void main()
{
- gl_Position = ViewProjectionMatrix * InstanceModelMatrix * vec4(pos * size, 1.0);
- finalId = uint(baseId + callId);
+ gl_Position = ViewProjectionMatrix * InstanceModelMatrix * vec4(pos * size, 1.0);
+ finalId = uint(baseId + callId);
}
diff --git a/source/blender/gpu/shaders/gpu_shader_instance_vert.glsl b/source/blender/gpu/shaders/gpu_shader_instance_vert.glsl
index 803dc4b3bcf..eeca6e972fa 100644
--- a/source/blender/gpu/shaders/gpu_shader_instance_vert.glsl
+++ b/source/blender/gpu/shaders/gpu_shader_instance_vert.glsl
@@ -9,5 +9,5 @@ in mat4 InstanceModelMatrix;
void main()
{
- gl_Position = ViewProjectionMatrix * InstanceModelMatrix * vec4(pos, 1.0);
+ gl_Position = ViewProjectionMatrix * InstanceModelMatrix * vec4(pos, 1.0);
}
diff --git a/source/blender/gpu/shaders/gpu_shader_keyframe_diamond_frag.glsl b/source/blender/gpu/shaders/gpu_shader_keyframe_diamond_frag.glsl
index 1c12a4f942d..1c4039bc590 100644
--- a/source/blender/gpu/shaders/gpu_shader_keyframe_diamond_frag.glsl
+++ b/source/blender/gpu/shaders/gpu_shader_keyframe_diamond_frag.glsl
@@ -11,77 +11,79 @@ out vec4 fragColor;
const float diagonal_scale = sqrt(0.5);
const float minmax_bias = 0.7;
-const float minmax_scale = sqrt(1.0 / (1.0 + 1.0/minmax_bias));
+const float minmax_scale = sqrt(1.0 / (1.0 + 1.0 / minmax_bias));
-bool test(int bit) {
- return (finalFlags & bit) != 0;
+bool test(int bit)
+{
+ return (finalFlags & bit) != 0;
}
-void main() {
- vec2 pos = gl_PointCoord - vec2(0.5);
- vec2 absPos = abs(pos);
- float radius = (absPos.x + absPos.y) * diagonal_scale;
-
- float outline_dist = -1.0;
-
- /* Diamond outline */
- if (test(0x1)) {
- outline_dist = max(outline_dist, radius - radii[0]);
- }
-
- /* Circle outline */
- if (test(0x2)) {
- radius = length(absPos);
-
- outline_dist = max(outline_dist, radius - radii[1]);
- }
-
- /* Top & Bottom clamp */
- if (test(0x4)) {
- outline_dist = max(outline_dist, absPos.y - radii[2]);
- }
-
- /* Left & Right clamp */
- if (test(0x8)) {
- outline_dist = max(outline_dist, absPos.x - radii[2]);
- }
-
- float alpha = 1 - smoothstep(thresholds[0], thresholds[1], abs(outline_dist));
-
- /* Inside the outline. */
- if (outline_dist < 0) {
- /* Middle dot */
- if (test(0x10)) {
- alpha = max(alpha, 1 - smoothstep(thresholds[2], thresholds[3], radius));
- }
-
- /* Up and down arrow-like shading. */
- if (test(0x300)) {
- float ypos = -1.0;
-
- /* Up arrow (maximum) */
- if (test(0x100)) {
- ypos = max(ypos, pos.y);
- }
- /* Down arrow (minimum) */
- if (test(0x200)) {
- ypos = max(ypos, -pos.y);
- }
-
- /* Arrow shape threshold. */
- float minmax_dist = (ypos - radii[3]) - absPos.x * minmax_bias;
- float minmax_step = smoothstep(thresholds[0], thresholds[1], minmax_dist * minmax_scale);
-
- /* Reduced alpha for uncertain extremes. */
- float minmax_alpha = test(0x400) ? 0.55 : 0.85;
-
- alpha = max(alpha, minmax_step * minmax_alpha);
- }
-
- fragColor = mix(finalColor, finalOutlineColor, alpha);
- }
- /* Outside the outline. */
- else {
- fragColor = vec4(finalOutlineColor.rgb, finalOutlineColor.a * alpha);
- }
+void main()
+{
+ vec2 pos = gl_PointCoord - vec2(0.5);
+ vec2 absPos = abs(pos);
+ float radius = (absPos.x + absPos.y) * diagonal_scale;
+
+ float outline_dist = -1.0;
+
+ /* Diamond outline */
+ if (test(0x1)) {
+ outline_dist = max(outline_dist, radius - radii[0]);
+ }
+
+ /* Circle outline */
+ if (test(0x2)) {
+ radius = length(absPos);
+
+ outline_dist = max(outline_dist, radius - radii[1]);
+ }
+
+ /* Top & Bottom clamp */
+ if (test(0x4)) {
+ outline_dist = max(outline_dist, absPos.y - radii[2]);
+ }
+
+ /* Left & Right clamp */
+ if (test(0x8)) {
+ outline_dist = max(outline_dist, absPos.x - radii[2]);
+ }
+
+ float alpha = 1 - smoothstep(thresholds[0], thresholds[1], abs(outline_dist));
+
+ /* Inside the outline. */
+ if (outline_dist < 0) {
+ /* Middle dot */
+ if (test(0x10)) {
+ alpha = max(alpha, 1 - smoothstep(thresholds[2], thresholds[3], radius));
+ }
+
+ /* Up and down arrow-like shading. */
+ if (test(0x300)) {
+ float ypos = -1.0;
+
+ /* Up arrow (maximum) */
+ if (test(0x100)) {
+ ypos = max(ypos, pos.y);
+ }
+ /* Down arrow (minimum) */
+ if (test(0x200)) {
+ ypos = max(ypos, -pos.y);
+ }
+
+ /* Arrow shape threshold. */
+ float minmax_dist = (ypos - radii[3]) - absPos.x * minmax_bias;
+ float minmax_step = smoothstep(thresholds[0], thresholds[1], minmax_dist * minmax_scale);
+
+ /* Reduced alpha for uncertain extremes. */
+ float minmax_alpha = test(0x400) ? 0.55 : 0.85;
+
+ alpha = max(alpha, minmax_step * minmax_alpha);
+ }
+
+ fragColor = mix(finalColor, finalOutlineColor, alpha);
+ }
+ /* Outside the outline. */
+ else {
+ fragColor = vec4(finalOutlineColor.rgb, finalOutlineColor.a * alpha);
+ }
}
diff --git a/source/blender/gpu/shaders/gpu_shader_keyframe_diamond_vert.glsl b/source/blender/gpu/shaders/gpu_shader_keyframe_diamond_vert.glsl
index 26eb864821a..8dc92a2b415 100644
--- a/source/blender/gpu/shaders/gpu_shader_keyframe_diamond_vert.glsl
+++ b/source/blender/gpu/shaders/gpu_shader_keyframe_diamond_vert.glsl
@@ -22,62 +22,65 @@ flat out int finalFlags;
flat out vec4 radii;
flat out vec4 thresholds;
-bool test(int bit) {
- return (flags & bit) != 0;
+bool test(int bit)
+{
+ return (flags & bit) != 0;
}
-vec2 line_thresholds(float width) {
- return vec2(max(0, width - line_falloff), width);
+vec2 line_thresholds(float width)
+{
+ return vec2(max(0, width - line_falloff), width);
}
-void main() {
- gl_Position = ModelViewProjectionMatrix * vec4(pos, 0.0, 1.0);
+void main()
+{
+ gl_Position = ModelViewProjectionMatrix * vec4(pos, 0.0, 1.0);
- /* Align to pixel grid if the viewport size is known. */
- if (ViewportSize.x > 0) {
- vec2 scale = ViewportSize * 0.5;
- vec2 px_pos = (gl_Position.xy + 1) * scale;
- vec2 adj_pos = round(px_pos - 0.5) + 0.5;
- gl_Position.xy = adj_pos / scale - 1;
- }
+ /* Align to pixel grid if the viewport size is known. */
+ if (ViewportSize.x > 0) {
+ vec2 scale = ViewportSize * 0.5;
+ vec2 px_pos = (gl_Position.xy + 1) * scale;
+ vec2 adj_pos = round(px_pos - 0.5) + 0.5;
+ gl_Position.xy = adj_pos / scale - 1;
+ }
- /* Pass through parameters. */
- finalColor = color;
- finalOutlineColor = outlineColor;
- finalFlags = flags;
+ /* Pass through parameters. */
+ finalColor = color;
+ finalOutlineColor = outlineColor;
+ finalFlags = flags;
- if (!test(0xF)) {
- finalFlags |= 1;
- }
+ if (!test(0xF)) {
+ finalFlags |= 1;
+ }
- /* Size-dependent line thickness. */
- float half_width = (0.06 + (size - 10) * 0.04);
- float line_width = half_width + line_falloff;
+ /* Size-dependent line thickness. */
+ float half_width = (0.06 + (size - 10) * 0.04);
+ float line_width = half_width + line_falloff;
- /* Outline thresholds. */
- thresholds.xy = line_thresholds(line_width);
+ /* Outline thresholds. */
+ thresholds.xy = line_thresholds(line_width);
- /* Inner dot thresholds. */
- thresholds.zw = line_thresholds(line_width * 1.6);
+ /* Inner dot thresholds. */
+ thresholds.zw = line_thresholds(line_width * 1.6);
- /* Extend the primitive size by half line width on either side; odd for symmetry. */
- float ext_radius = round(0.5 * size) + thresholds.x;
+ /* Extend the primitive size by half line width on either side; odd for symmetry. */
+ float ext_radius = round(0.5 * size) + thresholds.x;
- gl_PointSize = ceil(ext_radius + thresholds.y) * 2 + 1;
+ gl_PointSize = ceil(ext_radius + thresholds.y) * 2 + 1;
- /* Diamond radius. */
- radii[0] = ext_radius * diagonal_scale;
+ /* Diamond radius. */
+ radii[0] = ext_radius * diagonal_scale;
- /* Circle radius. */
- radii[1] = ext_radius * circle_scale;
+ /* Circle radius. */
+ radii[1] = ext_radius * circle_scale;
- /* Square radius. */
- radii[2] = round(ext_radius * square_scale);
+ /* Square radius. */
+ radii[2] = round(ext_radius * square_scale);
- /* Min/max cutout offset. */
- radii[3] = -line_falloff;
+ /* Min/max cutout offset. */
+ radii[3] = -line_falloff;
- /* Convert to PointCoord units. */
- radii /= gl_PointSize;
- thresholds /= gl_PointSize;
+ /* Convert to PointCoord units. */
+ radii /= gl_PointSize;
+ thresholds /= gl_PointSize;
}
diff --git a/source/blender/gpu/shaders/gpu_shader_material.glsl b/source/blender/gpu/shaders/gpu_shader_material.glsl
index 034f93cc273..545629dbfa0 100644
--- a/source/blender/gpu/shaders/gpu_shader_material.glsl
+++ b/source/blender/gpu/shaders/gpu_shader_material.glsl
@@ -13,1468 +13,1680 @@ uniform mat4 ModelMatrixInverse;
float convert_rgba_to_float(vec4 color)
{
- return dot(color.rgb, vec3(0.2126, 0.7152, 0.0722));
+ return dot(color.rgb, vec3(0.2126, 0.7152, 0.0722));
}
float exp_blender(float f)
{
- return pow(2.71828182846, f);
+ return pow(2.71828182846, f);
}
float compatible_pow(float x, float y)
{
- if (y == 0.0) /* x^0 -> 1, including 0^0 */
- return 1.0;
+ if (y == 0.0) /* x^0 -> 1, including 0^0 */
+ return 1.0;
- /* glsl pow doesn't accept negative x */
- if (x < 0.0) {
- if (mod(-y, 2.0) == 0.0)
- return pow(-x, y);
- else
- return -pow(-x, y);
- }
- else if (x == 0.0)
- return 0.0;
+ /* glsl pow doesn't accept negative x */
+ if (x < 0.0) {
+ if (mod(-y, 2.0) == 0.0)
+ return pow(-x, y);
+ else
+ return -pow(-x, y);
+ }
+ else if (x == 0.0)
+ return 0.0;
- return pow(x, y);
+ return pow(x, y);
}
void rgb_to_hsv(vec4 rgb, out vec4 outcol)
{
- float cmax, cmin, h, s, v, cdelta;
- vec3 c;
+ float cmax, cmin, h, s, v, cdelta;
+ vec3 c;
- cmax = max(rgb[0], max(rgb[1], rgb[2]));
- cmin = min(rgb[0], min(rgb[1], rgb[2]));
- cdelta = cmax - cmin;
+ cmax = max(rgb[0], max(rgb[1], rgb[2]));
+ cmin = min(rgb[0], min(rgb[1], rgb[2]));
+ cdelta = cmax - cmin;
- v = cmax;
- if (cmax != 0.0)
- s = cdelta / cmax;
- else {
- s = 0.0;
- h = 0.0;
- }
+ v = cmax;
+ if (cmax != 0.0)
+ s = cdelta / cmax;
+ else {
+ s = 0.0;
+ h = 0.0;
+ }
- if (s == 0.0) {
- h = 0.0;
- }
- else {
- c = (vec3(cmax) - rgb.xyz) / cdelta;
+ if (s == 0.0) {
+ h = 0.0;
+ }
+ else {
+ c = (vec3(cmax) - rgb.xyz) / cdelta;
- if (rgb.x == cmax) h = c[2] - c[1];
- else if (rgb.y == cmax) h = 2.0 + c[0] - c[2];
- else h = 4.0 + c[1] - c[0];
+ if (rgb.x == cmax)
+ h = c[2] - c[1];
+ else if (rgb.y == cmax)
+ h = 2.0 + c[0] - c[2];
+ else
+ h = 4.0 + c[1] - c[0];
- h /= 6.0;
+ h /= 6.0;
- if (h < 0.0)
- h += 1.0;
- }
+ if (h < 0.0)
+ h += 1.0;
+ }
- outcol = vec4(h, s, v, rgb.w);
+ outcol = vec4(h, s, v, rgb.w);
}
void hsv_to_rgb(vec4 hsv, out vec4 outcol)
{
- float i, f, p, q, t, h, s, v;
- vec3 rgb;
-
- h = hsv[0];
- s = hsv[1];
- v = hsv[2];
-
- if (s == 0.0) {
- rgb = vec3(v, v, v);
- }
- else {
- if (h == 1.0)
- h = 0.0;
-
- h *= 6.0;
- i = floor(h);
- f = h - i;
- rgb = vec3(f, f, f);
- p = v * (1.0 - s);
- q = v * (1.0 - (s * f));
- t = v * (1.0 - (s * (1.0 - f)));
-
- if (i == 0.0) rgb = vec3(v, t, p);
- else if (i == 1.0) rgb = vec3(q, v, p);
- else if (i == 2.0) rgb = vec3(p, v, t);
- else if (i == 3.0) rgb = vec3(p, q, v);
- else if (i == 4.0) rgb = vec3(t, p, v);
- else rgb = vec3(v, p, q);
- }
-
- outcol = vec4(rgb, hsv.w);
+ float i, f, p, q, t, h, s, v;
+ vec3 rgb;
+
+ h = hsv[0];
+ s = hsv[1];
+ v = hsv[2];
+
+ if (s == 0.0) {
+ rgb = vec3(v, v, v);
+ }
+ else {
+ if (h == 1.0)
+ h = 0.0;
+
+ h *= 6.0;
+ i = floor(h);
+ f = h - i;
+ rgb = vec3(f, f, f);
+ p = v * (1.0 - s);
+ q = v * (1.0 - (s * f));
+ t = v * (1.0 - (s * (1.0 - f)));
+
+ if (i == 0.0)
+ rgb = vec3(v, t, p);
+ else if (i == 1.0)
+ rgb = vec3(q, v, p);
+ else if (i == 2.0)
+ rgb = vec3(p, v, t);
+ else if (i == 3.0)
+ rgb = vec3(p, q, v);
+ else if (i == 4.0)
+ rgb = vec3(t, p, v);
+ else
+ rgb = vec3(v, p, q);
+ }
+
+ outcol = vec4(rgb, hsv.w);
}
float srgb_to_linearrgb(float c)
{
- if (c < 0.04045)
- return (c < 0.0) ? 0.0 : c * (1.0 / 12.92);
- else
- return pow((c + 0.055) * (1.0 / 1.055), 2.4);
+ if (c < 0.04045)
+ return (c < 0.0) ? 0.0 : c * (1.0 / 12.92);
+ else
+ return pow((c + 0.055) * (1.0 / 1.055), 2.4);
}
float linearrgb_to_srgb(float c)
{
- if (c < 0.0031308)
- return (c < 0.0) ? 0.0 : c * 12.92;
- else
- return 1.055 * pow(c, 1.0 / 2.4) - 0.055;
+ if (c < 0.0031308)
+ return (c < 0.0) ? 0.0 : c * 12.92;
+ else
+ return 1.055 * pow(c, 1.0 / 2.4) - 0.055;
}
void srgb_to_linearrgb(vec4 col_from, out vec4 col_to)
{
- col_to.r = srgb_to_linearrgb(col_from.r);
- col_to.g = srgb_to_linearrgb(col_from.g);
- col_to.b = srgb_to_linearrgb(col_from.b);
- col_to.a = col_from.a;
+ col_to.r = srgb_to_linearrgb(col_from.r);
+ col_to.g = srgb_to_linearrgb(col_from.g);
+ col_to.b = srgb_to_linearrgb(col_from.b);
+ col_to.a = col_from.a;
}
void linearrgb_to_srgb(vec4 col_from, out vec4 col_to)
{
- col_to.r = linearrgb_to_srgb(col_from.r);
- col_to.g = linearrgb_to_srgb(col_from.g);
- col_to.b = linearrgb_to_srgb(col_from.b);
- col_to.a = col_from.a;
+ col_to.r = linearrgb_to_srgb(col_from.r);
+ col_to.g = linearrgb_to_srgb(col_from.g);
+ col_to.b = linearrgb_to_srgb(col_from.b);
+ col_to.a = col_from.a;
}
void color_to_normal_new_shading(vec3 color, out vec3 normal)
{
- normal = vec3(2.0) * color - vec3(1.0);
+ normal = vec3(2.0) * color - vec3(1.0);
}
void color_to_blender_normal_new_shading(vec3 color, out vec3 normal)
{
- normal = vec3(2.0, -2.0, -2.0) * color - vec3(1.0);
+ normal = vec3(2.0, -2.0, -2.0) * color - vec3(1.0);
}
#ifndef M_PI
-#define M_PI 3.14159265358979323846
+# define M_PI 3.14159265358979323846
#endif
#ifndef M_1_PI
-#define M_1_PI 0.318309886183790671538
+# define M_1_PI 0.318309886183790671538
#endif
/*********** SHADER NODES ***************/
-void particle_info(
- vec4 sprops, vec4 loc, vec3 vel, vec3 avel,
- out float index, out float random, out float age,
- out float life_time, out vec3 location,
- out float size, out vec3 velocity, out vec3 angular_velocity)
-{
- index = sprops.x;
- random = loc.w;
- age = sprops.y;
- life_time = sprops.z;
- size = sprops.w;
-
- location = loc.xyz;
- velocity = vel;
- angular_velocity = avel;
+void particle_info(vec4 sprops,
+ vec4 loc,
+ vec3 vel,
+ vec3 avel,
+ out float index,
+ out float random,
+ out float age,
+ out float life_time,
+ out vec3 location,
+ out float size,
+ out vec3 velocity,
+ out vec3 angular_velocity)
+{
+ index = sprops.x;
+ random = loc.w;
+ age = sprops.y;
+ life_time = sprops.z;
+ size = sprops.w;
+
+ location = loc.xyz;
+ velocity = vel;
+ angular_velocity = avel;
}
void vect_normalize(vec3 vin, out vec3 vout)
{
- vout = normalize(vin);
+ vout = normalize(vin);
}
void direction_transform_m4v3(vec3 vin, mat4 mat, out vec3 vout)
{
- vout = (mat * vec4(vin, 0.0)).xyz;
+ vout = (mat * vec4(vin, 0.0)).xyz;
}
void mat3_mul(vec3 vin, mat3 mat, out vec3 vout)
{
- vout = mat * vin;
+ vout = mat * vin;
}
void point_transform_m4v3(vec3 vin, mat4 mat, out vec3 vout)
{
- vout = (mat * vec4(vin, 1.0)).xyz;
+ vout = (mat * vec4(vin, 1.0)).xyz;
}
void point_texco_remap_square(vec3 vin, out vec3 vout)
{
- vout = vin * 2.0 - 1.0;
+ vout = vin * 2.0 - 1.0;
}
void point_texco_clamp(vec3 vin, sampler2D ima, out vec3 vout)
{
- vec2 half_texel_size = 0.5 / vec2(textureSize(ima, 0).xy);
- vout = clamp(vin, half_texel_size.xyy, 1.0 - half_texel_size.xyy);
+ vec2 half_texel_size = 0.5 / vec2(textureSize(ima, 0).xy);
+ vout = clamp(vin, half_texel_size.xyy, 1.0 - half_texel_size.xyy);
}
void point_map_to_sphere(vec3 vin, out vec3 vout)
{
- float len = length(vin);
- float v, u;
- if (len > 0.0) {
- if (vin.x == 0.0 && vin.y == 0.0)
- u = 0.0;
- else
- u = (1.0 - atan(vin.x, vin.y) / M_PI) / 2.0;
+ float len = length(vin);
+ float v, u;
+ if (len > 0.0) {
+ if (vin.x == 0.0 && vin.y == 0.0)
+ u = 0.0;
+ else
+ u = (1.0 - atan(vin.x, vin.y) / M_PI) / 2.0;
- v = 1.0 - acos(vin.z / len) / M_PI;
- }
- else
- v = u = 0.0;
+ v = 1.0 - acos(vin.z / len) / M_PI;
+ }
+ else
+ v = u = 0.0;
- vout = vec3(u, v, 0.0);
+ vout = vec3(u, v, 0.0);
}
void point_map_to_tube(vec3 vin, out vec3 vout)
{
- float u, v;
- v = (vin.z + 1.0) * 0.5;
- float len = sqrt(vin.x * vin.x + vin.y * vin[1]);
- if (len > 0.0)
- u = (1.0 - (atan(vin.x / len, vin.y / len) / M_PI)) * 0.5;
- else
- v = u = 0.0;
+ float u, v;
+ v = (vin.z + 1.0) * 0.5;
+ float len = sqrt(vin.x * vin.x + vin.y * vin[1]);
+ if (len > 0.0)
+ u = (1.0 - (atan(vin.x / len, vin.y / len) / M_PI)) * 0.5;
+ else
+ v = u = 0.0;
- vout = vec3(u, v, 0.0);
+ vout = vec3(u, v, 0.0);
}
-void mapping(vec3 vec, vec4 m0, vec4 m1, vec4 m2, vec4 m3, vec3 minvec, vec3 maxvec, out vec3 outvec)
+void mapping(
+ vec3 vec, vec4 m0, vec4 m1, vec4 m2, vec4 m3, vec3 minvec, vec3 maxvec, out vec3 outvec)
{
- mat4 mat = mat4(m0, m1, m2, m3);
- outvec = (mat * vec4(vec, 1.0)).xyz;
- outvec = clamp(outvec, minvec, maxvec);
+ mat4 mat = mat4(m0, m1, m2, m3);
+ outvec = (mat * vec4(vec, 1.0)).xyz;
+ outvec = clamp(outvec, minvec, maxvec);
}
void camera(vec3 co, out vec3 outview, out float outdepth, out float outdist)
{
- outdepth = abs(co.z);
- outdist = length(co);
- outview = normalize(co);
+ outdepth = abs(co.z);
+ outdist = length(co);
+ outview = normalize(co);
}
void math_add(float val1, float val2, out float outval)
{
- outval = val1 + val2;
+ outval = val1 + val2;
}
void math_subtract(float val1, float val2, out float outval)
{
- outval = val1 - val2;
+ outval = val1 - val2;
}
void math_multiply(float val1, float val2, out float outval)
{
- outval = val1 * val2;
+ outval = val1 * val2;
}
void math_divide(float val1, float val2, out float outval)
{
- if (val2 == 0.0)
- outval = 0.0;
- else
- outval = val1 / val2;
+ if (val2 == 0.0)
+ outval = 0.0;
+ else
+ outval = val1 / val2;
}
void math_sine(float val, out float outval)
{
- outval = sin(val);
+ outval = sin(val);
}
void math_cosine(float val, out float outval)
{
- outval = cos(val);
+ outval = cos(val);
}
void math_tangent(float val, out float outval)
{
- outval = tan(val);
+ outval = tan(val);
}
void math_asin(float val, out float outval)
{
- if (val <= 1.0 && val >= -1.0)
- outval = asin(val);
- else
- outval = 0.0;
+ if (val <= 1.0 && val >= -1.0)
+ outval = asin(val);
+ else
+ outval = 0.0;
}
void math_acos(float val, out float outval)
{
- if (val <= 1.0 && val >= -1.0)
- outval = acos(val);
- else
- outval = 0.0;
+ if (val <= 1.0 && val >= -1.0)
+ outval = acos(val);
+ else
+ outval = 0.0;
}
void math_atan(float val, out float outval)
{
- outval = atan(val);
+ outval = atan(val);
}
void math_pow(float val1, float val2, out float outval)
{
- if (val1 >= 0.0) {
- outval = compatible_pow(val1, val2);
- }
- else {
- float val2_mod_1 = mod(abs(val2), 1.0);
+ if (val1 >= 0.0) {
+ outval = compatible_pow(val1, val2);
+ }
+ else {
+ float val2_mod_1 = mod(abs(val2), 1.0);
- if (val2_mod_1 > 0.999 || val2_mod_1 < 0.001)
- outval = compatible_pow(val1, floor(val2 + 0.5));
- else
- outval = 0.0;
- }
+ if (val2_mod_1 > 0.999 || val2_mod_1 < 0.001)
+ outval = compatible_pow(val1, floor(val2 + 0.5));
+ else
+ outval = 0.0;
+ }
}
void math_log(float val1, float val2, out float outval)
{
- if (val1 > 0.0 && val2 > 0.0)
- outval = log2(val1) / log2(val2);
- else
- outval = 0.0;
+ if (val1 > 0.0 && val2 > 0.0)
+ outval = log2(val1) / log2(val2);
+ else
+ outval = 0.0;
}
void math_max(float val1, float val2, out float outval)
{
- outval = max(val1, val2);
+ outval = max(val1, val2);
}
void math_min(float val1, float val2, out float outval)
{
- outval = min(val1, val2);
+ outval = min(val1, val2);
}
void math_round(float val, out float outval)
{
- outval = floor(val + 0.5);
+ outval = floor(val + 0.5);
}
void math_less_than(float val1, float val2, out float outval)
{
- if (val1 < val2)
- outval = 1.0;
- else
- outval = 0.0;
+ if (val1 < val2)
+ outval = 1.0;
+ else
+ outval = 0.0;
}
void math_greater_than(float val1, float val2, out float outval)
{
- if (val1 > val2)
- outval = 1.0;
- else
- outval = 0.0;
+ if (val1 > val2)
+ outval = 1.0;
+ else
+ outval = 0.0;
}
void math_modulo(float val1, float val2, out float outval)
{
- if (val2 == 0.0)
- outval = 0.0;
- else
- outval = mod(val1, val2);
+ if (val2 == 0.0)
+ outval = 0.0;
+ else
+ outval = mod(val1, val2);
- /* change sign to match C convention, mod in GLSL will take absolute for negative numbers,
- * see https://www.opengl.org/sdk/docs/man/html/mod.xhtml */
- outval = (val1 > 0.0) ? outval : outval - val2;
+ /* change sign to match C convention, mod in GLSL will take absolute for negative numbers,
+ * see https://www.opengl.org/sdk/docs/man/html/mod.xhtml */
+ outval = (val1 > 0.0) ? outval : outval - val2;
}
void math_abs(float val1, out float outval)
{
- outval = abs(val1);
+ outval = abs(val1);
}
void math_atan2(float val1, float val2, out float outval)
{
- outval = atan(val1, val2);
+ outval = atan(val1, val2);
}
void math_floor(float val, out float outval)
{
- outval = floor(val);
+ outval = floor(val);
}
void math_ceil(float val, out float outval)
{
- outval = ceil(val);
+ outval = ceil(val);
}
void math_fract(float val, out float outval)
{
- outval = val - floor(val);
+ outval = val - floor(val);
}
void math_sqrt(float val, out float outval)
{
- if (val > 0.0)
- outval = sqrt(val);
- else
- outval = 0.0;
+ if (val > 0.0)
+ outval = sqrt(val);
+ else
+ outval = 0.0;
}
void squeeze(float val, float width, float center, out float outval)
{
- outval = 1.0 / (1.0 + pow(2.71828183, -((val - center) * width)));
+ outval = 1.0 / (1.0 + pow(2.71828183, -((val - center) * width)));
}
void vec_math_add(vec3 v1, vec3 v2, out vec3 outvec, out float outval)
{
- outvec = v1 + v2;
- outval = (abs(outvec[0]) + abs(outvec[1]) + abs(outvec[2])) * 0.333333;
+ outvec = v1 + v2;
+ outval = (abs(outvec[0]) + abs(outvec[1]) + abs(outvec[2])) * 0.333333;
}
void vec_math_sub(vec3 v1, vec3 v2, out vec3 outvec, out float outval)
{
- outvec = v1 - v2;
- outval = (abs(outvec[0]) + abs(outvec[1]) + abs(outvec[2])) * 0.333333;
+ outvec = v1 - v2;
+ outval = (abs(outvec[0]) + abs(outvec[1]) + abs(outvec[2])) * 0.333333;
}
void vec_math_average(vec3 v1, vec3 v2, out vec3 outvec, out float outval)
{
- outvec = v1 + v2;
- outval = length(outvec);
- outvec = normalize(outvec);
+ outvec = v1 + v2;
+ outval = length(outvec);
+ outvec = normalize(outvec);
}
void vec_math_mix(float strength, vec3 v1, vec3 v2, out vec3 outvec)
{
- outvec = strength * v1 + (1 - strength) * v2;
+ outvec = strength * v1 + (1 - strength) * v2;
}
void vec_math_dot(vec3 v1, vec3 v2, out vec3 outvec, out float outval)
{
- outvec = vec3(0);
- outval = dot(v1, v2);
+ outvec = vec3(0);
+ outval = dot(v1, v2);
}
void vec_math_cross(vec3 v1, vec3 v2, out vec3 outvec, out float outval)
{
- outvec = cross(v1, v2);
- outval = length(outvec);
- outvec /= outval;
+ outvec = cross(v1, v2);
+ outval = length(outvec);
+ outvec /= outval;
}
void vec_math_normalize(vec3 v, out vec3 outvec, out float outval)
{
- outval = length(v);
- outvec = normalize(v);
+ outval = length(v);
+ outvec = normalize(v);
}
void vec_math_negate(vec3 v, out vec3 outv)
{
- outv = -v;
+ outv = -v;
}
void invert_z(vec3 v, out vec3 outv)
{
- v.z = -v.z;
- outv = v;
+ v.z = -v.z;
+ outv = v;
}
void normal_new_shading(vec3 nor, vec3 dir, out vec3 outnor, out float outdot)
{
- outnor = dir;
- outdot = dot(normalize(nor), dir);
+ outnor = dir;
+ outdot = dot(normalize(nor), dir);
}
void curves_vec(float fac, vec3 vec, sampler1DArray curvemap, float layer, out vec3 outvec)
{
- vec4 co = vec4(vec * 0.5 + 0.5, layer);
- outvec.x = texture(curvemap, co.xw).x;
- outvec.y = texture(curvemap, co.yw).y;
- outvec.z = texture(curvemap, co.zw).z;
- outvec = mix(vec, outvec, fac);
+ vec4 co = vec4(vec * 0.5 + 0.5, layer);
+ outvec.x = texture(curvemap, co.xw).x;
+ outvec.y = texture(curvemap, co.yw).y;
+ outvec.z = texture(curvemap, co.zw).z;
+ outvec = mix(vec, outvec, fac);
}
/* ext is vec4(in_x, in_dy, out_x, out_dy). */
float curve_extrapolate(float x, float y, vec4 ext)
{
- if (x < 0.0) {
- return y + x * ext.y;
- }
- else if (x > 1.0) {
- return y + (x - 1.0) * ext.w;
- }
- else {
- return y;
- }
+ if (x < 0.0) {
+ return y + x * ext.y;
+ }
+ else if (x > 1.0) {
+ return y + (x - 1.0) * ext.w;
+ }
+ else {
+ return y;
+ }
}
#define RANGE_RESCALE(x, min, range) ((x - min) * range)
-void curves_rgb(
- float fac, vec4 col, sampler1DArray curvemap, float layer,
- vec4 range, vec4 ext_r, vec4 ext_g, vec4 ext_b, vec4 ext_a,
- out vec4 outcol)
+void curves_rgb(float fac,
+ vec4 col,
+ sampler1DArray curvemap,
+ float layer,
+ vec4 range,
+ vec4 ext_r,
+ vec4 ext_g,
+ vec4 ext_b,
+ vec4 ext_a,
+ out vec4 outcol)
{
- vec4 co = vec4(RANGE_RESCALE(col.rgb, ext_a.x, range.a), layer);
- vec3 samp;
- samp.r = texture(curvemap, co.xw).a;
- samp.g = texture(curvemap, co.yw).a;
- samp.b = texture(curvemap, co.zw).a;
+ vec4 co = vec4(RANGE_RESCALE(col.rgb, ext_a.x, range.a), layer);
+ vec3 samp;
+ samp.r = texture(curvemap, co.xw).a;
+ samp.g = texture(curvemap, co.yw).a;
+ samp.b = texture(curvemap, co.zw).a;
- samp.r = curve_extrapolate(co.x, samp.r, ext_a);
- samp.g = curve_extrapolate(co.y, samp.g, ext_a);
- samp.b = curve_extrapolate(co.z, samp.b, ext_a);
+ samp.r = curve_extrapolate(co.x, samp.r, ext_a);
+ samp.g = curve_extrapolate(co.y, samp.g, ext_a);
+ samp.b = curve_extrapolate(co.z, samp.b, ext_a);
- vec3 rgb_min = vec3(ext_r.x, ext_g.x, ext_b.x);
- co.xyz = RANGE_RESCALE(samp.rgb, rgb_min, range.rgb);
+ vec3 rgb_min = vec3(ext_r.x, ext_g.x, ext_b.x);
+ co.xyz = RANGE_RESCALE(samp.rgb, rgb_min, range.rgb);
- samp.r = texture(curvemap, co.xw).r;
- samp.g = texture(curvemap, co.yw).g;
- samp.b = texture(curvemap, co.zw).b;
+ samp.r = texture(curvemap, co.xw).r;
+ samp.g = texture(curvemap, co.yw).g;
+ samp.b = texture(curvemap, co.zw).b;
- outcol.r = curve_extrapolate(co.x, samp.r, ext_r);
- outcol.g = curve_extrapolate(co.y, samp.g, ext_g);
- outcol.b = curve_extrapolate(co.z, samp.b, ext_b);
- outcol.a = col.a;
+ outcol.r = curve_extrapolate(co.x, samp.r, ext_r);
+ outcol.g = curve_extrapolate(co.y, samp.g, ext_g);
+ outcol.b = curve_extrapolate(co.z, samp.b, ext_b);
+ outcol.a = col.a;
- outcol = mix(col, outcol, fac);
+ outcol = mix(col, outcol, fac);
}
-void curves_rgb_opti(
- float fac, vec4 col, sampler1DArray curvemap, float layer,
- vec4 range, vec4 ext_a,
- out vec4 outcol)
+void curves_rgb_opti(float fac,
+ vec4 col,
+ sampler1DArray curvemap,
+ float layer,
+ vec4 range,
+ vec4 ext_a,
+ out vec4 outcol)
{
- vec4 co = vec4(RANGE_RESCALE(col.rgb, ext_a.x, range.a), layer);
- vec3 samp;
- samp.r = texture(curvemap, co.xw).a;
- samp.g = texture(curvemap, co.yw).a;
- samp.b = texture(curvemap, co.zw).a;
+ vec4 co = vec4(RANGE_RESCALE(col.rgb, ext_a.x, range.a), layer);
+ vec3 samp;
+ samp.r = texture(curvemap, co.xw).a;
+ samp.g = texture(curvemap, co.yw).a;
+ samp.b = texture(curvemap, co.zw).a;
- outcol.r = curve_extrapolate(co.x, samp.r, ext_a);
- outcol.g = curve_extrapolate(co.y, samp.g, ext_a);
- outcol.b = curve_extrapolate(co.z, samp.b, ext_a);
- outcol.a = col.a;
+ outcol.r = curve_extrapolate(co.x, samp.r, ext_a);
+ outcol.g = curve_extrapolate(co.y, samp.g, ext_a);
+ outcol.b = curve_extrapolate(co.z, samp.b, ext_a);
+ outcol.a = col.a;
- outcol = mix(col, outcol, fac);
+ outcol = mix(col, outcol, fac);
}
void set_value(float val, out float outval)
{
- outval = val;
+ outval = val;
}
void set_rgb(vec3 col, out vec3 outcol)
{
- outcol = col;
+ outcol = col;
}
void set_rgba(vec4 col, out vec4 outcol)
{
- outcol = col;
+ outcol = col;
}
void set_value_zero(out float outval)
{
- outval = 0.0;
+ outval = 0.0;
}
void set_value_one(out float outval)
{
- outval = 1.0;
+ outval = 1.0;
}
void set_rgb_zero(out vec3 outval)
{
- outval = vec3(0.0);
+ outval = vec3(0.0);
}
void set_rgb_one(out vec3 outval)
{
- outval = vec3(1.0);
+ outval = vec3(1.0);
}
void set_rgba_zero(out vec4 outval)
{
- outval = vec4(0.0);
+ outval = vec4(0.0);
}
void set_rgba_one(out vec4 outval)
{
- outval = vec4(1.0);
+ outval = vec4(1.0);
}
void brightness_contrast(vec4 col, float brightness, float contrast, out vec4 outcol)
{
- float a = 1.0 + contrast;
- float b = brightness - contrast * 0.5;
+ float a = 1.0 + contrast;
+ float b = brightness - contrast * 0.5;
- outcol.r = max(a * col.r + b, 0.0);
- outcol.g = max(a * col.g + b, 0.0);
- outcol.b = max(a * col.b + b, 0.0);
- outcol.a = col.a;
+ outcol.r = max(a * col.r + b, 0.0);
+ outcol.g = max(a * col.g + b, 0.0);
+ outcol.b = max(a * col.b + b, 0.0);
+ outcol.a = col.a;
}
void mix_blend(float fac, vec4 col1, vec4 col2, out vec4 outcol)
{
- fac = clamp(fac, 0.0, 1.0);
- outcol = mix(col1, col2, fac);
- outcol.a = col1.a;
+ fac = clamp(fac, 0.0, 1.0);
+ outcol = mix(col1, col2, fac);
+ outcol.a = col1.a;
}
void mix_add(float fac, vec4 col1, vec4 col2, out vec4 outcol)
{
- fac = clamp(fac, 0.0, 1.0);
- outcol = mix(col1, col1 + col2, fac);
- outcol.a = col1.a;
+ fac = clamp(fac, 0.0, 1.0);
+ outcol = mix(col1, col1 + col2, fac);
+ outcol.a = col1.a;
}
void mix_mult(float fac, vec4 col1, vec4 col2, out vec4 outcol)
{
- fac = clamp(fac, 0.0, 1.0);
- outcol = mix(col1, col1 * col2, fac);
- outcol.a = col1.a;
+ fac = clamp(fac, 0.0, 1.0);
+ outcol = mix(col1, col1 * col2, fac);
+ outcol.a = col1.a;
}
void mix_screen(float fac, vec4 col1, vec4 col2, out vec4 outcol)
{
- fac = clamp(fac, 0.0, 1.0);
- float facm = 1.0 - fac;
+ fac = clamp(fac, 0.0, 1.0);
+ float facm = 1.0 - fac;
- outcol = vec4(1.0) - (vec4(facm) + fac * (vec4(1.0) - col2)) * (vec4(1.0) - col1);
- outcol.a = col1.a;
+ outcol = vec4(1.0) - (vec4(facm) + fac * (vec4(1.0) - col2)) * (vec4(1.0) - col1);
+ outcol.a = col1.a;
}
void mix_overlay(float fac, vec4 col1, vec4 col2, out vec4 outcol)
{
- fac = clamp(fac, 0.0, 1.0);
- float facm = 1.0 - fac;
+ fac = clamp(fac, 0.0, 1.0);
+ float facm = 1.0 - fac;
- outcol = col1;
+ outcol = col1;
- if (outcol.r < 0.5)
- outcol.r *= facm + 2.0 * fac * col2.r;
- else
- outcol.r = 1.0 - (facm + 2.0 * fac * (1.0 - col2.r)) * (1.0 - outcol.r);
+ if (outcol.r < 0.5)
+ outcol.r *= facm + 2.0 * fac * col2.r;
+ else
+ outcol.r = 1.0 - (facm + 2.0 * fac * (1.0 - col2.r)) * (1.0 - outcol.r);
- if (outcol.g < 0.5)
- outcol.g *= facm + 2.0 * fac * col2.g;
- else
- outcol.g = 1.0 - (facm + 2.0 * fac * (1.0 - col2.g)) * (1.0 - outcol.g);
+ if (outcol.g < 0.5)
+ outcol.g *= facm + 2.0 * fac * col2.g;
+ else
+ outcol.g = 1.0 - (facm + 2.0 * fac * (1.0 - col2.g)) * (1.0 - outcol.g);
- if (outcol.b < 0.5)
- outcol.b *= facm + 2.0 * fac * col2.b;
- else
- outcol.b = 1.0 - (facm + 2.0 * fac * (1.0 - col2.b)) * (1.0 - outcol.b);
+ if (outcol.b < 0.5)
+ outcol.b *= facm + 2.0 * fac * col2.b;
+ else
+ outcol.b = 1.0 - (facm + 2.0 * fac * (1.0 - col2.b)) * (1.0 - outcol.b);
}
void mix_sub(float fac, vec4 col1, vec4 col2, out vec4 outcol)
{
- fac = clamp(fac, 0.0, 1.0);
- outcol = mix(col1, col1 - col2, fac);
- outcol.a = col1.a;
+ fac = clamp(fac, 0.0, 1.0);
+ outcol = mix(col1, col1 - col2, fac);
+ outcol.a = col1.a;
}
void mix_div(float fac, vec4 col1, vec4 col2, out vec4 outcol)
{
- fac = clamp(fac, 0.0, 1.0);
- float facm = 1.0 - fac;
+ fac = clamp(fac, 0.0, 1.0);
+ float facm = 1.0 - fac;
- outcol = col1;
+ outcol = col1;
- if (col2.r != 0.0) outcol.r = facm * outcol.r + fac * outcol.r / col2.r;
- if (col2.g != 0.0) outcol.g = facm * outcol.g + fac * outcol.g / col2.g;
- if (col2.b != 0.0) outcol.b = facm * outcol.b + fac * outcol.b / col2.b;
+ if (col2.r != 0.0)
+ outcol.r = facm * outcol.r + fac * outcol.r / col2.r;
+ if (col2.g != 0.0)
+ outcol.g = facm * outcol.g + fac * outcol.g / col2.g;
+ if (col2.b != 0.0)
+ outcol.b = facm * outcol.b + fac * outcol.b / col2.b;
}
void mix_diff(float fac, vec4 col1, vec4 col2, out vec4 outcol)
{
- fac = clamp(fac, 0.0, 1.0);
- outcol = mix(col1, abs(col1 - col2), fac);
- outcol.a = col1.a;
+ fac = clamp(fac, 0.0, 1.0);
+ outcol = mix(col1, abs(col1 - col2), fac);
+ outcol.a = col1.a;
}
void mix_dark(float fac, vec4 col1, vec4 col2, out vec4 outcol)
{
- fac = clamp(fac, 0.0, 1.0);
- outcol.rgb = min(col1.rgb, col2.rgb * fac);
- outcol.a = col1.a;
+ fac = clamp(fac, 0.0, 1.0);
+ outcol.rgb = min(col1.rgb, col2.rgb * fac);
+ outcol.a = col1.a;
}
void mix_light(float fac, vec4 col1, vec4 col2, out vec4 outcol)
{
- fac = clamp(fac, 0.0, 1.0);
- outcol.rgb = max(col1.rgb, col2.rgb * fac);
- outcol.a = col1.a;
+ fac = clamp(fac, 0.0, 1.0);
+ outcol.rgb = max(col1.rgb, col2.rgb * fac);
+ outcol.a = col1.a;
}
void mix_dodge(float fac, vec4 col1, vec4 col2, out vec4 outcol)
{
- fac = clamp(fac, 0.0, 1.0);
- outcol = col1;
-
- if (outcol.r != 0.0) {
- float tmp = 1.0 - fac * col2.r;
- if (tmp <= 0.0)
- outcol.r = 1.0;
- else if ((tmp = outcol.r / tmp) > 1.0)
- outcol.r = 1.0;
- else
- outcol.r = tmp;
- }
- if (outcol.g != 0.0) {
- float tmp = 1.0 - fac * col2.g;
- if (tmp <= 0.0)
- outcol.g = 1.0;
- else if ((tmp = outcol.g / tmp) > 1.0)
- outcol.g = 1.0;
- else
- outcol.g = tmp;
- }
- if (outcol.b != 0.0) {
- float tmp = 1.0 - fac * col2.b;
- if (tmp <= 0.0)
- outcol.b = 1.0;
- else if ((tmp = outcol.b / tmp) > 1.0)
- outcol.b = 1.0;
- else
- outcol.b = tmp;
- }
+ fac = clamp(fac, 0.0, 1.0);
+ outcol = col1;
+
+ if (outcol.r != 0.0) {
+ float tmp = 1.0 - fac * col2.r;
+ if (tmp <= 0.0)
+ outcol.r = 1.0;
+ else if ((tmp = outcol.r / tmp) > 1.0)
+ outcol.r = 1.0;
+ else
+ outcol.r = tmp;
+ }
+ if (outcol.g != 0.0) {
+ float tmp = 1.0 - fac * col2.g;
+ if (tmp <= 0.0)
+ outcol.g = 1.0;
+ else if ((tmp = outcol.g / tmp) > 1.0)
+ outcol.g = 1.0;
+ else
+ outcol.g = tmp;
+ }
+ if (outcol.b != 0.0) {
+ float tmp = 1.0 - fac * col2.b;
+ if (tmp <= 0.0)
+ outcol.b = 1.0;
+ else if ((tmp = outcol.b / tmp) > 1.0)
+ outcol.b = 1.0;
+ else
+ outcol.b = tmp;
+ }
}
void mix_burn(float fac, vec4 col1, vec4 col2, out vec4 outcol)
{
- fac = clamp(fac, 0.0, 1.0);
- float tmp, facm = 1.0 - fac;
-
- outcol = col1;
-
- tmp = facm + fac * col2.r;
- if (tmp <= 0.0)
- outcol.r = 0.0;
- else if ((tmp = (1.0 - (1.0 - outcol.r) / tmp)) < 0.0)
- outcol.r = 0.0;
- else if (tmp > 1.0)
- outcol.r = 1.0;
- else
- outcol.r = tmp;
-
- tmp = facm + fac * col2.g;
- if (tmp <= 0.0)
- outcol.g = 0.0;
- else if ((tmp = (1.0 - (1.0 - outcol.g) / tmp)) < 0.0)
- outcol.g = 0.0;
- else if (tmp > 1.0)
- outcol.g = 1.0;
- else
- outcol.g = tmp;
-
- tmp = facm + fac * col2.b;
- if (tmp <= 0.0)
- outcol.b = 0.0;
- else if ((tmp = (1.0 - (1.0 - outcol.b) / tmp)) < 0.0)
- outcol.b = 0.0;
- else if (tmp > 1.0)
- outcol.b = 1.0;
- else
- outcol.b = tmp;
+ fac = clamp(fac, 0.0, 1.0);
+ float tmp, facm = 1.0 - fac;
+
+ outcol = col1;
+
+ tmp = facm + fac * col2.r;
+ if (tmp <= 0.0)
+ outcol.r = 0.0;
+ else if ((tmp = (1.0 - (1.0 - outcol.r) / tmp)) < 0.0)
+ outcol.r = 0.0;
+ else if (tmp > 1.0)
+ outcol.r = 1.0;
+ else
+ outcol.r = tmp;
+
+ tmp = facm + fac * col2.g;
+ if (tmp <= 0.0)
+ outcol.g = 0.0;
+ else if ((tmp = (1.0 - (1.0 - outcol.g) / tmp)) < 0.0)
+ outcol.g = 0.0;
+ else if (tmp > 1.0)
+ outcol.g = 1.0;
+ else
+ outcol.g = tmp;
+
+ tmp = facm + fac * col2.b;
+ if (tmp <= 0.0)
+ outcol.b = 0.0;
+ else if ((tmp = (1.0 - (1.0 - outcol.b) / tmp)) < 0.0)
+ outcol.b = 0.0;
+ else if (tmp > 1.0)
+ outcol.b = 1.0;
+ else
+ outcol.b = tmp;
}
void mix_hue(float fac, vec4 col1, vec4 col2, out vec4 outcol)
{
- fac = clamp(fac, 0.0, 1.0);
- float facm = 1.0 - fac;
+ fac = clamp(fac, 0.0, 1.0);
+ float facm = 1.0 - fac;
- outcol = col1;
+ outcol = col1;
- vec4 hsv, hsv2, tmp;
- rgb_to_hsv(col2, hsv2);
+ vec4 hsv, hsv2, tmp;
+ rgb_to_hsv(col2, hsv2);
- if (hsv2.y != 0.0) {
- rgb_to_hsv(outcol, hsv);
- hsv.x = hsv2.x;
- hsv_to_rgb(hsv, tmp);
+ if (hsv2.y != 0.0) {
+ rgb_to_hsv(outcol, hsv);
+ hsv.x = hsv2.x;
+ hsv_to_rgb(hsv, tmp);
- outcol = mix(outcol, tmp, fac);
- outcol.a = col1.a;
- }
+ outcol = mix(outcol, tmp, fac);
+ outcol.a = col1.a;
+ }
}
void mix_sat(float fac, vec4 col1, vec4 col2, out vec4 outcol)
{
- fac = clamp(fac, 0.0, 1.0);
- float facm = 1.0 - fac;
+ fac = clamp(fac, 0.0, 1.0);
+ float facm = 1.0 - fac;
- outcol = col1;
+ outcol = col1;
- vec4 hsv, hsv2;
- rgb_to_hsv(outcol, hsv);
+ vec4 hsv, hsv2;
+ rgb_to_hsv(outcol, hsv);
- if (hsv.y != 0.0) {
- rgb_to_hsv(col2, hsv2);
+ if (hsv.y != 0.0) {
+ rgb_to_hsv(col2, hsv2);
- hsv.y = facm * hsv.y + fac * hsv2.y;
- hsv_to_rgb(hsv, outcol);
- }
+ hsv.y = facm * hsv.y + fac * hsv2.y;
+ hsv_to_rgb(hsv, outcol);
+ }
}
void mix_val(float fac, vec4 col1, vec4 col2, out vec4 outcol)
{
- fac = clamp(fac, 0.0, 1.0);
- float facm = 1.0 - fac;
+ fac = clamp(fac, 0.0, 1.0);
+ float facm = 1.0 - fac;
- vec4 hsv, hsv2;
- rgb_to_hsv(col1, hsv);
- rgb_to_hsv(col2, hsv2);
+ vec4 hsv, hsv2;
+ rgb_to_hsv(col1, hsv);
+ rgb_to_hsv(col2, hsv2);
- hsv.z = facm * hsv.z + fac * hsv2.z;
- hsv_to_rgb(hsv, outcol);
+ hsv.z = facm * hsv.z + fac * hsv2.z;
+ hsv_to_rgb(hsv, outcol);
}
void mix_color(float fac, vec4 col1, vec4 col2, out vec4 outcol)
{
- fac = clamp(fac, 0.0, 1.0);
- float facm = 1.0 - fac;
+ fac = clamp(fac, 0.0, 1.0);
+ float facm = 1.0 - fac;
- outcol = col1;
+ outcol = col1;
- vec4 hsv, hsv2, tmp;
- rgb_to_hsv(col2, hsv2);
+ vec4 hsv, hsv2, tmp;
+ rgb_to_hsv(col2, hsv2);
- if (hsv2.y != 0.0) {
- rgb_to_hsv(outcol, hsv);
- hsv.x = hsv2.x;
- hsv.y = hsv2.y;
- hsv_to_rgb(hsv, tmp);
+ if (hsv2.y != 0.0) {
+ rgb_to_hsv(outcol, hsv);
+ hsv.x = hsv2.x;
+ hsv.y = hsv2.y;
+ hsv_to_rgb(hsv, tmp);
- outcol = mix(outcol, tmp, fac);
- outcol.a = col1.a;
- }
+ outcol = mix(outcol, tmp, fac);
+ outcol.a = col1.a;
+ }
}
void mix_soft(float fac, vec4 col1, vec4 col2, out vec4 outcol)
{
- fac = clamp(fac, 0.0, 1.0);
- float facm = 1.0 - fac;
+ fac = clamp(fac, 0.0, 1.0);
+ float facm = 1.0 - fac;
- vec4 one = vec4(1.0);
- vec4 scr = one - (one - col2) * (one - col1);
- outcol = facm * col1 + fac * ((one - col1) * col2 * col1 + col1 * scr);
+ vec4 one = vec4(1.0);
+ vec4 scr = one - (one - col2) * (one - col1);
+ outcol = facm * col1 + fac * ((one - col1) * col2 * col1 + col1 * scr);
}
void mix_linear(float fac, vec4 col1, vec4 col2, out vec4 outcol)
{
- fac = clamp(fac, 0.0, 1.0);
+ fac = clamp(fac, 0.0, 1.0);
- outcol = col1 + fac * (2.0 * (col2 - vec4(0.5)));
+ outcol = col1 + fac * (2.0 * (col2 - vec4(0.5)));
}
-void valtorgb_opti_constant(float fac, float edge, vec4 color1, vec4 color2, out vec4 outcol, out float outalpha)
+void valtorgb_opti_constant(
+ float fac, float edge, vec4 color1, vec4 color2, out vec4 outcol, out float outalpha)
{
- outcol = (fac > edge) ? color2 : color1;
- outalpha = outcol.a;
+ outcol = (fac > edge) ? color2 : color1;
+ outalpha = outcol.a;
}
-void valtorgb_opti_linear(float fac, vec2 mulbias, vec4 color1, vec4 color2, out vec4 outcol, out float outalpha)
+void valtorgb_opti_linear(
+ float fac, vec2 mulbias, vec4 color1, vec4 color2, out vec4 outcol, out float outalpha)
{
- fac = clamp(fac * mulbias.x + mulbias.y, 0.0, 1.0);
- outcol = mix(color1, color2, fac);
- outalpha = outcol.a;
+ fac = clamp(fac * mulbias.x + mulbias.y, 0.0, 1.0);
+ outcol = mix(color1, color2, fac);
+ outalpha = outcol.a;
}
void valtorgb(float fac, sampler1DArray colormap, float layer, out vec4 outcol, out float outalpha)
{
- outcol = texture(colormap, vec2(fac, layer));
- outalpha = outcol.a;
+ outcol = texture(colormap, vec2(fac, layer));
+ outalpha = outcol.a;
}
-void valtorgb_nearest(float fac, sampler1DArray colormap, float layer, out vec4 outcol, out float outalpha)
+void valtorgb_nearest(
+ float fac, sampler1DArray colormap, float layer, out vec4 outcol, out float outalpha)
{
- fac = clamp(fac, 0.0, 1.0);
- outcol = texelFetch(colormap, ivec2(fac * (textureSize(colormap, 0).x - 1), layer), 0);
- outalpha = outcol.a;
+ fac = clamp(fac, 0.0, 1.0);
+ outcol = texelFetch(colormap, ivec2(fac * (textureSize(colormap, 0).x - 1), layer), 0);
+ outalpha = outcol.a;
}
void rgbtobw(vec4 color, out float outval)
{
- vec3 factors = vec3(0.2126, 0.7152, 0.0722);
- outval = dot(color.rgb, factors);
+ vec3 factors = vec3(0.2126, 0.7152, 0.0722);
+ outval = dot(color.rgb, factors);
}
void invert(float fac, vec4 col, out vec4 outcol)
{
- outcol.xyz = mix(col.xyz, vec3(1.0) - col.xyz, fac);
- outcol.w = col.w;
+ outcol.xyz = mix(col.xyz, vec3(1.0) - col.xyz, fac);
+ outcol.w = col.w;
}
void clamp_vec3(vec3 vec, vec3 min, vec3 max, out vec3 out_vec)
{
- out_vec = clamp(vec, min, max);
+ out_vec = clamp(vec, min, max);
}
void clamp_val(float value, float min, float max, out float out_value)
{
- out_value = clamp(value, min, max);
+ out_value = clamp(value, min, max);
}
void hue_sat(float hue, float sat, float value, float fac, vec4 col, out vec4 outcol)
{
- vec4 hsv;
+ vec4 hsv;
- rgb_to_hsv(col, hsv);
+ rgb_to_hsv(col, hsv);
- hsv[0] = fract(hsv[0] + hue + 0.5);
- hsv[1] = clamp(hsv[1] * sat, 0.0, 1.0);
- hsv[2] = hsv[2] * value;
+ hsv[0] = fract(hsv[0] + hue + 0.5);
+ hsv[1] = clamp(hsv[1] * sat, 0.0, 1.0);
+ hsv[2] = hsv[2] * value;
- hsv_to_rgb(hsv, outcol);
+ hsv_to_rgb(hsv, outcol);
- outcol = mix(col, outcol, fac);
+ outcol = mix(col, outcol, fac);
}
void separate_rgb(vec4 col, out float r, out float g, out float b)
{
- r = col.r;
- g = col.g;
- b = col.b;
+ r = col.r;
+ g = col.g;
+ b = col.b;
}
void combine_rgb(float r, float g, float b, out vec4 col)
{
- col = vec4(r, g, b, 1.0);
+ col = vec4(r, g, b, 1.0);
}
void separate_xyz(vec3 vec, out float x, out float y, out float z)
{
- x = vec.r;
- y = vec.g;
- z = vec.b;
+ x = vec.r;
+ y = vec.g;
+ z = vec.b;
}
void combine_xyz(float x, float y, float z, out vec3 vec)
{
- vec = vec3(x, y, z);
+ vec = vec3(x, y, z);
}
void separate_hsv(vec4 col, out float h, out float s, out float v)
{
- vec4 hsv;
+ vec4 hsv;
- rgb_to_hsv(col, hsv);
- h = hsv[0];
- s = hsv[1];
- v = hsv[2];
+ rgb_to_hsv(col, hsv);
+ h = hsv[0];
+ s = hsv[1];
+ v = hsv[2];
}
void combine_hsv(float h, float s, float v, out vec4 col)
{
- hsv_to_rgb(vec4(h, s, v, 1.0), col);
+ hsv_to_rgb(vec4(h, s, v, 1.0), col);
}
void output_node(vec4 rgb, float alpha, out vec4 outrgb)
{
- outrgb = vec4(rgb.rgb, alpha);
+ outrgb = vec4(rgb.rgb, alpha);
}
/*********** TEXTURES ***************/
void texco_norm(vec3 normal, out vec3 outnormal)
{
- /* corresponds to shi->orn, which is negated so cancels
- out blender normal negation */
- outnormal = normalize(normal);
+ /* corresponds to shi->orn, which is negated so cancels
+ out blender normal negation */
+ outnormal = normalize(normal);
}
vec3 mtex_2d_mapping(vec3 vec)
{
- return vec3(vec.xy * 0.5 + vec2(0.5), vec.z);
+ return vec3(vec.xy * 0.5 + vec2(0.5), vec.z);
}
/** helper method to extract the upper left 3x3 matrix from a 4x4 matrix */
mat3 to_mat3(mat4 m4)
{
- mat3 m3;
- m3[0] = m4[0].xyz;
- m3[1] = m4[1].xyz;
- m3[2] = m4[2].xyz;
- return m3;
+ mat3 m3;
+ m3[0] = m4[0].xyz;
+ m3[1] = m4[1].xyz;
+ m3[2] = m4[2].xyz;
+ return m3;
}
/*********** NEW SHADER UTILITIES **************/
float fresnel_dielectric_0(float eta)
{
- /* compute fresnel reflactance at normal incidence => cosi = 1.0 */
- float A = (eta - 1.0) / (eta + 1.0);
+ /* compute fresnel reflactance at normal incidence => cosi = 1.0 */
+ float A = (eta - 1.0) / (eta + 1.0);
- return A * A;
+ return A * A;
}
float fresnel_dielectric_cos(float cosi, float eta)
{
- /* compute fresnel reflectance without explicitly computing
- * the refracted direction */
- float c = abs(cosi);
- float g = eta * eta - 1.0 + c * c;
- float result;
+ /* compute fresnel reflectance without explicitly computing
+ * the refracted direction */
+ float c = abs(cosi);
+ float g = eta * eta - 1.0 + c * c;
+ float result;
- if (g > 0.0) {
- g = sqrt(g);
- float A = (g - c) / (g + c);
- float B = (c * (g + c) - 1.0) / (c * (g - c) + 1.0);
- result = 0.5 * A * A * (1.0 + B * B);
- }
- else {
- result = 1.0; /* TIR (no refracted component) */
- }
+ if (g > 0.0) {
+ g = sqrt(g);
+ float A = (g - c) / (g + c);
+ float B = (c * (g + c) - 1.0) / (c * (g - c) + 1.0);
+ result = 0.5 * A * A * (1.0 + B * B);
+ }
+ else {
+ result = 1.0; /* TIR (no refracted component) */
+ }
- return result;
+ return result;
}
float fresnel_dielectric(vec3 Incoming, vec3 Normal, float eta)
{
- /* compute fresnel reflectance without explicitly computing
- * the refracted direction */
- return fresnel_dielectric_cos(dot(Incoming, Normal), eta);
+ /* compute fresnel reflectance without explicitly computing
+ * the refracted direction */
+ return fresnel_dielectric_cos(dot(Incoming, Normal), eta);
}
float hypot(float x, float y)
{
- return sqrt(x * x + y * y);
+ return sqrt(x * x + y * y);
}
void generated_from_orco(vec3 orco, out vec3 generated)
{
#ifdef VOLUMETRICS
-#ifdef MESH_SHADER
- generated = volumeObjectLocalCoord;
-#else
- generated = worldPosition;
-#endif
+# ifdef MESH_SHADER
+ generated = volumeObjectLocalCoord;
+# else
+ generated = worldPosition;
+# endif
#else
- generated = orco;
+ generated = orco;
#endif
}
int floor_to_int(float x)
{
- return int(floor(x));
+ return int(floor(x));
}
int quick_floor(float x)
{
- return int(x) - ((x < 0) ? 1 : 0);
+ return int(x) - ((x < 0) ? 1 : 0);
}
float integer_noise(int n)
{
- int nn;
- n = (n + 1013) & 0x7fffffff;
- n = (n >> 13) ^ n;
- nn = (n * (n * n * 60493 + 19990303) + 1376312589) & 0x7fffffff;
- return 0.5 * (float(nn) / 1073741824.0);
+ int nn;
+ n = (n + 1013) & 0x7fffffff;
+ n = (n >> 13) ^ n;
+ nn = (n * (n * n * 60493 + 19990303) + 1376312589) & 0x7fffffff;
+ return 0.5 * (float(nn) / 1073741824.0);
}
uint hash(uint kx, uint ky, uint kz)
{
#define rot(x, k) (((x) << (k)) | ((x) >> (32 - (k))))
#define final(a, b, c) \
-{ \
- c ^= b; c -= rot(b, 14); \
- a ^= c; a -= rot(c, 11); \
- b ^= a; b -= rot(a, 25); \
- c ^= b; c -= rot(b, 16); \
- a ^= c; a -= rot(c, 4); \
- b ^= a; b -= rot(a, 14); \
- c ^= b; c -= rot(b, 24); \
-}
- // now hash the data!
- uint a, b, c, len = 3u;
- a = b = c = 0xdeadbeefu + (len << 2u) + 13u;
-
- c += kz;
- b += ky;
- a += kx;
- final (a, b, c);
-
- return c;
+ { \
+ c ^= b; \
+ c -= rot(b, 14); \
+ a ^= c; \
+ a -= rot(c, 11); \
+ b ^= a; \
+ b -= rot(a, 25); \
+ c ^= b; \
+ c -= rot(b, 16); \
+ a ^= c; \
+ a -= rot(c, 4); \
+ b ^= a; \
+ b -= rot(a, 14); \
+ c ^= b; \
+ c -= rot(b, 24); \
+ }
+ // now hash the data!
+ uint a, b, c, len = 3u;
+ a = b = c = 0xdeadbeefu + (len << 2u) + 13u;
+
+ c += kz;
+ b += ky;
+ a += kx;
+ final(a, b, c);
+
+ return c;
#undef rot
#undef final
}
uint hash(int kx, int ky, int kz)
{
- return hash(uint(kx), uint(ky), uint(kz));
+ return hash(uint(kx), uint(ky), uint(kz));
}
float bits_to_01(uint bits)
{
- return (float(bits) / 4294967295.0);
+ return (float(bits) / 4294967295.0);
}
float cellnoise(vec3 p)
{
- int ix = quick_floor(p.x);
- int iy = quick_floor(p.y);
- int iz = quick_floor(p.z);
+ int ix = quick_floor(p.x);
+ int iy = quick_floor(p.y);
+ int iz = quick_floor(p.z);
- return bits_to_01(hash(uint(ix), uint(iy), uint(iz)));
+ return bits_to_01(hash(uint(ix), uint(iy), uint(iz)));
}
vec3 cellnoise_color(vec3 p)
{
- float r = cellnoise(p.xyz);
- float g = cellnoise(p.yxz);
- float b = cellnoise(p.yzx);
+ float r = cellnoise(p.xyz);
+ float g = cellnoise(p.yxz);
+ float b = cellnoise(p.yzx);
- return vec3(r, g, b);
+ return vec3(r, g, b);
}
float floorfrac(float x, out int i)
{
- i = floor_to_int(x);
- return x - i;
+ i = floor_to_int(x);
+ return x - i;
}
/* bsdfs */
vec3 tint_from_color(vec3 color)
{
- float lum = dot(color, vec3(0.3, 0.6, 0.1)); /* luminance approx. */
- return (lum > 0) ? color / lum : vec3(1.0); /* normalize lum. to isolate hue+sat */
+ float lum = dot(color, vec3(0.3, 0.6, 0.1)); /* luminance approx. */
+ return (lum > 0) ? color / lum : vec3(1.0); /* normalize lum. to isolate hue+sat */
}
-void convert_metallic_to_specular_tinted(
- vec3 basecol, vec3 basecol_tint, float metallic, float specular_fac, float specular_tint,
- out vec3 diffuse, out vec3 f0)
+void convert_metallic_to_specular_tinted(vec3 basecol,
+ vec3 basecol_tint,
+ float metallic,
+ float specular_fac,
+ float specular_tint,
+ out vec3 diffuse,
+ out vec3 f0)
{
- vec3 tmp_col = mix(vec3(1.0), basecol_tint, specular_tint);
- f0 = mix((0.08 * specular_fac) * tmp_col, basecol, metallic);
- diffuse = basecol * (1.0 - metallic);
+ vec3 tmp_col = mix(vec3(1.0), basecol_tint, specular_tint);
+ f0 = mix((0.08 * specular_fac) * tmp_col, basecol, metallic);
+ diffuse = basecol * (1.0 - metallic);
}
vec3 principled_sheen(float NV, vec3 basecol_tint, float sheen_tint)
{
- float f = 1.0 - NV;
- /* Temporary fix for T59784. Normal map seems to contain NaNs for tangent space normal maps, therefore we need to clamp value. */
- f = clamp(f, 0.0, 1.0);
- /* Empirical approximation (manual curve fitting). Can be refined. */
- float sheen = f*f*f*0.077 + f*0.01 + 0.00026;
- return sheen * mix(vec3(1.0), basecol_tint, sheen_tint);
+ float f = 1.0 - NV;
+ /* Temporary fix for T59784. Normal map seems to contain NaNs for tangent space normal maps, therefore we need to clamp value. */
+ f = clamp(f, 0.0, 1.0);
+ /* Empirical approximation (manual curve fitting). Can be refined. */
+ float sheen = f * f * f * 0.077 + f * 0.01 + 0.00026;
+ return sheen * mix(vec3(1.0), basecol_tint, sheen_tint);
}
#ifndef VOLUMETRICS
void node_bsdf_diffuse(vec4 color, float roughness, vec3 N, out Closure result)
{
- N = normalize(N);
- vec3 vN = mat3(ViewMatrix) * N;
- result = CLOSURE_DEFAULT;
- result.ssr_normal = normal_encode(vN, viewCameraVec);
- eevee_closure_diffuse(N, color.rgb, 1.0, result.radiance);
- result.radiance *= color.rgb;
+ N = normalize(N);
+ vec3 vN = mat3(ViewMatrix) * N;
+ result = CLOSURE_DEFAULT;
+ result.ssr_normal = normal_encode(vN, viewCameraVec);
+ eevee_closure_diffuse(N, color.rgb, 1.0, result.radiance);
+ result.radiance *= color.rgb;
}
void node_bsdf_glossy(vec4 color, float roughness, vec3 N, float ssr_id, out Closure result)
{
- N = normalize(N);
- vec3 out_spec, ssr_spec;
- eevee_closure_glossy(N, vec3(1.0), int(ssr_id), roughness, 1.0, out_spec, ssr_spec);
- vec3 vN = mat3(ViewMatrix) * N;
- result = CLOSURE_DEFAULT;
- result.radiance = out_spec * color.rgb;
- result.ssr_data = vec4(ssr_spec * color.rgb, roughness);
- result.ssr_normal = normal_encode(vN, viewCameraVec);
- result.ssr_id = int(ssr_id);
-}
-
-void node_bsdf_anisotropic(
- vec4 color, float roughness, float anisotropy, float rotation, vec3 N, vec3 T,
- out Closure result)
-{
- node_bsdf_glossy(color, roughness, N, -1, result);
-}
-
-void node_bsdf_glass(vec4 color, float roughness, float ior, vec3 N, float ssr_id, out Closure result)
-{
- N = normalize(N);
- vec3 out_spec, out_refr, ssr_spec;
- vec3 refr_color = (refractionDepth > 0.0) ? color.rgb * color.rgb : color.rgb; /* Simulate 2 transmission event */
- eevee_closure_glass(N, vec3(1.0), int(ssr_id), roughness, 1.0, ior, out_spec, out_refr, ssr_spec);
- out_refr *= refr_color;
- out_spec *= color.rgb;
- float fresnel = F_eta(ior, dot(N, cameraVec));
- vec3 vN = mat3(ViewMatrix) * N;
- result = CLOSURE_DEFAULT;
- result.radiance = mix(out_refr, out_spec, fresnel);
- result.ssr_data = vec4(ssr_spec * color.rgb * fresnel, roughness);
- result.ssr_normal = normal_encode(vN, viewCameraVec);
- result.ssr_id = int(ssr_id);
+ N = normalize(N);
+ vec3 out_spec, ssr_spec;
+ eevee_closure_glossy(N, vec3(1.0), int(ssr_id), roughness, 1.0, out_spec, ssr_spec);
+ vec3 vN = mat3(ViewMatrix) * N;
+ result = CLOSURE_DEFAULT;
+ result.radiance = out_spec * color.rgb;
+ result.ssr_data = vec4(ssr_spec * color.rgb, roughness);
+ result.ssr_normal = normal_encode(vN, viewCameraVec);
+ result.ssr_id = int(ssr_id);
+}
+
+void node_bsdf_anisotropic(vec4 color,
+ float roughness,
+ float anisotropy,
+ float rotation,
+ vec3 N,
+ vec3 T,
+ out Closure result)
+{
+ node_bsdf_glossy(color, roughness, N, -1, result);
+}
+
+void node_bsdf_glass(
+ vec4 color, float roughness, float ior, vec3 N, float ssr_id, out Closure result)
+{
+ N = normalize(N);
+ vec3 out_spec, out_refr, ssr_spec;
+ vec3 refr_color = (refractionDepth > 0.0) ? color.rgb * color.rgb :
+ color.rgb; /* Simulate 2 transmission event */
+ eevee_closure_glass(
+ N, vec3(1.0), int(ssr_id), roughness, 1.0, ior, out_spec, out_refr, ssr_spec);
+ out_refr *= refr_color;
+ out_spec *= color.rgb;
+ float fresnel = F_eta(ior, dot(N, cameraVec));
+ vec3 vN = mat3(ViewMatrix) * N;
+ result = CLOSURE_DEFAULT;
+ result.radiance = mix(out_refr, out_spec, fresnel);
+ result.ssr_data = vec4(ssr_spec * color.rgb * fresnel, roughness);
+ result.ssr_normal = normal_encode(vN, viewCameraVec);
+ result.ssr_id = int(ssr_id);
}
void node_bsdf_toon(vec4 color, float size, float tsmooth, vec3 N, out Closure result)
{
- node_bsdf_diffuse(color, 0.0, N, result);
-}
-
-void node_bsdf_principled(
- vec4 base_color, float subsurface, vec3 subsurface_radius, vec4 subsurface_color, float metallic, float specular,
- float specular_tint, float roughness, float anisotropic, float anisotropic_rotation, float sheen, float sheen_tint, float clearcoat,
- float clearcoat_roughness, float ior, float transmission, float transmission_roughness, vec3 N, vec3 CN, vec3 T, vec3 I, float ssr_id,
- float sss_id, vec3 sss_scale, out Closure result)
-{
- N = normalize(N);
- ior = max(ior, 1e-5);
- metallic = saturate(metallic);
- transmission = saturate(transmission);
- float dielectric = 1.0 - metallic;
- transmission *= dielectric;
- sheen *= dielectric;
- subsurface_color *= dielectric;
-
- vec3 diffuse, f0, out_diff, out_spec, out_trans, out_refr, ssr_spec;
- vec3 ctint = tint_from_color(base_color.rgb);
- convert_metallic_to_specular_tinted(base_color.rgb, ctint, metallic, specular, specular_tint, diffuse, f0);
-
- float NV = dot(N, cameraVec);
- vec3 out_sheen = sheen * principled_sheen(NV, ctint, sheen_tint);
-
- /* Far from being accurate, but 2 glossy evaluation is too expensive.
- * Most noticeable difference is at grazing angles since the bsdf lut
- * f0 color interpolation is done on top of this interpolation. */
- vec3 f0_glass = mix(vec3(1.0), base_color.rgb, specular_tint);
- float fresnel = F_eta(ior, NV);
- vec3 spec_col = F_color_blend(ior, fresnel, f0_glass) * fresnel;
- f0 = mix(f0, spec_col, transmission);
-
- vec3 mixed_ss_base_color = mix(diffuse, subsurface_color.rgb, subsurface);
-
- float sss_scalef = dot(sss_scale, vec3(1.0 / 3.0)) * subsurface;
- eevee_closure_principled(N, mixed_ss_base_color, f0, int(ssr_id), roughness,
- CN, clearcoat * 0.25, clearcoat_roughness, 1.0, sss_scalef, ior,
- out_diff, out_trans, out_spec, out_refr, ssr_spec);
-
- vec3 refr_color = base_color.rgb;
- refr_color *= (refractionDepth > 0.0) ? refr_color : vec3(1.0); /* Simulate 2 transmission event */
- out_refr *= refr_color * (1.0 - fresnel) * transmission;
-
- vec3 vN = mat3(ViewMatrix) * N;
- result = CLOSURE_DEFAULT;
- result.radiance = out_spec + out_refr;
- result.radiance += out_diff * out_sheen; /* Coarse approx. */
-#ifndef USE_SSS
- result.radiance += (out_diff + out_trans) * mixed_ss_base_color * (1.0 - transmission);
-#endif
- result.ssr_data = vec4(ssr_spec, roughness);
- result.ssr_normal = normal_encode(vN, viewCameraVec);
- result.ssr_id = int(ssr_id);
-#ifdef USE_SSS
- result.sss_data.a = sss_scalef;
- result.sss_data.rgb = out_diff + out_trans;
-# ifdef USE_SSS_ALBEDO
- result.sss_albedo.rgb = mixed_ss_base_color;
-# else
- result.sss_data.rgb *= mixed_ss_base_color;
+ node_bsdf_diffuse(color, 0.0, N, result);
+}
+
+void node_bsdf_principled(vec4 base_color,
+ float subsurface,
+ vec3 subsurface_radius,
+ vec4 subsurface_color,
+ float metallic,
+ float specular,
+ float specular_tint,
+ float roughness,
+ float anisotropic,
+ float anisotropic_rotation,
+ float sheen,
+ float sheen_tint,
+ float clearcoat,
+ float clearcoat_roughness,
+ float ior,
+ float transmission,
+ float transmission_roughness,
+ vec3 N,
+ vec3 CN,
+ vec3 T,
+ vec3 I,
+ float ssr_id,
+ float sss_id,
+ vec3 sss_scale,
+ out Closure result)
+{
+ N = normalize(N);
+ ior = max(ior, 1e-5);
+ metallic = saturate(metallic);
+ transmission = saturate(transmission);
+ float dielectric = 1.0 - metallic;
+ transmission *= dielectric;
+ sheen *= dielectric;
+ subsurface_color *= dielectric;
+
+ vec3 diffuse, f0, out_diff, out_spec, out_trans, out_refr, ssr_spec;
+ vec3 ctint = tint_from_color(base_color.rgb);
+ convert_metallic_to_specular_tinted(
+ base_color.rgb, ctint, metallic, specular, specular_tint, diffuse, f0);
+
+ float NV = dot(N, cameraVec);
+ vec3 out_sheen = sheen * principled_sheen(NV, ctint, sheen_tint);
+
+ /* Far from being accurate, but 2 glossy evaluation is too expensive.
+ * Most noticeable difference is at grazing angles since the bsdf lut
+ * f0 color interpolation is done on top of this interpolation. */
+ vec3 f0_glass = mix(vec3(1.0), base_color.rgb, specular_tint);
+ float fresnel = F_eta(ior, NV);
+ vec3 spec_col = F_color_blend(ior, fresnel, f0_glass) * fresnel;
+ f0 = mix(f0, spec_col, transmission);
+
+ vec3 mixed_ss_base_color = mix(diffuse, subsurface_color.rgb, subsurface);
+
+ float sss_scalef = dot(sss_scale, vec3(1.0 / 3.0)) * subsurface;
+ eevee_closure_principled(N,
+ mixed_ss_base_color,
+ f0,
+ int(ssr_id),
+ roughness,
+ CN,
+ clearcoat * 0.25,
+ clearcoat_roughness,
+ 1.0,
+ sss_scalef,
+ ior,
+ out_diff,
+ out_trans,
+ out_spec,
+ out_refr,
+ ssr_spec);
+
+ vec3 refr_color = base_color.rgb;
+ refr_color *= (refractionDepth > 0.0) ? refr_color :
+ vec3(1.0); /* Simulate 2 transmission event */
+ out_refr *= refr_color * (1.0 - fresnel) * transmission;
+
+ vec3 vN = mat3(ViewMatrix) * N;
+ result = CLOSURE_DEFAULT;
+ result.radiance = out_spec + out_refr;
+ result.radiance += out_diff * out_sheen; /* Coarse approx. */
+# ifndef USE_SSS
+ result.radiance += (out_diff + out_trans) * mixed_ss_base_color * (1.0 - transmission);
+# endif
+ result.ssr_data = vec4(ssr_spec, roughness);
+ result.ssr_normal = normal_encode(vN, viewCameraVec);
+ result.ssr_id = int(ssr_id);
+# ifdef USE_SSS
+ result.sss_data.a = sss_scalef;
+ result.sss_data.rgb = out_diff + out_trans;
+# ifdef USE_SSS_ALBEDO
+ result.sss_albedo.rgb = mixed_ss_base_color;
+# else
+ result.sss_data.rgb *= mixed_ss_base_color;
+# endif
+ result.sss_data.rgb *= (1.0 - transmission);
# endif
- result.sss_data.rgb *= (1.0 - transmission);
-#endif
-}
-
-void node_bsdf_principled_dielectric(
- vec4 base_color, float subsurface, vec3 subsurface_radius, vec4 subsurface_color, float metallic, float specular,
- float specular_tint, float roughness, float anisotropic, float anisotropic_rotation, float sheen, float sheen_tint, float clearcoat,
- float clearcoat_roughness, float ior, float transmission, float transmission_roughness, vec3 N, vec3 CN, vec3 T, vec3 I, float ssr_id,
- float sss_id, vec3 sss_scale, out Closure result)
-{
- N = normalize(N);
- metallic = saturate(metallic);
- float dielectric = 1.0 - metallic;
-
- vec3 diffuse, f0, out_diff, out_spec, ssr_spec;
- vec3 ctint = tint_from_color(base_color.rgb);
- convert_metallic_to_specular_tinted(base_color.rgb, ctint, metallic, specular, specular_tint, diffuse, f0);
-
- float NV = dot(N, cameraVec);
- vec3 out_sheen = sheen * principled_sheen(NV, ctint, sheen_tint);
-
- eevee_closure_default(N, diffuse, f0, int(ssr_id), roughness, 1.0, out_diff, out_spec, ssr_spec);
-
- vec3 vN = mat3(ViewMatrix) * N;
- result = CLOSURE_DEFAULT;
- result.radiance = out_spec + out_diff * (diffuse + out_sheen);
- result.ssr_data = vec4(ssr_spec, roughness);
- result.ssr_normal = normal_encode(vN, viewCameraVec);
- result.ssr_id = int(ssr_id);
-}
-
-void node_bsdf_principled_metallic(
- vec4 base_color, float subsurface, vec3 subsurface_radius, vec4 subsurface_color, float metallic, float specular,
- float specular_tint, float roughness, float anisotropic, float anisotropic_rotation, float sheen, float sheen_tint, float clearcoat,
- float clearcoat_roughness, float ior, float transmission, float transmission_roughness, vec3 N, vec3 CN, vec3 T, vec3 I, float ssr_id,
- float sss_id, vec3 sss_scale, out Closure result)
-{
- N = normalize(N);
- vec3 out_spec, ssr_spec;
-
- eevee_closure_glossy(N, base_color.rgb, int(ssr_id), roughness, 1.0, out_spec, ssr_spec);
-
- vec3 vN = mat3(ViewMatrix) * N;
- result = CLOSURE_DEFAULT;
- result.radiance = out_spec;
- result.ssr_data = vec4(ssr_spec, roughness);
- result.ssr_normal = normal_encode(vN, viewCameraVec);
- result.ssr_id = int(ssr_id);
-}
-
-void node_bsdf_principled_clearcoat(
- vec4 base_color, float subsurface, vec3 subsurface_radius, vec4 subsurface_color, float metallic, float specular,
- float specular_tint, float roughness, float anisotropic, float anisotropic_rotation, float sheen, float sheen_tint, float clearcoat,
- float clearcoat_roughness, float ior, float transmission, float transmission_roughness, vec3 N, vec3 CN, vec3 T, vec3 I, float ssr_id,
- float sss_id, vec3 sss_scale, out Closure result)
-{
- vec3 out_spec, ssr_spec;
- N = normalize(N);
-
- eevee_closure_clearcoat(N, base_color.rgb, int(ssr_id), roughness, CN, clearcoat * 0.25, clearcoat_roughness,
- 1.0, out_spec, ssr_spec);
-
- vec3 vN = mat3(ViewMatrix) * N;
- result = CLOSURE_DEFAULT;
- result.radiance = out_spec;
- result.ssr_data = vec4(ssr_spec, roughness);
- result.ssr_normal = normal_encode(vN, viewCameraVec);
- result.ssr_id = int(ssr_id);
}
-void node_bsdf_principled_subsurface(
- vec4 base_color, float subsurface, vec3 subsurface_radius, vec4 subsurface_color, float metallic, float specular,
- float specular_tint, float roughness, float anisotropic, float anisotropic_rotation, float sheen, float sheen_tint, float clearcoat,
- float clearcoat_roughness, float ior, float transmission, float transmission_roughness, vec3 N, vec3 CN, vec3 T, vec3 I, float ssr_id,
- float sss_id, vec3 sss_scale, out Closure result)
-{
- metallic = saturate(metallic);
- N = normalize(N);
-
- vec3 diffuse, f0, out_diff, out_spec, out_trans, ssr_spec;
- vec3 ctint = tint_from_color(base_color.rgb);
- convert_metallic_to_specular_tinted(base_color.rgb, ctint, metallic, specular, specular_tint, diffuse, f0);
-
- subsurface_color = subsurface_color * (1.0 - metallic);
- vec3 mixed_ss_base_color = mix(diffuse, subsurface_color.rgb, subsurface);
- float sss_scalef = dot(sss_scale, vec3(1.0 / 3.0)) * subsurface;
-
- float NV = dot(N, cameraVec);
- vec3 out_sheen = sheen * principled_sheen(NV, ctint, sheen_tint);
-
- eevee_closure_skin(N, mixed_ss_base_color, f0, int(ssr_id), roughness, 1.0, sss_scalef,
- out_diff, out_trans, out_spec, ssr_spec);
-
- vec3 vN = mat3(ViewMatrix) * N;
- result = CLOSURE_DEFAULT;
- result.radiance = out_spec;
- result.ssr_data = vec4(ssr_spec, roughness);
- result.ssr_normal = normal_encode(vN, viewCameraVec);
- result.ssr_id = int(ssr_id);
-#ifdef USE_SSS
- result.sss_data.a = sss_scalef;
- result.sss_data.rgb = out_diff + out_trans;
-# ifdef USE_SSS_ALBEDO
- result.sss_albedo.rgb = mixed_ss_base_color;
+void node_bsdf_principled_dielectric(vec4 base_color,
+ float subsurface,
+ vec3 subsurface_radius,
+ vec4 subsurface_color,
+ float metallic,
+ float specular,
+ float specular_tint,
+ float roughness,
+ float anisotropic,
+ float anisotropic_rotation,
+ float sheen,
+ float sheen_tint,
+ float clearcoat,
+ float clearcoat_roughness,
+ float ior,
+ float transmission,
+ float transmission_roughness,
+ vec3 N,
+ vec3 CN,
+ vec3 T,
+ vec3 I,
+ float ssr_id,
+ float sss_id,
+ vec3 sss_scale,
+ out Closure result)
+{
+ N = normalize(N);
+ metallic = saturate(metallic);
+ float dielectric = 1.0 - metallic;
+
+ vec3 diffuse, f0, out_diff, out_spec, ssr_spec;
+ vec3 ctint = tint_from_color(base_color.rgb);
+ convert_metallic_to_specular_tinted(
+ base_color.rgb, ctint, metallic, specular, specular_tint, diffuse, f0);
+
+ float NV = dot(N, cameraVec);
+ vec3 out_sheen = sheen * principled_sheen(NV, ctint, sheen_tint);
+
+ eevee_closure_default(N, diffuse, f0, int(ssr_id), roughness, 1.0, out_diff, out_spec, ssr_spec);
+
+ vec3 vN = mat3(ViewMatrix) * N;
+ result = CLOSURE_DEFAULT;
+ result.radiance = out_spec + out_diff * (diffuse + out_sheen);
+ result.ssr_data = vec4(ssr_spec, roughness);
+ result.ssr_normal = normal_encode(vN, viewCameraVec);
+ result.ssr_id = int(ssr_id);
+}
+
+void node_bsdf_principled_metallic(vec4 base_color,
+ float subsurface,
+ vec3 subsurface_radius,
+ vec4 subsurface_color,
+ float metallic,
+ float specular,
+ float specular_tint,
+ float roughness,
+ float anisotropic,
+ float anisotropic_rotation,
+ float sheen,
+ float sheen_tint,
+ float clearcoat,
+ float clearcoat_roughness,
+ float ior,
+ float transmission,
+ float transmission_roughness,
+ vec3 N,
+ vec3 CN,
+ vec3 T,
+ vec3 I,
+ float ssr_id,
+ float sss_id,
+ vec3 sss_scale,
+ out Closure result)
+{
+ N = normalize(N);
+ vec3 out_spec, ssr_spec;
+
+ eevee_closure_glossy(N, base_color.rgb, int(ssr_id), roughness, 1.0, out_spec, ssr_spec);
+
+ vec3 vN = mat3(ViewMatrix) * N;
+ result = CLOSURE_DEFAULT;
+ result.radiance = out_spec;
+ result.ssr_data = vec4(ssr_spec, roughness);
+ result.ssr_normal = normal_encode(vN, viewCameraVec);
+ result.ssr_id = int(ssr_id);
+}
+
+void node_bsdf_principled_clearcoat(vec4 base_color,
+ float subsurface,
+ vec3 subsurface_radius,
+ vec4 subsurface_color,
+ float metallic,
+ float specular,
+ float specular_tint,
+ float roughness,
+ float anisotropic,
+ float anisotropic_rotation,
+ float sheen,
+ float sheen_tint,
+ float clearcoat,
+ float clearcoat_roughness,
+ float ior,
+ float transmission,
+ float transmission_roughness,
+ vec3 N,
+ vec3 CN,
+ vec3 T,
+ vec3 I,
+ float ssr_id,
+ float sss_id,
+ vec3 sss_scale,
+ out Closure result)
+{
+ vec3 out_spec, ssr_spec;
+ N = normalize(N);
+
+ eevee_closure_clearcoat(N,
+ base_color.rgb,
+ int(ssr_id),
+ roughness,
+ CN,
+ clearcoat * 0.25,
+ clearcoat_roughness,
+ 1.0,
+ out_spec,
+ ssr_spec);
+
+ vec3 vN = mat3(ViewMatrix) * N;
+ result = CLOSURE_DEFAULT;
+ result.radiance = out_spec;
+ result.ssr_data = vec4(ssr_spec, roughness);
+ result.ssr_normal = normal_encode(vN, viewCameraVec);
+ result.ssr_id = int(ssr_id);
+}
+
+void node_bsdf_principled_subsurface(vec4 base_color,
+ float subsurface,
+ vec3 subsurface_radius,
+ vec4 subsurface_color,
+ float metallic,
+ float specular,
+ float specular_tint,
+ float roughness,
+ float anisotropic,
+ float anisotropic_rotation,
+ float sheen,
+ float sheen_tint,
+ float clearcoat,
+ float clearcoat_roughness,
+ float ior,
+ float transmission,
+ float transmission_roughness,
+ vec3 N,
+ vec3 CN,
+ vec3 T,
+ vec3 I,
+ float ssr_id,
+ float sss_id,
+ vec3 sss_scale,
+ out Closure result)
+{
+ metallic = saturate(metallic);
+ N = normalize(N);
+
+ vec3 diffuse, f0, out_diff, out_spec, out_trans, ssr_spec;
+ vec3 ctint = tint_from_color(base_color.rgb);
+ convert_metallic_to_specular_tinted(
+ base_color.rgb, ctint, metallic, specular, specular_tint, diffuse, f0);
+
+ subsurface_color = subsurface_color * (1.0 - metallic);
+ vec3 mixed_ss_base_color = mix(diffuse, subsurface_color.rgb, subsurface);
+ float sss_scalef = dot(sss_scale, vec3(1.0 / 3.0)) * subsurface;
+
+ float NV = dot(N, cameraVec);
+ vec3 out_sheen = sheen * principled_sheen(NV, ctint, sheen_tint);
+
+ eevee_closure_skin(N,
+ mixed_ss_base_color,
+ f0,
+ int(ssr_id),
+ roughness,
+ 1.0,
+ sss_scalef,
+ out_diff,
+ out_trans,
+ out_spec,
+ ssr_spec);
+
+ vec3 vN = mat3(ViewMatrix) * N;
+ result = CLOSURE_DEFAULT;
+ result.radiance = out_spec;
+ result.ssr_data = vec4(ssr_spec, roughness);
+ result.ssr_normal = normal_encode(vN, viewCameraVec);
+ result.ssr_id = int(ssr_id);
+# ifdef USE_SSS
+ result.sss_data.a = sss_scalef;
+ result.sss_data.rgb = out_diff + out_trans;
+# ifdef USE_SSS_ALBEDO
+ result.sss_albedo.rgb = mixed_ss_base_color;
+# else
+ result.sss_data.rgb *= mixed_ss_base_color;
+# endif
# else
- result.sss_data.rgb *= mixed_ss_base_color;
+ result.radiance += (out_diff + out_trans) * mixed_ss_base_color;
# endif
-#else
- result.radiance += (out_diff + out_trans) * mixed_ss_base_color;
-#endif
- result.radiance += out_diff * out_sheen;
-}
-
-void node_bsdf_principled_glass(
- vec4 base_color, float subsurface, vec3 subsurface_radius, vec4 subsurface_color, float metallic, float specular,
- float specular_tint, float roughness, float anisotropic, float anisotropic_rotation, float sheen, float sheen_tint, float clearcoat,
- float clearcoat_roughness, float ior, float transmission, float transmission_roughness, vec3 N, vec3 CN, vec3 T, vec3 I, float ssr_id,
- float sss_id, vec3 sss_scale, out Closure result)
-{
- ior = max(ior, 1e-5);
- N = normalize(N);
-
- vec3 f0, out_spec, out_refr, ssr_spec;
- f0 = mix(vec3(1.0), base_color.rgb, specular_tint);
-
- eevee_closure_glass(N, vec3(1.0), int(ssr_id), roughness, 1.0, ior, out_spec, out_refr, ssr_spec);
-
- vec3 refr_color = base_color.rgb;
- refr_color *= (refractionDepth > 0.0) ? refr_color : vec3(1.0); /* Simulate 2 transmission events */
- out_refr *= refr_color;
-
- float fresnel = F_eta(ior, dot(N, cameraVec));
- vec3 spec_col = F_color_blend(ior, fresnel, f0);
- out_spec *= spec_col;
- ssr_spec *= spec_col * fresnel;
-
- vec3 vN = mat3(ViewMatrix) * N;
- result = CLOSURE_DEFAULT;
- result.radiance = mix(out_refr, out_spec, fresnel);
- result.ssr_data = vec4(ssr_spec, roughness);
- result.ssr_normal = normal_encode(vN, viewCameraVec);
- result.ssr_id = int(ssr_id);
+ result.radiance += out_diff * out_sheen;
+}
+
+void node_bsdf_principled_glass(vec4 base_color,
+ float subsurface,
+ vec3 subsurface_radius,
+ vec4 subsurface_color,
+ float metallic,
+ float specular,
+ float specular_tint,
+ float roughness,
+ float anisotropic,
+ float anisotropic_rotation,
+ float sheen,
+ float sheen_tint,
+ float clearcoat,
+ float clearcoat_roughness,
+ float ior,
+ float transmission,
+ float transmission_roughness,
+ vec3 N,
+ vec3 CN,
+ vec3 T,
+ vec3 I,
+ float ssr_id,
+ float sss_id,
+ vec3 sss_scale,
+ out Closure result)
+{
+ ior = max(ior, 1e-5);
+ N = normalize(N);
+
+ vec3 f0, out_spec, out_refr, ssr_spec;
+ f0 = mix(vec3(1.0), base_color.rgb, specular_tint);
+
+ eevee_closure_glass(
+ N, vec3(1.0), int(ssr_id), roughness, 1.0, ior, out_spec, out_refr, ssr_spec);
+
+ vec3 refr_color = base_color.rgb;
+ refr_color *= (refractionDepth > 0.0) ? refr_color :
+ vec3(1.0); /* Simulate 2 transmission events */
+ out_refr *= refr_color;
+
+ float fresnel = F_eta(ior, dot(N, cameraVec));
+ vec3 spec_col = F_color_blend(ior, fresnel, f0);
+ out_spec *= spec_col;
+ ssr_spec *= spec_col * fresnel;
+
+ vec3 vN = mat3(ViewMatrix) * N;
+ result = CLOSURE_DEFAULT;
+ result.radiance = mix(out_refr, out_spec, fresnel);
+ result.ssr_data = vec4(ssr_spec, roughness);
+ result.ssr_normal = normal_encode(vN, viewCameraVec);
+ result.ssr_id = int(ssr_id);
}
void node_bsdf_translucent(vec4 color, vec3 N, out Closure result)
{
- node_bsdf_diffuse(color, 0.0, -N, result);
+ node_bsdf_diffuse(color, 0.0, -N, result);
}
void node_bsdf_transparent(vec4 color, out Closure result)
{
- /* this isn't right */
- result = CLOSURE_DEFAULT;
- result.radiance = vec3(0.0);
- result.opacity = clamp(1.0 - dot(color.rgb, vec3(0.3333334)), 0.0, 1.0);
- result.ssr_id = TRANSPARENT_CLOSURE_FLAG;
+ /* this isn't right */
+ result = CLOSURE_DEFAULT;
+ result.radiance = vec3(0.0);
+ result.opacity = clamp(1.0 - dot(color.rgb, vec3(0.3333334)), 0.0, 1.0);
+ result.ssr_id = TRANSPARENT_CLOSURE_FLAG;
}
void node_bsdf_velvet(vec4 color, float sigma, vec3 N, out Closure result)
{
- node_bsdf_diffuse(color, 0.0, N, result);
-}
-
-void node_subsurface_scattering(
- vec4 color, float scale, vec3 radius, float sharpen, float texture_blur, vec3 N, float sss_id,
- out Closure result)
-{
-#if defined(USE_SSS)
- N = normalize(N);
- vec3 out_diff, out_trans;
- vec3 vN = mat3(ViewMatrix) * N;
- result = CLOSURE_DEFAULT;
- result.ssr_data = vec4(0.0);
- result.ssr_normal = normal_encode(vN, viewCameraVec);
- result.ssr_id = -1;
- result.sss_data.a = scale;
- eevee_closure_subsurface(N, color.rgb, 1.0, scale, out_diff, out_trans);
- result.sss_data.rgb = out_diff + out_trans;
-# ifdef USE_SSS_ALBEDO
- /* Not perfect for texture_blur not exactly equal to 0.0 or 1.0. */
- result.sss_albedo.rgb = mix(color.rgb, vec3(1.0), texture_blur);
- result.sss_data.rgb *= mix(vec3(1.0), color.rgb, texture_blur);
+ node_bsdf_diffuse(color, 0.0, N, result);
+}
+
+void node_subsurface_scattering(vec4 color,
+ float scale,
+ vec3 radius,
+ float sharpen,
+ float texture_blur,
+ vec3 N,
+ float sss_id,
+ out Closure result)
+{
+# if defined(USE_SSS)
+ N = normalize(N);
+ vec3 out_diff, out_trans;
+ vec3 vN = mat3(ViewMatrix) * N;
+ result = CLOSURE_DEFAULT;
+ result.ssr_data = vec4(0.0);
+ result.ssr_normal = normal_encode(vN, viewCameraVec);
+ result.ssr_id = -1;
+ result.sss_data.a = scale;
+ eevee_closure_subsurface(N, color.rgb, 1.0, scale, out_diff, out_trans);
+ result.sss_data.rgb = out_diff + out_trans;
+# ifdef USE_SSS_ALBEDO
+ /* Not perfect for texture_blur not exactly equal to 0.0 or 1.0. */
+ result.sss_albedo.rgb = mix(color.rgb, vec3(1.0), texture_blur);
+ result.sss_data.rgb *= mix(vec3(1.0), color.rgb, texture_blur);
+# else
+ result.sss_data.rgb *= color.rgb;
+# endif
# else
- result.sss_data.rgb *= color.rgb;
+ node_bsdf_diffuse(color, 0.0, N, result);
# endif
-#else
- node_bsdf_diffuse(color, 0.0, N, result);
-#endif
}
void node_bsdf_refraction(vec4 color, float roughness, float ior, vec3 N, out Closure result)
{
- N = normalize(N);
- vec3 out_refr;
- color.rgb *= (refractionDepth > 0.0) ? color.rgb : vec3(1.0); /* Simulate 2 absorption event. */
- eevee_closure_refraction(N, roughness, ior, out_refr);
- vec3 vN = mat3(ViewMatrix) * N;
- result = CLOSURE_DEFAULT;
- result.ssr_normal = normal_encode(vN, viewCameraVec);
- result.radiance = out_refr * color.rgb;
- result.ssr_id = REFRACT_CLOSURE_FLAG;
+ N = normalize(N);
+ vec3 out_refr;
+ color.rgb *= (refractionDepth > 0.0) ? color.rgb : vec3(1.0); /* Simulate 2 absorption event. */
+ eevee_closure_refraction(N, roughness, ior, out_refr);
+ vec3 vN = mat3(ViewMatrix) * N;
+ result = CLOSURE_DEFAULT;
+ result.ssr_normal = normal_encode(vN, viewCameraVec);
+ result.radiance = out_refr * color.rgb;
+ result.ssr_id = REFRACT_CLOSURE_FLAG;
}
-void node_ambient_occlusion(vec4 color, float distance, vec3 normal, out vec4 result_color, out float result_ao)
+void node_ambient_occlusion(
+ vec4 color, float distance, vec3 normal, out vec4 result_color, out float result_ao)
{
- vec3 bent_normal;
- vec4 rand = texelFetch(utilTex, ivec3(ivec2(gl_FragCoord.xy) % LUT_SIZE, 2.0), 0);
- result_ao = occlusion_compute(normalize(normal), viewPosition, 1.0, rand, bent_normal);
- result_color = result_ao * color;
+ vec3 bent_normal;
+ vec4 rand = texelFetch(utilTex, ivec3(ivec2(gl_FragCoord.xy) % LUT_SIZE, 2.0), 0);
+ result_ao = occlusion_compute(normalize(normal), viewPosition, 1.0, rand, bent_normal);
+ result_color = result_ao * color;
}
#endif /* VOLUMETRICS */
@@ -1484,40 +1696,40 @@ void node_ambient_occlusion(vec4 color, float distance, vec3 normal, out vec4 re
void node_emission(vec4 color, float strength, vec3 vN, out Closure result)
{
#ifndef VOLUMETRICS
- color *= strength;
- result = CLOSURE_DEFAULT;
- result.radiance = color.rgb;
- result.opacity = color.a;
- result.ssr_normal = normal_encode(vN, viewCameraVec);
+ color *= strength;
+ result = CLOSURE_DEFAULT;
+ result.radiance = color.rgb;
+ result.opacity = color.a;
+ result.ssr_normal = normal_encode(vN, viewCameraVec);
#else
- result = Closure(vec3(0.0), vec3(0.0), color.rgb * strength, 0.0);
+ result = Closure(vec3(0.0), vec3(0.0), color.rgb * strength, 0.0);
#endif
}
void node_wireframe(float size, vec2 barycentric, vec3 barycentric_dist, out float fac)
{
- vec3 barys = barycentric.xyy;
- barys.z = 1.0 - barycentric.x - barycentric.y;
+ vec3 barys = barycentric.xyy;
+ barys.z = 1.0 - barycentric.x - barycentric.y;
- size *= 0.5;
- vec3 s = step(-size, -barys * barycentric_dist);
+ size *= 0.5;
+ vec3 s = step(-size, -barys * barycentric_dist);
- fac = max(s.x, max(s.y, s.z));
+ fac = max(s.x, max(s.y, s.z));
}
void node_wireframe_screenspace(float size, vec2 barycentric, out float fac)
{
- vec3 barys = barycentric.xyy;
- barys.z = 1.0 - barycentric.x - barycentric.y;
+ vec3 barys = barycentric.xyy;
+ barys.z = 1.0 - barycentric.x - barycentric.y;
- size *= (1.0 / 3.0);
- vec3 dx = dFdx(barys);
- vec3 dy = dFdy(barys);
- vec3 deltas = sqrt(dx * dx + dy * dy);
+ size *= (1.0 / 3.0);
+ vec3 dx = dFdx(barys);
+ vec3 dy = dFdy(barys);
+ vec3 deltas = sqrt(dx * dx + dy * dy);
- vec3 s = step(-deltas * size, -barys);
+ vec3 s = step(-deltas * size, -barys);
- fac = max(s.x, max(s.y, s.z));
+ fac = max(s.x, max(s.y, s.z));
}
/* background */
@@ -1525,16 +1737,16 @@ void node_wireframe_screenspace(float size, vec2 barycentric, out float fac)
void node_tex_environment_texco(vec3 viewvec, out vec3 worldvec)
{
#ifdef MESH_SHADER
- worldvec = worldPosition;
+ worldvec = worldPosition;
#else
- vec4 v = (ProjectionMatrix[3][3] == 0.0) ? vec4(viewvec, 1.0) : vec4(0.0, 0.0, 1.0, 1.0);
- vec4 co_homogenous = (ProjectionMatrixInverse * v);
+ vec4 v = (ProjectionMatrix[3][3] == 0.0) ? vec4(viewvec, 1.0) : vec4(0.0, 0.0, 1.0, 1.0);
+ vec4 co_homogenous = (ProjectionMatrixInverse * v);
- vec4 co = vec4(co_homogenous.xyz / co_homogenous.w, 0.0);
+ vec4 co = vec4(co_homogenous.xyz / co_homogenous.w, 0.0);
# if defined(WORLD_BACKGROUND) || defined(PROBE_CAPTURE)
- worldvec = (ViewMatrixInverse * co).xyz;
+ worldvec = (ViewMatrixInverse * co).xyz;
# else
- worldvec = (ModelViewMatrixInverse * co).xyz;
+ worldvec = (ModelViewMatrixInverse * co).xyz;
# endif
#endif
}
@@ -1542,12 +1754,12 @@ void node_tex_environment_texco(vec3 viewvec, out vec3 worldvec)
void node_background(vec4 color, float strength, out Closure result)
{
#ifndef VOLUMETRICS
- color *= strength;
- result = CLOSURE_DEFAULT;
- result.radiance = color.rgb;
- result.opacity = color.a;
+ color *= strength;
+ result = CLOSURE_DEFAULT;
+ result.radiance = color.rgb;
+ result.opacity = color.a;
#else
- result = CLOSURE_DEFAULT;
+ result = CLOSURE_DEFAULT;
#endif
}
@@ -1556,100 +1768,100 @@ void node_background(vec4 color, float strength, out Closure result)
void node_volume_scatter(vec4 color, float density, float anisotropy, out Closure result)
{
#ifdef VOLUMETRICS
- result = Closure(vec3(0.0), color.rgb * density, vec3(0.0), anisotropy);
+ result = Closure(vec3(0.0), color.rgb * density, vec3(0.0), anisotropy);
#else
- result = CLOSURE_DEFAULT;
+ result = CLOSURE_DEFAULT;
#endif
}
void node_volume_absorption(vec4 color, float density, out Closure result)
{
#ifdef VOLUMETRICS
- result = Closure((1.0 - color.rgb) * density, vec3(0.0), vec3(0.0), 0.0);
+ result = Closure((1.0 - color.rgb) * density, vec3(0.0), vec3(0.0), 0.0);
#else
- result = CLOSURE_DEFAULT;
+ result = CLOSURE_DEFAULT;
#endif
}
void node_blackbody(float temperature, sampler1DArray spectrummap, float layer, out vec4 color)
{
- if (temperature >= 12000.0) {
- color = vec4(0.826270103, 0.994478524, 1.56626022, 1.0);
- }
- else if (temperature < 965.0) {
- color = vec4(4.70366907, 0.0, 0.0, 1.0);
- }
- else {
- float t = (temperature - 965.0) / (12000.0 - 965.0);
- color = vec4(texture(spectrummap, vec2(t, layer)).rgb, 1.0);
- }
-}
-
-void node_volume_principled(
- vec4 color,
- float density,
- float anisotropy,
- vec4 absorption_color,
- float emission_strength,
- vec4 emission_color,
- float blackbody_intensity,
- vec4 blackbody_tint,
- float temperature,
- float density_attribute,
- vec4 color_attribute,
- float temperature_attribute,
- sampler1DArray spectrummap,
- float layer,
- out Closure result)
+ if (temperature >= 12000.0) {
+ color = vec4(0.826270103, 0.994478524, 1.56626022, 1.0);
+ }
+ else if (temperature < 965.0) {
+ color = vec4(4.70366907, 0.0, 0.0, 1.0);
+ }
+ else {
+ float t = (temperature - 965.0) / (12000.0 - 965.0);
+ color = vec4(texture(spectrummap, vec2(t, layer)).rgb, 1.0);
+ }
+}
+
+void node_volume_principled(vec4 color,
+ float density,
+ float anisotropy,
+ vec4 absorption_color,
+ float emission_strength,
+ vec4 emission_color,
+ float blackbody_intensity,
+ vec4 blackbody_tint,
+ float temperature,
+ float density_attribute,
+ vec4 color_attribute,
+ float temperature_attribute,
+ sampler1DArray spectrummap,
+ float layer,
+ out Closure result)
{
#ifdef VOLUMETRICS
- vec3 absorption_coeff = vec3(0.0);
- vec3 scatter_coeff = vec3(0.0);
- vec3 emission_coeff = vec3(0.0);
-
- /* Compute density. */
- density = max(density, 0.0);
-
- if (density > 1e-5) {
- density = max(density * density_attribute, 0.0);
- }
-
- if (density > 1e-5) {
- /* Compute scattering and absorption coefficients. */
- vec3 scatter_color = color.rgb * color_attribute.rgb;
-
- scatter_coeff = scatter_color * density;
- absorption_color.rgb = sqrt(max(absorption_color.rgb, 0.0));
- absorption_coeff = max(1.0 - scatter_color, 0.0) * max(1.0 - absorption_color.rgb, 0.0) * density;
- }
-
- /* Compute emission. */
- emission_strength = max(emission_strength, 0.0);
-
- if (emission_strength > 1e-5) {
- emission_coeff += emission_strength * emission_color.rgb;
- }
-
- if (blackbody_intensity > 1e-3) {
- /* Add temperature from attribute. */
- float T = max(temperature * max(temperature_attribute, 0.0), 0.0);
-
- /* Stefan-Boltzman law. */
- float T2 = T * T;
- float T4 = T2 * T2;
- float sigma = 5.670373e-8 * 1e-6 / M_PI;
- float intensity = sigma * mix(1.0, T4, blackbody_intensity);
-
- if (intensity > 1e-5) {
- vec4 bb;
- node_blackbody(T, spectrummap, layer, bb);
- emission_coeff += bb.rgb * blackbody_tint.rgb * intensity;
- }
- }
-
- result = Closure(absorption_coeff, scatter_coeff, emission_coeff, anisotropy);
+ vec3 absorption_coeff = vec3(0.0);
+ vec3 scatter_coeff = vec3(0.0);
+ vec3 emission_coeff = vec3(0.0);
+
+ /* Compute density. */
+ density = max(density, 0.0);
+
+ if (density > 1e-5) {
+ density = max(density * density_attribute, 0.0);
+ }
+
+ if (density > 1e-5) {
+ /* Compute scattering and absorption coefficients. */
+ vec3 scatter_color = color.rgb * color_attribute.rgb;
+
+ scatter_coeff = scatter_color * density;
+ absorption_color.rgb = sqrt(max(absorption_color.rgb, 0.0));
+ absorption_coeff = max(1.0 - scatter_color, 0.0) * max(1.0 - absorption_color.rgb, 0.0) *
+ density;
+ }
+
+ /* Compute emission. */
+ emission_strength = max(emission_strength, 0.0);
+
+ if (emission_strength > 1e-5) {
+ emission_coeff += emission_strength * emission_color.rgb;
+ }
+
+ if (blackbody_intensity > 1e-3) {
+ /* Add temperature from attribute. */
+ float T = max(temperature * max(temperature_attribute, 0.0), 0.0);
+
+ /* Stefan-Boltzman law. */
+ float T2 = T * T;
+ float T4 = T2 * T2;
+ float sigma = 5.670373e-8 * 1e-6 / M_PI;
+ float intensity = sigma * mix(1.0, T4, blackbody_intensity);
+
+ if (intensity > 1e-5) {
+ vec4 bb;
+ node_blackbody(T, spectrummap, layer, bb);
+ emission_coeff += bb.rgb * blackbody_tint.rgb * intensity;
+ }
+ }
+
+ result = Closure(absorption_coeff, scatter_coeff, emission_coeff, anisotropy);
#else
- result = CLOSURE_DEFAULT;
+ result = CLOSURE_DEFAULT;
#endif
}
@@ -1657,60 +1869,60 @@ void node_volume_principled(
void node_mix_shader(float fac, Closure shader1, Closure shader2, out Closure shader)
{
- shader = closure_mix(shader1, shader2, fac);
+ shader = closure_mix(shader1, shader2, fac);
}
void node_add_shader(Closure shader1, Closure shader2, out Closure shader)
{
- shader = closure_add(shader1, shader2);
+ shader = closure_add(shader1, shader2);
}
/* fresnel */
void node_fresnel(float ior, vec3 N, vec3 I, out float result)
{
- N = normalize(N);
- /* handle perspective/orthographic */
- vec3 I_view = (ProjectionMatrix[3][3] == 0.0) ? normalize(I) : vec3(0.0, 0.0, -1.0);
+ N = normalize(N);
+ /* handle perspective/orthographic */
+ vec3 I_view = (ProjectionMatrix[3][3] == 0.0) ? normalize(I) : vec3(0.0, 0.0, -1.0);
- float eta = max(ior, 0.00001);
- result = fresnel_dielectric(I_view, N, (gl_FrontFacing) ? eta : 1.0 / eta);
+ float eta = max(ior, 0.00001);
+ result = fresnel_dielectric(I_view, N, (gl_FrontFacing) ? eta : 1.0 / eta);
}
/* layer_weight */
void node_layer_weight(float blend, vec3 N, vec3 I, out float fresnel, out float facing)
{
- N = normalize(N);
+ N = normalize(N);
- /* fresnel */
- float eta = max(1.0 - blend, 0.00001);
- vec3 I_view = (ProjectionMatrix[3][3] == 0.0) ? normalize(I) : vec3(0.0, 0.0, -1.0);
+ /* fresnel */
+ float eta = max(1.0 - blend, 0.00001);
+ vec3 I_view = (ProjectionMatrix[3][3] == 0.0) ? normalize(I) : vec3(0.0, 0.0, -1.0);
- fresnel = fresnel_dielectric(I_view, N, (gl_FrontFacing) ? 1.0 / eta : eta);
+ fresnel = fresnel_dielectric(I_view, N, (gl_FrontFacing) ? 1.0 / eta : eta);
- /* facing */
- facing = abs(dot(I_view, N));
- if (blend != 0.5) {
- blend = clamp(blend, 0.0, 0.99999);
- blend = (blend < 0.5) ? 2.0 * blend : 0.5 / (1.0 - blend);
- facing = pow(facing, blend);
- }
- facing = 1.0 - facing;
+ /* facing */
+ facing = abs(dot(I_view, N));
+ if (blend != 0.5) {
+ blend = clamp(blend, 0.0, 0.99999);
+ blend = (blend < 0.5) ? 2.0 * blend : 0.5 / (1.0 - blend);
+ facing = pow(facing, blend);
+ }
+ facing = 1.0 - facing;
}
/* gamma */
void node_gamma(vec4 col, float gamma, out vec4 outcol)
{
- outcol = col;
+ outcol = col;
- if (col.r > 0.0)
- outcol.r = compatible_pow(col.r, gamma);
- if (col.g > 0.0)
- outcol.g = compatible_pow(col.g, gamma);
- if (col.b > 0.0)
- outcol.b = compatible_pow(col.b, gamma);
+ if (col.r > 0.0)
+ outcol.r = compatible_pow(col.r, gamma);
+ if (col.g > 0.0)
+ outcol.g = compatible_pow(col.g, gamma);
+ if (col.b > 0.0)
+ outcol.b = compatible_pow(col.b, gamma);
}
/* geometry */
@@ -1718,13 +1930,13 @@ void node_gamma(vec4 col, float gamma, out vec4 outcol)
void node_attribute_volume_density(sampler3D tex, out vec4 outcol, out vec3 outvec, out float outf)
{
#if defined(MESH_SHADER) && defined(VOLUMETRICS)
- vec3 cos = volumeObjectLocalCoord;
+ vec3 cos = volumeObjectLocalCoord;
#else
- vec3 cos = vec3(0.0);
+ vec3 cos = vec3(0.0);
#endif
- outvec = texture(tex, cos).aaa;
- outcol = vec4(outvec, 1.0);
- outf = dot(vec3(1.0 / 3.0), outvec);
+ outvec = texture(tex, cos).aaa;
+ outcol = vec4(outvec, 1.0);
+ outf = dot(vec3(1.0 / 3.0), outvec);
}
uniform vec3 volumeColor = vec3(1.0);
@@ -1732,353 +1944,401 @@ uniform vec3 volumeColor = vec3(1.0);
void node_attribute_volume_color(sampler3D tex, out vec4 outcol, out vec3 outvec, out float outf)
{
#if defined(MESH_SHADER) && defined(VOLUMETRICS)
- vec3 cos = volumeObjectLocalCoord;
+ vec3 cos = volumeObjectLocalCoord;
#else
- vec3 cos = vec3(0.0);
+ vec3 cos = vec3(0.0);
#endif
- vec4 value = texture(tex, cos).rgba;
- /* Density is premultiplied for interpolation, divide it out here. */
- if (value.a > 1e-8)
- value.rgb /= value.a;
+ vec4 value = texture(tex, cos).rgba;
+ /* Density is premultiplied for interpolation, divide it out here. */
+ if (value.a > 1e-8)
+ value.rgb /= value.a;
- outvec = value.rgb * volumeColor;
- outcol = vec4(outvec, 1.0);
- outf = dot(vec3(1.0 / 3.0), outvec);
+ outvec = value.rgb * volumeColor;
+ outcol = vec4(outvec, 1.0);
+ outf = dot(vec3(1.0 / 3.0), outvec);
}
void node_attribute_volume_flame(sampler3D tex, out vec4 outcol, out vec3 outvec, out float outf)
{
#if defined(MESH_SHADER) && defined(VOLUMETRICS)
- vec3 cos = volumeObjectLocalCoord;
+ vec3 cos = volumeObjectLocalCoord;
#else
- vec3 cos = vec3(0.0);
+ vec3 cos = vec3(0.0);
#endif
- outf = texture(tex, cos).r;
- outvec = vec3(outf, outf, outf);
- outcol = vec4(outf, outf, outf, 1.0);
+ outf = texture(tex, cos).r;
+ outvec = vec3(outf, outf, outf);
+ outcol = vec4(outf, outf, outf, 1.0);
}
-void node_attribute_volume_temperature(sampler3D tex, vec2 temperature, out vec4 outcol, out vec3 outvec, out float outf)
+void node_attribute_volume_temperature(
+ sampler3D tex, vec2 temperature, out vec4 outcol, out vec3 outvec, out float outf)
{
#if defined(MESH_SHADER) && defined(VOLUMETRICS)
- vec3 cos = volumeObjectLocalCoord;
+ vec3 cos = volumeObjectLocalCoord;
#else
- vec3 cos = vec3(0.0);
+ vec3 cos = vec3(0.0);
#endif
- float flame = texture(tex, cos).r;
+ float flame = texture(tex, cos).r;
- outf = (flame > 0.01) ? temperature.x + flame * (temperature.y - temperature.x): 0.0;
- outvec = vec3(outf, outf, outf);
- outcol = vec4(outf, outf, outf, 1.0);
+ outf = (flame > 0.01) ? temperature.x + flame * (temperature.y - temperature.x) : 0.0;
+ outvec = vec3(outf, outf, outf);
+ outcol = vec4(outf, outf, outf, 1.0);
}
void node_attribute(vec3 attr, out vec4 outcol, out vec3 outvec, out float outf)
{
- outcol = vec4(attr, 1.0);
- outvec = attr;
- outf = dot(vec3(1.0 / 3.0), attr);
+ outcol = vec4(attr, 1.0);
+ outvec = attr;
+ outf = dot(vec3(1.0 / 3.0), attr);
}
void node_uvmap(vec3 attr_uv, out vec3 outvec)
{
- outvec = attr_uv;
+ outvec = attr_uv;
}
void tangent_orco_x(vec3 orco_in, out vec3 orco_out)
{
- orco_out = orco_in.xzy * vec3(0.0, -0.5, 0.5) + vec3(0.0, 0.25, -0.25);
+ orco_out = orco_in.xzy * vec3(0.0, -0.5, 0.5) + vec3(0.0, 0.25, -0.25);
}
void tangent_orco_y(vec3 orco_in, out vec3 orco_out)
{
- orco_out = orco_in.zyx * vec3(-0.5, 0.0, 0.5) + vec3(0.25, 0.0, -0.25);
+ orco_out = orco_in.zyx * vec3(-0.5, 0.0, 0.5) + vec3(0.25, 0.0, -0.25);
}
void tangent_orco_z(vec3 orco_in, out vec3 orco_out)
{
- orco_out = orco_in.yxz * vec3(-0.5, 0.5, 0.0) + vec3(0.25, -0.25, 0.0);
+ orco_out = orco_in.yxz * vec3(-0.5, 0.5, 0.0) + vec3(0.25, -0.25, 0.0);
}
void node_tangentmap(vec4 attr_tangent, mat4 toworld, out vec3 tangent)
{
- tangent = normalize((toworld * vec4(attr_tangent.xyz, 0.0)).xyz);
+ tangent = normalize((toworld * vec4(attr_tangent.xyz, 0.0)).xyz);
}
void node_tangent(vec3 N, vec3 orco, mat4 objmat, mat4 toworld, out vec3 T)
{
#ifndef VOLUMETRICS
- N = normalize(gl_FrontFacing ? worldNormal : -worldNormal);
+ N = normalize(gl_FrontFacing ? worldNormal : -worldNormal);
#else
- N = (toworld * vec4(N, 0.0)).xyz;
+ N = (toworld * vec4(N, 0.0)).xyz;
#endif
- T = (objmat * vec4(orco, 0.0)).xyz;
- T = cross(N, normalize(cross(T, N)));
-}
-
-void node_geometry(
- vec3 I, vec3 N, vec3 orco, mat4 objmat, mat4 toworld, vec2 barycentric,
- out vec3 position, out vec3 normal, out vec3 tangent,
- out vec3 true_normal, out vec3 incoming, out vec3 parametric,
- out float backfacing, out float pointiness)
-{
- /* handle perspective/orthographic */
- vec3 I_view = (ProjectionMatrix[3][3] == 0.0) ? normalize(I) : vec3(0.0, 0.0, -1.0);
- incoming = -(toworld * vec4(I_view, 0.0)).xyz;
+ T = (objmat * vec4(orco, 0.0)).xyz;
+ T = cross(N, normalize(cross(T, N)));
+}
+
+void node_geometry(vec3 I,
+ vec3 N,
+ vec3 orco,
+ mat4 objmat,
+ mat4 toworld,
+ vec2 barycentric,
+ out vec3 position,
+ out vec3 normal,
+ out vec3 tangent,
+ out vec3 true_normal,
+ out vec3 incoming,
+ out vec3 parametric,
+ out float backfacing,
+ out float pointiness)
+{
+ /* handle perspective/orthographic */
+ vec3 I_view = (ProjectionMatrix[3][3] == 0.0) ? normalize(I) : vec3(0.0, 0.0, -1.0);
+ incoming = -(toworld * vec4(I_view, 0.0)).xyz;
#if defined(WORLD_BACKGROUND) || defined(PROBE_CAPTURE)
- position = -incoming;
- true_normal = normal = incoming;
- tangent = parametric = vec3(0.0);
- vec3(0.0);
- backfacing = 0.0;
- pointiness = 0.0;
+ position = -incoming;
+ true_normal = normal = incoming;
+ tangent = parametric = vec3(0.0);
+ vec3(0.0);
+ backfacing = 0.0;
+ pointiness = 0.0;
#else
- position = worldPosition;
+ position = worldPosition;
# ifndef VOLUMETRICS
- normal = normalize(gl_FrontFacing ? worldNormal : -worldNormal);
- vec3 B = dFdx(worldPosition);
- vec3 T = dFdy(worldPosition);
- true_normal = normalize(cross(B, T));
+ normal = normalize(gl_FrontFacing ? worldNormal : -worldNormal);
+ vec3 B = dFdx(worldPosition);
+ vec3 T = dFdy(worldPosition);
+ true_normal = normalize(cross(B, T));
# else
- normal = (toworld * vec4(N, 0.0)).xyz;
- true_normal = normal;
+ normal = (toworld * vec4(N, 0.0)).xyz;
+ true_normal = normal;
# endif
- tangent_orco_z(orco, orco);
- node_tangent(N, orco, objmat, toworld, tangent);
+ tangent_orco_z(orco, orco);
+ node_tangent(N, orco, objmat, toworld, tangent);
- parametric = vec3(barycentric, 0.0);
- backfacing = (gl_FrontFacing) ? 0.0 : 1.0;
- pointiness = 0.5;
+ parametric = vec3(barycentric, 0.0);
+ backfacing = (gl_FrontFacing) ? 0.0 : 1.0;
+ pointiness = 0.5;
#endif
}
void generated_texco(vec3 I, vec3 attr_orco, out vec3 generated)
{
- vec4 v = (ProjectionMatrix[3][3] == 0.0) ? vec4(I, 1.0) : vec4(0.0, 0.0, 1.0, 1.0);
- vec4 co_homogenous = (ProjectionMatrixInverse * v);
- vec4 co = vec4(co_homogenous.xyz / co_homogenous.w, 0.0);
- co.xyz = normalize(co.xyz);
+ vec4 v = (ProjectionMatrix[3][3] == 0.0) ? vec4(I, 1.0) : vec4(0.0, 0.0, 1.0, 1.0);
+ vec4 co_homogenous = (ProjectionMatrixInverse * v);
+ vec4 co = vec4(co_homogenous.xyz / co_homogenous.w, 0.0);
+ co.xyz = normalize(co.xyz);
#if defined(WORLD_BACKGROUND) || defined(PROBE_CAPTURE)
- generated = (ViewMatrixInverse * co).xyz;
+ generated = (ViewMatrixInverse * co).xyz;
#else
- generated_from_orco(attr_orco, generated);
+ generated_from_orco(attr_orco, generated);
#endif
}
-void node_tex_coord(
- vec3 I, vec3 N, mat4 viewinvmat, mat4 obinvmat, vec4 camerafac,
- vec3 attr_orco, vec3 attr_uv,
- out vec3 generated, out vec3 normal, out vec3 uv, out vec3 object,
- out vec3 camera, out vec3 window, out vec3 reflection)
-{
- generated = attr_orco;
- normal = normalize(NormalMatrixInverse * N);
- uv = attr_uv;
- object = (obinvmat * (viewinvmat * vec4(I, 1.0))).xyz;
- camera = vec3(I.xy, -I.z);
- vec4 projvec = ProjectionMatrix * vec4(I, 1.0);
- window = vec3(mtex_2d_mapping(projvec.xyz / projvec.w).xy * camerafac.xy + camerafac.zw, 0.0);
-
- vec3 shade_I = (ProjectionMatrix[3][3] == 0.0) ? normalize(I) : vec3(0.0, 0.0, -1.0);
- vec3 view_reflection = reflect(shade_I, normalize(N));
- reflection = (viewinvmat * vec4(view_reflection, 0.0)).xyz;
-}
-
-void node_tex_coord_background(
- vec3 I, vec3 N, mat4 viewinvmat, mat4 obinvmat, vec4 camerafac,
- vec3 attr_orco, vec3 attr_uv,
- out vec3 generated, out vec3 normal, out vec3 uv, out vec3 object,
- out vec3 camera, out vec3 window, out vec3 reflection)
-{
- vec4 v = (ProjectionMatrix[3][3] == 0.0) ? vec4(I, 1.0) : vec4(0.0, 0.0, 1.0, 1.0);
- vec4 co_homogenous = (ProjectionMatrixInverse * v);
-
- vec4 co = vec4(co_homogenous.xyz / co_homogenous.w, 0.0);
-
- co = normalize(co);
+void node_tex_coord(vec3 I,
+ vec3 N,
+ mat4 viewinvmat,
+ mat4 obinvmat,
+ vec4 camerafac,
+ vec3 attr_orco,
+ vec3 attr_uv,
+ out vec3 generated,
+ out vec3 normal,
+ out vec3 uv,
+ out vec3 object,
+ out vec3 camera,
+ out vec3 window,
+ out vec3 reflection)
+{
+ generated = attr_orco;
+ normal = normalize(NormalMatrixInverse * N);
+ uv = attr_uv;
+ object = (obinvmat * (viewinvmat * vec4(I, 1.0))).xyz;
+ camera = vec3(I.xy, -I.z);
+ vec4 projvec = ProjectionMatrix * vec4(I, 1.0);
+ window = vec3(mtex_2d_mapping(projvec.xyz / projvec.w).xy * camerafac.xy + camerafac.zw, 0.0);
+
+ vec3 shade_I = (ProjectionMatrix[3][3] == 0.0) ? normalize(I) : vec3(0.0, 0.0, -1.0);
+ vec3 view_reflection = reflect(shade_I, normalize(N));
+ reflection = (viewinvmat * vec4(view_reflection, 0.0)).xyz;
+}
+
+void node_tex_coord_background(vec3 I,
+ vec3 N,
+ mat4 viewinvmat,
+ mat4 obinvmat,
+ vec4 camerafac,
+ vec3 attr_orco,
+ vec3 attr_uv,
+ out vec3 generated,
+ out vec3 normal,
+ out vec3 uv,
+ out vec3 object,
+ out vec3 camera,
+ out vec3 window,
+ out vec3 reflection)
+{
+ vec4 v = (ProjectionMatrix[3][3] == 0.0) ? vec4(I, 1.0) : vec4(0.0, 0.0, 1.0, 1.0);
+ vec4 co_homogenous = (ProjectionMatrixInverse * v);
+
+ vec4 co = vec4(co_homogenous.xyz / co_homogenous.w, 0.0);
+
+ co = normalize(co);
#if defined(WORLD_BACKGROUND) || defined(PROBE_CAPTURE)
- vec3 coords = (ViewMatrixInverse * co).xyz;
+ vec3 coords = (ViewMatrixInverse * co).xyz;
#else
- vec3 coords = (ModelViewMatrixInverse * co).xyz;
+ vec3 coords = (ModelViewMatrixInverse * co).xyz;
#endif
- generated = coords;
- normal = -coords;
- uv = vec3(attr_uv.xy, 0.0);
- object = coords;
+ generated = coords;
+ normal = -coords;
+ uv = vec3(attr_uv.xy, 0.0);
+ object = coords;
- camera = vec3(co.xy, -co.z);
- window = vec3(mtex_2d_mapping(I).xy * camerafac.xy + camerafac.zw, 0.0);
+ camera = vec3(co.xy, -co.z);
+ window = vec3(mtex_2d_mapping(I).xy * camerafac.xy + camerafac.zw, 0.0);
- reflection = -coords;
+ reflection = -coords;
}
#if defined(WORLD_BACKGROUND) || (defined(PROBE_CAPTURE) && !defined(MESH_SHADER))
-#define node_tex_coord node_tex_coord_background
+# define node_tex_coord node_tex_coord_background
#endif
/* textures */
float calc_gradient(vec3 p, int gradient_type)
{
- float x, y, z;
- x = p.x;
- y = p.y;
- z = p.z;
- if (gradient_type == 0) { /* linear */
- return x;
- }
- else if (gradient_type == 1) { /* quadratic */
- float r = max(x, 0.0);
- return r * r;
- }
- else if (gradient_type == 2) { /* easing */
- float r = min(max(x, 0.0), 1.0);
- float t = r * r;
- return (3.0 * t - 2.0 * t * r);
- }
- else if (gradient_type == 3) { /* diagonal */
- return (x + y) * 0.5;
- }
- else if (gradient_type == 4) { /* radial */
- return atan(y, x) / (M_PI * 2) + 0.5;
- }
- else {
- /* Bias a little bit for the case where p is a unit length vector,
- * to get exactly zero instead of a small random value depending
- * on float precision. */
- float r = max(0.999999 - sqrt(x * x + y * y + z * z), 0.0);
- if (gradient_type == 5) { /* quadratic sphere */
- return r * r;
- }
- else if (gradient_type == 6) { /* sphere */
- return r;
- }
- }
- return 0.0;
+ float x, y, z;
+ x = p.x;
+ y = p.y;
+ z = p.z;
+ if (gradient_type == 0) { /* linear */
+ return x;
+ }
+ else if (gradient_type == 1) { /* quadratic */
+ float r = max(x, 0.0);
+ return r * r;
+ }
+ else if (gradient_type == 2) { /* easing */
+ float r = min(max(x, 0.0), 1.0);
+ float t = r * r;
+ return (3.0 * t - 2.0 * t * r);
+ }
+ else if (gradient_type == 3) { /* diagonal */
+ return (x + y) * 0.5;
+ }
+ else if (gradient_type == 4) { /* radial */
+ return atan(y, x) / (M_PI * 2) + 0.5;
+ }
+ else {
+ /* Bias a little bit for the case where p is a unit length vector,
+ * to get exactly zero instead of a small random value depending
+ * on float precision. */
+ float r = max(0.999999 - sqrt(x * x + y * y + z * z), 0.0);
+ if (gradient_type == 5) { /* quadratic sphere */
+ return r * r;
+ }
+ else if (gradient_type == 6) { /* sphere */
+ return r;
+ }
+ }
+ return 0.0;
}
void node_tex_gradient(vec3 co, float gradient_type, out vec4 color, out float fac)
{
- float f = calc_gradient(co, int(gradient_type));
- f = clamp(f, 0.0, 1.0);
+ float f = calc_gradient(co, int(gradient_type));
+ f = clamp(f, 0.0, 1.0);
- color = vec4(f, f, f, 1.0);
- fac = f;
+ color = vec4(f, f, f, 1.0);
+ fac = f;
}
-void node_tex_checker(vec3 co, vec4 color1, vec4 color2, float scale, out vec4 color, out float fac)
+void node_tex_checker(
+ vec3 co, vec4 color1, vec4 color2, float scale, out vec4 color, out float fac)
{
- vec3 p = co * scale;
+ vec3 p = co * scale;
- /* Prevent precision issues on unit coordinates. */
- p = (p + 0.000001) * 0.999999;
+ /* Prevent precision issues on unit coordinates. */
+ p = (p + 0.000001) * 0.999999;
- int xi = int(abs(floor(p.x)));
- int yi = int(abs(floor(p.y)));
- int zi = int(abs(floor(p.z)));
+ int xi = int(abs(floor(p.x)));
+ int yi = int(abs(floor(p.y)));
+ int zi = int(abs(floor(p.z)));
- bool check = ((mod(xi, 2) == mod(yi, 2)) == bool(mod(zi, 2)));
+ bool check = ((mod(xi, 2) == mod(yi, 2)) == bool(mod(zi, 2)));
- color = check ? color1 : color2;
- fac = check ? 1.0 : 0.0;
+ color = check ? color1 : color2;
+ fac = check ? 1.0 : 0.0;
}
-vec2 calc_brick_texture(vec3 p, float mortar_size, float mortar_smooth, float bias,
- float brick_width, float row_height,
- float offset_amount, int offset_frequency,
- float squash_amount, int squash_frequency)
+vec2 calc_brick_texture(vec3 p,
+ float mortar_size,
+ float mortar_smooth,
+ float bias,
+ float brick_width,
+ float row_height,
+ float offset_amount,
+ int offset_frequency,
+ float squash_amount,
+ int squash_frequency)
{
- int bricknum, rownum;
- float offset = 0.0;
- float x, y;
+ int bricknum, rownum;
+ float offset = 0.0;
+ float x, y;
- rownum = floor_to_int(p.y / row_height);
+ rownum = floor_to_int(p.y / row_height);
- if (offset_frequency != 0 && squash_frequency != 0) {
- brick_width *= (rownum % squash_frequency != 0) ? 1.0 : squash_amount; /* squash */
- offset = (rownum % offset_frequency != 0) ? 0.0 : (brick_width * offset_amount); /* offset */
- }
+ if (offset_frequency != 0 && squash_frequency != 0) {
+ brick_width *= (rownum % squash_frequency != 0) ? 1.0 : squash_amount; /* squash */
+ offset = (rownum % offset_frequency != 0) ? 0.0 : (brick_width * offset_amount); /* offset */
+ }
- bricknum = floor_to_int((p.x + offset) / brick_width);
+ bricknum = floor_to_int((p.x + offset) / brick_width);
- x = (p.x + offset) - brick_width * bricknum;
- y = p.y - row_height * rownum;
+ x = (p.x + offset) - brick_width * bricknum;
+ y = p.y - row_height * rownum;
- float tint = clamp((integer_noise((rownum << 16) + (bricknum & 0xFFFF)) + bias), 0.0, 1.0);
+ float tint = clamp((integer_noise((rownum << 16) + (bricknum & 0xFFFF)) + bias), 0.0, 1.0);
- float min_dist = min(min(x, y), min(brick_width - x, row_height - y));
- if (min_dist >= mortar_size) {
- return vec2(tint, 0.0);
- }
- else if (mortar_smooth == 0.0) {
- return vec2(tint, 1.0);
- }
- else {
- min_dist = 1.0 - min_dist/mortar_size;
- return vec2(tint, smoothstep(0.0, mortar_smooth, min_dist));
- }
+ float min_dist = min(min(x, y), min(brick_width - x, row_height - y));
+ if (min_dist >= mortar_size) {
+ return vec2(tint, 0.0);
+ }
+ else if (mortar_smooth == 0.0) {
+ return vec2(tint, 1.0);
+ }
+ else {
+ min_dist = 1.0 - min_dist / mortar_size;
+ return vec2(tint, smoothstep(0.0, mortar_smooth, min_dist));
+ }
}
void node_tex_brick(vec3 co,
- vec4 color1, vec4 color2,
- vec4 mortar, float scale,
- float mortar_size, float mortar_smooth, float bias,
- float brick_width, float row_height,
- float offset_amount, float offset_frequency,
- float squash_amount, float squash_frequency,
- out vec4 color, out float fac)
-{
- vec2 f2 = calc_brick_texture(co * scale,
- mortar_size, mortar_smooth, bias,
- brick_width, row_height,
- offset_amount, int(offset_frequency),
- squash_amount, int(squash_frequency));
- float tint = f2.x;
- float f = f2.y;
- if (f != 1.0) {
- float facm = 1.0 - tint;
- color1 = facm * color1 + tint * color2;
- }
- color = mix(color1, mortar, f);
- fac = f;
+ vec4 color1,
+ vec4 color2,
+ vec4 mortar,
+ float scale,
+ float mortar_size,
+ float mortar_smooth,
+ float bias,
+ float brick_width,
+ float row_height,
+ float offset_amount,
+ float offset_frequency,
+ float squash_amount,
+ float squash_frequency,
+ out vec4 color,
+ out float fac)
+{
+ vec2 f2 = calc_brick_texture(co * scale,
+ mortar_size,
+ mortar_smooth,
+ bias,
+ brick_width,
+ row_height,
+ offset_amount,
+ int(offset_frequency),
+ squash_amount,
+ int(squash_frequency));
+ float tint = f2.x;
+ float f = f2.y;
+ if (f != 1.0) {
+ float facm = 1.0 - tint;
+ color1 = facm * color1 + tint * color2;
+ }
+ color = mix(color1, mortar, f);
+ fac = f;
}
void node_tex_clouds(vec3 co, float size, out vec4 color, out float fac)
{
- color = vec4(1.0);
- fac = 1.0;
+ color = vec4(1.0);
+ fac = 1.0;
}
void node_tex_environment_equirectangular(vec3 co, float clamp_size, sampler2D ima, out vec3 uv)
{
- vec3 nco = normalize(co);
- uv.x = -atan(nco.y, nco.x) / (2.0 * M_PI) + 0.5;
- uv.y = atan(nco.z, hypot(nco.x, nco.y)) / M_PI + 0.5;
+ vec3 nco = normalize(co);
+ uv.x = -atan(nco.y, nco.x) / (2.0 * M_PI) + 0.5;
+ uv.y = atan(nco.z, hypot(nco.x, nco.y)) / M_PI + 0.5;
- /* Fix pole bleeding */
- float half_height = clamp_size / float(textureSize(ima, 0).y);
- uv.y = clamp(uv.y, half_height, 1.0 - half_height);
- uv.z = 0.0;
+ /* Fix pole bleeding */
+ float half_height = clamp_size / float(textureSize(ima, 0).y);
+ uv.y = clamp(uv.y, half_height, 1.0 - half_height);
+ uv.z = 0.0;
}
void node_tex_environment_mirror_ball(vec3 co, out vec3 uv)
{
- vec3 nco = normalize(co);
- nco.y -= 1.0;
+ vec3 nco = normalize(co);
+ nco.y -= 1.0;
- float div = 2.0 * sqrt(max(-0.5 * nco.y, 0.0));
- nco /= max(1e-8, div);
+ float div = 2.0 * sqrt(max(-0.5 * nco.y, 0.0));
+ nco /= max(1e-8, div);
- uv = 0.5 * nco.xzz + 0.5;
+ uv = 0.5 * nco.xzz + 0.5;
}
void node_tex_environment_empty(vec3 co, out vec4 color)
{
- color = vec4(1.0, 0.0, 1.0, 1.0);
+ color = vec4(1.0, 0.0, 1.0, 1.0);
}
/* 16bits floats limits. Higher/Lower values produce +/-inf. */
@@ -2086,200 +2346,185 @@ void node_tex_environment_empty(vec3 co, out vec4 color)
void node_tex_image_linear(vec3 co, sampler2D ima, out vec4 color, out float alpha)
{
- color = safe_color(texture(ima, co.xy));
- alpha = color.a;
+ color = safe_color(texture(ima, co.xy));
+ alpha = color.a;
}
void node_tex_image_linear_no_mip(vec3 co, sampler2D ima, out vec4 color, out float alpha)
{
- color = safe_color(textureLod(ima, co.xy, 0.0));
- alpha = color.a;
+ color = safe_color(textureLod(ima, co.xy, 0.0));
+ alpha = color.a;
}
void node_tex_image_nearest(vec3 co, sampler2D ima, out vec4 color, out float alpha)
{
- ivec2 pix = ivec2(fract(co.xy) * textureSize(ima, 0).xy);
- color = safe_color(texelFetch(ima, pix, 0));
- alpha = color.a;
+ ivec2 pix = ivec2(fract(co.xy) * textureSize(ima, 0).xy);
+ color = safe_color(texelFetch(ima, pix, 0));
+ alpha = color.a;
}
/* @arg f: signed distance to texel center. */
void cubic_bspline_coefs(vec2 f, out vec2 w0, out vec2 w1, out vec2 w2, out vec2 w3)
{
- vec2 f2 = f * f;
- vec2 f3 = f2 * f;
- /* Bspline coefs (optimized) */
- w3 = f3 / 6.0;
- w0 = -w3 + f2 * 0.5 - f * 0.5 + 1.0 / 6.0;
- w1 = f3 * 0.5 - f2 * 1.0 + 2.0 / 3.0;
- w2 = 1.0 - w0 - w1 - w3;
+ vec2 f2 = f * f;
+ vec2 f3 = f2 * f;
+ /* Bspline coefs (optimized) */
+ w3 = f3 / 6.0;
+ w0 = -w3 + f2 * 0.5 - f * 0.5 + 1.0 / 6.0;
+ w1 = f3 * 0.5 - f2 * 1.0 + 2.0 / 3.0;
+ w2 = 1.0 - w0 - w1 - w3;
}
-void node_tex_image_cubic_ex(vec3 co, sampler2D ima, float do_extend, out vec4 color, out float alpha)
+void node_tex_image_cubic_ex(
+ vec3 co, sampler2D ima, float do_extend, out vec4 color, out float alpha)
{
- vec2 tex_size = vec2(textureSize(ima, 0).xy);
+ vec2 tex_size = vec2(textureSize(ima, 0).xy);
- co.xy *= tex_size;
- /* texel center */
- vec2 tc = floor(co.xy - 0.5) + 0.5;
- vec2 w0, w1, w2, w3;
- cubic_bspline_coefs(co.xy - tc, w0, w1, w2, w3);
+ co.xy *= tex_size;
+ /* texel center */
+ vec2 tc = floor(co.xy - 0.5) + 0.5;
+ vec2 w0, w1, w2, w3;
+ cubic_bspline_coefs(co.xy - tc, w0, w1, w2, w3);
#if 1 /* Optimized version using 4 filtered tap. */
- vec2 s0 = w0 + w1;
- vec2 s1 = w2 + w3;
+ vec2 s0 = w0 + w1;
+ vec2 s1 = w2 + w3;
- vec2 f0 = w1 / (w0 + w1);
- vec2 f1 = w3 / (w2 + w3);
+ vec2 f0 = w1 / (w0 + w1);
+ vec2 f1 = w3 / (w2 + w3);
- vec4 final_co;
- final_co.xy = tc - 1.0 + f0;
- final_co.zw = tc + 1.0 + f1;
+ vec4 final_co;
+ final_co.xy = tc - 1.0 + f0;
+ final_co.zw = tc + 1.0 + f1;
- if (do_extend == 1.0) {
- final_co = clamp(final_co, vec4(0.5), tex_size.xyxy - 0.5);
- }
- final_co /= tex_size.xyxy;
+ if (do_extend == 1.0) {
+ final_co = clamp(final_co, vec4(0.5), tex_size.xyxy - 0.5);
+ }
+ final_co /= tex_size.xyxy;
- color = safe_color(textureLod(ima, final_co.xy, 0.0)) * s0.x * s0.y;
- color += safe_color(textureLod(ima, final_co.zy, 0.0)) * s1.x * s0.y;
- color += safe_color(textureLod(ima, final_co.xw, 0.0)) * s0.x * s1.y;
- color += safe_color(textureLod(ima, final_co.zw, 0.0)) * s1.x * s1.y;
+ color = safe_color(textureLod(ima, final_co.xy, 0.0)) * s0.x * s0.y;
+ color += safe_color(textureLod(ima, final_co.zy, 0.0)) * s1.x * s0.y;
+ color += safe_color(textureLod(ima, final_co.xw, 0.0)) * s0.x * s1.y;
+ color += safe_color(textureLod(ima, final_co.zw, 0.0)) * s1.x * s1.y;
#else /* Reference bruteforce 16 tap. */
- color = texelFetch(ima, ivec2(tc + vec2(-1.0, -1.0)), 0) * w0.x * w0.y;
- color += texelFetch(ima, ivec2(tc + vec2( 0.0, -1.0)), 0) * w1.x * w0.y;
- color += texelFetch(ima, ivec2(tc + vec2( 1.0, -1.0)), 0) * w2.x * w0.y;
- color += texelFetch(ima, ivec2(tc + vec2( 2.0, -1.0)), 0) * w3.x * w0.y;
-
- color += texelFetch(ima, ivec2(tc + vec2(-1.0, 0.0)), 0) * w0.x * w1.y;
- color += texelFetch(ima, ivec2(tc + vec2( 0.0, 0.0)), 0) * w1.x * w1.y;
- color += texelFetch(ima, ivec2(tc + vec2( 1.0, 0.0)), 0) * w2.x * w1.y;
- color += texelFetch(ima, ivec2(tc + vec2( 2.0, 0.0)), 0) * w3.x * w1.y;
-
- color += texelFetch(ima, ivec2(tc + vec2(-1.0, 1.0)), 0) * w0.x * w2.y;
- color += texelFetch(ima, ivec2(tc + vec2( 0.0, 1.0)), 0) * w1.x * w2.y;
- color += texelFetch(ima, ivec2(tc + vec2( 1.0, 1.0)), 0) * w2.x * w2.y;
- color += texelFetch(ima, ivec2(tc + vec2( 2.0, 1.0)), 0) * w3.x * w2.y;
-
- color += texelFetch(ima, ivec2(tc + vec2(-1.0, 2.0)), 0) * w0.x * w3.y;
- color += texelFetch(ima, ivec2(tc + vec2( 0.0, 2.0)), 0) * w1.x * w3.y;
- color += texelFetch(ima, ivec2(tc + vec2( 1.0, 2.0)), 0) * w2.x * w3.y;
- color += texelFetch(ima, ivec2(tc + vec2( 2.0, 2.0)), 0) * w3.x * w3.y;
+ color = texelFetch(ima, ivec2(tc + vec2(-1.0, -1.0)), 0) * w0.x * w0.y;
+ color += texelFetch(ima, ivec2(tc + vec2(0.0, -1.0)), 0) * w1.x * w0.y;
+ color += texelFetch(ima, ivec2(tc + vec2(1.0, -1.0)), 0) * w2.x * w0.y;
+ color += texelFetch(ima, ivec2(tc + vec2(2.0, -1.0)), 0) * w3.x * w0.y;
+
+ color += texelFetch(ima, ivec2(tc + vec2(-1.0, 0.0)), 0) * w0.x * w1.y;
+ color += texelFetch(ima, ivec2(tc + vec2(0.0, 0.0)), 0) * w1.x * w1.y;
+ color += texelFetch(ima, ivec2(tc + vec2(1.0, 0.0)), 0) * w2.x * w1.y;
+ color += texelFetch(ima, ivec2(tc + vec2(2.0, 0.0)), 0) * w3.x * w1.y;
+
+ color += texelFetch(ima, ivec2(tc + vec2(-1.0, 1.0)), 0) * w0.x * w2.y;
+ color += texelFetch(ima, ivec2(tc + vec2(0.0, 1.0)), 0) * w1.x * w2.y;
+ color += texelFetch(ima, ivec2(tc + vec2(1.0, 1.0)), 0) * w2.x * w2.y;
+ color += texelFetch(ima, ivec2(tc + vec2(2.0, 1.0)), 0) * w3.x * w2.y;
+
+ color += texelFetch(ima, ivec2(tc + vec2(-1.0, 2.0)), 0) * w0.x * w3.y;
+ color += texelFetch(ima, ivec2(tc + vec2(0.0, 2.0)), 0) * w1.x * w3.y;
+ color += texelFetch(ima, ivec2(tc + vec2(1.0, 2.0)), 0) * w2.x * w3.y;
+ color += texelFetch(ima, ivec2(tc + vec2(2.0, 2.0)), 0) * w3.x * w3.y;
#endif
- alpha = color.a;
+ alpha = color.a;
}
void node_tex_image_cubic(vec3 co, sampler2D ima, out vec4 color, out float alpha)
{
- node_tex_image_cubic_ex(co, ima, 0.0, color, alpha);
+ node_tex_image_cubic_ex(co, ima, 0.0, color, alpha);
}
void node_tex_image_cubic_extend(vec3 co, sampler2D ima, out vec4 color, out float alpha)
{
- node_tex_image_cubic_ex(co, ima, 1.0, color, alpha);
+ node_tex_image_cubic_ex(co, ima, 1.0, color, alpha);
}
void node_tex_image_smart(vec3 co, sampler2D ima, out vec4 color, out float alpha)
{
- /* use cubic for now */
- node_tex_image_cubic_ex(co, ima, 0.0, color, alpha);
-}
-
-void tex_box_sample_linear(vec3 texco,
- vec3 N,
- sampler2D ima,
- out vec4 color1,
- out vec4 color2,
- out vec4 color3)
-{
- /* X projection */
- vec2 uv = texco.yz;
- if (N.x < 0.0) {
- uv.x = 1.0 - uv.x;
- }
- color1 = texture(ima, uv);
- /* Y projection */
- uv = texco.xz;
- if (N.y > 0.0) {
- uv.x = 1.0 - uv.x;
- }
- color2 = texture(ima, uv);
- /* Z projection */
- uv = texco.yx;
- if (N.z > 0.0) {
- uv.x = 1.0 - uv.x;
- }
- color3 = texture(ima, uv);
-}
-
-void tex_box_sample_nearest(vec3 texco,
- vec3 N,
- sampler2D ima,
- out vec4 color1,
- out vec4 color2,
- out vec4 color3)
-{
- /* X projection */
- vec2 uv = texco.yz;
- if (N.x < 0.0) {
- uv.x = 1.0 - uv.x;
- }
- ivec2 pix = ivec2(uv.xy * textureSize(ima, 0).xy);
- color1 = texelFetch(ima, pix, 0);
- /* Y projection */
- uv = texco.xz;
- if (N.y > 0.0) {
- uv.x = 1.0 - uv.x;
- }
- pix = ivec2(uv.xy * textureSize(ima, 0).xy);
- color2 = texelFetch(ima, pix, 0);
- /* Z projection */
- uv = texco.yx;
- if (N.z > 0.0) {
- uv.x = 1.0 - uv.x;
- }
- pix = ivec2(uv.xy * textureSize(ima, 0).xy);
- color3 = texelFetch(ima, pix, 0);
-}
-
-void tex_box_sample_cubic(vec3 texco,
- vec3 N,
- sampler2D ima,
- out vec4 color1,
- out vec4 color2,
- out vec4 color3)
-{
- float alpha;
- /* X projection */
- vec2 uv = texco.yz;
- if (N.x < 0.0) {
- uv.x = 1.0 - uv.x;
- }
- node_tex_image_cubic_ex(uv.xyy, ima, 0.0, color1, alpha);
- /* Y projection */
- uv = texco.xz;
- if (N.y > 0.0) {
- uv.x = 1.0 - uv.x;
- }
- node_tex_image_cubic_ex(uv.xyy, ima, 0.0, color2, alpha);
- /* Z projection */
- uv = texco.yx;
- if (N.z > 0.0) {
- uv.x = 1.0 - uv.x;
- }
- node_tex_image_cubic_ex(uv.xyy, ima, 0.0, color3, alpha);
-}
-
-void tex_box_sample_smart(vec3 texco,
- vec3 N,
- sampler2D ima,
- out vec4 color1,
- out vec4 color2,
- out vec4 color3)
-{
- tex_box_sample_cubic(texco, N, ima, color1, color2, color3);
+ /* use cubic for now */
+ node_tex_image_cubic_ex(co, ima, 0.0, color, alpha);
+}
+
+void tex_box_sample_linear(
+ vec3 texco, vec3 N, sampler2D ima, out vec4 color1, out vec4 color2, out vec4 color3)
+{
+ /* X projection */
+ vec2 uv = texco.yz;
+ if (N.x < 0.0) {
+ uv.x = 1.0 - uv.x;
+ }
+ color1 = texture(ima, uv);
+ /* Y projection */
+ uv = texco.xz;
+ if (N.y > 0.0) {
+ uv.x = 1.0 - uv.x;
+ }
+ color2 = texture(ima, uv);
+ /* Z projection */
+ uv = texco.yx;
+ if (N.z > 0.0) {
+ uv.x = 1.0 - uv.x;
+ }
+ color3 = texture(ima, uv);
+}
+
+void tex_box_sample_nearest(
+ vec3 texco, vec3 N, sampler2D ima, out vec4 color1, out vec4 color2, out vec4 color3)
+{
+ /* X projection */
+ vec2 uv = texco.yz;
+ if (N.x < 0.0) {
+ uv.x = 1.0 - uv.x;
+ }
+ ivec2 pix = ivec2(uv.xy * textureSize(ima, 0).xy);
+ color1 = texelFetch(ima, pix, 0);
+ /* Y projection */
+ uv = texco.xz;
+ if (N.y > 0.0) {
+ uv.x = 1.0 - uv.x;
+ }
+ pix = ivec2(uv.xy * textureSize(ima, 0).xy);
+ color2 = texelFetch(ima, pix, 0);
+ /* Z projection */
+ uv = texco.yx;
+ if (N.z > 0.0) {
+ uv.x = 1.0 - uv.x;
+ }
+ pix = ivec2(uv.xy * textureSize(ima, 0).xy);
+ color3 = texelFetch(ima, pix, 0);
+}
+
+void tex_box_sample_cubic(
+ vec3 texco, vec3 N, sampler2D ima, out vec4 color1, out vec4 color2, out vec4 color3)
+{
+ float alpha;
+ /* X projection */
+ vec2 uv = texco.yz;
+ if (N.x < 0.0) {
+ uv.x = 1.0 - uv.x;
+ }
+ node_tex_image_cubic_ex(uv.xyy, ima, 0.0, color1, alpha);
+ /* Y projection */
+ uv = texco.xz;
+ if (N.y > 0.0) {
+ uv.x = 1.0 - uv.x;
+ }
+ node_tex_image_cubic_ex(uv.xyy, ima, 0.0, color2, alpha);
+ /* Z projection */
+ uv = texco.yx;
+ if (N.z > 0.0) {
+ uv.x = 1.0 - uv.x;
+ }
+ node_tex_image_cubic_ex(uv.xyy, ima, 0.0, color3, alpha);
+}
+
+void tex_box_sample_smart(
+ vec3 texco, vec3 N, sampler2D ima, out vec4 color1, out vec4 color2, out vec4 color3)
+{
+ tex_box_sample_cubic(texco, N, ima, color1, color2, color3);
}
void node_tex_image_box(vec3 texco,
@@ -2292,298 +2537,303 @@ void node_tex_image_box(vec3 texco,
out vec4 color,
out float alpha)
{
- /* project from direction vector to barycentric coordinates in triangles */
- N = abs(N);
- N /= dot(N, vec3(1.0));
-
- /* basic idea is to think of this as a triangle, each corner representing
- * one of the 3 faces of the cube. in the corners we have single textures,
- * in between we blend between two textures, and in the middle we a blend
- * between three textures.
- *
- * the Nxyz values are the barycentric coordinates in an equilateral
- * triangle, which in case of blending, in the middle has a smaller
- * equilateral triangle where 3 textures blend. this divides things into
- * 7 zones, with an if () test for each zone
- * EDIT: Now there is only 4 if's. */
-
- float limit = 0.5 + 0.5 * blend;
-
- vec3 weight;
- weight = N.xyz / (N.xyx + N.yzz);
- weight = clamp((weight - 0.5 * (1.0 - blend)) / max(1e-8, blend), 0.0, 1.0);
-
- /* test for mixes between two textures */
- if (N.z < (1.0 - limit) * (N.y + N.x)) {
- weight.z = 0.0;
- weight.y = 1.0 - weight.x;
- }
- else if (N.x < (1.0 - limit) * (N.y + N.z)) {
- weight.x = 0.0;
- weight.z = 1.0 - weight.y;
- }
- else if (N.y < (1.0 - limit) * (N.x + N.z)) {
- weight.y = 0.0;
- weight.x = 1.0 - weight.z;
- }
- else {
- /* last case, we have a mix between three */
- weight = ((2.0 - limit) * N + (limit - 1.0)) / max(1e-8, blend);
- }
-
- color = weight.x * color1 + weight.y * color2 + weight.z * color3;
- alpha = color.a;
+ /* project from direction vector to barycentric coordinates in triangles */
+ N = abs(N);
+ N /= dot(N, vec3(1.0));
+
+ /* basic idea is to think of this as a triangle, each corner representing
+ * one of the 3 faces of the cube. in the corners we have single textures,
+ * in between we blend between two textures, and in the middle we a blend
+ * between three textures.
+ *
+ * the Nxyz values are the barycentric coordinates in an equilateral
+ * triangle, which in case of blending, in the middle has a smaller
+ * equilateral triangle where 3 textures blend. this divides things into
+ * 7 zones, with an if () test for each zone
+ * EDIT: Now there is only 4 if's. */
+
+ float limit = 0.5 + 0.5 * blend;
+
+ vec3 weight;
+ weight = N.xyz / (N.xyx + N.yzz);
+ weight = clamp((weight - 0.5 * (1.0 - blend)) / max(1e-8, blend), 0.0, 1.0);
+
+ /* test for mixes between two textures */
+ if (N.z < (1.0 - limit) * (N.y + N.x)) {
+ weight.z = 0.0;
+ weight.y = 1.0 - weight.x;
+ }
+ else if (N.x < (1.0 - limit) * (N.y + N.z)) {
+ weight.x = 0.0;
+ weight.z = 1.0 - weight.y;
+ }
+ else if (N.y < (1.0 - limit) * (N.x + N.z)) {
+ weight.y = 0.0;
+ weight.x = 1.0 - weight.z;
+ }
+ else {
+ /* last case, we have a mix between three */
+ weight = ((2.0 - limit) * N + (limit - 1.0)) / max(1e-8, blend);
+ }
+
+ color = weight.x * color1 + weight.y * color2 + weight.z * color3;
+ alpha = color.a;
}
void tex_clip_linear(vec3 co, sampler2D ima, vec4 icolor, out vec4 color, out float alpha)
{
- vec2 tex_size = vec2(textureSize(ima, 0).xy);
- vec2 minco = min(co.xy, 1.0 - co.xy);
- minco = clamp(minco * tex_size + 0.5, 0.0, 1.0);
- float fac = minco.x * minco.y;
+ vec2 tex_size = vec2(textureSize(ima, 0).xy);
+ vec2 minco = min(co.xy, 1.0 - co.xy);
+ minco = clamp(minco * tex_size + 0.5, 0.0, 1.0);
+ float fac = minco.x * minco.y;
- color = mix(vec4(0.0), icolor, fac);
- alpha = color.a;
+ color = mix(vec4(0.0), icolor, fac);
+ alpha = color.a;
}
void tex_clip_nearest(vec3 co, sampler2D ima, vec4 icolor, out vec4 color, out float alpha)
{
- vec4 minco = vec4(co.xy, 1.0 - co.xy);
- color = (any(lessThan(minco, vec4(0.0)))) ? vec4(0.0) : icolor;
- alpha = color.a;
+ vec4 minco = vec4(co.xy, 1.0 - co.xy);
+ color = (any(lessThan(minco, vec4(0.0)))) ? vec4(0.0) : icolor;
+ alpha = color.a;
}
void tex_clip_cubic(vec3 co, sampler2D ima, vec4 icolor, out vec4 color, out float alpha)
{
- vec2 tex_size = vec2(textureSize(ima, 0).xy);
-
- co.xy *= tex_size;
- /* texel center */
- vec2 tc = floor(co.xy - 0.5) + 0.5;
- vec2 w0, w1, w2, w3;
- cubic_bspline_coefs(co.xy - tc, w0, w1, w2, w3);
-
- /* TODO Optimize this part. I'm sure there is a smarter way to do that.
- * Could do that when sampling? */
-#define CLIP_CUBIC_SAMPLE(samp, size) (float(all(greaterThan(samp, vec2(-0.5)))) * float(all(lessThan(ivec2(samp), itex_size))))
- ivec2 itex_size = textureSize(ima, 0).xy;
- float fac;
- fac = CLIP_CUBIC_SAMPLE(tc + vec2(-1.0, -1.0), itex_size) * w0.x * w0.y;
- fac += CLIP_CUBIC_SAMPLE(tc + vec2( 0.0, -1.0), itex_size) * w1.x * w0.y;
- fac += CLIP_CUBIC_SAMPLE(tc + vec2( 1.0, -1.0), itex_size) * w2.x * w0.y;
- fac += CLIP_CUBIC_SAMPLE(tc + vec2( 2.0, -1.0), itex_size) * w3.x * w0.y;
-
- fac += CLIP_CUBIC_SAMPLE(tc + vec2(-1.0, 0.0), itex_size) * w0.x * w1.y;
- fac += CLIP_CUBIC_SAMPLE(tc + vec2( 0.0, 0.0), itex_size) * w1.x * w1.y;
- fac += CLIP_CUBIC_SAMPLE(tc + vec2( 1.0, 0.0), itex_size) * w2.x * w1.y;
- fac += CLIP_CUBIC_SAMPLE(tc + vec2( 2.0, 0.0), itex_size) * w3.x * w1.y;
-
- fac += CLIP_CUBIC_SAMPLE(tc + vec2(-1.0, 1.0), itex_size) * w0.x * w2.y;
- fac += CLIP_CUBIC_SAMPLE(tc + vec2( 0.0, 1.0), itex_size) * w1.x * w2.y;
- fac += CLIP_CUBIC_SAMPLE(tc + vec2( 1.0, 1.0), itex_size) * w2.x * w2.y;
- fac += CLIP_CUBIC_SAMPLE(tc + vec2( 2.0, 1.0), itex_size) * w3.x * w2.y;
-
- fac += CLIP_CUBIC_SAMPLE(tc + vec2(-1.0, 2.0), itex_size) * w0.x * w3.y;
- fac += CLIP_CUBIC_SAMPLE(tc + vec2( 0.0, 2.0), itex_size) * w1.x * w3.y;
- fac += CLIP_CUBIC_SAMPLE(tc + vec2( 1.0, 2.0), itex_size) * w2.x * w3.y;
- fac += CLIP_CUBIC_SAMPLE(tc + vec2( 2.0, 2.0), itex_size) * w3.x * w3.y;
+ vec2 tex_size = vec2(textureSize(ima, 0).xy);
+
+ co.xy *= tex_size;
+ /* texel center */
+ vec2 tc = floor(co.xy - 0.5) + 0.5;
+ vec2 w0, w1, w2, w3;
+ cubic_bspline_coefs(co.xy - tc, w0, w1, w2, w3);
+
+ /* TODO Optimize this part. I'm sure there is a smarter way to do that.
+ * Could do that when sampling? */
+#define CLIP_CUBIC_SAMPLE(samp, size) \
+ (float(all(greaterThan(samp, vec2(-0.5)))) * float(all(lessThan(ivec2(samp), itex_size))))
+ ivec2 itex_size = textureSize(ima, 0).xy;
+ float fac;
+ fac = CLIP_CUBIC_SAMPLE(tc + vec2(-1.0, -1.0), itex_size) * w0.x * w0.y;
+ fac += CLIP_CUBIC_SAMPLE(tc + vec2(0.0, -1.0), itex_size) * w1.x * w0.y;
+ fac += CLIP_CUBIC_SAMPLE(tc + vec2(1.0, -1.0), itex_size) * w2.x * w0.y;
+ fac += CLIP_CUBIC_SAMPLE(tc + vec2(2.0, -1.0), itex_size) * w3.x * w0.y;
+
+ fac += CLIP_CUBIC_SAMPLE(tc + vec2(-1.0, 0.0), itex_size) * w0.x * w1.y;
+ fac += CLIP_CUBIC_SAMPLE(tc + vec2(0.0, 0.0), itex_size) * w1.x * w1.y;
+ fac += CLIP_CUBIC_SAMPLE(tc + vec2(1.0, 0.0), itex_size) * w2.x * w1.y;
+ fac += CLIP_CUBIC_SAMPLE(tc + vec2(2.0, 0.0), itex_size) * w3.x * w1.y;
+
+ fac += CLIP_CUBIC_SAMPLE(tc + vec2(-1.0, 1.0), itex_size) * w0.x * w2.y;
+ fac += CLIP_CUBIC_SAMPLE(tc + vec2(0.0, 1.0), itex_size) * w1.x * w2.y;
+ fac += CLIP_CUBIC_SAMPLE(tc + vec2(1.0, 1.0), itex_size) * w2.x * w2.y;
+ fac += CLIP_CUBIC_SAMPLE(tc + vec2(2.0, 1.0), itex_size) * w3.x * w2.y;
+
+ fac += CLIP_CUBIC_SAMPLE(tc + vec2(-1.0, 2.0), itex_size) * w0.x * w3.y;
+ fac += CLIP_CUBIC_SAMPLE(tc + vec2(0.0, 2.0), itex_size) * w1.x * w3.y;
+ fac += CLIP_CUBIC_SAMPLE(tc + vec2(1.0, 2.0), itex_size) * w2.x * w3.y;
+ fac += CLIP_CUBIC_SAMPLE(tc + vec2(2.0, 2.0), itex_size) * w3.x * w3.y;
#undef CLIP_CUBIC_SAMPLE
- color = mix(vec4(0.0), icolor, fac);
- alpha = color.a;
+ color = mix(vec4(0.0), icolor, fac);
+ alpha = color.a;
}
void tex_clip_smart(vec3 co, sampler2D ima, vec4 icolor, out vec4 color, out float alpha)
{
- tex_clip_cubic(co, ima, icolor, color, alpha);
+ tex_clip_cubic(co, ima, icolor, color, alpha);
}
void node_tex_image_empty(vec3 co, out vec4 color, out float alpha)
{
- color = vec4(0.0);
- alpha = 0.0;
-}
-
-void node_tex_magic(vec3 co, float scale, float distortion, float depth, out vec4 color, out float fac)
-{
- vec3 p = co * scale;
- float x = sin((p.x + p.y + p.z) * 5.0);
- float y = cos((-p.x + p.y - p.z) * 5.0);
- float z = -cos((-p.x - p.y + p.z) * 5.0);
-
- if (depth > 0) {
- x *= distortion;
- y *= distortion;
- z *= distortion;
- y = -cos(x - y + z);
- y *= distortion;
- if (depth > 1) {
- x = cos(x - y - z);
- x *= distortion;
- if (depth > 2) {
- z = sin(-x - y - z);
- z *= distortion;
- if (depth > 3) {
- x = -cos(-x + y - z);
- x *= distortion;
- if (depth > 4) {
- y = -sin(-x + y + z);
- y *= distortion;
- if (depth > 5) {
- y = -cos(-x + y + z);
- y *= distortion;
- if (depth > 6) {
- x = cos(x + y + z);
- x *= distortion;
- if (depth > 7) {
- z = sin(x + y - z);
- z *= distortion;
- if (depth > 8) {
- x = -cos(-x - y + z);
- x *= distortion;
- if (depth > 9) {
- y = -sin(x - y + z);
- y *= distortion;
- }
- }
- }
- }
- }
- }
- }
- }
- }
- }
- if (distortion != 0.0) {
- distortion *= 2.0;
- x /= distortion;
- y /= distortion;
- z /= distortion;
- }
-
- color = vec4(0.5 - x, 0.5 - y, 0.5 - z, 1.0);
- fac = (color.x + color.y + color.z) / 3.0;
+ color = vec4(0.0);
+ alpha = 0.0;
+}
+
+void node_tex_magic(
+ vec3 co, float scale, float distortion, float depth, out vec4 color, out float fac)
+{
+ vec3 p = co * scale;
+ float x = sin((p.x + p.y + p.z) * 5.0);
+ float y = cos((-p.x + p.y - p.z) * 5.0);
+ float z = -cos((-p.x - p.y + p.z) * 5.0);
+
+ if (depth > 0) {
+ x *= distortion;
+ y *= distortion;
+ z *= distortion;
+ y = -cos(x - y + z);
+ y *= distortion;
+ if (depth > 1) {
+ x = cos(x - y - z);
+ x *= distortion;
+ if (depth > 2) {
+ z = sin(-x - y - z);
+ z *= distortion;
+ if (depth > 3) {
+ x = -cos(-x + y - z);
+ x *= distortion;
+ if (depth > 4) {
+ y = -sin(-x + y + z);
+ y *= distortion;
+ if (depth > 5) {
+ y = -cos(-x + y + z);
+ y *= distortion;
+ if (depth > 6) {
+ x = cos(x + y + z);
+ x *= distortion;
+ if (depth > 7) {
+ z = sin(x + y - z);
+ z *= distortion;
+ if (depth > 8) {
+ x = -cos(-x - y + z);
+ x *= distortion;
+ if (depth > 9) {
+ y = -sin(x - y + z);
+ y *= distortion;
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ if (distortion != 0.0) {
+ distortion *= 2.0;
+ x /= distortion;
+ y /= distortion;
+ z /= distortion;
+ }
+
+ color = vec4(0.5 - x, 0.5 - y, 0.5 - z, 1.0);
+ fac = (color.x + color.y + color.z) / 3.0;
}
float noise_fade(float t)
{
- return t * t * t * (t * (t * 6.0 - 15.0) + 10.0);
+ return t * t * t * (t * (t * 6.0 - 15.0) + 10.0);
}
float noise_scale3(float result)
{
- return 0.9820 * result;
+ return 0.9820 * result;
}
float noise_nerp(float t, float a, float b)
{
- return (1.0 - t) * a + t * b;
+ return (1.0 - t) * a + t * b;
}
float noise_grad(uint hash, float x, float y, float z)
{
- uint h = hash & 15u;
- float u = h < 8u ? x : y;
- float vt = ((h == 12u) || (h == 14u)) ? x : z;
- float v = h < 4u ? y : vt;
- return (((h & 1u) != 0u) ? -u : u) + (((h & 2u) != 0u) ? -v : v);
+ uint h = hash & 15u;
+ float u = h < 8u ? x : y;
+ float vt = ((h == 12u) || (h == 14u)) ? x : z;
+ float v = h < 4u ? y : vt;
+ return (((h & 1u) != 0u) ? -u : u) + (((h & 2u) != 0u) ? -v : v);
}
float noise_perlin(float x, float y, float z)
{
- int X; float fx = floorfrac(x, X);
- int Y; float fy = floorfrac(y, Y);
- int Z; float fz = floorfrac(z, Z);
+ int X;
+ float fx = floorfrac(x, X);
+ int Y;
+ float fy = floorfrac(y, Y);
+ int Z;
+ float fz = floorfrac(z, Z);
- float u = noise_fade(fx);
- float v = noise_fade(fy);
- float w = noise_fade(fz);
+ float u = noise_fade(fx);
+ float v = noise_fade(fy);
+ float w = noise_fade(fz);
- float noise_u[2], noise_v[2];
+ float noise_u[2], noise_v[2];
- noise_u[0] = noise_nerp(u,
- noise_grad(hash(X, Y, Z), fx, fy, fz),
- noise_grad(hash(X + 1, Y, Z), fx - 1.0, fy, fz));
+ noise_u[0] = noise_nerp(
+ u, noise_grad(hash(X, Y, Z), fx, fy, fz), noise_grad(hash(X + 1, Y, Z), fx - 1.0, fy, fz));
- noise_u[1] = noise_nerp(u,
- noise_grad(hash(X, Y + 1, Z), fx, fy - 1.0, fz),
- noise_grad(hash(X + 1, Y + 1, Z), fx - 1.0, fy - 1.0, fz));
+ noise_u[1] = noise_nerp(u,
+ noise_grad(hash(X, Y + 1, Z), fx, fy - 1.0, fz),
+ noise_grad(hash(X + 1, Y + 1, Z), fx - 1.0, fy - 1.0, fz));
- noise_v[0] = noise_nerp(v, noise_u[0], noise_u[1]);
+ noise_v[0] = noise_nerp(v, noise_u[0], noise_u[1]);
- noise_u[0] = noise_nerp(u,
- noise_grad(hash(X, Y, Z + 1), fx, fy, fz - 1.0),
- noise_grad(hash(X + 1, Y, Z + 1), fx - 1.0, fy, fz - 1.0));
+ noise_u[0] = noise_nerp(u,
+ noise_grad(hash(X, Y, Z + 1), fx, fy, fz - 1.0),
+ noise_grad(hash(X + 1, Y, Z + 1), fx - 1.0, fy, fz - 1.0));
- noise_u[1] = noise_nerp(u,
- noise_grad(hash(X, Y + 1, Z + 1), fx, fy - 1.0, fz - 1.0),
- noise_grad(hash(X + 1, Y + 1, Z + 1), fx - 1.0, fy - 1.0, fz - 1.0));
+ noise_u[1] = noise_nerp(u,
+ noise_grad(hash(X, Y + 1, Z + 1), fx, fy - 1.0, fz - 1.0),
+ noise_grad(hash(X + 1, Y + 1, Z + 1), fx - 1.0, fy - 1.0, fz - 1.0));
- noise_v[1] = noise_nerp(v, noise_u[0], noise_u[1]);
+ noise_v[1] = noise_nerp(v, noise_u[0], noise_u[1]);
- return noise_scale3(noise_nerp(w, noise_v[0], noise_v[1]));
+ return noise_scale3(noise_nerp(w, noise_v[0], noise_v[1]));
}
float noise(vec3 p)
{
- return 0.5 * noise_perlin(p.x, p.y, p.z) + 0.5;
+ return 0.5 * noise_perlin(p.x, p.y, p.z) + 0.5;
}
float snoise(vec3 p)
{
- return noise_perlin(p.x, p.y, p.z);
+ return noise_perlin(p.x, p.y, p.z);
}
float noise_turbulence(vec3 p, float octaves, int hard)
{
- float fscale = 1.0;
- float amp = 1.0;
- float sum = 0.0;
- octaves = clamp(octaves, 0.0, 16.0);
- int n = int(octaves);
- for (int i = 0; i <= n; i++) {
- float t = noise(fscale * p);
- if (hard != 0) {
- t = abs(2.0 * t - 1.0);
- }
- sum += t * amp;
- amp *= 0.5;
- fscale *= 2.0;
- }
- float rmd = octaves - floor(octaves);
- if (rmd != 0.0) {
- float t = noise(fscale * p);
- if (hard != 0) {
- t = abs(2.0 * t - 1.0);
- }
- float sum2 = sum + t * amp;
- sum *= (float(1 << n) / float((1 << (n + 1)) - 1));
- sum2 *= (float(1 << (n + 1)) / float((1 << (n + 2)) - 1));
- return (1.0 - rmd) * sum + rmd * sum2;
- }
- else {
- sum *= (float(1 << n) / float((1 << (n + 1)) - 1));
- return sum;
- }
-}
-
-void node_tex_noise(vec3 co, float scale, float detail, float distortion, out vec4 color, out float fac)
-{
- vec3 p = co * scale;
- int hard = 0;
- if (distortion != 0.0) {
- vec3 r, offset = vec3(13.5, 13.5, 13.5);
- r.x = noise(p + offset) * distortion;
- r.y = noise(p) * distortion;
- r.z = noise(p - offset) * distortion;
- p += r;
- }
-
- fac = noise_turbulence(p, detail, hard);
- color = vec4(fac,
- noise_turbulence(vec3(p.y, p.x, p.z), detail, hard),
- noise_turbulence(vec3(p.y, p.z, p.x), detail, hard),
- 1);
+ float fscale = 1.0;
+ float amp = 1.0;
+ float sum = 0.0;
+ octaves = clamp(octaves, 0.0, 16.0);
+ int n = int(octaves);
+ for (int i = 0; i <= n; i++) {
+ float t = noise(fscale * p);
+ if (hard != 0) {
+ t = abs(2.0 * t - 1.0);
+ }
+ sum += t * amp;
+ amp *= 0.5;
+ fscale *= 2.0;
+ }
+ float rmd = octaves - floor(octaves);
+ if (rmd != 0.0) {
+ float t = noise(fscale * p);
+ if (hard != 0) {
+ t = abs(2.0 * t - 1.0);
+ }
+ float sum2 = sum + t * amp;
+ sum *= (float(1 << n) / float((1 << (n + 1)) - 1));
+ sum2 *= (float(1 << (n + 1)) / float((1 << (n + 2)) - 1));
+ return (1.0 - rmd) * sum + rmd * sum2;
+ }
+ else {
+ sum *= (float(1 << n) / float((1 << (n + 1)) - 1));
+ return sum;
+ }
+}
+
+void node_tex_noise(
+ vec3 co, float scale, float detail, float distortion, out vec4 color, out float fac)
+{
+ vec3 p = co * scale;
+ int hard = 0;
+ if (distortion != 0.0) {
+ vec3 r, offset = vec3(13.5, 13.5, 13.5);
+ r.x = noise(p + offset) * distortion;
+ r.y = noise(p) * distortion;
+ r.z = noise(p - offset) * distortion;
+ p += r;
+ }
+
+ fac = noise_turbulence(p, detail, hard);
+ color = vec4(fac,
+ noise_turbulence(vec3(p.y, p.x, p.z), detail, hard),
+ noise_turbulence(vec3(p.y, p.z, p.x), detail, hard),
+ 1);
}
/* Musgrave fBm
@@ -2597,22 +2847,22 @@ void node_tex_noise(vec3 co, float scale, float detail, float distortion, out ve
float noise_musgrave_fBm(vec3 p, float H, float lacunarity, float octaves)
{
- float rmd;
- float value = 0.0;
- float pwr = 1.0;
- float pwHL = pow(lacunarity, -H);
+ float rmd;
+ float value = 0.0;
+ float pwr = 1.0;
+ float pwHL = pow(lacunarity, -H);
- for (int i = 0; i < int(octaves); i++) {
- value += snoise(p) * pwr;
- pwr *= pwHL;
- p *= lacunarity;
- }
+ for (int i = 0; i < int(octaves); i++) {
+ value += snoise(p) * pwr;
+ pwr *= pwHL;
+ p *= lacunarity;
+ }
- rmd = octaves - floor(octaves);
- if (rmd != 0.0)
- value += rmd * snoise(p) * pwr;
+ rmd = octaves - floor(octaves);
+ if (rmd != 0.0)
+ value += rmd * snoise(p) * pwr;
- return value;
+ return value;
}
/* Musgrave Multifractal
@@ -2624,22 +2874,22 @@ float noise_musgrave_fBm(vec3 p, float H, float lacunarity, float octaves)
float noise_musgrave_multi_fractal(vec3 p, float H, float lacunarity, float octaves)
{
- float rmd;
- float value = 1.0;
- float pwr = 1.0;
- float pwHL = pow(lacunarity, -H);
+ float rmd;
+ float value = 1.0;
+ float pwr = 1.0;
+ float pwHL = pow(lacunarity, -H);
- for (int i = 0; i < int(octaves); i++) {
- value *= (pwr * snoise(p) + 1.0);
- pwr *= pwHL;
- p *= lacunarity;
- }
+ for (int i = 0; i < int(octaves); i++) {
+ value *= (pwr * snoise(p) + 1.0);
+ pwr *= pwHL;
+ p *= lacunarity;
+ }
- rmd = octaves - floor(octaves);
- if (rmd != 0.0)
- value *= (rmd * pwr * snoise(p) + 1.0); /* correct? */
+ rmd = octaves - floor(octaves);
+ if (rmd != 0.0)
+ value *= (rmd * pwr * snoise(p) + 1.0); /* correct? */
- return value;
+ return value;
}
/* Musgrave Heterogeneous Terrain
@@ -2652,28 +2902,28 @@ float noise_musgrave_multi_fractal(vec3 p, float H, float lacunarity, float octa
float noise_musgrave_hetero_terrain(vec3 p, float H, float lacunarity, float octaves, float offset)
{
- float value, increment, rmd;
- float pwHL = pow(lacunarity, -H);
- float pwr = pwHL;
+ float value, increment, rmd;
+ float pwHL = pow(lacunarity, -H);
+ float pwr = pwHL;
- /* first unscaled octave of function; later octaves are scaled */
- value = offset + snoise(p);
- p *= lacunarity;
+ /* first unscaled octave of function; later octaves are scaled */
+ value = offset + snoise(p);
+ p *= lacunarity;
- for (int i = 1; i < int(octaves); i++) {
- increment = (snoise(p) + offset) * pwr * value;
- value += increment;
- pwr *= pwHL;
- p *= lacunarity;
- }
+ for (int i = 1; i < int(octaves); i++) {
+ increment = (snoise(p) + offset) * pwr * value;
+ value += increment;
+ pwr *= pwHL;
+ p *= lacunarity;
+ }
- rmd = octaves - floor(octaves);
- if (rmd != 0.0) {
- increment = (snoise(p) + offset) * pwr * value;
- value += rmd * increment;
- }
+ rmd = octaves - floor(octaves);
+ if (rmd != 0.0) {
+ increment = (snoise(p) + offset) * pwr * value;
+ value += rmd * increment;
+ }
- return value;
+ return value;
}
/* Hybrid Additive/Multiplicative Multifractal Terrain
@@ -2684,32 +2934,33 @@ float noise_musgrave_hetero_terrain(vec3 p, float H, float lacunarity, float oct
* offset: raises the terrain from `sea level'
*/
-float noise_musgrave_hybrid_multi_fractal(vec3 p, float H, float lacunarity, float octaves, float offset, float gain)
+float noise_musgrave_hybrid_multi_fractal(
+ vec3 p, float H, float lacunarity, float octaves, float offset, float gain)
{
- float result, signal, weight, rmd;
- float pwHL = pow(lacunarity, -H);
- float pwr = pwHL;
+ float result, signal, weight, rmd;
+ float pwHL = pow(lacunarity, -H);
+ float pwr = pwHL;
- result = snoise(p) + offset;
- weight = gain * result;
- p *= lacunarity;
+ result = snoise(p) + offset;
+ weight = gain * result;
+ p *= lacunarity;
- for (int i = 1; (weight > 0.001f) && (i < int(octaves)); i++) {
- if (weight > 1.0)
- weight = 1.0;
+ for (int i = 1; (weight > 0.001f) && (i < int(octaves)); i++) {
+ if (weight > 1.0)
+ weight = 1.0;
- signal = (snoise(p) + offset) * pwr;
- pwr *= pwHL;
- result += weight * signal;
- weight *= gain * signal;
- p *= lacunarity;
- }
+ signal = (snoise(p) + offset) * pwr;
+ pwr *= pwHL;
+ result += weight * signal;
+ weight *= gain * signal;
+ p *= lacunarity;
+ }
- rmd = octaves - floor(octaves);
- if (rmd != 0.0)
- result += rmd * ((snoise(p) + offset) * pwr);
+ rmd = octaves - floor(octaves);
+ if (rmd != 0.0)
+ result += rmd * ((snoise(p) + offset) * pwr);
- return result;
+ return result;
}
/* Ridged Multifractal Terrain
@@ -2720,28 +2971,29 @@ float noise_musgrave_hybrid_multi_fractal(vec3 p, float H, float lacunarity, flo
* offset: raises the terrain from `sea level'
*/
-float noise_musgrave_ridged_multi_fractal(vec3 p, float H, float lacunarity, float octaves, float offset, float gain)
+float noise_musgrave_ridged_multi_fractal(
+ vec3 p, float H, float lacunarity, float octaves, float offset, float gain)
{
- float result, signal, weight;
- float pwHL = pow(lacunarity, -H);
- float pwr = pwHL;
+ float result, signal, weight;
+ float pwHL = pow(lacunarity, -H);
+ float pwr = pwHL;
- signal = offset - abs(snoise(p));
- signal *= signal;
- result = signal;
- weight = 1.0;
+ signal = offset - abs(snoise(p));
+ signal *= signal;
+ result = signal;
+ weight = 1.0;
- for (int i = 1; i < int(octaves); i++) {
- p *= lacunarity;
- weight = clamp(signal * gain, 0.0, 1.0);
- signal = offset - abs(snoise(p));
- signal *= signal;
- signal *= weight;
- result += signal * pwr;
- pwr *= pwHL;
- }
+ for (int i = 1; i < int(octaves); i++) {
+ p *= lacunarity;
+ weight = clamp(signal * gain, 0.0, 1.0);
+ signal = offset - abs(snoise(p));
+ signal *= signal;
+ signal *= weight;
+ result += signal * pwr;
+ pwr *= pwHL;
+ }
- return result;
+ return result;
}
float svm_musgrave(int type,
@@ -2753,17 +3005,19 @@ float svm_musgrave(int type,
float gain,
vec3 p)
{
- if (type == 0 /* NODE_MUSGRAVE_MULTIFRACTAL */)
- return intensity * noise_musgrave_multi_fractal(p, dimension, lacunarity, octaves);
- else if (type == 1 /* NODE_MUSGRAVE_FBM */)
- return intensity * noise_musgrave_fBm(p, dimension, lacunarity, octaves);
- else if (type == 2 /* NODE_MUSGRAVE_HYBRID_MULTIFRACTAL */)
- return intensity * noise_musgrave_hybrid_multi_fractal(p, dimension, lacunarity, octaves, offset, gain);
- else if (type == 3 /* NODE_MUSGRAVE_RIDGED_MULTIFRACTAL */)
- return intensity * noise_musgrave_ridged_multi_fractal(p, dimension, lacunarity, octaves, offset, gain);
- else if (type == 4 /* NODE_MUSGRAVE_HETERO_TERRAIN */)
- return intensity * noise_musgrave_hetero_terrain(p, dimension, lacunarity, octaves, offset);
- return 0.0;
+ if (type == 0 /* NODE_MUSGRAVE_MULTIFRACTAL */)
+ return intensity * noise_musgrave_multi_fractal(p, dimension, lacunarity, octaves);
+ else if (type == 1 /* NODE_MUSGRAVE_FBM */)
+ return intensity * noise_musgrave_fBm(p, dimension, lacunarity, octaves);
+ else if (type == 2 /* NODE_MUSGRAVE_HYBRID_MULTIFRACTAL */)
+ return intensity *
+ noise_musgrave_hybrid_multi_fractal(p, dimension, lacunarity, octaves, offset, gain);
+ else if (type == 3 /* NODE_MUSGRAVE_RIDGED_MULTIFRACTAL */)
+ return intensity *
+ noise_musgrave_ridged_multi_fractal(p, dimension, lacunarity, octaves, offset, gain);
+ else if (type == 4 /* NODE_MUSGRAVE_HETERO_TERRAIN */)
+ return intensity * noise_musgrave_hetero_terrain(p, dimension, lacunarity, octaves, offset);
+ return 0.0;
}
void node_tex_musgrave(vec3 co,
@@ -2777,308 +3031,337 @@ void node_tex_musgrave(vec3 co,
out vec4 color,
out float fac)
{
- fac = svm_musgrave(int(type),
- dimension,
- lacunarity,
- detail,
- offset,
- 1.0,
- gain,
- co * scale);
+ fac = svm_musgrave(int(type), dimension, lacunarity, detail, offset, 1.0, gain, co *scale);
- color = vec4(fac, fac, fac, 1.0);
+ color = vec4(fac, fac, fac, 1.0);
}
void node_tex_sky(vec3 co, out vec4 color)
{
- color = vec4(1.0);
-}
-
-void node_tex_voronoi(vec3 co, float scale, float exponent, float coloring, float metric, float feature, out vec4 color, out float fac)
-{
- vec3 p = co * scale;
- int xx, yy, zz, xi, yi, zi;
- vec4 da = vec4(1e10);
- vec3 pa[4] = vec3[4](vec3(0.0), vec3(0.0), vec3(0.0), vec3(0.0));
-
- xi = floor_to_int(p[0]);
- yi = floor_to_int(p[1]);
- zi = floor_to_int(p[2]);
-
- for (xx = xi - 1; xx <= xi + 1; xx++) {
- for (yy = yi - 1; yy <= yi + 1; yy++) {
- for (zz = zi - 1; zz <= zi + 1; zz++) {
- vec3 ip = vec3(xx, yy, zz);
- vec3 vp = cellnoise_color(ip);
- vec3 pd = p - (vp + ip);
-
- float d = 0.0;
- if (metric == 0.0) { /* SHD_VORONOI_DISTANCE 0 */
- d = dot(pd, pd);
- }
- else if (metric == 1.0) { /* SHD_VORONOI_MANHATTAN 1 */
- d = abs(pd[0]) + abs(pd[1]) + abs(pd[2]);
- }
- else if (metric == 2.0) { /* SHD_VORONOI_CHEBYCHEV 2 */
- d = max(abs(pd[0]), max(abs(pd[1]), abs(pd[2])));
- }
- else if (metric == 3.0) { /* SHD_VORONOI_MINKOWSKI 3 */
- d = pow(pow(abs(pd[0]), exponent) + pow(abs(pd[1]), exponent) + pow(abs(pd[2]), exponent), 1.0/exponent);
- }
-
- vp += vec3(xx, yy, zz);
- if (d < da[0]) {
- da.yzw = da.xyz;
- da[0] = d;
-
- pa[3] = pa[2];
- pa[2] = pa[1];
- pa[1] = pa[0];
- pa[0] = vp;
- }
- else if (d < da[1]) {
- da.zw = da.yz;
- da[1] = d;
-
- pa[3] = pa[2];
- pa[2] = pa[1];
- pa[1] = vp;
- }
- else if (d < da[2]) {
- da[3] = da[2];
- da[2] = d;
-
- pa[3] = pa[2];
- pa[2] = vp;
- }
- else if (d < da[3]) {
- da[3] = d;
- pa[3] = vp;
- }
- }
- }
- }
-
- if (coloring == 0.0) {
- /* Intensity output */
- if (feature == 0.0) { /* F1 */
- fac = abs(da[0]);
- }
- else if (feature == 1.0) { /* F2 */
- fac = abs(da[1]);
- }
- else if (feature == 2.0) { /* F3 */
- fac = abs(da[2]);
- }
- else if (feature == 3.0) { /* F4 */
- fac = abs(da[3]);
- }
- else if (feature == 4.0) { /* F2F1 */
- fac = abs(da[1] - da[0]);
- }
- color = vec4(fac, fac, fac, 1.0);
- }
- else {
- /* Color output */
- vec3 col = vec3(fac, fac, fac);
- if (feature == 0.0) { /* F1 */
- col = pa[0];
- }
- else if (feature == 1.0) { /* F2 */
- col = pa[1];
- }
- else if (feature == 2.0) { /* F3 */
- col = pa[2];
- }
- else if (feature == 3.0) { /* F4 */
- col = pa[3];
- }
- else if (feature == 4.0) { /* F2F1 */
- col = abs(pa[1] - pa[0]);
- }
-
- color = vec4(cellnoise_color(col), 1.0);
- fac = (color.x + color.y + color.z) * (1.0 / 3.0);
- }
-}
-
-float calc_wave(vec3 p, float distortion, float detail, float detail_scale, int wave_type, int wave_profile)
-{
- float n;
-
- if (wave_type == 0) /* type bands */
- n = (p.x + p.y + p.z) * 10.0;
- else /* type rings */
- n = length(p) * 20.0;
-
- if (distortion != 0.0)
- n += distortion * noise_turbulence(p * detail_scale, detail, 0);
-
- if (wave_profile == 0) { /* profile sin */
- return 0.5 + 0.5 * sin(n);
- }
- else { /* profile saw */
- n /= 2.0 * M_PI;
- n -= int(n);
- return (n < 0.0) ? n + 1.0 : n;
- }
-}
-
-void node_tex_wave(
- vec3 co, float scale, float distortion, float detail, float detail_scale, float wave_type, float wave_profile,
- out vec4 color, out float fac)
-{
- float f;
- f = calc_wave(co * scale, distortion, detail, detail_scale, int(wave_type), int(wave_profile));
-
- color = vec4(f, f, f, 1.0);
- fac = f;
+ color = vec4(1.0);
+}
+
+void node_tex_voronoi(vec3 co,
+ float scale,
+ float exponent,
+ float coloring,
+ float metric,
+ float feature,
+ out vec4 color,
+ out float fac)
+{
+ vec3 p = co * scale;
+ int xx, yy, zz, xi, yi, zi;
+ vec4 da = vec4(1e10);
+ vec3 pa[4] = vec3[4](vec3(0.0), vec3(0.0), vec3(0.0), vec3(0.0));
+
+ xi = floor_to_int(p[0]);
+ yi = floor_to_int(p[1]);
+ zi = floor_to_int(p[2]);
+
+ for (xx = xi - 1; xx <= xi + 1; xx++) {
+ for (yy = yi - 1; yy <= yi + 1; yy++) {
+ for (zz = zi - 1; zz <= zi + 1; zz++) {
+ vec3 ip = vec3(xx, yy, zz);
+ vec3 vp = cellnoise_color(ip);
+ vec3 pd = p - (vp + ip);
+
+ float d = 0.0;
+ if (metric == 0.0) { /* SHD_VORONOI_DISTANCE 0 */
+ d = dot(pd, pd);
+ }
+ else if (metric == 1.0) { /* SHD_VORONOI_MANHATTAN 1 */
+ d = abs(pd[0]) + abs(pd[1]) + abs(pd[2]);
+ }
+ else if (metric == 2.0) { /* SHD_VORONOI_CHEBYCHEV 2 */
+ d = max(abs(pd[0]), max(abs(pd[1]), abs(pd[2])));
+ }
+ else if (metric == 3.0) { /* SHD_VORONOI_MINKOWSKI 3 */
+ d = pow(pow(abs(pd[0]), exponent) + pow(abs(pd[1]), exponent) +
+ pow(abs(pd[2]), exponent),
+ 1.0 / exponent);
+ }
+
+ vp += vec3(xx, yy, zz);
+ if (d < da[0]) {
+ da.yzw = da.xyz;
+ da[0] = d;
+
+ pa[3] = pa[2];
+ pa[2] = pa[1];
+ pa[1] = pa[0];
+ pa[0] = vp;
+ }
+ else if (d < da[1]) {
+ da.zw = da.yz;
+ da[1] = d;
+
+ pa[3] = pa[2];
+ pa[2] = pa[1];
+ pa[1] = vp;
+ }
+ else if (d < da[2]) {
+ da[3] = da[2];
+ da[2] = d;
+
+ pa[3] = pa[2];
+ pa[2] = vp;
+ }
+ else if (d < da[3]) {
+ da[3] = d;
+ pa[3] = vp;
+ }
+ }
+ }
+ }
+
+ if (coloring == 0.0) {
+ /* Intensity output */
+ if (feature == 0.0) { /* F1 */
+ fac = abs(da[0]);
+ }
+ else if (feature == 1.0) { /* F2 */
+ fac = abs(da[1]);
+ }
+ else if (feature == 2.0) { /* F3 */
+ fac = abs(da[2]);
+ }
+ else if (feature == 3.0) { /* F4 */
+ fac = abs(da[3]);
+ }
+ else if (feature == 4.0) { /* F2F1 */
+ fac = abs(da[1] - da[0]);
+ }
+ color = vec4(fac, fac, fac, 1.0);
+ }
+ else {
+ /* Color output */
+ vec3 col = vec3(fac, fac, fac);
+ if (feature == 0.0) { /* F1 */
+ col = pa[0];
+ }
+ else if (feature == 1.0) { /* F2 */
+ col = pa[1];
+ }
+ else if (feature == 2.0) { /* F3 */
+ col = pa[2];
+ }
+ else if (feature == 3.0) { /* F4 */
+ col = pa[3];
+ }
+ else if (feature == 4.0) { /* F2F1 */
+ col = abs(pa[1] - pa[0]);
+ }
+
+ color = vec4(cellnoise_color(col), 1.0);
+ fac = (color.x + color.y + color.z) * (1.0 / 3.0);
+ }
+}
+
+float calc_wave(
+ vec3 p, float distortion, float detail, float detail_scale, int wave_type, int wave_profile)
+{
+ float n;
+
+ if (wave_type == 0) /* type bands */
+ n = (p.x + p.y + p.z) * 10.0;
+ else /* type rings */
+ n = length(p) * 20.0;
+
+ if (distortion != 0.0)
+ n += distortion * noise_turbulence(p * detail_scale, detail, 0);
+
+ if (wave_profile == 0) { /* profile sin */
+ return 0.5 + 0.5 * sin(n);
+ }
+ else { /* profile saw */
+ n /= 2.0 * M_PI;
+ n -= int(n);
+ return (n < 0.0) ? n + 1.0 : n;
+ }
+}
+
+void node_tex_wave(vec3 co,
+ float scale,
+ float distortion,
+ float detail,
+ float detail_scale,
+ float wave_type,
+ float wave_profile,
+ out vec4 color,
+ out float fac)
+{
+ float f;
+ f = calc_wave(co * scale, distortion, detail, detail_scale, int(wave_type), int(wave_profile));
+
+ color = vec4(f, f, f, 1.0);
+ fac = f;
}
/* light path */
-void node_light_path(
- out float is_camera_ray,
- out float is_shadow_ray,
- out float is_diffuse_ray,
- out float is_glossy_ray,
- out float is_singular_ray,
- out float is_reflection_ray,
- out float is_transmission_ray,
- out float ray_length,
- out float ray_depth,
- out float diffuse_depth,
- out float glossy_depth,
- out float transparent_depth,
- out float transmission_depth)
-{
- /* Supported. */
- is_camera_ray = (rayType == EEVEE_RAY_CAMERA) ? 1.0 : 0.0;
- is_shadow_ray = (rayType == EEVEE_RAY_SHADOW) ? 1.0 : 0.0;
- is_diffuse_ray = (rayType == EEVEE_RAY_DIFFUSE) ? 1.0 : 0.0;
- is_glossy_ray = (rayType == EEVEE_RAY_GLOSSY) ? 1.0 : 0.0;
- /* Kind of supported. */
- is_singular_ray = is_glossy_ray;
- is_reflection_ray = is_glossy_ray;
- is_transmission_ray = is_glossy_ray;
- ray_depth = rayDepth;
- diffuse_depth = (is_diffuse_ray == 1.0) ? rayDepth : 0.0;
- glossy_depth = (is_glossy_ray == 1.0) ? rayDepth : 0.0;
- transmission_depth = (is_transmission_ray == 1.0) ? glossy_depth : 0.0;
- /* Not supported. */
- ray_length = 1.0;
- transparent_depth = 0.0;
-}
-
-void node_light_falloff(float strength, float tsmooth, out float quadratic, out float linear, out float constant)
-{
- quadratic = strength;
- linear = strength;
- constant = strength;
-}
-
-void node_object_info(mat4 obmat, vec4 info, out vec3 location, out float object_index, out float material_index, out float random)
-{
- location = obmat[3].xyz;
- object_index = info.x;
- material_index = info.y;
- random = info.z;
+void node_light_path(out float is_camera_ray,
+ out float is_shadow_ray,
+ out float is_diffuse_ray,
+ out float is_glossy_ray,
+ out float is_singular_ray,
+ out float is_reflection_ray,
+ out float is_transmission_ray,
+ out float ray_length,
+ out float ray_depth,
+ out float diffuse_depth,
+ out float glossy_depth,
+ out float transparent_depth,
+ out float transmission_depth)
+{
+ /* Supported. */
+ is_camera_ray = (rayType == EEVEE_RAY_CAMERA) ? 1.0 : 0.0;
+ is_shadow_ray = (rayType == EEVEE_RAY_SHADOW) ? 1.0 : 0.0;
+ is_diffuse_ray = (rayType == EEVEE_RAY_DIFFUSE) ? 1.0 : 0.0;
+ is_glossy_ray = (rayType == EEVEE_RAY_GLOSSY) ? 1.0 : 0.0;
+ /* Kind of supported. */
+ is_singular_ray = is_glossy_ray;
+ is_reflection_ray = is_glossy_ray;
+ is_transmission_ray = is_glossy_ray;
+ ray_depth = rayDepth;
+ diffuse_depth = (is_diffuse_ray == 1.0) ? rayDepth : 0.0;
+ glossy_depth = (is_glossy_ray == 1.0) ? rayDepth : 0.0;
+ transmission_depth = (is_transmission_ray == 1.0) ? glossy_depth : 0.0;
+ /* Not supported. */
+ ray_length = 1.0;
+ transparent_depth = 0.0;
+}
+
+void node_light_falloff(
+ float strength, float tsmooth, out float quadratic, out float linear, out float constant)
+{
+ quadratic = strength;
+ linear = strength;
+ constant = strength;
+}
+
+void node_object_info(mat4 obmat,
+ vec4 info,
+ out vec3 location,
+ out float object_index,
+ out float material_index,
+ out float random)
+{
+ location = obmat[3].xyz;
+ object_index = info.x;
+ material_index = info.y;
+ random = info.z;
}
void node_normal_map(vec4 info, vec4 tangent, vec3 normal, vec3 texnormal, out vec3 outnormal)
{
- if (all(equal(tangent, vec4(0.0, 0.0, 0.0, 1.0)))) {
- outnormal = normal;
- return;
- }
- tangent *= (gl_FrontFacing ? 1.0 : -1.0);
- vec3 B = tangent.w * cross(normal, tangent.xyz) * info.w;
+ if (all(equal(tangent, vec4(0.0, 0.0, 0.0, 1.0)))) {
+ outnormal = normal;
+ return;
+ }
+ tangent *= (gl_FrontFacing ? 1.0 : -1.0);
+ vec3 B = tangent.w * cross(normal, tangent.xyz) * info.w;
- outnormal = texnormal.x * tangent.xyz + texnormal.y * B + texnormal.z * normal;
- outnormal = normalize(outnormal);
+ outnormal = texnormal.x * tangent.xyz + texnormal.y * B + texnormal.z * normal;
+ outnormal = normalize(outnormal);
}
-void node_bump(float strength, float dist, float height, vec3 N, vec3 surf_pos, float invert, out vec3 result)
+void node_bump(
+ float strength, float dist, float height, vec3 N, vec3 surf_pos, float invert, out vec3 result)
{
- N = mat3(ViewMatrix) * normalize(N);
- dist *= invert;
+ N = mat3(ViewMatrix) * normalize(N);
+ dist *= invert;
- vec3 dPdx = dFdx(surf_pos);
- vec3 dPdy = dFdy(surf_pos);
+ vec3 dPdx = dFdx(surf_pos);
+ vec3 dPdy = dFdy(surf_pos);
- /* Get surface tangents from normal. */
- vec3 Rx = cross(dPdy, N);
- vec3 Ry = cross(N, dPdx);
+ /* Get surface tangents from normal. */
+ vec3 Rx = cross(dPdy, N);
+ vec3 Ry = cross(N, dPdx);
- /* Compute surface gradient and determinant. */
- float det = dot(dPdx, Rx);
+ /* Compute surface gradient and determinant. */
+ float det = dot(dPdx, Rx);
- float dHdx = dFdx(height);
- float dHdy = dFdy(height);
- vec3 surfgrad = dHdx * Rx + dHdy * Ry;
+ float dHdx = dFdx(height);
+ float dHdy = dFdy(height);
+ vec3 surfgrad = dHdx * Rx + dHdy * Ry;
- strength = max(strength, 0.0);
+ strength = max(strength, 0.0);
- result = normalize(abs(det) * N - dist * sign(det) * surfgrad);
- result = normalize(mix(N, result, strength));
+ result = normalize(abs(det) * N - dist * sign(det) * surfgrad);
+ result = normalize(mix(N, result, strength));
- result = mat3(ViewMatrixInverse) * result;
+ result = mat3(ViewMatrixInverse) * result;
}
void node_bevel(float radius, vec3 N, out vec3 result)
{
- result = N;
+ result = N;
}
-void node_hair_info(out float is_strand, out float intercept, out float thickness, out vec3 tangent, out float random)
+void node_hair_info(out float is_strand,
+ out float intercept,
+ out float thickness,
+ out vec3 tangent,
+ out float random)
{
#ifdef HAIR_SHADER
- is_strand = 1.0;
- intercept = hairTime;
- thickness = hairThickness;
- tangent = normalize(hairTangent);
- random = wang_hash_noise(uint(hairStrandID)); /* TODO: could be precomputed per strand instead. */
+ is_strand = 1.0;
+ intercept = hairTime;
+ thickness = hairThickness;
+ tangent = normalize(hairTangent);
+ random = wang_hash_noise(
+ uint(hairStrandID)); /* TODO: could be precomputed per strand instead. */
#else
- is_strand = 0.0;
- intercept = 0.0;
- thickness = 0.0;
- tangent = vec3(1.0);
- random = 0.0;
+ is_strand = 0.0;
+ intercept = 0.0;
+ thickness = 0.0;
+ tangent = vec3(1.0);
+ random = 0.0;
#endif
}
-void node_displacement_object(float height, float midlevel, float scale, vec3 N, mat4 obmat, out vec3 result)
+void node_displacement_object(
+ float height, float midlevel, float scale, vec3 N, mat4 obmat, out vec3 result)
{
- N = (vec4(N, 0.0) * obmat).xyz;
- result = (height - midlevel) * scale * normalize(N);
- result = (obmat * vec4(result, 0.0)).xyz;
+ N = (vec4(N, 0.0) * obmat).xyz;
+ result = (height - midlevel) * scale * normalize(N);
+ result = (obmat * vec4(result, 0.0)).xyz;
}
void node_displacement_world(float height, float midlevel, float scale, vec3 N, out vec3 result)
{
- result = (height - midlevel) * scale * normalize(N);
+ result = (height - midlevel) * scale * normalize(N);
}
-void node_vector_displacement_tangent(vec4 vector, float midlevel, float scale, vec4 tangent, vec3 normal, mat4 obmat, mat4 viewmat, out vec3 result)
+void node_vector_displacement_tangent(vec4 vector,
+ float midlevel,
+ float scale,
+ vec4 tangent,
+ vec3 normal,
+ mat4 obmat,
+ mat4 viewmat,
+ out vec3 result)
{
- vec3 N_object = normalize(((vec4(normal, 0.0) * viewmat) * obmat).xyz);
- vec3 T_object = normalize(((vec4(tangent.xyz, 0.0) * viewmat) * obmat).xyz);
- vec3 B_object = tangent.w * normalize(cross(N_object, T_object));
+ vec3 N_object = normalize(((vec4(normal, 0.0) * viewmat) * obmat).xyz);
+ vec3 T_object = normalize(((vec4(tangent.xyz, 0.0) * viewmat) * obmat).xyz);
+ vec3 B_object = tangent.w * normalize(cross(N_object, T_object));
- vec3 offset = (vector.xyz - vec3(midlevel)) * scale;
- result = offset.x * T_object + offset.y * N_object + offset.z * B_object;
- result = (obmat * vec4(result, 0.0)).xyz;
+ vec3 offset = (vector.xyz - vec3(midlevel)) * scale;
+ result = offset.x * T_object + offset.y * N_object + offset.z * B_object;
+ result = (obmat * vec4(result, 0.0)).xyz;
}
-void node_vector_displacement_object(vec4 vector, float midlevel, float scale, mat4 obmat, out vec3 result)
+void node_vector_displacement_object(
+ vec4 vector, float midlevel, float scale, mat4 obmat, out vec3 result)
{
- result = (vector.xyz - vec3(midlevel)) * scale;
- result = (obmat * vec4(result, 0.0)).xyz;
+ result = (vector.xyz - vec3(midlevel)) * scale;
+ result = (obmat * vec4(result, 0.0)).xyz;
}
void node_vector_displacement_world(vec4 vector, float midlevel, float scale, out vec3 result)
{
- result = (vector.xyz - vec3(midlevel)) * scale;
+ result = (vector.xyz - vec3(midlevel)) * scale;
}
/* output */
@@ -3086,9 +3369,9 @@ void node_vector_displacement_world(vec4 vector, float midlevel, float scale, ou
void node_output_material(Closure surface, Closure volume, vec3 displacement, out Closure result)
{
#ifdef VOLUMETRICS
- result = volume;
+ result = volume;
#else
- result = surface;
+ result = surface;
#endif
}
@@ -3097,10 +3380,10 @@ uniform float backgroundAlpha;
void node_output_world(Closure surface, Closure volume, out Closure result)
{
#ifndef VOLUMETRICS
- result.radiance = surface.radiance * backgroundAlpha;
- result.opacity = backgroundAlpha;
+ result.radiance = surface.radiance * backgroundAlpha;
+ result.opacity = backgroundAlpha;
#else
- result = volume;
+ result = volume;
#endif /* VOLUMETRICS */
}
@@ -3109,65 +3392,80 @@ void node_output_world(Closure surface, Closure volume, out Closure result)
/* EEVEE output */
void world_normals_get(out vec3 N)
{
-#ifdef HAIR_SHADER
- vec3 B = normalize(cross(worldNormal, hairTangent));
- float cos_theta;
- if (hairThicknessRes == 1) {
- vec4 rand = texelFetch(utilTex, ivec3(ivec2(gl_FragCoord.xy) % LUT_SIZE, 2.0), 0);
- /* Random cosine normal distribution on the hair surface. */
- cos_theta = rand.x * 2.0 - 1.0;
- }
- else {
- /* Shade as a cylinder. */
- cos_theta = hairThickTime / hairThickness;
- }
- float sin_theta = sqrt(max(0.0, 1.0f - cos_theta*cos_theta));
- N = normalize(worldNormal * sin_theta + B * cos_theta);
-#else
- N = gl_FrontFacing ? worldNormal : -worldNormal;
-#endif
+# ifdef HAIR_SHADER
+ vec3 B = normalize(cross(worldNormal, hairTangent));
+ float cos_theta;
+ if (hairThicknessRes == 1) {
+ vec4 rand = texelFetch(utilTex, ivec3(ivec2(gl_FragCoord.xy) % LUT_SIZE, 2.0), 0);
+ /* Random cosine normal distribution on the hair surface. */
+ cos_theta = rand.x * 2.0 - 1.0;
+ }
+ else {
+ /* Shade as a cylinder. */
+ cos_theta = hairThickTime / hairThickness;
+ }
+ float sin_theta = sqrt(max(0.0, 1.0f - cos_theta * cos_theta));
+ N = normalize(worldNormal * sin_theta + B * cos_theta);
+# else
+ N = gl_FrontFacing ? worldNormal : -worldNormal;
+# endif
}
-void node_eevee_specular(
- vec4 diffuse, vec4 specular, float roughness, vec4 emissive, float transp, vec3 normal,
- float clearcoat, float clearcoat_roughness, vec3 clearcoat_normal,
- float occlusion, float ssr_id, out Closure result)
-{
- vec3 out_diff, out_spec, ssr_spec;
- eevee_closure_default(normal, diffuse.rgb, specular.rgb, int(ssr_id), roughness, occlusion,
- out_diff, out_spec, ssr_spec);
-
- vec3 vN = normalize(mat3(ViewMatrix) * normal);
- result = CLOSURE_DEFAULT;
- result.radiance = out_diff * diffuse.rgb + out_spec + emissive.rgb;
- result.opacity = 1.0 - transp;
- result.ssr_data = vec4(ssr_spec, roughness);
- result.ssr_normal = normal_encode(vN, viewCameraVec);
- result.ssr_id = int(ssr_id);
+void node_eevee_specular(vec4 diffuse,
+ vec4 specular,
+ float roughness,
+ vec4 emissive,
+ float transp,
+ vec3 normal,
+ float clearcoat,
+ float clearcoat_roughness,
+ vec3 clearcoat_normal,
+ float occlusion,
+ float ssr_id,
+ out Closure result)
+{
+ vec3 out_diff, out_spec, ssr_spec;
+ eevee_closure_default(normal,
+ diffuse.rgb,
+ specular.rgb,
+ int(ssr_id),
+ roughness,
+ occlusion,
+ out_diff,
+ out_spec,
+ ssr_spec);
+
+ vec3 vN = normalize(mat3(ViewMatrix) * normal);
+ result = CLOSURE_DEFAULT;
+ result.radiance = out_diff * diffuse.rgb + out_spec + emissive.rgb;
+ result.opacity = 1.0 - transp;
+ result.ssr_data = vec4(ssr_spec, roughness);
+ result.ssr_normal = normal_encode(vN, viewCameraVec);
+ result.ssr_id = int(ssr_id);
}
void node_shader_to_rgba(Closure cl, out vec4 outcol, out float outalpha)
{
- vec4 spec_accum = vec4(0.0);
- if (ssrToggle && cl.ssr_id == outputSsrId) {
- vec3 V = cameraVec;
- vec3 vN = normal_decode(cl.ssr_normal, viewCameraVec);
- vec3 N = transform_direction(ViewMatrixInverse, vN);
- float roughness = cl.ssr_data.a;
- float roughnessSquared = max(1e-3, roughness * roughness);
- fallback_cubemap(N, V, worldPosition, viewPosition, roughness, roughnessSquared, spec_accum);
- }
-
- outalpha = cl.opacity;
- outcol = vec4((spec_accum.rgb * cl.ssr_data.rgb) + cl.radiance, 1.0);
-
-# ifdef USE_SSS
-# ifdef USE_SSS_ALBEDO
- outcol.rgb += cl.sss_data.rgb * cl.sss_albedo;
-# else
- outcol.rgb += cl.sss_data.rgb;
-# endif
-# endif
+ vec4 spec_accum = vec4(0.0);
+ if (ssrToggle && cl.ssr_id == outputSsrId) {
+ vec3 V = cameraVec;
+ vec3 vN = normal_decode(cl.ssr_normal, viewCameraVec);
+ vec3 N = transform_direction(ViewMatrixInverse, vN);
+ float roughness = cl.ssr_data.a;
+ float roughnessSquared = max(1e-3, roughness * roughness);
+ fallback_cubemap(N, V, worldPosition, viewPosition, roughness, roughnessSquared, spec_accum);
+ }
+
+ outalpha = cl.opacity;
+ outcol = vec4((spec_accum.rgb * cl.ssr_data.rgb) + cl.radiance, 1.0);
+
+# ifdef USE_SSS
+# ifdef USE_SSS_ALBEDO
+ outcol.rgb += cl.sss_data.rgb * cl.sss_albedo;
+# else
+ outcol.rgb += cl.sss_data.rgb;
+# endif
+# endif
}
#endif /* VOLUMETRICS */
diff --git a/source/blender/gpu/shaders/gpu_shader_point_uniform_color_aa_frag.glsl b/source/blender/gpu/shaders/gpu_shader_point_uniform_color_aa_frag.glsl
index fef81cf58fe..a8e9c620535 100644
--- a/source/blender/gpu/shaders/gpu_shader_point_uniform_color_aa_frag.glsl
+++ b/source/blender/gpu/shaders/gpu_shader_point_uniform_color_aa_frag.glsl
@@ -4,21 +4,22 @@ uniform vec4 color;
in vec2 radii;
out vec4 fragColor;
-void main() {
- float dist = length(gl_PointCoord - vec2(0.5));
+void main()
+{
+ float dist = length(gl_PointCoord - vec2(0.5));
-// transparent outside of point
-// --- 0 ---
-// smooth transition
-// --- 1 ---
-// pure point color
-// ...
-// dist = 0 at center of point
+ // transparent outside of point
+ // --- 0 ---
+ // smooth transition
+ // --- 1 ---
+ // pure point color
+ // ...
+ // dist = 0 at center of point
- fragColor.rgb = color.rgb;
- fragColor.a = mix(color.a, 0.0, smoothstep(radii[1], radii[0], dist));
+ fragColor.rgb = color.rgb;
+ fragColor.a = mix(color.a, 0.0, smoothstep(radii[1], radii[0], dist));
- if (fragColor.a == 0.0) {
- discard;
- }
+ if (fragColor.a == 0.0) {
+ discard;
+ }
}
diff --git a/source/blender/gpu/shaders/gpu_shader_point_uniform_color_frag.glsl b/source/blender/gpu/shaders/gpu_shader_point_uniform_color_frag.glsl
index 852c76fcb26..c31cf852f6a 100644
--- a/source/blender/gpu/shaders/gpu_shader_point_uniform_color_frag.glsl
+++ b/source/blender/gpu/shaders/gpu_shader_point_uniform_color_frag.glsl
@@ -5,13 +5,13 @@ out vec4 fragColor;
void main()
{
- vec2 centered = gl_PointCoord - vec2(0.5);
- float dist_squared = dot(centered, centered);
- const float rad_squared = 0.25;
+ vec2 centered = gl_PointCoord - vec2(0.5);
+ float dist_squared = dot(centered, centered);
+ const float rad_squared = 0.25;
- // round point with jaggy edges
- if (dist_squared > rad_squared)
- discard;
+ // round point with jaggy edges
+ if (dist_squared > rad_squared)
+ discard;
- fragColor = color;
+ fragColor = color;
}
diff --git a/source/blender/gpu/shaders/gpu_shader_point_uniform_color_outline_aa_frag.glsl b/source/blender/gpu/shaders/gpu_shader_point_uniform_color_outline_aa_frag.glsl
index eae5ee633ae..1c1301dd818 100644
--- a/source/blender/gpu/shaders/gpu_shader_point_uniform_color_outline_aa_frag.glsl
+++ b/source/blender/gpu/shaders/gpu_shader_point_uniform_color_outline_aa_frag.glsl
@@ -5,32 +5,33 @@ uniform vec4 outlineColor;
in vec4 radii;
out vec4 fragColor;
-void main() {
- float dist = length(gl_PointCoord - vec2(0.5));
+void main()
+{
+ float dist = length(gl_PointCoord - vec2(0.5));
-// transparent outside of point
-// --- 0 ---
-// smooth transition
-// --- 1 ---
-// pure outline color
-// --- 2 ---
-// smooth transition
-// --- 3 ---
-// pure point color
-// ...
-// dist = 0 at center of point
+ // transparent outside of point
+ // --- 0 ---
+ // smooth transition
+ // --- 1 ---
+ // pure outline color
+ // --- 2 ---
+ // smooth transition
+ // --- 3 ---
+ // pure point color
+ // ...
+ // dist = 0 at center of point
- float midStroke = 0.5 * (radii[1] + radii[2]);
+ float midStroke = 0.5 * (radii[1] + radii[2]);
- if (dist > midStroke) {
- fragColor.rgb = outlineColor.rgb;
- fragColor.a = mix(outlineColor.a, 0.0, smoothstep(radii[1], radii[0], dist));
- }
- else {
- fragColor = mix(color, outlineColor, smoothstep(radii[3], radii[2], dist));
- }
+ if (dist > midStroke) {
+ fragColor.rgb = outlineColor.rgb;
+ fragColor.a = mix(outlineColor.a, 0.0, smoothstep(radii[1], radii[0], dist));
+ }
+ else {
+ fragColor = mix(color, outlineColor, smoothstep(radii[3], radii[2], dist));
+ }
- if (fragColor.a == 0.0) {
- discard;
- }
+ if (fragColor.a == 0.0) {
+ discard;
+ }
}
diff --git a/source/blender/gpu/shaders/gpu_shader_point_varying_color_frag.glsl b/source/blender/gpu/shaders/gpu_shader_point_varying_color_frag.glsl
index 2d2724bb686..ba8321aa295 100644
--- a/source/blender/gpu/shaders/gpu_shader_point_varying_color_frag.glsl
+++ b/source/blender/gpu/shaders/gpu_shader_point_varying_color_frag.glsl
@@ -4,13 +4,13 @@ out vec4 fragColor;
void main()
{
- vec2 centered = gl_PointCoord - vec2(0.5);
- float dist_squared = dot(centered, centered);
- const float rad_squared = 0.25;
+ vec2 centered = gl_PointCoord - vec2(0.5);
+ float dist_squared = dot(centered, centered);
+ const float rad_squared = 0.25;
- // round point with jaggy edges
- if (dist_squared > rad_squared)
- discard;
+ // round point with jaggy edges
+ if (dist_squared > rad_squared)
+ discard;
- fragColor = finalColor;
+ fragColor = finalColor;
}
diff --git a/source/blender/gpu/shaders/gpu_shader_point_varying_color_outline_aa_frag.glsl b/source/blender/gpu/shaders/gpu_shader_point_varying_color_outline_aa_frag.glsl
index 9b7d4bfc6d6..8ddf460a3ac 100644
--- a/source/blender/gpu/shaders/gpu_shader_point_varying_color_outline_aa_frag.glsl
+++ b/source/blender/gpu/shaders/gpu_shader_point_varying_color_outline_aa_frag.glsl
@@ -5,27 +5,28 @@ in vec4 radii;
in vec4 fillColor;
out vec4 fragColor;
-void main() {
- float dist = length(gl_PointCoord - vec2(0.5));
+void main()
+{
+ float dist = length(gl_PointCoord - vec2(0.5));
-// transparent outside of point
-// --- 0 ---
-// smooth transition
-// --- 1 ---
-// pure outline color
-// --- 2 ---
-// smooth transition
-// --- 3 ---
-// pure fill color
-// ...
-// dist = 0 at center of point
+ // transparent outside of point
+ // --- 0 ---
+ // smooth transition
+ // --- 1 ---
+ // pure outline color
+ // --- 2 ---
+ // smooth transition
+ // --- 3 ---
+ // pure fill color
+ // ...
+ // dist = 0 at center of point
- float midStroke = 0.5 * (radii[1] + radii[2]);
+ float midStroke = 0.5 * (radii[1] + radii[2]);
- if (dist > midStroke) {
- fragColor.rgb = outlineColor.rgb;
- fragColor.a = mix(outlineColor.a, 0.0, smoothstep(radii[1], radii[0], dist));
- }
- else
- fragColor = mix(fillColor, outlineColor, smoothstep(radii[3], radii[2], dist));
+ if (dist > midStroke) {
+ fragColor.rgb = outlineColor.rgb;
+ fragColor.a = mix(outlineColor.a, 0.0, smoothstep(radii[1], radii[0], dist));
+ }
+ else
+ fragColor = mix(fillColor, outlineColor, smoothstep(radii[3], radii[2], dist));
}
diff --git a/source/blender/gpu/shaders/gpu_shader_point_varying_color_varying_outline_aa_frag.glsl b/source/blender/gpu/shaders/gpu_shader_point_varying_color_varying_outline_aa_frag.glsl
index e1f8203cb26..9c5690bf373 100644
--- a/source/blender/gpu/shaders/gpu_shader_point_varying_color_varying_outline_aa_frag.glsl
+++ b/source/blender/gpu/shaders/gpu_shader_point_varying_color_varying_outline_aa_frag.glsl
@@ -4,27 +4,28 @@ in vec4 fillColor;
in vec4 outlineColor;
out vec4 fragColor;
-void main() {
- float dist = length(gl_PointCoord - vec2(0.5));
+void main()
+{
+ float dist = length(gl_PointCoord - vec2(0.5));
-// transparent outside of point
-// --- 0 ---
-// smooth transition
-// --- 1 ---
-// pure outline color
-// --- 2 ---
-// smooth transition
-// --- 3 ---
-// pure fill color
-// ...
-// dist = 0 at center of point
+ // transparent outside of point
+ // --- 0 ---
+ // smooth transition
+ // --- 1 ---
+ // pure outline color
+ // --- 2 ---
+ // smooth transition
+ // --- 3 ---
+ // pure fill color
+ // ...
+ // dist = 0 at center of point
- float midStroke = 0.5 * (radii[1] + radii[2]);
+ float midStroke = 0.5 * (radii[1] + radii[2]);
- if (dist > midStroke) {
- fragColor.rgb = outlineColor.rgb;
- fragColor.a = mix(outlineColor.a, 0.0, smoothstep(radii[1], radii[0], dist));
- }
- else
- fragColor = mix(fillColor, outlineColor, smoothstep(radii[3], radii[2], dist));
+ if (dist > midStroke) {
+ fragColor.rgb = outlineColor.rgb;
+ fragColor.a = mix(outlineColor.a, 0.0, smoothstep(radii[1], radii[0], dist));
+ }
+ else
+ fragColor = mix(fillColor, outlineColor, smoothstep(radii[3], radii[2], dist));
}
diff --git a/source/blender/gpu/shaders/gpu_shader_selection_id_frag.glsl b/source/blender/gpu/shaders/gpu_shader_selection_id_frag.glsl
index 45ba6cf4d08..1f22b9cb0b4 100644
--- a/source/blender/gpu/shaders/gpu_shader_selection_id_frag.glsl
+++ b/source/blender/gpu/shaders/gpu_shader_selection_id_frag.glsl
@@ -9,5 +9,5 @@ out uint fragColor;
void main()
{
- fragColor = id;
+ fragColor = id;
}
diff --git a/source/blender/gpu/shaders/gpu_shader_simple_lighting_frag.glsl b/source/blender/gpu/shaders/gpu_shader_simple_lighting_frag.glsl
index d65768eff4d..6bce517fee3 100644
--- a/source/blender/gpu/shaders/gpu_shader_simple_lighting_frag.glsl
+++ b/source/blender/gpu/shaders/gpu_shader_simple_lighting_frag.glsl
@@ -13,6 +13,6 @@ out vec4 fragColor;
void main()
{
- fragColor = color;
- fragColor.xyz *= clamp(dot(normalize(normal), light), 0.0, 1.0);
+ fragColor = color;
+ fragColor.xyz *= clamp(dot(normalize(normal), light), 0.0, 1.0);
}
diff --git a/source/blender/gpu/shaders/gpu_shader_simple_lighting_smooth_color_alpha_frag.glsl b/source/blender/gpu/shaders/gpu_shader_simple_lighting_smooth_color_alpha_frag.glsl
index 6b13f408c84..2ed99be2bcf 100644
--- a/source/blender/gpu/shaders/gpu_shader_simple_lighting_smooth_color_alpha_frag.glsl
+++ b/source/blender/gpu/shaders/gpu_shader_simple_lighting_smooth_color_alpha_frag.glsl
@@ -9,6 +9,6 @@ out vec4 fragColor;
void main()
{
- fragColor = finalColor * (global + (1.0 - global) * max(0.0, dot(normalize(normal), light)));
- fragColor.a = alpha;
+ fragColor = finalColor * (global + (1.0 - global) * max(0.0, dot(normalize(normal), light)));
+ fragColor.a = alpha;
}
diff --git a/source/blender/gpu/shaders/gpu_shader_simple_lighting_smooth_color_frag.glsl b/source/blender/gpu/shaders/gpu_shader_simple_lighting_smooth_color_frag.glsl
index 58c5f292647..738b0d84e51 100644
--- a/source/blender/gpu/shaders/gpu_shader_simple_lighting_smooth_color_frag.glsl
+++ b/source/blender/gpu/shaders/gpu_shader_simple_lighting_smooth_color_frag.glsl
@@ -12,5 +12,5 @@ out vec4 fragColor;
void main()
{
- fragColor = finalColor * max(0.0, dot(normalize(normal), light));
+ fragColor = finalColor * max(0.0, dot(normalize(normal), light));
}
diff --git a/source/blender/gpu/shaders/gpu_shader_text_frag.glsl b/source/blender/gpu/shaders/gpu_shader_text_frag.glsl
index fbfa4cfcc9d..4a6ce4fd3ac 100644
--- a/source/blender/gpu/shaders/gpu_shader_text_frag.glsl
+++ b/source/blender/gpu/shaders/gpu_shader_text_frag.glsl
@@ -7,68 +7,76 @@ out vec4 fragColor;
uniform sampler2D glyph;
const vec2 offsets4[4] = vec2[4](
- vec2(-0.5, 0.5), vec2( 0.5, 0.5),
- vec2(-0.5, -0.5), vec2(-0.5, -0.5)
-);
+ vec2(-0.5, 0.5), vec2(0.5, 0.5), vec2(-0.5, -0.5), vec2(-0.5, -0.5));
-const vec2 offsets16[16] = vec2[16](
- vec2(-1.5, 1.5), vec2(-0.5, 1.5), vec2( 0.5, 1.5), vec2( 1.5, 1.5),
- vec2(-1.5, 0.5), vec2(-0.5, 0.5), vec2( 0.5, 0.5), vec2( 1.5, 0.5),
- vec2(-1.5, -0.5), vec2(-0.5, -0.5), vec2( 0.5, -0.5), vec2( 1.5, -0.5),
- vec2(-1.5, -1.5), vec2(-0.5, -1.5), vec2( 0.5, -1.5), vec2( 1.5, -1.5)
-);
+const vec2 offsets16[16] = vec2[16](vec2(-1.5, 1.5),
+ vec2(-0.5, 1.5),
+ vec2(0.5, 1.5),
+ vec2(1.5, 1.5),
+ vec2(-1.5, 0.5),
+ vec2(-0.5, 0.5),
+ vec2(0.5, 0.5),
+ vec2(1.5, 0.5),
+ vec2(-1.5, -0.5),
+ vec2(-0.5, -0.5),
+ vec2(0.5, -0.5),
+ vec2(1.5, -0.5),
+ vec2(-1.5, -1.5),
+ vec2(-0.5, -1.5),
+ vec2(0.5, -1.5),
+ vec2(1.5, -1.5));
#define sample_glyph_offset(texco, texel, ofs) texture(glyph, texco + ofs * texel).r
void main()
{
- // input color replaces texture color
- fragColor.rgb = color_flat.rgb;
+ // input color replaces texture color
+ fragColor.rgb = color_flat.rgb;
- vec2 texel = 1.0 / vec2(textureSize(glyph, 0));
- vec2 texco = mix(abs(texCoord_rect.xy), abs(texCoord_rect.zw), texCoord_interp);
+ vec2 texel = 1.0 / vec2(textureSize(glyph, 0));
+ vec2 texco = mix(abs(texCoord_rect.xy), abs(texCoord_rect.zw), texCoord_interp);
- // modulate input alpha & texture alpha
- if (texCoord_rect.x > 0) {
- fragColor.a = texture(glyph, texco).r;
- }
- else {
- fragColor.a = 0.0;
+ // modulate input alpha & texture alpha
+ if (texCoord_rect.x > 0) {
+ fragColor.a = texture(glyph, texco).r;
+ }
+ else {
+ fragColor.a = 0.0;
- if (texCoord_rect.w > 0) {
- /* 3x3 blur */
- /* Manual unroll for perf. (stupid glsl compiler) */
- fragColor.a += sample_glyph_offset(texco, texel, offsets4[0]);
- fragColor.a += sample_glyph_offset(texco, texel, offsets4[1]);
- fragColor.a += sample_glyph_offset(texco, texel, offsets4[2]);
- fragColor.a += sample_glyph_offset(texco, texel, offsets4[3]);
- fragColor.a *= (1.0 / 4.0);
- }
- else {
- /* 5x5 blur */
- /* Manual unroll for perf. (stupid glsl compiler) */
- fragColor.a += sample_glyph_offset(texco, texel, offsets16[ 0]);
- fragColor.a += sample_glyph_offset(texco, texel, offsets16[ 1]);
- fragColor.a += sample_glyph_offset(texco, texel, offsets16[ 2]);
- fragColor.a += sample_glyph_offset(texco, texel, offsets16[ 3]);
+ if (texCoord_rect.w > 0) {
+ /* 3x3 blur */
+ /* Manual unroll for perf. (stupid glsl compiler) */
+ fragColor.a += sample_glyph_offset(texco, texel, offsets4[0]);
+ fragColor.a += sample_glyph_offset(texco, texel, offsets4[1]);
+ fragColor.a += sample_glyph_offset(texco, texel, offsets4[2]);
+ fragColor.a += sample_glyph_offset(texco, texel, offsets4[3]);
+ fragColor.a *= (1.0 / 4.0);
+ }
+ else {
+ /* 5x5 blur */
+ /* Manual unroll for perf. (stupid glsl compiler) */
+ fragColor.a += sample_glyph_offset(texco, texel, offsets16[0]);
+ fragColor.a += sample_glyph_offset(texco, texel, offsets16[1]);
+ fragColor.a += sample_glyph_offset(texco, texel, offsets16[2]);
+ fragColor.a += sample_glyph_offset(texco, texel, offsets16[3]);
- fragColor.a += sample_glyph_offset(texco, texel, offsets16[ 4]);
- fragColor.a += sample_glyph_offset(texco, texel, offsets16[ 5]) * 2.0;
- fragColor.a += sample_glyph_offset(texco, texel, offsets16[ 6]) * 2.0;
- fragColor.a += sample_glyph_offset(texco, texel, offsets16[ 7]);
+ fragColor.a += sample_glyph_offset(texco, texel, offsets16[4]);
+ fragColor.a += sample_glyph_offset(texco, texel, offsets16[5]) * 2.0;
+ fragColor.a += sample_glyph_offset(texco, texel, offsets16[6]) * 2.0;
+ fragColor.a += sample_glyph_offset(texco, texel, offsets16[7]);
- fragColor.a += sample_glyph_offset(texco, texel, offsets16[ 8]);
- fragColor.a += sample_glyph_offset(texco, texel, offsets16[ 9]) * 2.0;
- fragColor.a += sample_glyph_offset(texco, texel, offsets16[10]) * 2.0;
- fragColor.a += sample_glyph_offset(texco, texel, offsets16[11]);
+ fragColor.a += sample_glyph_offset(texco, texel, offsets16[8]);
+ fragColor.a += sample_glyph_offset(texco, texel, offsets16[9]) * 2.0;
+ fragColor.a += sample_glyph_offset(texco, texel, offsets16[10]) * 2.0;
+ fragColor.a += sample_glyph_offset(texco, texel, offsets16[11]);
- fragColor.a += sample_glyph_offset(texco, texel, offsets16[12]);
- fragColor.a += sample_glyph_offset(texco, texel, offsets16[13]);
- fragColor.a += sample_glyph_offset(texco, texel, offsets16[14]);
- fragColor.a += sample_glyph_offset(texco, texel, offsets16[15]);
- fragColor.a *= (1.0 / 20.0);
- }
- }
+ fragColor.a += sample_glyph_offset(texco, texel, offsets16[12]);
+ fragColor.a += sample_glyph_offset(texco, texel, offsets16[13]);
+ fragColor.a += sample_glyph_offset(texco, texel, offsets16[14]);
+ fragColor.a += sample_glyph_offset(texco, texel, offsets16[15]);
+ fragColor.a *= (1.0 / 20.0);
+ }
+ }
- fragColor.a *= color_flat.a;
+ fragColor.a *= color_flat.a;
}
diff --git a/source/blender/gpu/shaders/gpu_shader_text_geom.glsl b/source/blender/gpu/shaders/gpu_shader_text_geom.glsl
index 0acd2106f7a..12ccbf00130 100644
--- a/source/blender/gpu/shaders/gpu_shader_text_geom.glsl
+++ b/source/blender/gpu/shaders/gpu_shader_text_geom.glsl
@@ -14,24 +14,24 @@ noperspective out vec2 texCoord_interp;
void main()
{
- color_flat = color[0];
- texCoord_rect = tex_rect[0];
+ color_flat = color[0];
+ texCoord_rect = tex_rect[0];
- gl_Position = (ModelViewProjectionMatrix * vec4(pos_rect[0].xy, 0.0, 1.0));
- texCoord_interp = vec2(0.0, 0.0);
- EmitVertex();
+ gl_Position = (ModelViewProjectionMatrix * vec4(pos_rect[0].xy, 0.0, 1.0));
+ texCoord_interp = vec2(0.0, 0.0);
+ EmitVertex();
- gl_Position = (ModelViewProjectionMatrix * vec4(pos_rect[0].zy, 0.0, 1.0));
- texCoord_interp = vec2(1.0, 0.0);
- EmitVertex();
+ gl_Position = (ModelViewProjectionMatrix * vec4(pos_rect[0].zy, 0.0, 1.0));
+ texCoord_interp = vec2(1.0, 0.0);
+ EmitVertex();
- gl_Position = (ModelViewProjectionMatrix * vec4(pos_rect[0].xw, 0.0, 1.0));
- texCoord_interp = vec2(0.0, 1.0);
- EmitVertex();
+ gl_Position = (ModelViewProjectionMatrix * vec4(pos_rect[0].xw, 0.0, 1.0));
+ texCoord_interp = vec2(0.0, 1.0);
+ EmitVertex();
- gl_Position = (ModelViewProjectionMatrix * vec4(pos_rect[0].zw, 0.0, 1.0));
- texCoord_interp = vec2(1.0, 1.0);
- EmitVertex();
+ gl_Position = (ModelViewProjectionMatrix * vec4(pos_rect[0].zw, 0.0, 1.0));
+ texCoord_interp = vec2(1.0, 1.0);
+ EmitVertex();
- EndPrimitive();
+ EndPrimitive();
}
diff --git a/source/blender/gpu/shaders/gpu_shader_text_simple_geom.glsl b/source/blender/gpu/shaders/gpu_shader_text_simple_geom.glsl
index 8903fd1df57..7a8a872f919 100644
--- a/source/blender/gpu/shaders/gpu_shader_text_simple_geom.glsl
+++ b/source/blender/gpu/shaders/gpu_shader_text_simple_geom.glsl
@@ -12,25 +12,25 @@ noperspective out vec2 texCoord_interp;
void main()
{
- color_flat = color[0];
- texCoord_rect = tex_rect[0];
- gl_Position.zw = vec2(0.0, 1.0);
+ color_flat = color[0];
+ texCoord_rect = tex_rect[0];
+ gl_Position.zw = vec2(0.0, 1.0);
- gl_Position.xy = pos_rect[0].xy;
- texCoord_interp = vec2(0.0, 0.0);
- EmitVertex();
+ gl_Position.xy = pos_rect[0].xy;
+ texCoord_interp = vec2(0.0, 0.0);
+ EmitVertex();
- gl_Position.xy = pos_rect[0].zy;
- texCoord_interp = vec2(1.0, 0.0);
- EmitVertex();
+ gl_Position.xy = pos_rect[0].zy;
+ texCoord_interp = vec2(1.0, 0.0);
+ EmitVertex();
- gl_Position.xy = pos_rect[0].xw;
- texCoord_interp = vec2(0.0, 1.0);
- EmitVertex();
+ gl_Position.xy = pos_rect[0].xw;
+ texCoord_interp = vec2(0.0, 1.0);
+ EmitVertex();
- gl_Position.xy = pos_rect[0].zw;
- texCoord_interp = vec2(1.0, 1.0);
- EmitVertex();
+ gl_Position.xy = pos_rect[0].zw;
+ texCoord_interp = vec2(1.0, 1.0);
+ EmitVertex();
- EndPrimitive();
+ EndPrimitive();
}
diff --git a/source/blender/gpu/shaders/gpu_shader_text_simple_vert.glsl b/source/blender/gpu/shaders/gpu_shader_text_simple_vert.glsl
index 4a2cde71e07..a8a79ffe6c9 100644
--- a/source/blender/gpu/shaders/gpu_shader_text_simple_vert.glsl
+++ b/source/blender/gpu/shaders/gpu_shader_text_simple_vert.glsl
@@ -13,10 +13,10 @@ out vec4 color;
void main()
{
- /* Manual mat4*vec2 */
- pos_rect = ModelViewProjectionMatrix[0].xyxy * pos.xxzz;
- pos_rect += ModelViewProjectionMatrix[1].xyxy * pos.yyww;
- pos_rect += ModelViewProjectionMatrix[3].xyxy;
- tex_rect = tex;
- color = col;
+ /* Manual mat4*vec2 */
+ pos_rect = ModelViewProjectionMatrix[0].xyxy * pos.xxzz;
+ pos_rect += ModelViewProjectionMatrix[1].xyxy * pos.yyww;
+ pos_rect += ModelViewProjectionMatrix[3].xyxy;
+ tex_rect = tex;
+ color = col;
}
diff --git a/source/blender/gpu/shaders/gpu_shader_text_vert.glsl b/source/blender/gpu/shaders/gpu_shader_text_vert.glsl
index 338156f5b68..d8e4b2bc986 100644
--- a/source/blender/gpu/shaders/gpu_shader_text_vert.glsl
+++ b/source/blender/gpu/shaders/gpu_shader_text_vert.glsl
@@ -11,7 +11,7 @@ out vec4 color;
void main()
{
- pos_rect = pos;
- tex_rect = tex;
- color = col;
+ pos_rect = pos;
+ tex_rect = tex;
+ color = col;
}
diff --git a/source/blender/gpu/shaders/gpu_shader_uniform_color_frag.glsl b/source/blender/gpu/shaders/gpu_shader_uniform_color_frag.glsl
index f6f0f5b83ec..cfa82572e87 100644
--- a/source/blender/gpu/shaders/gpu_shader_uniform_color_frag.glsl
+++ b/source/blender/gpu/shaders/gpu_shader_uniform_color_frag.glsl
@@ -10,16 +10,15 @@ out vec4 fragColor;
void main()
{
#if defined(USE_COLOR_U32)
- fragColor = vec4(
- ((color ) & uint(0xFF)) * (1.0f / 255.0f),
- ((color >> 8) & uint(0xFF)) * (1.0f / 255.0f),
- ((color >> 16) & uint(0xFF)) * (1.0f / 255.0f),
- ((color >> 24) ) * (1.0f / 255.0f));
+ fragColor = vec4(((color)&uint(0xFF)) * (1.0f / 255.0f),
+ ((color >> 8) & uint(0xFF)) * (1.0f / 255.0f),
+ ((color >> 16) & uint(0xFF)) * (1.0f / 255.0f),
+ ((color >> 24)) * (1.0f / 255.0f));
#else
- fragColor = color;
+ fragColor = color;
#endif
#if defined(USE_BACKGROUND)
- gl_FragDepth = 1.0;
+ gl_FragDepth = 1.0;
#endif
}