Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorClément Foucault <foucault.clem@gmail.com>2019-05-09 00:23:31 +0300
committerClément Foucault <foucault.clem@gmail.com>2019-05-09 00:28:07 +0300
commit9489fea07b61c83a429b61de887b692dffb6a4f4 (patch)
tree6df48cba007743aebb81fb98bda0f18245a8cc5a /source/blender/gpu
parent7ec7888ff384adccfaca2777c021b40dd726fa8d (diff)
GPU: Refactor some shader for a bit more efficiency
Remove matrices multiplication and use more correct codestyle for variables
Diffstat (limited to 'source/blender/gpu')
-rw-r--r--source/blender/gpu/shaders/gpu_shader_instance_edges_variying_color_vert.glsl10
-rw-r--r--source/blender/gpu/shaders/gpu_shader_instance_objectspace_variying_color_vert.glsl13
2 files changed, 11 insertions, 12 deletions
diff --git a/source/blender/gpu/shaders/gpu_shader_instance_edges_variying_color_vert.glsl b/source/blender/gpu/shaders/gpu_shader_instance_edges_variying_color_vert.glsl
index d9e73f81c45..b4a6b0de33f 100644
--- a/source/blender/gpu/shaders/gpu_shader_instance_edges_variying_color_vert.glsl
+++ b/source/blender/gpu/shaders/gpu_shader_instance_edges_variying_color_vert.glsl
@@ -26,9 +26,9 @@ out vec3 fCol;
// TODO: in float angle; // [-pi .. +pi], + peak, 0 flat, - valley
-bool front(mat3 NormalMatrix, vec3 N, vec3 eye)
+bool front(mat3 normal_matrix, vec3 N, vec3 eye)
{
- return dot(NormalMatrix * N, eye) > 0.0;
+ return dot(normal_matrix * N, eye) > 0.0;
}
void main()
@@ -40,7 +40,7 @@ void main()
vec4 pos_4d = vec4(pos, 1.0);
MV_pos = ModelViewMatrix * pos_4d;
- mat3 NormalMatrix = transpose(inverse(mat3(ModelViewMatrix)));
+ mat3 normal_matrix = transpose(inverse(mat3(ModelViewMatrix)));
/* if persp */
if (ProjectionMatrix[3][3] == 0.0) {
@@ -50,8 +50,8 @@ void main()
eye = vec3(0.0, 0.0, 1.0);
}
- bool face_1_front = front(NormalMatrix, N1, eye);
- bool face_2_front = front(NormalMatrix, N2, eye);
+ bool face_1_front = front(normal_matrix, N1, eye);
+ bool face_2_front = front(normal_matrix, N2, eye);
if (face_1_front && face_2_front)
edgeClass = 1.0; // front-facing edge
diff --git a/source/blender/gpu/shaders/gpu_shader_instance_objectspace_variying_color_vert.glsl b/source/blender/gpu/shaders/gpu_shader_instance_objectspace_variying_color_vert.glsl
index 9b1a08d8d86..5b3922d7a72 100644
--- a/source/blender/gpu/shaders/gpu_shader_instance_objectspace_variying_color_vert.glsl
+++ b/source/blender/gpu/shaders/gpu_shader_instance_objectspace_variying_color_vert.glsl
@@ -1,5 +1,5 @@
-uniform mat4 ViewMatrix;
+uniform mat4 ViewMatrixInverse;
uniform mat4 ViewProjectionMatrix;
/* ---- Instantiated Attrs ---- */
@@ -15,13 +15,12 @@ flat out vec4 finalColor;
void main()
{
- mat4 ModelViewProjectionMatrix = ViewProjectionMatrix * InstanceModelMatrix;
- /* This is slow and run per vertex, but it's still faster than
- * doing it per instance on CPU and sending it on via instance attr. */
- mat3 NormalMatrix = transpose(inverse(mat3(ViewMatrix * InstanceModelMatrix)));
+ gl_Position = ViewProjectionMatrix * (InstanceModelMatrix * vec4(pos, 1.0));
- gl_Position = ModelViewProjectionMatrix * vec4(pos, 1.0);
- normal = NormalMatrix * nor;
+ /* This is slow and run per vertex, but it's still faster than
+ * doing it per instance on CPU and sending it on via instance attribute. */
+ mat3 normal_mat = transpose(inverse(mat3(InstanceModelMatrix)));
+ normal = normalize((transpose(mat3(ViewMatrixInverse)) * (normal_mat * nor)));
finalColor = color;
}