Cleanup: DRW: Move ModelMatrix declaration to common_view_lib

This commit is contained in:
Clément Foucault 2019-05-14 00:48:17 +02:00
parent 016fc7f0c2
commit 20421ef952
42 changed files with 56 additions and 134 deletions

View File

@ -1,9 +1,4 @@
#ifndef USE_ATTR
uniform mat4 ModelMatrix;
uniform mat4 ModelMatrixInverse;
#endif
#ifndef HAIR_SHADER
in vec3 pos;
in vec3 nor;

View File

@ -1,7 +1,4 @@
uniform mat4 ModelMatrix;
uniform mat4 ModelMatrixInverse;
#ifdef CLIP_PLANES
/* keep in sync with DRWManager.view_data */
layout(std140) uniform clip_block

View File

@ -1,8 +1,4 @@
#ifndef USE_ATTR
uniform mat4 ModelMatrix;
#endif
in vec3 pos;
in vec3 nor;

View File

@ -1,4 +1,3 @@
uniform mat4 ModelMatrix;
in vec3 pos;
in vec4 color;

View File

@ -1,4 +1,3 @@
uniform mat4 ModelMatrix;
in vec3 pos;
in vec4 color;

View File

@ -1,6 +1,4 @@
uniform mat4 ModelMatrix;
uniform float pixsize; /* rv3d->pixsize */
uniform int keep_size;
uniform float objscale;

View File

@ -1,4 +1,3 @@
uniform mat4 ModelMatrix;
uniform float pixsize; /* rv3d->pixsize */
uniform int keep_size;

View File

@ -1,5 +1,3 @@
uniform mat4 ModelMatrix;
uniform mat4 ModelMatrixInverse;
#ifndef HAIR_SHADER
in vec3 pos;

View File

@ -1,7 +1,5 @@
#define INFINITE 1000.0
uniform mat4 ModelMatrix;
uniform vec3 lightDirection = vec3(0.57, 0.57, -0.57);
uniform float lightDistance = 1e4;

View File

@ -1,7 +1,4 @@
uniform mat4 ModelMatrix;
uniform mat4 ModelMatrixInverse;
uniform vec3 OrcoTexCoFactors[2];
uniform sampler2D depthBuffer;

View File

@ -1,6 +1,4 @@
uniform mat4 ModelMatrix;
uniform vec3 OrcoTexCoFactors[2];
uniform float slicePosition;
uniform int sliceAxis; /* -1 is no slice, 0 is X, 1 is Y, 2 is Z. */

View File

@ -1,9 +1,7 @@
uniform mat4 ViewProjectionMatrix;
uniform vec3 screenVecs[3];
#ifdef USE_WORLD_CLIP_PLANES
uniform mat4 ModelMatrix;
#endif
/* ---- Instantiated Attrs ---- */
in float axis; /* position on the axis. [0.0-1.0] is X axis, [1.0-2.0] is Y, etc... */
in vec2 screenPos;
@ -32,6 +30,6 @@ void main()
finalColor.a = 1.0;
#ifdef USE_WORLD_CLIP_PLANES
world_clip_planes_calc_clip_distance((ModelMatrix * pos_4d).xyz);
world_clip_planes_calc_clip_distance(pos_4d.xyz);
#endif
}

View File

@ -3,9 +3,6 @@ uniform mat4 ViewMatrix;
uniform mat4 ViewMatrixInverse;
uniform mat4 ViewProjectionMatrix;
uniform mat4 ProjectionMatrix;
#ifdef USE_WORLD_CLIP_PLANES
uniform mat4 ModelMatrix;
#endif
uniform vec2 viewportSize;
uniform float lineThickness = 2.0;
@ -145,7 +142,7 @@ void main()
vec4 pos_4d = vec4(wpos1, 1.0);
#ifdef USE_WORLD_CLIP_PLANES
world_clip_planes_calc_clip_distance((ModelMatrix * pos_4d).xyz);
world_clip_planes_calc_clip_distance(pos_4d.xyz);
#endif
vec4 V = ViewMatrix * pos_4d;

View File

@ -2,9 +2,6 @@
uniform mat4 ViewMatrix;
uniform mat4 ViewMatrixInverse;
uniform mat4 ViewProjectionMatrix;
#ifdef USE_WORLD_CLIP_PLANES
uniform mat4 ModelMatrix;
#endif
/* ---- Instantiated Attrs ---- */
in vec3 pos;
@ -57,6 +54,6 @@ void main()
vec4 pos_4d = vec4(sp, 1.0);
gl_Position = ViewProjectionMatrix * pos_4d;
#ifdef USE_WORLD_CLIP_PLANES
world_clip_planes_calc_clip_distance((ModelMatrix * pos_4d).xyz);
world_clip_planes_calc_clip_distance(pos_4d.xyz);
#endif
}

View File

@ -1,7 +1,7 @@
uniform mat4 ProjectionMatrix;
uniform mat4 ViewProjectionMatrix;
uniform mat4 ModelMatrix;
uniform mat4 ViewMatrix;
uniform vec2 viewportSize;
@ -88,8 +88,7 @@ void main()
gl_Position.z += (is_bone) ? 0.0 : 1e-6; /* Avoid Z fighting of head/tails. */
#ifdef USE_WORLD_CLIP_PLANES
world_clip_planes_calc_clip_distance(
(ModelMatrix * (is_head ? boneStart_4d : boneEnd_4d)).xyz);
world_clip_planes_calc_clip_distance((is_head ? boneStart_4d : boneEnd_4d).xyz);
#endif
}
else {

View File

@ -14,23 +14,26 @@ layout(std140) uniform viewBlock
vec4 clipPlanes[2];
};
/** Transform shortcuts. */
/* Rule of thumb: Try to reuse world positions and normals because converting though viewspace
* will always be decomposed in at least 2 matrix operation. */
uniform mat4 ModelMatrix;
uniform mat4 ModelMatrixInverse;
/**
* Some clarification:
* Usually Normal matrix is transpose(inverse(ViewMatrix * ModelMatrix))
*
* But since it is slow to multiply matrices we decompose it. Decomposing
* inversion and transposition both invert the product order leaving us with
* the same original order:
* transpose(ViewMatrixInverse) * transpose(ModelMatrixInverse)
*
* Knowing that the view matrix is orthogonal, the transpose is also the inverse.
* Note: This is only valid because we are only using the mat3 of the ViewMatrixInverse.
* ViewMatrix * transpose(ModelMatrixInverse)
**/
/** Transform shortcuts. */
/* Rule of thumb: Try to reuse world positions and normals because converting though viewspace
* will always be decomposed in at least 2 matrix operation. */
/**
* Some clarification:
* Usually Normal matrix is transpose(inverse(ViewMatrix * ModelMatrix))
*
* But since it is slow to multiply matrices we decompose it. Decomposing
* inversion and transposition both invert the product order leaving us with
* the same original order:
* transpose(ViewMatrixInverse) * transpose(ModelMatrixInverse)
*
* Knowing that the view matrix is orthogonal, the transpose is also the inverse.
* Note: This is only valid because we are only using the mat3 of the ViewMatrixInverse.
* ViewMatrix * transpose(ModelMatrixInverse)
**/
#define normal_object_to_view(n) (mat3(ViewMatrix) * (transpose(mat3(ModelMatrixInverse)) * n))
#define normal_object_to_world(n) (transpose(mat3(ModelMatrixInverse)) * n)
#define normal_world_to_object(n) (transpose(mat3(ModelMatrix)) * n)

View File

@ -1,5 +1,4 @@
/* Draw Curve Handles */
uniform mat4 ModelMatrix;
in vec3 pos;
in int data;

View File

@ -1,5 +1,4 @@
/* Draw Curve Vertices */
uniform mat4 ModelMatrix;
uniform vec2 viewportSize;

View File

@ -1,5 +1,4 @@
/* Draw Curve Normals */
uniform mat4 ModelMatrix;
uniform float normalSize;

View File

@ -1,8 +1,5 @@
/* Draw Lattice Vertices */
uniform mat4 ModelMatrix;
uniform vec2 viewportSize;
in vec3 pos;

View File

@ -1,6 +1,4 @@
uniform mat4 ModelMatrix;
uniform ivec4 dataMask = ivec4(0xFF);
in vec3 pos;

View File

@ -1,4 +1,3 @@
uniform mat4 ModelMatrix;
in vec3 pos;
in vec4 weight_color;

View File

@ -1,7 +1,4 @@
uniform mat4 ModelMatrix;
uniform mat4 ModelMatrixInverse;
uniform float faceAlphaMod;
uniform ivec4 dataMask = ivec4(0xFF);
uniform float ofs;

View File

@ -1,7 +1,4 @@
uniform mat4 ModelMatrix;
uniform mat4 ModelMatrixInverse;
uniform float normalSize;
in vec3 pos;

View File

@ -1,8 +1,5 @@
uniform mat4 ViewProjectionMatrix;
#ifdef USE_WORLD_CLIP_PLANES
uniform mat4 ModelMatrix;
#endif
uniform vec3 screenVecs[3];
@ -33,6 +30,6 @@ void main()
finalColor = vec4(color, 1.0);
#ifdef USE_WORLD_CLIP_PLANES
world_clip_planes_calc_clip_distance((ModelMatrix * pos_4d).xyz);
world_clip_planes_calc_clip_distance(pos_4d.xyz);
#endif
}

View File

@ -1,4 +1,3 @@
uniform mat4 ModelMatrix;
uniform vec2 aspect;
uniform float size;

View File

@ -4,7 +4,6 @@
* Note that if the stiffness is zero, it assumes the scale is directly multiplied by the radius */
uniform mat4 ViewProjectionMatrix;
uniform mat4 ModelMatrix;
uniform vec3 screen_vecs[2];
/* ---- Instantiated Attrs ---- */
@ -32,6 +31,6 @@ void main()
finalColor = vec4(color, 1.0);
#ifdef USE_WORLD_CLIP_PLANES
world_clip_planes_calc_clip_distance((ModelMatrix * world_pos).xyz);
world_clip_planes_calc_clip_distance(world_pos.xyz);
#endif
}

View File

@ -1,6 +1,4 @@
uniform mat4 ModelMatrix;
in vec3 pos;
out vec4 pPos;

View File

@ -1,6 +1,4 @@
uniform mat4 ModelMatrix;
uniform float pixel_size;
uniform float size;

View File

@ -1,6 +1,4 @@
uniform mat4 ModelMatrix;
uniform bool screen_space;
uniform float draw_size;
uniform vec3 color;

View File

@ -1,4 +1,3 @@
uniform mat4 ModelMatrix;
in vec3 pos;

View File

@ -1,7 +1,4 @@
uniform mat4 ModelMatrix;
uniform mat4 ModelMatrixInverse;
uniform float wireStepParam;
uniform float ofs;

View File

@ -1,6 +1,4 @@
uniform mat4 ModelMatrix;
in vec3 pos;
in vec4 nor; /* select flag on the 4th component */

View File

@ -1,6 +1,4 @@
uniform mat4 ModelMatrix;
in vec2 u; /* active uv map */
in vec3 pos;

View File

@ -1,6 +1,4 @@
uniform mat4 ModelMatrix;
in vec3 pos;
in vec3 c; /* active color */

View File

@ -1,6 +1,4 @@
uniform mat4 ModelMatrix;
in float weight;
in vec3 pos;

View File

@ -1,6 +1,4 @@
uniform mat4 ModelMatrix;
in vec3 pos;
in vec4 nor; /* flag stored in w */

View File

@ -1,6 +1,4 @@
uniform mat4 ModelMatrix;
in vec3 pos;
in float color;

View File

@ -1,6 +1,4 @@
uniform mat4 ModelMatrix;
uniform float maskOpacity;
in vec3 pos;

View File

@ -1,6 +1,4 @@
uniform mat4 ModelMatrix;
uniform sampler3D velocityX;
uniform sampler3D velocityY;
uniform sampler3D velocityZ;

View File

@ -1035,12 +1035,39 @@ static char *code_generate_vertex(ListBase *nodes, const char *vert_code, bool u
BLI_dynstr_append(ds, "out vec3 barycentricPosg;\n");
}
BLI_dynstr_append(ds, "\n#define USE_ATTR\n");
/* Prototype, defined later (this is because of matrices definition). */
BLI_dynstr_append(ds, "void pass_attr(in vec3 position);\n");
BLI_dynstr_append(ds, "\n");
if (use_geom) {
/* XXX HACK: Eevee specific. */
char *vert_new, *vert_new2;
vert_new = BLI_str_replaceN(vert_code, "worldPosition", "worldPositiong");
vert_new2 = vert_new;
vert_new = BLI_str_replaceN(vert_new2, "viewPosition", "viewPositiong");
MEM_freeN(vert_new2);
vert_new2 = vert_new;
vert_new = BLI_str_replaceN(vert_new2, "worldNormal", "worldNormalg");
MEM_freeN(vert_new2);
vert_new2 = vert_new;
vert_new = BLI_str_replaceN(vert_new2, "viewNormal", "viewNormalg");
MEM_freeN(vert_new2);
BLI_dynstr_append(ds, vert_new);
MEM_freeN(vert_new);
}
else {
BLI_dynstr_append(ds, vert_code);
}
BLI_dynstr_append(ds, "\n");
BLI_dynstr_append(ds,
"#define USE_ATTR\n"
"uniform mat4 ModelMatrixInverse;\n"
"uniform mat4 ModelMatrix;\n"
"vec3 srgb_to_linear_attr(vec3 c) {\n"
"\tc = max(c, vec3(0.0));\n"
"\tvec3 c1 = c * (1.0 / 12.92);\n"
@ -1177,28 +1204,6 @@ static char *code_generate_vertex(ListBase *nodes, const char *vert_code, bool u
BLI_dynstr_append(ds, "}\n");
if (use_geom) {
/* XXX HACK: Eevee specific. */
char *vert_new, *vert_new2;
vert_new = BLI_str_replaceN(vert_code, "worldPosition", "worldPositiong");
vert_new2 = vert_new;
vert_new = BLI_str_replaceN(vert_new2, "viewPosition", "viewPositiong");
MEM_freeN(vert_new2);
vert_new2 = vert_new;
vert_new = BLI_str_replaceN(vert_new2, "worldNormal", "worldNormalg");
MEM_freeN(vert_new2);
vert_new2 = vert_new;
vert_new = BLI_str_replaceN(vert_new2, "viewNormal", "viewNormalg");
MEM_freeN(vert_new2);
BLI_dynstr_append(ds, vert_new);
MEM_freeN(vert_new);
}
else {
BLI_dynstr_append(ds, vert_code);
}
code = BLI_dynstr_get_cstring(ds);
BLI_dynstr_free(ds);

View File

@ -1,9 +1,4 @@
#ifndef USE_ATTR
uniform mat4 ModelMatrix;
uniform mat4 ModelMatrixInverse;
#endif
/* Converters */
float convert_rgba_to_float(vec4 color)