diff options
author | Clément Foucault <foucault.clem@gmail.com> | 2021-02-21 02:46:41 +0300 |
---|---|---|
committer | Clément Foucault <foucault.clem@gmail.com> | 2021-02-21 03:33:56 +0300 |
commit | 1d51cb6be24e3097de2a20f490ef0dd535240f5b (patch) | |
tree | edf300e8c8100db887ae582e7a9c59b63ca96899 /source | |
parent | dee94afd039de7b7d3002ff2f8f1f0bf4c515bb3 (diff) |
Cleanup: EEVEE: change cameraVec macro to cameraVec(P)
This makes is clearer and avoid having to setup worldPosition if
shader is not a material shader.
Diffstat (limited to 'source')
17 files changed, 44 insertions, 44 deletions
diff --git a/source/blender/draw/engines/eevee/shaders/closure_eval_lib.glsl b/source/blender/draw/engines/eevee/shaders/closure_eval_lib.glsl index b372a8c2467..8cb702796da 100644 --- a/source/blender/draw/engines/eevee/shaders/closure_eval_lib.glsl +++ b/source/blender/draw/engines/eevee/shaders/closure_eval_lib.glsl @@ -200,7 +200,7 @@ ClosureEvalCommon closure_Common_eval_init(ClosureInputCommon cl_in) { ClosureEvalCommon cl_eval; cl_eval.rand = texelfetch_noise_tex(gl_FragCoord.xy); - cl_eval.V = cameraVec; + cl_eval.V = cameraVec(worldPosition); cl_eval.P = worldPosition; cl_eval.N = safe_normalize(gl_FrontFacing ? worldNormal : -worldNormal); cl_eval.vN = safe_normalize(gl_FrontFacing ? viewNormal : -viewNormal); diff --git a/source/blender/draw/engines/eevee/shaders/closure_type_lib.glsl b/source/blender/draw/engines/eevee/shaders/closure_type_lib.glsl index 9ca25ef240f..38ae3972aa7 100644 --- a/source/blender/draw/engines/eevee/shaders/closure_type_lib.glsl +++ b/source/blender/draw/engines/eevee/shaders/closure_type_lib.glsl @@ -159,7 +159,7 @@ void closure_load_ssr_data( { /* Still encode to avoid artifacts in the SSR pass. */ vec3 vN = normalize(mat3(ViewMatrix) * N); - cl.ssr_normal = normal_encode(vN, viewCameraVec); + cl.ssr_normal = normal_encode(vN, viewCameraVec(viewPosition)); if (ssrToggle && int(ssr_id) == outputSsrId) { cl.ssr_data = vec4(ssr_radiance, roughness); diff --git a/source/blender/draw/engines/eevee/shaders/effect_gtao_frag.glsl b/source/blender/draw/engines/eevee/shaders/effect_gtao_frag.glsl index 369b0735cd2..19ae0acc443 100644 --- a/source/blender/draw/engines/eevee/shaders/effect_gtao_frag.glsl +++ b/source/blender/draw/engines/eevee/shaders/effect_gtao_frag.glsl @@ -91,10 +91,8 @@ void main() } else { vec3 P = transform_point(ViewMatrixInverse, vP); - vec3 worldPosition = P; /* For cameraVec macro. TODO(fclem) make cameraVec(P). */ - vec3 viewPosition = vP; /* For viewCameraVec macro. TODO(fclem) make viewCameraVec(vP). */ - vec3 V = cameraVec; - vec3 vV = viewCameraVec; + vec3 V = cameraVec(P); + vec3 vV = viewCameraVec(vP); vec3 vN = normal_decode(texture(normalBuffer, uvcoordsvar.xy).rg, vV); vec3 N = transform_direction(ViewMatrixInverse, vN); vec3 Ng = transform_direction(ViewMatrixInverse, vNg); diff --git a/source/blender/draw/engines/eevee/shaders/effect_ssr_frag.glsl b/source/blender/draw/engines/eevee/shaders/effect_ssr_frag.glsl index b7caaf127bf..71aead9155d 100644 --- a/source/blender/draw/engines/eevee/shaders/effect_ssr_frag.glsl +++ b/source/blender/draw/engines/eevee/shaders/effect_ssr_frag.glsl @@ -142,9 +142,12 @@ void main() vec2 uvs = vec2(fullres_texel) / vec2(textureSize(depthBuffer, 0)); /* Using view space */ - vec3 viewPosition = get_view_space_from_depth(uvs, depth); - vec3 V = viewCameraVec; - vec3 N = normal_decode(texelFetch(normalBuffer, fullres_texel, 0).rg, V); + vec3 vP = get_view_space_from_depth(uvs, depth); + vec3 P = transform_point(ViewMatrixInverse, vP); + vec3 vV = viewCameraVec(vP); + vec3 V = cameraVec(P); + vec3 vN = normal_decode(texelFetch(normalBuffer, fullres_texel, 0).rg, vV); + vec3 N = transform_direction(ViewMatrixInverse, vN); /* Retrieve pixel data */ vec4 speccol_roughness = texelFetch(specroughBuffer, fullres_texel, 0).rgba; @@ -172,27 +175,24 @@ void main() /* Importance sampling bias */ rand.x = mix(rand.x, 0.0, ssrBrdfBias); - vec3 W = transform_point(ViewMatrixInverse, viewPosition); - vec3 wN = transform_direction(ViewMatrixInverse, N); - - vec3 T, B; - make_orthonormal_basis(N, T, B); /* Generate tangent space */ + vec3 vT, vB; + make_orthonormal_basis(vN, vT, vB); /* Generate tangent space */ /* Planar Reflections */ for (int i = 0; i < MAX_PLANAR && i < prbNumPlanar; i++) { PlanarData pd = planars_data[i]; - float fade = probe_attenuation_planar(pd, W); - fade *= probe_attenuation_planar_normal_roughness(pd, wN, 0.0); + float fade = probe_attenuation_planar(pd, P); + fade *= probe_attenuation_planar_normal_roughness(pd, N, 0.0); if (fade > 0.5) { /* Find view vector / reflection plane intersection. */ /* TODO optimize, use view space for all. */ - vec3 tracePosition = line_plane_intersect(W, cameraVec, pd.pl_plane_eq); + vec3 tracePosition = line_plane_intersect(P, V, pd.pl_plane_eq); tracePosition = transform_point(ViewMatrix, tracePosition); vec3 planeNormal = transform_direction(ViewMatrix, pd.pl_normal); - do_planar_ssr(i, V, N, T, B, planeNormal, tracePosition, a2, rand); + do_planar_ssr(i, vV, vN, vT, vB, planeNormal, tracePosition, a2, rand); return; } } @@ -200,9 +200,9 @@ void main() /* Constant bias (due to depth buffer precision). Helps with self intersection. */ /* Magic numbers for 24bits of precision. * From http://terathon.com/gdc07_lengyel.pdf (slide 26) */ - viewPosition.z = get_view_z_from_depth(depth - mix(2.4e-7, 4.8e-7, depth)); + vP.z = get_view_z_from_depth(depth - mix(2.4e-7, 4.8e-7, depth)); - do_ssr(V, N, T, B, viewPosition, a2, rand); + do_ssr(vV, vN, vT, vB, vP, a2, rand); } #else /* STEP_RESOLVE */ @@ -580,7 +580,7 @@ void main() worldPosition = transform_point(ViewMatrixInverse, viewPosition); vec2 normal_encoded = texelFetch(normalBuffer, texel, 0).rg; - viewNormal = normal_decode(normal_encoded, viewCameraVec); + viewNormal = normal_decode(normal_encoded, viewCameraVec(viewPosition)); worldNormal = transform_direction(ViewMatrixInverse, viewNormal); CLOSURE_VARS_DECLARE_1(Glossy); diff --git a/source/blender/draw/engines/eevee/shaders/renderpass_postprocess_frag.glsl b/source/blender/draw/engines/eevee/shaders/renderpass_postprocess_frag.glsl index 0bbbe58c44a..363b5cb978a 100644 --- a/source/blender/draw/engines/eevee/shaders/renderpass_postprocess_frag.glsl +++ b/source/blender/draw/engines/eevee/shaders/renderpass_postprocess_frag.glsl @@ -82,7 +82,7 @@ void main() * with NaN's */ if (depth != 1.0 && any(notEqual(encoded_normal, vec2(0.0)))) { vec3 decoded_normal = normal_decode(texelFetch(inputBuffer, texel, 0).rg, vec3(0.0)); - vec3 world_normal = mat3(ViewMatrixInverse) * decoded_normal; + vec3 world_normal = transform_direction(ViewMatrixInverse, decoded_normal); color.rgb = world_normal; } else { diff --git a/source/blender/draw/engines/eevee/shaders/ssr_lib.glsl b/source/blender/draw/engines/eevee/shaders/ssr_lib.glsl index 29495e98355..15c28efe622 100644 --- a/source/blender/draw/engines/eevee/shaders/ssr_lib.glsl +++ b/source/blender/draw/engines/eevee/shaders/ssr_lib.glsl @@ -9,8 +9,7 @@ #define BTDF_BIAS 0.85 -vec4 screen_space_refraction( - vec3 viewPosition, vec3 N, vec3 V, float ior, float roughnessSquared, vec4 rand) +vec4 screen_space_refraction(vec3 vP, vec3 N, vec3 V, float ior, float roughnessSquared, vec4 rand) { float a2 = max(5e-6, roughnessSquared * roughnessSquared); @@ -29,7 +28,7 @@ vec4 screen_space_refraction( pdf = pdf_ggx_reflect(NH, a2); } - vec3 vV = viewCameraVec; + vec3 vV = viewCameraVec(vP); float eta = 1.0 / ior; if (dot(H, V) < 0.0) { H = -H; @@ -41,11 +40,11 @@ vec4 screen_space_refraction( R = transform_direction(ViewMatrix, R); vec3 hit_pos = raycast( - -1, viewPosition, R * 1e16, ssrThickness, rand.y, ssrQuality, roughnessSquared, false); + -1, vP, R * 1e16, ssrThickness, rand.y, ssrQuality, roughnessSquared, false); if ((hit_pos.z > 0.0) && (F_eta(ior, dot(H, V)) < 1.0)) { hit_pos = get_view_space_from_depth(hit_pos.xy, hit_pos.z); - float hit_dist = distance(hit_pos, viewPosition); + float hit_dist = distance(hit_pos, vP); float cone_cos = cone_cosine(roughnessSquared); float cone_tan = sqrt(1 - cone_cos * cone_cos) / cone_cos; diff --git a/source/blender/draw/engines/eevee/shaders/volumetric_scatter_frag.glsl b/source/blender/draw/engines/eevee/shaders/volumetric_scatter_frag.glsl index 806f1b5b205..13287eab82b 100644 --- a/source/blender/draw/engines/eevee/shaders/volumetric_scatter_frag.glsl +++ b/source/blender/draw/engines/eevee/shaders/volumetric_scatter_frag.glsl @@ -30,7 +30,7 @@ void main() vec3 s_scattering = texelFetch(volumeScattering, volume_cell, 0).rgb; vec3 volume_ndc = volume_to_ndc((vec3(volume_cell) + volJitter.xyz) * volInvTexSize.xyz); vec3 worldPosition = get_world_space_from_depth(volume_ndc.xy, volume_ndc.z); - vec3 wdir = cameraVec; + vec3 wdir = cameraVec(worldPosition); vec2 phase = texelFetch(volumePhase, volume_cell, 0).rg; float s_anisotropy = phase.x / max(1.0, phase.y); diff --git a/source/blender/draw/intern/shaders/common_view_lib.glsl b/source/blender/draw/intern/shaders/common_view_lib.glsl index 0f2782fc2b2..4012de4f95b 100644 --- a/source/blender/draw/intern/shaders/common_view_lib.glsl +++ b/source/blender/draw/intern/shaders/common_view_lib.glsl @@ -27,10 +27,8 @@ layout(std140) uniform viewBlock #define cameraForward ViewMatrixInverse[2].xyz #define cameraPos ViewMatrixInverse[3].xyz -#define cameraVec \ - ((ProjectionMatrix[3][3] == 0.0) ? normalize(cameraPos - worldPosition) : cameraForward) -#define viewCameraVec \ - ((ProjectionMatrix[3][3] == 0.0) ? normalize(-viewPosition) : vec3(0.0, 0.0, 1.0)) +#define cameraVec(P) ((ProjectionMatrix[3][3] == 0.0) ? normalize(cameraPos - P) : cameraForward) +#define viewCameraVec(vP) ((ProjectionMatrix[3][3] == 0.0) ? normalize(-vP) : vec3(0.0, 0.0, 1.0)) #ifdef world_clip_planes_calc_clip_distance # undef world_clip_planes_calc_clip_distance diff --git a/source/blender/gpu/shaders/material/gpu_shader_material_ambient_occlusion.glsl b/source/blender/gpu/shaders/material/gpu_shader_material_ambient_occlusion.glsl index 4721b9f0132..0231aeca04b 100644 --- a/source/blender/gpu/shaders/material/gpu_shader_material_ambient_occlusion.glsl +++ b/source/blender/gpu/shaders/material/gpu_shader_material_ambient_occlusion.glsl @@ -10,7 +10,7 @@ void node_ambient_occlusion(vec4 color, vec4 rand = texelfetch_noise_tex(gl_FragCoord.xy); OcclusionData data = occlusion_search(viewPosition, maxzBuffer, dist, inverted, 8.0); - vec3 V = cameraVec; + vec3 V = cameraVec(worldPosition); vec3 N = normalize(normal); vec3 Ng = safe_normalize(cross(dFdx(worldPosition), dFdy(worldPosition))); diff --git a/source/blender/gpu/shaders/material/gpu_shader_material_eevee_specular.glsl b/source/blender/gpu/shaders/material/gpu_shader_material_eevee_specular.glsl index 429c4ed41ac..d5623c890e4 100644 --- a/source/blender/gpu/shaders/material/gpu_shader_material_eevee_specular.glsl +++ b/source/blender/gpu/shaders/material/gpu_shader_material_eevee_specular.glsl @@ -32,6 +32,8 @@ void node_eevee_specular(vec4 diffuse, result = CLOSURE_DEFAULT; + vec3 V = cameraVec(worldPosition); + { /* Diffuse. */ out_Diffuse_0.radiance = render_pass_diffuse_mask(vec3(1), out_Diffuse_0.radiance); @@ -40,7 +42,7 @@ void node_eevee_specular(vec4 diffuse, } { /* Glossy. */ - float NV = dot(in_Glossy_1.N, cameraVec); + float NV = dot(in_Glossy_1.N, V); vec2 split_sum = brdf_lut(NV, in_Glossy_1.roughness); vec3 brdf = F_brdf_single_scatter(specular.rgb, vec3(1.0), split_sum); @@ -52,7 +54,7 @@ void node_eevee_specular(vec4 diffuse, } { /* Clearcoat. */ - float NV = dot(in_Glossy_2.N, cameraVec); + float NV = dot(in_Glossy_2.N, V); vec2 split_sum = brdf_lut(NV, in_Glossy_2.roughness); vec3 brdf = F_brdf_single_scatter(vec3(0.04), vec3(1.0), split_sum); diff --git a/source/blender/gpu/shaders/material/gpu_shader_material_emission.glsl b/source/blender/gpu/shaders/material/gpu_shader_material_emission.glsl index 502bc7f92d6..f2de7c2da39 100644 --- a/source/blender/gpu/shaders/material/gpu_shader_material_emission.glsl +++ b/source/blender/gpu/shaders/material/gpu_shader_material_emission.glsl @@ -3,7 +3,7 @@ void node_emission(vec4 color, float strength, vec3 vN, out Closure result) result = CLOSURE_DEFAULT; #ifndef VOLUMETRICS result.radiance = render_pass_emission_mask(color.rgb) * strength; - result.ssr_normal = normal_encode(vN, viewCameraVec); + result.ssr_normal = normal_encode(vN, viewCameraVec(viewPosition)); #else result.emission = color.rgb * strength; #endif diff --git a/source/blender/gpu/shaders/material/gpu_shader_material_glass.glsl b/source/blender/gpu/shaders/material/gpu_shader_material_glass.glsl index 6788b34c938..aa0a8873596 100644 --- a/source/blender/gpu/shaders/material/gpu_shader_material_glass.glsl +++ b/source/blender/gpu/shaders/material/gpu_shader_material_glass.glsl @@ -23,7 +23,7 @@ void node_bsdf_glass(vec4 color, result = CLOSURE_DEFAULT; - float NV = dot(in_Refraction_1.N, cameraVec); + float NV = dot(in_Refraction_1.N, cameraVec(worldPosition)); float fresnel = (do_multiscatter != 0.0) ? btdf_lut(NV, in_Refraction_1.roughness, in_Refraction_1.ior).y : diff --git a/source/blender/gpu/shaders/material/gpu_shader_material_glossy.glsl b/source/blender/gpu/shaders/material/gpu_shader_material_glossy.glsl index ca7c3749597..fa83bfb6c7a 100644 --- a/source/blender/gpu/shaders/material/gpu_shader_material_glossy.glsl +++ b/source/blender/gpu/shaders/material/gpu_shader_material_glossy.glsl @@ -16,7 +16,7 @@ void node_bsdf_glossy( result = CLOSURE_DEFAULT; - vec2 split_sum = brdf_lut(dot(in_Glossy_0.N, cameraVec), in_Glossy_0.roughness); + vec2 split_sum = brdf_lut(dot(in_Glossy_0.N, cameraVec(worldPosition)), in_Glossy_0.roughness); vec3 brdf = (use_multiscatter != 0.0) ? F_brdf_multi_scatter(vec3(1.0), vec3(1.0), split_sum) : F_brdf_single_scatter(vec3(1.0), vec3(1.0), split_sum); out_Glossy_0.radiance = closure_mask_ssr_radiance(out_Glossy_0.radiance, ssr_id); diff --git a/source/blender/gpu/shaders/material/gpu_shader_material_principled.glsl b/source/blender/gpu/shaders/material/gpu_shader_material_principled.glsl index 139dcb33222..40fe83a3616 100644 --- a/source/blender/gpu/shaders/material/gpu_shader_material_principled.glsl +++ b/source/blender/gpu/shaders/material/gpu_shader_material_principled.glsl @@ -86,8 +86,10 @@ void node_bsdf_principled(vec4 base_color, out_Refraction_3.radiance = vec3(0); } + vec3 V = cameraVec(worldPosition); + /* Glossy_1 will always be evaluated. */ - float NV = dot(in_Glossy_1.N, cameraVec); + float NV = dot(in_Glossy_1.N, V); vec3 base_color_tint = tint_from_color(base_color.rgb); @@ -172,7 +174,7 @@ void node_bsdf_principled(vec4 base_color, } if (clearcoat > 1e-5) { - float NV = dot(in_Glossy_2.N, cameraVec); + float NV = dot(in_Glossy_2.N, V); vec2 split_sum = brdf_lut(NV, in_Glossy_2.roughness); vec3 brdf = F_brdf_single_scatter(vec3(0.04), vec3(1.0), split_sum); diff --git a/source/blender/gpu/shaders/material/gpu_shader_material_refraction.glsl b/source/blender/gpu/shaders/material/gpu_shader_material_refraction.glsl index db820efa42e..7cbc7218f5c 100644 --- a/source/blender/gpu/shaders/material/gpu_shader_material_refraction.glsl +++ b/source/blender/gpu/shaders/material/gpu_shader_material_refraction.glsl @@ -22,7 +22,8 @@ void node_bsdf_refraction(vec4 color, float roughness, float ior, vec3 N, out Cl result.radiance = out_Refraction_0.radiance; /* TODO(fclem) Try to not use this. */ - result.ssr_normal = normal_encode(mat3(ViewMatrix) * in_Refraction_0.N, viewCameraVec); + result.ssr_normal = normal_encode(mat3(ViewMatrix) * in_Refraction_0.N, + viewCameraVec(viewPosition)); } #else diff --git a/source/blender/gpu/shaders/material/gpu_shader_material_shader_to_rgba.glsl b/source/blender/gpu/shaders/material/gpu_shader_material_shader_to_rgba.glsl index f495157f6e1..a5fdc7a2337 100644 --- a/source/blender/gpu/shaders/material/gpu_shader_material_shader_to_rgba.glsl +++ b/source/blender/gpu/shaders/material/gpu_shader_material_shader_to_rgba.glsl @@ -3,8 +3,8 @@ void node_shader_to_rgba(Closure cl, out vec4 outcol, out float outalpha) { vec4 spec_accum = vec4(0.0); if (ssrToggle && FLAG_TEST(cl.flag, CLOSURE_SSR_FLAG)) { - vec3 V = cameraVec; - vec3 vN = normal_decode(cl.ssr_normal, viewCameraVec); + vec3 V = cameraVec(worldPosition); + vec3 vN = normal_decode(cl.ssr_normal, viewCameraVec(viewPosition)); vec3 N = transform_direction(ViewMatrixInverse, vN); float roughness = cl.ssr_data.a; float roughnessSquared = max(1e-3, roughness * roughness); diff --git a/source/blender/gpu/shaders/material/gpu_shader_material_texture_coordinates.glsl b/source/blender/gpu/shaders/material/gpu_shader_material_texture_coordinates.glsl index 24276156d55..08d566224bf 100644 --- a/source/blender/gpu/shaders/material/gpu_shader_material_texture_coordinates.glsl +++ b/source/blender/gpu/shaders/material/gpu_shader_material_texture_coordinates.glsl @@ -50,7 +50,7 @@ void node_tex_coord(vec3 I, camera = vec3(I.xy, -I.z); vec4 projvec = ProjectionMatrix * vec4(I, 1.0); window = vec3(mtex_2d_mapping(projvec.xyz / projvec.w).xy * camerafac.xy + camerafac.zw, 0.0); - reflection = -reflect(cameraVec, normalize(wN)); + reflection = -reflect(cameraVec(worldPosition), normalize(wN)); } void node_tex_coord_background(vec3 I, |