diff options
author | Clément Foucault <foucault.clem@gmail.com> | 2018-03-10 02:00:04 +0300 |
---|---|---|
committer | Clément Foucault <foucault.clem@gmail.com> | 2018-03-10 04:18:25 +0300 |
commit | 82957cfec8818b97b1c91b2c36b6efd585f0ab3b (patch) | |
tree | 21be689a7842865fcc8fc4d893946bb91a0ffbc5 /source/blender/draw/engines | |
parent | 41abbc271c58cdbd24a4e919c102e6bd1c7b64b3 (diff) |
Eevee: Make use of the new view matrix UBO.
Diffstat (limited to 'source/blender/draw/engines')
12 files changed, 68 insertions, 23 deletions
diff --git a/source/blender/draw/engines/eevee/eevee_lightprobes.c b/source/blender/draw/engines/eevee/eevee_lightprobes.c index 229f4d45606..b8e4e52befe 100644 --- a/source/blender/draw/engines/eevee/eevee_lightprobes.c +++ b/source/blender/draw/engines/eevee/eevee_lightprobes.c @@ -109,6 +109,7 @@ extern char datatoc_lightprobe_lib_glsl[]; extern char datatoc_octahedron_lib_glsl[]; extern char datatoc_bsdf_common_lib_glsl[]; extern char datatoc_common_uniforms_lib_glsl[]; +extern char datatoc_common_view_lib_glsl[]; extern char datatoc_bsdf_sampling_lib_glsl[]; extern GlobalsUboStorage ts; @@ -205,8 +206,10 @@ static void lightprobe_shaders_init(void) "#define NOISE_SIZE 64\n"; char *shader_str = NULL; + char *vert_str = NULL; shader_str = BLI_string_joinN( + datatoc_common_view_lib_glsl, datatoc_common_uniforms_lib_glsl, datatoc_bsdf_common_lib_glsl, datatoc_bsdf_sampling_lib_glsl, @@ -221,6 +224,7 @@ static void lightprobe_shaders_init(void) MEM_freeN(shader_str); shader_str = BLI_string_joinN( + datatoc_common_view_lib_glsl, datatoc_common_uniforms_lib_glsl, datatoc_bsdf_common_lib_glsl, datatoc_bsdf_sampling_lib_glsl, @@ -231,6 +235,7 @@ static void lightprobe_shaders_init(void) MEM_freeN(shader_str); shader_str = BLI_string_joinN( + datatoc_common_view_lib_glsl, datatoc_common_uniforms_lib_glsl, datatoc_bsdf_common_lib_glsl, datatoc_bsdf_sampling_lib_glsl, @@ -242,15 +247,20 @@ static void lightprobe_shaders_init(void) shader_str = BLI_string_joinN( datatoc_octahedron_lib_glsl, + datatoc_common_view_lib_glsl, datatoc_common_uniforms_lib_glsl, datatoc_bsdf_common_lib_glsl, datatoc_irradiance_lib_glsl, datatoc_lightprobe_lib_glsl, datatoc_lightprobe_grid_display_frag_glsl); - e_data.probe_grid_display_sh = DRW_shader_create( - datatoc_lightprobe_grid_display_vert_glsl, NULL, shader_str, filter_defines); + vert_str = BLI_string_joinN( + datatoc_common_view_lib_glsl, + datatoc_lightprobe_grid_display_vert_glsl); + e_data.probe_grid_display_sh = DRW_shader_create(vert_str, NULL, shader_str, filter_defines); + + MEM_freeN(vert_str); MEM_freeN(shader_str); e_data.probe_grid_fill_sh = DRW_shader_create_fullscreen( @@ -258,19 +268,33 @@ static void lightprobe_shaders_init(void) shader_str = BLI_string_joinN( datatoc_octahedron_lib_glsl, + datatoc_common_view_lib_glsl, datatoc_common_uniforms_lib_glsl, datatoc_bsdf_common_lib_glsl, datatoc_lightprobe_lib_glsl, datatoc_lightprobe_cube_display_frag_glsl); - e_data.probe_cube_display_sh = DRW_shader_create( - datatoc_lightprobe_cube_display_vert_glsl, NULL, shader_str, NULL); + vert_str = BLI_string_joinN( + datatoc_common_view_lib_glsl, + datatoc_lightprobe_cube_display_vert_glsl); + + e_data.probe_cube_display_sh = DRW_shader_create(vert_str, NULL, shader_str, NULL); + MEM_freeN(vert_str); MEM_freeN(shader_str); - e_data.probe_planar_display_sh = DRW_shader_create( - datatoc_lightprobe_planar_display_vert_glsl, NULL, - datatoc_lightprobe_planar_display_frag_glsl, NULL); + vert_str = BLI_string_joinN( + datatoc_common_view_lib_glsl, + datatoc_lightprobe_planar_display_vert_glsl); + + shader_str = BLI_string_joinN( + datatoc_common_view_lib_glsl, + datatoc_lightprobe_planar_display_frag_glsl); + + e_data.probe_planar_display_sh = DRW_shader_create(vert_str, NULL, shader_str, NULL); + + MEM_freeN(vert_str); + MEM_freeN(shader_str); e_data.probe_planar_downsample_sh = DRW_shader_create( datatoc_lightprobe_planar_downsample_vert_glsl, diff --git a/source/blender/draw/engines/eevee/eevee_materials.c b/source/blender/draw/engines/eevee/eevee_materials.c index a72bf85cbe9..6c76a86d491 100644 --- a/source/blender/draw/engines/eevee/eevee_materials.c +++ b/source/blender/draw/engines/eevee/eevee_materials.c @@ -47,6 +47,7 @@ /* *********** STATIC *********** */ static struct { + char *shadow_shader_lib; char *frag_shader_lib; char *volume_shader_lib; @@ -81,6 +82,7 @@ extern char datatoc_bsdf_common_lib_glsl[]; extern char datatoc_bsdf_direct_lib_glsl[]; extern char datatoc_bsdf_sampling_lib_glsl[]; extern char datatoc_common_uniforms_lib_glsl[]; +extern char datatoc_common_view_lib_glsl[]; extern char datatoc_irradiance_lib_glsl[]; extern char datatoc_octahedron_lib_glsl[]; extern char datatoc_lit_surface_frag_glsl[]; @@ -531,7 +533,7 @@ void EEVEE_materials_init(EEVEE_ViewLayerData *sldata, EEVEE_StorageList *stl, E char *frag_str = NULL; /* Shaders */ - e_data.frag_shader_lib = BLI_string_joinN( + e_data.shadow_shader_lib = BLI_string_joinN( datatoc_common_uniforms_lib_glsl, datatoc_bsdf_common_lib_glsl, datatoc_bsdf_sampling_lib_glsl, @@ -555,7 +557,12 @@ void EEVEE_materials_init(EEVEE_ViewLayerData *sldata, EEVEE_StorageList *stl, E datatoc_lit_surface_frag_glsl, datatoc_volumetric_lib_glsl); + e_data.frag_shader_lib = BLI_string_joinN( + datatoc_common_view_lib_glsl, + e_data.shadow_shader_lib); + e_data.volume_shader_lib = BLI_string_joinN( + datatoc_common_view_lib_glsl, datatoc_common_uniforms_lib_glsl, datatoc_bsdf_common_lib_glsl, datatoc_ambient_occlusion_lib_glsl, @@ -755,7 +762,7 @@ struct GPUMaterial *EEVEE_material_mesh_depth_get( char *defines = eevee_get_defines(options); char *frag_str = BLI_string_joinN( - e_data.frag_shader_lib, + (is_shadow) ? e_data.shadow_shader_lib : e_data.frag_shader_lib, datatoc_prepass_frag_glsl); mat = DRW_shader_create_from_material( @@ -1515,6 +1522,7 @@ void EEVEE_materials_free(void) for (int i = 0; i < VAR_MAT_MAX; ++i) { DRW_SHADER_FREE_SAFE(e_data.default_lit[i]); } + MEM_SAFE_FREE(e_data.shadow_shader_lib); MEM_SAFE_FREE(e_data.frag_shader_lib); MEM_SAFE_FREE(e_data.volume_shader_lib); DRW_SHADER_FREE_SAFE(e_data.default_prepass_sh); diff --git a/source/blender/draw/engines/eevee/eevee_mist.c b/source/blender/draw/engines/eevee/eevee_mist.c index ba9157a7f91..e221ed865b5 100644 --- a/source/blender/draw/engines/eevee/eevee_mist.c +++ b/source/blender/draw/engines/eevee/eevee_mist.c @@ -35,6 +35,7 @@ #include "eevee_private.h" +extern char datatoc_common_view_lib_glsl[]; extern char datatoc_common_uniforms_lib_glsl[]; extern char datatoc_bsdf_common_lib_glsl[]; extern char datatoc_effect_mist_frag_glsl[]; @@ -59,6 +60,7 @@ void EEVEE_mist_output_init(EEVEE_ViewLayerData *sldata, EEVEE_Data *vedata) if (e_data.mist_sh == NULL) { char *frag_str = BLI_string_joinN( + datatoc_common_view_lib_glsl, datatoc_common_uniforms_lib_glsl, datatoc_bsdf_common_lib_glsl, datatoc_effect_mist_frag_glsl); diff --git a/source/blender/draw/engines/eevee/eevee_occlusion.c b/source/blender/draw/engines/eevee/eevee_occlusion.c index 944003d7d1f..d7d022e9b98 100644 --- a/source/blender/draw/engines/eevee/eevee_occlusion.c +++ b/source/blender/draw/engines/eevee/eevee_occlusion.c @@ -44,6 +44,7 @@ static struct { } e_data = {NULL}; /* Engine data */ extern char datatoc_ambient_occlusion_lib_glsl[]; +extern char datatoc_common_view_lib_glsl[]; extern char datatoc_common_uniforms_lib_glsl[]; extern char datatoc_bsdf_common_lib_glsl[]; extern char datatoc_effect_gtao_frag_glsl[]; @@ -51,6 +52,7 @@ extern char datatoc_effect_gtao_frag_glsl[]; static void eevee_create_shader_occlusion(void) { char *frag_str = BLI_string_joinN( + datatoc_common_view_lib_glsl, datatoc_common_uniforms_lib_glsl, datatoc_bsdf_common_lib_glsl, datatoc_ambient_occlusion_lib_glsl, diff --git a/source/blender/draw/engines/eevee/eevee_screen_raytrace.c b/source/blender/draw/engines/eevee/eevee_screen_raytrace.c index 2917bfd1236..4ae18b24bdc 100644 --- a/source/blender/draw/engines/eevee/eevee_screen_raytrace.c +++ b/source/blender/draw/engines/eevee/eevee_screen_raytrace.c @@ -51,6 +51,7 @@ static struct { } e_data = {NULL}; /* Engine data */ extern char datatoc_ambient_occlusion_lib_glsl[]; +extern char datatoc_common_view_lib_glsl[]; extern char datatoc_common_uniforms_lib_glsl[]; extern char datatoc_bsdf_common_lib_glsl[]; extern char datatoc_bsdf_sampling_lib_glsl[]; @@ -63,6 +64,7 @@ static struct GPUShader *eevee_effects_screen_raytrace_shader_get(int options) { if (e_data.ssr_sh[options] == NULL) { char *ssr_shader_str = BLI_string_joinN( + datatoc_common_view_lib_glsl, datatoc_common_uniforms_lib_glsl, datatoc_bsdf_common_lib_glsl, datatoc_bsdf_sampling_lib_glsl, diff --git a/source/blender/draw/engines/eevee/eevee_subsurface.c b/source/blender/draw/engines/eevee/eevee_subsurface.c index c3079d931fb..be62a407615 100644 --- a/source/blender/draw/engines/eevee/eevee_subsurface.c +++ b/source/blender/draw/engines/eevee/eevee_subsurface.c @@ -36,12 +36,14 @@ static struct { struct GPUShader *sss_sh[4]; } e_data = {NULL}; /* Engine data */ +extern char datatoc_common_view_lib_glsl[]; extern char datatoc_common_uniforms_lib_glsl[]; extern char datatoc_effect_subsurface_frag_glsl[]; static void eevee_create_shader_subsurface(void) { char *frag_str = BLI_string_joinN( + datatoc_common_view_lib_glsl, datatoc_common_uniforms_lib_glsl, datatoc_effect_subsurface_frag_glsl); diff --git a/source/blender/draw/engines/eevee/eevee_volumes.c b/source/blender/draw/engines/eevee/eevee_volumes.c index 2dbce1379ec..26ac4498073 100644 --- a/source/blender/draw/engines/eevee/eevee_volumes.c +++ b/source/blender/draw/engines/eevee/eevee_volumes.c @@ -65,6 +65,7 @@ static struct { extern char datatoc_bsdf_common_lib_glsl[]; extern char datatoc_bsdf_direct_lib_glsl[]; extern char datatoc_common_uniforms_lib_glsl[]; +extern char datatoc_common_view_lib_glsl[]; extern char datatoc_octahedron_lib_glsl[]; extern char datatoc_irradiance_lib_glsl[]; extern char datatoc_lamps_lib_glsl[]; @@ -80,11 +81,13 @@ extern char datatoc_gpu_shader_fullscreen_vert_glsl[]; static void eevee_create_shader_volumes(void) { e_data.volumetric_common_lib = BLI_string_joinN( + datatoc_common_view_lib_glsl, datatoc_common_uniforms_lib_glsl, datatoc_bsdf_common_lib_glsl, datatoc_volumetric_lib_glsl); e_data.volumetric_common_lamps_lib = BLI_string_joinN( + datatoc_common_view_lib_glsl, datatoc_common_uniforms_lib_glsl, datatoc_bsdf_common_lib_glsl, datatoc_bsdf_direct_lib_glsl, 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 f571d8c727b..23487e66a17 100644 --- a/source/blender/draw/engines/eevee/shaders/bsdf_common_lib.glsl +++ b/source/blender/draw/engines/eevee/shaders/bsdf_common_lib.glsl @@ -8,12 +8,7 @@ #define LUT_SIZE 64 -uniform mat4 ProjectionMatrix; -uniform mat4 ViewProjectionMatrix; -uniform mat4 ViewMatrixInverse; -#ifndef SHADOW_SHADER -uniform mat4 ViewMatrix; -#else +#ifdef SHADOW_SHADER layout(std140) uniform shadow_render_block { mat4 ShadowMatrix[6]; mat4 FaceViewMatrix[6]; @@ -27,7 +22,21 @@ layout(std140) uniform shadow_render_block { }; flat in int shFace; /* Shadow layer we are rendering to. */ -#define ViewMatrix FaceViewMatrix[shFace] + +/* Replacing viewBlock */ +#define ViewMatrix FaceViewMatrix[shFace] +#define ViewProjectionMatrix ShadowMatrix[shFace] +/* TODO optimize */ +#define ProjectionMatrix \ +mat4(vec4(1.0, 0.0, 0.0, 0.0), \ + vec4(0.0, 1.0, 0.0, 0.0), \ + vec4(0.0, 0.0, -(farClip + nearClip) / (farClip - nearClip), -1.0), \ + vec4(0.0, 0.0, (-2.0 * farClip * nearClip) / (farClip - nearClip), 0.0)) + +#define ViewMatrixInverse invert(ViewMatrix) +#define ViewProjectionMatrixInverse invert(ViewProjectionMatrix) +#define ProjectionMatrixInverse invert(ProjectionMatrix) +#define CameraTexCoFactors vec4(1.0f, 1.0f, 0.0f, 0.0f) #endif /* Buffers */ diff --git a/source/blender/draw/engines/eevee/shaders/lightprobe_cube_display_vert.glsl b/source/blender/draw/engines/eevee/shaders/lightprobe_cube_display_vert.glsl index 202b27be0ef..57da4d0d1ec 100644 --- a/source/blender/draw/engines/eevee/shaders/lightprobe_cube_display_vert.glsl +++ b/source/blender/draw/engines/eevee/shaders/lightprobe_cube_display_vert.glsl @@ -6,8 +6,6 @@ in int probe_id; in vec3 probe_location; in float sphere_size; -uniform mat4 ViewProjectionMatrix; - flat out int pid; out vec3 worldNormal; out vec3 worldPosition; diff --git a/source/blender/draw/engines/eevee/shaders/lightprobe_grid_display_vert.glsl b/source/blender/draw/engines/eevee/shaders/lightprobe_grid_display_vert.glsl index fd200ec5984..37f73714a8e 100644 --- a/source/blender/draw/engines/eevee/shaders/lightprobe_grid_display_vert.glsl +++ b/source/blender/draw/engines/eevee/shaders/lightprobe_grid_display_vert.glsl @@ -1,8 +1,6 @@ in vec3 pos; -uniform mat4 ViewProjectionMatrix; - uniform float sphere_size; uniform int offset; uniform ivec3 grid_resolution; diff --git a/source/blender/draw/engines/eevee/shaders/lightprobe_planar_display_frag.glsl b/source/blender/draw/engines/eevee/shaders/lightprobe_planar_display_frag.glsl index 655cc626bba..3808b59761f 100644 --- a/source/blender/draw/engines/eevee/shaders/lightprobe_planar_display_frag.glsl +++ b/source/blender/draw/engines/eevee/shaders/lightprobe_planar_display_frag.glsl @@ -1,5 +1,4 @@ -uniform mat4 ViewProjectionMatrix; uniform sampler2DArray probePlanars; in vec3 worldPosition; diff --git a/source/blender/draw/engines/eevee/shaders/lightprobe_planar_display_vert.glsl b/source/blender/draw/engines/eevee/shaders/lightprobe_planar_display_vert.glsl index a9716332eb5..3ecd85fd72e 100644 --- a/source/blender/draw/engines/eevee/shaders/lightprobe_planar_display_vert.glsl +++ b/source/blender/draw/engines/eevee/shaders/lightprobe_planar_display_vert.glsl @@ -4,8 +4,6 @@ in vec3 pos; in int probe_id; in mat4 probe_mat; -uniform mat4 ViewProjectionMatrix; - out vec3 worldPosition; flat out int probeIdx; |