DRW: Remove WorldNormalMatrix

This commit is contained in:
Clément Foucault 2019-05-08 20:13:24 +02:00
parent bb41626ab3
commit f2f62b184c
Notes: blender-bot 2023-02-14 09:38:57 +01:00
Referenced by issue #64284, Mirroed Collection Intances have flipped normals/face orientation.
9 changed files with 13 additions and 31 deletions

View File

@ -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 */

View File

@ -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

View File

@ -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;

View File

@ -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;
}

View File

@ -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);

View File

@ -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)

View File

@ -45,7 +45,6 @@ typedef enum {
GPU_UNIFORM_VIEWPROJECTION_INV, /* mat4 ViewProjectionMatrixInverse */
GPU_UNIFORM_NORMAL, /* mat3 NormalMatrix */
GPU_UNIFORM_WORLDNORMAL, /* mat3 WorldNormalMatrix */
GPU_UNIFORM_CAMERATEXCO, /* vec4 CameraTexCoFactors */
GPU_UNIFORM_ORCO, /* vec3 OrcoTexCoFactors[] */

View File

@ -61,7 +61,6 @@ static const char *BuiltinUniform_name(GPUUniformBuiltin u)
[GPU_UNIFORM_VIEWPROJECTION_INV] = "ViewProjectionMatrixInverse",
[GPU_UNIFORM_NORMAL] = "NormalMatrix",
[GPU_UNIFORM_WORLDNORMAL] = "WorldNormalMatrix",
[GPU_UNIFORM_CAMERATEXCO] = "CameraTexCoFactors",
[GPU_UNIFORM_ORCO] = "OrcoTexCoFactors",

View File

@ -1,7 +1,6 @@
uniform mat4 ModelViewMatrix;
uniform mat4 ModelViewMatrixInverse;
uniform mat3 NormalMatrix;
#ifndef USE_ATTR
uniform mat4 ModelMatrix;