diff options
author | Clément Foucault <foucault.clem@gmail.com> | 2018-01-21 19:25:10 +0300 |
---|---|---|
committer | Clément Foucault <foucault.clem@gmail.com> | 2018-01-22 01:16:59 +0300 |
commit | a507c251b23f2fd6ef7758e443939ce0c5c09e61 (patch) | |
tree | 9fe4e1ac28c23cb52e334cd0ec7b92c83f4ffd5a /source/blender/draw/engines/eevee/shaders | |
parent | 790025c01ed76c06e69e6054f1a718ca57771e28 (diff) |
Eevee: Put all constant uniforms in a global UBO.
This is an optimization / cleanup commit.
The use of a global ubo remove lots of uniform lookups and only transfert data when needed.
Lots of renaming for more consistent codestyle.
Diffstat (limited to 'source/blender/draw/engines/eevee/shaders')
13 files changed, 106 insertions, 121 deletions
diff --git a/source/blender/draw/engines/eevee/shaders/ambient_occlusion_lib.glsl b/source/blender/draw/engines/eevee/shaders/ambient_occlusion_lib.glsl index 302b7596cc3..55f66f5500a 100644 --- a/source/blender/draw/engines/eevee/shaders/ambient_occlusion_lib.glsl +++ b/source/blender/draw/engines/eevee/shaders/ambient_occlusion_lib.glsl @@ -33,19 +33,8 @@ uniform sampler2DArray utilTex; #define texelfetch_noise_tex(coord) texelFetch(utilTex, ivec3(ivec2(coord) % LUT_SIZE, 2.0), 0) #endif /* UTIL_TEX */ -uniform vec4 aoParameters[2]; uniform sampler2D horizonBuffer; -#define aoDistance aoParameters[0].x -#define aoSamples aoParameters[0].y /* UNUSED */ -#define aoFactor aoParameters[0].z -#define aoInvSamples aoParameters[0].w /* UNUSED */ - -#define aoOffset aoParameters[1].x /* UNUSED */ -#define aoBounceFac aoParameters[1].y -#define aoQuality aoParameters[1].z -#define aoSettings aoParameters[1].w - /* aoSettings flags */ #define USE_AO 1 #define USE_BENT_NORMAL 2 diff --git a/source/blender/draw/engines/eevee/shaders/bsdf_common_lib.glsl b/source/blender/draw/engines/eevee/shaders/bsdf_common_lib.glsl index bdc59ec345a..68299fe7546 100644 --- a/source/blender/draw/engines/eevee/shaders/bsdf_common_lib.glsl +++ b/source/blender/draw/engines/eevee/shaders/bsdf_common_lib.glsl @@ -11,7 +11,6 @@ uniform mat4 ProjectionMatrix; uniform mat4 ViewProjectionMatrix; uniform mat4 ViewMatrixInverse; -uniform vec4 viewvecs[2]; #ifndef SHADOW_SHADER uniform mat4 ViewMatrix; #else @@ -31,8 +30,6 @@ flat in int shFace; /* Shadow layer we are rendering to. */ #define ViewMatrix FaceViewMatrix[shFace] #endif -uniform vec2 mipRatio[10]; - /* Buffers */ uniform sampler2D colorBuffer; uniform sampler2D depthBuffer; @@ -304,7 +301,7 @@ float get_view_z_from_depth(float depth) return -ProjectionMatrix[3][2] / (d + ProjectionMatrix[2][2]); } else { - return viewvecs[0].z + depth * viewvecs[1].z; + return viewVecs[0].z + depth * viewVecs[1].z; } } @@ -315,7 +312,7 @@ float get_depth_from_view_z(float z) return d * 0.5 + 0.5; } else { - return (z - viewvecs[0].z) / viewvecs[1].z; + return (z - viewVecs[0].z) / viewVecs[1].z; } } @@ -328,10 +325,10 @@ vec2 get_uvs_from_view(vec3 view) vec3 get_view_space_from_depth(vec2 uvcoords, float depth) { if (ProjectionMatrix[3][3] == 0.0) { - return (viewvecs[0].xyz + vec3(uvcoords, 0.0) * viewvecs[1].xyz) * get_view_z_from_depth(depth); + return (viewVecs[0].xyz + vec3(uvcoords, 0.0) * viewVecs[1].xyz) * get_view_z_from_depth(depth); } else { - return viewvecs[0].xyz + vec3(uvcoords, depth) * viewvecs[1].xyz; + return viewVecs[0].xyz + vec3(uvcoords, depth) * viewVecs[1].xyz; } } @@ -746,8 +743,6 @@ Closure closure_add(Closure cl1, Closure cl2) return cl; } -uniform bool sssToggle; - #if defined(MESH_SHADER) && !defined(USE_ALPHA_HASH) && !defined(USE_ALPHA_CLIP) && !defined(SHADOW_SHADER) && !defined(USE_MULTIPLY) layout(location = 0) out vec4 fragColor; #ifdef USE_SSS diff --git a/source/blender/draw/engines/eevee/shaders/common_uniforms_lib.glsl b/source/blender/draw/engines/eevee/shaders/common_uniforms_lib.glsl new file mode 100644 index 00000000000..37106fc32bd --- /dev/null +++ b/source/blender/draw/engines/eevee/shaders/common_uniforms_lib.glsl @@ -0,0 +1,55 @@ + +layout(std140) uniform common_block { + mat4 pastViewProjectionMatrix; + vec4 viewVecs[2]; + vec2 mipRatio[10]; /* To correct mip level texel mis-alignement */ + /* Ambient Occlusion */ + vec4 aoParameters[2]; + /* Volumetric */ + ivec4 volTexSize; + vec4 volDepthParameters; /* Parameters to the volume Z equation */ + vec4 volInvTexSize; + vec4 volJitter; + vec4 volCoordScale; /* To convert volume uvs to screen uvs */ + float volHistoryAlpha; + float volLightClamp; + float volShadowSteps; + bool volUseLights; + /* Screen Space Reflections */ + vec4 ssrParameters; + float ssrBorderFac; + float ssrMaxRoughness; + float ssrFireflyFac; + float ssrBrdfBias; + bool ssrToggle; + /* SubSurface Scattering */ + float sssJitterThreshold; + bool sssToggle; + /* Specular */ + bool specToggle; + /* Lamps */ + int laNumLight; + /* Probes */ + int prbNumPlanar; + int prbNumRenderCube; + int prbNumRenderGrid; + int prbIrradianceVisSize; + float prbLodCubeMax; + float prbLodPlanarMax; +}; + +/* aoParameters */ +#define aoDistance aoParameters[0].x +#define aoSamples aoParameters[0].y /* UNUSED */ +#define aoFactor aoParameters[0].z +#define aoInvSamples aoParameters[0].w /* UNUSED */ + +#define aoOffset aoParameters[1].x /* UNUSED */ +#define aoBounceFac aoParameters[1].y +#define aoQuality aoParameters[1].z +#define aoSettings aoParameters[1].w + +/* ssrParameters */ +#define ssrQuality ssrParameters.x +#define ssrThickness ssrParameters.y +#define ssrPixelSize ssrParameters.zw
\ No newline at end of file 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 9043a4ca768..354526b2db9 100644 --- a/source/blender/draw/engines/eevee/shaders/effect_ssr_frag.glsl +++ b/source/blender/draw/engines/eevee/shaders/effect_ssr_frag.glsl @@ -10,9 +10,6 @@ uniform sampler2DArray utilTex; #define MAX_MIP 9.0 -uniform float brdfBias; -uniform float fireflyFactor; -uniform float maxRoughness; uniform ivec2 halfresOffset; ivec2 encode_hit_data(vec2 hit_pos, bool has_hit, bool is_planar) @@ -35,9 +32,6 @@ vec2 decode_hit_data(vec2 hit_data, out bool has_hit, out bool is_planar) uniform sampler2D normalBuffer; uniform sampler2D specroughBuffer; -uniform int planar_count; -uniform float noiseOffset; - layout(location = 0) out ivec2 hitData; layout(location = 1) out float pdfData; @@ -125,7 +119,7 @@ void main() float a2 = roughnessSquared * roughnessSquared; /* Early out */ - if (roughness > maxRoughness + 0.2) + if (roughness > ssrMaxRoughness + 0.2) return; vec4 rand = texelFetch(utilTex, ivec3(halfres_texel % LUT_SIZE, 2), 0); @@ -135,7 +129,7 @@ void main() rand.xzw *= 0.0; } /* Importance sampling bias */ - rand.x = mix(rand.x, 0.0, brdfBias); + rand.x = mix(rand.x, 0.0, ssrBrdfBias); vec3 worldPosition = transform_point(ViewMatrixInverse, viewPosition); vec3 wN = transform_direction(ViewMatrixInverse, N); @@ -144,7 +138,7 @@ void main() make_orthonormal_basis(N, T, B); /* Generate tangent space */ /* Planar Reflections */ - for (int i = 0; i < MAX_PLANAR && i < planar_count; ++i) { + for (int i = 0; i < MAX_PLANAR && i < prbNumPlanar; ++i) { PlanarData pd = planars_data[i]; float fade = probe_attenuation_planar(pd, worldPosition, wN, 0.0); @@ -173,9 +167,6 @@ uniform sampler2D specroughBuffer; uniform isampler2D hitBuffer; uniform sampler2D pdfBuffer; -uniform int probe_count; -uniform int planar_count; - uniform int neighborOffset; const ivec2 neighbors[32] = ivec2[32]( @@ -190,8 +181,6 @@ const ivec2 neighbors[32] = ivec2[32]( ivec2( 0, 0), ivec2( 2, 2), ivec2( 2, -2), ivec2(-1, 0) ); -uniform mat4 PastViewProjectionMatrix; - out vec4 fragColor; void fallback_cubemap( @@ -206,7 +195,7 @@ void fallback_cubemap( final_ao = specular_occlusion(dot(N, V), final_ao, roughness); /* Starts at 1 because 0 is world probe */ - for (int i = 1; i < MAX_PROBE && i < probe_count && spec_accum.a < 0.999; ++i) { + for (int i = 1; i < MAX_PROBE && i < prbNumRenderCube && spec_accum.a < 0.999; ++i) { CubeData cd = probes_data[i]; float fade = probe_attenuation_cube(cd, W); @@ -257,7 +246,7 @@ float brightness(vec3 c) vec2 get_reprojected_reflection(vec3 hit, vec3 pos, vec3 N) { /* TODO real reprojection with motion vectors, etc... */ - return project_point(PastViewProjectionMatrix, hit).xy * 0.5 + 0.5; + return project_point(pastViewProjectionMatrix, hit).xy * 0.5 + 0.5; } float get_sample_depth(vec2 hit_co, bool is_planar, float planar_index) @@ -296,7 +285,7 @@ vec3 get_hit_vector( vec3 get_scene_color(vec2 ref_uvs, float mip, float planar_index, bool is_planar) { if (is_planar) { - return textureLod(probePlanars, vec3(ref_uvs, planar_index), min(mip, lodPlanarMax)).rgb; + return textureLod(probePlanars, vec3(ref_uvs, planar_index), min(mip, prbLodPlanarMax)).rgb; } else { return textureLod(prevColorBuffer, ref_uvs, mip).rgb; @@ -361,7 +350,7 @@ vec4 get_ssr_samples( /* Compute cone footprint in screen space. */ vec4 cone_footprint = hit_dist * cone_tan; - cone_footprint = brdfBias * 0.5 * cone_footprint * max(ProjectionMatrix[0][0], ProjectionMatrix[1][1]) / homcoord; + cone_footprint = ssrBrdfBias * 0.5 * cone_footprint * max(ProjectionMatrix[0][0], ProjectionMatrix[1][1]) / homcoord; /* Estimate a cone footprint to sample a corresponding mipmap level. */ vec4 mip = log2(cone_footprint * max_v2(vec2(textureSize(depthBuffer, 0)))); @@ -395,7 +384,7 @@ vec4 get_ssr_samples( luma.z = brightness(sample[2]); luma.w = brightness(sample[3]); luma = max(vec4(1e-8), luma); - luma = 1.0 - max(vec4(0.0), luma - fireflyFactor) / luma; + luma = 1.0 - max(vec4(0.0), luma - ssrFireflyFac) / luma; sample[0] *= luma.x; sample[1] *= luma.y; @@ -474,7 +463,7 @@ void main() /* Find Planar Reflections affecting this pixel */ PlanarData pd; float planar_index; - for (int i = 0; i < MAX_PLANAR && i < planar_count; ++i) { + for (int i = 0; i < MAX_PLANAR && i < prbNumPlanar; ++i) { pd = planars_data[i]; float fade = probe_attenuation_planar(pd, worldPosition, N, 0.0); @@ -495,12 +484,12 @@ void main() float cone_tan = sqrt(1 - cone_cos * cone_cos) / cone_cos; cone_tan *= mix(saturate(dot(N, -V) * 2.0), 1.0, roughness); /* Elongation fit */ - vec2 source_uvs = project_point(PastViewProjectionMatrix, worldPosition).xy * 0.5 + 0.5; + vec2 source_uvs = project_point(pastViewProjectionMatrix, worldPosition).xy * 0.5 + 0.5; vec4 ssr_accum = vec4(0.0); float weight_acc = 0.0; - if (roughness < maxRoughness + 0.2) { + if (roughness < ssrMaxRoughness + 0.2) { ssr_accum += get_ssr_samples(hit_pdf, hit_data, pd, planar_index, worldPosition, N, V, roughnessSquared, cone_tan, source_uvs, weight_acc); } @@ -509,7 +498,7 @@ void main() if (weight_acc > 0.0) { ssr_accum /= weight_acc; /* fade between 0.5 and 1.0 roughness */ - ssr_accum.a *= smoothstep(maxRoughness + 0.2, maxRoughness, roughness); + ssr_accum.a *= smoothstep(ssrMaxRoughness + 0.2, ssrMaxRoughness, roughness); accumulate_light(ssr_accum.rgb, ssr_accum.a, spec_accum); } diff --git a/source/blender/draw/engines/eevee/shaders/effect_subsurface_frag.glsl b/source/blender/draw/engines/eevee/shaders/effect_subsurface_frag.glsl index a0c39c79048..184eac54c26 100644 --- a/source/blender/draw/engines/eevee/shaders/effect_subsurface_frag.glsl +++ b/source/blender/draw/engines/eevee/shaders/effect_subsurface_frag.glsl @@ -8,7 +8,6 @@ layout(std140) uniform sssProfile { int sss_samples; }; -uniform float jitterThreshold; uniform sampler2D depthBuffer; uniform sampler2D sssData; uniform sampler2D sssAlbedo; @@ -22,7 +21,6 @@ uniform sampler2DArray utilTex; out vec4 FragColor; uniform mat4 ProjectionMatrix; -uniform vec4 viewvecs[2]; float get_view_z_from_depth(float depth) { @@ -31,7 +29,7 @@ float get_view_z_from_depth(float depth) return -ProjectionMatrix[3][2] / (d + ProjectionMatrix[2][2]); } else { - return viewvecs[0].z + depth * viewvecs[1].z; + return viewVecs[0].z + depth * viewVecs[1].z; } } @@ -66,7 +64,7 @@ void main(void) vec3 accum = sss_data.rgb * kernel[0].rgb; for (int i = 1; i < sss_samples && i < MAX_SSS_SAMPLES; i++) { - vec2 sample_uv = uvs + kernel[i].a * finalStep * ((abs(kernel[i].a) > jitterThreshold) ? dir : dir_rand); + vec2 sample_uv = uvs + kernel[i].a * finalStep * ((abs(kernel[i].a) > sssJitterThreshold) ? dir : dir_rand); vec3 color = texture(sssData, sample_uv).rgb; float sample_depth = texture(depthBuffer, sample_uv).r; sample_depth = get_view_z_from_depth(sample_depth); diff --git a/source/blender/draw/engines/eevee/shaders/irradiance_lib.glsl b/source/blender/draw/engines/eevee/shaders/irradiance_lib.glsl index 76d20486d3d..132cc16fcbd 100644 --- a/source/blender/draw/engines/eevee/shaders/irradiance_lib.glsl +++ b/source/blender/draw/engines/eevee/shaders/irradiance_lib.glsl @@ -1,6 +1,5 @@ uniform sampler2DArray irradianceGrid; -uniform int irradianceVisibilitySize; #define IRRADIANCE_LIB @@ -81,8 +80,8 @@ IrradianceData load_irradiance_cell(int cell, vec3 N) float load_visibility_cell(int cell, vec3 L, float dist, float bias, float bleed_bias, float range) { /* Keep in sync with diffuse_filter_probe() */ - ivec2 cell_co = ivec2(irradianceVisibilitySize); - ivec2 cell_per_row_col = textureSize(irradianceGrid, 0).xy / irradianceVisibilitySize; + ivec2 cell_co = ivec2(prbIrradianceVisSize); + ivec2 cell_per_row_col = textureSize(irradianceGrid, 0).xy / prbIrradianceVisSize; cell_co.x *= (cell % cell_per_row_col.x); cell_co.y *= (cell / cell_per_row_col.x) % cell_per_row_col.y; float layer = 1.0 + float((cell / cell_per_row_col.x) / cell_per_row_col.y); @@ -90,8 +89,8 @@ float load_visibility_cell(int cell, vec3 L, float dist, float bias, float bleed vec2 texel_size = 1.0 / vec2(textureSize(irradianceGrid, 0).xy); vec2 co = vec2(cell_co) * texel_size; - vec2 uv = mapping_octahedron(-L, vec2(1.0 / float(irradianceVisibilitySize))); - uv *= vec2(irradianceVisibilitySize) * texel_size; + vec2 uv = mapping_octahedron(-L, vec2(1.0 / float(prbIrradianceVisSize))); + uv *= vec2(prbIrradianceVisSize) * texel_size; vec4 data = texture(irradianceGrid, vec3(co + uv, layer)); diff --git a/source/blender/draw/engines/eevee/shaders/lightprobe_cube_display_frag.glsl b/source/blender/draw/engines/eevee/shaders/lightprobe_cube_display_frag.glsl index fc0b5b9548b..d10f4bc0d42 100644 --- a/source/blender/draw/engines/eevee/shaders/lightprobe_cube_display_frag.glsl +++ b/source/blender/draw/engines/eevee/shaders/lightprobe_cube_display_frag.glsl @@ -11,5 +11,5 @@ void main() ? normalize(cameraPos - worldPosition) : cameraForward; vec3 N = normalize(worldNormal); - FragColor = vec4(textureLod_octahedron(probeCubes, vec4(reflect(-V, N), pid), 0.0, lodCubeMax).rgb, 1.0); + FragColor = vec4(textureLod_octahedron(probeCubes, vec4(reflect(-V, N), pid), 0.0, prbLodCubeMax).rgb, 1.0); } diff --git a/source/blender/draw/engines/eevee/shaders/lightprobe_lib.glsl b/source/blender/draw/engines/eevee/shaders/lightprobe_lib.glsl index e914228aded..429f6ea92e4 100644 --- a/source/blender/draw/engines/eevee/shaders/lightprobe_lib.glsl +++ b/source/blender/draw/engines/eevee/shaders/lightprobe_lib.glsl @@ -1,10 +1,7 @@ /* ----------- Uniforms --------- */ uniform sampler2DArray probePlanars; -uniform float lodPlanarMax; - uniform sampler2DArray probeCubes; -uniform float lodCubeMax; /* ----------- Structures --------- */ @@ -162,12 +159,12 @@ vec3 probe_evaluate_cube(float id, CubeData cd, vec3 W, vec3 R, float roughness) float fac = saturate(original_roughness * 2.0 - 1.0); R = mix(intersection, R, fac * fac); - return textureLod_octahedron(probeCubes, vec4(R, id), roughness * lodCubeMax, lodCubeMax).rgb; + return textureLod_octahedron(probeCubes, vec4(R, id), roughness * prbLodCubeMax, prbLodCubeMax).rgb; } vec3 probe_evaluate_world_spec(vec3 R, float roughness) { - return textureLod_octahedron(probeCubes, vec4(R, 0.0), roughness * lodCubeMax, lodCubeMax).rgb; + return textureLod_octahedron(probeCubes, vec4(R, 0.0), roughness * prbLodCubeMax, prbLodCubeMax).rgb; } vec3 probe_evaluate_planar( diff --git a/source/blender/draw/engines/eevee/shaders/lit_surface_frag.glsl b/source/blender/draw/engines/eevee/shaders/lit_surface_frag.glsl index a2917842d43..cc66b477da0 100644 --- a/source/blender/draw/engines/eevee/shaders/lit_surface_frag.glsl +++ b/source/blender/draw/engines/eevee/shaders/lit_surface_frag.glsl @@ -2,14 +2,6 @@ #ifndef LIT_SURFACE_UNIFORM #define LIT_SURFACE_UNIFORM -uniform int light_count; -uniform int probe_count; -uniform int grid_count; -uniform int planar_count; - -uniform bool specToggle; -uniform bool ssrToggle; - uniform float refractionDepth; #ifndef UTIL_TEX @@ -29,8 +21,6 @@ in vec3 worldNormal; in vec3 viewNormal; #endif -uniform float maxRoughness; - #endif /* LIT_SURFACE_UNIFORM */ /** AUTO CONFIG @@ -187,7 +177,7 @@ void CLOSURE_NAME( norm_view = normalize(cross(norm_view, N)); /* Normal facing view */ #endif - for (int i = 0; i < MAX_LIGHT && i < light_count; ++i) { + for (int i = 0; i < MAX_LIGHT && i < laNumLight; ++i) { LightData ld = lights_data[i]; vec4 l_vector; /* Non-Normalized Light Vector with length in last component. */ @@ -266,7 +256,7 @@ void CLOSURE_NAME( /* Planar Reflections */ /* ---------------------------- */ - for (int i = 0; i < MAX_PLANAR && i < planar_count && spec_accum.a < 0.999; ++i) { + for (int i = 0; i < MAX_PLANAR && i < prbNumPlanar && spec_accum.a < 0.999; ++i) { PlanarData pd = planars_data[i]; /* Fade on geometric normal. */ @@ -312,11 +302,11 @@ void CLOSURE_NAME( /* Screen Space Refraction */ /* ---------------------------- */ #ifdef USE_REFRACTION - if (ssrToggle && roughness < maxRoughness + 0.2) { + if (ssrToggle && roughness < ssrMaxRoughness + 0.2) { /* Find approximated position of the 2nd refraction event. */ vec3 refr_vpos = (refractionDepth > 0.0) ? transform_point(ViewMatrix, refr_pos) : viewPosition; vec4 trans = screen_space_refraction(refr_vpos, N, refr_V, final_ior, roughnessSquared, rand); - trans.a *= smoothstep(maxRoughness + 0.2, maxRoughness, roughness); + trans.a *= smoothstep(ssrMaxRoughness + 0.2, ssrMaxRoughness, roughness); accumulate_light(trans.rgb, trans.a, refr_accum); } #endif @@ -336,7 +326,7 @@ void CLOSURE_NAME( #endif /* Starts at 1 because 0 is world probe */ - for (int i = 1; ACCUM.a < 0.999 && i < probe_count && i < MAX_PROBE; ++i) { + for (int i = 1; ACCUM.a < 0.999 && i < prbNumRenderCube && i < MAX_PROBE; ++i) { CubeData cd = probes_data[i]; float fade = probe_attenuation_cube(cd, worldPosition); @@ -448,7 +438,7 @@ void CLOSURE_NAME( /* Irradiance Grids */ /* ---------------------------- */ /* Start at 1 because 0 is world irradiance */ - for (int i = 1; i < MAX_GRID && i < grid_count && diff_accum.a < 0.999; ++i) { + for (int i = 1; i < MAX_GRID && i < prbNumRenderGrid && diff_accum.a < 0.999; ++i) { GridData gd = grids_data[i]; vec3 localpos; @@ -463,7 +453,7 @@ void CLOSURE_NAME( /* ---------------------------- */ /* World Diffuse */ /* ---------------------------- */ - if (diff_accum.a < 0.999 && grid_count > 0) { + if (diff_accum.a < 0.999 && prbNumRenderGrid > 0) { vec3 diff = probe_evaluate_world_diff(bent_normal); accumulate_light(diff, 1.0, diff_accum); } diff --git a/source/blender/draw/engines/eevee/shaders/raytrace_lib.glsl b/source/blender/draw/engines/eevee/shaders/raytrace_lib.glsl index c593081ce91..cb75731b7da 100644 --- a/source/blender/draw/engines/eevee/shaders/raytrace_lib.glsl +++ b/source/blender/draw/engines/eevee/shaders/raytrace_lib.glsl @@ -1,13 +1,5 @@ #define MAX_STEP 256 -uniform vec4 ssrParameters; - -#define ssrQuality ssrParameters.x -#define ssrThickness ssrParameters.y -#define ssrPixelSize ssrParameters.zw - -uniform float borderFadeFactor; - float sample_depth(vec2 uv, int index, float lod) { #ifdef PLANAR_PROBE_RAYTRACE @@ -233,7 +225,7 @@ vec3 raycast( float screen_border_mask(vec2 hit_co) { const float margin = 0.003; - float atten = borderFadeFactor + margin; /* Screen percentage */ + float atten = ssrBorderFac + margin; /* Screen percentage */ hit_co = smoothstep(margin, atten, hit_co) * (1 - smoothstep(1.0 - atten, 1.0 - margin, hit_co)); float screenfade = hit_co.x * hit_co.y; diff --git a/source/blender/draw/engines/eevee/shaders/volumetric_frag.glsl b/source/blender/draw/engines/eevee/shaders/volumetric_frag.glsl index 00e01e753f9..3a293647f84 100644 --- a/source/blender/draw/engines/eevee/shaders/volumetric_frag.glsl +++ b/source/blender/draw/engines/eevee/shaders/volumetric_frag.glsl @@ -4,9 +4,6 @@ #define NODETREE_EXEC -uniform ivec3 volumeTextureSize; -uniform vec3 volume_jitter; - #ifdef MESH_SHADER uniform mat4 volumeObjectMatrix; uniform vec3 volumeOrcoLoc; @@ -33,7 +30,7 @@ layout(location = 3) out vec4 volumePhase; void main() { ivec3 volume_cell = ivec3(gl_FragCoord.xy, slice); - vec3 ndc_cell = volume_to_ndc((vec3(volume_cell) + volume_jitter) / volumeTextureSize); + vec3 ndc_cell = volume_to_ndc((vec3(volume_cell) + volJitter.xyz) * volInvTexSize.xyz); viewPosition = get_view_space_from_depth(ndc_cell.xy, ndc_cell.z); worldPosition = transform_point(ViewMatrixInverse, viewPosition); diff --git a/source/blender/draw/engines/eevee/shaders/volumetric_lib.glsl b/source/blender/draw/engines/eevee/shaders/volumetric_lib.glsl index e12554bfabc..1a8167c2830 100644 --- a/source/blender/draw/engines/eevee/shaders/volumetric_lib.glsl +++ b/source/blender/draw/engines/eevee/shaders/volumetric_lib.glsl @@ -2,22 +2,16 @@ /* Based on Frosbite Unified Volumetric. * https://www.ea.com/frostbite/news/physically-based-unified-volumetric-rendering-in-frostbite */ -uniform float volume_light_clamp; - -uniform vec3 volume_param; /* Parameters to the volume Z equation */ - -uniform vec2 volume_uv_ratio; /* To convert volume uvs to screen uvs */ - /* Volume slice to view space depth. */ float volume_z_to_view_z(float z) { if (ProjectionMatrix[3][3] == 0.0) { /* Exponential distribution */ - return (exp2(z / volume_param.z) - volume_param.x) / volume_param.y; + return (exp2(z / volDepthParameters.z) - volDepthParameters.x) / volDepthParameters.y; } else { /* Linear distribution */ - return mix(volume_param.x, volume_param.y, z); + return mix(volDepthParameters.x, volDepthParameters.y, z); } } @@ -25,11 +19,11 @@ float view_z_to_volume_z(float depth) { if (ProjectionMatrix[3][3] == 0.0) { /* Exponential distribution */ - return volume_param.z * log2(depth * volume_param.y + volume_param.x); + return volDepthParameters.z * log2(depth * volDepthParameters.y + volDepthParameters.x); } else { /* Linear distribution */ - return (depth - volume_param.x) * volume_param.z; + return (depth - volDepthParameters.x) * volDepthParameters.z; } } @@ -38,7 +32,7 @@ vec3 volume_to_ndc(vec3 cos) { cos.z = volume_z_to_view_z(cos.z); cos.z = get_depth_from_view_z(cos.z); - cos.xy /= volume_uv_ratio; + cos.xy /= volCoordScale.xy; return cos; } @@ -46,7 +40,7 @@ vec3 ndc_to_volume(vec3 cos) { cos.z = get_view_z_from_depth(cos.z); cos.z = view_z_to_volume_z(cos.z); - cos.xy *= volume_uv_ratio; + cos.xy *= volCoordScale.xy; return cos; } @@ -90,15 +84,13 @@ vec3 light_volume(LightData ld, vec4 l_vector) power /= (l_vector.w * l_vector.w); - lum = min(lum * power, volume_light_clamp); + lum = min(lum * power, volLightClamp); return tint * lum; } #define VOLUMETRIC_SHADOW_MAX_STEP 32.0 -uniform float volume_shadows_steps; - vec3 participating_media_extinction(vec3 wpos, sampler3D volume_extinction) { /* Waiting for proper volume shadowmaps and out of frustum shadow map. */ @@ -113,11 +105,11 @@ vec3 light_volume_shadow(LightData ld, vec3 ray_wpos, vec4 l_vector, sampler3D v { #if defined(VOLUME_SHADOW) /* Heterogeneous volume shadows */ - float dd = l_vector.w / volume_shadows_steps; + float dd = l_vector.w / volShadowSteps; vec3 L = l_vector.xyz * l_vector.w; vec3 shadow = vec3(1.0); - for (float s = 0.5; s < VOLUMETRIC_SHADOW_MAX_STEP && s < (volume_shadows_steps - 0.1); s += 1.0) { - vec3 pos = ray_wpos + L * (s / volume_shadows_steps); + for (float s = 0.5; s < VOLUMETRIC_SHADOW_MAX_STEP && s < (volShadowSteps - 0.1); s += 1.0) { + vec3 pos = ray_wpos + L * (s / volShadowSteps); vec3 s_extinction = participating_media_extinction(pos, volume_extinction); shadow *= exp(-s_extinction * dd); } 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 ea402ff3d99..fcbb6661b14 100644 --- a/source/blender/draw/engines/eevee/shaders/volumetric_scatter_frag.glsl +++ b/source/blender/draw/engines/eevee/shaders/volumetric_scatter_frag.glsl @@ -13,28 +13,20 @@ uniform sampler3D volumePhase; uniform sampler3D historyScattering; uniform sampler3D historyTransmittance; -uniform vec3 volume_jitter; -uniform float volume_history_alpha; -uniform int light_count; -uniform mat4 PastViewProjectionMatrix; - flat in int slice; layout(location = 0) out vec4 outScattering; layout(location = 1) out vec4 outTransmittance; -#define VOLUME_LIGHTING - void main() { - vec3 volume_tex_size = vec3(textureSize(volumeScattering, 0)); ivec3 volume_cell = ivec3(gl_FragCoord.xy, slice); /* Emission */ outScattering = texelFetch(volumeEmission, volume_cell, 0); outTransmittance = texelFetch(volumeExtinction, volume_cell, 0); vec3 s_scattering = texelFetch(volumeScattering, volume_cell, 0).rgb; - vec3 volume_ndc = volume_to_ndc((vec3(volume_cell) + volume_jitter) / volume_tex_size); + 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; @@ -45,7 +37,7 @@ void main() outScattering.rgb += irradiance_volumetric(worldPosition) * s_scattering * phase_function_isotropic(); #ifdef VOLUME_LIGHTING /* Lights */ - for (int i = 0; i < MAX_LIGHT && i < light_count; ++i) { + for (int i = 0; i < MAX_LIGHT && i < laNumLight; ++i) { LightData ld = lights_data[i]; @@ -63,16 +55,16 @@ void main() /* Temporal supersampling */ /* Note : this uses the cell non-jittered position (texel center). */ - vec3 curr_ndc = volume_to_ndc(vec3(gl_FragCoord.xy, float(slice) + 0.5) / volume_tex_size); + vec3 curr_ndc = volume_to_ndc(vec3(gl_FragCoord.xy, float(slice) + 0.5) * volInvTexSize.xyz); vec3 wpos = get_world_space_from_depth(curr_ndc.xy, curr_ndc.z); - vec3 prev_ndc = project_point(PastViewProjectionMatrix, wpos); + vec3 prev_ndc = project_point(pastViewProjectionMatrix, wpos); vec3 prev_volume = ndc_to_volume(prev_ndc * 0.5 + 0.5); - if ((volume_history_alpha > 0.0) && all(greaterThan(prev_volume, vec3(0.0))) && all(lessThan(prev_volume, vec3(1.0)))) { + if ((volHistoryAlpha > 0.0) && all(greaterThan(prev_volume, vec3(0.0))) && all(lessThan(prev_volume, vec3(1.0)))) { vec4 h_Scattering = texture(historyScattering, prev_volume); vec4 h_Transmittance = texture(historyTransmittance, prev_volume); - outScattering = mix(outScattering, h_Scattering, volume_history_alpha); - outTransmittance = mix(outTransmittance, h_Transmittance, volume_history_alpha); + outScattering = mix(outScattering, h_Scattering, volHistoryAlpha); + outTransmittance = mix(outTransmittance, h_Transmittance, volHistoryAlpha); } /* Catch NaNs */ |