From b18c2a3c413b7741b2a854b7bd25721352be2589 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Foucault?= Date: Tue, 2 Jun 2020 16:58:07 +0200 Subject: EEVEE: Refactor of eevee_material.c These are the modifications: -With DRW modification we reduce the number of passes we need to populate. -Rename passes for consistent naming. -Reduce complexity in code compilation -Cleanup how renderpass accumulation passes are setup, using pass instances. -Make sculpt mode compatible with shadows -Make hair passes compatible with SSS -Error shader and lookdev materials now use standalone materials. -Support default shader (world and material) using a default nodetree internally. -Change BLEND_CLIP to be emulated by gpu nodetree. Making less shader variations. -Use BLI_memblock for cache memory allocation. -Renderpasses are handled by switching a UBO ref bind. One major hack in this patch is the use of modified pointer as ghash keys. This rely on the assumption that the keys will never overlap because the number of options per key will never be bigger than the pointed struct. The use of one single nodetree to support default material is also a bit hacky since it won't support concurent usage of this nodetree. (see EEVEE_shader_default_surface_nodetree) Another change is that objects with shader errors now appear solid magenta instead of shaded magenta. This is only because of code reuse purpose but could be changed if really needed. Reviewed By: jbakker Differential Revision: https://developer.blender.org/D7642 --- source/blender/gpu/GPU_material.h | 1 + source/blender/gpu/intern/gpu_material.c | 8 ++++++++ .../shaders/material/gpu_shader_material_output_material.glsl | 10 +++++++++- 3 files changed, 18 insertions(+), 1 deletion(-) (limited to 'source/blender/gpu') diff --git a/source/blender/gpu/GPU_material.h b/source/blender/gpu/GPU_material.h index 337c0b03308..c23960da1ed 100644 --- a/source/blender/gpu/GPU_material.h +++ b/source/blender/gpu/GPU_material.h @@ -190,6 +190,7 @@ void GPU_materials_free(struct Main *bmain); struct Scene *GPU_material_scene(GPUMaterial *material); struct GPUPass *GPU_material_get_pass(GPUMaterial *material); +struct GPUShader *GPU_material_get_shader(GPUMaterial *material); struct Material *GPU_material_get_material(GPUMaterial *material); eGPUMaterialStatus GPU_material_status(GPUMaterial *mat); diff --git a/source/blender/gpu/intern/gpu_material.c b/source/blender/gpu/intern/gpu_material.c index 97e4c880644..d2384b9c065 100644 --- a/source/blender/gpu/intern/gpu_material.c +++ b/source/blender/gpu/intern/gpu_material.c @@ -209,6 +209,11 @@ GPUPass *GPU_material_get_pass(GPUMaterial *material) return material->pass; } +GPUShader *GPU_material_get_shader(GPUMaterial *material) +{ + return material->pass ? GPU_pass_shader_get(material->pass) : NULL; +} + /* Return can be NULL if it's a world material. */ Material *GPU_material_get_material(GPUMaterial *material) { @@ -662,6 +667,9 @@ GPUMaterial *GPU_material_from_nodetree(Scene *scene, /* Caller must re-use materials. */ BLI_assert(GPU_material_from_nodetree_find(gpumaterials, engine_type, options) == NULL); + /* HACK: Eevee assume this to create Ghash keys. */ + BLI_assert(sizeof(GPUPass) > 16); + /* allocate material */ GPUMaterial *mat = MEM_callocN(sizeof(GPUMaterial), "GPUMaterial"); mat->ma = ma; diff --git a/source/blender/gpu/shaders/material/gpu_shader_material_output_material.glsl b/source/blender/gpu/shaders/material/gpu_shader_material_output_material.glsl index 62f76d46088..4cb00c15b78 100644 --- a/source/blender/gpu/shaders/material/gpu_shader_material_output_material.glsl +++ b/source/blender/gpu/shaders/material/gpu_shader_material_output_material.glsl @@ -1,8 +1,16 @@ -void node_output_material(Closure surface, Closure volume, vec3 displacement, out Closure result) +void node_output_material( + Closure surface, Closure volume, vec3 displacement, float alpha_threshold, out Closure result) { #ifdef VOLUMETRICS result = volume; #else result = surface; +# if defined(USE_ALPHA_HASH) + /* Alpha clip emulation. */ + if (alpha_threshold >= 0.0) { + float alpha = saturate(1.0 - avg(result.transmittance)); + result.transmittance = vec3(step(alpha, alpha_threshold)); + } +# endif #endif } -- cgit v1.2.3