diff options
author | Clément Foucault <foucault.clem@gmail.com> | 2019-05-08 21:13:24 +0300 |
---|---|---|
committer | Clément Foucault <foucault.clem@gmail.com> | 2019-05-08 21:13:32 +0300 |
commit | f2f62b184c67f6b548da1cd9c022c9383e541bb0 (patch) | |
tree | 12896f71f49dda76cc6c430c2cdb5ae454d58762 /source/blender/draw | |
parent | bb41626ab3de31f670fcbe3365b61064e899c87f (diff) |
DRW: Remove WorldNormalMatrix
Diffstat (limited to 'source/blender/draw')
6 files changed, 13 insertions, 28 deletions
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 40075ed64be..cddc8e87a1e 100644 --- a/source/blender/draw/engines/eevee/shaders/lit_surface_vert.glsl +++ b/source/blender/draw/engines/eevee/shaders/lit_surface_vert.glsl @@ -1,10 +1,8 @@ uniform mat4 ModelViewProjectionMatrix; uniform mat4 ModelViewMatrix; -uniform mat3 WorldNormalMatrix; #ifndef USE_ATTR uniform mat4 ModelMatrix; -uniform mat3 NormalMatrix; uniform mat4 ModelMatrixInverse; #endif @@ -67,8 +65,10 @@ void main() gl_Position = ModelViewProjectionMatrix * vec4(pos, 1.0); viewPosition = (ModelViewMatrix * vec4(pos, 1.0)).xyz; worldPosition = (ModelMatrix * vec4(pos, 1.0)).xyz; - worldNormal = normalize(WorldNormalMatrix * nor); - viewNormal = normalize(NormalMatrix * nor); + + worldNormal = normalize(transform_normal_object_to_world(nor)); + /* No need to normalize since this is just a rotation. */ + viewNormal = transform_normal_world_to_view(worldNormal); #endif /* Used for planar reflections */ diff --git a/source/blender/draw/engines/eevee/shaders/shadow_vert.glsl b/source/blender/draw/engines/eevee/shaders/shadow_vert.glsl index f9225cd100b..f8850300dc4 100644 --- a/source/blender/draw/engines/eevee/shaders/shadow_vert.glsl +++ b/source/blender/draw/engines/eevee/shaders/shadow_vert.glsl @@ -2,10 +2,8 @@ uniform mat4 ModelViewProjectionMatrix; #ifdef MESH_SHADER uniform mat4 ModelViewMatrix; -uniform mat3 WorldNormalMatrix; # ifndef USE_ATTR uniform mat4 ModelMatrix; -uniform mat3 NormalMatrix; # endif #endif @@ -25,8 +23,10 @@ void main() #ifdef MESH_SHADER viewPosition = (ModelViewMatrix * vec4(pos, 1.0)).xyz; worldPosition = (ModelMatrix * vec4(pos, 1.0)).xyz; - viewNormal = normalize(NormalMatrix * nor); - worldNormal = normalize(WorldNormalMatrix * nor); + + worldNormal = normalize(transform_normal_object_to_world(nor)); + /* No need to normalize since this is just a rotation. */ + viewNormal = transform_normal_world_to_view(worldNormal); # ifdef USE_ATTR pass_attr(pos); # endif diff --git a/source/blender/draw/intern/draw_manager.h b/source/blender/draw/intern/draw_manager.h index 4d74a95bf20..496e5b785bf 100644 --- a/source/blender/draw/intern/draw_manager.h +++ b/source/blender/draw/intern/draw_manager.h @@ -104,7 +104,6 @@ enum { DRW_CALL_MODELVIEWINVERSE = (1 << 2), DRW_CALL_MODELVIEWPROJECTION = (1 << 3), DRW_CALL_NORMALVIEW = (1 << 4), - DRW_CALL_NORMALWORLD = (1 << 6), DRW_CALL_ORCOTEXFAC = (1 << 7), DRW_CALL_OBJECTINFO = (1 << 8), }; @@ -126,8 +125,7 @@ typedef struct DRWCallState { float modelviewinverse[4][4]; float modelviewprojection[4][4]; float normalview[3][3]; - float normalworld[3][3]; /* Not view dependent */ - float orcotexfac[2][3]; /* Not view dependent */ + float orcotexfac[2][3]; /* Not view dependent */ float objectinfo[2]; } DRWCallState; @@ -258,7 +256,6 @@ struct DRWShadingGroup { int modelviewinverse; int modelviewprojection; int normalview; - int normalworld; int orcotexfac; int callid; int objectinfo; diff --git a/source/blender/draw/intern/draw_manager_data.c b/source/blender/draw/intern/draw_manager_data.c index b7225275d72..deabffdaa0d 100644 --- a/source/blender/draw/intern/draw_manager_data.c +++ b/source/blender/draw/intern/draw_manager_data.c @@ -838,7 +838,6 @@ static void drw_shgroup_init(DRWShadingGroup *shgroup, GPUShader *shader) shgroup->modelviewinverse = GPU_shader_get_builtin_uniform(shader, GPU_UNIFORM_MODELVIEW_INV); shgroup->modelviewprojection = GPU_shader_get_builtin_uniform(shader, GPU_UNIFORM_MVP); shgroup->normalview = GPU_shader_get_builtin_uniform(shader, GPU_UNIFORM_NORMAL); - shgroup->normalworld = GPU_shader_get_builtin_uniform(shader, GPU_UNIFORM_WORLDNORMAL); shgroup->orcotexfac = GPU_shader_get_builtin_uniform(shader, GPU_UNIFORM_ORCO); shgroup->objectinfo = GPU_shader_get_builtin_uniform(shader, GPU_UNIFORM_OBJECT_INFO); shgroup->callid = GPU_shader_get_builtin_uniform(shader, GPU_UNIFORM_CALLID); @@ -859,9 +858,6 @@ static void drw_shgroup_init(DRWShadingGroup *shgroup, GPUShader *shader) if (shgroup->normalview > -1) { shgroup->matflag |= DRW_CALL_NORMALVIEW; } - if (shgroup->normalworld > -1) { - shgroup->matflag |= DRW_CALL_NORMALWORLD; - } if (shgroup->orcotexfac > -1) { shgroup->matflag |= DRW_CALL_ORCOTEXFAC; } diff --git a/source/blender/draw/intern/draw_manager_exec.c b/source/blender/draw/intern/draw_manager_exec.c index f98c2cb1025..51ec38088c3 100644 --- a/source/blender/draw/intern/draw_manager_exec.c +++ b/source/blender/draw/intern/draw_manager_exec.c @@ -806,13 +806,6 @@ static void draw_matrices_model_prepare(DRWCallState *st) invert_m3(st->normalview); transpose_m3(st->normalview); } - /* Non view dependent */ - if (st->matflag & DRW_CALL_NORMALWORLD) { - copy_m3_m4(st->normalworld, st->model); - invert_m3(st->normalworld); - transpose_m3(st->normalworld); - st->matflag &= ~DRW_CALL_NORMALWORLD; - } } static void draw_geometry_prepare(DRWShadingGroup *shgroup, DRWCall *call) @@ -847,10 +840,6 @@ static void draw_geometry_prepare(DRWShadingGroup *shgroup, DRWCall *call) GPU_shader_uniform_vector( shgroup->shader, shgroup->normalview, 9, 1, (float *)state->normalview); } - if (shgroup->normalworld != -1) { - GPU_shader_uniform_vector( - shgroup->shader, shgroup->normalworld, 9, 1, (float *)state->normalworld); - } if (shgroup->objectinfo != -1) { float objectinfo[4]; objectinfo[0] = state->objectinfo[0]; @@ -865,7 +854,7 @@ static void draw_geometry_prepare(DRWShadingGroup *shgroup, DRWCall *call) } } else { - BLI_assert((shgroup->normalview == -1) && (shgroup->normalworld == -1)); + BLI_assert((shgroup->normalview == -1)); /* For instancing and batching. */ float unitmat[4][4]; unit_m4(unitmat); diff --git a/source/blender/draw/modes/shaders/common_view_lib.glsl b/source/blender/draw/modes/shaders/common_view_lib.glsl index 25aa8e19474..50d6760cafa 100644 --- a/source/blender/draw/modes/shaders/common_view_lib.glsl +++ b/source/blender/draw/modes/shaders/common_view_lib.glsl @@ -17,5 +17,8 @@ layout(std140) uniform viewBlock /* Transform shortcuts. */ #define transform_normal_object_to_world(nor) (transpose(mat3(ModelMatrixInverse)) * nor) #define transform_normal_world_to_object(nor) (transpose(mat3(ModelMatrix)) * nor) +#define transform_normal_world_to_view(nor) (transpose(mat3(ViewMatrixInverse)) * nor) +#define transform_normal_object_to_view(nor) \ + (transpose(mat3(ViewMatrixInverse)) * (transpose(mat3(ModelMatrixInverse)) * nor)) #define transform_point_view_to_object(point) \ ((ModelMatrixInverse * (ViewMatrixInverse * vec4(point, 1.0))).xyz) |