Page MenuHome

Allow multiayer matcaps to override cavity shading.
Needs RevisionPublic

Authored by Jean Da Costa (jeacom256) on Mar 1 2020, 3:05 AM.

Details

Summary

Matcaps currently can only override the specular pass.
This patch adds the possibility for matcaps to override the cavity pass colors to allow for more advanced and customizable effects.

The possibilities are endless, apparently its possible to fake SSS/Translucency to certain degree too.

Here are some matcaps I made to test the feature, I had a lot of fun making those.

Diff Detail

Event Timeline

Jean Da Costa (jeacom256) edited the summary of this revision. (Show Details)

That's interesting.
Maybe you should add Jeroen Bakker (jbakker) as a reviewer, since he was the one who implemented that multi-layer matcap system D5335 ? 🤔

That's interesting.
Maybe you should add Jeroen Bakker (jbakker) as a reviewer, since he was the one who implemented that multi-layer matcap system D5335 ? 🤔

Oops, I forgot to add him, I even used this commit as reference.

I've refactored the whole workbench this past week and this would need to be updated. Note that the refactor has not yet been commited but it should be before the end of next week.

The refactor changes how the cavity effect is computed to reduce memory usage. You would have to change the cavity shader directly.

Note that I do like the feature.

Clément Foucault (fclem) requested changes to this revision.Thu, Mar 12, 5:49 PM

The workbench refactor has been merged. Update this patch and I'll review it.

Now that the cavity pass is a separate pass, you need to modify its state to DRW_STATE_BLEND_ALPHA in order to overlay the ridge and valley matcap on top of the render.
The shader is workbench_effect_cavity_frag.glsl.

This revision now requires changes to proceed.Thu, Mar 12, 5:49 PM

@Clément Foucault (fclem)
I'm trying to update the patch, but as soon as I changed the state to DRW_STATE_BLEND_ALPHA, I get this ghosting.

Not sure on whats going on or why it doesn't happen in DRW_STATE_BLEND_MUL.

@Clément Foucault (fclem)
I'm trying to update the patch, but as soon as I changed the state to DRW_STATE_BLEND_ALPHA, I get this ghosting.


Not sure on whats going on or why it doesn't happen in DRW_STATE_BLEND_MUL.

That's because it's missing an early out case in the curvature shader. That's my mistake. i'm going to fix it. in the meantime, test with only with the cavity (world space).

That's because it's missing an early out case in the curvature shader. That's my mistake. i'm going to fix it. in the meantime, test with only with the cavity (world space).

I think I found it, I was already including the check to the curvature shader in my patch, but wasn't sure if it's safe to assume the background would be always zero.

if (texture(objectIdBuffer, uv).r == uint(0)) {
  return;
}

So I should just implement the main feature and leave this for later.

That's because it's missing an early out case in the curvature shader. That's my mistake. i'm going to fix it. in the meantime, test with only with the cavity (world space).

I think I found it, I was already including the check to the curvature shader in my patch, but wasn't sure if it's safe to assume the background would be always zero.

if (texture(objectIdBuffer, uv).r == uint(0)) {
  return;
}

So I should just implement the main feature and leave this for later.

you can include the fix in your patch. also you can use 0u for the test.

Jean Da Costa (jeacom256) updated this revision to Diff 22796.EditedSat, Mar 14, 6:39 PM

Update diff.

The effect is a little better now that it has access to edges and cavities individually.

I made another matcap for testing:


Clément Foucault (fclem) requested changes to this revision.Mon, Mar 16, 12:33 AM

While I do see the usefulness of the valley matcap, the benefit of the ridges matcap is less obvious to me.
@William Reynish (billreynish) @Julien Kaspar (JulienKaspar) do you have any use case in mind?

I'm still not sure about how to mix the cavity matcap with the darkening/lightening of the cavity effect.
Maybe the valley matcap should use the non modified cavity weight, blend with the base matcap THEN we apply the cavity darkening/lightening based on viewport value.

I think we should use another blend mode for all of this. You cannot lighten the render without breaking the alpha channel (alpha > 1). Ideally it would be the same as DRW_STATE_BLEND_ALPHA_PREMUL but without the alpha change.

source/blender/draw/engines/workbench/shaders/workbench_effect_cavity_frag.glsl
31

Do only one shader variation for matcaps. Use a boolean uniforms to set if valley and/or ridges are to be used.

39

I think you should reuse the final_cavity_factor and use that to blend between the cavity and ridge matcap.

final_cavity_factor == 1 > no alpha base matcap
final_cavity_factor == 0 > full alpha valleys matcap
final_cavity_factor == 2 > full alpha ridges matcap

52

Set factor calculation out of the #ifdef to avoid duplicated code and multiline mix.

source/blender/draw/engines/workbench/shaders/workbench_matcap_lib.glsl
4

Dont move this. Just include matcap_lib with
#pragma BLENDER_REQUIRE(workbench_matcap_lib.glsl)

This revision now requires changes to proceed.Mon, Mar 16, 12:33 AM

While I do see the usefulness of the valley matcap, the benefit of the ridges matcap is less obvious to me.
@William Reynish (billreynish) @Julien Kaspar (JulienKaspar) do you have any use case in mind?
I'm still not sure about how to mix the cavity matcap with the darkening/lightening of the cavity effect.
Maybe the valley matcap should use the non modified cavity weight, blend with the base matcap THEN we apply the cavity darkening/lightening based on viewport value.
I think we should use another blend mode for all of this. You cannot lighten the render without breaking the alpha channel (alpha > 1). Ideally it would be the same as DRW_STATE_BLEND_ALPHA_PREMUL but without the alpha change.

My line of thought is that the cavity can be treated not just as ambient occlusion but also as a pointness attribute.
To lighten the pixels just make the ridge layer brighter itself, as long as its light enough, it shouldn't be a problem, also since its an exr file, pixels can have values greater than one.

The main use for the ridge in my opinion is for when the matcap designer wants the edges to have a different color or phisical properties,

as an example, here I tried to make a rusty "copper" material:
valleys become oxide (dark green) and ridges become worn out/polished metal.

Clément Foucault (fclem) requested changes to this revision.Thu, Mar 26, 1:10 AM

My line of thought is that the cavity can be treated not just as ambient occlusion but also as a pointness attribute.

Yes I see. I just don't like adding more feature than what will be used in practice.

Not all comments have been addressed so requesting change for bookkeeping.

If you have no time to dedicate to this patch I can take care of it personally.

This revision now requires changes to proceed.Thu, Mar 26, 1:10 AM