diff options
Diffstat (limited to 'source/blender/draw/engines')
3 files changed, 54 insertions, 8 deletions
diff --git a/source/blender/draw/engines/eevee/eevee_engine.c b/source/blender/draw/engines/eevee/eevee_engine.c index 5f7c7787cfc..825a7b75502 100644 --- a/source/blender/draw/engines/eevee/eevee_engine.c +++ b/source/blender/draw/engines/eevee/eevee_engine.c @@ -399,7 +399,7 @@ static void EEVEE_cache_init(void *vedata) if (wo && wo->use_nodes && wo->nodetree) { struct GPUMaterial *gpumat = GPU_material_from_nodetree( - wo->nodetree, &wo->gpumaterial, &DRW_engine_viewport_eevee_type, 0, + scene, wo->nodetree, &wo->gpumaterial, &DRW_engine_viewport_eevee_type, 0, datatoc_probe_vert_glsl, datatoc_probe_geom_glsl, e_data.frag_shader_lib, "#define PROBE_CAPTURE\n" "#define MAX_LIGHT 128\n" @@ -541,11 +541,44 @@ static void EEVEE_cache_populate(void *vedata, Object *ob) if (ma == NULL) ma = &defmaterial; - DRWShadingGroup *shgrp = DRW_shgroup_create(e_data.default_lit, psl->material_pass); - DRW_shgroup_uniform_vec3(shgrp, "diffuse_col", &ma->r, 1); - DRW_shgroup_uniform_vec3(shgrp, "specular_col", &ma->specr, 1); - DRW_shgroup_uniform_short(shgrp, "hardness", &ma->har, 1); - DRW_shgroup_call_add(shgrp, mat_geom[i], ob->obmat); + if (ma->use_nodes && ma->nodetree) { + const DRWContextState *draw_ctx = DRW_context_state_get(); + Scene *scene = draw_ctx->scene; + struct GPUMaterial *gpumat = GPU_material_from_nodetree( + scene, ma->nodetree, &ma->gpumaterial, &DRW_engine_viewport_eevee_type, 0, + datatoc_lit_surface_vert_glsl, NULL, e_data.frag_shader_lib, + "#define PROBE_CAPTURE\n" + "#define MAX_LIGHT 128\n" + "#define MAX_SHADOW_CUBE 42\n" + "#define MAX_SHADOW_MAP 64\n" + "#define MAX_SHADOW_CASCADE 8\n" + "#define MAX_CASCADE_NUM 4\n"); + + DRWShadingGroup *shgrp = DRW_shgroup_material_create(gpumat, psl->material_pass); + + if (shgrp) { + DRW_shgroup_call_add(shgrp, mat_geom[i], ob->obmat); + } + else { + /* Shader failed : pink color */ + static float col[3] = {1.0f, 0.0f, 1.0f}; + static float spec[3] = {1.0f, 0.0f, 1.0f}; + static short hardness = 1; + shgrp = DRW_shgroup_create(e_data.default_lit, psl->default_pass); + DRW_shgroup_uniform_vec3(shgrp, "diffuse_col", col, 1); + DRW_shgroup_uniform_vec3(shgrp, "specular_col", spec, 1); + DRW_shgroup_uniform_short(shgrp, "hardness", &hardness, 1); + DRW_shgroup_call_add(shgrp, mat_geom[i], ob->obmat); + } + } + else { + DRWShadingGroup *shgrp = DRW_shgroup_create(e_data.default_lit, psl->default_pass); + DRW_shgroup_uniform_vec3(shgrp, "diffuse_col", &ma->r, 1); + DRW_shgroup_uniform_vec3(shgrp, "specular_col", &ma->specr, 1); + DRW_shgroup_uniform_short(shgrp, "hardness", &ma->har, 1); + DRW_shgroup_call_add(shgrp, mat_geom[i], ob->obmat); + } + } } else { @@ -555,7 +588,6 @@ static void EEVEE_cache_populate(void *vedata, Object *ob) eevee_cascade_shadow_shgroup(psl, stl, geom, ob->obmat); eevee_cube_shadow_shgroup(psl, stl, geom, ob->obmat); } - // GPUMaterial *gpumat = GPU_material_from_nodetree(struct bNodeTree *ntree, ListBase *gpumaterials, void *engine_type, int options) // DRW_shgroup_call_add(stl->g_data->shadow_shgrp, geom, ob->obmat); 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 10d9ce7c4c0..9b8963ef798 100644 --- a/source/blender/draw/engines/eevee/shaders/lit_surface_frag.glsl +++ b/source/blender/draw/engines/eevee/shaders/lit_surface_frag.glsl @@ -26,7 +26,9 @@ layout(std140) uniform shadow_block { }; in vec3 worldPosition; +in vec3 viewPosition; in vec3 worldNormal; +in vec3 viewNormal; /* type */ #define POINT 0.0 diff --git a/source/blender/draw/engines/eevee/shaders/lit_surface_vert.glsl b/source/blender/draw/engines/eevee/shaders/lit_surface_vert.glsl index d0a5ee06694..4dd6bb1e287 100644 --- a/source/blender/draw/engines/eevee/shaders/lit_surface_vert.glsl +++ b/source/blender/draw/engines/eevee/shaders/lit_surface_vert.glsl @@ -1,16 +1,28 @@ uniform mat4 ModelViewProjectionMatrix; uniform mat4 ModelMatrix; +uniform mat4 ModelViewMatrix; uniform mat3 WorldNormalMatrix; +#ifndef ATTRIB +uniform mat3 NormalMatrix; +#endif in vec3 pos; in vec3 nor; out vec3 worldPosition; +out vec3 viewPosition; out vec3 worldNormal; +out vec3 viewNormal; void main() { gl_Position = ModelViewProjectionMatrix * vec4(pos, 1.0); + viewPosition = (ModelViewMatrix * vec4(pos, 1.0)).xyz; worldPosition = (ModelMatrix * vec4(pos, 1.0)).xyz; - worldNormal = WorldNormalMatrix * nor; + viewNormal = normalize(NormalMatrix * nor); + worldNormal = normalize(WorldNormalMatrix * nor); + +#ifdef ATTRIB + pass_attrib(); +#endif }
\ No newline at end of file |