Differential D16452 Diff 58434 source/blender/draw/engines/overlay/shaders/overlay_edit_uv_edges_vert_no_geom.glsl
Changeset View
Changeset View
Standalone View
Standalone View
source/blender/draw/engines/overlay/shaders/overlay_edit_uv_edges_vert_no_geom.glsl
| Show All 35 Lines | else { | ||||
| DISCARD_VERTEX | DISCARD_VERTEX | ||||
| } | } | ||||
| /* Read vertex attributes for line prims. */ | /* Read vertex attributes for line prims. */ | ||||
| vec2 root_au0 = vertex_fetch_attribute(base_vertex_id, au, vec2); | vec2 root_au0 = vertex_fetch_attribute(base_vertex_id, au, vec2); | ||||
| vec2 root_au1 = vertex_fetch_attribute(base_vertex_id + 1, au, vec2); | vec2 root_au1 = vertex_fetch_attribute(base_vertex_id + 1, au, vec2); | ||||
| int root_flag0 = vertex_fetch_attribute(base_vertex_id, flag, int); | int root_flag0 = vertex_fetch_attribute(base_vertex_id, flag, int); | ||||
| int root_flag1 = vertex_fetch_attribute(base_vertex_id + 1, flag, int); | int root_flag1 = vertex_fetch_attribute(base_vertex_id + 1, flag, int); | ||||
| /* Vertex shader per input vertex. */ | /* Vertex shader per input vertex. */ | ||||
fclem: Do not use `gl_` prefix. These are reserved and might cause compilation issue on some… | |||||
| vec3 world_pos0 = point_object_to_world(vec3(root_au0, 0.0)); | vec3 world_pos0 = point_object_to_world(vec3(root_au0, 0.0)); | ||||
| vec3 world_pos1 = point_object_to_world(vec3(root_au1, 0.0)); | vec3 world_pos1 = point_object_to_world(vec3(root_au1, 0.0)); | ||||
| vec4 gl_pos0 = point_world_to_ndc(world_pos0); | vec4 ndc_pos0 = point_world_to_ndc(world_pos0); | ||||
| vec4 gl_pos1 = point_world_to_ndc(world_pos1); | vec4 ndc_pos1 = point_world_to_ndc(world_pos1); | ||||
| /* Snap vertices to the pixel grid to reduce artifacts. */ | /* Snap vertices to the pixel grid to reduce artifacts. */ | ||||
| vec2 half_viewport_res = sizeViewport * 0.5; | vec2 half_viewport_res = sizeViewport * 0.5; | ||||
| vec2 half_pixel_offset = sizeViewportInv * 0.5; | vec2 half_pixel_offset = sizeViewportInv * 0.5; | ||||
| gl_pos0.xy = floor(gl_pos0.xy * half_viewport_res) / half_viewport_res + half_pixel_offset; | ndc_pos0.xy = floor(ndc_pos0.xy * half_viewport_res) / half_viewport_res + half_pixel_offset; | ||||
| gl_pos1.xy = floor(gl_pos1.xy * half_viewport_res) / half_viewport_res + half_pixel_offset; | ndc_pos1.xy = floor(ndc_pos1.xy * half_viewport_res) / half_viewport_res + half_pixel_offset; | ||||
| #ifdef USE_EDGE_SELECT | #ifdef USE_EDGE_SELECT | ||||
| bool is_select0 = (root_flag0 & EDGE_UV_SELECT) != 0; | bool is_select0 = (root_flag0 & EDGE_UV_SELECT) != 0; | ||||
| bool is_select1 = (root_flag1 & EDGE_UV_SELECT) != 0; | bool is_select1 = (root_flag1 & EDGE_UV_SELECT) != 0; | ||||
| #else | #else | ||||
| bool is_select0 = (root_flag0 & VERT_UV_SELECT) != 0; | bool is_select0 = (root_flag0 & VERT_UV_SELECT) != 0; | ||||
| bool is_select1 = (root_flag1 & VERT_UV_SELECT) != 0; | bool is_select1 = (root_flag1 & VERT_UV_SELECT) != 0; | ||||
| #endif | #endif | ||||
| float selectionFac0 = is_select0 ? 1.0 : 0.0; // out float selectionFac; | float selectionFac0 = is_select0 ? 1.0 : 0.0; // out float selectionFac; | ||||
| float selectionFac1 = is_select1 ? 1.0 : 0.0; // out float selectionFac; | float selectionFac1 = is_select1 ? 1.0 : 0.0; // out float selectionFac; | ||||
| #ifdef USE_EDGE_SELECT | #ifdef USE_EDGE_SELECT | ||||
| /* No blending with edge selection. */ | /* No blending with edge selection. */ | ||||
| selectionFac1 = selectionFac0; | selectionFac1 = selectionFac0; | ||||
| #endif | #endif | ||||
| /* Move selected edges to the top | /* Move selected edges to the top | ||||
| * Vertices are between 0.0 and 0.2, Edges between 0.2 and 0.4 | * Vertices are between 0.0 and 0.2, Edges between 0.2 and 0.4 | ||||
| * actual pixels are at 0.75, 1.0 is used for the background. */ | * actual pixels are at 0.75, 1.0 is used for the background. */ | ||||
| float depth0 = is_select0 ? 0.25 : 0.35; | float depth0 = is_select0 ? 0.25 : 0.35; | ||||
| float depth1 = is_select1 ? 0.25 : 0.35; | float depth1 = is_select1 ? 0.25 : 0.35; | ||||
| gl_pos0.z = depth0; | ndc_pos0.z = depth0; | ||||
| gl_pos1.z = depth1; | ndc_pos1.z = depth1; | ||||
| /* Avoid precision loss. */ | /* Avoid precision loss. */ | ||||
| vec2 stipplePos0 = 500.0 + 500.0 * (gl_pos0.xy / gl_pos0.w); | vec2 stipplePos0 = 500.0 + 500.0 * (ndc_pos0.xy / ndc_pos0.w); | ||||
| vec2 stipplePos1 = 500.0 + 500.0 * (gl_pos1.xy / gl_pos1.w); | vec2 stipplePos1 = 500.0 + 500.0 * (ndc_pos1.xy / ndc_pos1.w); | ||||
| vec2 stippleStart0 = stipplePos0; | vec2 stippleStart0 = stipplePos0; | ||||
| vec2 stippleStart1 = stipplePos1; | vec2 stippleStart1 = stipplePos1; | ||||
| /* Geometry shader equivalent calculations. */ | /* Geometry shader equivalent calculations. */ | ||||
| vec2 ss_pos[2]; | vec2 ss_pos[2]; | ||||
| ss_pos[0] = gl_pos0.xy / gl_pos0.w; | ss_pos[0] = ndc_pos0.xy / ndc_pos0.w; | ||||
| ss_pos[1] = gl_pos1.xy / gl_pos1.w; | ss_pos[1] = ndc_pos1.xy / ndc_pos1.w; | ||||
| float half_size = sizeEdge; | float half_size = sizeEdge; | ||||
| /* Enlarge edge for outline drawing. */ | /* Enlarge edge for outline drawing. */ | ||||
| /* Factor of 3.0 out of nowhere! Seems to fix issues with float imprecision. */ | /* Factor of 3.0 out of nowhere! Seems to fix issues with float imprecision. */ | ||||
| half_size += (lineStyle == OVERLAY_UV_LINE_STYLE_OUTLINE) ? | half_size += (lineStyle == OVERLAY_UV_LINE_STYLE_OUTLINE) ? | ||||
| max(sizeEdge * (doSmoothWire ? 1.0 : 3.0), 1.0) : | max(sizeEdge * (doSmoothWire ? 1.0 : 3.0), 1.0) : | ||||
| 0.0; | 0.0; | ||||
| /* Add 1 px for AA */ | /* Add 1 px for AA */ | ||||
| if (doSmoothWire) { | if (doSmoothWire) { | ||||
| half_size += 0.5; | half_size += 0.5; | ||||
| } | } | ||||
| vec2 line = ss_pos[0] - ss_pos[1]; | vec2 line = ss_pos[0] - ss_pos[1]; | ||||
| vec2 line_dir = normalize(line); | vec2 line_dir = normalize(line); | ||||
| vec2 line_perp = vec2(-line_dir.y, line_dir.x); | vec2 line_perp = vec2(-line_dir.y, line_dir.x); | ||||
| vec2 edge_ofs = line_perp * sizeViewportInv * ceil(half_size); | vec2 edge_ofs = line_perp * sizeViewportInv * ceil(half_size); | ||||
| switch (quad_vertex_id) { | switch (quad_vertex_id) { | ||||
| case 1: /* vertex A */ | case 1: /* vertex A */ | ||||
| case 3: | case 3: | ||||
| do_vertex(gl_pos1, selectionFac1, stippleStart1, stipplePos1, half_size, edge_ofs.xy); | do_vertex(ndc_pos1, selectionFac1, stippleStart1, stipplePos1, half_size, edge_ofs.xy); | ||||
| break; | break; | ||||
| case 0: /* B */ | case 0: /* B */ | ||||
| do_vertex(gl_pos0, selectionFac0, stippleStart0, stipplePos0, half_size, edge_ofs.xy); | do_vertex(ndc_pos0, selectionFac0, stippleStart0, stipplePos0, half_size, edge_ofs.xy); | ||||
| break; | break; | ||||
| case 2: /* C */ | case 2: /* C */ | ||||
| case 4: | case 4: | ||||
| do_vertex(gl_pos0, selectionFac0, stippleStart0, stipplePos0, -half_size, -edge_ofs.xy); | do_vertex(ndc_pos0, selectionFac0, stippleStart0, stipplePos0, -half_size, -edge_ofs.xy); | ||||
| break; | break; | ||||
| case 5: /* D */ | case 5: /* D */ | ||||
| do_vertex(gl_pos1, selectionFac1, stippleStart1, stipplePos1, -half_size, -edge_ofs.xy); | do_vertex(ndc_pos1, selectionFac1, stippleStart1, stipplePos1, -half_size, -edge_ofs.xy); | ||||
| break; | break; | ||||
| } | } | ||||
| } | } | ||||
Do not use gl_ prefix. These are reserved and might cause compilation issue on some implementation. Use ndc_pos instead.