MatCap inverts if Viewport Display Metallic and Roughness are set below certain threshold #75938

Closed
opened 2020-04-20 17:11:27 +02:00 by Marc Zbinden · 8 comments

System Information
Operating system: Windows-10-10.0.18362-SP0 64 Bits
Graphics card: GeForce RTX 2080 Ti/PCIe/SSE2 NVIDIA Corporation 4.5.0 NVIDIA 445.87

Blender Version
Broken: version: 2.83 (sub 13), branch: master, commit date: 2020-04-20 02:11, hash: 23bb42a06e
Worked: 2.82a

Short description of error
MatCap inverts if Viewport Display Metallic and Roughness are set below certain threshold.

Exact steps for others to reproduce the error
Change Viewport Shading to MatCap, select Cube, go to Material Properties to Viewport Display, set Metallic and Roughness to 0. Metallic can be as low as 0.144.

**System Information** Operating system: Windows-10-10.0.18362-SP0 64 Bits Graphics card: GeForce RTX 2080 Ti/PCIe/SSE2 NVIDIA Corporation 4.5.0 NVIDIA 445.87 **Blender Version** Broken: version: 2.83 (sub 13), branch: master, commit date: 2020-04-20 02:11, hash: `23bb42a06e` Worked: 2.82a **Short description of error** MatCap inverts if Viewport Display Metallic and Roughness are set below certain threshold. **Exact steps for others to reproduce the error** Change Viewport Shading to MatCap, select Cube, go to Material Properties to Viewport Display, set Metallic and Roughness to 0. Metallic can be as low as 0.144.
Author

Added subscriber: @MarcZbinden

Added subscriber: @MarcZbinden
Robert Guetzkow self-assigned this 2020-04-20 21:02:52 +02:00

Changed status from 'Needs Triage' to: 'Confirmed'

Changed status from 'Needs Triage' to: 'Confirmed'

Added subscriber: @fclem

Added subscriber: @fclem

The issue is the following part of the workbench_composite_frag.glsl

#ifdef V3D_LIGHTING_MATCAP
  /* When using matcaps, mat_data.a is the backface sign. */
  N = (mat_data.a > 0.0) ? N : -N;

  fragColor.rgb = get_matcap_lighting(base_color, N, I);
#endif

It changes the normal direction based on the data stored in the alpha channel. This appears to be incorrect for two reasons:

If the N = (mat_data.a > 0.0) ? N : -N; is indeed redundant, then it could simply be removed along with the materialData.a = float(gl_FrontFacing);. If it isn't redundant, then if (useMatcap) should be replaced with a check that is always true when matcaps are used. This means either a different check/macro or useMatcap needs to be set to true for more cases than just hair the current shading groups.

@fclem Could you take a quick look and tell me which approach you would prefer?

The issue is the following part of the [workbench_composite_frag.glsl ](https://developer.blender.org/diffusion/B/browse/master/source/blender/draw/engines/workbench/shaders/workbench_composite_frag.glsl) ``` #ifdef V3D_LIGHTING_MATCAP /* When using matcaps, mat_data.a is the backface sign. */ N = (mat_data.a > 0.0) ? N : -N; fragColor.rgb = get_matcap_lighting(base_color, N, I); #endif ``` It changes the normal direction based on the data stored in the alpha channel. This appears to be incorrect for two reasons: - In [workbench_prepass_frag.glsl ]] the `materialData.a = float(gl_FrontFacing);` is only set if `useMatcap` is true. Despite its name, the variable is not always set to true when matcaps are used. It is only set to true for ~~hair~~ certain shading groups in `workbench_opaque_cache_init` ([[ https:*developer.blender.org/diffusion/B/browse/master/source/blender/draw/engines/workbench/workbench_opaque.c | workbench_opaque.c ](https:*developer.blender.org/diffusion/B/browse/master/source/blender/draw/engines/workbench/shaders/workbench_prepass_frag.glsl)). As a result the alpha channel instead contains the `packed_rough_metal`, which is why the values for roughness and metal impact the direction of the normal. - In [workbench_prepass_frag.glsl ]] the `workbench_normal_encode(gl_FrontFacing, normal_interp)` already includes backface/frontface information (see [[ https:*developer.blender.org/diffusion/B/browse/master/source/blender/draw/engines/workbench/shaders/workbench_common_lib.glsl | workbench_common_lib.glsl ]]). If I'm not mistaken that makes the (potential) normal inversion in the [[ https://developer.blender.org/diffusion/B/browse/master/source/blender/draw/engines/workbench/shaders/workbench_composite_frag.glsl | workbench_composite_frag.glsl ](https:*developer.blender.org/diffusion/B/browse/master/source/blender/draw/engines/workbench/shaders/workbench_prepass_frag.glsl) redundant. If the `N = (mat_data.a > 0.0) ? N : -N;` is indeed redundant, then it could simply be removed along with the `materialData.a = float(gl_FrontFacing);`. If it isn't redundant, then `if (useMatcap)` should be replaced with a check that is always true when matcaps are used. This means either a different check/macro or `useMatcap` needs to be set to true for more cases than just ~~hair~~ the current shading groups. @fclem Could you take a quick look and tell me which approach you would prefer?

We used the double inversion because users asked for it. It is indeed a strange thing but it's by design.

I think it's just a matter of adding DRW_shgroup_uniform_bool_copy(grp, "useMatcap", use_matcap);somewhere.

We used the double inversion because users asked for it. It is indeed a strange thing but it's by design. I think it's just a matter of adding ` DRW_shgroup_uniform_bool_copy(grp, "useMatcap", use_matcap);`somewhere.

@fclem Good to know. I will set useMatcap in the patch then.

@fclem Good to know. I will set `useMatcap` in the patch then.

This issue was referenced by 0dfe30502a

This issue was referenced by 0dfe30502a02c0567be50f980a8f1e00198cf93e

Changed status from 'Confirmed' to: 'Resolved'

Changed status from 'Confirmed' to: 'Resolved'
Sign in to join this conversation.
No Label
Interest
Alembic
Interest
Animation & Rigging
Interest
Asset Browser
Interest
Asset Browser Project Overview
Interest
Audio
Interest
Automated Testing
Interest
Blender Asset Bundle
Interest
BlendFile
Interest
Collada
Interest
Compatibility
Interest
Compositing
Interest
Core
Interest
Cycles
Interest
Dependency Graph
Interest
Development Management
Interest
EEVEE
Interest
EEVEE & Viewport
Interest
Freestyle
Interest
Geometry Nodes
Interest
Grease Pencil
Interest
ID Management
Interest
Images & Movies
Interest
Import Export
Interest
Line Art
Interest
Masking
Interest
Metal
Interest
Modeling
Interest
Modifiers
Interest
Motion Tracking
Interest
Nodes & Physics
Interest
OpenGL
Interest
Overlay
Interest
Overrides
Interest
Performance
Interest
Physics
Interest
Pipeline, Assets & IO
Interest
Platforms, Builds & Tests
Interest
Python API
Interest
Render & Cycles
Interest
Render Pipeline
Interest
Sculpt, Paint & Texture
Interest
Text Editor
Interest
Translations
Interest
Triaging
Interest
Undo
Interest
USD
Interest
User Interface
Interest
UV Editing
Interest
VFX & Video
Interest
Video Sequencer
Interest
Virtual Reality
Interest
Vulkan
Interest
Wayland
Interest
Workbench
Interest: X11
Legacy
Blender 2.8 Project
Legacy
Milestone 1: Basic, Local Asset Browser
Legacy
OpenGL Error
Meta
Good First Issue
Meta
Papercut
Meta
Retrospective
Meta
Security
Module
Animation & Rigging
Module
Core
Module
Development Management
Module
EEVEE & Viewport
Module
Grease Pencil
Module
Modeling
Module
Nodes & Physics
Module
Pipeline, Assets & IO
Module
Platforms, Builds & Tests
Module
Python API
Module
Render & Cycles
Module
Sculpt, Paint & Texture
Module
Triaging
Module
User Interface
Module
VFX & Video
Platform
FreeBSD
Platform
Linux
Platform
macOS
Platform
Windows
Priority
High
Priority
Low
Priority
Normal
Priority
Unbreak Now!
Status
Archived
Status
Confirmed
Status
Duplicate
Status
Needs Info from Developers
Status
Needs Information from User
Status
Needs Triage
Status
Resolved
Type
Bug
Type
Design
Type
Known Issue
Type
Patch
Type
Report
Type
To Do
No Milestone
No project
No Assignees
4 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: blender/blender#75938
No description provided.