Refactor: GLSL: Cleanup Clip Space vs. NDC Space naming #105423

Closed
Prakhar-Singh-Chouhan wants to merge 15 commits from (deleted):fix#105070 into main

When changing the target branch, be careful to rebase the branch in your fork to match. See documentation.
75 changed files with 146 additions and 146 deletions

View File

@ -21,7 +21,7 @@ void main()
thickness,
thick_time);
gl_Position = point_world_to_ndc(world_pos);
gl_Position = point_world_to_homogenous(world_pos);
view_clipping_distances(world_pos);
}

View File

@ -11,7 +11,7 @@ void main()
float world_radius;
pointcloud_get_pos_nor_radius(world_pos, world_nor, world_radius);
gl_Position = point_world_to_ndc(world_pos);
gl_Position = point_world_to_homogenous(world_pos);
#ifdef CONSERVATIVE_RASTER
/* Avoid expense of geometry shader by ensuring rastered pointcloud primitive

View File

@ -8,7 +8,7 @@ void main()
vec3 world_pos = point_object_to_world(pos);
gl_Position = point_world_to_ndc(world_pos);
gl_Position = point_world_to_homogenous(world_pos);
view_clipping_distances(world_pos);
}

View File

@ -37,7 +37,7 @@ void main()
vec3 world_pos = point_object_to_world(pos);
#endif
gl_Position = point_world_to_ndc(world_pos);
gl_Position = point_world_to_homogenous(world_pos);
/* Used for planar reflections */
gl_ClipDistance[0] = dot(vec4(world_pos, 1.0), planarClipPlane);

View File

@ -52,5 +52,5 @@ void main()
interp.P += nodetree_displacement();
gl_Position = point_world_to_ndc(interp.P);
gl_Position = point_world_to_homogenous(interp.P);
}

View File

@ -32,5 +32,5 @@ void main()
interp.P += nodetree_displacement();
gl_Position = point_world_to_ndc(interp.P);
gl_Position = point_world_to_homogenous(interp.P);
}

View File

@ -90,9 +90,9 @@ float shadow_slope_bias_get(vec2 atlas_size, LightData light, vec3 lNg, vec3 lP,
vec2 ndc_texel_center_delta = uv_subpixel_coord * 2.0 - 1.0;
/* Create a normal plane equation and go through the normal projection matrix. */
vec4 lNg_plane = vec4(lNg, -dot(lNg, lP));
vec4 ndc_Ng = shadow_load_normal_matrix(light) * lNg_plane;
vec4 hs_Ng = shadow_load_normal_matrix(light) * lNg_plane;
/* Get slope from normal vector. Note that this is signed. */
vec2 ndc_slope = ndc_Ng.xy / abs(ndc_Ng.z);
vec2 ndc_slope = hs_Ng.xy / abs(hs_Ng.z);
/* Clamp out to avoid the bias going to infinity. Remember this is in NDC space. */
ndc_slope = clamp(ndc_slope, -100.0, 100.0);
/* Compute slope to where the receiver should be by extending the plane to the texel center. */

View File

@ -18,5 +18,5 @@ void main()
interp.P += bounds.bounding_corners[3].xyz * pos.z;
interp.vP = point_world_to_view(interp.P);
gl_Position = point_world_to_ndc(interp.P);
gl_Position = point_world_to_homogenous(interp.P);
}

View File

@ -23,7 +23,7 @@ void main()
pos.y * abs((pos.y > 0.0) ? amax.y : amin.y));
vec3 world_pos = (model_mat * vec4(final_pos, 1.0)).xyz;
gl_Position = point_world_to_ndc(world_pos);
gl_Position = point_world_to_homogenous(world_pos);
finalColor = color;
edgeStart = edgePos = ((gl_Position.xy / gl_Position.w) * 0.5 + 0.5) * sizeViewport;

View File

@ -123,9 +123,9 @@ void main()
view_clipping_distances(wpos1);
vec4 p0 = point_world_to_ndc(wpos0);
vec4 p1 = point_world_to_ndc(wpos1);
vec4 p2 = point_world_to_ndc(wpos2);
vec4 p0 = point_world_to_homogenous(wpos0);
vec4 p1 = point_world_to_homogenous(wpos1);
vec4 p2 = point_world_to_homogenous(wpos2);
gl_Position = p1;

View File

@ -8,7 +8,7 @@ void main()
mat4 model_mat = extract_matrix_packed_data(inst_obmat, state_color, bone_color);
vec3 world_pos = (model_mat * vec4(pos, 1.0)).xyz;
gl_Position = point_world_to_ndc(world_pos);
gl_Position = point_world_to_homogenous(world_pos);
finalColor.rgb = mix(state_color.rgb, bone_color.rgb, 0.5);
finalColor.a = 1.0;

View File

@ -8,7 +8,7 @@ void main()
finalColor.a = 1.0;
vec3 world_pos = point_object_to_world(pos);
gl_Position = point_world_to_ndc(world_pos);
gl_Position = point_world_to_homogenous(world_pos);
edgeStart = edgePos = ((gl_Position.xy / gl_Position.w) * 0.5 + 0.5) * sizeViewport.xy;

View File

@ -4,7 +4,7 @@
void main()
{
vec3 world_pos = boundbox[gl_VertexID];
gl_Position = point_world_to_ndc(world_pos);
gl_Position = point_world_to_homogenous(world_pos);
/* Result in a position at 1.0 (far plane). Small epsilon to avoid precision issue.
* This mimics the effect of infinite projection matrix

View File

@ -7,7 +7,7 @@ void main()
GPU_INTEL_VERTEX_SHADER_WORKAROUND
vec3 world_pos = point_object_to_world(pos);
gl_Position = point_world_to_ndc(world_pos);
gl_Position = point_world_to_homogenous(world_pos);
view_clipping_distances(world_pos);
}

View File

@ -7,7 +7,7 @@ void main()
GPU_INTEL_VERTEX_SHADER_WORKAROUND
vec3 world_pos = point_object_to_world(pos);
gl_Position = point_world_to_ndc(world_pos);
gl_Position = point_world_to_homogenous(world_pos);
vert.flag = data;
view_clipping_distances(world_pos);

View File

@ -8,11 +8,11 @@
finalColor = vec4(0.0); \
return;
void output_line(vec2 offset, vec4 color, vec3 out_world_pos, vec4 out_ndc_pos)
void output_line(vec2 offset, vec4 color, vec3 out_world_pos, vec4 out_hs_pos)
{
finalColor = color;
gl_Position = out_ndc_pos;
gl_Position.xy += offset * out_ndc_pos.w;
gl_Position = out_hs_pos;
gl_Position.xy += offset * out_hs_pos.w;
view_clipping_distances(out_world_pos);
}
@ -23,7 +23,7 @@ void main()
/* Perform vertex shader for each input primitive. */
vec3 in_pos[2];
vec3 world_pos[2];
vec4 ndc_pos[2];
vec4 hs_pos[2];
uint vert_flag[2];
/* Input prim is LineList. */
@ -39,7 +39,7 @@ void main()
in_pos[i] = vertex_fetch_attribute((input_line_id * 2) + i, pos, vec3).xyz;
vert_flag[i] = (uint)vertex_fetch_attribute((input_line_id * 2) + i, data, uchar);
world_pos[i] = point_object_to_world(in_pos[i]);
ndc_pos[i] = point_world_to_ndc(world_pos[i]);
hs_pos[i] = point_world_to_homogenous(world_pos[i]);
}
/* Perform Geometry shader equivalent calculation. */
@ -103,7 +103,7 @@ void main()
:
vec4(inner_color.rgb, 0.0);
vec2 v1_2 = (ndc_pos[1].xy / ndc_pos[1].w - ndc_pos[0].xy / ndc_pos[0].w);
vec2 v1_2 = (hs_pos[1].xy / hs_pos[1].w - hs_pos[0].xy / hs_pos[0].w);
vec2 offset = sizeEdge * 4.0 * sizeViewportInv; /* 4.0 is eyeballed */
if (abs(v1_2.x * sizeViewport.x) < abs(v1_2.y * sizeViewport.y)) {
@ -122,7 +122,7 @@ void main()
output_line(offset * 2.0,
vec4(colorActiveSpline.rgb, 0.0),
world_pos[output_prim_vert_id],
ndc_pos[output_prim_vert_id]);
hs_pos[output_prim_vert_id]);
}
else {
DISCARD_VERTEX
@ -132,19 +132,19 @@ void main()
case 1: {
/* draw the outline. */
output_line(
offset, outer_color, world_pos[output_prim_vert_id], ndc_pos[output_prim_vert_id]);
offset, outer_color, world_pos[output_prim_vert_id], hs_pos[output_prim_vert_id]);
break;
}
case 2: {
/* draw the core of the line. */
output_line(
vec2(0.0), inner_color, world_pos[output_prim_vert_id], ndc_pos[output_prim_vert_id]);
vec2(0.0), inner_color, world_pos[output_prim_vert_id], hs_pos[output_prim_vert_id]);
break;
}
case 3: {
/* draw the outline. */
output_line(
-offset, outer_color, world_pos[output_prim_vert_id], ndc_pos[output_prim_vert_id]);
-offset, outer_color, world_pos[output_prim_vert_id], hs_pos[output_prim_vert_id]);
break;
}
case 4: {
@ -153,7 +153,7 @@ void main()
output_line(offset * -2.0,
vec4(colorActiveSpline.rgb, 0.0),
world_pos[output_prim_vert_id],
ndc_pos[output_prim_vert_id]);
hs_pos[output_prim_vert_id]);
}
break;
}

View File

@ -21,7 +21,7 @@ void main()
}
vec3 world_pos = point_object_to_world(pos);
gl_Position = point_world_to_ndc(world_pos);
gl_Position = point_world_to_homogenous(world_pos);
gl_PointSize = (!is_gpencil) ? sizeVertex * 2.0 : sizeVertexGpencil * 2.0;
view_clipping_distances(world_pos);

View File

@ -15,7 +15,7 @@ void main()
}
vec3 world_pos = point_object_to_world(final_pos);
gl_Position = point_world_to_ndc(world_pos);
gl_Position = point_world_to_homogenous(world_pos);
finalColor = colorWireEdit;

View File

@ -19,7 +19,7 @@ void main()
vec3 world_pos = xAxis * pos.x + yAxis * pos.y + origin;
gl_Position = point_world_to_ndc(world_pos);
gl_Position = point_world_to_homogenous(world_pos);
view_clipping_distances(world_pos);

View File

@ -6,7 +6,7 @@ void main()
{
GPU_INTEL_VERTEX_SHADER_WORKAROUND
gl_Position = point_world_to_ndc(pPosition);
gl_Position = point_world_to_homogenous(pPosition);
finalColor = pColor;
gl_PointSize = pSize;

View File

@ -36,7 +36,7 @@ void main()
GPU_INTEL_VERTEX_SHADER_WORKAROUND
vec3 world_pos = point_object_to_world(pos);
gl_Position = point_world_to_ndc(world_pos);
gl_Position = point_world_to_homogenous(world_pos);
bool is_multiframe = (vflag & GP_EDIT_MULTIFRAME) != 0u;
bool is_stroke_sel = (vflag & GP_EDIT_STROKE_SELECTED) != 0u;

View File

@ -17,7 +17,7 @@ void main()
}
vec3 world_pos = point_object_to_world(pos);
gl_Position = point_world_to_ndc(world_pos);
gl_Position = point_world_to_homogenous(world_pos);
/* Small offset in Z */
gl_Position.z -= 3e-4;

View File

@ -26,7 +26,7 @@ void main()
finalColor = vec4(weight_to_rgb(weight), 1.0);
vec3 world_pos = point_object_to_world(pos);
gl_Position = point_world_to_ndc(world_pos);
gl_Position = point_world_to_homogenous(world_pos);
view_clipping_distances(world_pos);
}

View File

@ -22,7 +22,7 @@ void main()
GPU_INTEL_VERTEX_SHADER_WORKAROUND
vec3 world_pos = point_object_to_world(pos);
gl_Position = point_world_to_ndc(world_pos);
gl_Position = point_world_to_homogenous(world_pos);
weightColor = vec4(weight_to_rgb(weight), 1.0);
view_clipping_distances(world_pos);

View File

@ -61,7 +61,7 @@ void main()
}
}
gl_Position = point_world_to_ndc(world_pos);
gl_Position = point_world_to_homogenous(world_pos);
finalColor.a *= (test_occlusion()) ? alpha : 1.0;

View File

@ -30,7 +30,7 @@ void main()
vec3 world_pos = point_object_to_world(pos);
vec3 view_pos = point_world_to_view(world_pos);
fclem marked this conversation as resolved

Here.

Here.
gl_Position = point_view_to_ndc(view_pos);
gl_Position = point_world_to_homogenous(world_pos);
fclem marked this conversation as resolved

You still need to fix the merge errors. This will not compile as point_view_to_ndc does not exist anymore.
You only removed the merge tags, but you need to remove what was below the <<<<<<< HEAD and do the renaming of what was above >>>>>>> main.

You still need to fix the merge errors. This will not compile as `point_view_to_ndc` does not exist anymore. You only removed the merge tags, but you need to remove what was below the `<<<<<<< HEAD` and do the renaming of what was above `>>>>>>> main`.
/* Offset Z position for retopology overlay. */
gl_Position.z += get_homogenous_z_offset(view_pos.z, gl_Position.w, retopologyOffset);

View File

@ -84,8 +84,8 @@ void main()
vec3 world_pos1 = point_object_to_world(in_pos1);
vec3 view_pos0 = point_world_to_view(world_pos0);
fclem marked this conversation as resolved

Here

Here
vec3 view_pos1 = point_world_to_view(world_pos1);
vec4 out_pos0 = point_view_to_ndc(view_pos0);
vec4 out_pos1 = point_view_to_ndc(view_pos1);
vec4 out_pos0 = point_world_to_homogenous(world_pos0);
fclem marked this conversation as resolved

Same thing here.

Same thing here.
vec4 out_pos1 = point_world_to_homogenous(world_pos1);
/* Offset Z position for retopology overlay. */
out_pos0.z += get_homogenous_z_offset(view_pos0.z, out_pos0.w, retopologyOffset);

View File

@ -5,7 +5,7 @@
void main()
{
vec3 world_pos = point_object_to_world(pos);
gl_Position = point_world_to_ndc(world_pos);
gl_Position = point_world_to_homogenous(world_pos);
finalColor = mix(colorWire, colorVertexSelect, selection);

View File

@ -22,7 +22,7 @@ vec3 weight_to_rgb(float t)
void main()
{
vec3 world_pos = point_object_to_world(pos);
gl_Position = point_world_to_ndc(world_pos);
gl_Position = point_world_to_homogenous(world_pos);
if (useWeight) {
finalColor = vec4(weight_to_rgb(selection), 1.0);

View File

@ -3,7 +3,7 @@
void main()
{
vec3 world_pos = point_object_to_world(vec3(au, 0.0));
gl_Position = point_world_to_ndc(world_pos);
gl_Position = point_world_to_homogenous(world_pos);
/* Snap vertices to the pixel grid to reduce artifacts. */
vec2 half_viewport_res = sizeViewport * 0.5;
vec2 half_pixel_offset = sizeViewportInv * 0.5;

View File

@ -45,14 +45,14 @@ void main()
/* Vertex shader per input vertex. */
vec3 world_pos0 = point_object_to_world(vec3(root_au0, 0.0));
vec3 world_pos1 = point_object_to_world(vec3(root_au1, 0.0));
vec4 ndc_pos0 = point_world_to_ndc(world_pos0);
vec4 ndc_pos1 = point_world_to_ndc(world_pos1);
vec4 hs_pos0 = point_world_to_homogenous(world_pos0);
vec4 hs_pos1 = point_world_to_homogeous(world_pos1);
/* Snap vertices to the pixel grid to reduce artifacts. */
vec2 half_viewport_res = sizeViewport * 0.5;
vec2 half_pixel_offset = sizeViewportInv * 0.5;
ndc_pos0.xy = floor(ndc_pos0.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;
hs_pos0.xy = floor(hs_pos0.xy * half_viewport_res) / half_viewport_res + half_pixel_offset;
hs_pos1.xy = floor(hs_pos1.xy * half_viewport_res) / half_viewport_res + half_pixel_offset;
#ifdef USE_EDGE_SELECT
bool is_select0 = (root_flag0 & EDGE_UV_SELECT) != 0;
@ -74,19 +74,19 @@ void main()
* actual pixels are at 0.75, 1.0 is used for the background. */
float depth0 = is_select0 ? 0.25 : 0.35;
float depth1 = is_select1 ? 0.25 : 0.35;
ndc_pos0.z = depth0;
ndc_pos1.z = depth1;
hs_pos0.z = depth0;
hs_pos1.z = depth1;
/* Avoid precision loss. */
vec2 stipplePos0 = 500.0 + 500.0 * (ndc_pos0.xy / ndc_pos0.w);
vec2 stipplePos1 = 500.0 + 500.0 * (ndc_pos1.xy / ndc_pos1.w);
vec2 stipplePos0 = 500.0 + 500.0 * (hs_pos0.xy / hs_pos0.w);
vec2 stipplePos1 = 500.0 + 500.0 * (hs_pos1.xy / hs_pos1.w);
vec2 stippleStart0 = stipplePos0;
vec2 stippleStart1 = stipplePos1;
/* Geometry shader equivalent calculations. */
vec2 ss_pos[2];
ss_pos[0] = ndc_pos0.xy / ndc_pos0.w;
ss_pos[1] = ndc_pos1.xy / ndc_pos1.w;
vec2 ndc_pos[2];
fclem marked this conversation as resolved

This should become ndc_pos since it is the position after the division.

This should become `ndc_pos` since it is the position after the division.
ndc_pos[0] = hs_pos0.xy / hs_pos0.w;
ndc_pos[1] = hs_pos1.xy / hs_pos1.w;
float half_size = sizeEdge;
@ -100,7 +100,7 @@ void main()
half_size += 0.5;
}
vec2 line = ss_pos[0] - ss_pos[1];
vec2 line = ndc_pos[0] - ndc_pos[1];
vec2 line_dir = normalize(line);
vec2 line_perp = vec2(-line_dir.y, line_dir.x);
vec2 edge_ofs = line_perp * sizeViewportInv * ceil(half_size);
@ -108,19 +108,19 @@ void main()
switch (quad_vertex_id) {
case 1: /* vertex A */
case 3:
do_vertex(ndc_pos1, selectionFac1, stippleStart1, stipplePos1, half_size, edge_ofs.xy);
do_vertex(hs_pos1, selectionFac1, stippleStart1, stipplePos1, half_size, edge_ofs.xy);
break;
case 0: /* B */
do_vertex(ndc_pos0, selectionFac0, stippleStart0, stipplePos0, half_size, edge_ofs.xy);
do_vertex(hs_pos0, selectionFac0, stippleStart0, stipplePos0, half_size, edge_ofs.xy);
break;
case 2: /* C */
case 4:
do_vertex(ndc_pos0, selectionFac0, stippleStart0, stipplePos0, -half_size, -edge_ofs.xy);
do_vertex(hs_pos0, selectionFac0, stippleStart0, stipplePos0, -half_size, -edge_ofs.xy);
break;
case 5: /* D */
do_vertex(ndc_pos1, selectionFac1, stippleStart1, stipplePos1, -half_size, -edge_ofs.xy);
do_vertex(hs_pos1, selectionFac1, stippleStart1, stipplePos1, -half_size, -edge_ofs.xy);
break;
}
}

View File

@ -3,7 +3,7 @@
void main()
{
vec3 world_pos = point_object_to_world(vec3(au, 0.0));
gl_Position = point_world_to_ndc(world_pos);
gl_Position = point_world_to_homogenous(world_pos);
finalColor = ((flag & FACE_UV_SELECT) != 0) ? colorFaceDot : vec4(colorWire.rgb, 1.0);
gl_PointSize = pointSize;

View File

@ -3,7 +3,7 @@
void main()
{
vec3 world_pos = point_object_to_world(vec3(au, 0.0));
gl_Position = point_world_to_ndc(world_pos);
gl_Position = point_world_to_homogenous(world_pos);
bool is_selected = (flag & FACE_UV_SELECT) != 0u;
bool is_active = (flag & FACE_UV_ACTIVE) != 0u;

View File

@ -5,7 +5,7 @@ void main()
/* `pos` contains the coordinates of a quad (-1..1). but we need the coordinates of an image
* plane (0..1) */
vec3 image_pos = pos * 0.5 + 0.5;
vec4 position = point_object_to_ndc(image_pos);
vec4 position = point_object_to_homogenous(image_pos);
gl_Position = position;
uvs = image_pos.xy;
}

View File

@ -64,7 +64,7 @@ float area_ratio_to_stretch(float ratio, float tot_ratio)
void main()
{
vec3 world_pos = point_object_to_world(vec3(pos, 0.0));
gl_Position = point_world_to_ndc(world_pos);
gl_Position = point_world_to_homogenous(world_pos);
#ifdef STRETCH_ANGLE
vec2 v1 = angle_to_v2(uv_angles.x * M_PI);

View File

@ -9,6 +9,6 @@ void main()
/* `pos` contains the coordinates of a quad (-1..1). but we need the coordinates of an image
* plane (0..1) */
vec3 image_pos = pos * 0.5 + 0.5;
vec4 position = point_object_to_ndc(image_pos);
vec4 position = point_object_to_homogenous(image_pos);
gl_Position = position;
}

View File

@ -16,7 +16,7 @@ void main()
* 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. */
float depth = is_selected ? (is_pinned ? 0.05 : 0.10) : 0.15;
gl_Position = vec4(point_world_to_ndc(world_pos).xy, depth, 1.0);
gl_Position = vec4(point_world_to_homogenous(world_pos).xy, depth, 1.0);
gl_PointSize = pointSize;
/* calculate concentric radii in pixels */

View File

@ -13,7 +13,7 @@ void main()
float screen_size = mul_project_m4_v3_zfac(p) * sizePixel;
vec3 world_pos = p + screen_pos * screen_size;
gl_Position = point_world_to_ndc(world_pos);
gl_Position = point_world_to_homogenous(world_pos);
/* Convert to screen position [0..sizeVp]. */
edgePos = edgeStart = ((gl_Position.xy / gl_Position.w) * 0.5 + 0.5) * sizeViewport.xy;

View File

@ -42,7 +42,7 @@ void main()
ls_cell_location = ls_cell_location * 2.0 - 1.0;
vec3 ws_cell_location = (model_mat * vec4(ls_cell_location, 1.0)).xyz;
gl_Position = point_world_to_ndc(ws_cell_location);
gl_Position = point_world_to_homogenous(ws_cell_location);
gl_PointSize = sizeVertex * 2.0;
finalColor = color_from_id(color_id);

View File

@ -9,7 +9,7 @@ void main()
finalColor = vec4(obmat[0][3], obmat[1][3], obmat[2][3], obmat[3][3]);
vec3 world_pos = (ModelMatrix * vec4(pos, 1.0)).xyz;
gl_Position = point_world_to_ndc(world_pos);
gl_Position = point_world_to_homogenous(world_pos);
gl_PointSize = sizeVertex * 2.0;

View File

@ -5,7 +5,7 @@
void main()
{
vec3 world_pos = point_object_to_world(pos);
gl_Position = point_world_to_ndc(world_pos);
gl_Position = point_world_to_homogenous(world_pos);
gl_PointSize = sizeObjectCenter;
float radius = 0.5 * sizeObjectCenter;

View File

@ -209,7 +209,7 @@ void main()
}
}
gl_Position = point_world_to_ndc(world_pos);
gl_Position = point_world_to_homogenous(world_pos);
/* Convert to screen position [0..sizeVp]. */
edgePos = edgeStart = ((gl_Position.xy / gl_Position.w) * 0.5 + 0.5) * sizeViewport.xy;

View File

@ -10,7 +10,7 @@ vec2 screen_position(vec4 p)
void main()
{
vec3 world_pos = point_object_to_world(pos);
gl_Position = point_world_to_ndc(world_pos);
gl_Position = point_world_to_homogenous(world_pos);
#ifdef SELECT_EDGES
/* HACK: to avoid losing sub-pixel object in selections, we add a bit of randomness to the

View File

@ -5,6 +5,6 @@
void main()
{
vec3 world_pos = point_object_to_world(pos);
gl_Position = point_world_to_ndc(world_pos);
gl_Position = point_world_to_homogenous(world_pos);
view_clipping_distances(world_pos);
}

View File

@ -7,13 +7,13 @@ void main()
vec3 world_pos = point_object_to_world(pos);
if (isCameraBackground) {
/* Model matrix converts to view position to avoid jittering (see #91398). */
gl_Position = point_view_to_ndc(world_pos);
gl_Position = point_view_to_homogenous(world_pos);
/* Camera background images are not really part of the 3D space.
* It makes no sense to apply clipping on them. */
view_clipping_distances_bypass();
}
else {
gl_Position = point_world_to_ndc(world_pos);
gl_Position = point_world_to_homogenous(world_pos);
view_clipping_distances(world_pos);
}

View File

@ -45,7 +45,7 @@ void main()
vec3 world_pos;
if (hairThicknessRes > 1) {
/* Calculate the thickness, thicktime, worldpos taken into account the outline. */
float outline_width = point_world_to_ndc(center_wpos).w * 1.25 * sizeViewportInv.y *
float outline_width = point_world_to_homogenous(center_wpos).w * 1.25 * sizeViewportInv.y *
fclem marked this conversation as resolved

Did you run make format? there is an extra blank space here that should have been fixed by clang format.

Did you run `make format`? there is an extra blank space here that should have been fixed by clang format.
drw_view.wininv[1][1];
thickness += outline_width;
float thick_time = float(gl_VertexID % hairThicknessRes) / float(hairThicknessRes - 1);
@ -59,7 +59,7 @@ void main()
world_pos = center_wpos;
}
gl_Position = point_world_to_ndc(world_pos);
gl_Position = point_world_to_homogenous(world_pos);
#ifdef USE_GEOM
vert.pos = point_world_to_view(world_pos);

View File

@ -32,8 +32,8 @@ void main()
vec3 ray_ori = pos;
vec3 ray_dir = (is_persp) ? (drw_view.viewinv[3].xyz - pos) : drw_view.viewinv[2].xyz;
vec3 isect = ray_plane_intersection(ray_ori, ray_dir, gpDepthPlane);
vec4 ndc = point_world_to_ndc(isect);
gl_FragDepth = (ndc.z / ndc.w) * 0.5 + 0.5;
vec4 hs_isect = point_world_to_homogenous(isect);
fclem marked this conversation as resolved

Rename to hs_isect.

Rename to `hs_isect`.
gl_FragDepth = (hs_isect.z / hs_isect.w) * 0.5 + 0.5;
}
else {
gl_FragDepth = gl_FragCoord.z;

View File

@ -30,7 +30,7 @@ void main()
{
vec3 world_pos = pointcloud_get_pos();
gl_Position = point_world_to_ndc(world_pos);
gl_Position = point_world_to_homogenous(world_pos);
/* Small bias to always be on top of the geom. */
gl_Position.z -= 1e-3;

View File

@ -29,7 +29,7 @@ void main()
{
vec3 world_pos = point_object_to_world(pos);
gl_Position = point_world_to_ndc(world_pos);
gl_Position = point_world_to_homogenous(world_pos);
#ifdef USE_GEOM
vert.pos = point_world_to_view(world_pos);
#endif

View File

@ -46,7 +46,7 @@ void main()
vertex_id_from_index_id(4 * line_prim_id + i), pos, vec3);
world_pos[i] = point_object_to_world(in_pos);
view_pos[i] = point_world_to_view(world_pos[i]);
gl_pos[i] = point_world_to_ndc(world_pos[i]);
gl_pos[i] = point_world_to_homogenous(world_pos[i]);
gl_pos[i].z -= 1e-3;
}

View File

@ -6,7 +6,7 @@ void main()
GPU_INTEL_VERTEX_SHADER_WORKAROUND
vec3 world_pos = point_object_to_world(pos);
gl_Position = point_world_to_ndc(world_pos);
gl_Position = point_world_to_homogenous(world_pos);
bool is_select = (nor.w > 0.0);
bool is_hidden = (nor.w < 0.0);

View File

@ -9,7 +9,7 @@ void main()
bool is_hidden = (nor.w < 0.0);
vec3 world_pos = point_object_to_world(pos);
gl_Position = point_world_to_ndc(world_pos);
gl_Position = point_world_to_homogenous(world_pos);
/* Add offset in Z to avoid Z-fighting and render selected wires on top. */
/* TODO: scale this bias using Z-near and Z-far range. */
gl_Position.z -= (is_select ? 2e-4 : 1e-4);

View File

@ -6,7 +6,7 @@ void main()
GPU_INTEL_VERTEX_SHADER_WORKAROUND
vec3 world_pos = point_object_to_world(pos);
gl_Position = point_world_to_ndc(world_pos);
gl_Position = point_world_to_homogenous(world_pos);
uv_interp = mu;

View File

@ -14,7 +14,7 @@ void main()
GPU_INTEL_VERTEX_SHADER_WORKAROUND
vec3 world_pos = point_object_to_world(pos);
gl_Position = point_world_to_ndc(world_pos);
gl_Position = point_world_to_homogenous(world_pos);
finalColor = srgb_to_linear_attr(ac);

View File

@ -6,7 +6,7 @@ void main()
GPU_INTEL_VERTEX_SHADER_WORKAROUND
vec3 world_pos = point_object_to_world(pos);
gl_Position = point_world_to_ndc(world_pos);
gl_Position = point_world_to_homogenous(world_pos);
/* Separate actual weight and alerts for independent interpolation */
weight_interp = max(vec2(weight, -weight), 0.0);

View File

@ -9,7 +9,7 @@ void main()
bool is_hidden = (nor.w < 0.0) && useSelect;
vec3 world_pos = point_object_to_world(pos);
gl_Position = point_world_to_ndc(world_pos);
gl_Position = point_world_to_homogenous(world_pos);
/* Add offset in Z to avoid Z-fighting and render selected wires on top. */
/* TODO: scale this bias using Z-near and Z-far range. */
gl_Position.z -= (is_select ? 2e-4 : 1e-4);

View File

@ -21,7 +21,7 @@ void main()
vec3 world_pos = part_pos;
#ifdef USE_DOTS
gl_Position = point_world_to_ndc(world_pos);
gl_Position = point_world_to_homogenous(world_pos);
/* World sized points. */
gl_PointSize = sizePixel * draw_size * drw_view.winmat[1][1] * sizeViewport.y / gl_Position.w;
#else
@ -34,7 +34,7 @@ void main()
world_pos += rotate(pos, part_rot) * draw_size;
}
gl_Position = point_world_to_ndc(world_pos);
gl_Position = point_world_to_homogenous(world_pos);
#endif
/* Coloring */

View File

@ -5,5 +5,5 @@
void main()
{
vec3 world_pos = pointcloud_get_pos();
gl_Position = point_world_to_ndc(world_pos);
gl_Position = point_world_to_homogenous(world_pos);
}

View File

@ -5,7 +5,7 @@
void main()
{
vec3 world_pos = point_object_to_world(pos);
gl_Position = point_world_to_ndc(world_pos);
gl_Position = point_world_to_homogenous(world_pos);
finalColor = vec4(selection);
finalColor.a *= opacity;

View File

@ -26,7 +26,7 @@ void main()
thickness,
thick_time);
gl_Position = point_world_to_ndc(world_pos);
gl_Position = point_world_to_homogenous(world_pos);
mask_weight = 1.0 - (selection_opacity - retrieve_selection() * selection_opacity);

View File

@ -4,7 +4,7 @@
void main()
{
vec3 world_pos = point_object_to_world(pos);
gl_Position = point_world_to_ndc(world_pos);
gl_Position = point_world_to_homogenous(world_pos);
faceset_color = mix(vec3(1.0), fset, faceSetsOpacity);
mask_color = 1.0 - (msk * maskOpacity);

View File

@ -4,6 +4,6 @@
void main()
{
vec3 world_pos = point_object_to_world(pos);
gl_Position = point_world_to_ndc(world_pos);
gl_Position = point_world_to_homogenous(world_pos);
finalColor = attribute_value;
}

View File

@ -17,7 +17,7 @@ void main()
time,
thickness,
thick_time);
gl_Position = point_world_to_ndc(world_pos);
gl_Position = point_world_to_homogenous(world_pos);
if (is_point_domain) {
finalColor = texelFetch(color_tx, hair_get_base_id());

View File

@ -4,6 +4,6 @@
void main()
{
vec3 world_pos = point_object_to_world(pos);
gl_Position = point_world_to_ndc(world_pos);
gl_Position = point_world_to_homogenous(world_pos);
finalColor = attribute_value;
}

View File

@ -5,6 +5,6 @@
void main()
{
vec3 world_pos = pointcloud_get_pos();
gl_Position = point_world_to_ndc(world_pos);
gl_Position = point_world_to_homogenous(world_pos);
finalColor = pointcloud_get_customdata_vec4(attribute_tx);
}

View File

@ -95,5 +95,5 @@ void main()
pos += rotated_pos * cellSize;
vec3 world_pos = point_object_to_world(pos);
gl_Position = point_world_to_ndc(world_pos);
gl_Position = point_world_to_homogenous(world_pos);
}

View File

@ -189,5 +189,5 @@ void main()
#endif
vec3 world_pos = point_object_to_world(pos);
gl_Position = point_world_to_ndc(world_pos);
gl_Position = point_world_to_homogenous(world_pos);
}

View File

@ -86,7 +86,7 @@ void main()
float facing = dot(wnor, V);
gl_Position = point_world_to_ndc(wpos);
gl_Position = point_world_to_homogenous(wpos);
#ifndef CUSTOM_DEPTH_BIAS
float facing_ratio = clamp(1.0 - facing * facing, 0.0, 1.0);

View File

@ -57,7 +57,7 @@ void main()
thickness,
thick_time);
gl_Position = point_world_to_ndc(world_pos);
gl_Position = point_world_to_homogenous(world_pos);
float hair_rand = integer_noise(hair_get_strand_id());
vec3 nor = workbench_hair_random_normal(tan, binor, hair_rand);

View File

@ -13,7 +13,7 @@ void main()
normal_interp = normalize(normal_world_to_view(normal_interp));
gl_Position = point_world_to_ndc(world_pos);
gl_Position = point_world_to_homogenous(world_pos);
view_clipping_distances(world_pos);

View File

@ -8,7 +8,7 @@
void main()
{
vec3 world_pos = point_object_to_world(pos);
gl_Position = point_world_to_ndc(world_pos);
gl_Position = point_world_to_homogenous(world_pos);
view_clipping_distances(world_pos);

View File

@ -82,17 +82,17 @@ void main()
vData[3].pos = vertex_fetch_attribute(input_base_vertex_id + 3, pos, vec3);
/* Calculate front/back Positions. */
vData[0].frontPosition = point_object_to_ndc(vData[0].pos);
vData[0].backPosition = point_object_to_ndc(vData[0].pos + lightDirection * lightDistance);
vData[0].frontPosition = point_object_to_homogenous(vData[0].pos);
vData[0].backPosition = point_object_to_homogenous(vData[0].pos + lightDirection * lightDistance);
vData[1].frontPosition = point_object_to_ndc(vData[1].pos);
vData[1].backPosition = point_object_to_ndc(vData[1].pos + lightDirection * lightDistance);
vData[1].frontPosition = point_object_to_homogenous(vData[1].pos);
vData[1].backPosition = point_object_to_homogenous(vData[1].pos + lightDirection * lightDistance);
vData[2].frontPosition = point_object_to_ndc(vData[2].pos);
vData[2].backPosition = point_object_to_ndc(vData[2].pos + lightDirection * lightDistance);
vData[2].frontPosition = point_object_to_homogenous(vData[2].pos);
vData[2].backPosition = point_object_to_homogenous(vData[2].pos + lightDirection * lightDistance);
vData[3].frontPosition = point_object_to_ndc(vData[3].pos);
vData[3].backPosition = point_object_to_ndc(vData[3].pos + lightDirection * lightDistance);
vData[3].frontPosition = point_object_to_homogenous(vData[3].pos);
vData[3].backPosition = point_object_to_homogenous(vData[3].pos + lightDirection * lightDistance);
/* Geometry shader equivalent path. */
vec3 v10 = vData[0].pos - vData[1].pos;

View File

@ -25,7 +25,7 @@ void main()
#else
final_pos = (volumeTextureToObject * vec4(final_pos * 0.5 + 0.5, 1.0)).xyz;
#endif
gl_Position = point_object_to_ndc(final_pos);
gl_Position = point_object_to_homogenous(final_pos);
PASS_RESOURCE_ID
}

View File

@ -61,7 +61,7 @@ vec2 gpencil_project_to_screenspace(vec4 v, vec4 viewport_size)
return ((v.xy / v.w) * 0.5 + 0.5) * viewport_size.xy;
}
float gpencil_stroke_thickness_modulate(float thickness, vec4 ndc_pos, vec4 viewport_size)
float gpencil_stroke_thickness_modulate(float thickness, vec4 hs_pos, vec4 viewport_size)
{
/* Modify stroke thickness by object and layer factors. */
thickness = max(1.0, thickness * gpThicknessScale + gpThicknessOffset);
@ -69,7 +69,7 @@ float gpencil_stroke_thickness_modulate(float thickness, vec4 ndc_pos, vec4 view
if (gpThicknessIsScreenSpace) {
/* Multiply offset by view Z so that offset is constant in screenspace.
* (e.i: does not change with the distance to camera) */
thickness *= ndc_pos.w;
thickness *= hs_pos.w;
}
else {
/* World space point size. */
@ -78,11 +78,11 @@ float gpencil_stroke_thickness_modulate(float thickness, vec4 ndc_pos, vec4 view
return thickness;
}
float gpencil_clamp_small_stroke_thickness(float thickness, vec4 ndc_pos)
float gpencil_clamp_small_stroke_thickness(float thickness, vec4 hs_pos)
{
/* To avoid aliasing artifacts, we clamp the line thickness and
* reduce its opacity in the fragment shader. */
float min_thickness = ndc_pos.w * 1.3;
float min_thickness = hs_pos.w * 1.3;
thickness = max(min_thickness, thickness);
return thickness;
@ -175,7 +175,7 @@ vec4 gpencil_vertex(vec4 viewport_size,
# define uvrot1 ma1.w
# define aspect1 ma1.w
vec4 out_ndc;
vec4 out_hs;
if (gpencil_is_stroke_vertex()) {
bool is_dot = flag_test(material_flags, GP_STROKE_ALIGNMENT);
@ -190,8 +190,8 @@ vec4 gpencil_vertex(vec4 viewport_size,
/* Endpoints, we discard the vertices. */
if (!is_dot && ma2.x == -1) {
/* We set the vertex at the camera origin to generate 0 fragments. */
out_ndc = vec4(0.0, 0.0, -3e36, 0.0);
return out_ndc;
out_hs = vec4(0.0, 0.0, -3e36, 0.0);
return out_hs;
}
/* Avoid using a vertex attribute for quad positioning. */
@ -220,25 +220,25 @@ vec4 gpencil_vertex(vec4 viewport_size,
vec3 B = cross(T, ViewMatrixInverse[2].xyz);
out_N = normalize(cross(B, T));
vec4 ndc_adj = point_world_to_ndc(wpos_adj);
vec4 ndc1 = point_world_to_ndc(wpos1);
vec4 ndc2 = point_world_to_ndc(wpos2);
vec4 hs_pos_adj = point_world_to_hs(wpos_adj);
fclem marked this conversation as resolved

Rename to hs_pos_adj.

Rename to `hs_pos_adj`.
vec4 hs_pos1 = point_world_to_homogenous(wpos1);
fclem marked this conversation as resolved

Rename to hs_pos1 and hs_pos2.

Rename to `hs_pos1` and `hs_pos2`.
vec4 hs_pos2 = point_world_to_homogenous(wpos2);
out_ndc = (use_curr) ? ndc1 : ndc2;
out_hs = (use_curr) ? hs_pos1 : hs_pos2;
out_P = (use_curr) ? wpos1 : wpos2;
out_strength = abs((use_curr) ? strength1 : strength2);
vec2 ss_adj = gpencil_project_to_screenspace(ndc_adj, viewport_size);
vec2 ss1 = gpencil_project_to_screenspace(ndc1, viewport_size);
vec2 ss2 = gpencil_project_to_screenspace(ndc2, viewport_size);
vec2 ss_adj = gpencil_project_to_screenspace(hs_pos_adj, viewport_size);
vec2 ss1 = gpencil_project_to_screenspace(hs_pos1, viewport_size);
vec2 ss2 = gpencil_project_to_screenspace(hs_pos2, viewport_size);
/* Screenspace Lines tangents. */
float line_len;
vec2 line = safe_normalize_len(ss2 - ss1, line_len);
vec2 line_adj = safe_normalize((use_curr) ? (ss1 - ss_adj) : (ss_adj - ss2));
float thickness = abs((use_curr) ? thickness1 : thickness2);
thickness = gpencil_stroke_thickness_modulate(thickness, out_ndc, viewport_size);
float clamped_thickness = gpencil_clamp_small_stroke_thickness(thickness, out_ndc);
thickness = gpencil_stroke_thickness_modulate(thickness, out_hs, viewport_size);
float clamped_thickness = gpencil_clamp_small_stroke_thickness(thickness, out_hs);
out_uv = vec2(x, y) * 0.5 + 0.5;
out_hardness = gpencil_decode_hardness(use_curr ? hardness1 : hardness2);
@ -260,8 +260,8 @@ vec4 gpencil_vertex(vec4 viewport_size,
x_axis = vec2(1.0, 0.0);
}
else { /* GP_STROKE_ALIGNMENT_OBJECT */
vec4 ndc_x = point_world_to_ndc(wpos1 + ModelMatrix[0].xyz);
vec2 ss_x = gpencil_project_to_screenspace(ndc_x, viewport_size);
vec4 hs_x = point_world_to_homogenous(wpos1 + ModelMatrix[0].xyz);
vec2 ss_x = gpencil_project_to_screenspace(hs_x, viewport_size);
x_axis = safe_normalize(ss_x - ss1);
}
@ -284,12 +284,12 @@ vec4 gpencil_vertex(vec4 viewport_size,
/* Invert for vertex shader. */
out_aspect = 1.0 / out_aspect;
out_ndc.xy += (x * x_axis + y * y_axis) * viewport_size.zw * clamped_thickness;
out_hs.xy += (x * x_axis + y * y_axis) * viewport_size.zw * clamped_thickness;
out_sspos.xy = ss1;
out_sspos.zw = ss1 + x_axis * 0.5;
out_thickness.x = (is_squares) ? 1e18 : (clamped_thickness / out_ndc.w);
out_thickness.y = (is_squares) ? 1e18 : (thickness / out_ndc.w);
out_thickness.x = (is_squares) ? 1e18 : (clamped_thickness / out_hs.w);
out_thickness.y = (is_squares) ? 1e18 : (thickness / out_hs.w);
}
else {
bool is_stroke_start = (ma.x == -1 && x == -1);
@ -308,8 +308,8 @@ vec4 gpencil_vertex(vec4 viewport_size,
out_sspos.xy = ss1;
out_sspos.zw = ss2;
out_thickness.x = clamped_thickness / out_ndc.w;
out_thickness.y = thickness / out_ndc.w;
out_thickness.x = clamped_thickness / out_hs.w;
out_thickness.y = thickness / out_hs.w;
out_aspect = vec2(1.0);
vec2 screen_ofs = miter * y;
@ -320,7 +320,7 @@ vec4 gpencil_vertex(vec4 viewport_size,
screen_ofs += line * x;
}
out_ndc.xy += screen_ofs * viewport_size.zw * clamped_thickness;
out_hs.xy += screen_ofs * viewport_size.zw * clamped_thickness;
out_uv.x = (use_curr) ? uv1.z : uv2.z;
}
@ -330,7 +330,7 @@ vec4 gpencil_vertex(vec4 viewport_size,
else {
/* Fill vertex. */
out_P = transform_point(ModelMatrix, pos1.xyz);
out_ndc = point_world_to_ndc(out_P);
out_hs = point_world_to_homogenous(out_P);
out_uv = uv1.xy;
out_thickness.x = 1e18;
out_thickness.y = 1e20;
@ -349,7 +349,7 @@ vec4 gpencil_vertex(vec4 viewport_size,
out_color = vec4(fcol1.rgb, floor(fcol1.a / 10.0) / 10000.0);
/* We still offset the fills a little to avoid overlaps */
out_ndc.z += 0.000002;
out_hs.z += 0.000002;
}
# undef thickness1
@ -361,7 +361,7 @@ vec4 gpencil_vertex(vec4 viewport_size,
# undef uvrot1
# undef aspect1
return out_ndc;
return out_hs;
}
vec4 gpencil_vertex(vec4 viewport_size,

View File

@ -230,24 +230,24 @@ uniform mat4 ModelMatrixInverse;
#define normal_world_to_view(n) (mat3(ViewMatrix) * n)
#define normal_view_to_world(n) (mat3(ViewMatrixInverse) * n)
#define point_object_to_ndc(p) \
#define point_object_to_homogenous(p) \
(ProjectionMatrix * (ViewMatrix * vec4((ModelMatrix * vec4(p, 1.0)).xyz, 1.0)))
#define point_object_to_view(p) ((ViewMatrix * vec4((ModelMatrix * vec4(p, 1.0)).xyz, 1.0)).xyz)
#define point_object_to_world(p) ((ModelMatrix * vec4(p, 1.0)).xyz)
#define point_view_to_object(p) ((ModelMatrixInverse * (ViewMatrixInverse * vec4(p, 1.0))).xyz)
#define point_world_to_object(p) ((ModelMatrixInverse * vec4(p, 1.0)).xyz)
vec4 point_view_to_ndc(vec3 p)
vec4 point_view_to_homogenous(vec3 p)
{
return ProjectionMatrix * vec4(p, 1.0);
}
vec3 point_view_to_world(vec3 p)
vec3 point_view_to_homogenous(vec3 p)
{
return (ViewMatrixInverse * vec4(p, 1.0)).xyz;
}
vec4 point_world_to_ndc(vec3 p)
vec4 point_world_to_homogenous(vec3 p)
{
return ProjectionMatrix * (ViewMatrix * vec4(p, 1.0));
}
@ -335,8 +335,8 @@ float get_depth_from_view_z(float z)
vec2 get_uvs_from_view(vec3 view)
{
vec4 ndc = ProjectionMatrix * vec4(view, 1.0);
return (ndc.xy / ndc.w) * 0.5 + 0.5;
vec4 hs = ProjectionMatrix * vec4(view, 1.0);
return (hs.xy / hs.w) * 0.5 + 0.5;
}
vec3 get_view_space_from_depth(vec2 uvcoords, float depth)