-
Notifications
You must be signed in to change notification settings - Fork 840
Fix URP blending modes and separate preserve specular lighting feature. #5762
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix URP blending modes and separate preserve specular lighting feature. #5762
Conversation
Hi! This comment will help you figure out which jobs to run before merging your PR. The suggestions are dynamic based on what files you have changed. URP Shader Graph Depending on the scope of your PR, you may need to run more jobs than what has been suggested. Please speak to your lead or a Graphics SDET (#devs-graphics-automation) if you are unsure. |
* Change the Alpha blend property from ...BlendA to ...BlendAlpha to be more clear. * Update ref images.
com.unity.render-pipelines.universal/Editor/ShaderGraph/Includes/PBRForwardPass.hlsl
Outdated
Show resolved
Hide resolved
* Shadergraph: Make sure alpha keywords are only set on transparent surfaces.
# Conflicts: # com.unity.render-pipelines.universal/CHANGELOG.md
# Conflicts: # com.unity.render-pipelines.universal/CHANGELOG.md
// ref: http://advances.realtimerendering.com/other/2016/naughty_dog/NaughtyDog_TechArt_Final.pdf | ||
bool preserveSpecular = (material.HasProperty(Property.BlendModePreserveSpecular) && | ||
material.GetFloat(Property.BlendModePreserveSpecular) > 0) && | ||
blendMode != BlendMode.Multiply && blendMode != BlendMode.Premultiply; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it by design additive mode supports premultiply?
@@ -249,7 +251,7 @@ Shader "Universal Render Pipeline/Baked Lit" | |||
#pragma shader_feature_local _NORMALMAP | |||
#pragma shader_feature_local_fragment _SURFACE_TYPE_TRANSPARENT | |||
#pragma shader_feature_local_fragment _ALPHATEST_ON | |||
#pragma shader_feature_local_fragment _ALPHAPREMULTIPLY_ON | |||
#pragma shader_feature_local_fragment _ _ALPHAMODULATE_ON |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not an issue, but the _ is not necessary for shader feature when there are only two keywords. Just mentioning because it's inconsistent with the other pass in same shader (line 54)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. Ran some automated tests with Universal Rendering Examples, tested different settings. Good to see new test added for blend modes. However, I would like to see more complex tests added in the future.
PR had green ABV before merging staging. Talked to @Verasl this one is good to go. |
…e. (#5762) * Blend Test, Unlit, Simple Lit blending. * Move alpha modulate to match "premultiplied" manual authoring. * Reduce keywords. * Lit blending fixes + clean up. * Shadergraph blending & preserve spec fixes. * Update test scene. * Graph allow override test and fix. * Fix tests, update change log. * Add blend test platform ref images. * Change multiply blend mode alpha to keep dst instead of multiply. * Change the Alpha blend property from ...BlendA to ...BlendAlpha to be more clear. * Update ref images. * Update change log. * Update Images. * Fix Lit graph Preserve Spec GUI. * Update d3d ref images. * Hide "Preserve Spec" button when not available. * Shadergraph: Make sure alpha keywords are only set on transparent surfaces. * Use HDR for test output image. * Reset ref images to match expectations for new test result settings. * Move AlphaModulate into it's own function. * Update ref pics. * Refactor AlphaModulate for PBRForwardPass. * Add material upgrader for blend modes. * Allow material upgrades for (overridable) shadergraph materials. * Fix blend specular graph UI. * Add upgrade path for UniversalLit graph target settings. * Add updated materials. * Fix Preserve Spec for ParticleLit. * Fix double multiplying of alpha for Particle shaders. * Separate AlphaModulate and AlphaPremultiply in Particle Lit code. * Move separated AlphaModulate and AlphaPremultiply into URP core. * Remove ApplyAlphaModulate as it's now not needed. * Fix more manually updated materials. * Review improvements. * Improve upgrader comment. * Switch the blending test to use the backbuffer. * Update ref images to match backbuffer rendering. * Disable XR compatibility due to minor test artifact causing either XR or Non-XR to always fail. * ref pic. * Bump wait frames so that indirect light gets baked on all platforms. * Revert "Disable XR compatibility due to minor test artifact causing either XR or Non-XR to always fail." This reverts commit ea05278. * Clamp source textures, solid color background. * Unlit and BakedLit does not have specular. Remove _ALPHAPREMULTIPLY. * Add unlit shader path for material postprocessor. * Upgrade Unlit shadergraph blendmode. * Upgrade only active subtarget to avoid inactive subtarget override. * Update Unlit premultiplied .shadergraph. * Adjust blending test threshold and images. * Disable XR, adjust ref image to 1920x1080. * Update 050_Shader_Graphs lighting settings and materials. * Update 050_Shader_Graphs images. * Remove ref images from wrong folder. * Update 066_Blending ref images. * Update linux vulkan. * Add changelog for material upgrade. * Disable 050_ShaderGraphs for Android and iOS. Co-authored-by: Felipe Lira <felipedrl@gmail.com>
Checklist for PR maker
need-backport-*
label. After you backport the PR, the label changes tobackported-*
.CHANGELOG.md
file.Purpose of this PR
There is a Preserve Specular Lighting feature which applies the alpha differently for diffuse and specular parts of shading. The intent is glass rendering.
Specular reflection should not be transparent while the diffuse part should be transparent (transmittance).
It is implemented by lifting the Src Alpha multiplication from fixed HW to the shader, so that we can selectively vary the alpha.
Previously URP implemented/mixed that with premultiplied mode, probably because that mode does use premultiplied blend mode in its implementation, even if the logical blend is Alpha blending.
This PR separates the Premultiplied alpha blend mode and Preserve Spec mode. It aims to parity with HDRP.
Preserve Spec mode is supported for Alpha and Additive blending.
This PR also adds "alpha emulation" for multiply blend mode.
It lerps the source texture towards white based on alpha value. Emulating the manual process of lessening color multiply effect by authoring the texture pixels towards white (value of 1). Effectively a sort of automatic "premultiplied" case for multiply.
The preserve spec is not supported for premultiply or multiply modes.
Previous "Premultiplied" mode can be achieved with Alpha Blend + Preserve Spec mode.
This PR handles the written shader and shadergraph cases.
Fixes at least bugs: 1260085, 1347301 and 1357703.
Testing status
Ran URP test locally.
Added a new test for basic blend modes:

UI Changes, preserve spec toggle:


Material:
Shadergraph target:
Comments to reviewers
Does not implement fog on transparent or off-screen accumulation features for HDRP parity.
Those should be a separate PR(s).