diff options
author | Clément Foucault <foucault.clem@gmail.com> | 2018-12-03 02:36:54 +0300 |
---|---|---|
committer | Clément Foucault <foucault.clem@gmail.com> | 2018-12-03 19:19:11 +0300 |
commit | 24fd03d0c2fc5f49bc3813afce7ac5d67fc762bd (patch) | |
tree | 4af65d73762c28ce003d425cb288d66bec226a3d /source/blender/draw/engines/workbench/shaders/workbench_prepass_frag.glsl | |
parent | 17a4323ef59570975b254da9936fde16969b1df0 (diff) |
Workbench: Reduce VRAM usage depending on mode
We exploit the fact that we are using the metallic workflow for material
and pass the metallic parameter instead of the specular color.
Pack the front facing bit in the color buffer only for matcap display.
Change buffer formats to use less bytes as possible.
Also don't request buffers that we won't use.
Saved 40MB on 2K screen on StudioLight + Shadows + Specular Lighting.
Includes several cleanups.
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.glsl | 46 |
1 files changed, 21 insertions, 25 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 5f622b00bca..ee968c4eb02 100644 --- a/source/blender/draw/engines/workbench/shaders/workbench_prepass_frag.glsl +++ b/source/blender/draw/engines/workbench/shaders/workbench_prepass_frag.glsl @@ -1,7 +1,7 @@ uniform int object_id = 0; -uniform vec4 materialDiffuseColor; -uniform vec4 materialSpecularColor; +uniform vec3 materialDiffuseColor; +uniform float materialMetallic; uniform float materialRoughness; #ifdef V3D_SHADING_TEXTURE_COLOR @@ -23,9 +23,9 @@ flat in float hair_rand; #endif layout(location=0) out uint objectId; -layout(location=1) out vec4 diffuseColor; +layout(location=1) out vec4 colorRoughness; #ifdef V3D_SHADING_SPECULAR_HIGHLIGHT -layout(location=2) out vec4 specularColor; +layout(location=2) out float metallic; #endif #ifdef NORMAL_VIEWPORT_PASS_ENABLED # ifdef WORKBENCH_ENCODE_NORMALS @@ -39,41 +39,37 @@ void main() { objectId = uint(object_id); -#ifdef NORMAL_VIEWPORT_PASS_ENABLED - vec3 n = (gl_FrontFacing) ? normal_viewport : -normal_viewport; - n = normalize(n); -#endif - #ifdef V3D_SHADING_TEXTURE_COLOR - diffuseColor = texture(image, uv_interp); - if (diffuseColor.a < ImageTransparencyCutoff) { + colorRoughness = texture(image, uv_interp); + if (colorRoughness.a < ImageTransparencyCutoff) { discard; } + colorRoughness.a = materialRoughness; #else - diffuseColor = vec4(materialDiffuseColor.rgb, 0.0); + colorRoughness = vec4(materialDiffuseColor, materialRoughness); #endif /* V3D_SHADING_TEXTURE_COLOR */ +#ifdef V3D_LIGHTING_MATCAP + /* Encode front facing in color alpha. */ + colorRoughness.a = float(gl_FrontFacing); +#endif + #ifdef HAIR_SHADER float hair_color_variation = hair_rand * 0.1; - diffuseColor.rgb = clamp(diffuseColor.rgb - hair_color_variation, 0.0, 1.0); + colorRoughness = clamp(colorRoughness - hair_color_variation, 0.0, 1.0); #endif #ifdef V3D_SHADING_SPECULAR_HIGHLIGHT - specularColor = vec4(materialSpecularColor.rgb, materialRoughness); # ifdef HAIR_SHADER - specularColor.rgb = clamp(specularColor.rgb - hair_color_variation, 0.0, 1.0); + metallic = clamp(materialMetallic - hair_color_variation, 0.0, 1.0); +# else + metallic = materialMetallic; # endif #endif #ifdef NORMAL_VIEWPORT_PASS_ENABLED -# ifdef WORKBENCH_ENCODE_NORMALS - diffuseColor.a = float(gl_FrontFacing); - normalViewport = normal_encode(n); -# else /* WORKBENCH_ENCODE_NORMALS */ - normalViewport = n; -# endif /* WORKBENCH_ENCODE_NORMALS */ -# ifdef HAIR_SHADER - diffuseColor.a = 0.5; -# endif -#endif /* NORMAL_VIEWPORT_PASS_ENABLED */ + vec3 n = (gl_FrontFacing) ? normal_viewport : -normal_viewport; + n = normalize(n); + normalViewport = workbench_normal_encode(n); +#endif } |