EEVEE-Next: Remove common lib usage

Replaces all usage by the the gpu_shader_math
equivalent. This is because the old shader
library was quite tangled.

This avoids dependency hell trying to
mix libraries.

Changes are split into isolated commits until
I had to do mass changes because of inter-
dependencies.

Pull Request: https://projects.blender.org/blender/blender/pulls/113631
This commit is contained in:
Clément Foucault
2023-10-13 17:59:46 +02:00
committed by Clément Foucault
parent f7a8536112
commit 71dfcf4558
123 changed files with 1622 additions and 467 deletions

View File

@@ -669,8 +669,12 @@ set(GLSL_SRC
intern/shaders/draw_debug_info.hh
intern/shaders/draw_debug_print_display_frag.glsl
intern/shaders/draw_debug_print_display_vert.glsl
intern/shaders/draw_intersect_lib.glsl
intern/shaders/draw_math_geom_lib.glsl
intern/shaders/draw_model_lib.glsl
intern/shaders/draw_resource_finalize_comp.glsl
intern/shaders/draw_view_finalize_comp.glsl
intern/shaders/draw_view_lib.glsl
intern/shaders/draw_visibility_comp.glsl
intern/draw_command_shared.hh

View File

@@ -331,7 +331,7 @@ static inline float film_filter_weight(float filter_radius, float sample_distanc
float weight = expf(fac * r);
#else
/* Blackman-Harris filter. */
float r = M_2PI * saturate(0.5 + sqrtf(sample_distance_sqr) / (2.0 * filter_radius));
float r = M_TAU * saturate(0.5 + sqrtf(sample_distance_sqr) / (2.0 * filter_radius));
float weight = 0.35875 - 0.48829 * cosf(r) + 0.14128 * cosf(2.0 * r) - 0.01168 * cosf(3.0 * r);
#endif
return weight;
@@ -520,12 +520,12 @@ static inline float view_z_to_volume_z(
}
}
static inline float3 ndc_to_volume(float4x4 projection_matrix,
float near,
float far,
float distribution,
float2 coord_scale,
float3 coord)
static inline float3 screen_to_volume(float4x4 projection_matrix,
float near,
float far,
float distribution,
float2 coord_scale,
float3 coord)
{
bool is_persp = projection_matrix[3][3] == 0.0;

View File

@@ -32,12 +32,12 @@ bool VolumeModule::GridAABB::init(Object *ob, const Camera &camera, const Volume
float3 ndc_coords = math::project_point(projection_matrix * view_matrix, wP);
ndc_coords = (ndc_coords * 0.5f) + float3(0.5f);
float3 grid_coords = ndc_to_volume(projection_matrix,
data.depth_near,
data.depth_far,
data.depth_distribution,
data.coord_scale,
ndc_coords);
float3 grid_coords = screen_to_volume(projection_matrix,
data.depth_near,
data.depth_far,
data.depth_distribution,
data.coord_scale,
ndc_coords);
return int3(grid_coords * float3(data.tex_size));
};

View File

@@ -2,8 +2,11 @@
*
* SPDX-License-Identifier: GPL-2.0-or-later */
#pragma BLENDER_REQUIRE(common_math_lib.glsl)
#pragma BLENDER_REQUIRE(common_math_geom_lib.glsl)
#pragma BLENDER_REQUIRE(draw_view_lib.glsl)
#pragma BLENDER_REQUIRE(gpu_shader_utildefines_lib.glsl)
#pragma BLENDER_REQUIRE(gpu_shader_math_base_lib.glsl)
#pragma BLENDER_REQUIRE(gpu_shader_math_fast_lib.glsl)
#pragma BLENDER_REQUIRE(draw_math_geom_lib.glsl)
#pragma BLENDER_REQUIRE(eevee_sampling_lib.glsl)
#pragma BLENDER_REQUIRE(eevee_ray_types_lib.glsl)
@@ -93,14 +96,14 @@ float ambient_ambient_occlusion_search_horizon(vec3 vI,
if (ssray.max_time <= 2.0) {
/* Produces self shadowing under this threshold. */
return fast_acos(h);
return acos_fast(h);
}
float prev_time, time = 0.0;
for (float iter = 0.0; time < ssray.max_time && iter < sample_count; iter++) {
prev_time = time;
/* Gives us good precision at center and ensure we cross at least one pixel per iteration. */
time = 1.0 + iter + sqr((iter + noise) / sample_count) * ssray.max_time;
time = 1.0 + iter + square((iter + noise) / sample_count) * ssray.max_time;
float stride = time - prev_time;
float lod = (log2(stride) - noise) / (1.0 + uniform_buf.ao.quality);
@@ -116,7 +119,7 @@ float ambient_ambient_occlusion_search_horizon(vec3 vI,
const float bias = 2.0 * 2.4e-7;
depth += (inverted != 0.0) ? -bias : bias;
vec3 s = get_view_space_from_depth(uv, depth);
vec3 s = drw_point_screen_to_view(vec3(uv, depth));
vec3 omega_s = s - vP;
float len = length(omega_s);
/* Sample's horizon angle cosine. */
@@ -124,7 +127,7 @@ float ambient_ambient_occlusion_search_horizon(vec3 vI,
/* Blend weight to fade artifacts. */
float dist_ratio = abs(len) / radius;
/* Sphere falloff. */
float dist_fac = sqr(saturate(dist_ratio));
float dist_fac = square(saturate(dist_ratio));
/* Unbiased, gives too much hard cut behind objects */
// float dist_fac = step(0.999, dist_ratio);
@@ -135,7 +138,7 @@ float ambient_ambient_occlusion_search_horizon(vec3 vI,
h = mix(max(h, s_h), h, dist_fac);
}
}
return fast_acos(h);
return acos_fast(h);
}
OcclusionData ambient_occlusion_search(vec3 vP,
@@ -147,8 +150,8 @@ OcclusionData ambient_occlusion_search(vec3 vP,
{
vec2 noise = ambient_occlusion_get_noise(texel);
vec2 dir = ambient_occlusion_get_dir(noise.x);
vec2 uv = get_uvs_from_view(vP);
vec3 vI = ((ProjectionMatrix[3][3] == 0.0) ? normalize(-vP) : vec3(0.0, 0.0, 1.0));
vec2 uv = drw_point_view_to_screen(vP).xy;
vec3 vI = (drw_view_is_perspective() ? normalize(-vP) : vec3(0.0, 0.0, 1.0));
vec3 avg_dir = vec3(0.0);
float avg_apperture = 0.0;
@@ -211,8 +214,8 @@ void ambient_occlusion_eval(OcclusionData data,
/* No error by default. */
visibility_error = 1.0;
bool early_out = (inverted != 0.0) ? (max_v4(abs(data.horizons)) == 0.0) :
(min_v4(abs(data.horizons)) == M_PI);
bool early_out = (inverted != 0.0) ? (reduce_max(abs(data.horizons)) == 0.0) :
(reduce_min(abs(data.horizons)) == M_PI);
if (early_out) {
visibility = saturate(dot(N, Ng) * 0.5 + 0.5);
visibility = min(visibility, data.custom_occlusion);
@@ -234,13 +237,13 @@ void ambient_occlusion_eval(OcclusionData data,
bent_normal = N * 0.001;
for (int i = 0; i < 2; i++) {
vec3 T = transform_direction(ViewMatrixInverse, vec3(dir, 0.0));
vec3 T = drw_point_view_to_world(vec3(dir, 0.0));
/* Setup integration domain around V. */
vec3 B = normalize(cross(V, T));
T = normalize(cross(B, V));
float proj_N_len;
vec3 proj_N = normalize_len(N - B * dot(N, B), proj_N_len);
vec3 proj_N = normalize_and_get_length(N - B * dot(N, B), proj_N_len);
vec3 proj_Ng = normalize(Ng - B * dot(Ng, B));
vec2 h = (i == 0) ? data.horizons.xy : data.horizons.zw;
@@ -250,8 +253,8 @@ void ambient_occlusion_eval(OcclusionData data,
float N_cos = saturate(dot(proj_N, V));
float Ng_cos = saturate(dot(proj_Ng, V));
/* Gamma, angle between normalized projected normal and view vector. */
float angle_Ng = sign(Ng_sin) * fast_acos(Ng_cos);
float angle_N = sign(N_sin) * fast_acos(N_cos);
float angle_Ng = sign(Ng_sin) * acos_fast(Ng_cos);
float angle_N = sign(N_sin) * acos_fast(N_cos);
/* Clamp horizons to hemisphere around shading normal. */
h = ambient_occlusion_clamp_horizons_to_hemisphere(h, angle_N, inverted);
@@ -285,7 +288,7 @@ void ambient_occlusion_eval(OcclusionData data,
if (AO_BENT_NORMALS) {
/* NOTE: using pow(visibility, 6.0) produces NaN (see #87369). */
float tmp = saturate(pow6(visibility));
float tmp = saturate(pow6f(visibility));
bent_normal = normalize(mix(bent_normal, N, tmp));
}
else {
@@ -379,14 +382,14 @@ float ambient_occlusion_specular(
specular_dir = normalize(mix(specular_dir, visibility_dir, roughness * (1.0 - visibility)));
/* Visibility to cone angle (eq. 18). */
float vis_angle = fast_acos(sqrt(1 - visibility));
float vis_angle = acos_fast(sqrt(1 - visibility));
/* Roughness to cone angle (eq. 26). */
/* A 0.001 min_angle can generate NaNs on Intel GPUs. See D12508. */
const float min_angle = 0.00990998744964599609375;
float spec_angle = max(min_angle, fast_acos(ambient_occlusion_cone_cosine(roughness)));
float spec_angle = max(min_angle, acos_fast(ambient_occlusion_cone_cosine(roughness)));
/* Angle between cone axes. */
float cone_cone_dist = fast_acos(saturate(dot(visibility_dir, specular_dir)));
float cone_nor_dist = fast_acos(saturate(dot(N, specular_dir)));
float cone_cone_dist = acos_fast(saturate(dot(visibility_dir, specular_dir)));
float cone_nor_dist = acos_fast(saturate(dot(N, specular_dir)));
float isect_solid_angle = ambient_occlusion_spherical_cap_intersection(
vis_angle, spec_angle, cone_cone_dist);
@@ -394,7 +397,7 @@ float ambient_occlusion_specular(
M_PI_2, spec_angle, cone_nor_dist);
float specular_occlusion = isect_solid_angle / specular_solid_angle;
/* Mix because it is unstable in unoccluded areas. */
float tmp = saturate(pow8(visibility));
float tmp = saturate(pow8f(visibility));
visibility = mix(specular_occlusion, 1.0, tmp);
return saturate(visibility);

View File

@@ -2,9 +2,7 @@
*
* SPDX-License-Identifier: GPL-2.0-or-later */
#pragma BLENDER_REQUIRE(common_view_lib.glsl)
#pragma BLENDER_REQUIRE(common_math_lib.glsl)
#pragma BLENDER_REQUIRE(common_math_geom_lib.glsl)
#pragma BLENDER_REQUIRE(gpu_shader_math_vector_lib.glsl)
#pragma BLENDER_REQUIRE(eevee_ambient_occlusion_lib.glsl)
/* Similar to https://atyuwen.github.io/posts/normal-reconstruction/.
@@ -27,16 +25,17 @@ vec3 view_position_derivative_from_depth(
/* Fix issue with depth precision. Take even larger diff. */
vec4 diff = abs(vec4(depth_center, H.yzw) - H.x);
if (max_v4(diff) < 2.4e-7 && all(lessThan(diff.xyz, diff.www))) {
return 0.25 * (get_view_space_from_depth(uv3, H.w) - get_view_space_from_depth(uv1, H.x));
if (reduce_max(diff) < 2.4e-7 && all(lessThan(diff.xyz, diff.www))) {
return 0.25 *
(drw_point_screen_to_view(vec3(uv3, H.w)) - drw_point_screen_to_view(vec3(uv1, H.x)));
}
/* Simplified (H.xw + 2.0 * (H.yz - H.xw)) - depth_center */
vec2 deltas = abs((2.0 * H.yz - H.xw) - depth_center);
if (deltas.x < deltas.y) {
return vP - get_view_space_from_depth(uv2, H.y);
return vP - drw_point_screen_to_view(vec3(uv2, H.y));
}
else {
return get_view_space_from_depth(uv3, H.z) - vP;
return drw_point_screen_to_view(vec3(uv3, H.z)) - vP;
}
}
@@ -47,7 +46,7 @@ bool reconstruct_view_position_and_normal_from_depth(
{
float depth_center = texelFetch(depth_tx, ivec2(uv * vec2(extent)), 0).r;
vP = get_view_space_from_depth(uv, depth_center);
vP = drw_point_screen_to_view(vec3(uv, depth_center));
vec3 dPdx = view_position_derivative_from_depth(
depth_tx, extent, uv, ivec2(1, 0), vP, depth_center);
@@ -76,9 +75,9 @@ void main()
return;
}
vec3 P = transform_point(ViewMatrixInverse, vP);
vec3 V = cameraVec(P);
vec3 Ng = transform_direction(ViewMatrixInverse, vNg);
vec3 P = drw_point_view_to_world(vP);
vec3 V = drw_world_incident_vector(P);
vec3 Ng = drw_normal_view_to_world(vNg);
vec3 N = imageLoad(in_normal_img, ivec3(texel, in_normal_img_layer_index)).xyz;
OcclusionData data = ambient_occlusion_search(

View File

@@ -2,8 +2,8 @@
*
* SPDX-License-Identifier: GPL-2.0-or-later */
#pragma BLENDER_REQUIRE(common_view_lib.glsl)
#pragma BLENDER_REQUIRE(common_math_lib.glsl)
#pragma BLENDER_REQUIRE(draw_model_lib.glsl)
#pragma BLENDER_REQUIRE(gpu_shader_math_vector_lib.glsl)
#pragma BLENDER_REQUIRE(gpu_shader_codegen_lib.glsl)
#define EEVEE_ATTRIBUTE_LIB
@@ -33,7 +33,7 @@ vec3 attr_load_orco(vec4 orco)
# endif
vec4 attr_load_tangent(vec4 tangent)
{
tangent.xyz = safe_normalize(normal_object_to_world(tangent.xyz));
tangent.xyz = safe_normalize(drw_normal_object_to_world(tangent.xyz));
return tangent;
}
vec4 attr_load_vec4(vec4 attr)

View File

@@ -6,6 +6,7 @@
* BxDF evaluation functions.
*/
#pragma BLENDER_REQUIRE(gpu_shader_utildefines_lib.glsl)
#pragma BLENDER_REQUIRE(gpu_shader_math_base_lib.glsl)
/* -------------------------------------------------------------------- */

View File

@@ -7,7 +7,7 @@
*/
#pragma BLENDER_REQUIRE(eevee_bxdf_lib.glsl)
#pragma BLENDER_REQUIRE(common_math_geom_lib.glsl)
#pragma BLENDER_REQUIRE(draw_math_geom_lib.glsl)
/* -------------------------------------------------------------------- */
/** \name Microfacet GGX distribution
@@ -17,7 +17,7 @@
float sample_pdf_ggx_reflect(float NH, float NV, float VH, float G1_V, float alpha)
{
float a2 = sqr(alpha);
float a2 = square(alpha);
#if GGX_USE_VISIBLE_NORMAL
return 0.25 * bxdf_ggx_D(NH, a2) * G1_V / NV;
#else
@@ -28,10 +28,10 @@ float sample_pdf_ggx_reflect(float NH, float NV, float VH, float G1_V, float alp
float sample_pdf_ggx_refract(
float NH, float NV, float VH, float LH, float G1_V, float alpha, float eta)
{
float a2 = sqr(alpha);
float a2 = square(alpha);
float D = bxdf_ggx_D(NH, a2);
float Ht2 = sqr(eta * LH + VH);
return (D * G1_V * abs(VH * LH) * sqr(eta)) / (NV * Ht2);
float Ht2 = square(eta * LH + VH);
return (D * G1_V * abs(VH * LH) * square(eta)) / (NV * Ht2);
}
/**
@@ -70,8 +70,8 @@ vec3 sample_ggx(vec3 rand, float alpha, vec3 Vt, out float G1_V)
return Ht;
#else
/* Theta is the cone angle. */
float z = sqrt((1.0 - rand.x) / (1.0 + sqr(alpha) * rand.x - rand.x)); /* cos theta */
float r = sqrt(max(0.0, 1.0 - z * z)); /* sin theta */
float z = sqrt((1.0 - rand.x) / (1.0 + square(alpha) * rand.x - rand.x)); /* cos theta */
float r = sqrt(max(0.0, 1.0 - z * z)); /* sin theta */
float x = r * rand.y;
float y = r * rand.z;
/* Microfacet Normal */

View File

@@ -6,7 +6,7 @@
* Camera projection / uv functions and utils.
*/
#pragma BLENDER_REQUIRE(common_math_lib.glsl)
#pragma BLENDER_REQUIRE(gpu_shader_math_base_lib.glsl)
/* -------------------------------------------------------------------- */
/** \name Panoramic Projections
@@ -68,10 +68,10 @@ vec3 camera_mirror_ball_to_direction(CameraData cam, vec2 uv)
uv = uv * cam.uv_scale + cam.uv_bias;
vec3 dir;
dir.xy = uv * 2.0 - 1.0;
if (len_squared(dir.xy) > 1.0) {
if (length_squared(dir.xy) > 1.0) {
return vec3(0.0);
}
dir.z = -safe_sqrt(1.0 - sqr(dir.x) - sqr(dir.y));
dir.z = -safe_sqrt(1.0 - square(dir.x) - square(dir.y));
const vec3 I = vec3(0.0, 0.0, 1.0);
return reflect(I, dir);
}

View File

@@ -38,3 +38,16 @@ vec4 colorspace_scene_linear_from_YCoCg(vec4 ycocg_color)
}
/** \} */
/**
* Clamp components to avoid black square artifacts if a pixel goes NaN or negative.
* Threshold is arbitrary.
*/
vec4 colorspace_safe_color(vec4 c)
{
return clamp(c, vec4(0.0), vec4(1e20));
}
vec3 colorspace_safe_color(vec3 c)
{
return clamp(c, vec3(0.0), vec3(1e20));
}

View File

@@ -2,8 +2,8 @@
*
* SPDX-License-Identifier: GPL-2.0-or-later */
#pragma BLENDER_REQUIRE(draw_view_lib.glsl)
#pragma BLENDER_REQUIRE(eevee_lightprobe_lib.glsl)
#pragma BLENDER_REQUIRE(common_view_lib.glsl)
void main()
{
@@ -49,7 +49,7 @@ void main()
}
}
gl_Position = point_world_to_ndc(P);
gl_Position = drw_point_world_to_homogenous(P);
gl_Position.z -= 2.5e-5;
gl_PointSize = 3.0;
}

View File

@@ -2,8 +2,8 @@
*
* SPDX-License-Identifier: GPL-2.0-or-later */
#pragma BLENDER_REQUIRE(gpu_shader_debug_gradients_lib.glsl)
#pragma BLENDER_REQUIRE(eevee_sampling_lib.glsl)
#pragma BLENDER_REQUIRE(common_math_lib.glsl)
vec3 debug_random_color(int v)
{

View File

@@ -2,8 +2,8 @@
*
* SPDX-License-Identifier: GPL-2.0-or-later */
#pragma BLENDER_REQUIRE(common_view_lib.glsl)
#pragma BLENDER_REQUIRE(common_math_geom_lib.glsl)
#pragma BLENDER_REQUIRE(draw_view_lib.glsl)
#pragma BLENDER_REQUIRE(gpu_shader_math_matrix_lib.glsl)
void main()
{
@@ -37,17 +37,15 @@ void main()
break;
}
vec3 N = surfel.normal;
vec3 T, B;
make_orthonormal_basis(N, T, B);
mat3x3 TBN = from_up_axis(surfel.normal);
mat4 model_matrix = mat4(vec4(T * debug_surfel_radius, 0),
vec4(B * debug_surfel_radius, 0),
vec4(N * debug_surfel_radius, 0),
mat4 model_matrix = mat4(vec4(TBN[0] * debug_surfel_radius, 0),
vec4(TBN[1] * debug_surfel_radius, 0),
vec4(TBN[2] * debug_surfel_radius, 0),
vec4(surfel.position, 1));
P = (model_matrix * vec4(lP, 1)).xyz;
gl_Position = point_world_to_ndc(P);
gl_Position = drw_point_world_to_homogenous(P);
gl_Position.z -= 2.5e-5;
}

View File

@@ -6,8 +6,8 @@
* Compute light objects lighting contribution using captured Gbuffer data.
*/
#pragma BLENDER_REQUIRE(draw_view_lib.glsl)
#pragma BLENDER_REQUIRE(eevee_gbuffer_lib.glsl)
#pragma BLENDER_REQUIRE(common_view_lib.glsl)
#pragma BLENDER_REQUIRE(eevee_light_eval_lib.glsl)
#pragma BLENDER_REQUIRE(eevee_lightprobe_eval_lib.glsl)
@@ -24,10 +24,10 @@ void main()
stack.cl[0].ltc_mat = LTC_LAMBERT_MAT;
stack.cl[0].type = LIGHT_DIFFUSE;
vec3 P = get_world_space_from_depth(uvcoordsvar.xy, depth);
vec3 P = drw_point_screen_to_world(vec3(uvcoordsvar.xy, depth));
vec3 Ng = stack.cl[0].N;
vec3 V = cameraVec(P);
float vPz = dot(cameraForward, P) - dot(cameraForward, cameraPos);
vec3 V = drw_world_incident_vector(P);
float vPz = dot(drw_view_forward(), P) - dot(drw_view_forward(), drw_view_position());
/* Direct light. */
light_eval(stack, P, Ng, V, vPz, gbuf.thickness);

View File

@@ -6,12 +6,12 @@
* Compute light objects lighting contribution using Gbuffer data.
*/
#pragma BLENDER_REQUIRE(draw_view_lib.glsl)
#pragma BLENDER_REQUIRE(eevee_gbuffer_lib.glsl)
#pragma BLENDER_REQUIRE(eevee_renderpass_lib.glsl)
#pragma BLENDER_REQUIRE(eevee_light_eval_lib.glsl)
#pragma BLENDER_REQUIRE(eevee_thickness_lib.glsl)
#pragma BLENDER_REQUIRE(eevee_subsurface_lib.glsl)
#pragma BLENDER_REQUIRE(common_view_lib.glsl)
void main()
{
@@ -20,8 +20,12 @@ void main()
float depth = texelFetch(hiz_tx, texel, 0).r;
GBufferData gbuf = gbuffer_read(gbuf_header_tx, gbuf_closure_tx, gbuf_color_tx, texel);
vec3 P = get_world_space_from_depth(uvcoordsvar.xy, depth);
vec3 V = cameraVec(P);
vec3 P = drw_point_screen_to_world(vec3(uvcoordsvar.xy, depth));
/* Assume reflection closure normal is always somewhat representative of the geometric normal.
* Ng is only used for shadow biases and subsurface check in this case. */
vec3 Ng = gbuf.has_reflection ? gbuf.reflection.N : gbuf.diffuse.N;
vec3 V = drw_world_incident_vector(P);
float vPz = dot(drw_view_forward(), P) - dot(drw_view_forward(), drw_view_position());
ClosureLightStack stack;
@@ -45,11 +49,6 @@ void main()
stack.cl[2] = cl_sss;
#endif
/* Assume reflection closure normal is always somewhat representative of the geometric normal.
* Ng is only used for shadow biases and subsurface check in this case. */
vec3 Ng = gbuf.has_reflection ? gbuf.reflection.N : gbuf.diffuse.N;
float vPz = dot(cameraForward, P) - dot(cameraForward, cameraPos);
#ifdef SSS_TRANSMITTANCE
float shadow_thickness = thickness_from_shadow(P, Ng, vPz);
float thickness = (shadow_thickness != THICKNESS_NO_VALUE) ?
@@ -90,7 +89,7 @@ void main()
/* TODO(fclem): Change shadow pass to be colored. */
vec3 shadows = radiance_shadowed * safe_rcp(radiance_unshadowed);
output_renderpass_value(uniform_buf.render_pass.shadow_id, avg(shadows));
output_renderpass_value(uniform_buf.render_pass.shadow_id, average(shadows));
imageStore(direct_diffuse_img, texel, vec4(radiance_diffuse, 1.0));
imageStore(direct_reflect_img, texel, vec4(radiance_specular, 1.0));

View File

@@ -6,8 +6,8 @@
* Compute light objects lighting contribution using captured Gbuffer data.
*/
#pragma BLENDER_REQUIRE(draw_view_lib.glsl)
#pragma BLENDER_REQUIRE(eevee_gbuffer_lib.glsl)
#pragma BLENDER_REQUIRE(common_view_lib.glsl)
#pragma BLENDER_REQUIRE(eevee_light_eval_lib.glsl)
#pragma BLENDER_REQUIRE(eevee_lightprobe_eval_lib.glsl)
@@ -19,10 +19,10 @@ void main()
GBufferData gbuf = gbuffer_read(gbuf_header_tx, gbuf_closure_tx, gbuf_color_tx, texel);
vec3 P = get_world_space_from_depth(uvcoordsvar.xy, depth);
vec3 P = drw_point_screen_to_world(vec3(uvcoordsvar.xy, depth));
vec3 Ng = gbuf.diffuse.N;
vec3 V = cameraVec(P);
float vPz = dot(cameraForward, P) - dot(cameraForward, cameraPos);
vec3 V = drw_world_incident_vector(P);
float vPz = dot(drw_view_forward(), P) - dot(drw_view_forward(), drw_view_position());
ClosureLightStack stack;
stack.cl[0].N = gbuf.diffuse.N;

View File

@@ -8,10 +8,12 @@
* One is for the half-resolution gather passes and the other one for slight in focus regions.
*/
#pragma BLENDER_REQUIRE(common_view_lib.glsl)
#pragma BLENDER_REQUIRE(gpu_shader_debug_gradients_lib.glsl)
#pragma BLENDER_REQUIRE(draw_view_lib.glsl)
#pragma BLENDER_REQUIRE(gpu_shader_math_matrix_lib.glsl)
#pragma BLENDER_REQUIRE(eevee_colorspace_lib.glsl)
#pragma BLENDER_REQUIRE(eevee_sampling_lib.glsl)
#pragma BLENDER_REQUIRE(eevee_depth_of_field_lib.glsl)
#pragma BLENDER_REQUIRE(eevee_sampling_lib.glsl)
/* -------------------------------------------------------------------- */
/** \name Options.
@@ -316,7 +318,7 @@ void dof_gather_accumulate_center_sample(DofGatherData center_data,
if (is_foreground && !is_resolve) {
/* Reduce issue with closer foreground over distant foreground. */
float ring_area = sqr(bordering_radius);
float ring_area = square(bordering_radius);
dof_gather_ammend_weight(center_data, ring_area);
}
@@ -468,7 +470,7 @@ void dof_gather_accumulator(sampler2D color_tx,
int sample_pair_count = gather_ring_density * ring;
float step_rot = M_PI / float(sample_pair_count);
mat2 step_rot_mat = rot2_from_angle(step_rot);
mat2 step_rot_mat = from_rotation(Angle(step_rot));
float angle_offset = noise.y * step_rot;
vec2 offset = vec2(cos(angle_offset), sin(angle_offset));
@@ -516,9 +518,9 @@ void dof_gather_accumulator(sampler2D color_tx,
if (is_foreground) {
/* Reduce issue with closer foreground over distant foreground. */
/* TODO(fclem) this seems to not be completely correct as the issue remains. */
float ring_area = (sqr(float(ring) + 0.5 + coc_radius_error) -
sqr(float(ring) - 0.5 + coc_radius_error)) *
sqr(base_radius * unit_sample_radius);
float ring_area = (square(float(ring) + 0.5 + coc_radius_error) -
square(float(ring) - 0.5 + coc_radius_error)) *
square(base_radius * unit_sample_radius);
dof_gather_ammend_weight(ring_data, ring_area);
}
@@ -574,13 +576,13 @@ void dof_gather_accumulator(sampler2D color_tx,
if (debug_gather_perf && density_change > 0) {
float fac = saturate(float(density_change) / float(10.0));
out_color.rgb = avg(out_color.rgb) * neon_gradient(fac);
out_color.rgb = average(out_color.rgb) * neon_gradient(fac);
}
if (debug_gather_perf && do_fast_gather) {
out_color.rgb = avg(out_color.rgb) * vec3(0.0, 1.0, 0.0);
out_color.rgb = average(out_color.rgb) * vec3(0.0, 1.0, 0.0);
}
if (debug_scatter_perf) {
out_color.rgb = avg(out_color.rgb) * vec3(0.0, 1.0, 0.0);
out_color.rgb = average(out_color.rgb) * vec3(0.0, 1.0, 0.0);
}
/* Output premultiplied color so we can use bilinear sampler in resolve pass. */
@@ -616,7 +618,7 @@ void dof_slight_focus_gather(depth2D depth_tx,
const float sample_count_max = float(DOF_SLIGHT_FOCUS_SAMPLE_MAX);
/* Scale by search area. */
float sample_count = sample_count_max * saturate(sqr(radius) / sqr(dof_layer_threshold));
float sample_count = sample_count_max * saturate(square(radius) / square(dof_layer_threshold));
bool first_ring = true;
@@ -632,7 +634,7 @@ void dof_slight_focus_gather(depth2D depth_tx,
vec2 sample_uv = (frag_coord + sample_offset) / vec2(textureSize(depth_tx, 0));
float depth = textureLod(depth_tx, sample_uv, 0.0).r;
pair_data[i].coc = dof_coc_from_depth(dof_buf, sample_uv, depth);
pair_data[i].color = safe_color(textureLod(color_tx, sample_uv, 0.0));
pair_data[i].color = colorspace_safe_color(textureLod(color_tx, sample_uv, 0.0));
pair_data[i].dist = ring_dist;
if (DOF_BOKEH_TEXTURE) {
/* Contains sub-pixel distance to bokeh shape. */
@@ -668,7 +670,7 @@ void dof_slight_focus_gather(depth2D depth_tx,
/* Center sample. */
vec2 sample_uv = frag_coord / vec2(textureSize(depth_tx, 0));
DofGatherData center_data;
center_data.color = safe_color(textureLod(color_tx, sample_uv, 0.0));
center_data.color = colorspace_safe_color(textureLod(color_tx, sample_uv, 0.0));
center_data.coc = dof_coc_from_depth(dof_buf, sample_uv, textureLod(depth_tx, sample_uv, 0.0).r);
center_data.coc = clamp(center_data.coc, -dof_buf.coc_abs_max, dof_buf.coc_abs_max);
center_data.dist = 0.0;

View File

@@ -24,7 +24,7 @@ void main()
if (dof_buf.bokeh_blades > 0.0) {
/* NOTE: atan(y,x) has output range [-M_PI..M_PI], so add 2pi to avoid negative angles. */
float theta = atan(gather_uv.y, gather_uv.x) + M_2PI;
float theta = atan(gather_uv.y, gather_uv.x) + M_TAU;
float r = length(gather_uv);
radius /= circle_to_polygon_radius(dof_buf.bokeh_blades, theta - dof_buf.bokeh_rotation);
@@ -39,7 +39,7 @@ void main()
{
/* Slight focus distance */
slight_focus_texel *= dof_buf.bokeh_anisotropic_scale_inv;
float theta = atan(slight_focus_texel.y, -slight_focus_texel.x) + M_2PI;
float theta = atan(slight_focus_texel.y, -slight_focus_texel.x) + M_TAU;
slight_focus_texel /= circle_to_polygon_radius(dof_buf.bokeh_blades,
theta + dof_buf.bokeh_rotation);
}

View File

@@ -9,6 +9,7 @@
* Also does not weight luma for the bilateral weights.
*/
#pragma BLENDER_REQUIRE(gpu_shader_math_vector_lib.glsl)
#pragma BLENDER_REQUIRE(eevee_depth_of_field_lib.glsl)
void main()
@@ -27,7 +28,7 @@ void main()
vec4 weights = dof_bilateral_coc_weights(cocs);
/* Normalize so that the sum is 1. */
weights *= safe_rcp(sum(weights));
weights *= safe_rcp(reduce_add(weights));
vec4 out_color = weighted_sum_array(colors, weights);

View File

@@ -6,8 +6,9 @@
* Depth of Field utils.
*/
#pragma BLENDER_REQUIRE(common_view_lib.glsl)
#pragma BLENDER_REQUIRE(common_math_lib.glsl)
#pragma BLENDER_REQUIRE(draw_view_lib.glsl)
#pragma BLENDER_REQUIRE(gpu_shader_utildefines_lib.glsl)
#pragma BLENDER_REQUIRE(gpu_shader_math_base_lib.glsl)
/* -------------------------------------------------------------------- */
/** \name Constants.
@@ -114,10 +115,10 @@ float dof_coc_from_depth(DepthOfFieldData dof_data, vec2 uv, float depth)
{
if (is_panoramic(dof_data.camera_type)) {
/* Use radial depth. */
depth = -length(get_view_space_from_depth(uv, depth));
depth = -length(drw_point_screen_to_view(vec3(uv, depth)));
}
else {
depth = get_view_z_from_depth(depth);
depth = drw_depth_screen_to_view(depth);
}
return coc_radius_from_camera_depth(dof_data, depth);
}
@@ -153,7 +154,7 @@ vec4 dof_layer_weight(vec4 coc)
float dof_sample_weight(float coc)
{
#if 1 /* Optimized */
return min(1.0, 1.0 / sqr(coc));
return min(1.0, 1.0 / square(coc));
#else
/* Full intensity if CoC radius is below the pixel footprint. */
const float min_coc = 1.0;
@@ -164,7 +165,7 @@ float dof_sample_weight(float coc)
vec4 dof_sample_weight(vec4 coc)
{
#if 1 /* Optimized */
return min(vec4(1.0), 1.0 / sqr(coc));
return min(vec4(1.0), 1.0 / square(coc));
#else
/* Full intensity if CoC radius is below the pixel footprint. */
const float min_coc = 1.0;

View File

@@ -16,6 +16,7 @@
*/
#pragma BLENDER_REQUIRE(eevee_depth_of_field_lib.glsl)
#pragma BLENDER_REQUIRE(gpu_shader_math_vector_lib.glsl)
/* NOTE: Do not compare alpha as it is not scattered by the scatter pass. */
float dof_scatter_neighborhood_rejection(vec3 color)
@@ -34,7 +35,7 @@ float dof_scatter_neighborhood_rejection(vec3 color)
vec3 ref = textureLod(downsample_tx, sample_uv, 0.0).rgb;
ref = min(vec3(dof_buf.scatter_neighbor_max_color), ref);
float diff = max_v3(max(vec3(0.0), abs(ref - color)));
float diff = reduce_max(max(vec3(0.0), abs(ref - color)));
const float rejection_threshold = 0.7;
diff = saturate(diff / rejection_threshold - 1.0);
@@ -51,7 +52,7 @@ float dof_scatter_screen_border_rejection(float coc, ivec2 texel)
vec2 screen_size = vec2(imageSize(inout_color_lod0_img));
vec2 uv = (vec2(texel) + 0.5) / screen_size;
vec2 screen_pos = uv * screen_size;
float min_screen_border_distance = min_v2(min(screen_pos, screen_size - screen_pos));
float min_screen_border_distance = reduce_min(min(screen_pos, screen_size - screen_pos));
/* Full-resolution to half-resolution CoC. */
coc *= 0.5;
/* Allow 10px transition. */
@@ -62,7 +63,7 @@ float dof_scatter_screen_border_rejection(float coc, ivec2 texel)
float dof_scatter_luminosity_rejection(vec3 color)
{
const float rejection_hardness = 1.0;
return saturate(max_v3(color - dof_buf.scatter_color_threshold) * rejection_hardness);
return saturate(reduce_max(color - dof_buf.scatter_color_threshold) * rejection_hardness);
}
float dof_scatter_coc_radius_rejection(float coc)
@@ -118,7 +119,7 @@ void main()
do_scatter4.w = do_scatter[LOCAL_OFFSET(0, 0)];
if (any(greaterThan(do_scatter4, vec4(0.0)))) {
/* Apply energy conservation to anamorphic scattered bokeh. */
do_scatter4 *= max_v2(dof_buf.bokeh_anisotropic_scale_inv);
do_scatter4 *= reduce_max(dof_buf.bokeh_anisotropic_scale_inv);
/* Circle of Confusion. */
vec4 coc4;
@@ -132,7 +133,7 @@ void main()
vec2 offset = vec2(gl_GlobalInvocationID.xy) + 1;
/* Add 2.5 to max_coc because the max_coc may not be centered on the sprite origin
* and because we smooth the bokeh shape a bit in the pixel shader. */
vec2 half_extent = max_v4(abs(coc4)) * dof_buf.bokeh_anisotropic_scale + 2.5;
vec2 half_extent = reduce_max(abs(coc4)) * dof_buf.bokeh_anisotropic_scale + 2.5;
/* Issue a sprite for each field if any CoC matches. */
if (any(lessThan(do_scatter4 * sign(coc4), vec4(0.0)))) {
/* Same value for all threads. Not an issue if we don't sync access to it. */
@@ -226,7 +227,7 @@ void main()
vec4 weights = dof_bilateral_coc_weights(coc4);
weights *= dof_bilateral_color_weights(colors);
/* Normalize so that the sum is 1. */
weights *= safe_rcp(sum(weights));
weights *= safe_rcp(reduce_add(weights));
color_cache[LOCAL_INDEX] = weighted_sum_array(colors, weights);
coc_cache[LOCAL_INDEX] = dot(coc4, weights);

View File

@@ -72,11 +72,11 @@ vec3 dof_neighborhood_clamp(vec2 frag_coord, vec3 color, float center_coc, float
neighbor_max = (i == 0) ? ycocg_sample : max(neighbor_max, ycocg_sample);
}
/* Pad the bounds in the near in focus region to get back a bit of detail. */
float padding = 0.125 * saturate(1.0 - sqr(center_coc) / sqr(8.0));
float padding = 0.125 * saturate(1.0 - square(center_coc) / square(8.0));
neighbor_max += abs(neighbor_min) * padding;
neighbor_min -= abs(neighbor_min) * padding;
/* Progressively apply the clamp to avoid harsh transition. Also mask by weight. */
float fac = saturate(sqr(center_coc) * 4.0) * weight;
float fac = saturate(square(center_coc) * 4.0) * weight;
/* Clamp in YCoCg space to avoid too much color drift. */
color = colorspace_YCoCg_from_scene_linear(color);
color = mix(color, clamp(color, neighbor_min, neighbor_max), fac);
@@ -154,7 +154,7 @@ void main()
}
if (!no_focus_pass && prediction.do_focus) {
layer_color = safe_color(textureLod(color_tx, uv, 0.0));
layer_color = colorspace_safe_color(textureLod(color_tx, uv, 0.0));
layer_weight = 1.0;
/* Composite in focus. */
out_color = out_color * (1.0 - layer_weight) + layer_color;

View File

@@ -10,6 +10,7 @@
*/
#pragma BLENDER_REQUIRE(eevee_depth_of_field_lib.glsl)
#pragma BLENDER_REQUIRE(gpu_shader_math_vector_lib.glsl)
#define linearstep(p0, p1, v) (clamp(((v) - (p0)) / abs((p1) - (p0)), 0.0, 1.0))
@@ -38,7 +39,7 @@ void main()
/* Smooth the edges a bit to fade out the undersampling artifacts. */
shapes = saturate(1.0 - linearstep(-0.8, 0.8, shapes));
/* Outside of bokeh shape. Try to avoid overloading ROPs. */
if (max_v4(shapes) == 0.0) {
if (reduce_max(shapes) == 0.0) {
discard;
return;
}
@@ -52,7 +53,7 @@ void main()
/* Occlude the sprite with geometry from the same field using a chebychev test (slide 85). */
float mean = occlusion_data.x;
float variance = occlusion_data.y;
shapes *= variance * safe_rcp(variance + sqr(max(coc4 * correction_fac - mean, 0.0)));
shapes *= variance * safe_rcp(variance + square(max(coc4 * correction_fac - mean, 0.0)));
}
out_color = (interp_flat.color_and_coc1 * shapes[0] + interp_flat.color_and_coc2 * shapes[1] +
@@ -61,6 +62,6 @@ void main()
out_color.a = 0.0;
if (debug_scatter_perf) {
out_color.rgb = avg(out_color.rgb) * vec3(1.0, 0.0, 0.0);
out_color.rgb = average(out_color.rgb) * vec3(1.0, 0.0, 0.0);
}
}

View File

@@ -10,6 +10,7 @@
*/
#pragma BLENDER_REQUIRE(eevee_depth_of_field_lib.glsl)
#pragma BLENDER_REQUIRE(gpu_shader_math_vector_lib.glsl)
void main()
{
@@ -36,7 +37,7 @@ void main()
interp_noperspective.rect_uv3 = ((uv + quad_offsets[2]) * uv_div) * 0.5 + 0.5;
interp_noperspective.rect_uv4 = ((uv + quad_offsets[3]) * uv_div) * 0.5 + 0.5;
/* Only for sampling. */
interp_flat.distance_scale *= max_v2(abs(rect.half_extent));
interp_flat.distance_scale *= reduce_max(abs(rect.half_extent));
}
else {
interp_flat.distance_scale = 1.0;

View File

@@ -14,9 +14,10 @@
* Half-resolution Color, signed CoC (out_coc.x), and max slight focus abs CoC (out_coc.y).
*/
#pragma BLENDER_REQUIRE(common_math_lib.glsl)
#pragma BLENDER_REQUIRE(common_view_lib.glsl)
#pragma BLENDER_REQUIRE(draw_view_lib.glsl)
#pragma BLENDER_REQUIRE(eevee_depth_of_field_lib.glsl)
#pragma BLENDER_REQUIRE(eevee_colorspace_lib.glsl)
#pragma BLENDER_REQUIRE(gpu_shader_math_vector_lib.glsl)
void main()
{
@@ -29,7 +30,7 @@ void main()
for (int i = 0; i < 4; i++) {
vec2 sample_uv = quad_center + quad_offsets[i] * fullres_texel_size;
/* NOTE: We use samplers without filtering. */
colors[i] = safe_color(textureLod(color_tx, sample_uv, 0.0));
colors[i] = colorspace_safe_color(textureLod(color_tx, sample_uv, 0.0));
cocs[i] = dof_coc_from_depth(dof_buf, sample_uv, textureLod(depth_tx, sample_uv, 0.0).r);
}
@@ -38,7 +39,7 @@ void main()
vec4 weights = dof_bilateral_coc_weights(cocs);
weights *= dof_bilateral_color_weights(colors);
/* Normalize so that the sum is 1. */
weights *= safe_rcp(sum(weights));
weights *= safe_rcp(reduce_add(weights));
ivec2 out_texel = ivec2(gl_GlobalInvocationID.xy);
vec4 out_color = weighted_sum_array(colors, weights);

View File

@@ -17,7 +17,6 @@
* - Stabilized Color and CoC (half-resolution).
*/
#pragma BLENDER_REQUIRE(common_math_geom_lib.glsl)
#pragma BLENDER_REQUIRE(eevee_colorspace_lib.glsl)
#pragma BLENDER_REQUIRE(eevee_depth_of_field_lib.glsl)
#pragma BLENDER_REQUIRE(eevee_velocity_lib.glsl)
@@ -263,7 +262,7 @@ DofSample dof_sample_history(vec2 input_texel)
color += textureLod(in_history_tx, vec2(uv_3.x, uv_12.y), 0.0) * weight_cross.z;
color += textureLod(in_history_tx, vec2(uv_12.x, uv_3.y), 0.0) * weight_cross.w;
/* Re-normalize for the removed corners. */
color /= (weight_center + sum(weight_cross));
color /= (weight_center + reduce_add(weight_cross));
#endif
/* NOTE(fclem): Opacity is wrong on purpose. Final Opacity does not rely on history. */
return DofSample(color.xyzz, color.w);
@@ -306,7 +305,7 @@ float dof_history_blend_factor(
* "High Quality Temporal Supersampling" by Brian Karis at Siggraph 2014 (Slide 43)
* Bias towards history if incoming pixel is near clamping. Reduces flicker.
*/
float distance_to_luma_clip = min_v2(vec2(luma_history - luma_min, luma_max - luma_history));
float distance_to_luma_clip = reduce_min(vec2(luma_history - luma_min, luma_max - luma_history));
/* Divide by bbox size to get a factor. 2 factor to compensate the line above. */
distance_to_luma_clip *= 2.0 * safe_rcp(luma_max - luma_min);
/* Linearly blend when history gets below to 25% of the bbox size. */

View File

@@ -3,8 +3,8 @@
* SPDX-License-Identifier: GPL-2.0-or-later */
#pragma BLENDER_REQUIRE(eevee_spherical_harmonics_lib.glsl)
#pragma BLENDER_REQUIRE(common_view_lib.glsl)
#pragma BLENDER_REQUIRE(common_math_lib.glsl)
#pragma BLENDER_REQUIRE(gpu_shader_math_matrix_lib.glsl)
#pragma BLENDER_REQUIRE(draw_view_lib.glsl)
void main()
{
@@ -24,7 +24,7 @@ void main()
float validity = texelFetch(validity_tx, cell, 0).r;
vec3 vN = vec3(lP, sqrt(max(0.0, 1.0 - dist_sqr)));
vec3 N = normal_view_to_world(vN);
vec3 N = drw_normal_view_to_world(vN);
vec3 lN = transform_direction(world_to_grid, N);
vec3 irradiance = spherical_harmonics_evaluate_lambert(lN, sh);

View File

@@ -2,7 +2,7 @@
*
* SPDX-License-Identifier: GPL-2.0-or-later */
#pragma BLENDER_REQUIRE(common_view_lib.glsl)
#pragma BLENDER_REQUIRE(draw_view_lib.glsl)
#pragma BLENDER_REQUIRE(eevee_lightprobe_lib.glsl)
void main()
@@ -35,9 +35,9 @@ void main()
}
vec3 vs_offset = vec3(lP, 0.0) * sphere_radius_final;
vec3 vP = (ViewMatrix * vec4(ws_cell_pos, 1.0)).xyz + vs_offset;
vec3 vP = drw_point_world_to_view(ws_cell_pos) + vs_offset;
gl_Position = ProjectionMatrix * vec4(vP, 1.0);
gl_Position = drw_point_view_to_homogenous(vP);
/* Small bias to let the icon draw without Z-fighting. */
gl_Position.z += 0.0001;
}

View File

@@ -2,7 +2,6 @@
*
* SPDX-License-Identifier: GPL-2.0-or-later */
#pragma BLENDER_REQUIRE(common_view_lib.glsl)
#pragma BLENDER_REQUIRE(eevee_film_lib.glsl)
void main()

View File

@@ -2,7 +2,7 @@
*
* SPDX-License-Identifier: GPL-2.0-or-later */
#pragma BLENDER_REQUIRE(common_math_lib.glsl)
#pragma BLENDER_REQUIRE(gpu_shader_math_base_lib.glsl)
#define CRYPTOMATTE_LEVELS_MAX 16

View File

@@ -2,7 +2,6 @@
*
* SPDX-License-Identifier: GPL-2.0-or-later */
#pragma BLENDER_REQUIRE(common_view_lib.glsl)
#pragma BLENDER_REQUIRE(eevee_film_lib.glsl)
void main()
@@ -33,7 +32,7 @@ void main()
film_process_data(texel_film, out_color, out_depth);
}
gl_FragDepth = get_depth_from_view_z(-out_depth);
gl_FragDepth = drw_depth_view_to_screen(-out_depth);
gl_FragDepth = film_display_depth_ammend(texel_film, gl_FragDepth);
}

View File

@@ -6,12 +6,12 @@
* Film accumulation utils functions.
*/
#pragma BLENDER_REQUIRE(common_view_lib.glsl)
#pragma BLENDER_REQUIRE(common_math_geom_lib.glsl)
#pragma BLENDER_REQUIRE(eevee_camera_lib.glsl)
#pragma BLENDER_REQUIRE(eevee_velocity_lib.glsl)
#pragma BLENDER_REQUIRE(draw_view_lib.glsl)
#pragma BLENDER_REQUIRE(eevee_colorspace_lib.glsl)
#pragma BLENDER_REQUIRE(eevee_cryptomatte_lib.glsl)
#pragma BLENDER_REQUIRE(gpu_shader_math_vector_lib.glsl)
#pragma BLENDER_REQUIRE(draw_math_geom_lib.glsl)
#pragma BLENDER_REQUIRE(eevee_velocity_lib.glsl)
/* Return scene linear Z depth from the camera or radial depth for panoramic cameras. */
float film_depth_convert_to_scene(float depth)
@@ -20,7 +20,7 @@ float film_depth_convert_to_scene(float depth)
/* TODO */
return 1.0;
}
return abs(get_view_z_from_depth(depth));
return abs(drw_depth_screen_to_view(depth));
}
/* Load a texture sample in a specific format. Combined pass needs to use this. */
@@ -70,7 +70,7 @@ FilmSample film_sample_get(int sample_n, ivec2 texel_film)
* can be used by many final pixel. */
vec2 offset = uniform_buf.film.subpixel_offset -
vec2(texel_film % uniform_buf.film.scaling_factor);
film_sample.weight = film_filter_weight(uniform_buf.film.filter_size, len_squared(offset));
film_sample.weight = film_filter_weight(uniform_buf.film.filter_size, length_squared(offset));
# endif
#endif /* PANORAMIC */
@@ -119,7 +119,7 @@ void film_sample_accum_mist(FilmSample samp, inout float accum)
}
float depth = texelFetch(depth_tx, samp.texel, 0).x;
vec2 uv = (vec2(samp.texel) + 0.5) / vec2(textureSize(depth_tx, 0).xy);
vec3 vP = get_view_space_from_depth(uv, depth);
vec3 vP = drw_point_screen_to_view(vec3(uv, depth));
bool is_persp = ProjectionMatrix[3][3] == 0.0;
float mist = (is_persp) ? length(vP) : abs(vP.z);
/* Remap to 0..1 range. */
@@ -312,7 +312,7 @@ vec4 film_sample_catmull_rom(sampler2D color_tx, vec2 input_texel)
color += textureLod(color_tx, vec2(uv_3.x, uv_12.y), 0.0) * weight_cross.z;
color += textureLod(color_tx, vec2(uv_12.x, uv_3.y), 0.0) * weight_cross.w;
/* Re-normalize for the removed corners. */
return color / (weight_center + sum(weight_cross));
return color / (weight_center + reduce_add(weight_cross));
#else /* Nearest interpolation for debugging. 1 Tap. */
ivec2 texel = ivec2(center_texel) + ivec2(greaterThan(inter_texel, vec2(0.5)));
@@ -343,7 +343,7 @@ void film_combined_neighbor_boundbox(ivec2 texel, out vec4 min_c, out vec4 max_c
for (int i = 0; i < 5; i++) {
vec4 color = film_texelfetch_as_YCoCg_opacity(combined_tx, texel + plus_offsets[i]);
mu1 += color;
mu2 += sqr(color);
mu2 += square(color);
}
mu1 *= (1.0 / 5.0);
mu2 *= (1.0 / 5.0);
@@ -352,7 +352,7 @@ void film_combined_neighbor_boundbox(ivec2 texel, out vec4 min_c, out vec4 max_c
* Balance between more flickering (0.75) or more ghosting (1.25). */
const float gamma = 1.25;
/* Standard deviation. */
vec4 sigma = sqrt(abs(mu2 - sqr(mu1)));
vec4 sigma = sqrt(abs(mu2 - square(mu1)));
/* eq. 6 in "A Survey of Temporal Anti-aliasing Techniques". */
min_c = mu1 - gamma * sigma;
max_c = mu1 + gamma * sigma;
@@ -425,7 +425,7 @@ float film_history_blend_factor(float velocity,
* "High Quality Temporal Supersampling" by Brian Karis at Siggraph 2014 (Slide 43)
* Bias towards history if incoming pixel is near clamping. Reduces flicker.
*/
float distance_to_luma_clip = min_v2(vec2(luma_history - luma_min, luma_max - luma_history));
float distance_to_luma_clip = reduce_min(vec2(luma_history - luma_min, luma_max - luma_history));
/* Divide by bbox size to get a factor. 2 factor to compensate the line above. */
distance_to_luma_clip *= 2.0 * safe_rcp(luma_max - luma_min);
/* Linearly blend when history gets below to 25% of the bbox size. */

View File

@@ -2,13 +2,12 @@
*
* SPDX-License-Identifier: GPL-2.0-or-later */
#pragma BLENDER_REQUIRE(common_hair_lib.glsl) /* TODO rename to curve. */
#pragma BLENDER_REQUIRE(common_math_lib.glsl)
#pragma BLENDER_REQUIRE(common_view_lib.glsl)
#pragma BLENDER_REQUIRE(draw_model_lib.glsl)
#pragma BLENDER_REQUIRE(eevee_attributes_lib.glsl)
#pragma BLENDER_REQUIRE(eevee_nodetree_lib.glsl)
#pragma BLENDER_REQUIRE(eevee_surf_lib.glsl)
#pragma BLENDER_REQUIRE(eevee_velocity_lib.glsl)
#pragma BLENDER_REQUIRE(common_hair_lib.glsl) /* TODO rename to curve. */
void main()
{
@@ -58,5 +57,5 @@ void main()
clip_interp.clip_distance = dot(clip_plane.plane, vec4(interp.P, 1.0));
#endif
gl_Position = point_world_to_ndc(interp.P);
gl_Position = drw_point_world_to_homogenous(interp.P);
}

View File

@@ -2,8 +2,9 @@
*
* SPDX-License-Identifier: GPL-2.0-or-later */
#pragma BLENDER_REQUIRE(common_gpencil_lib.glsl)
#pragma BLENDER_REQUIRE(common_view_lib.glsl)
#pragma BLENDER_REQUIRE(draw_model_lib.glsl)
/* Grease pencil includes commmon_view_lib. */
// #pragma BLENDER_REQUIRE(common_gpencil_lib.glsl)
#pragma BLENDER_REQUIRE(eevee_attributes_lib.glsl)
#pragma BLENDER_REQUIRE(eevee_surf_lib.glsl)
#pragma BLENDER_REQUIRE(eevee_velocity_lib.glsl)
@@ -38,7 +39,7 @@ void main()
hardness);
#ifdef MAT_VELOCITY
/* GPencil do not support deformation motion blur. */
vec3 lP_curr = transform_point(ModelMatrixInverse, interp.P);
vec3 lP_curr = drw_point_world_to_object(interp.P);
/* FIXME(fclem): Evaluating before displacement avoid displacement being treated as motion but
* ignores motion from animated displacement. Supporting animated displacement motion vectors
* would require evaluating the node-tree multiple time with different node-tree UBOs evaluated

View File

@@ -2,7 +2,7 @@
*
* SPDX-License-Identifier: GPL-2.0-or-later */
#pragma BLENDER_REQUIRE(common_view_lib.glsl)
#pragma BLENDER_REQUIRE(draw_model_lib.glsl)
#pragma BLENDER_REQUIRE(eevee_attributes_lib.glsl)
#pragma BLENDER_REQUIRE(eevee_nodetree_lib.glsl)
#pragma BLENDER_REQUIRE(eevee_surf_lib.glsl)
@@ -17,8 +17,8 @@ void main()
init_interface();
interp.P = point_object_to_world(pos);
interp.N = normal_object_to_world(nor);
interp.P = drw_point_object_to_world(pos);
interp.N = drw_normal_object_to_world(nor);
#ifdef MAT_VELOCITY
vec3 prv, nxt;
velocity_local_pos_get(pos, gl_VertexID, prv, nxt);
@@ -39,5 +39,5 @@ void main()
clip_interp.clip_distance = dot(clip_plane.plane, vec4(interp.P, 1.0));
#endif
gl_Position = point_world_to_ndc(interp.P);
gl_Position = drw_point_world_to_homogenous(interp.P);
}

View File

@@ -2,13 +2,13 @@
*
* SPDX-License-Identifier: GPL-2.0-or-later */
#pragma BLENDER_REQUIRE(draw_model_lib.glsl)
#pragma BLENDER_REQUIRE(gpu_shader_math_rotation_lib.glsl)
#pragma BLENDER_REQUIRE(common_pointcloud_lib.glsl)
#pragma BLENDER_REQUIRE(common_view_lib.glsl)
#pragma BLENDER_REQUIRE(eevee_attributes_lib.glsl)
#pragma BLENDER_REQUIRE(eevee_nodetree_lib.glsl)
#pragma BLENDER_REQUIRE(eevee_surf_lib.glsl)
#pragma BLENDER_REQUIRE(eevee_velocity_lib.glsl)
#pragma BLENDER_REQUIRE(common_pointcloud_lib.glsl)
void main()
{
@@ -27,11 +27,11 @@ void main()
* Apply a bias to avoid self-shadow issues. */
/* TODO(fclem): remove multiplication here. Here only for keeping the size correct for now. */
float actual_radius = point_cloud_interp.radius * 0.01;
interp.P -= cameraVec(interp.P) * actual_radius;
interp.P -= drw_world_incident_vector(interp.P) * actual_radius;
#endif
#ifdef MAT_VELOCITY
vec3 lP = point_world_to_object(point_cloud_interp.position);
vec3 lP = drw_point_world_to_object(point_cloud_interp.position);
vec3 prv, nxt;
velocity_local_pos_get(lP, point_cloud_interp_flat.id, prv, nxt);
/* FIXME(fclem): Evaluating before displacement avoid displacement being treated as motion but
@@ -51,5 +51,5 @@ void main()
clip_interp.clip_distance = dot(clip_plane.plane, vec4(interp.P, 1.0));
#endif
gl_Position = point_world_to_ndc(interp.P);
gl_Position = drw_point_world_to_homogenous(interp.P);
}

View File

@@ -6,7 +6,7 @@
* Custom full-screen triangle with placeholders varyings.
*/
#pragma BLENDER_REQUIRE(common_view_lib.glsl)
#pragma BLENDER_REQUIRE(draw_view_lib.glsl)
#pragma BLENDER_REQUIRE(eevee_nodetree_lib.glsl)
#pragma BLENDER_REQUIRE(eevee_surf_lib.glsl)
@@ -19,6 +19,6 @@ void main()
gl_Position = vec4(x, y, 1.0, 1.0);
/* Pass view position to keep accuracy. */
interp.P = project_point(ProjectionMatrixInverse, gl_Position.xyz);
interp.P = drw_point_ndc_to_view(gl_Position.xyz);
interp.N = vec3(1);
}

View File

@@ -17,7 +17,7 @@
* downsample to max level.
*/
#pragma BLENDER_REQUIRE(common_math_lib.glsl)
#pragma BLENDER_REQUIRE(gpu_shader_math_vector_lib.glsl)
shared float local_depths[gl_WorkGroupSize.y][gl_WorkGroupSize.x];
@@ -59,7 +59,7 @@ void main()
}
/* Level 1. (No load) */
float max_depth = max_v4(samp);
float max_depth = reduce_max(samp);
ivec2 dst_px = ivec2(kernel_origin + local_px);
imageStore(out_mip_1, dst_px, vec4(max_depth));
store_local_depth(local_px, max_depth);
@@ -72,7 +72,7 @@ void main()
active_thread = all(lessThan(uvec2(local_px), gl_WorkGroupSize.xy >> uint(mask_shift))); \
barrier(); /* Wait for previous writes to finish. */ \
if (active_thread) { \
max_depth = max_v4(load_local_depths(local_px)); \
max_depth = reduce_max(load_local_depths(local_px)); \
dst_px = ivec2((kernel_origin >> mask_shift) + local_px); \
imageStore(out_mip__, dst_px, vec4(max_depth)); \
} \
@@ -109,7 +109,7 @@ void main()
samp.z = imageLoad(out_mip_5, min(src_px + ivec2(1, 0), image_border)).x;
samp.w = imageLoad(out_mip_5, min(src_px + ivec2(0, 0), image_border)).x;
/* Level 6. */
float max_depth = max_v4(samp);
float max_depth = reduce_max(samp);
ivec2 dst_px = ivec2(kernel_origin + local_px);
imageStore(out_mip_6, dst_px, vec4(max_depth));
store_local_depth(local_px, max_depth);

View File

@@ -8,8 +8,8 @@
* pass is not conservative enough).
*/
#pragma BLENDER_REQUIRE(common_view_lib.glsl)
#pragma BLENDER_REQUIRE(common_math_lib.glsl)
#pragma BLENDER_REQUIRE(gpu_shader_debug_gradients_lib.glsl)
#pragma BLENDER_REQUIRE(draw_view_lib.glsl)
#pragma BLENDER_REQUIRE(eevee_light_lib.glsl)
#pragma BLENDER_REQUIRE(eevee_light_iter_lib.glsl)
@@ -18,8 +18,8 @@ void main()
ivec2 texel = ivec2(gl_FragCoord.xy);
float depth = texelFetch(hiz_tx, texel, 0).r;
float vP_z = get_view_z_from_depth(depth);
vec3 P = get_world_space_from_depth(uvcoordsvar.xy, depth);
float vP_z = drw_depth_screen_to_view(depth);
vec3 P = drw_point_screen_to_world(vec3(uvcoordsvar.xy, depth));
float light_count = 0.0;
uint light_cull = 0u;

View File

@@ -6,9 +6,9 @@
* Select the visible items inside the active view and put them inside the sorting buffer.
*/
#pragma BLENDER_REQUIRE(common_view_lib.glsl)
#pragma BLENDER_REQUIRE(common_math_geom_lib.glsl)
#pragma BLENDER_REQUIRE(common_intersect_lib.glsl)
#pragma BLENDER_REQUIRE(draw_view_lib.glsl)
#pragma BLENDER_REQUIRE(draw_math_geom_lib.glsl)
#pragma BLENDER_REQUIRE(draw_intersect_lib.glsl)
void main()
{
@@ -62,7 +62,9 @@ void main()
if (intersect_view(sphere)) {
uint index = atomicAdd(light_cull_buf.visible_count, 1u);
out_zdist_buf[index] = dot(cameraForward, light._position) - dot(cameraForward, cameraPos);
float z_dist = dot(drw_view_forward(), light._position) -
dot(drw_view_forward(), drw_view_position());
out_zdist_buf[index] = z_dist;
out_key_buf[index] = l_idx;
}
}

View File

@@ -8,7 +8,7 @@
* One thread processes one Light entity.
*/
#pragma BLENDER_REQUIRE(common_math_lib.glsl)
#pragma BLENDER_REQUIRE(gpu_shader_math_base_lib.glsl)
shared float zdists_cache[gl_WorkGroupSize.x];

View File

@@ -8,7 +8,7 @@
* Dispatch one thread per word.
*/
#pragma BLENDER_REQUIRE(common_view_lib.glsl)
#pragma BLENDER_REQUIRE(draw_view_lib.glsl)
#pragma BLENDER_REQUIRE(common_intersect_lib.glsl)
#pragma BLENDER_REQUIRE(eevee_light_iter_lib.glsl)
@@ -148,10 +148,10 @@ void main()
LightData light = light_buf[l_idx];
/* Culling in view space for precision and simplicity. */
vec3 vP = transform_point(ViewMatrix, light._position);
vec3 v_right = transform_direction(ViewMatrix, light._right);
vec3 v_up = transform_direction(ViewMatrix, light._up);
vec3 v_back = transform_direction(ViewMatrix, light._back);
vec3 vP = drw_point_world_to_view(light._position);
vec3 v_right = drw_normal_world_to_view(light._right);
vec3 v_up = drw_normal_world_to_view(light._up);
vec3 v_back = drw_normal_world_to_view(light._back);
float radius = light.influence_radius_max;
Sphere sphere = shape_sphere(vP, radius);

View File

@@ -8,7 +8,8 @@
* For this reason, we only dispatch 1 thread group.
*/
#pragma BLENDER_REQUIRE(common_view_lib.glsl)
#pragma BLENDER_REQUIRE(draw_view_lib.glsl)
#pragma BLENDER_REQUIRE(gpu_shader_math_base_lib.glsl)
#pragma BLENDER_REQUIRE(eevee_light_iter_lib.glsl)
/* Fits the limit of 32KB. */
@@ -37,7 +38,7 @@ void main()
vec3 P = light_buf[index]._position;
/* TODO(fclem): Could have better bounds for spot and area lights. */
float radius = light_buf[index].influence_radius_max;
float z_dist = dot(cameraForward, P) - dot(cameraForward, cameraPos);
float z_dist = dot(drw_view_forward(), P) - dot(drw_view_forward(), drw_view_position());
int z_min = culling_z_to_zbin(
light_cull_buf.zbin_scale, light_cull_buf.zbin_bias, z_dist + radius);
int z_max = culling_z_to_zbin(

View File

@@ -2,7 +2,12 @@
*
* SPDX-License-Identifier: GPL-2.0-or-later */
#pragma BLENDER_REQUIRE(common_math_lib.glsl)
uint bitfield_mask(uint bit_width, uint bit_min)
{
/* Cannot bit shift more than 31 positions. */
uint mask = (bit_width > 31u) ? 0x0u : (0xFFFFFFFFu << bit_width);
return ~mask << bit_min;
}
uint zbin_mask(uint word_index, uint zbin_min, uint zbin_max)
{
@@ -11,7 +16,7 @@ uint zbin_mask(uint word_index, uint zbin_min, uint zbin_max)
uint local_min = max(zbin_min, word_start);
uint local_max = min(zbin_max, word_end);
uint mask_width = local_max - local_min + 1;
return bit_field_mask(mask_width, local_min);
return bitfield_mask(mask_width, local_min);
}
int culling_z_to_zbin(float scale, float bias, float z)

View File

@@ -2,7 +2,7 @@
*
* SPDX-License-Identifier: GPL-2.0-or-later */
#pragma BLENDER_REQUIRE(common_math_geom_lib.glsl)
#pragma BLENDER_REQUIRE(draw_math_geom_lib.glsl)
#pragma BLENDER_REQUIRE(eevee_ltc_lib.glsl)
#pragma BLENDER_REQUIRE(eevee_light_iter_lib.glsl)
@@ -29,7 +29,7 @@ LightVector light_vector_get(LightData light, const bool is_directional, vec3 P)
}
else {
lv.L = light._position - P;
float inv_distance = inversesqrt(len_squared(lv.L));
float inv_distance = inversesqrt(length_squared(lv.L));
lv.L *= inv_distance;
lv.dist = 1.0 / inv_distance;
}
@@ -56,7 +56,7 @@ LightVector light_shape_vector_get(LightData light, const bool is_directional, v
vec3 L_prime = light._right * closest_point.x + light._up * closest_point.y;
L = L_prime - L;
float inv_distance = inversesqrt(len_squared(L));
float inv_distance = inversesqrt(length_squared(L));
LightVector lv;
lv.L = L * inv_distance;
lv.dist = 1.0 / inv_distance;
@@ -89,15 +89,15 @@ vec3 light_local_position_to_world(LightData light, vec3 lP)
* http://www.frostbite.com/wp-content/uploads/2014/11/course_notes_moving_frostbite_to_pbr.pdf */
float light_influence_attenuation(float dist, float inv_sqr_influence)
{
float factor = sqr(dist) * inv_sqr_influence;
float fac = saturate(1.0 - sqr(factor));
return sqr(fac);
float factor = square(dist) * inv_sqr_influence;
float fac = saturate(1.0 - square(factor));
return square(fac);
}
float light_spot_attenuation(LightData light, vec3 L)
{
vec3 lL = light_world_to_local(light, L);
float ellipse = inversesqrt(1.0 + len_squared(lL.xy * light.spot_size_inv / lL.z));
float ellipse = inversesqrt(1.0 + length_squared(lL.xy * light.spot_size_inv / lL.z));
float spotmask = smoothstep(0.0, 1.0, ellipse * light._spot_mul + light._spot_bias);
return spotmask * step(0.0, -dot(L, -light._back));
}
@@ -156,7 +156,7 @@ float light_point_light(LightData light, const bool is_directional, LightVector
* http://www.cemyuksel.com/research/pointlightattenuation/pointlightattenuation.pdf
* http://www.cemyuksel.com/research/pointlightattenuation/
*/
float d_sqr = sqr(lv.dist);
float d_sqr = square(lv.dist);
float r_sqr = light.radius_squared;
/* Using reformulation that has better numerical precision. */
float power = 2.0 / (d_sqr + r_sqr + lv.dist * sqrt(d_sqr + r_sqr));
@@ -177,7 +177,7 @@ float light_sphere_disk_radius(float sphere_radius, float distance_to_sphere)
{
/* The sine of the half-angle spanned by a sphere light is equal to the tangent of the
* half-angle spanned by a disk light with the same radius. */
return sphere_radius * inversesqrt(1.0 - sqr(sphere_radius / distance_to_sphere));
return sphere_radius * inversesqrt(1.0 - square(sphere_radius / distance_to_sphere));
}
float light_ltc(

View File

@@ -13,7 +13,7 @@
#pragma BLENDER_REQUIRE(eevee_lightprobe_lib.glsl)
#pragma BLENDER_REQUIRE(eevee_spherical_harmonics_lib.glsl)
#pragma BLENDER_REQUIRE(eevee_reflection_probe_eval_lib.glsl)
#pragma BLENDER_REQUIRE(common_math_lib.glsl)
#pragma BLENDER_REQUIRE(gpu_shader_math_base_lib.glsl)
/**
* Return the brick coordinate inside the grid.

View File

@@ -10,8 +10,7 @@
*/
#pragma BLENDER_REQUIRE(gpu_shader_utildefines_lib.glsl)
#pragma BLENDER_REQUIRE(common_math_lib.glsl)
#pragma BLENDER_REQUIRE(common_intersect_lib.glsl)
#pragma BLENDER_REQUIRE(draw_intersect_lib.glsl)
#pragma BLENDER_REQUIRE(eevee_shadow_tilemap_lib.glsl)
#pragma BLENDER_REQUIRE(eevee_light_iter_lib.glsl)

View File

@@ -16,7 +16,6 @@
#pragma BLENDER_REQUIRE(eevee_surfel_list_lib.glsl)
#pragma BLENDER_REQUIRE(eevee_lightprobe_lib.glsl)
#pragma BLENDER_REQUIRE(eevee_reflection_probe_lib.glsl)
#pragma BLENDER_REQUIRE(common_math_lib.glsl)
void irradiance_capture(vec3 L, vec3 irradiance, float visibility, inout SphericalHarmonicL1 sh)
{
@@ -39,7 +38,7 @@ void irradiance_capture_surfel(Surfel surfel, vec3 P, inout SphericalHarmonicL1
irradiance_vis += facing ? surfel.radiance_direct.front : surfel.radiance_direct.back;
/* Clamped brightness. */
float luma = max(1e-8, max_v3(irradiance_vis.rgb));
float luma = max(1e-8, reduce_max(irradiance_vis.rgb));
irradiance_vis.rgb *= 1.0 - max(0.0, luma - capture_info_buf.clamp_direct) / luma;
/* NOTE: The indirect radiance is already normalized and this is wanted, because we are not
@@ -74,7 +73,7 @@ void irradiance_capture_world(vec3 L, inout SphericalHarmonicL1 sh)
radiance = reflection_probes_sample(L, 0.0, atlas_coord).rgb;
/* Clamped brightness. */
float luma = max(1e-8, max_v3(radiance));
float luma = max(1e-8, reduce_max(radiance));
radiance *= 1.0 - max(0.0, luma - capture_info_buf.clamp_direct) / luma;
}
@@ -117,7 +116,7 @@ void main()
surfel_prev = surfel_next;
}
vec3 sky_L = cameraVec(P);
vec3 sky_L = drw_world_incident_vector(P);
SphericalHarmonicL1 sh;
sh.L0.M0 = imageLoad(irradiance_L0_img, grid_coord);

View File

@@ -10,6 +10,8 @@
* Project page: https://eheitzresearch.wordpress.com/415-2/
*/
#pragma BLENDER_REQUIRE(gpu_shader_utildefines_lib.glsl)
#define LTC_LAMBERT_MAT vec4(1.0, 0.0, 0.0, 1.0)
#define LTC_GGX_MAT(cos_theta, roughness) \
utility_tx_sample_lut(utility_tx, cos_theta, roughness, UTIL_LTC_MAT_LAYER)
@@ -206,9 +208,9 @@ float ltc_evaluate_disk(sampler2DArray utility_tx, vec3 N, vec3 V, mat3 Minv, ve
/* Intermediate step: init ellipse. */
vec3 L_[3];
L_[0] = mul(R, disk_points[0]);
L_[1] = mul(R, disk_points[1]);
L_[2] = mul(R, disk_points[2]);
L_[0] = R * disk_points[0];
L_[1] = R * disk_points[1];
L_[2] = R * disk_points[2];
vec3 C = 0.5 * (L_[0] + L_[2]);
vec3 V1 = 0.5 * (L_[1] - L_[2]);

View File

@@ -7,7 +7,7 @@
* Outputs the largest intersecting motion vector in the neighborhood.
*/
#pragma BLENDER_REQUIRE(common_math_geom_lib.glsl)
#pragma BLENDER_REQUIRE(draw_math_geom_lib.glsl)
#pragma BLENDER_REQUIRE(eevee_motion_blur_lib.glsl)
#define DEBUG_BYPASS_DILATION 0

View File

@@ -14,7 +14,7 @@
* Adapted from G3D Innovation Engine implementation.
*/
#pragma BLENDER_REQUIRE(common_math_geom_lib.glsl)
#pragma BLENDER_REQUIRE(draw_math_geom_lib.glsl)
#pragma BLENDER_REQUIRE(eevee_velocity_lib.glsl)
shared uint payload_prev;

View File

@@ -13,8 +13,7 @@
* by Jorge Jimenez
*/
#pragma BLENDER_REQUIRE(common_view_lib.glsl)
#pragma BLENDER_REQUIRE(common_math_lib.glsl)
#pragma BLENDER_REQUIRE(draw_view_lib.glsl)
#pragma BLENDER_REQUIRE(eevee_sampling_lib.glsl)
#pragma BLENDER_REQUIRE(eevee_velocity_lib.glsl)
#pragma BLENDER_REQUIRE(eevee_motion_blur_lib.glsl)
@@ -86,7 +85,7 @@ void gather_sample(vec2 screen_uv,
float sample_depth = texture(depth_tx, sample_uv).r;
vec4 sample_color = textureLod(in_color_tx, sample_uv, 0.0);
sample_depth = get_view_z_from_depth(sample_depth);
sample_depth = drw_depth_screen_to_view(sample_depth);
vec3 weights;
weights.xy = sample_weights(
@@ -161,7 +160,7 @@ void main()
}
/* Data of the center pixel of the gather (target). */
float center_depth = get_view_z_from_depth(texelFetch(depth_tx, texel, 0).r);
float center_depth = drw_depth_screen_to_view(texelFetch(depth_tx, texel, 0).r);
vec4 center_motion = motion_blur_sample_velocity(velocity_tx, uv);
vec4 center_color = textureLod(in_color_tx, uv, 0.0);

View File

@@ -2,8 +2,9 @@
*
* SPDX-License-Identifier: GPL-2.0-or-later */
#pragma BLENDER_REQUIRE(common_view_lib.glsl)
#pragma BLENDER_REQUIRE(common_math_lib.glsl)
#pragma BLENDER_REQUIRE(draw_view_lib.glsl)
#pragma BLENDER_REQUIRE(gpu_shader_utildefines_lib.glsl)
#pragma BLENDER_REQUIRE(gpu_shader_math_base_lib.glsl)
#pragma BLENDER_REQUIRE(gpu_shader_codegen_lib.glsl)
#pragma BLENDER_REQUIRE(eevee_renderpass_lib.glsl)
@@ -231,12 +232,12 @@ float ambient_occlusion_eval(vec3 normal,
// clang-format off
#if defined(GPU_FRAGMENT_SHADER) && defined(MAT_AMBIENT_OCCLUSION) && !defined(MAT_DEPTH) && !defined(MAT_SHADOW)
// clang-format on
vec3 vP = transform_point(ViewMatrix, g_data.P);
vec3 vP = drw_point_world_to_view(g_data.P);
ivec2 texel = ivec2(gl_FragCoord.xy);
OcclusionData data = ambient_occlusion_search(
vP, hiz_tx, texel, max_distance, inverted, sample_count);
vec3 V = cameraVec(g_data.P);
vec3 V = drw_world_incident_vector(g_data.P);
vec3 N = g_data.N;
vec3 Ng = g_data.Ng;
@@ -339,7 +340,7 @@ vec3 lut_coords_bsdf(float cos_theta, float roughness, float ior)
float critical_cos = sqrt(1.0 - ior * ior);
vec3 coords;
coords.x = sqr(ior);
coords.x = square(ior);
coords.y = cos_theta;
coords.y -= critical_cos;
coords.y /= (coords.y > 0.0) ? (1.0 - critical_cos) : critical_cos;
@@ -507,9 +508,9 @@ vec3 coordinate_camera(vec3 P)
}
else {
#ifdef MAT_WORLD
vP = transform_direction(ViewMatrix, P);
vP = drw_normal_world_to_view(P);
#else
vP = transform_point(ViewMatrix, P);
vP = drw_point_world_to_view(P);
#endif
}
vP.z = -vP.z;
@@ -525,7 +526,7 @@ vec3 coordinate_screen(vec3 P)
}
else {
/* TODO(fclem): Actual camera transform. */
window.xy = project_point(ProjectionMatrix, transform_point(ViewMatrix, P)).xy * 0.5 + 0.5;
window.xy = drw_point_world_to_screen(P).xy;
window.xy = window.xy * uniform_buf.camera.uv_scale + uniform_buf.camera.uv_bias;
}
return window;
@@ -536,7 +537,7 @@ vec3 coordinate_reflect(vec3 P, vec3 N)
#ifdef MAT_WORLD
return N;
#else
return -reflect(cameraVec(P), N);
return -reflect(drw_world_incident_vector(P), N);
#endif
}
@@ -545,7 +546,7 @@ vec3 coordinate_incoming(vec3 P)
#ifdef MAT_WORLD
return -P;
#else
return cameraVec(P);
return drw_world_incident_vector(P);
#endif
}

View File

@@ -15,11 +15,10 @@
* https://www.ea.com/seed/news/seed-dd18-presentation-slides-raytracing
*/
#pragma BLENDER_REQUIRE(draw_view_lib.glsl)
#pragma BLENDER_REQUIRE(gpu_shader_utildefines_lib.glsl)
#pragma BLENDER_REQUIRE(gpu_shader_math_vector_lib.glsl)
#pragma BLENDER_REQUIRE(gpu_shader_codegen_lib.glsl)
#pragma BLENDER_REQUIRE(common_view_lib.glsl)
#pragma BLENDER_REQUIRE(common_math_lib.glsl)
#pragma BLENDER_REQUIRE(eevee_sampling_lib.glsl)
#pragma BLENDER_REQUIRE(eevee_gbuffer_lib.glsl)
@@ -30,7 +29,7 @@ float bilateral_depth_weight(vec3 center_N, vec3 center_P, vec3 sample_P)
float depth_delta = dot(center_plane_eq, vec4(sample_P, 1.0));
/* TODO(fclem): Scene parameter. This is dependent on scene scale. */
const float scale = 10000.0;
float weight = exp2(-scale * sqr(depth_delta));
float weight = exp2(-scale * square(depth_delta));
return weight;
}
@@ -105,7 +104,7 @@ void main()
vec2 center_uv = vec2(texel_fullres) * uniform_buf.raytrace.full_resolution_inv;
float center_depth = texelFetch(depth_tx, texel_fullres, 0).r;
vec3 center_P = get_world_space_from_depth(center_uv, center_depth);
vec3 center_P = drw_point_screen_to_world(vec3(center_uv, center_depth));
#if defined(RAYTRACE_DIFFUSE)
ClosureDiffuse sample_closure, center_closure;
@@ -165,7 +164,7 @@ void main()
float sample_depth = texelFetch(depth_tx, sample_texel, 0).r;
vec2 sample_uv = vec2(sample_texel) * uniform_buf.raytrace.full_resolution_inv;
vec3 sample_P = get_world_space_from_depth(sample_uv, sample_depth);
vec3 sample_P = drw_point_screen_to_world(vec3(sample_uv, sample_depth));
/* Background case. */
if (sample_depth == 0.0) {

View File

@@ -15,12 +15,12 @@
* https://www.ea.com/seed/news/seed-dd18-presentation-slides-raytracing
*/
#pragma BLENDER_REQUIRE(draw_view_lib.glsl)
#pragma BLENDER_REQUIRE(gpu_shader_codegen_lib.glsl)
#pragma BLENDER_REQUIRE(gpu_shader_utildefines_lib.glsl)
#pragma BLENDER_REQUIRE(eevee_gbuffer_lib.glsl)
#pragma BLENDER_REQUIRE(eevee_sampling_lib.glsl)
#pragma BLENDER_REQUIRE(eevee_bxdf_lib.glsl)
#pragma BLENDER_REQUIRE(common_view_lib.glsl)
float bxdf_eval(ClosureDiffuse closure, vec3 L, vec3 V)
{
@@ -104,7 +104,9 @@ void main()
}
vec2 uv = (vec2(texel_fullres) + 0.5) * uniform_buf.raytrace.full_resolution_inv;
vec3 V = transform_direction(ViewMatrixInverse, get_view_vector_from_screen_uv(uv));
vec3 P = drw_point_screen_to_world(vec3(uv, 0.5));
vec3 V = drw_world_incident_vector(P);
GBufferData gbuf = gbuffer_read(gbuf_header_tx, gbuf_closure_tx, gbuf_color_tx, texel_fullres);
@@ -132,7 +134,7 @@ void main()
sample_count = max(sample_count, 5u);
}
/* NOTE: Roughness is squared now. */
closure.roughness = max(1e-3, sqr(closure.roughness));
closure.roughness = max(1e-3, square(closure.roughness));
#endif
vec2 noise = utility_tx_fetch(utility_tx, vec2(texel_fullres), UTIL_BLUE_NOISE_LAYER).ba;
@@ -176,7 +178,7 @@ void main()
radiance_accum += ray_radiance.rgb * weight;
weight_accum += weight;
rgb_moment += sqr(ray_radiance.rgb) * weight;
rgb_moment += square(ray_radiance.rgb) * weight;
}
float inv_weight = safe_rcp(weight_accum);
@@ -185,11 +187,11 @@ void main()
vec3 rgb_mean = radiance_accum;
rgb_moment *= inv_weight;
vec3 rgb_variance = abs(rgb_moment - sqr(rgb_mean));
float hit_variance = max_v3(rgb_variance);
vec3 rgb_variance = abs(rgb_moment - square(rgb_mean));
float hit_variance = reduce_max(rgb_variance);
float scene_z = get_view_z_from_depth(texelFetch(depth_tx, texel_fullres, 0).r);
float hit_depth = get_depth_from_view_z(scene_z - closest_hit_time);
float scene_z = drw_depth_screen_to_view(texelFetch(depth_tx, texel_fullres, 0).r);
float hit_depth = drw_depth_view_to_screen(scene_z - closest_hit_time);
imageStore(out_radiance_img, texel_fullres, vec4(radiance_accum, 0.0));
imageStore(out_variance_img, texel_fullres, vec4(hit_variance));

View File

@@ -15,13 +15,12 @@
* https://www.ea.com/seed/news/seed-dd18-presentation-slides-raytracing
*/
#pragma BLENDER_REQUIRE(draw_view_lib.glsl)
#pragma BLENDER_REQUIRE(gpu_shader_codegen_lib.glsl)
#pragma BLENDER_REQUIRE(gpu_shader_utildefines_lib.glsl)
#pragma BLENDER_REQUIRE(gpu_shader_math_matrix_lib.glsl)
#pragma BLENDER_REQUIRE(eevee_gbuffer_lib.glsl)
#pragma BLENDER_REQUIRE(eevee_colorspace_lib.glsl)
#pragma BLENDER_REQUIRE(common_view_lib.glsl)
#pragma BLENDER_REQUIRE(common_math_lib.glsl)
struct LocalStatistics {
vec3 mean;
@@ -183,11 +182,11 @@ void main()
/* Surface reprojection. */
/* TODO(fclem): Use per pixel velocity. Is this worth it? */
float scene_depth = texelFetch(depth_tx, texel_fullres, 0).r;
vec3 P = get_world_space_from_depth(uv, scene_depth);
vec3 P = drw_point_screen_to_world(vec3(uv, scene_depth));
vec4 history_radiance = radiance_history_sample(P, local);
/* Reflection reprojection. */
float hit_depth = imageLoad(hit_depth_img, texel_fullres).r;
vec3 P_hit = get_world_space_from_depth(uv, hit_depth);
vec3 P_hit = drw_point_screen_to_world(vec3(uv, hit_depth));
history_radiance += radiance_history_sample(P_hit, local);
/* Finalize accumulation. */
history_radiance *= safe_rcp(history_radiance.w);
@@ -199,7 +198,8 @@ void main()
float mix_fac = (history_radiance.w > 1e-3) ? 0.97 : 0.0;
/* Reduce blend factor to improve low roughness reflections. Use variance instead for speed. */
mix_fac *= mix(0.75, 1.0, saturate(in_variance * 20.0));
vec3 out_radiance = mix(safe_color(in_radiance), safe_color(history_radiance.rgb), mix_fac);
vec3 out_radiance = mix(
colorspace_safe_color(in_radiance), colorspace_safe_color(history_radiance.rgb), mix_fac);
/* This is feedback next frame as radiance_history_tx. */
imageStore(out_radiance_img, texel_fullres, vec4(out_radiance, 0.0));

View File

@@ -38,7 +38,8 @@ void main()
}
vec2 uv = (vec2(texel_fullres) + 0.5) / vec2(textureSize(gbuf_header_tx, 0).xy);
vec3 V = transform_direction(ViewMatrixInverse, get_view_vector_from_screen_uv(uv));
vec3 P = drw_point_screen_to_world(vec3(uv, 0.5));
vec3 V = drw_world_incident_vector(P);
vec2 noise = utility_tx_fetch(utility_tx, vec2(texel), UTIL_BLUE_NOISE_LAYER).rg;
#if defined(RAYTRACE_DIFFUSE)

View File

@@ -8,7 +8,6 @@
#pragma BLENDER_REQUIRE(gpu_shader_utildefines_lib.glsl)
#pragma BLENDER_REQUIRE(gpu_shader_math_vector_lib.glsl)
#pragma BLENDER_REQUIRE(common_view_lib.glsl)
#pragma BLENDER_REQUIRE(eevee_bxdf_sampling_lib.glsl)
#pragma BLENDER_REQUIRE(eevee_gbuffer_lib.glsl)
#pragma BLENDER_REQUIRE(eevee_ray_types_lib.glsl)
@@ -28,7 +27,7 @@ vec3 ray_generate_direction(vec2 noise, ClosureReflection reflection, vec3 V, ou
/* Bias the rays so we never get really high energy rays almost parallel to the surface. */
Xi.x = Xi.x * (1.0 - RAY_BIAS_REFLECTION) + RAY_BIAS_REFLECTION;
float roughness_sqr = max(1e-3, sqr(reflection.roughness));
float roughness_sqr = max(1e-3, square(reflection.roughness));
/* Gives *perfect* reflection for very small roughness. */
if (reflection.roughness < 0.0016) {
Xi = vec3(0.0);
@@ -47,7 +46,7 @@ vec3 ray_generate_direction(vec2 noise, ClosureRefraction refraction, vec3 V, ou
/* Bias the rays so we never get really high energy rays almost parallel to the surface. */
Xi.x = Xi.x * (1.0 - RAY_BIAS_REFRACTION) + RAY_BIAS_REFRACTION;
float roughness_sqr = max(1e-3, sqr(refraction.roughness));
float roughness_sqr = max(1e-3, square(refraction.roughness));
/* Gives *perfect* refraction for very small roughness. */
if (refraction.roughness < 0.0016) {
Xi = vec3(0.0);

View File

@@ -11,8 +11,6 @@
#pragma BLENDER_REQUIRE(eevee_sampling_lib.glsl)
#pragma BLENDER_REQUIRE(eevee_ray_types_lib.glsl)
#pragma BLENDER_REQUIRE(eevee_ray_trace_screen_lib.glsl)
#pragma BLENDER_REQUIRE(common_math_lib.glsl)
#pragma BLENDER_REQUIRE(common_math_geom_lib.glsl)
void main()
{
@@ -36,13 +34,13 @@ void main()
return;
}
vec3 P = get_world_space_from_depth(uv, depth);
vec3 P = drw_point_screen_to_world(vec3(uv, depth));
vec3 V = drw_world_incident_vector(P);
Ray ray;
ray.origin = P;
ray.direction = ray_data.xyz;
vec3 V = cameraVec(P);
/* Using ray direction as geometric normal to bias the sampling position.
* This is faster than loading the gbuffer again and averages between reflected and normal
* direction over many rays. */
@@ -52,7 +50,7 @@ void main()
/* Set point really far for correct reprojection of background. */
float hit_time = 1000.0;
float luma = max(1e-8, max_v3(radiance));
float luma = max(1e-8, reduce_max(radiance));
radiance *= 1.0 - max(0.0, luma - uniform_buf.raytrace.brightness_clamp) / luma;
imageStore(ray_time_img, texel, vec4(hit_time));

View File

@@ -14,8 +14,6 @@
#pragma BLENDER_REQUIRE(eevee_sampling_lib.glsl)
#pragma BLENDER_REQUIRE(eevee_ray_types_lib.glsl)
#pragma BLENDER_REQUIRE(eevee_ray_trace_screen_lib.glsl)
#pragma BLENDER_REQUIRE(common_math_lib.glsl)
#pragma BLENDER_REQUIRE(common_math_geom_lib.glsl)
void main()
{
@@ -39,8 +37,8 @@ void main()
float depth = texelFetch(depth_tx, texel_fullres, 0).r;
vec2 uv = (vec2(texel_fullres) + 0.5) * uniform_buf.raytrace.full_resolution_inv;
vec3 P = get_world_space_from_depth(uv, depth);
vec3 V = cameraVec(P);
vec3 P = drw_point_screen_to_world(vec3(uv, depth));
vec3 V = drw_world_incident_vector(P);
int planar_id = lightprobe_planar_select(P, V, ray_data.xyz);
if (planar_id == -1) {
@@ -95,7 +93,7 @@ void main()
hit.time = 10000.0;
}
float luma = max(1e-8, max_v3(radiance));
float luma = max(1e-8, reduce_max(radiance));
radiance *= 1.0 - max(0.0, luma - uniform_buf.raytrace.brightness_clamp) / luma;
imageStore(ray_time_img, texel, vec4(hit.time));

View File

@@ -11,8 +11,6 @@
#pragma BLENDER_REQUIRE(eevee_sampling_lib.glsl)
#pragma BLENDER_REQUIRE(eevee_ray_types_lib.glsl)
#pragma BLENDER_REQUIRE(eevee_ray_trace_screen_lib.glsl)
#pragma BLENDER_REQUIRE(common_math_lib.glsl)
#pragma BLENDER_REQUIRE(common_math_geom_lib.glsl)
void main()
{
@@ -41,8 +39,8 @@ void main()
float depth = texelFetch(depth_tx, texel_fullres, 0).r;
vec2 uv = (vec2(texel_fullres) + 0.5) * uniform_buf.raytrace.full_resolution_inv;
vec3 P = get_world_space_from_depth(uv, depth);
vec3 V = cameraVec(P);
vec3 P = drw_point_screen_to_world(vec3(uv, depth));
vec3 V = drw_world_incident_vector(P);
Ray ray;
ray.origin = P;
ray.direction = ray_data.xyz;
@@ -104,7 +102,7 @@ void main()
hit.time = 10000.0;
}
float luma = max(1e-8, max_v3(radiance));
float luma = max(1e-8, reduce_max(radiance));
radiance *= 1.0 - max(0.0, luma - uniform_buf.raytrace.brightness_clamp) / luma;
imageStore(ray_time_img, texel, vec4(hit.time));

View File

@@ -12,12 +12,15 @@
* Many modifications were made for our own usage.
*/
#pragma BLENDER_REQUIRE(draw_view_lib.glsl)
#pragma BLENDER_REQUIRE(gpu_shader_math_matrix_lib.glsl)
#pragma BLENDER_REQUIRE(gpu_shader_math_fast_lib.glsl)
#pragma BLENDER_REQUIRE(eevee_ray_types_lib.glsl)
/* Inputs expected to be in view-space. */
void raytrace_clip_ray_to_near_plane(inout Ray ray)
{
float near_dist = get_view_z_from_depth(0.0);
float near_dist = drw_view_near();
if ((ray.origin.z + ray.direction.z * ray.max_time) > near_dist) {
ray.max_time = abs((near_dist - ray.origin.z) / ray.direction.z);
}
@@ -76,7 +79,7 @@ METAL_ATTR ScreenTraceHitData raytrace_screen(RayTraceData rt_data,
if (!allow_self_intersection && ssray.max_time < 1.1) {
/* Still output the clipped ray. */
vec3 hit_ssP = ssray.origin.xyz + ssray.direction.xyz * ssray.max_time;
vec3 hit_P = get_world_space_from_depth(hit_ssP.xy, saturate(hit_ssP.z));
vec3 hit_P = drw_point_screen_to_world(vec3(hit_ssP.xy, saturate(hit_ssP.z)));
ray.direction = hit_P - ray.origin;
ScreenTraceHitData no_hit;
@@ -88,10 +91,10 @@ METAL_ATTR ScreenTraceHitData raytrace_screen(RayTraceData rt_data,
ssray.max_time = max(1.1, ssray.max_time);
float prev_delta = 0.0, prev_time = 0.0;
float depth_sample = get_depth_from_view_z(ray.origin.z);
float depth_sample = drw_depth_view_to_screen(ray.origin.z);
float delta = depth_sample - ssray.origin.z;
float lod_fac = saturate(fast_sqrt(roughness) * 2.0 - 0.4);
float lod_fac = saturate(sqrt_fast(roughness) * 2.0 - 0.4);
/* Cross at least one pixel. */
float t = 1.001, time = 1.001;
@@ -142,7 +145,7 @@ METAL_ATTR ScreenTraceHitData raytrace_screen(RayTraceData rt_data,
ScreenTraceHitData result;
result.valid = hit;
result.ss_hit_P = ssray.origin.xyz + ssray.direction.xyz * time;
result.v_hit_P = project_point(drw_view.wininv, result.ss_hit_P * 2.0 - 1.0);
result.v_hit_P = drw_point_screen_to_view(result.ss_hit_P);
/* Convert to world space ray time. */
result.time = length(result.v_hit_P - ray.origin) / length(ray.direction);
@@ -211,7 +214,7 @@ ScreenTraceHitData raytrace_planar(RayTraceData rt_data,
result.ss_hit_P = ssray.origin.xyz + ssray.direction.xyz * time;
/* TODO(@fclem): This uses the main view's projection matrix, not the planar's one.
* This works fine for reflection, but this prevent the use of any other projection capture. */
result.v_hit_P = project_point(drw_view.wininv, result.ss_hit_P * 2.0 - 1.0);
result.v_hit_P = drw_point_screen_to_view(result.ss_hit_P);
/* Convert to world space ray time. */
result.time = length(result.v_hit_P - ray.origin) / length(ray.direction);
return result;

View File

@@ -2,8 +2,7 @@
*
* SPDX-License-Identifier: GPL-2.0-or-later */
#pragma BLENDER_REQUIRE(common_view_lib.glsl)
#pragma BLENDER_REQUIRE(common_math_lib.glsl)
#pragma BLENDER_REQUIRE(draw_view_lib.glsl)
/**
* General purpose 3D ray.
@@ -37,17 +36,17 @@ void raytrace_screenspace_ray_finalize(inout ScreenSpaceRay ray, vec2 pixel_size
ray.direction -= ray.origin;
/* If the line is degenerate, make it cover at least one pixel
* to not have to handle zero-pixel extent as a special case later */
if (len_squared(ray.direction.xy) < 0.00001) {
if (length_squared(ray.direction.xy) < 0.00001) {
ray.direction.xy = vec2(0.0, 0.00001);
}
float ray_len_sqr = len_squared(ray.direction.xyz);
float ray_len_sqr = length_squared(ray.direction.xyz);
/* Make ray.direction cover one pixel. */
bool is_more_vertical = abs(ray.direction.x / pixel_size.x) <
abs(ray.direction.y / pixel_size.y);
ray.direction /= (is_more_vertical) ? abs(ray.direction.y) : abs(ray.direction.x);
ray.direction *= (is_more_vertical) ? pixel_size.y : pixel_size.x;
/* Clip to segment's end. */
ray.max_time = sqrt(ray_len_sqr * safe_rcp(len_squared(ray.direction.xyz)));
ray.max_time = sqrt(ray_len_sqr * safe_rcp(length_squared(ray.direction.xyz)));
/* Clipping to frustum sides. */
float clip_dist = line_unit_box_intersect_dist_safe(ray.origin.xyz, ray.direction.xyz);
ray.max_time = min(ray.max_time, clip_dist);
@@ -59,8 +58,8 @@ void raytrace_screenspace_ray_finalize(inout ScreenSpaceRay ray, vec2 pixel_size
ScreenSpaceRay raytrace_screenspace_ray_create(Ray ray, vec2 pixel_size)
{
ScreenSpaceRay ssray;
ssray.origin.xyz = project_point(ProjectionMatrix, ray.origin);
ssray.direction.xyz = project_point(ProjectionMatrix, ray.origin + ray.direction * ray.max_time);
ssray.origin.xyz = drw_point_view_to_ndc(ray.origin);
ssray.direction.xyz = drw_point_view_to_ndc(ray.origin + ray.direction * ray.max_time);
raytrace_screenspace_ray_finalize(ssray, pixel_size);
return ssray;
@@ -69,12 +68,12 @@ ScreenSpaceRay raytrace_screenspace_ray_create(Ray ray, vec2 pixel_size)
ScreenSpaceRay raytrace_screenspace_ray_create(Ray ray, vec2 pixel_size, float thickness)
{
ScreenSpaceRay ssray;
ssray.origin.xyz = project_point(ProjectionMatrix, ray.origin);
ssray.direction.xyz = project_point(ProjectionMatrix, ray.origin + ray.direction * ray.max_time);
ssray.origin.xyz = drw_point_view_to_ndc(ray.origin);
ssray.direction.xyz = drw_point_view_to_ndc(ray.origin + ray.direction * ray.max_time);
/* Interpolate thickness in screen space.
* Calculate thickness further away to avoid near plane clipping issues. */
ssray.origin.w = get_depth_from_view_z(ray.origin.z - thickness);
ssray.direction.w = get_depth_from_view_z(ray.origin.z + ray.direction.z - thickness);
ssray.origin.w = drw_depth_view_to_screen(ray.origin.z - thickness);
ssray.direction.w = drw_depth_view_to_screen(ray.origin.z + ray.direction.z - thickness);
ssray.origin.w = ssray.origin.w * 2.0 - 1.0;
ssray.direction.w = ssray.direction.w * 2.0 - 1.0;

View File

@@ -7,7 +7,7 @@
* Also contains some sample mapping functions.
*/
#pragma BLENDER_REQUIRE(common_math_lib.glsl)
#pragma BLENDER_REQUIRE(gpu_shader_math_base_lib.glsl)
/* -------------------------------------------------------------------- */
/** \name Sampling data.
@@ -114,9 +114,9 @@ vec2 hammersley_2d(int i, int sample_count)
/* Given 1 random number in [0..1] range, return a random unit circle sample. */
vec2 sample_circle(float rand)
{
float phi = (rand - 0.5) * M_2PI;
float phi = (rand - 0.5) * M_TAU;
float cos_phi = cos(phi);
float sin_phi = sqrt(1.0 - sqr(cos_phi)) * sign(phi);
float sin_phi = sqrt(1.0 - square(cos_phi)) * sign(phi);
return vec2(cos_phi, sin_phi);
}
@@ -149,7 +149,7 @@ vec3 sample_sphere(vec2 rand)
vec3 sample_hemisphere(vec2 rand)
{
float cos_theta = rand.x;
float sin_theta = safe_sqrt(1.0 - sqr(cos_theta));
float sin_theta = safe_sqrt(1.0 - square(cos_theta));
return vec3(sin_theta * sample_circle(rand.y), cos_theta);
}

View File

@@ -7,8 +7,8 @@
* See eShadowDebug for more information.
*/
#pragma BLENDER_REQUIRE(common_view_lib.glsl)
#pragma BLENDER_REQUIRE(common_math_lib.glsl)
#pragma BLENDER_REQUIRE(gpu_shader_debug_gradients_lib.glsl)
#pragma BLENDER_REQUIRE(draw_view_lib.glsl)
#pragma BLENDER_REQUIRE(eevee_light_iter_lib.glsl)
#pragma BLENDER_REQUIRE(eevee_light_lib.glsl)
#pragma BLENDER_REQUIRE(eevee_shadow_lib.glsl)
@@ -173,7 +173,7 @@ void main()
out_color_mul = vec4(1.0);
float depth = texelFetch(hiz_tx, ivec2(gl_FragCoord.xy), 0).r;
vec3 P = get_world_space_from_depth(uvcoordsvar.xy, depth);
vec3 P = drw_point_screen_to_world(vec3(uvcoordsvar.xy, depth));
/* Make it pass the depth test. */
gl_FragDepth = depth - 1e-6;

View File

@@ -2,6 +2,7 @@
*
* SPDX-License-Identifier: GPL-2.0-or-later */
#pragma BLENDER_REQUIRE(gpu_shader_math_matrix_lib.glsl)
#pragma BLENDER_REQUIRE(eevee_shadow_tilemap_lib.glsl)
#define EEVEE_SHADOW_LIB

View File

@@ -35,6 +35,7 @@
* belong to shadow pages not being updated in this pass are discarded.
**/
#pragma BLENDER_REQUIRE(gpu_shader_utildefines_lib.glsl)
#pragma BLENDER_REQUIRE(eevee_shadow_tilemap_lib.glsl)
#if defined(PASS_CLEAR)

View File

@@ -11,8 +11,9 @@
* tag the appropriate tiles.
*/
#pragma BLENDER_REQUIRE(gpu_shader_utildefines_lib.glsl)
#pragma BLENDER_REQUIRE(draw_view_lib.glsl)
#pragma BLENDER_REQUIRE(common_intersect_lib.glsl)
#pragma BLENDER_REQUIRE(common_view_lib.glsl)
#pragma BLENDER_REQUIRE(common_aabb_lib.glsl)
#pragma BLENDER_REQUIRE(eevee_shadow_tilemap_lib.glsl)

View File

@@ -27,8 +27,8 @@ void main()
}
vec2 uv = (vec2(texel) + 0.5) / vec2(tex_size);
vec3 vP = get_view_space_from_depth(uv, depth);
vec3 P = transform_point(ViewMatrixInverse, vP);
vec3 vP = drw_point_screen_to_view(vec3(uv, depth));
vec3 P = drw_point_view_to_world(vP);
vec2 pixel = vec2(gl_GlobalInvocationID.xy);
shadow_tag_usage(vP, P, pixel);

View File

@@ -10,8 +10,8 @@
* tiles.
*/
#pragma BLENDER_REQUIRE(draw_model_lib.glsl)
#pragma BLENDER_REQUIRE(eevee_shadow_tag_usage_lib.glsl)
#pragma BLENDER_REQUIRE(common_view_lib.glsl)
float ray_aabb(vec3 ray_origin, vec3 ray_direction, vec3 aabb_min, vec3 aabb_max)
{
@@ -19,8 +19,8 @@ float ray_aabb(vec3 ray_origin, vec3 ray_direction, vec3 aabb_min, vec3 aabb_max
vec3 t_mins = (aabb_min - ray_origin) / ray_direction;
vec3 t_maxs = (aabb_max - ray_origin) / ray_direction;
float t_min = max_v3(min(t_mins, t_maxs));
float t_max = min_v3(max(t_mins, t_maxs));
float t_min = reduce_max(min(t_mins, t_maxs));
float t_max = reduce_min(max(t_mins, t_maxs));
/* AABB is in the opposite direction. */
if (t_max < 0.0) {
@@ -68,14 +68,14 @@ void step_bounding_sphere(vec3 vs_near_plane,
for (int x = -1; x <= 1; x += 2) {
for (int y = -1; y <= 1; y += 2) {
vec3 near_corner = near_center + (near_pixel_size * 0.5 * vec3(x, y, 0));
sphere_radius = max(sphere_radius, len_squared(near_corner - sphere_center));
sphere_radius = max(sphere_radius, length_squared(near_corner - sphere_center));
vec3 far_corner = far_center + (far_pixel_size * 0.5 * vec3(x, y, 0));
sphere_radius = max(sphere_radius, len_squared(far_corner - sphere_center));
sphere_radius = max(sphere_radius, length_squared(far_corner - sphere_center));
}
}
sphere_center = point_view_to_world(sphere_center);
sphere_center = drw_point_view_to_world(sphere_center);
sphere_radius = sqrt(sphere_radius);
}
@@ -84,14 +84,14 @@ void main()
vec2 screen_uv = gl_FragCoord.xy / vec2(fb_resolution);
float opaque_depth = texelFetch(hiz_tx, ivec2(gl_FragCoord.xy), fb_lod).r;
vec3 ws_opaque = get_world_space_from_depth(screen_uv, opaque_depth);
vec3 ws_opaque = drw_point_screen_to_world(vec3(screen_uv, opaque_depth));
vec3 ws_near_plane = get_world_space_from_depth(screen_uv, 0);
vec3 ws_near_plane = drw_point_screen_to_world(vec3(screen_uv, 0.0));
vec3 ws_view_direction = normalize(interp.P - ws_near_plane);
vec3 vs_near_plane = get_view_space_from_depth(screen_uv, 0);
vec3 vs_near_plane = drw_point_screen_to_view(vec3(screen_uv, 0.0));
vec3 vs_view_direction = normalize(interp.vP - vs_near_plane);
vec3 ls_near_plane = point_world_to_object(ws_near_plane);
vec3 ls_view_direction = normalize(point_world_to_object(interp.P) - ls_near_plane);
vec3 ls_near_plane = drw_point_world_to_object(ws_near_plane);
vec3 ls_view_direction = normalize(drw_point_world_to_object(interp.P) - ls_near_plane);
/* TODO (Miguel Pozo): We could try to ray-cast against the non-inflated bounds first,
* and fallback to the inflated ones if there is no hit.
@@ -99,7 +99,7 @@ void main()
float ls_near_box_t = ray_aabb(
ls_near_plane, ls_view_direction, interp_flat.ls_aabb_min, interp_flat.ls_aabb_max);
vec3 ls_near_box = ls_near_plane + ls_view_direction * ls_near_box_t;
vec3 ws_near_box = point_object_to_world(ls_near_box);
vec3 ws_near_box = drw_point_object_to_world(ls_near_box);
float near_box_t = distance(ws_near_plane, ws_near_box);
float far_box_t = distance(ws_near_plane, interp.P);
@@ -116,7 +116,7 @@ void main()
vec3 P = ws_near_plane + (ws_view_direction * t);
float step_radius;
step_bounding_sphere(vs_near_plane, vs_view_direction, t, t + step_size, P, step_radius);
vec3 vP = point_world_to_view(P);
vec3 vP = drw_point_world_to_view(P);
shadow_tag_usage(
vP, P, ws_view_direction, step_radius, t, gl_FragCoord.xy * exp2(float(fb_lod)), 0);

View File

@@ -9,9 +9,8 @@
* This contains the common logic used for tagging shadows for opaque and transparent receivers.
*/
#pragma BLENDER_REQUIRE(common_intersect_lib.glsl)
#pragma BLENDER_REQUIRE(common_math_geom_lib.glsl)
#pragma BLENDER_REQUIRE(common_view_lib.glsl)
#pragma BLENDER_REQUIRE(draw_view_lib.glsl)
#pragma BLENDER_REQUIRE(draw_intersect_lib.glsl)
#pragma BLENDER_REQUIRE(eevee_light_iter_lib.glsl)
#pragma BLENDER_REQUIRE(eevee_light_lib.glsl)
#pragma BLENDER_REQUIRE(eevee_shadow_lib.glsl)

View File

@@ -9,39 +9,40 @@
* This renders the bounding boxes for transparent objects in order to tag the correct shadows.
*/
#pragma BLENDER_REQUIRE(common_view_lib.glsl)
#pragma BLENDER_REQUIRE(gpu_shader_utildefines_lib.glsl)
#pragma BLENDER_REQUIRE(gpu_shader_math_vector_lib.glsl)
#pragma BLENDER_REQUIRE(draw_model_lib.glsl)
#pragma BLENDER_REQUIRE(common_shape_lib.glsl)
/* Inflate bounds by half a pixel as a conservative rasterization alternative,
* to ensure the tiles needed by all LOD0 pixels get tagged */
void inflate_bounds(vec3 ls_center, inout vec3 P, inout vec3 lP)
{
vec3 vP = point_world_to_view(P);
vec3 vP = drw_point_world_to_view(P);
float inflate_scale = pixel_world_radius * exp2(float(fb_lod));
bool is_persp = (ProjectionMatrix[3][3] == 0.0);
if (is_persp) {
if (drw_view_is_perspective()) {
inflate_scale *= -vP.z;
}
/* Half-pixel. */
inflate_scale *= 0.5;
vec3 vs_inflate_vector = normal_object_to_view(sign(lP - ls_center));
vec3 vs_inflate_vector = drw_normal_object_to_view(sign(lP - ls_center));
vs_inflate_vector.z = 0;
/* Scale the vector so the largest axis length is 1 */
vs_inflate_vector /= max_v2(abs(vs_inflate_vector.xy));
vs_inflate_vector /= reduce_max(abs(vs_inflate_vector.xy));
vs_inflate_vector *= inflate_scale;
vP += vs_inflate_vector;
P = point_view_to_world(vP);
lP = point_world_to_object(P);
P = drw_point_view_to_world(vP);
lP = drw_point_world_to_object(P);
}
void main()
{
PASS_RESOURCE_ID
DRW_RESOURCE_ID_VARYING_SET
const ObjectBounds bounds = bounds_buf[resource_id];
ObjectBounds bounds = bounds_buf[resource_id];
Box box = shape_box(bounds.bounding_corners[0].xyz,
bounds.bounding_corners[0].xyz + bounds.bounding_corners[1].xyz,
@@ -52,14 +53,14 @@ void main()
vec3 ws_aabb_max = bounds.bounding_corners[0].xyz + bounds.bounding_corners[1].xyz +
bounds.bounding_corners[2].xyz + bounds.bounding_corners[3].xyz;
vec3 ls_center = point_world_to_object((ws_aabb_min + ws_aabb_max) / 2.0);
vec3 ls_center = drw_point_world_to_object(midpoint(ws_aabb_min, ws_aabb_max));
vec3 ls_conservative_min = vec3(FLT_MAX);
vec3 ls_conservative_max = vec3(-FLT_MAX);
for (int i = 0; i < 8; i++) {
vec3 P = box.corners[i];
vec3 lP = point_world_to_object(P);
vec3 lP = drw_point_world_to_object(P);
inflate_bounds(ls_center, P, lP);
ls_conservative_min = min(ls_conservative_min, lP);
@@ -71,10 +72,10 @@ void main()
vec3 lP = mix(ls_conservative_min, ls_conservative_max, max(vec3(0), pos));
interp.P = point_object_to_world(lP);
interp.vP = point_world_to_view(interp.P);
interp.P = drw_point_object_to_world(lP);
interp.vP = drw_point_world_to_view(interp.P);
gl_Position = point_world_to_ndc(interp.P);
gl_Position = drw_point_world_to_homogenous(interp.P);
#if 0
if (gl_VertexID == 0) {
@@ -84,7 +85,7 @@ void main()
ls_conservative_min + (ls_conservative_max - ls_conservative_min) * vec3(0, 1, 0),
ls_conservative_min + (ls_conservative_max - ls_conservative_min) * vec3(0, 0, 1));
for (int i = 0; i < 8; i++) {
debug_box.corners[i] = point_object_to_world(debug_box.corners[i]);
debug_box.corners[i] = drw_point_object_to_world(debug_box.corners[i]);
}
drw_debug(debug_box);
}

View File

@@ -29,9 +29,9 @@ void main()
}
vec3 jitter = sampling_rng_3D_get(SAMPLING_VOLUME_U);
vec3 volume_ndc = volume_to_ndc((vec3(froxel) + jitter) * uniform_buf.volumes.inv_tex_size);
vec3 vP = get_view_space_from_depth(volume_ndc.xy, volume_ndc.z);
vec3 P = point_view_to_world(vP);
vec3 volume_ndc = volume_to_screen((vec3(froxel) + jitter) * uniform_buf.volumes.inv_tex_size);
vec3 vP = drw_point_screen_to_view(vec3(volume_ndc.xy, volume_ndc.z));
vec3 P = drw_point_view_to_world(vP);
float depth = texelFetch(hiz_tx, froxel.xy, uniform_buf.volumes.tile_size_lod).r;
if (depth < volume_ndc.z) {
@@ -42,5 +42,5 @@ void main()
uniform_buf.volumes.viewport_size_inv;
int bias = uniform_buf.volumes.tile_size_lod;
shadow_tag_usage(vP, P, cameraVec(P), 0.01, length(vP), pixel, bias);
shadow_tag_usage(vP, P, drw_world_incident_vector(P), 0.01, length(vP), pixel, bias);
}

View File

@@ -11,7 +11,6 @@
*/
#pragma BLENDER_REQUIRE(gpu_shader_utildefines_lib.glsl)
#pragma BLENDER_REQUIRE(common_math_lib.glsl)
#pragma BLENDER_REQUIRE(common_intersect_lib.glsl)
#pragma BLENDER_REQUIRE(eevee_shadow_tilemap_lib.glsl)
#pragma BLENDER_REQUIRE(eevee_light_iter_lib.glsl)

View File

@@ -12,7 +12,6 @@
#pragma BLENDER_REQUIRE(gpu_shader_utildefines_lib.glsl)
#pragma BLENDER_REQUIRE(gpu_shader_math_matrix_lib.glsl)
#pragma BLENDER_REQUIRE(common_math_lib.glsl)
#pragma BLENDER_REQUIRE(eevee_shadow_tilemap_lib.glsl)
shared int rect_min_x;

View File

@@ -11,7 +11,6 @@
*/
#pragma BLENDER_REQUIRE(gpu_shader_utildefines_lib.glsl)
#pragma BLENDER_REQUIRE(common_math_lib.glsl)
#pragma BLENDER_REQUIRE(eevee_shadow_tilemap_lib.glsl)
shared int directional_range_changed;

View File

@@ -2,7 +2,6 @@
*
* SPDX-License-Identifier: GPL-2.0-or-later */
#pragma BLENDER_REQUIRE(common_math_lib.glsl)
#pragma BLENDER_REQUIRE(common_shape_lib.glsl)
/* ---------------------------------------------------------------------- */

View File

@@ -13,12 +13,11 @@
* we precompute a weight profile texture to be able to support per pixel AND per channel radius.
*/
#pragma BLENDER_REQUIRE(draw_view_lib.glsl)
#pragma BLENDER_REQUIRE(gpu_shader_math_rotation_lib.glsl)
#pragma BLENDER_REQUIRE(gpu_shader_math_matrix_lib.glsl)
#pragma BLENDER_REQUIRE(gpu_shader_codegen_lib.glsl)
#pragma BLENDER_REQUIRE(eevee_gbuffer_lib.glsl)
#pragma BLENDER_REQUIRE(common_view_lib.glsl)
#pragma BLENDER_REQUIRE(common_math_geom_lib.glsl)
#pragma BLENDER_REQUIRE(eevee_sampling_lib.glsl)
shared vec3 cached_radiance[SUBSURFACE_GROUP_SIZE][SUBSURFACE_GROUP_SIZE];
@@ -77,7 +76,7 @@ void main(void)
cache_populate(center_uv);
float depth = texelFetch(depth_tx, texel, 0).r;
vec3 vP = get_view_space_from_depth(center_uv, depth);
vec3 vP = drw_point_screen_to_view(vec3(center_uv, depth));
GBufferData gbuf = gbuffer_read(gbuf_header_tx, gbuf_closure_tx, gbuf_color_tx, texel);
@@ -85,7 +84,7 @@ void main(void)
return;
}
float max_radius = max_v3(gbuf.diffuse.sss_radius);
float max_radius = reduce_max(gbuf.diffuse.sss_radius);
float homcoord = ProjectionMatrix[2][3] * vP.z + ProjectionMatrix[3][3];
vec2 sample_scale = vec2(ProjectionMatrix[0][0], ProjectionMatrix[1][1]) *
@@ -94,7 +93,7 @@ void main(void)
/* Avoid too small radii that have float imprecision. */
vec3 clamped_sss_radius = max(vec3(1e-4), gbuf.diffuse.sss_radius / max_radius) * max_radius;
/* Scale albedo because we can have HDR value caused by BSDF sampling. */
vec3 albedo = gbuf.diffuse.color / max(1e-6, max_v3(gbuf.diffuse.color));
vec3 albedo = gbuf.diffuse.color / max(1e-6, reduce_max(gbuf.diffuse.color));
vec3 d = burley_setup(clamped_sss_radius, albedo);
/* Do not rotate too much to avoid too much cache misses. */
@@ -116,7 +115,7 @@ void main(void)
continue;
}
/* Slide 34. */
vec3 sample_vP = get_view_space_from_depth(sample_uv, samp.depth);
vec3 sample_vP = drw_point_screen_to_view(vec3(sample_uv, samp.depth));
float r = distance(sample_vP, vP);
vec3 weight = burley_eval(d, r) * pdf_inv;

View File

@@ -7,9 +7,9 @@
* processing.
*/
#pragma BLENDER_REQUIRE(draw_view_lib.glsl)
#pragma BLENDER_REQUIRE(eevee_gbuffer_lib.glsl)
#pragma BLENDER_REQUIRE(common_view_lib.glsl)
#pragma BLENDER_REQUIRE(common_math_lib.glsl)
#pragma BLENDER_REQUIRE(gpu_shader_math_vector_lib.glsl)
shared uint has_visible_sss;
@@ -29,7 +29,7 @@ void main(void)
vec3 radiance = imageLoad(direct_light_img, texel).rgb +
imageLoad(indirect_light_img, texel).rgb;
float max_radius = max_v3(gbuf.diffuse.sss_radius);
float max_radius = reduce_max(gbuf.diffuse.sss_radius);
imageStore(radiance_img, texel, vec4(radiance, 0.0));
imageStore(object_id_img, texel, uvec4(gbuf.diffuse.sss_id));
@@ -37,7 +37,7 @@ void main(void)
vec2 center_uv = (vec2(texel) + 0.5) / vec2(textureSize(gbuf_header_tx, 0));
float depth = texelFetch(depth_tx, texel, 0).r;
/* TODO(fclem): Check if this simplifies. */
float vPz = get_view_z_from_depth(depth);
float vPz = drw_depth_screen_to_view(depth);
float homcoord = ProjectionMatrix[2][3] * vPz + ProjectionMatrix[3][3];
float sample_scale = ProjectionMatrix[0][0] * (0.5 * max_radius / homcoord);
float pixel_footprint = sample_scale * float(textureSize(gbuf_header_tx, 0).x);

View File

@@ -9,10 +9,9 @@
* into other surface shaders.
*/
#pragma BLENDER_REQUIRE(draw_view_lib.glsl)
#pragma BLENDER_REQUIRE(gpu_shader_math_vector_lib.glsl)
#pragma BLENDER_REQUIRE(eevee_gbuffer_lib.glsl)
#pragma BLENDER_REQUIRE(common_view_lib.glsl)
#pragma BLENDER_REQUIRE(common_math_lib.glsl)
#pragma BLENDER_REQUIRE(common_hair_lib.glsl)
#pragma BLENDER_REQUIRE(eevee_surf_lib.glsl)
#pragma BLENDER_REQUIRE(eevee_nodetree_lib.glsl)
@@ -42,7 +41,7 @@ void main()
if (capture_info_buf.do_surfel_count) {
/* Generate a surfel only once. This check allow cases where no axis is dominant. */
vec3 vNg = normal_world_to_view(g_data.Ng);
vec3 vNg = drw_normal_world_to_view(g_data.Ng);
bool is_surface_view_aligned = dominant_axis(vNg) == 2;
if (is_surface_view_aligned) {
uint surfel_id = atomicAdd(capture_info_buf.surfel_len, 1u);

View File

@@ -9,9 +9,8 @@
* Some render-pass are written during this pass.
*/
#pragma BLENDER_REQUIRE(draw_view_lib.glsl)
#pragma BLENDER_REQUIRE(eevee_gbuffer_lib.glsl)
#pragma BLENDER_REQUIRE(common_view_lib.glsl)
#pragma BLENDER_REQUIRE(common_math_lib.glsl)
#pragma BLENDER_REQUIRE(common_hair_lib.glsl)
#pragma BLENDER_REQUIRE(eevee_ambient_occlusion_lib.glsl)
#pragma BLENDER_REQUIRE(eevee_surf_lib.glsl)
@@ -22,7 +21,7 @@ vec4 closure_to_rgba(Closure cl)
{
vec4 out_color;
out_color.rgb = g_emission;
out_color.a = saturate(1.0 - avg(g_transmittance));
out_color.a = saturate(1.0 - average(g_transmittance));
/* Reset for the next closure tree. */
closure_weights_reset();
@@ -147,5 +146,5 @@ void main()
out_radiance.rgb *= 1.0 - g_holdout;
out_transmittance.rgb = g_transmittance;
out_transmittance.a = saturate(avg(g_transmittance));
out_transmittance.a = saturate(average(g_transmittance));
}

View File

@@ -6,8 +6,7 @@
* Depth shader that can stochastically discard transparent pixel.
*/
#pragma BLENDER_REQUIRE(common_view_lib.glsl)
#pragma BLENDER_REQUIRE(common_math_lib.glsl)
#pragma BLENDER_REQUIRE(draw_view_lib.glsl)
#pragma BLENDER_REQUIRE(common_hair_lib.glsl)
#pragma BLENDER_REQUIRE(eevee_sampling_lib.glsl)
#pragma BLENDER_REQUIRE(eevee_nodetree_lib.glsl)
@@ -19,7 +18,7 @@ vec4 closure_to_rgba(Closure cl)
{
vec4 out_color;
out_color.rgb = g_emission;
out_color.a = saturate(1.0 - avg(g_transmittance));
out_color.a = saturate(1.0 - average(g_transmittance));
/* Reset for the next closure tree. */
closure_weights_reset();
@@ -37,7 +36,7 @@ void main()
float noise_offset = sampling_rng_1D_get(SAMPLING_TRANSPARENCY);
float random_threshold = transparency_hashed_alpha_threshold(1.0, noise_offset, g_data.P);
float transparency = avg(g_transmittance);
float transparency = average(g_transmittance);
if (transparency > random_threshold) {
discard;
return;

View File

@@ -8,6 +8,7 @@
* This is used by alpha blended materials and materials using Shader to RGB nodes.
*/
#pragma BLENDER_REQUIRE(draw_view_lib.glsl)
#pragma BLENDER_REQUIRE(eevee_light_eval_lib.glsl)
#pragma BLENDER_REQUIRE(eevee_lightprobe_eval_lib.glsl)
#pragma BLENDER_REQUIRE(eevee_ambient_occlusion_lib.glsl)
@@ -17,8 +18,6 @@
#pragma BLENDER_REQUIRE(eevee_subsurface_lib.glsl)
#pragma BLENDER_REQUIRE(eevee_volume_lib.glsl)
#pragma BLENDER_REQUIRE(common_hair_lib.glsl)
#pragma BLENDER_REQUIRE(common_math_lib.glsl)
#pragma BLENDER_REQUIRE(common_view_lib.glsl)
vec4 closure_to_rgba(Closure cl)
{
@@ -27,8 +26,8 @@ vec4 closure_to_rgba(Closure cl)
vec3 refraction_light = vec3(0.0);
float shadow = 1.0;
float vPz = dot(cameraForward, g_data.P) - dot(cameraForward, cameraPos);
vec3 V = cameraVec(g_data.P);
float vPz = dot(drw_view_forward(), g_data.P) - dot(drw_view_forward(), drw_view_position());
vec3 V = drw_world_incident_vector(g_data.P);
ClosureLightStack stack;
@@ -58,7 +57,7 @@ vec4 closure_to_rgba(Closure cl)
out_color.rgb += g_diffuse_data.color * g_diffuse_data.weight * stack.cl[0].light_shadowed;
out_color.rgb += g_reflection_data.color * g_reflection_data.weight * stack.cl[1].light_shadowed;
out_color.a = saturate(1.0 - avg(g_transmittance));
out_color.a = saturate(1.0 - average(g_transmittance));
/* Reset for the next closure tree. */
closure_weights_reset();
@@ -84,8 +83,8 @@ void main()
float thickness = nodetree_thickness();
float vPz = dot(cameraForward, g_data.P) - dot(cameraForward, cameraPos);
vec3 V = cameraVec(g_data.P);
float vPz = dot(drw_view_forward(), g_data.P) - dot(drw_view_forward(), drw_view_position());
vec3 V = drw_world_incident_vector(g_data.P);
ClosureLightStack stack;
@@ -176,7 +175,7 @@ void main()
output_renderpass_color(uniform_buf.render_pass.specular_color_id, vec4(specular_color, 1.0));
output_renderpass_color(uniform_buf.render_pass.specular_light_id, vec4(specular_light, 1.0));
output_renderpass_color(uniform_buf.render_pass.emission_id, vec4(g_emission, 1.0));
output_renderpass_value(uniform_buf.render_pass.shadow_id, avg(shadows));
output_renderpass_value(uniform_buf.render_pass.shadow_id, average(shadows));
/** NOTE: AO is done on its own pass. */
#endif
@@ -197,5 +196,5 @@ void main()
out_radiance.rgb *= 1.0 - g_holdout;
out_transmittance.rgb = g_transmittance;
out_transmittance.a = saturate(avg(g_transmittance));
out_transmittance.a = saturate(average(g_transmittance));
}

View File

@@ -2,7 +2,9 @@
*
* SPDX-License-Identifier: GPL-2.0-or-later */
#pragma BLENDER_REQUIRE(common_math_lib.glsl)
#pragma BLENDER_REQUIRE(draw_model_lib.glsl)
#pragma BLENDER_REQUIRE(gpu_shader_math_base_lib.glsl)
#pragma BLENDER_REQUIRE(gpu_shader_math_vector_lib.glsl)
#pragma BLENDER_REQUIRE(gpu_shader_codegen_lib.glsl)
#pragma BLENDER_REQUIRE(eevee_nodetree_lib.glsl)
#pragma BLENDER_REQUIRE(eevee_sampling_lib.glsl)
@@ -60,7 +62,7 @@ void init_globals_curves()
g_data.N = g_data.Ni = normalize(interp.N * sin_theta + curve_interp.binormal * cos_theta);
/* Costly, but follows cycles per pixel tangent space (not following curve shape). */
vec3 V = cameraVec(g_data.P);
vec3 V = drw_world_incident_vector(g_data.P);
g_data.curve_T = -curve_interp.tangent;
g_data.curve_B = cross(V, g_data.curve_T);
g_data.curve_N = safe_normalize(cross(g_data.curve_T, g_data.curve_B));
@@ -94,7 +96,7 @@ void init_globals()
g_data.hair_strand_id = 0;
g_data.ray_type = RAY_TYPE_CAMERA; /* TODO */
g_data.ray_depth = 0.0;
g_data.ray_length = distance(g_data.P, cameraPos);
g_data.ray_length = distance(g_data.P, drw_view_position());
g_data.barycentric_coords = vec2(0.0);
g_data.barycentric_dists = vec3(0.0);

View File

@@ -11,8 +11,7 @@
* the destination texel.
*/
#pragma BLENDER_REQUIRE(common_view_lib.glsl)
#pragma BLENDER_REQUIRE(common_math_lib.glsl)
#pragma BLENDER_REQUIRE(draw_view_lib.glsl)
#pragma BLENDER_REQUIRE(eevee_attributes_lib.glsl)
#pragma BLENDER_REQUIRE(eevee_surf_lib.glsl)
#pragma BLENDER_REQUIRE(eevee_nodetree_lib.glsl)
@@ -30,7 +29,7 @@ void main()
float noise_offset = sampling_rng_1D_get(SAMPLING_TRANSPARENCY);
float random_threshold = transparency_hashed_alpha_threshold(1.0, noise_offset, g_data.P);
float transparency = avg(g_transmittance);
float transparency = average(g_transmittance);
if (transparency > random_threshold) {
discard;
return;

View File

@@ -8,11 +8,11 @@
* Outputs shading parameter per pixel using a set of randomized BSDFs.
*/
#pragma BLENDER_REQUIRE(common_view_lib.glsl)
#pragma BLENDER_REQUIRE(common_math_lib.glsl)
#pragma BLENDER_REQUIRE(draw_view_lib.glsl)
#pragma BLENDER_REQUIRE(eevee_attributes_lib.glsl)
#pragma BLENDER_REQUIRE(eevee_surf_lib.glsl)
#pragma BLENDER_REQUIRE(eevee_nodetree_lib.glsl)
#pragma BLENDER_REQUIRE(eevee_colorspace_lib.glsl)
void main()
{
@@ -21,7 +21,7 @@ void main()
init_globals();
/* View position is passed to keep accuracy. */
g_data.N = normal_view_to_world(viewCameraVec(interp.P));
g_data.N = normal_view_to_world(drw_view_incident_vector(interp.P));
g_data.Ng = g_data.N;
g_data.P = -g_data.N;
attrib_load();
@@ -30,8 +30,8 @@ void main()
g_holdout = saturate(g_holdout);
out_background.rgb = safe_color(g_emission) * (1.0 - g_holdout);
out_background.a = saturate(avg(g_transmittance)) * g_holdout;
out_background.rgb = colorspace_safe_color(g_emission) * (1.0 - g_holdout);
out_background.a = saturate(average(g_transmittance)) * g_holdout;
/* World opacity. */
out_background = mix(vec4(0.0, 0.0, 0.0, 1.0), out_background, world_opacity_fade);

View File

@@ -2,7 +2,7 @@
*
* SPDX-License-Identifier: GPL-2.0-or-later */
#pragma BLENDER_REQUIRE(common_view_lib.glsl)
#pragma BLENDER_REQUIRE(draw_view_lib.glsl)
#pragma BLENDER_REQUIRE(gpu_shader_math_matrix_lib.glsl)
/**
@@ -12,10 +12,9 @@
*/
int surfel_list_index_get(ivec2 ray_grid_size, vec3 P, out float r_ray_distance)
{
vec4 hP = point_world_to_ndc(P);
r_ray_distance = -hP.z;
vec2 ssP = hP.xy * 0.5 + 0.5;
ivec2 ray_coord_on_grid = ivec2(ssP * vec2(ray_grid_size));
vec3 ssP = drw_point_world_to_screen(P);
r_ray_distance = -ssP.z;
ivec2 ray_coord_on_grid = ivec2(ssP.xy * vec2(ray_grid_size));
ray_coord_on_grid = clamp(ray_coord_on_grid, ivec2(0), ray_grid_size - 1);
int list_index = ray_coord_on_grid.y * ray_grid_size.x + ray_coord_on_grid.x;

View File

@@ -11,11 +11,11 @@
* Dispatched as 1 thread per surfel.
*/
#pragma BLENDER_REQUIRE(draw_view_lib.glsl)
#pragma BLENDER_REQUIRE(gpu_shader_utildefines_lib.glsl)
#pragma BLENDER_REQUIRE(gpu_shader_math_base_lib.glsl)
#pragma BLENDER_REQUIRE(gpu_shader_math_vector_lib.glsl)
#pragma BLENDER_REQUIRE(eevee_reflection_probe_lib.glsl)
#pragma BLENDER_REQUIRE(common_view_lib.glsl)
#pragma BLENDER_REQUIRE(common_math_lib.glsl)
float avg_albedo(vec3 albedo)
{
@@ -25,7 +25,7 @@ float avg_albedo(vec3 albedo)
void radiance_transfer(inout Surfel surfel, vec3 in_radiance, float in_visibility, vec3 L)
{
/* Clamped brightness. */
float luma = max(1e-8, max_v3(in_radiance));
float luma = max(1e-8, reduce_max(in_radiance));
in_radiance *= 1.0 - max(0.0, luma - capture_info_buf.clamp_indirect) / luma;
float NL = dot(surfel.normal, L);
@@ -110,7 +110,7 @@ void main()
Surfel surfel = surfel_buf[surfel_index];
vec3 sky_L = cameraVec(surfel.position);
vec3 sky_L = drw_world_incident_vector(surfel.position);
if (surfel.next > -1) {
Surfel surfel_next = surfel_buf[surfel.next];

View File

@@ -2,7 +2,8 @@
*
* SPDX-License-Identifier: GPL-2.0-or-later */
#pragma BLENDER_REQUIRE(common_view_lib.glsl)
#pragma BLENDER_REQUIRE(gpu_shader_math_matrix_lib.glsl)
#pragma BLENDER_REQUIRE(draw_view_lib.glsl)
#pragma BLENDER_REQUIRE(eevee_camera_lib.glsl)
vec4 velocity_pack(vec4 data)
@@ -71,12 +72,12 @@ vec4 velocity_resolve(vec4 vector, vec2 uv, float depth)
bool is_background = (depth == 1.0);
if (is_background) {
/* NOTE: Use viewCameraVec to avoid imprecision if camera is far from origin. */
vec3 vV = viewCameraVec(get_view_space_from_depth(uv, 1.0));
vec3 vV = drw_view_incident_vector(drw_point_screen_to_view(vec3(uv, 1.0)));
return velocity_background(vV);
}
else {
/* Static geometry. No translation in world space. */
vec3 P = get_world_space_from_depth(uv, depth);
vec3 P = drw_point_screen_to_world(vec3(uv, depth));
return velocity_surface(P, P, P);
}
}

View File

@@ -8,6 +8,7 @@
/* Step 3 : Integrate for each froxel the final amount of light
* scattered back to the viewer and the amount of transmittance. */
#pragma BLENDER_REQUIRE(draw_view_lib.glsl)
#pragma BLENDER_REQUIRE(eevee_volume_lib.glsl)
void main()
@@ -25,8 +26,8 @@ void main()
/* Compute view ray. */
vec2 uvs = (vec2(texel) + vec2(0.5)) / vec2(tex_size.xy);
vec3 ndc_cell = volume_to_ndc(vec3(uvs, 1e-5));
vec3 view_cell = get_view_space_from_depth(ndc_cell.xy, ndc_cell.z);
vec3 ss_cell = volume_to_screen(vec3(uvs, 1e-5));
vec3 view_cell = drw_point_screen_to_view(ss_cell);
float prev_ray_len;
float orig_ray_len;

View File

@@ -7,7 +7,7 @@
* - uniform_buf.volumes
*/
#pragma BLENDER_REQUIRE(common_view_lib.glsl)
#pragma BLENDER_REQUIRE(draw_view_lib.glsl)
#pragma BLENDER_REQUIRE(eevee_light_lib.glsl)
#pragma BLENDER_REQUIRE(eevee_shadow_lib.glsl)
@@ -35,23 +35,23 @@ float view_z_to_volume_z(float depth)
return view_z_to_volume_z(near, far, distribution, is_persp, depth);
}
/* Volume texture normalized coordinates to NDC (special range [0, 1]). */
vec3 volume_to_ndc(vec3 coord)
/* Volume texture normalized coordinates to screen UVs (special range [0, 1]). */
vec3 volume_to_screen(vec3 coord)
{
coord.z = volume_z_to_view_z(coord.z);
coord.z = get_depth_from_view_z(coord.z);
coord.z = drw_depth_view_to_screen(coord.z);
coord.xy /= uniform_buf.volumes.coord_scale;
return coord;
}
vec3 ndc_to_volume(vec3 coord)
vec3 screen_to_volume(vec3 coord)
{
float near = uniform_buf.volumes.depth_near;
float far = uniform_buf.volumes.depth_far;
float distribution = uniform_buf.volumes.depth_distribution;
vec2 coord_scale = uniform_buf.volumes.coord_scale;
/* Implemented in eevee_shader_shared.cc */
return ndc_to_volume(ProjectionMatrix, near, far, distribution, coord_scale, coord);
return screen_to_volume(ProjectionMatrix, near, far, distribution, coord_scale, coord);
}
float volume_phase_function_isotropic()
@@ -76,7 +76,7 @@ vec3 volume_light(LightData light, const bool is_directional, LightVector lv)
float light_clamp = uniform_buf.volumes.light_clamp;
if (light_clamp != 0.0) {
/* 0.0 light clamp means it's disabled. */
float max_power = max_v3(light.color) * light.power[LIGHT_VOLUME];
float max_power = reduce_max(light.color) * light.power[LIGHT_VOLUME];
if (max_power > 0.0) {
/* The limit of the power attenuation function when the distance to the light goes to 0 is
* `2 / r^2` where r is the light radius. We need to find the right radius that emits at
@@ -93,7 +93,7 @@ vec3 volume_light(LightData light, const bool is_directional, LightVector lv)
* http://www.cemyuksel.com/research/pointlightattenuation/
*/
float d = lv.dist;
float d_sqr = sqr(d);
float d_sqr = square(d);
float r_sqr = volume_radius_squared;
/* Using reformulation that has better numerical precision. */
@@ -123,14 +123,12 @@ vec3 volume_shadow(
if (is_directional) {
/* For sun light we scan the whole frustum. So we need to get the correct endpoints. */
vec3 ndcP = project_point(ProjectionMatrix, transform_point(ViewMatrix, P));
vec3 ndcL = project_point(ProjectionMatrix, transform_point(ViewMatrix, P + lv.L * lv.dist)) -
ndcP;
vec3 ndcP = drw_point_world_to_ndc(P);
vec3 ndcL = drw_point_world_to_ndc(P + lv.L * lv.dist) - ndcP;
vec3 frustum_isect = ndcP + ndcL * line_unit_box_intersect_dist_safe(ndcP, ndcL);
vec4 L_hom = ViewMatrixInverse * (ProjectionMatrixInverse * vec4(frustum_isect, 1.0));
L = (L_hom.xyz / L_hom.w) - P;
L = drw_point_screen_to_world(frustum_isect) - P;
L /= uniform_buf.volumes.shadow_steps;
dd = length(L);
}
@@ -142,8 +140,8 @@ vec3 volume_shadow(
{
vec3 pos = P + L * t;
vec3 ndc = project_point(ProjectionMatrix, transform_point(ViewMatrix, pos));
vec3 volume_co = ndc_to_volume(ndc * 0.5 + 0.5);
vec3 ndc = drw_point_world_to_ndc(pos);
vec3 volume_co = screen_to_volume(drw_ndc_to_screen(ndc));
/* Let the texture be clamped to edge. This reduce visual glitches. */
vec3 s_extinction = texture(extinction_tx, volume_co).rgb;
@@ -172,7 +170,7 @@ struct VolumeResolveSample {
VolumeResolveSample volume_resolve(vec3 ndc_P, sampler3D transmittance_tx, sampler3D scattering_tx)
{
vec3 coord = ndc_to_volume(ndc_P);
vec3 coord = screen_to_volume(ndc_P);
VolumeResolveSample volume;
volume.scattering = texture(scattering_tx, coord).rgb;

View File

@@ -5,8 +5,6 @@
#pragma BLENDER_REQUIRE(eevee_volume_lib.glsl)
/* Needed includes for shader nodes. */
#pragma BLENDER_REQUIRE(common_math_lib.glsl)
#pragma BLENDER_REQUIRE(common_view_lib.glsl)
#pragma BLENDER_REQUIRE(common_attribute_lib.glsl)
#pragma BLENDER_REQUIRE(eevee_sampling_lib.glsl)
#pragma BLENDER_REQUIRE(eevee_attributes_lib.glsl)
@@ -31,7 +29,7 @@ GlobalData init_globals(vec3 wP)
surf.barycentric_dists = vec3(0.0);
surf.ray_type = RAY_TYPE_CAMERA;
surf.ray_depth = 0.0;
surf.ray_length = distance(surf.P, cameraPos);
surf.ray_length = distance(surf.P, drw_view_position());
return surf;
}
@@ -52,7 +50,7 @@ void main()
}
vec3 jitter = sampling_rng_3D_get(SAMPLING_VOLUME_U);
vec3 ndc_cell = volume_to_ndc((vec3(froxel) + jitter) * uniform_buf.volumes.inv_tex_size);
vec3 ndc_cell = volume_to_screen((vec3(froxel) + jitter) * uniform_buf.volumes.inv_tex_size);
vec3 vP = get_view_space_from_depth(ndc_cell.xy, ndc_cell.z);
vec3 wP = point_view_to_world(vP);

View File

@@ -18,7 +18,7 @@ void main()
vec3(uvs, scene_depth), volume_transmittance_tx, volume_scattering_tx);
out_radiance = vec4(vol.scattering, 0.0);
out_transmittance = vec4(vol.transmittance, saturate(avg(vol.transmittance)));
out_transmittance = vec4(vol.transmittance, saturate(average(vol.transmittance)));
if (uniform_buf.render_pass.volume_light_id >= 0) {
imageStore(rp_color_img,

View File

@@ -9,7 +9,6 @@
* Also do the temporal reprojection to fight aliasing artifacts. */
#pragma BLENDER_REQUIRE(gpu_shader_math_vector_lib.glsl)
#pragma BLENDER_REQUIRE(common_math_lib.glsl)
/* Included here to avoid requiring lightprobe resources for all volume lib users. */
#pragma BLENDER_REQUIRE(eevee_lightprobe_eval_lib.glsl)
@@ -68,10 +67,11 @@ void main()
vec3 s_scattering = imageLoad(in_scattering_img, froxel).rgb;
vec3 jitter = sampling_rng_3D_get(SAMPLING_VOLUME_U);
vec3 volume_ndc = volume_to_ndc((vec3(froxel) + jitter) * uniform_buf.volumes.inv_tex_size);
vec3 vP = get_view_space_from_depth(volume_ndc.xy, volume_ndc.z);
vec3 P = point_view_to_world(vP);
vec3 V = cameraVec(P);
vec3 volume_screen = volume_to_screen((vec3(froxel) + jitter) *
uniform_buf.volumes.inv_tex_size);
vec3 vP = drw_point_screen_to_view(volume_screen);
vec3 P = drw_point_view_to_world(vP);
vec3 V = drw_world_incident_vector(P);
vec2 phase = imageLoad(in_phase_img, froxel).rg;
/* Divide by phase total weight, to compute the mean anisotropy. */

View File

@@ -249,6 +249,7 @@ GPU_SHADER_CREATE_INFO(eevee_volume_material_common)
.local_group_size(VOLUME_GROUP_SIZE, VOLUME_GROUP_SIZE, VOLUME_GROUP_SIZE)
.define("VOLUMETRICS")
.additional_info("draw_modelmat_new_common",
/* TODO(fclem): Legacy API. To remove. */
"draw_resource_id_uniform",
"draw_view",
"eevee_shared",
@@ -343,7 +344,8 @@ GPU_SHADER_CREATE_INFO(eevee_material_stub)
# define EEVEE_MAT_GEOM_VARIATIONS(prefix, ...) \
EEVEE_MAT_FINAL_VARIATION(prefix##_world, "eevee_geom_world", __VA_ARGS__) \
EEVEE_MAT_FINAL_VARIATION(prefix##_gpencil, "eevee_geom_gpencil", __VA_ARGS__) \
/* Turned off until dependency on common_view/math_lib are sorted out. */ \
/* EEVEE_MAT_FINAL_VARIATION(prefix##_gpencil, "eevee_geom_gpencil", __VA_ARGS__) */ \
EEVEE_MAT_FINAL_VARIATION(prefix##_curves, "eevee_geom_curves", __VA_ARGS__) \
EEVEE_MAT_FINAL_VARIATION(prefix##_mesh, "eevee_geom_mesh", __VA_ARGS__) \
EEVEE_MAT_FINAL_VARIATION(prefix##_point_cloud, "eevee_geom_point_cloud", __VA_ARGS__)

View File

@@ -129,7 +129,7 @@ IsectFrustum isect_data_setup(Frustum shape)
/** \name View Intersection functions.
* \{ */
#ifdef COMMON_VIEW_LIB_GLSL
#ifdef DRW_VIEW_CULLING_INFO
bool intersect_view(Pyramid pyramid)
{

View File

@@ -114,6 +114,8 @@ float avg(vec4 v) { return dot(vec4(1.0 / 4.0), v); }
/* WORKAROUND: To be removed once we port all code to use gpu_shader_math_base_lib.glsl. */
#ifndef GPU_SHADER_MATH_BASE_LIB_GLSL
float safe_rcp(float a) { return (a != 0.0) ? (1.0 / a) : 0.0; }
float safe_sqrt(float a) { return sqrt(max(a, 0.0)); }
float safe_acos(float a) { return acos(clamp(a, -1.0, 1.0)); }
#endif
#ifndef GPU_SHADER_MATH_VECTOR_LIB_GLSL
vec2 safe_rcp(vec2 a) { return select(vec2(0.0), (1.0 / a), notEqual(a, vec2(0.0))); }
@@ -121,10 +123,6 @@ vec3 safe_rcp(vec3 a) { return select(vec3(0.0), (1.0 / a), notEqual(a, vec3(0.0
vec4 safe_rcp(vec4 a) { return select(vec4(0.0), (1.0 / a), notEqual(a, vec4(0.0))); }
#endif
float safe_sqrt(float a) { return sqrt(max(a, 0.0)); }
float safe_acos(float a) { return acos(clamp(a, -1.0, 1.0)); }
float sqr(float a) { return a * a; }
vec2 sqr(vec2 a) { return a * a; }
vec3 sqr(vec3 a) { return a * a; }
@@ -146,10 +144,10 @@ bool flag_test(int flag, int val) { return (flag & val) != 0; }
void set_flag_from_test(inout uint value, bool test, uint flag) { if (test) { value |= flag; } else { value &= ~flag; } }
void set_flag_from_test(inout int value, bool test, int flag) { if (test) { value |= flag; } else { value &= ~flag; } }
#endif
#define weighted_sum(val0, val1, val2, val3, weights) ((val0 * weights[0] + val1 * weights[1] + val2 * weights[2] + val3 * weights[3]) * safe_rcp(sum(weights)))
#define weighted_sum_array(val, weights) ((val[0] * weights[0] + val[1] * weights[1] + val[2] * weights[2] + val[3] * weights[3]) * safe_rcp(sum(weights)))
#endif
/* clang-format on */

View File

@@ -8,8 +8,6 @@
* allow for more than one constructor per type.
*/
#pragma BLENDER_REQUIRE(common_math_geom_lib.glsl)
/* ---------------------------------------------------------------------- */
/** \name Circle
* \{ */

View File

@@ -0,0 +1,520 @@
/* SPDX-FileCopyrightText: 2022-2023 Blender Authors
*
* SPDX-License-Identifier: GPL-2.0-or-later */
/**
* Intersection library used for culling.
* Results are meant to be conservative.
*/
#pragma BLENDER_REQUIRE(gpu_shader_utildefines_lib.glsl)
#pragma BLENDER_REQUIRE(draw_math_geom_lib.glsl)
#pragma BLENDER_REQUIRE(common_shape_lib.glsl)
/* ---------------------------------------------------------------------- */
/** \name Plane extraction functions.
* \{ */
/** \a v1 and \a v2 are vectors on the plane. \a p is a point on the plane. */
vec4 isect_plane_setup(vec3 p, vec3 v1, vec3 v2)
{
vec3 normal_to_plane = normalize(cross(v1, v2));
return vec4(normal_to_plane, -dot(normal_to_plane, p));
}
struct IsectPyramid {
vec3 corners[5];
vec4 planes[5];
};
IsectPyramid isect_data_setup(Pyramid shape)
{
vec3 A1 = shape.corners[1] - shape.corners[0];
vec3 A2 = shape.corners[2] - shape.corners[0];
vec3 A3 = shape.corners[3] - shape.corners[0];
vec3 A4 = shape.corners[4] - shape.corners[0];
vec3 S4 = shape.corners[4] - shape.corners[1];
vec3 S2 = shape.corners[2] - shape.corners[1];
IsectPyramid data;
data.planes[0] = isect_plane_setup(shape.corners[0], A2, A1);
data.planes[1] = isect_plane_setup(shape.corners[0], A3, A2);
data.planes[2] = isect_plane_setup(shape.corners[0], A4, A3);
data.planes[3] = isect_plane_setup(shape.corners[0], A1, A4);
data.planes[4] = isect_plane_setup(shape.corners[1], S2, S4);
for (int i = 0; i < 5; i++) {
data.corners[i] = shape.corners[i];
}
return data;
}
struct IsectBox {
vec3 corners[8];
vec4 planes[6];
};
IsectBox isect_data_setup(Box shape)
{
vec3 A1 = shape.corners[1] - shape.corners[0];
vec3 A3 = shape.corners[3] - shape.corners[0];
vec3 A4 = shape.corners[4] - shape.corners[0];
IsectBox data;
data.planes[0] = isect_plane_setup(shape.corners[0], A3, A1);
data.planes[1] = isect_plane_setup(shape.corners[0], A4, A3);
data.planes[2] = isect_plane_setup(shape.corners[0], A1, A4);
/* Assumes that the box is actually a box! */
data.planes[3] = vec4(-data.planes[0].xyz, -dot(-data.planes[0].xyz, shape.corners[6]));
data.planes[4] = vec4(-data.planes[1].xyz, -dot(-data.planes[1].xyz, shape.corners[6]));
data.planes[5] = vec4(-data.planes[2].xyz, -dot(-data.planes[2].xyz, shape.corners[6]));
for (int i = 0; i < 8; i++) {
data.corners[i] = shape.corners[i];
}
return data;
}
/* Construct box from 1 corner point + 3 side vectors. */
IsectBox isect_data_setup(vec3 origin, vec3 side_x, vec3 side_y, vec3 side_z)
{
IsectBox data;
data.corners[0] = origin;
data.corners[1] = origin + side_x;
data.corners[2] = origin + side_y + side_x;
data.corners[3] = origin + side_y;
data.corners[4] = data.corners[0] + side_z;
data.corners[5] = data.corners[1] + side_z;
data.corners[6] = data.corners[2] + side_z;
data.corners[7] = data.corners[3] + side_z;
data.planes[0] = isect_plane_setup(data.corners[0], side_y, side_z);
data.planes[1] = isect_plane_setup(data.corners[0], side_x, side_y);
data.planes[2] = isect_plane_setup(data.corners[0], side_z, side_x);
/* Assumes that the box is actually a box! */
data.planes[3] = vec4(-data.planes[0].xyz, -dot(-data.planes[0].xyz, data.corners[6]));
data.planes[4] = vec4(-data.planes[1].xyz, -dot(-data.planes[1].xyz, data.corners[6]));
data.planes[5] = vec4(-data.planes[2].xyz, -dot(-data.planes[2].xyz, data.corners[6]));
return data;
}
struct IsectFrustum {
vec3 corners[8];
vec4 planes[6];
};
IsectFrustum isect_data_setup(Frustum shape)
{
vec3 A1 = shape.corners[1] - shape.corners[0];
vec3 A3 = shape.corners[3] - shape.corners[0];
vec3 A4 = shape.corners[4] - shape.corners[0];
vec3 B5 = shape.corners[5] - shape.corners[6];
vec3 B7 = shape.corners[7] - shape.corners[6];
vec3 B2 = shape.corners[2] - shape.corners[6];
IsectFrustum data;
data.planes[0] = isect_plane_setup(shape.corners[0], A3, A1);
data.planes[1] = isect_plane_setup(shape.corners[0], A4, A3);
data.planes[2] = isect_plane_setup(shape.corners[0], A1, A4);
data.planes[3] = isect_plane_setup(shape.corners[6], B7, B5);
data.planes[4] = isect_plane_setup(shape.corners[6], B5, B2);
data.planes[5] = isect_plane_setup(shape.corners[6], B2, B7);
for (int i = 0; i < 8; i++) {
data.corners[i] = shape.corners[i];
}
return data;
}
/** \} */
/* ---------------------------------------------------------------------- */
/** \name View Intersection functions.
* \{ */
#ifdef DRW_VIEW_CULLING_INFO
bool intersect_view(Pyramid pyramid)
{
bool intersects = true;
/* Do Pyramid vertices vs Frustum planes. */
for (int p = 0; p < 6; ++p) {
bool is_any_vertex_on_positive_side = false;
for (int v = 0; v < 5; ++v) {
float test = dot(drw_view_culling.frustum_planes.planes[p], vec4(pyramid.corners[v], 1.0));
if (test > 0.0) {
is_any_vertex_on_positive_side = true;
break;
}
}
bool all_vertex_on_negative_side = !is_any_vertex_on_positive_side;
if (all_vertex_on_negative_side) {
intersects = false;
break;
}
}
if (!intersects) {
return intersects;
}
/* Now do Frustum vertices vs Pyramid planes. */
IsectPyramid i_pyramid = isect_data_setup(pyramid);
for (int p = 0; p < 5; ++p) {
bool is_any_vertex_on_positive_side = false;
for (int v = 0; v < 8; ++v) {
float test = dot(i_pyramid.planes[p],
vec4(drw_view_culling.frustum_corners.corners[v].xyz, 1.0));
if (test > 0.0) {
is_any_vertex_on_positive_side = true;
break;
}
}
bool all_vertex_on_negative_side = !is_any_vertex_on_positive_side;
if (all_vertex_on_negative_side) {
intersects = false;
break;
}
}
return intersects;
}
bool intersect_view(Box box)
{
bool intersects = true;
/* Do Box vertices vs Frustum planes. */
for (int p = 0; p < 6; ++p) {
bool is_any_vertex_on_positive_side = false;
for (int v = 0; v < 8; ++v) {
float test = dot(drw_view_culling.frustum_planes.planes[p], vec4(box.corners[v], 1.0));
if (test > 0.0) {
is_any_vertex_on_positive_side = true;
break;
}
}
bool all_vertex_on_negative_side = !is_any_vertex_on_positive_side;
if (all_vertex_on_negative_side) {
intersects = false;
break;
}
}
if (!intersects) {
return intersects;
}
/* Now do Frustum vertices vs Box planes. */
IsectBox i_box = isect_data_setup(box);
for (int p = 0; p < 6; ++p) {
bool is_any_vertex_on_positive_side = false;
for (int v = 0; v < 8; ++v) {
float test = dot(i_box.planes[p],
vec4(drw_view_culling.frustum_corners.corners[v].xyz, 1.0));
if (test > 0.0) {
is_any_vertex_on_positive_side = true;
break;
}
}
bool all_vertex_on_negative_side = !is_any_vertex_on_positive_side;
if (all_vertex_on_negative_side) {
intersects = false;
break;
}
}
return intersects;
}
bool intersect_view(IsectBox i_box)
{
bool intersects = true;
/* Do Box vertices vs Frustum planes. */
for (int p = 0; p < 6; ++p) {
bool is_any_vertex_on_positive_side = false;
for (int v = 0; v < 8; ++v) {
float test = dot(drw_view_culling.frustum_planes.planes[p], vec4(i_box.corners[v], 1.0));
if (test > 0.0) {
is_any_vertex_on_positive_side = true;
break;
}
}
bool all_vertex_on_negative_side = !is_any_vertex_on_positive_side;
if (all_vertex_on_negative_side) {
intersects = false;
break;
}
}
if (!intersects) {
return intersects;
}
for (int p = 0; p < 6; ++p) {
bool is_any_vertex_on_positive_side = false;
for (int v = 0; v < 8; ++v) {
float test = dot(i_box.planes[p],
vec4(drw_view_culling.frustum_corners.corners[v].xyz, 1.0));
if (test > 0.0) {
is_any_vertex_on_positive_side = true;
break;
}
}
bool all_vertex_on_negative_side = !is_any_vertex_on_positive_side;
if (all_vertex_on_negative_side) {
intersects = false;
break;
}
}
return intersects;
}
bool intersect_view(Sphere sphere)
{
bool intersects = true;
for (int p = 0; p < 6 && intersects; ++p) {
float dist_to_plane = dot(drw_view_culling.frustum_planes.planes[p], vec4(sphere.center, 1.0));
if (dist_to_plane < -sphere.radius) {
intersects = false;
}
}
/* TODO reject false positive. */
return intersects;
}
#endif
/** \} */
/* ---------------------------------------------------------------------- */
/** \name Shape vs. Shape Intersection functions.
* \{ */
bool intersect(IsectPyramid i_pyramid, Box box)
{
bool intersects = true;
/* Do Box vertices vs Pyramid planes. */
for (int p = 0; p < 5; ++p) {
bool is_any_vertex_on_positive_side = false;
for (int v = 0; v < 8; ++v) {
float test = dot(i_pyramid.planes[p], vec4(box.corners[v], 1.0));
if (test > 0.0) {
is_any_vertex_on_positive_side = true;
break;
}
}
bool all_vertex_on_negative_side = !is_any_vertex_on_positive_side;
if (all_vertex_on_negative_side) {
intersects = false;
break;
}
}
if (!intersects) {
return intersects;
}
/* Now do Pyramid vertices vs Box planes. */
IsectBox i_box = isect_data_setup(box);
for (int p = 0; p < 6; ++p) {
bool is_any_vertex_on_positive_side = false;
for (int v = 0; v < 5; ++v) {
float test = dot(i_box.planes[p], vec4(i_pyramid.corners[v], 1.0));
if (test > 0.0) {
is_any_vertex_on_positive_side = true;
break;
}
}
bool all_vertex_on_negative_side = !is_any_vertex_on_positive_side;
if (all_vertex_on_negative_side) {
intersects = false;
break;
}
}
return intersects;
}
bool intersect(IsectPyramid i_pyramid, IsectBox i_box)
{
bool intersects = true;
/* Do Box vertices vs Pyramid planes. */
for (int p = 0; p < 5; ++p) {
bool is_any_vertex_on_positive_side = false;
for (int v = 0; v < 8; ++v) {
float test = dot(i_pyramid.planes[p], vec4(i_box.corners[v], 1.0));
if (test > 0.0) {
is_any_vertex_on_positive_side = true;
break;
}
}
bool all_vertex_on_negative_side = !is_any_vertex_on_positive_side;
if (all_vertex_on_negative_side) {
intersects = false;
break;
}
}
if (!intersects) {
return intersects;
}
/* Now do Pyramid vertices vs Box planes. */
for (int p = 0; p < 6; ++p) {
bool is_any_vertex_on_positive_side = false;
for (int v = 0; v < 5; ++v) {
float test = dot(i_box.planes[p], vec4(i_pyramid.corners[v], 1.0));
if (test > 0.0) {
is_any_vertex_on_positive_side = true;
break;
}
}
bool all_vertex_on_negative_side = !is_any_vertex_on_positive_side;
if (all_vertex_on_negative_side) {
intersects = false;
break;
}
}
return intersects;
}
bool intersect(IsectFrustum i_frustum, Pyramid pyramid)
{
bool intersects = true;
/* Do Pyramid vertices vs Frustum planes. */
for (int p = 0; p < 6; ++p) {
bool is_any_vertex_on_positive_side = false;
for (int v = 0; v < 5; ++v) {
float test = dot(i_frustum.planes[p], vec4(pyramid.corners[v], 1.0));
if (test > 0.0) {
is_any_vertex_on_positive_side = true;
break;
}
}
bool all_vertex_on_negative_side = !is_any_vertex_on_positive_side;
if (all_vertex_on_negative_side) {
intersects = false;
break;
}
}
if (!intersects) {
return intersects;
}
/* Now do Frustum vertices vs Pyramid planes. */
IsectPyramid i_pyramid = isect_data_setup(pyramid);
for (int p = 0; p < 5; ++p) {
bool is_any_vertex_on_positive_side = false;
for (int v = 0; v < 8; ++v) {
float test = dot(i_pyramid.planes[p], vec4(i_frustum.corners[v].xyz, 1.0));
if (test > 0.0) {
is_any_vertex_on_positive_side = true;
break;
}
}
bool all_vertex_on_negative_side = !is_any_vertex_on_positive_side;
if (all_vertex_on_negative_side) {
intersects = false;
break;
}
}
return intersects;
}
bool intersect(IsectFrustum i_frustum, Box box)
{
bool intersects = true;
/* Do Box vertices vs Frustum planes. */
for (int p = 0; p < 6; ++p) {
bool is_any_vertex_on_positive_side = false;
for (int v = 0; v < 8; ++v) {
float test = dot(i_frustum.planes[p], vec4(box.corners[v], 1.0));
if (test > 0.0) {
is_any_vertex_on_positive_side = true;
break;
}
}
bool all_vertex_on_negative_side = !is_any_vertex_on_positive_side;
if (all_vertex_on_negative_side) {
intersects = false;
break;
}
}
if (!intersects) {
return intersects;
}
/* Now do Frustum vertices vs Box planes. */
IsectBox i_box = isect_data_setup(box);
for (int p = 0; p < 6; ++p) {
bool is_any_vertex_on_positive_side = false;
for (int v = 0; v < 8; ++v) {
float test = dot(i_box.planes[p], vec4(i_frustum.corners[v].xyz, 1.0));
if (test > 0.0) {
is_any_vertex_on_positive_side = true;
break;
}
}
bool all_vertex_on_negative_side = !is_any_vertex_on_positive_side;
if (all_vertex_on_negative_side) {
intersects = false;
break;
}
}
return intersects;
}
bool intersect(IsectFrustum i_frustum, Sphere sphere)
{
bool intersects = true;
for (int p = 0; p < 6; ++p) {
float dist_to_plane = dot(i_frustum.planes[p], vec4(sphere.center, 1.0));
if (dist_to_plane < -sphere.radius) {
intersects = false;
break;
}
}
return intersects;
}
bool intersect(Cone cone, Sphere sphere)
{
/**
* Following "Improve Tile-based Light Culling with Spherical-sliced Cone"
* by Eric Zhang
* https://lxjk.github.io/2018/03/25/Improve-Tile-based-Light-Culling-with-Spherical-sliced-Cone.html
*/
float sphere_distance = length(sphere.center);
float sphere_distance_rcp = safe_rcp(sphere_distance);
float sphere_sin = saturate(sphere.radius * sphere_distance_rcp);
float sphere_cos = sqrt(1.0 - sphere_sin * sphere_sin);
float cone_aperture_sin = sqrt(1.0 - cone.angle_cos * cone.angle_cos);
float cone_sphere_center_cos = dot(sphere.center * sphere_distance_rcp, cone.direction);
/* cos(A+B) = cos(A) * cos(B) - sin(A) * sin(B). */
float cone_sphere_angle_sum_cos = (sphere.radius > sphere_distance) ?
-1.0 :
(cone.angle_cos * sphere_cos -
cone_aperture_sin * sphere_sin);
/* Comparing cosines instead of angles since we are interested
* only in the monotonic region [0 .. M_PI / 2]. This saves costly `acos()` calls. */
bool intersects = (cone_sphere_center_cos >= cone_sphere_angle_sum_cos);
return intersects;
}
bool intersect(Circle circle_a, Circle circle_b)
{
return distance_squared(circle_a.center, circle_b.center) <
square(circle_a.radius + circle_b.radius);
}
/** \} */

View File

@@ -0,0 +1,208 @@
/* SPDX-FileCopyrightText: 2020-2022 Blender Authors
*
* SPDX-License-Identifier: GPL-2.0-or-later */
/**
* Version of common_math_geom_lib.glsl that doesn't rely on common_math_lib.
* This should ultimately be rewritten inside a gpu_shader lib with higher quality standard.
*/
#pragma BLENDER_REQUIRE(gpu_shader_math_vector_lib.glsl)
/* ---------------------------------------------------------------------- */
/** \name Math intersection & projection functions.
* \{ */
vec4 plane_from_quad(vec3 v0, vec3 v1, vec3 v2, vec3 v3)
{
vec3 nor = normalize(cross(v2 - v1, v0 - v1) + cross(v0 - v3, v2 - v3));
return vec4(nor, -dot(nor, v2));
}
vec4 plane_from_tri(vec3 v0, vec3 v1, vec3 v2)
{
vec3 nor = normalize(cross(v2 - v1, v0 - v1));
return vec4(nor, -dot(nor, v2));
}
float point_plane_projection_dist(vec3 line_origin, vec3 plane_origin, vec3 plane_normal)
{
return dot(plane_normal, plane_origin - line_origin);
}
float point_line_projection_dist(vec2 point, vec2 line_origin, vec2 line_normal)
{
return dot(line_normal, line_origin - point);
}
float line_plane_intersect_dist(vec3 line_origin,
vec3 line_direction,
vec3 plane_origin,
vec3 plane_normal)
{
return dot(plane_normal, plane_origin - line_origin) / dot(plane_normal, line_direction);
}
float line_plane_intersect_dist(vec3 line_origin, vec3 line_direction, vec4 plane)
{
vec3 plane_co = plane.xyz * (-plane.w / length_squared(plane.xyz));
vec3 h = line_origin - plane_co;
return -dot(plane.xyz, h) / dot(plane.xyz, line_direction);
}
vec3 line_plane_intersect(vec3 line_origin,
vec3 line_direction,
vec3 plane_origin,
vec3 plane_normal)
{
float dist = line_plane_intersect_dist(line_origin, line_direction, plane_origin, plane_normal);
return line_origin + line_direction * dist;
}
vec3 line_plane_intersect(vec3 line_origin, vec3 line_direction, vec4 plane)
{
float dist = line_plane_intersect_dist(line_origin, line_direction, plane);
return line_origin + line_direction * dist;
}
float line_aligned_plane_intersect_dist(vec3 line_origin, vec3 line_direction, vec3 plane_origin)
{
/* aligned plane normal */
vec3 L = plane_origin - line_origin;
float disk_dist = length(L);
vec3 plane_normal = -normalize(L);
return -disk_dist / dot(plane_normal, line_direction);
}
vec3 line_aligned_plane_intersect(vec3 line_origin, vec3 line_direction, vec3 plane_origin)
{
float dist = line_aligned_plane_intersect_dist(line_origin, line_direction, plane_origin);
if (dist < 0) {
/* if intersection is behind we fake the intersection to be
* really far and (hopefully) not inside the radius of interest */
dist = 1e16;
}
return line_origin + line_direction * dist;
}
/**
* Returns intersection distance between the unit sphere and the line
* with the assumption that \a line_origin is contained in the unit sphere.
* It will always returns the farthest intersection.
*/
float line_unit_sphere_intersect_dist(vec3 line_origin, vec3 line_direction)
{
float a = dot(line_direction, line_direction);
float b = dot(line_direction, line_origin);
float c = dot(line_origin, line_origin) - 1;
float dist = 1e15;
float determinant = b * b - a * c;
if (determinant >= 0) {
dist = (sqrt(determinant) - b) / a;
}
return dist;
}
/**
* Returns minimum intersection distance between the unit box and the line
* with the assumption that \a line_origin is contained in the unit box.
* In other words, it will always returns the farthest intersection.
*/
float line_unit_box_intersect_dist(vec3 line_origin, vec3 line_direction)
{
/* https://seblagarde.wordpress.com/2012/09/29/image-based-lighting-approaches-and-parallax-corrected-cubemap/
*/
vec3 first_plane = (vec3(1.0) - line_origin) / line_direction;
vec3 second_plane = (vec3(-1.0) - line_origin) / line_direction;
vec3 farthest_plane = max(first_plane, second_plane);
return reduce_min(farthest_plane);
}
float line_unit_box_intersect_dist_safe(vec3 line_origin, vec3 line_direction)
{
vec3 safe_line_direction = max(vec3(1e-8), abs(line_direction)) *
select(vec3(1.0), -vec3(1.0), lessThan(line_direction, vec3(0.0)));
return line_unit_box_intersect_dist(line_origin, safe_line_direction);
}
/**
* Same as line_unit_box_intersect_dist but for 2D case.
*/
float line_unit_square_intersect_dist(vec2 line_origin, vec2 line_direction)
{
vec2 first_plane = (vec2(1.0) - line_origin) / line_direction;
vec2 second_plane = (vec2(-1.0) - line_origin) / line_direction;
vec2 farthest_plane = max(first_plane, second_plane);
return reduce_min(farthest_plane);
}
float line_unit_square_intersect_dist_safe(vec2 line_origin, vec2 line_direction)
{
vec2 safe_line_direction = max(vec2(1e-8), abs(line_direction)) *
select(vec2(1.0), -vec2(1.0), lessThan(line_direction, vec2(0.0)));
return line_unit_square_intersect_dist(line_origin, safe_line_direction);
}
/**
* Returns clipping distance (intersection with the nearest plane) with the given axis-aligned
* bound box along \a line_direction.
* Safe even if \a line_direction is degenerate.
* It assumes that an intersection exists (i.e: that \a line_direction points towards the AABB).
*/
float line_aabb_clipping_dist(vec3 line_origin, vec3 line_direction, vec3 aabb_min, vec3 aabb_max)
{
vec3 safe_dir = select(line_direction, vec3(1e-5), lessThan(abs(line_direction), vec3(1e-5)));
vec3 dir_inv = 1.0 / safe_dir;
vec3 first_plane = (aabb_min - line_origin) * dir_inv;
vec3 second_plane = (aabb_max - line_origin) * dir_inv;
vec3 nearest_plane = min(first_plane, second_plane);
return reduce_max(nearest_plane);
}
/** \} */
/* ---------------------------------------------------------------------- */
/** \name Other useful functions.
* \{ */
void make_orthonormal_basis(vec3 N, out vec3 T, out vec3 B)
{
vec3 up_vector = abs(N.z) < 0.99999 ? vec3(0.0, 0.0, 1.0) : vec3(1.0, 0.0, 0.0);
T = normalize(cross(up_vector, N));
B = cross(N, T);
}
/* ---- Encode / Decode Normal buffer data ---- */
/* From http://aras-p.info/texts/CompactNormalStorage.html
* Using Method #4: Sphere-map Transform */
vec2 normal_encode(vec3 n, vec3 view)
{
float p = sqrt(n.z * 8.0 + 8.0);
return n.xy / p + 0.5;
}
vec3 normal_decode(vec2 enc, vec3 view)
{
vec2 fenc = enc * 4.0 - 2.0;
float f = dot(fenc, fenc);
float g = sqrt(1.0 - f / 4.0);
vec3 n;
n.xy = fenc * g;
n.z = 1 - f / 2;
return n;
}
vec3 tangent_to_world(vec3 vector, vec3 N, vec3 T, vec3 B)
{
return T * vector.x + B * vector.y + N * vector.z;
}
vec3 world_to_tangent(vec3 vector, vec3 N, vec3 T, vec3 B)
{
return vec3(dot(T, vector), dot(B, vector), dot(N, vector));
}
/** \} */

View File

@@ -0,0 +1,120 @@
/* SPDX-FileCopyrightText: 2018-2023 Blender Authors
*
* SPDX-License-Identifier: GPL-2.0-or-later */
#pragma BLENDER_REQUIRE(draw_view_lib.glsl)
#ifndef DRAW_MODELMAT_CREATE_INFO
# error Missing draw_modelmat additional create info on shader create info
#endif
#if defined(UNIFORM_RESOURCE_ID)
/* TODO(fclem): Legacy API. To remove. */
# define resource_id drw_ResourceID
# define DRW_RESOURCE_ID_VARYING_SET
#elif defined(GPU_VERTEX_SHADER)
# if defined(UNIFORM_RESOURCE_ID_NEW)
# define resource_id (drw_ResourceID >> DRW_VIEW_SHIFT)
# else
# define resource_id gpu_InstanceIndex
# endif
# define DRW_RESOURCE_ID_VARYING_SET drw_ResourceID_iface.resource_index = resource_id;
#elif defined(GPU_GEOMETRY_SHADER)
# define resource_id drw_ResourceID_iface_in[0].resource_index
#elif defined(GPU_FRAGMENT_SHADER)
# define resource_id drw_ResourceID_iface.resource_index
#endif
mat4x4 drw_modelmat()
{
return drw_matrix_buf[resource_id].model;
}
mat4x4 drw_modelinv()
{
return drw_matrix_buf[resource_id].model_inverse;
}
/**
* Usually Normal matrix is `transpose(inverse(ViewMatrix * ModelMatrix))`.
*
* But since it is slow to multiply matrices we decompose it. Decomposing
* inversion and transposition both invert the product order leaving us with
* the same original order:
* transpose(ViewMatrixInverse) * transpose(ModelMatrixInverse)
*
* Knowing that the view matrix is orthogonal, the transpose is also the inverse.
* NOTE: This is only valid because we are only using the mat3 of the ViewMatrixInverse.
* ViewMatrix * transpose(ModelMatrixInverse)
*/
mat3x3 drw_normat()
{
return transpose(mat3x3(drw_modelinv()));
}
mat3x3 drw_norinv()
{
return transpose(mat3x3(drw_modelmat()));
}
/* -------------------------------------------------------------------- */
/** \name Transform Normal
*
* Space conversion helpers for normal vectors.
* \{ */
vec3 drw_normal_object_to_world(vec3 lN)
{
return (drw_normat() * lN);
}
vec3 drw_normal_world_to_object(vec3 N)
{
return (drw_norinv() * N);
}
vec3 drw_normal_object_to_view(vec3 lN)
{
return (mat3x3(drw_view.viewmat) * (drw_normat() * lN));
}
vec3 drw_normal_view_to_object(vec3 vN)
{
return (drw_norinv() * (mat3x3(drw_view.viewinv) * vN));
}
/** \} */
/* -------------------------------------------------------------------- */
/** \name Transform Normal
*
* Space conversion helpers for points (coordinates).
* \{ */
vec3 drw_point_object_to_world(vec3 lP)
{
return (drw_modelmat() * vec4(lP, 1.0)).xyz;
}
vec3 drw_point_world_to_object(vec3 P)
{
return (drw_modelinv() * vec4(P, 1.0)).xyz;
}
vec3 drw_point_object_to_view(vec3 lP)
{
return (drw_view.viewmat * (drw_modelmat() * vec4(lP, 1.0))).xyz;
}
vec3 drw_point_view_to_object(vec3 vP)
{
return (drw_modelinv() * (drw_view.viewinv * vec4(vP, 1.0))).xyz;
}
vec4 drw_point_object_to_homogenous(vec3 lP)
{
return (drw_view.winmat * (drw_view.viewmat * (drw_modelmat() * vec4(lP, 1.0))));
}
vec3 drw_point_object_to_ndc(vec3 lP)
{
return drw_perspective_divide(drw_point_object_to_homogenous(lP));
}
/** \} */

View File

@@ -48,11 +48,13 @@ GPU_SHADER_CREATE_INFO(draw_resource_handle)
GPU_SHADER_CREATE_INFO(draw_view)
.uniform_buf(DRW_VIEW_UBO_SLOT, "ViewMatrices", "drw_view_[DRW_VIEW_LEN]", Frequency::PASS)
.define("DRAW_VIEW_CREATE_INFO")
.define("drw_view", "drw_view_[drw_view_id]")
.typedef_source("draw_shader_shared.h");
GPU_SHADER_CREATE_INFO(draw_view_culling)
.uniform_buf(DRW_VIEW_CULLING_UBO_SLOT, "ViewCullingData", "drw_view_culling_[DRW_VIEW_LEN]")
.define("DRW_VIEW_CULLING_INFO")
.define("drw_view_culling", "drw_view_culling_[drw_view_id]")
.typedef_source("draw_shader_shared.h");
@@ -279,6 +281,7 @@ GPU_SHADER_CREATE_INFO(draw_resource_handle_new).define("resource_handle", "drw_
GPU_SHADER_CREATE_INFO(draw_modelmat_new_common)
.typedef_source("draw_shader_shared.h")
.storage_buf(DRW_OBJ_MAT_SLOT, Qualifier::READ, "ObjectMatrices", "drw_matrix_buf[]")
.define("DRAW_MODELMAT_CREATE_INFO")
.define("drw_ModelMatrixInverse", "drw_matrix_buf[resource_id].model_inverse")
.define("drw_ModelMatrix", "drw_matrix_buf[resource_id].model")
/* TODO For compatibility with old shaders. To be removed. */

View File

@@ -0,0 +1,188 @@
/* SPDX-FileCopyrightText: 2018-2023 Blender Authors
*
* SPDX-License-Identifier: GPL-2.0-or-later */
#ifndef DRAW_VIEW_CREATE_INFO
# error Missing draw_view additional create info on shader create info
#endif
/* Returns true if the current view has a perspective projection matrix. */
bool drw_view_is_perspective()
{
return drw_view.winmat[3][3] == 0.0;
}
/* Returns the view forward vector, going towards the viewer. */
vec3 drw_view_forward()
{
return drw_view.viewinv[2].xyz;
}
/* Returns the view origin. */
vec3 drw_view_position()
{
return drw_view.viewinv[3].xyz;
}
/* Returns the projection matrix far clip distance. */
float drw_view_far()
{
if (drw_view_is_perspective()) {
return -drw_view.winmat[3][2] / (drw_view.winmat[2][2] + 1.0);
}
return -(drw_view.winmat[3][2] - 1.0) / drw_view.winmat[2][2];
}
/* Returns the projection matrix near clip distance. */
float drw_view_near()
{
if (drw_view_is_perspective()) {
return -drw_view.winmat[3][2] / (drw_view.winmat[2][2] - 1.0);
}
return -(drw_view.winmat[3][2] + 1.0) / drw_view.winmat[2][2];
}
/**
* Returns the world incident vector `V` (going towards the viewer)
* from the world position `P` and the current view.
*/
vec3 drw_world_incident_vector(vec3 P)
{
return drw_view_is_perspective() ? normalize(drw_view_position() - P) : drw_view_forward();
}
/**
* Returns the view incident vector `vV` (going towards the viewer)
* from the view position `vP` and the current view.
*/
vec3 drw_view_incident_vector(vec3 vP)
{
return drw_view_is_perspective() ? normalize(vP) : vec3(0.0, 0.0, -1.0);
}
/**
* Transform position on screen UV space [0..1] to Normalized Device Coordinate space [-1..1].
*/
vec3 drw_screen_to_ndc(vec3 ss_P)
{
return ss_P * 2.0 - 1.0;
}
vec2 drw_screen_to_ndc(vec2 ss_P)
{
return ss_P * 2.0 - 1.0;
}
float drw_screen_to_ndc(float ss_P)
{
return ss_P * 2.0 - 1.0;
}
/**
* Transform position in Normalized Device Coordinate [-1..1] to screen UV space [0..1].
*/
vec3 drw_ndc_to_screen(vec3 ndc_P)
{
return ndc_P * 0.5 + 0.5;
}
vec2 drw_ndc_to_screen(vec2 ndc_P)
{
return ndc_P * 0.5 + 0.5;
}
float drw_ndc_to_screen(float ndc_P)
{
return ndc_P * 0.5 + 0.5;
}
/* -------------------------------------------------------------------- */
/** \name Transform Normal
* \{ */
vec3 drw_normal_view_to_world(vec3 vN)
{
return (mat3x3(drw_view.viewinv) * vN);
}
vec3 drw_normal_world_to_view(vec3 N)
{
return (mat3x3(drw_view.viewmat) * N);
}
/** \} */
/* -------------------------------------------------------------------- */
/** \name Transform Position
* \{ */
vec3 drw_perspective_divide(vec4 hs_P)
{
return hs_P.xyz / hs_P.w;
}
vec3 drw_point_view_to_world(vec3 vP)
{
return (drw_view.viewinv * vec4(vP, 1.0)).xyz;
}
vec4 drw_point_view_to_homogenous(vec3 vP)
{
return (drw_view.winmat * vec4(vP, 1.0));
}
vec3 drw_point_view_to_ndc(vec3 vP)
{
return drw_perspective_divide(drw_point_view_to_homogenous(vP));
}
vec3 drw_point_world_to_view(vec3 P)
{
return (drw_view.viewmat * vec4(P, 1.0)).xyz;
}
vec4 drw_point_world_to_homogenous(vec3 P)
{
return (drw_view.winmat * (drw_view.viewmat * vec4(P, 1.0)));
}
vec3 drw_point_world_to_ndc(vec3 P)
{
return drw_perspective_divide(drw_point_world_to_homogenous(P));
}
vec3 drw_point_ndc_to_view(vec3 ssP)
{
return drw_perspective_divide(drw_view.wininv * vec4(ssP, 1.0));
}
vec3 drw_point_ndc_to_world(vec3 ssP)
{
return drw_point_view_to_world(drw_point_ndc_to_view(ssP));
}
/** \} */
/* -------------------------------------------------------------------- */
/** \name Transform Screen Postions
* \{ */
vec3 drw_point_view_to_screen(vec3 vP)
{
return drw_ndc_to_screen(drw_point_view_to_ndc(vP));
}
vec3 drw_point_world_to_screen(vec3 vP)
{
return drw_ndc_to_screen(drw_point_world_to_ndc(vP));
}
vec3 drw_point_screen_to_view(vec3 ssP)
{
return drw_point_ndc_to_view(drw_screen_to_ndc(ssP));
}
vec3 drw_point_screen_to_world(vec3 ssP)
{
return drw_point_view_to_world(drw_point_screen_to_view(ssP));
}
float drw_depth_view_to_screen(float v_depth)
{
return drw_point_view_to_screen(vec3(0.0, 0.0, v_depth)).z;
}
float drw_depth_screen_to_view(float ss_depth)
{
return drw_point_screen_to_view(vec3(0.0, 0.0, ss_depth)).z;
}
/** \} */

View File

@@ -473,6 +473,7 @@ set(GLSL_SRC
shaders/common/gpu_shader_common_math.glsl
shaders/common/gpu_shader_common_math_utils.glsl
shaders/common/gpu_shader_common_mix_rgb.glsl
shaders/common/gpu_shader_debug_gradients_lib.glsl
shaders/common/gpu_shader_math_base_lib.glsl
shaders/common/gpu_shader_math_fast_lib.glsl
shaders/common/gpu_shader_math_matrix_lib.glsl

View File

@@ -228,3 +228,14 @@ void math_smoothmax(float a, float b, float c, out float result)
math_smoothmin(-a, -b, c, result);
result = -result;
}
/* TODO(fclem): Fix dependency hell one EEVEE legacy is removed. */
float math_reduce_max(vec3 a)
{
return max(a.x, max(a.y, a.z));
}
float math_average(vec3 a)
{
return (a.x + a.y + a.z) * (1.0 / 3.0);
}

View File

@@ -0,0 +1,28 @@
/* SPDX-FileCopyrightText: 2023 Blender Authors
*
* SPDX-License-Identifier: GPL-2.0-or-later */
/*
* For debugging purpose mainly.
* From https://www.shadertoy.com/view/4dsSzr
* By Morgan McGuire @morgan3d, http://graphicscodex.com
* Reuse permitted under the BSD license.
*/
vec3 neon_gradient(float t)
{
float tt = abs(0.43 - t) * 1.7;
return clamp(vec3(t * 1.3 + 0.1, tt * tt, (1.0 - t) * 1.7), 0.0, 1.0);
}
vec3 heatmap_gradient(float t)
{
float a = pow(t, 1.5) * 0.8 + 0.2;
float b = smoothstep(0.0, 0.35, t) + t * 0.5;
float c = smoothstep(0.5, 1.0, t);
float d = max(1.0 - t * 1.7, t * 7.0 - 6.0);
return clamp(a * vec3(b, c, d), vec3(0.0), vec3(1.0));
}
vec3 hue_gradient(float t)
{
vec3 p = abs(fract(t + vec3(1.0, 2.0 / 3.0, 1.0 / 3.0)) * 6.0 - 3.0);
return (clamp(p - 1.0, 0.0, 1.0));
}

View File

@@ -163,6 +163,31 @@ float safe_rcp(float a)
return (a != 0.0) ? (1.0 / a) : 0.0;
}
/**
* Safe square root function. Returns `sqrt(a)`.
* If `a` is less or equal to 0 then the result will be 0.
*/
float safe_sqrt(float a)
{
return sqrt(max(0.0, a));
}
/**
* Safe arccosine function. Returns `acos(a)`.
* If `a` is greater than 1, returns 0.
* If `a` is less than -1, returns PI.
*/
float safe_acos(float a)
{
if (a <= -1.0) {
return M_PI;
}
else if (a >= 1.0) {
return 0.0;
}
return acos(a);
}
/**
* Return true if the difference between`a` and `b` is below the `epsilon` value.
*/

View File

@@ -36,6 +36,9 @@
#define in_range_exclusive(val, min_v, max_v) (all(greaterThan(val, min_v)) && all(lessThan(val, max_v)))
#define in_texture_range(texel, tex) (all(greaterThanEqual(texel, ivec2(0))) && all(lessThan(texel, textureSize(tex, 0).xy)))
#define in_image_range(texel, tex) (all(greaterThanEqual(texel, ivec2(0))) && all(lessThan(texel, imageSize(tex).xy)))
#define weighted_sum(val0, val1, val2, val3, weights) ((val0 * weights[0] + val1 * weights[1] + val2 * weights[2] + val3 * weights[3]) * safe_rcp(weights[0] + weights[1] + weights[2] + weights[3]))
#define weighted_sum_array(val, weights) ((val[0] * weights[0] + val[1] * weights[1] + val[2] * weights[2] + val[3] * weights[3]) * safe_rcp(weights[0] + weights[1] + weights[2] + weights[3]))
/* clang-format on */
bool flag_test(uint flag, uint val)

View File

@@ -101,11 +101,11 @@ vec4 tangent_get(vec4 attr, mat3 normalmat)
/* Assumes GPU_VEC4 is color data. So converting to luminance like cycles. */
#define float_from_vec4(v) dot(v.rgb, vec3(0.2126, 0.7152, 0.0722))
#define float_from_vec3(v) avg(v.rgb)
#define float_from_vec3(v) ((v.r + v.g + v.b) * (1.0 / 3.0))
#define float_from_vec2(v) v.r
#define vec2_from_vec4(v) vec2(avg(v.rgb), v.a)
#define vec2_from_vec3(v) vec2(avg(v.rgb), 1.0)
#define vec2_from_vec4(v) vec2(((v.r + v.g + v.b) * (1.0 / 3.0)), v.a)
#define vec2_from_vec3(v) vec2(((v.r + v.g + v.b) * (1.0 / 3.0)), 1.0)
#define vec2_from_float(v) vec2(v)
#define vec3_from_vec4(v) v.rgb

View File

@@ -2,6 +2,8 @@
*
* SPDX-License-Identifier: GPL-2.0-or-later */
#pragma BLENDER_REQUIRE(gpu_shader_common_math.glsl)
void node_attribute_color(vec4 attr, out vec4 out_attr)
{
out_attr = attr_load_color_post(attr);
@@ -63,6 +65,6 @@ void node_attribute(
{
outcol = vec4(attr.xyz, 1.0);
outvec = attr.xyz;
outf = avg(attr.xyz);
outf = math_average(attr.xyz);
outalpha = attr.w;
}

View File

@@ -2,9 +2,12 @@
*
* SPDX-License-Identifier: GPL-2.0-or-later */
#pragma BLENDER_REQUIRE(gpu_shader_material_transform_utils.glsl)
void camera(out vec3 outview, out float outdepth, out float outdist)
{
vec3 vP = transform_point(ViewMatrix, g_data.P);
vec3 vP;
point_transform_world_to_view(g_data.P, vP);
vP.z = -vP.z;
outdepth = abs(vP.z);
outdist = length(vP);

View File

@@ -2,12 +2,15 @@
*
* SPDX-License-Identifier: GPL-2.0-or-later */
#pragma BLENDER_REQUIRE(gpu_shader_material_transform_utils.glsl)
void node_displacement_object(float height, float midlevel, float scale, vec3 N, out vec3 result)
{
N = transform_direction(ModelMatrixInverse, N);
result = (height - midlevel) * scale * normalize(N);
vec3 lN;
direction_transform_world_to_object(N, lN);
vec3 l_displacement = (height - midlevel) * scale * normalize(lN);
/* Apply object scale and orientation. */
result = transform_direction(ModelMatrix, result);
direction_transform_object_to_world(l_displacement, result);
}
void node_displacement_world(float height, float midlevel, float scale, vec3 N, out vec3 result)

View File

@@ -18,7 +18,7 @@ void node_eevee_specular(vec4 diffuse,
{
N = safe_normalize(N);
CN = safe_normalize(CN);
vec3 V = cameraVec(g_data.P);
vec3 V = coordinate_incoming(g_data.P);
ClosureEmission emission_data;
emission_data.weight = weight;

View File

@@ -33,7 +33,7 @@ float fresnel_dielectric(vec3 Incoming, vec3 Normal, float eta)
void node_fresnel(float ior, vec3 N, out float result)
{
N = normalize(N);
vec3 V = cameraVec(g_data.P);
vec3 V = coordinate_incoming(g_data.P);
float eta = max(ior, 0.00001);
result = fresnel_dielectric(V, N, (FrontFacing) ? eta : 1.0 / eta);

View File

@@ -11,7 +11,7 @@ void node_bsdf_glass(vec4 color,
out Closure result)
{
N = safe_normalize(N);
vec3 V = cameraVec(g_data.P);
vec3 V = coordinate_incoming(g_data.P);
float NV = dot(N, V);
vec2 bsdf = bsdf_lut(NV, roughness, ior, do_multiscatter != 0.0);

View File

@@ -13,7 +13,7 @@ void node_bsdf_glossy(vec4 color,
out Closure result)
{
N = safe_normalize(N);
vec3 V = cameraVec(g_data.P);
vec3 V = coordinate_incoming(g_data.P);
float NV = dot(N, V);
vec2 split_sum = brdf_lut(NV, roughness);

View File

@@ -10,7 +10,7 @@ void node_layer_weight(float blend, vec3 N, out float fresnel, out float facing)
/* fresnel */
float eta = max(1.0 - blend, 0.00001);
vec3 V = cameraVec(g_data.P);
vec3 V = coordinate_incoming(g_data.P);
fresnel = fresnel_dielectric(V, N, (FrontFacing) ? 1.0 / eta : eta);

View File

@@ -2,6 +2,9 @@
*
* SPDX-License-Identifier: GPL-2.0-or-later */
#pragma BLENDER_REQUIRE(gpu_shader_math_fast_lib.glsl)
#pragma BLENDER_REQUIRE(gpu_shader_common_math.glsl)
vec3 tint_from_color(vec3 color)
{
float lum = dot(color, vec3(0.3, 0.6, 0.1)); /* luminance approx. */
@@ -79,7 +82,7 @@ void node_bsdf_principled(vec4 base_color,
N = safe_normalize(N);
CN = safe_normalize(CN);
vec3 V = cameraVec(g_data.P);
vec3 V = coordinate_incoming(g_data.P);
float NV = dot(N, V);
ClosureTransparency transparency_data;
@@ -97,7 +100,7 @@ void node_bsdf_principled(vec4 base_color,
vec3 sheen_color = sheen_weight * sheen_tint.rgb * principled_sheen(NV, sheen_roughness);
diffuse_data.color = weight * sheen_color;
/* Attenuate lower layers */
weight *= (1.0 - max_v3(sheen_color));
weight *= (1.0 - math_reduce_max(sheen_color));
}
else {
diffuse_data.color = vec3(0.0);
@@ -118,7 +121,7 @@ void node_bsdf_principled(vec4 base_color,
if (!all(equal(coat_tint.rgb, vec3(1.0)))) {
float coat_neta = 1.0 / coat_ior;
float NT = fast_sqrt(1.0 - coat_neta * coat_neta * (1 - NV * NV));
float NT = sqrt_fast(1.0 - coat_neta * coat_neta * (1 - NV * NV));
/* Tint lower layers. */
coat_tint.rgb = pow(coat_tint.rgb, vec3(coat_weight / NT));
}
@@ -202,7 +205,7 @@ void node_bsdf_principled(vec4 base_color,
reflection_data.color += weight * reflectance;
/* Attenuate lower layers */
weight *= (1.0 - max_v3(reflectance));
weight *= (1.0 - math_reduce_max(reflectance));
}
/* Diffuse component */
@@ -214,10 +217,10 @@ void node_bsdf_principled(vec4 base_color,
/* Adjust the weight of picking the closure. */
reflection_data.color *= coat_tint.rgb;
reflection_data.weight = avg(reflection_data.color);
reflection_data.weight = math_average(reflection_data.color);
reflection_data.color *= safe_rcp(reflection_data.weight);
diffuse_data.weight = avg(diffuse_data.color);
diffuse_data.weight = math_average(diffuse_data.color);
diffuse_data.color *= safe_rcp(diffuse_data.weight);
/* Ref. #98190: Defines are optimizations for old compilers.

View File

@@ -2,6 +2,8 @@
*
* SPDX-License-Identifier: GPL-2.0-or-later */
#pragma BLENDER_REQUIRE(gpu_shader_material_transform_utils.glsl)
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);
@@ -24,6 +26,6 @@ void node_tangentmap(vec4 attr_tangent, out vec3 tangent)
void node_tangent(vec3 orco, out vec3 T)
{
T = transform_direction(ModelMatrix, orco);
direction_transform_object_to_world(orco, T);
T = cross(g_data.N, normalize(cross(T, g_data.N)));
}

View File

@@ -166,7 +166,8 @@ void node_tex_sky_nishita(vec3 co,
}
else {
/* evaluate longitudinal position on the map */
float x = (spherical.y + M_PI + sun_rotation) / M_2PI;
const float tau = 6.28318530717958647692;
float x = (spherical.y + M_PI + sun_rotation) / tau;
if (x > 1.0) {
x -= 1.0;
}

View File

@@ -2,6 +2,8 @@
*
* SPDX-License-Identifier: GPL-2.0-or-later */
#pragma BLENDER_REQUIRE(gpu_shader_material_transform_utils.glsl)
void node_tex_coord_position(out vec3 out_pos)
{
out_pos = g_data.P;
@@ -19,9 +21,15 @@ void node_tex_coord(mat4 obmatinv,
out vec3 reflection)
{
generated = attr_orco;
normal = normal_world_to_object(g_data.N);
normal_transform_world_to_object(g_data.N, normal);
uv = attr_uv.xyz;
object = transform_point((obmatinv[3][3] == 0.0) ? ModelMatrixInverse : obmatinv, g_data.P);
bool valid_mat = (obmatinv[3][3] != 0.0);
if (valid_mat) {
object = (obmatinv * vec4(g_data.P, 1.0)).xyz;
}
else {
point_transform_world_to_object(g_data.P, object);
}
camera = coordinate_camera(g_data.P);
window = coordinate_screen(g_data.P);
reflection = coordinate_reflect(g_data.P, g_data.N);

View File

@@ -2,74 +2,78 @@
*
* SPDX-License-Identifier: GPL-2.0-or-later */
/* Requires all common matrices declared. */
void normal_transform_object_to_world(vec3 vin, out vec3 vout)
{
vout = normal_object_to_world(vin);
/* Expansion of NormalMatrix. */
vout = vin * mat3(ModelMatrixInverse);
}
void normal_transform_world_to_object(vec3 vin, out vec3 vout)
{
vout = normal_world_to_object(vin);
/* Expansion of NormalMatrixInverse. */
vout = vin * mat3(ModelMatrix);
}
void direction_transform_object_to_world(vec3 vin, out vec3 vout)
{
vout = transform_direction(ModelMatrix, vin);
vout = mat3x3(ModelMatrix) * vin;
}
void direction_transform_object_to_view(vec3 vin, out vec3 vout)
{
vout = transform_direction(ModelMatrix, vin);
vout = transform_direction(ViewMatrix, vout);
vout = mat3x3(ModelMatrix) * vin;
vout = mat3x3(ViewMatrix) * vout;
}
void direction_transform_view_to_world(vec3 vin, out vec3 vout)
{
vout = transform_direction(ViewMatrixInverse, vin);
vout = mat3x3(ViewMatrixInverse) * vin;
}
void direction_transform_view_to_object(vec3 vin, out vec3 vout)
{
vout = transform_direction(ViewMatrixInverse, vin);
vout = transform_direction(ModelMatrixInverse, vout);
vout = mat3x3(ViewMatrixInverse) * vin;
vout = mat3x3(ModelMatrixInverse) * vout;
}
void direction_transform_world_to_view(vec3 vin, out vec3 vout)
{
vout = transform_direction(ViewMatrix, vin);
vout = mat3x3(ViewMatrix) * vin;
}
void direction_transform_world_to_object(vec3 vin, out vec3 vout)
{
vout = transform_direction(ModelMatrixInverse, vin);
vout = mat3x3(ModelMatrixInverse) * vin;
}
void point_transform_object_to_world(vec3 vin, out vec3 vout)
{
vout = point_object_to_world(vin);
vout = (ModelMatrix * vec4(vin, 1.0)).xyz;
}
void point_transform_object_to_view(vec3 vin, out vec3 vout)
{
vout = point_object_to_view(vin);
vout = (ViewMatrix * (ModelMatrix * vec4(vin, 1.0))).xyz;
}
void point_transform_view_to_world(vec3 vin, out vec3 vout)
{
vout = point_view_to_world(vin);
vout = (ViewMatrixInverse * vec4(vin, 1.0)).xyz;
}
void point_transform_view_to_object(vec3 vin, out vec3 vout)
{
vout = point_view_to_object(vin);
vout = (ModelMatrixInverse * (ViewMatrixInverse * vec4(vin, 1.0))).xyz;
}
void point_transform_world_to_view(vec3 vin, out vec3 vout)
{
vout = point_world_to_view(vin);
vout = (ViewMatrix * vec4(vin, 1.0)).xyz;
}
void point_transform_world_to_object(vec3 vin, out vec3 vout)
{
vout = point_world_to_object(vin);
vout = (ModelMatrixInverse * vec4(vin, 1.0)).xyz;
}

View File

@@ -2,22 +2,27 @@
*
* SPDX-License-Identifier: GPL-2.0-or-later */
#pragma BLENDER_REQUIRE(gpu_shader_material_transform_utils.glsl)
void node_vector_displacement_tangent(
vec4 vector, float midlevel, float scale, vec4 T, out vec3 result)
{
vec3 oN = normalize(normal_world_to_object(g_data.N));
vec3 oT = normalize(normal_world_to_object(T.xyz));
vec3 oB = T.w * safe_normalize(cross(oN, oT));
vec3 oN, oT, oB;
normal_transform_world_to_object(g_data.N, oN);
normal_transform_world_to_object(T.xyz, oT);
oN = normalize(oN);
oT = normalize(oT);
oB = T.w * safe_normalize(cross(oN, oT));
result = (vector.xyz - midlevel) * scale;
result = result.x * oT + result.y * oN + result.z * oB;
result = transform_point(ModelMatrix, result);
vec3 disp = (vector.xyz - midlevel) * scale;
disp = disp.x * oT + disp.y * oN + disp.z * oB;
point_transform_object_to_world(disp, result);
}
void node_vector_displacement_object(vec4 vector, float midlevel, float scale, out vec3 result)
{
result = (vector.xyz - midlevel) * scale;
result = transform_point(ModelMatrix, result);
vec3 disp = (vector.xyz - midlevel) * scale;
point_transform_object_to_world(disp, result);
}
void node_vector_displacement_world(vec4 vector, float midlevel, float scale, out vec3 result)