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>2018-12-05 04:07:23 +0300
committerClément Foucault <foucault.clem@gmail.com>2018-12-05 04:51:48 +0300
commit7ffde286be0774e24ea04b4acaad6c6e4ae16bfe (patch)
tree2c4a3891df3438b24480651f157e07632f9cf15f /source/blender/draw/engines/workbench/shaders/workbench_prepass_frag.glsl
parent53685404316e05879bc9ff46837dd224ba3cce4f (diff)
Workbench: Cleanups and reduce shader variations
Also optimize deferred engine by only outputing material data if needed. This make the bare flat shading mode (no effects) only a depth prepass.
Diffstat (limited to 'source/blender/draw/engines/workbench/shaders/workbench_prepass_frag.glsl')
-rw-r--r--source/blender/draw/engines/workbench/shaders/workbench_prepass_frag.glsl77
1 files changed, 39 insertions, 38 deletions
diff --git a/source/blender/draw/engines/workbench/shaders/workbench_prepass_frag.glsl b/source/blender/draw/engines/workbench/shaders/workbench_prepass_frag.glsl
index 93170037c4b..722add22a89 100644
--- a/source/blender/draw/engines/workbench/shaders/workbench_prepass_frag.glsl
+++ b/source/blender/draw/engines/workbench/shaders/workbench_prepass_frag.glsl
@@ -4,69 +4,70 @@ uniform vec3 materialDiffuseColor;
uniform float materialMetallic;
uniform float materialRoughness;
-#ifdef V3D_SHADING_TEXTURE_COLOR
uniform sampler2D image;
uniform float ImageTransparencyCutoff = 0.1;
-#endif
-
#ifdef NORMAL_VIEWPORT_PASS_ENABLED
in vec3 normal_viewport;
-#endif /* NORMAL_VIEWPORT_PASS_ENABLED */
+#endif
#ifdef V3D_SHADING_TEXTURE_COLOR
in vec2 uv_interp;
-#endif /* V3D_SHADING_TEXTURE_COLOR */
+#endif
#ifdef HAIR_SHADER
flat in float hair_rand;
#endif
-layout(location=0) out uint objectId;
-layout(location=1) out vec4 materialData;
+#ifdef MATDATA_PASS_ENABLED
+layout(location=0) out vec4 materialData;
+#endif
+#ifdef OBJECT_ID_PASS_ENABLED
+layout(location=1) out uint objectId;
+#endif
#ifdef NORMAL_VIEWPORT_PASS_ENABLED
-# ifdef WORKBENCH_ENCODE_NORMALS
-layout(location=2) out vec2 normalViewport;
-# else /* WORKBENCH_ENCODE_NORMALS */
-layout(location=2) out vec3 normalViewport;
-# endif /* WORKBENCH_ENCODE_NORMALS */
-#endif /* NORMAL_VIEWPORT_PASS_ENABLED */
+layout(location=2) out WB_Normal normalViewport;
+#endif
void main()
{
- objectId = uint(object_id);
+#ifdef MATDATA_PASS_ENABLED
+ float metallic, roughness;
+ vec4 color;
- vec4 color_roughness;
-#ifdef V3D_SHADING_TEXTURE_COLOR
- color_roughness = texture(image, uv_interp);
- if (color_roughness.a < ImageTransparencyCutoff) {
+# ifdef V3D_SHADING_TEXTURE_COLOR
+ color = texture(image, uv_interp);
+ if (color.a < ImageTransparencyCutoff) {
discard;
}
- color_roughness.a = materialRoughness;
-#else
- color_roughness = vec4(materialDiffuseColor, materialRoughness);
-#endif /* V3D_SHADING_TEXTURE_COLOR */
-
-#ifdef HAIR_SHADER
- float hair_color_variation = hair_rand * 0.1;
- color_roughness = clamp(color_roughness - hair_color_variation, 0.0, 1.0);
-#endif
-
- float metallic;
-#ifdef V3D_SHADING_SPECULAR_HIGHLIGHT
-# ifdef HAIR_SHADER
- metallic = clamp(materialMetallic - hair_color_variation, 0.0, 1.0);
# else
- metallic = materialMetallic;
+ color.rgb = materialDiffuseColor;
# endif
-#elif defined(V3D_LIGHTING_MATCAP)
+
+# ifdef V3D_LIGHTING_MATCAP
/* Encode front facing in metallic channel. */
metallic = float(gl_FrontFacing);
- color_roughness.a = 0.0;
-#endif
+ roughness = 0.0;
+# else
+ metallic = materialMetallic;
+ roughness = materialRoughness;
+# endif
- materialData.rgb = color_roughness.rgb;
- materialData.a = workbench_float_pair_encode(color_roughness.a, metallic);
+# ifdef HAIR_SHADER
+ /* Add some variation to the hairs to avoid uniform look. */
+ float hair_variation = hair_rand * 0.1;
+ color = clamp(color - hair_variation, 0.0, 1.0);
+ metallic = clamp(materialMetallic - hair_variation, 0.0, 1.0);
+ roughness = clamp(materialRoughness - hair_variation, 0.0, 1.0);
+# endif
+
+ materialData.rgb = color.rgb;
+ materialData.a = workbench_float_pair_encode(roughness, metallic);
+#endif /* MATDATA_PASS_ENABLED */
+
+#ifdef OBJECT_ID_PASS_ENABLED
+ objectId = uint(object_id);
+#endif
#ifdef NORMAL_VIEWPORT_PASS_ENABLED
vec3 n = (gl_FrontFacing) ? normal_viewport : -normal_viewport;