Workbench: Replace usage of legacy GLSL libraries by new ones

This commit is contained in:
Clément Foucault
2024-11-13 21:36:11 +01:00
parent c6e7cdbc57
commit 9396c8f388
14 changed files with 48 additions and 42 deletions

View File

@@ -4,7 +4,7 @@
#pragma once
#include "common_view_lib.glsl"
#include "draw_view_lib.glsl"
#include "workbench_common_lib.glsl"
/* From The Alchemy screen-space ambient obscurance algorithm
@@ -33,7 +33,7 @@ void cavity_compute(vec2 screenco,
return;
}
vec3 position = get_view_space_from_depth(screenco, depth);
vec3 position = drw_point_screen_to_view(vec3(screenco, depth));
vec3 normal = workbench_normal_decode(texture(normalBuffer, screenco));
vec2 jitter_co = (screenco * world_data.viewport_size.xy) * world_data.cavity_jitter_scale;
@@ -73,7 +73,7 @@ void cavity_compute(vec2 screenco,
bool is_background = (s_depth == 1.0);
/* This trick provide good edge effect even if no neighbor is found. */
s_depth = (is_background) ? depth : s_depth;
vec3 s_pos = get_view_space_from_depth(uvcoords, s_depth);
vec3 s_pos = drw_point_screen_to_view(vec3(uvcoords, s_depth));
if (is_background) {
s_pos.z -= world_data.cavity_distance;

View File

@@ -2,7 +2,7 @@
*
* SPDX-License-Identifier: GPL-2.0-or-later */
#include "common_view_lib.glsl"
#include "draw_view_lib.glsl"
#include "workbench_cavity_lib.glsl"
#include "workbench_common_lib.glsl"
#include "workbench_curvature_lib.glsl"
@@ -21,7 +21,8 @@ void main()
}
/* Normal and Incident vector are in view-space. Lighting is evaluated in view-space. */
vec3 V = get_view_vector_from_screen_uv(uv);
vec3 P = drw_point_screen_to_view(vec3(uv, 0.5));
vec3 V = drw_view_incident_vector(P);
vec3 N = workbench_normal_decode(texture(normal_tx, uv));
vec4 mat_data = texture(material_tx, uv);

View File

@@ -8,8 +8,9 @@
* Converted and adapted from HLSL to GLSL by Clément Foucault
*/
#include "common_math_lib.glsl"
#include "common_view_lib.glsl"
#include "draw_view_lib.glsl"
#include "gpu_shader_math_vector_lib.glsl"
#include "gpu_shader_utildefines_lib.glsl"
#define dof_aperturesize dofParams.x
#define dof_distance dofParams.y
@@ -63,8 +64,8 @@ void main()
vec4 cocs_near = calculate_coc(zdepths);
vec4 cocs_far = -cocs_near;
float coc_near = max(max_v4(cocs_near), 0.0);
float coc_far = max(max_v4(cocs_far), 0.0);
float coc_near = max(reduce_max(cocs_near), 0.0);
float coc_far = max(reduce_max(cocs_far), 0.0);
/* now we need to write the near-far fields premultiplied by the coc
* also use bilateral weighting by each coc values to avoid bleeding. */
@@ -109,8 +110,8 @@ void main()
vec4 cocs_near = vec4(cocs1.r, cocs2.r, cocs3.r, cocs4.r) * MAX_COC_SIZE;
vec4 cocs_far = vec4(cocs1.g, cocs2.g, cocs3.g, cocs4.g) * MAX_COC_SIZE;
float coc_near = max_v4(cocs_near);
float coc_far = max_v4(cocs_far);
float coc_near = reduce_max(cocs_near);
float coc_far = reduce_max(cocs_far);
/* now we need to write the near-far fields premultiplied by the coc
* also use bilateral weighting by each coc values to avoid bleeding. */

View File

@@ -2,7 +2,7 @@
*
* SPDX-License-Identifier: GPL-2.0-or-later */
#include "common_view_lib.glsl"
#include "draw_view_lib.glsl"
#include "workbench_common_lib.glsl"
#include "workbench_image_lib.glsl"

View File

@@ -4,7 +4,7 @@
#include "common_hair_lib.glsl"
#include "common_view_clipping_lib.glsl"
#include "common_view_lib.glsl"
#include "draw_view_lib.glsl"
#include "workbench_common_lib.glsl"
#include "workbench_image_lib.glsl"
#include "workbench_material_lib.glsl"
@@ -61,7 +61,7 @@ void main()
thickness,
thick_time);
gl_Position = point_world_to_ndc(world_pos);
gl_Position = drw_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

@@ -2,9 +2,11 @@
*
* SPDX-License-Identifier: GPL-2.0-or-later */
#include "draw_view_lib.glsl"
#include "common_pointcloud_lib.glsl"
#include "common_view_clipping_lib.glsl"
#include "common_view_lib.glsl"
#include "workbench_common_lib.glsl"
#include "workbench_image_lib.glsl"
#include "workbench_material_lib.glsl"
@@ -16,7 +18,7 @@ void main()
normal_interp = normalize(normal_world_to_view(normal_interp));
gl_Position = point_world_to_ndc(world_pos);
gl_Position = drw_point_world_to_homogenous(world_pos);
view_clipping_distances(world_pos);

View File

@@ -3,15 +3,16 @@
* SPDX-License-Identifier: GPL-2.0-or-later */
#include "common_view_clipping_lib.glsl"
#include "common_view_lib.glsl"
#include "draw_model_lib.glsl"
#include "draw_view_lib.glsl"
#include "workbench_common_lib.glsl"
#include "workbench_image_lib.glsl"
#include "workbench_material_lib.glsl"
void main()
{
vec3 world_pos = point_object_to_world(pos);
gl_Position = point_world_to_ndc(world_pos);
vec3 world_pos = drw_point_object_to_world(pos);
gl_Position = drw_point_world_to_homogenous(world_pos);
view_clipping_distances(world_pos);

View File

@@ -54,7 +54,7 @@ void geometry_main(VertOut geom_in[3],
vec3 Ng = cross(v12, v10);
vec3 ls_light_direction = normal_world_to_object(vec3(pass_data.light_direction_ws));
vec3 ls_light_direction = drw_normal_world_to_object(vec3(pass_data.light_direction_ws));
float facing = dot(Ng, ls_light_direction);

View File

@@ -4,7 +4,8 @@
#pragma once
#include "common_view_lib.glsl"
#include "draw_model_lib.glsl"
#include "draw_view_lib.glsl"
#include "gpu_shader_attribute_load_lib.glsl"
#include "gpu_shader_index_load_lib.glsl"
#include "gpu_shader_math_vector_lib.glsl"
@@ -40,7 +41,7 @@ VertOut vertex_main(VertIn vert_in)
vert_out.lP = vert_in.lP;
vec3 L = pass_data.light_direction_ws;
vec3 ws_P = point_object_to_world(vert_in.lP);
vec3 ws_P = drw_point_object_to_world(vert_in.lP);
float extrude_distance = 1e5f;
float L_FP = dot(L, pass_data.far_plane.xyz);
if (L_FP > 0.0) {
@@ -49,8 +50,8 @@ VertOut vertex_main(VertIn vert_in)
/* Ensure we don't overlap the far plane. */
extrude_distance -= 1e-3;
}
vert_out.backPosition = point_world_to_ndc(ws_P + L * extrude_distance);
vert_out.frontPosition = point_object_to_ndc(vert_in.lP);
vert_out.backPosition = drw_point_world_to_homogenous(ws_P + L * extrude_distance);
vert_out.frontPosition = drw_point_world_to_homogenous(drw_point_object_to_world(vert_in.lP));
return vert_out;
}

View File

@@ -66,7 +66,7 @@ void geometry_main(VertOut geom_in[4],
}
#endif
vec3 ls_light_direction = normal_world_to_object(vec3(pass_data.light_direction_ws));
vec3 ls_light_direction = drw_normal_world_to_object(vec3(pass_data.light_direction_ws));
vec2 facing = vec2(dot(n1, ls_light_direction), dot(n2, ls_light_direction));

View File

@@ -3,7 +3,7 @@
* SPDX-License-Identifier: GPL-2.0-or-later */
#include "common_intersect_lib.glsl"
#include "common_math_lib.glsl"
#include "gpu_shader_math_vector_lib.glsl"
shared uint shared_result;

View File

@@ -2,7 +2,7 @@
*
* SPDX-License-Identifier: GPL-2.0-or-later */
#include "common_view_lib.glsl"
#include "draw_view_lib.glsl"
#include "workbench_common_lib.glsl"
#include "workbench_image_lib.glsl"
#include "workbench_matcap_lib.glsl"
@@ -52,7 +52,7 @@ void main()
{
/* Normal and Incident vector are in view-space. Lighting is evaluated in view-space. */
vec2 uv_viewport = gl_FragCoord.xy * world_data.viewport_size_inv;
vec3 I = get_view_vector_from_screen_uv(uv_viewport);
vec3 I = normalize(drw_point_screen_to_view(vec3(uv_viewport, 0.5)));
vec3 N = normalize(normal_interp);
vec3 color = color_interp;

View File

@@ -2,8 +2,9 @@
*
* SPDX-License-Identifier: GPL-2.0-or-later */
#include "common_math_lib.glsl"
#include "common_view_lib.glsl"
#include "draw_model_lib.glsl"
#include "draw_view_lib.glsl"
#include "gpu_shader_math_vector_lib.glsl"
#include "workbench_common_lib.glsl"
float phase_function_isotropic()
@@ -18,7 +19,7 @@ float line_unit_box_intersect_dist(vec3 lineorigin, vec3 linedirection)
vec3 firstplane = (vec3(1.0) - lineorigin) / linedirection;
vec3 secondplane = (vec3(-1.0) - lineorigin) / linedirection;
vec3 furthestplane = min(firstplane, secondplane);
return max_v3(furthestplane);
return reduce_max(furthestplane);
}
#define sample_trilinear(ima, co) texture(ima, co)
@@ -262,14 +263,14 @@ void main()
float depth = do_depth_test ? texelFetch(depthBuffer, ivec2(gl_FragCoord.xy), 0).r : 1.0;
float depth_end = min(depth, gl_FragCoord.z);
vec3 vs_ray_end = get_view_space_from_depth(screen_uv, depth_end);
vec3 vs_ray_ori = get_view_space_from_depth(screen_uv, 0.0);
vec3 vs_ray_end = drw_point_screen_to_view(vec3(screen_uv, depth_end));
vec3 vs_ray_ori = drw_point_screen_to_view(vec3(screen_uv, 0.0));
vec3 vs_ray_dir = (is_persp) ? (vs_ray_end - vs_ray_ori) : vec3(0.0, 0.0, -1.0);
vs_ray_dir /= abs(vs_ray_dir.z);
vec3 ls_ray_dir = point_view_to_object(vs_ray_ori + vs_ray_dir);
vec3 ls_ray_ori = point_view_to_object(vs_ray_ori);
vec3 ls_ray_end = point_view_to_object(vs_ray_end);
vec3 ls_ray_dir = drw_point_view_to_object(vs_ray_ori + vs_ray_dir);
vec3 ls_ray_ori = drw_point_view_to_object(vs_ray_ori);
vec3 ls_ray_end = drw_point_view_to_object(vs_ray_end);
# ifdef VOLUME_SMOKE
ls_ray_dir = (OrcoTexCoFactors[0].xyz + ls_ray_dir * OrcoTexCoFactors[1].xyz) * 2.0 - 1.0;

View File

@@ -2,12 +2,13 @@
*
* SPDX-License-Identifier: GPL-2.0-or-later */
#include "common_view_lib.glsl"
RESOURCE_ID_VARYING
#include "draw_model_lib.glsl"
#include "draw_view_lib.glsl"
void main()
{
drw_ResourceID_iface.resource_index = resource_id;
#ifdef VOLUME_SLICE
if (sliceAxis == 0) {
localPos = vec3(slicePosition * 2.0 - 1.0, pos.xy);
@@ -28,7 +29,5 @@ 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);
PASS_RESOURCE_ID
gl_Position = drw_point_world_to_homogenous(drw_point_object_to_world(final_pos));
}