Differential D6975 Diff 22822 source/blender/draw/engines/workbench/shaders/workbench_effect_cavity_frag.glsl
Changeset View
Changeset View
Standalone View
Standalone View
source/blender/draw/engines/workbench/shaders/workbench_effect_cavity_frag.glsl
| Context not available. | |||||
| #pragma BLENDER_REQUIRE(common_view_lib.glsl) | #pragma BLENDER_REQUIRE(common_view_lib.glsl) | ||||
| #pragma BLENDER_REQUIRE(workbench_common_lib.glsl) | #pragma BLENDER_REQUIRE(workbench_common_lib.glsl) | ||||
| #pragma BLENDER_REQUIRE(workbench_cavity_lib.glsl) | #pragma BLENDER_REQUIRE(workbench_cavity_lib.glsl) | ||||
| #pragma BLENDER_REQUIRE(workbench_matcap_lib.glsl) | |||||
| #pragma BLENDER_REQUIRE(workbench_curvature_lib.glsl) | #pragma BLENDER_REQUIRE(workbench_curvature_lib.glsl) | ||||
| #pragma BLENDER_REQUIRE(workbench_data_lib.glsl) | |||||
| uniform sampler2D depthBuffer; | uniform sampler2D depthBuffer; | ||||
| uniform sampler2D normalBuffer; | uniform sampler2D normalBuffer; | ||||
| uniform usampler2D objectIdBuffer; | uniform usampler2D objectIdBuffer; | ||||
| uniform sampler2D matcapRidge; | |||||
| uniform sampler2D matcapValley; | |||||
| uniform sampler2D materialBuffer; | |||||
| uniform bool useRidge; | |||||
| uniform bool useValley; | |||||
| in vec4 uvcoordsvar; | in vec4 uvcoordsvar; | ||||
fclem: Do only one shader variation for matcaps. Use a boolean uniforms to set if valley and/or ridges… | |||||
| Context not available. | |||||
| curvature_compute(uvcoordsvar.st, objectIdBuffer, normalBuffer, curvature); | curvature_compute(uvcoordsvar.st, objectIdBuffer, normalBuffer, curvature); | ||||
| #endif | #endif | ||||
| #if defined(USE_MATCAP_CAVITY) | |||||
| vec3 I = view_vector_from_screen_uv(uvcoordsvar.st, world_data.viewvecs, ProjectionMatrix); | |||||
| vec3 N = workbench_normal_decode(texture(normalBuffer, uvcoordsvar.st)); | |||||
| vec4 mat_data = texture(materialBuffer, uvcoordsvar.st); | |||||
| vec3 base_color = mat_data.rgb; | |||||
Not Done Inline ActionsI 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 fclem: I think you should reuse the final_cavity_factor and use that to blend between the cavity and… | |||||
| bool flipped = world_data.matcap_orientation != 0; | |||||
| vec2 matcap_uv = matcap_uv_compute(I, N, flipped); | |||||
| vec3 final_shading = vec3(0.0, 0.0, 0.0); | |||||
| float factor = clamp(((edges + curvature - cavity + 1.0) * 0.5), 0.0, 1.0); | |||||
| if (useValley) { | |||||
| final_shading = texture(matcapValley, matcap_uv).rgb; | |||||
| } | |||||
| if (useRidge) { | |||||
| final_shading = mix(final_shading, texture(matcapRidge, matcap_uv).rgb, factor); | |||||
| } | |||||
Not Done Inline ActionsSet factor calculation out of the #ifdef to avoid duplicated code and multiline mix. fclem: Set factor calculation out of the #ifdef to avoid duplicated code and multiline mix. | |||||
| else { | |||||
| final_shading = mix(final_shading, vec3(1.0), factor); | |||||
| } | |||||
| fragColor.rgb = final_shading * base_color; | |||||
| fragColor.a = abs((factor - 0.5) * 2); | |||||
| #else | |||||
| float final_cavity_factor = clamp((1.0 - cavity) * (1.0 + edges) * (1.0 + curvature), 0.0, 4.0); | float final_cavity_factor = clamp((1.0 - cavity) * (1.0 + edges) * (1.0 + curvature), 0.0, 4.0); | ||||
| fragColor.rgb = vec3(final_cavity_factor); | fragColor.rgb = vec3(final_cavity_factor); | ||||
| fragColor.a = 1.0; | fragColor.a = 1.0; | ||||
| #endif | |||||
| } | } | ||||
| Context not available. | |||||
Do only one shader variation for matcaps. Use a boolean uniforms to set if valley and/or ridges are to be used.