浏览代码

Merge pull request #505 from Unity-Technologies/Fix-fog-rough-refraction

Fix fog rough refraction
/Yibing-Project-2
GitHub 7 年前
当前提交
c7d467a6
共有 23 个文件被更改,包括 295 次插入70 次删除
  1. 74
      SampleScenes/HDTest/SkyFogTest.unity
  2. 6
      SampleScenes/HDTest/SkyFogTest/Lit_Transparent_Add.mat
  3. 5
      SampleScenes/HDTest/SkyFogTest/Lit_Transparent_Add_NoFog.mat
  4. 8
      SampleScenes/HDTest/SkyFogTest/Lit_Transparent_Alpha.mat
  5. 6
      SampleScenes/HDTest/SkyFogTest/Lit_Transparent_Multiply.mat
  6. 6
      SampleScenes/HDTest/SkyFogTest/Lit_Transparent_PreMultipliedAlpha.mat
  7. 6
      SampleScenes/HDTest/SkyFogTest/Unlit_Transparent_Add.mat
  8. 5
      SampleScenes/HDTest/SkyFogTest/Unlit_Transparent_Add_NoFog.mat
  9. 6
      SampleScenes/HDTest/SkyFogTest/Unlit_Transparent_Alpha.mat
  10. 6
      SampleScenes/HDTest/SkyFogTest/Unlit_Transparent_Multiply.mat
  11. 6
      SampleScenes/HDTest/SkyFogTest/Unlit_Transparent_PreMultipliedAlpha.mat
  12. 1
      ScriptableRenderPipeline/HDRenderPipeline/Material/LayeredLit/LayeredLit.shader
  13. 1
      ScriptableRenderPipeline/HDRenderPipeline/Material/LayeredLit/LayeredLitTessellation.shader
  14. 4
      ScriptableRenderPipeline/HDRenderPipeline/Material/Lit/Lit.hlsl
  15. 3
      ScriptableRenderPipeline/HDRenderPipeline/Material/Lit/Lit.shader
  16. 2
      ScriptableRenderPipeline/HDRenderPipeline/Material/Lit/LitData.hlsl
  17. 1
      ScriptableRenderPipeline/HDRenderPipeline/Material/Lit/LitTessellation.shader
  18. 17
      ScriptableRenderPipeline/HDRenderPipeline/Material/Material.hlsl
  19. 11
      ScriptableRenderPipeline/HDRenderPipeline/Material/Unlit/Editor/BaseUnlitUI.cs
  20. 1
      ScriptableRenderPipeline/HDRenderPipeline/Material/Unlit/Unlit.shader
  21. 2
      ScriptableRenderPipeline/HDRenderPipeline/Material/Unlit/UnlitData.hlsl
  22. 178
      SampleScenes/HDTest/SkyFogTest/Rough_Refraction_Transparent.mat
  23. 10
      SampleScenes/HDTest/SkyFogTest/Rough_Refraction_Transparent.mat.meta

74
SampleScenes/HDTest/SkyFogTest.unity


m_EditorClassIdentifier:
m_CommonSettings: {fileID: 0}
m_SkySettings: {fileID: 11400000, guid: 7d119d7ec4e5e964d92d40232696fa43, type: 2}
m_SsaoSettings: {fileID: 0}
--- !u!4 &185241299
Transform:
m_ObjectHideFlags: 0

- {fileID: 351200262}
- {fileID: 548582831}
- {fileID: 691539951}
- {fileID: 1671222037}
m_Father: {fileID: 0}
m_RootOrder: 15
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}

m_Father: {fileID: 0}
m_RootOrder: 3
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1001 &1671222036
Prefab:
m_ObjectHideFlags: 0
serializedVersion: 2
m_Modification:
m_TransformParent: {fileID: 919865824}
m_Modifications:
- target: {fileID: 4590821631456672, guid: 63d293d8d9b22af4eb3a41f61a9d3538, type: 2}
propertyPath: m_LocalPosition.x
value: 0.65092087
objectReference: {fileID: 0}
- target: {fileID: 4590821631456672, guid: 63d293d8d9b22af4eb3a41f61a9d3538, type: 2}
propertyPath: m_LocalPosition.y
value: -2.8777113
objectReference: {fileID: 0}
- target: {fileID: 4590821631456672, guid: 63d293d8d9b22af4eb3a41f61a9d3538, type: 2}
propertyPath: m_LocalPosition.z
value: 50.06
objectReference: {fileID: 0}
- target: {fileID: 4590821631456672, guid: 63d293d8d9b22af4eb3a41f61a9d3538, type: 2}
propertyPath: m_LocalRotation.x
value: -0
objectReference: {fileID: 0}
- target: {fileID: 4590821631456672, guid: 63d293d8d9b22af4eb3a41f61a9d3538, type: 2}
propertyPath: m_LocalRotation.y
value: -0
objectReference: {fileID: 0}
- target: {fileID: 4590821631456672, guid: 63d293d8d9b22af4eb3a41f61a9d3538, type: 2}
propertyPath: m_LocalRotation.z
value: -0
objectReference: {fileID: 0}
- target: {fileID: 4590821631456672, guid: 63d293d8d9b22af4eb3a41f61a9d3538, type: 2}
propertyPath: m_LocalRotation.w
value: 1
objectReference: {fileID: 0}
- target: {fileID: 4590821631456672, guid: 63d293d8d9b22af4eb3a41f61a9d3538, type: 2}
propertyPath: m_RootOrder
value: 5
objectReference: {fileID: 0}
- target: {fileID: 23355822747673064, guid: 63d293d8d9b22af4eb3a41f61a9d3538,
type: 2}
propertyPath: m_Materials.Array.data[0]
value:
objectReference: {fileID: 2100000, guid: 544a5d9e76974a740b92437acef58b62, type: 2}
- target: {fileID: 4590821631456672, guid: 63d293d8d9b22af4eb3a41f61a9d3538, type: 2}
propertyPath: m_LocalScale.x
value: 0.59999996
objectReference: {fileID: 0}
- target: {fileID: 4590821631456672, guid: 63d293d8d9b22af4eb3a41f61a9d3538, type: 2}
propertyPath: m_LocalScale.y
value: 12
objectReference: {fileID: 0}
- target: {fileID: 4590821631456672, guid: 63d293d8d9b22af4eb3a41f61a9d3538, type: 2}
propertyPath: m_LocalScale.z
value: 4
objectReference: {fileID: 0}
- target: {fileID: 1142537199752488, guid: 63d293d8d9b22af4eb3a41f61a9d3538, type: 2}
propertyPath: m_Name
value: Block_0.3x6_Lit_Lerp (1)
objectReference: {fileID: 0}
- target: {fileID: 1142537199752488, guid: 63d293d8d9b22af4eb3a41f61a9d3538, type: 2}
propertyPath: m_IsActive
value: 1
objectReference: {fileID: 0}
m_RemovedComponents: []
m_ParentPrefab: {fileID: 100100000, guid: 63d293d8d9b22af4eb3a41f61a9d3538, type: 2}
m_IsPrefabParent: 0
--- !u!4 &1671222037 stripped
Transform:
m_PrefabParentObject: {fileID: 4590821631456672, guid: 63d293d8d9b22af4eb3a41f61a9d3538,
type: 2}
m_PrefabInternal: {fileID: 1671222036}
--- !u!1001 &1677549155
Prefab:
m_ObjectHideFlags: 0

6
SampleScenes/HDTest/SkyFogTest/Lit_Transparent_Add.mat


m_PrefabInternal: {fileID: 0}
m_Name: Lit_Transparent_Add
m_Shader: {fileID: 4800000, guid: 6e4ae4064600d784cac1e41a9e6f2e59, type: 3}
m_ShaderKeywords: _ALBEDOAFFECTEMISSIVE_OFF _ALPHACUTOFFENABLE_OFF _BLENDMODE_ADD
_DEPTHOFFSETENABLE_OFF _DISTORTIONDEPTHTEST_OFF _DISTORTIONENABLE_OFF _DISTORTIONONLY_OFF
_DOUBLESIDEDENABLE_OFF _ENABLEPERPIXELDISPLACEMENT_OFF _ENABLESPECULAROCCLUSION_OFF
_ENABLEVERTEXDISPLACEMENT_OFF _ENABLEWIND_OFF _ENABLE_FOG _NORMALMAP_TANGENT_SPACE
_PREREFRACTIONPASS_OFF
m_ShaderKeywords: _BLENDMODE_ADD _ENABLE_FOG _NORMALMAP_TANGENT_SPACE _SURFACE_TYPE_TRANSPARENT
m_LightmapFlags: 4
m_EnableInstancingVariants: 0
m_DoubleSidedGI: 0

5
SampleScenes/HDTest/SkyFogTest/Lit_Transparent_Add_NoFog.mat


m_PrefabInternal: {fileID: 0}
m_Name: Lit_Transparent_Add_NoFog
m_Shader: {fileID: 4800000, guid: 6e4ae4064600d784cac1e41a9e6f2e59, type: 3}
m_ShaderKeywords: _ALBEDOAFFECTEMISSIVE_OFF _ALPHACUTOFFENABLE_OFF _BLENDMODE_ADD
_DEPTHOFFSETENABLE_OFF _DISTORTIONDEPTHTEST_OFF _DISTORTIONENABLE_OFF _DISTORTIONONLY_OFF
_DOUBLESIDEDENABLE_OFF _ENABLEFOG_OFF _ENABLEPERPIXELDISPLACEMENT_OFF _ENABLESPECULAROCCLUSION_OFF
_ENABLEVERTEXDISPLACEMENT_OFF _ENABLEWIND_OFF _NORMALMAP_TANGENT_SPACE _PREREFRACTIONPASS_OFF
m_ShaderKeywords: _BLENDMODE_ADD _NORMALMAP_TANGENT_SPACE _SURFACE_TYPE_TRANSPARENT
m_LightmapFlags: 4
m_EnableInstancingVariants: 0
m_DoubleSidedGI: 0

8
SampleScenes/HDTest/SkyFogTest/Lit_Transparent_Alpha.mat


m_PrefabInternal: {fileID: 0}
m_Name: Lit_Transparent_Alpha
m_Shader: {fileID: 4800000, guid: 6e4ae4064600d784cac1e41a9e6f2e59, type: 3}
m_ShaderKeywords: _ALBEDOAFFECTEMISSIVE_OFF _ALPHACUTOFFENABLE_OFF _BLENDMODE_ALPHA
_BLENDMODE_LERP _DEPTHOFFSETENABLE_OFF _DISTORTIONDEPTHTEST_OFF _DISTORTIONENABLE_OFF
_DISTORTIONONLY_OFF _DOUBLESIDEDENABLE_OFF _ENABLEPERPIXELDISPLACEMENT_OFF _ENABLESPECULAROCCLUSION_OFF
_ENABLEVERTEXDISPLACEMENT_OFF _ENABLEWIND_OFF _ENABLE_FOG _NORMALMAP_TANGENT_SPACE
_PREREFRACTIONPASS_OFF
m_ShaderKeywords: _BLENDMODE_ALPHA _ENABLE_FOG _NORMALMAP_TANGENT_SPACE _SURFACE_TYPE_TRANSPARENT
m_LightmapFlags: 4
m_EnableInstancingVariants: 0
m_DoubleSidedGI: 0

- _HeightCenter: 0.5
- _HeightMax: 1
- _HeightMin: -1
- _IOR: 1
- _IOR: 2.179
- _InitialBend: 1
- _InvTilingScale: 1
- _LinkDetailsWithBase: 1

6
SampleScenes/HDTest/SkyFogTest/Lit_Transparent_Multiply.mat


m_PrefabInternal: {fileID: 0}
m_Name: Lit_Transparent_Multiply
m_Shader: {fileID: 4800000, guid: 6e4ae4064600d784cac1e41a9e6f2e59, type: 3}
m_ShaderKeywords: _ALBEDOAFFECTEMISSIVE_OFF _ALPHACUTOFFENABLE_OFF _BLENDMODE_MULTIPLY
_DEPTHOFFSETENABLE_OFF _DISTORTIONDEPTHTEST_OFF _DISTORTIONENABLE_OFF _DISTORTIONONLY_OFF
_DOUBLESIDEDENABLE_OFF _ENABLEPERPIXELDISPLACEMENT_OFF _ENABLESPECULAROCCLUSION_OFF
_ENABLEVERTEXDISPLACEMENT_OFF _ENABLEWIND_OFF _ENABLE_FOG _NORMALMAP_TANGENT_SPACE
_PREREFRACTIONPASS_OFF
m_ShaderKeywords: _BLENDMODE_MULTIPLY _ENABLE_FOG _NORMALMAP_TANGENT_SPACE _SURFACE_TYPE_TRANSPARENT
m_LightmapFlags: 4
m_EnableInstancingVariants: 0
m_DoubleSidedGI: 0

6
SampleScenes/HDTest/SkyFogTest/Lit_Transparent_PreMultipliedAlpha.mat


m_PrefabInternal: {fileID: 0}
m_Name: Lit_Transparent_PreMultipliedAlpha
m_Shader: {fileID: 4800000, guid: 6e4ae4064600d784cac1e41a9e6f2e59, type: 3}
m_ShaderKeywords: _ALBEDOAFFECTEMISSIVE_OFF _ALPHACUTOFFENABLE_OFF _BLENDMODE_PRE_MULTIPLY
_DEPTHOFFSETENABLE_OFF _DISTORTIONDEPTHTEST_OFF _DISTORTIONENABLE_OFF _DISTORTIONONLY_OFF
_DOUBLESIDEDENABLE_OFF _ENABLEPERPIXELDISPLACEMENT_OFF _ENABLESPECULAROCCLUSION_OFF
_ENABLEVERTEXDISPLACEMENT_OFF _ENABLEWIND_OFF _ENABLE_FOG _NORMALMAP_TANGENT_SPACE
_PREREFRACTIONPASS_OFF
m_ShaderKeywords: _BLENDMODE_PRE_MULTIPLY _ENABLE_FOG _NORMALMAP_TANGENT_SPACE _SURFACE_TYPE_TRANSPARENT
m_LightmapFlags: 4
m_EnableInstancingVariants: 0
m_DoubleSidedGI: 0

6
SampleScenes/HDTest/SkyFogTest/Unlit_Transparent_Add.mat


m_PrefabInternal: {fileID: 0}
m_Name: Unlit_Transparent_Add
m_Shader: {fileID: 4800000, guid: c4edd00ff2db5b24391a4fcb1762e459, type: 3}
m_ShaderKeywords: _ALBEDOAFFECTEMISSIVE_OFF _ALPHACUTOFFENABLE_OFF _BLENDMODE_ADD
_DEPTHOFFSETENABLE_OFF _DISTORTIONDEPTHTEST_OFF _DISTORTIONENABLE_OFF _DISTORTIONONLY_OFF
_DOUBLESIDEDENABLE_OFF _ENABLEPERPIXELDISPLACEMENT_OFF _ENABLESPECULAROCCLUSION_OFF
_ENABLEVERTEXDISPLACEMENT_OFF _ENABLEWIND_OFF _ENABLE_FOG _NORMALMAP_TANGENT_SPACE
_PREREFRACTIONPASS_OFF
m_ShaderKeywords: _BLENDMODE_ADD _ENABLE_FOG _SURFACE_TYPE_TRANSPARENT
m_LightmapFlags: 4
m_EnableInstancingVariants: 0
m_DoubleSidedGI: 0

5
SampleScenes/HDTest/SkyFogTest/Unlit_Transparent_Add_NoFog.mat


m_PrefabInternal: {fileID: 0}
m_Name: Unlit_Transparent_Add_NoFog
m_Shader: {fileID: 4800000, guid: c4edd00ff2db5b24391a4fcb1762e459, type: 3}
m_ShaderKeywords: _ALBEDOAFFECTEMISSIVE_OFF _ALPHACUTOFFENABLE_OFF _BLENDMODE_ADD
_DEPTHOFFSETENABLE_OFF _DISTORTIONDEPTHTEST_OFF _DISTORTIONENABLE_OFF _DISTORTIONONLY_OFF
_DOUBLESIDEDENABLE_OFF _ENABLEFOG_OFF _ENABLEPERPIXELDISPLACEMENT_OFF _ENABLESPECULAROCCLUSION_OFF
_ENABLEVERTEXDISPLACEMENT_OFF _ENABLEWIND_OFF _NORMALMAP_TANGENT_SPACE _PREREFRACTIONPASS_OFF
m_ShaderKeywords: _BLENDMODE_ADD _SURFACE_TYPE_TRANSPARENT
m_LightmapFlags: 4
m_EnableInstancingVariants: 0
m_DoubleSidedGI: 0

6
SampleScenes/HDTest/SkyFogTest/Unlit_Transparent_Alpha.mat


m_PrefabInternal: {fileID: 0}
m_Name: Unlit_Transparent_Alpha
m_Shader: {fileID: 4800000, guid: c4edd00ff2db5b24391a4fcb1762e459, type: 3}
m_ShaderKeywords: _ALBEDOAFFECTEMISSIVE_OFF _ALPHACUTOFFENABLE_OFF _BLENDMODE_ALPHA
_BLENDMODE_LERP _DEPTHOFFSETENABLE_OFF _DISTORTIONDEPTHTEST_OFF _DISTORTIONENABLE_OFF
_DISTORTIONONLY_OFF _DOUBLESIDEDENABLE_OFF _ENABLEPERPIXELDISPLACEMENT_OFF _ENABLESPECULAROCCLUSION_OFF
_ENABLEVERTEXDISPLACEMENT_OFF _ENABLEWIND_OFF _ENABLE_FOG _NORMALMAP_TANGENT_SPACE
_PREREFRACTIONPASS_OFF
m_ShaderKeywords: _BLENDMODE_ALPHA _ENABLE_FOG _SURFACE_TYPE_TRANSPARENT
m_LightmapFlags: 4
m_EnableInstancingVariants: 0
m_DoubleSidedGI: 0

6
SampleScenes/HDTest/SkyFogTest/Unlit_Transparent_Multiply.mat


m_PrefabInternal: {fileID: 0}
m_Name: Unlit_Transparent_Multiply
m_Shader: {fileID: 4800000, guid: c4edd00ff2db5b24391a4fcb1762e459, type: 3}
m_ShaderKeywords: _ALBEDOAFFECTEMISSIVE_OFF _ALPHACUTOFFENABLE_OFF _BLENDMODE_MULTIPLY
_DEPTHOFFSETENABLE_OFF _DISTORTIONDEPTHTEST_OFF _DISTORTIONENABLE_OFF _DISTORTIONONLY_OFF
_DOUBLESIDEDENABLE_OFF _ENABLEPERPIXELDISPLACEMENT_OFF _ENABLESPECULAROCCLUSION_OFF
_ENABLEVERTEXDISPLACEMENT_OFF _ENABLEWIND_OFF _ENABLE_FOG _NORMALMAP_TANGENT_SPACE
_PREREFRACTIONPASS_OFF
m_ShaderKeywords: _BLENDMODE_MULTIPLY _ENABLE_FOG _SURFACE_TYPE_TRANSPARENT
m_LightmapFlags: 4
m_EnableInstancingVariants: 0
m_DoubleSidedGI: 0

6
SampleScenes/HDTest/SkyFogTest/Unlit_Transparent_PreMultipliedAlpha.mat


m_PrefabInternal: {fileID: 0}
m_Name: Unlit_Transparent_PreMultipliedAlpha
m_Shader: {fileID: 4800000, guid: c4edd00ff2db5b24391a4fcb1762e459, type: 3}
m_ShaderKeywords: _ALBEDOAFFECTEMISSIVE_OFF _ALPHACUTOFFENABLE_OFF _BLENDMODE_PRE_MULTIPLY
_DEPTHOFFSETENABLE_OFF _DISTORTIONDEPTHTEST_OFF _DISTORTIONENABLE_OFF _DISTORTIONONLY_OFF
_DOUBLESIDEDENABLE_OFF _ENABLEPERPIXELDISPLACEMENT_OFF _ENABLESPECULAROCCLUSION_OFF
_ENABLEVERTEXDISPLACEMENT_OFF _ENABLEWIND_OFF _ENABLE_FOG _NORMALMAP_TANGENT_SPACE
_PREREFRACTIONPASS_OFF
m_ShaderKeywords: _BLENDMODE_PRE_MULTIPLY _ENABLE_FOG _SURFACE_TYPE_TRANSPARENT
m_LightmapFlags: 4
m_EnableInstancingVariants: 0
m_DoubleSidedGI: 0

1
ScriptableRenderPipeline/HDRenderPipeline/Material/LayeredLit/LayeredLit.shader


#pragma shader_feature _HEIGHT_BASED_BLEND
#pragma shader_feature _ _LAYEREDLIT_3_LAYERS _LAYEREDLIT_4_LAYERS
#pragma shader_feature _SURFACE_TYPE_TRANSPARENT
#pragma shader_feature _ _BLENDMODE_ALPHA _BLENDMODE_ADD _BLENDMODE_MULTIPLY _BLENDMODE_PRE_MULTIPLY
// This feature is only for transparent Lit

1
ScriptableRenderPipeline/HDRenderPipeline/Material/LayeredLit/LayeredLitTessellation.shader


#pragma shader_feature _HEIGHT_BASED_BLEND
#pragma shader_feature _ _LAYEREDLIT_3_LAYERS _LAYEREDLIT_4_LAYERS
#pragma shader_feature _SURFACE_TYPE_TRANSPARENT
#pragma shader_feature _ _BLENDMODE_ALPHA _BLENDMODE_ADD _BLENDMODE_MULTIPLY _BLENDMODE_PRE_MULTIPLY
// This feature is only for transparent Lit

4
ScriptableRenderPipeline/HDRenderPipeline/Material/Lit/Lit.hlsl


#if defined(_REFRACTION_THINPLANE) || defined(_REFRACTION_THICKPLANE) || defined(_REFRACTION_THICKSPHERE)
// Note: Will override thickness of SSS's property set
FillMaterialIdTransparencyData(
surfaceData.ior, surfaceData.transmittanceColor, surfaceData.atDistance, surfaceData.thickness, surfaceData.refractionMask,
surfaceData.ior, surfaceData.transmittanceColor, surfaceData.atDistance, surfaceData.thickness, surfaceData.refractionMask,
bsdfData);
#endif

[branch] if (lightData.shadowIndex >= 0)
{
#ifdef SURFACE_TYPE_TRANSPARENT
#ifdef _SURFACE_TYPE_TRANSPARENT
shadow = GetDirectionalShadowAttenuation(lightLoopContext.shadowContext, positionWS, bsdfData.normalWS, lightData.shadowIndex, L, posInput.unPositionSS);
#else
shadow = LOAD_TEXTURE2D(_DeferredShadowTexture, posInput.unPositionSS).x;

3
ScriptableRenderPipeline/HDRenderPipeline/Material/Lit/Lit.shader


#pragma shader_feature _THICKNESSMAP
#pragma shader_feature _SPECULARCOLORMAP
#pragma shader_feature _SURFACE_TYPE_TRANSPARENT
// This feature is only for transparent Lit
#pragma shader_feature _ENABLE_FOG

2
ScriptableRenderPipeline/HDRenderPipeline/Material/Lit/LitData.hlsl


// If we have a prepass, we need to remove the clip from the GBuffer pass (otherwise HiZ does not work on PS4)
// For Forward
// Opaque geometry always has a depth pre-pass so we never want to do the clip here. For transparent we perform the clip as usual.
#if !(SHADERPASS == SHADERPASS_FORWARD && defined(SURFACE_TYPE_OPAQUE)) && !(SHADERPASS == SHADERPASS_GBUFFER && defined(_BYPASS_ALPHA_TEST))
#if !(SHADERPASS == SHADERPASS_FORWARD && !defined(_SURFACE_TYPE_TRANSPARENT)) && !(SHADERPASS == SHADERPASS_GBUFFER && defined(_BYPASS_ALPHA_TEST))
clip(alpha - alphaCutoff);
#endif
}

1
ScriptableRenderPipeline/HDRenderPipeline/Material/Lit/LitTessellation.shader


#pragma shader_feature _THICKNESSMAP
#pragma shader_feature _SPECULARCOLORMAP
#pragma shader_feature _SURFACE_TYPE_TRANSPARENT
#pragma shader_feature _ _BLENDMODE_ALPHA _BLENDMODE_ADD _BLENDMODE_MULTIPLY _BLENDMODE_PRE_MULTIPLY
// This feature is only for transparent Lit

17
ScriptableRenderPipeline/HDRenderPipeline/Material/Material.hlsl


#include "../../Core/ShaderLibrary/ImageBasedLighting.hlsl"
#include "../Sky/AtmosphericScattering/AtmosphericScattering.hlsl"
//-----------------------------------------------------------------------------
// Blending
//-----------------------------------------------------------------------------
// This should match the possible blending modes in any material .shader file (lit/layeredlit/unlit etc)
#if defined(_BLENDMODE_ALPHA) || defined(_BLENDMODE_ADD) || defined(_BLENDMODE_MULTIPLY) || defined(_BLENDMODE_PRE_MULTIPLY)
#define SURFACE_TYPE_TRANSPARENT
#else
#define SURFACE_TYPE_OPAQUE
#endif
// Guidelines
// .Shader need to define _SURFACE_TYPE_TRANSPARENT if they use a transparent material
// Also when transparent material object use a blend mode, it must define the blend mode (Note: Rough Refraction don't use blend mode)
// _BLENDMODE_ALPHA, _BLENDMODE_ADD, _BLENDMODE_MULTIPLY, (_BLENDMODE_PRE_MULTIPLY)
//-----------------------------------------------------------------------------
// Fog sampling function for materials

{
float4 result = inputColor;
#if defined(SURFACE_TYPE_TRANSPARENT) && defined(_ENABLE_FOG)
#if defined(_SURFACE_TYPE_TRANSPARENT) && defined(_ENABLE_FOG)
float4 fog = EvaluateAtmosphericScattering(posInput);
#if defined(_BLENDMODE_ALPHA)

// For additive, we just need to fade to black with fog density (black + background == background color == fog color)
result.rgb = result.rgb * (1.0 - fog.a);
#elif defined(_BLENDMODE_MULTIPLY)
#elif defined(_BLENDMODE_MULTIPLY)
// For multiplicative, we just need to fade to white with fog density (white * background == background color == fog color)
result.rgb = lerp(result.rgb, float3(1.0, 1.0, 1.0), fog.a);
#elif defined(_BLENDMODE_PRE_MULTIPLY)

11
ScriptableRenderPipeline/HDRenderPipeline/Material/Unlit/Editor/BaseUnlitUI.cs


public static GUIContent alphaCutoffText = new GUIContent("Alpha Cutoff", "Threshold for alpha cutoff");
public static GUIContent alphaCutoffShadowText = new GUIContent("Alpha Cutoff Shadow", "Threshold for alpha cutoff in case of shadow pass");
public static GUIContent alphaCutoffPrepassText = new GUIContent("Alpha Cutoff Prepass", "Threshold for alpha cutoff in case of depth prepass");
public static GUIContent transparentDepthPrepassEnableText = new GUIContent("Enable transparent depth prepass", "It allow to ");
public static GUIContent transparentDepthPrepassEnableText = new GUIContent("Enable transparent depth prepass", "It allow to ");
public static GUIContent enableFogText = new GUIContent("Enable Fog");
public static GUIContent doubleSidedEnableText = new GUIContent("Double Sided", "This will render the two face of the objects (disable backface culling) and flip/mirror normal");

if (showBlendModePopup)
BlendModePopup();
EditorGUI.indentLevel++;
EditorGUI.indentLevel--;
}
m_MaterialEditor.ShaderProperty(alphaCutoffEnable, StylesBaseUnlit.alphaCutoffEnableText);
if (alphaCutoffEnable.floatValue == 1.0f)

SurfaceType surfaceType = (SurfaceType)material.GetFloat(kSurfaceType);
BlendMode blendMode = (BlendMode)material.GetFloat(kBlendMode);
SetKeyword(material, "_SURFACE_TYPE_TRANSPARENT", surfaceType == SurfaceType.Transparent);
// These need to always been set either with opaque or transparent! So a users can switch to opaque and remove the keyword correctly
SetKeyword(material, "_BLENDMODE_ALPHA", false);
SetKeyword(material, "_BLENDMODE_ADD", false);

SetKeyword(material, "_ENABLE_FOG", fogEnabled);
if (material.HasProperty(kDistortionEnable))
{
{
bool distortionDepthTest = material.GetFloat(kDistortionDepthTest) > 0.0f;
if (distortionDepthTest)
{

// If distortion only is enabled, disable all passes (except distortion and debug)
bool enablePass = !(distortionEnable && distortionOnly);
// Disable all passes except distortion
// Distortion is setup in code above
material.SetShaderPassEnabled(HDShaderPassNames.s_ForwardStr, enablePass);

1
ScriptableRenderPipeline/HDRenderPipeline/Material/Unlit/Unlit.shader


#pragma shader_feature _EMISSIVE_COLOR_MAP
#pragma shader_feature _SURFACE_TYPE_TRANSPARENT
#pragma shader_feature _ _BLENDMODE_ALPHA _BLENDMODE_ADD _BLENDMODE_MULTIPLY _BLENDMODE_PRE_MULTIPLY
// This feature is only for transparent Unlit

2
ScriptableRenderPipeline/HDRenderPipeline/Material/Unlit/UnlitData.hlsl


void DoAlphaTest(float alpha, float alphaCutoff)
{
// Don't do the clip when rendering forward opaque (unlit). Forward opaque always have a prepass (with depth test on)
#if !(SHADERPASS == SHADERPASS_FORWARD_UNLIT && defined(SURFACE_TYPE_OPAQUE))
#if !(SHADERPASS == SHADERPASS_FORWARD_UNLIT && !defined(_SURFACE_TYPE_TRANSPARENT))
clip(alpha - alphaCutoff);
#endif
}

178
SampleScenes/HDTest/SkyFogTest/Rough_Refraction_Transparent.mat


%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!21 &2100000
Material:
serializedVersion: 6
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_Name: Rough_Refraction_Transparent
m_Shader: {fileID: 4800000, guid: 6e4ae4064600d784cac1e41a9e6f2e59, type: 3}
m_ShaderKeywords: _BLENDMODE_ALPHA _ENABLE_FOG _NORMALMAP_TANGENT_SPACE _REFRACTION_THINPLANE
_SURFACE_TYPE_TRANSPARENT
m_LightmapFlags: 4
m_EnableInstancingVariants: 0
m_DoubleSidedGI: 0
m_CustomRenderQueue: 3000
stringTagMap:
RenderType: Transparent
disabledShaderPasses:
- DistortionVectors
m_SavedProperties:
serializedVersion: 3
m_TexEnvs:
- _AnisotropyMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _BaseColorMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _BentNormalMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _BentNormalMapOS:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _DetailMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _DistortionVectorMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _EmissiveColorMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _HeightMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _MaskMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _NormalMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _NormalMapOS:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _SpecularColorMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _SubsurfaceRadiusMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _TangentMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _TangentMapOS:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _ThicknessMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
m_Floats:
- _ATDistance: 1
- _AlbedoAffectEmissive: 0
- _AlphaCutoff: 0.5
- _AlphaCutoffEnable: 0
- _Anisotropy: 0
- _BlendMode: 0
- _CoatCoverage: 1
- _CoatIOR: 0.5
- _CullMode: 2
- _DepthOffsetEnable: 0
- _DetailAlbedoScale: 1
- _DetailNormalScale: 1
- _DetailSmoothnessScale: 1
- _DisplacementLockObjectScale: 1
- _DisplacementLockTilingScale: 1
- _DisplacementMode: 0
- _DistortionBlendMode: 0
- _DistortionBlurBlendMode: 0
- _DistortionBlurDstBlend: 1
- _DistortionBlurRemapMax: 1
- _DistortionBlurRemapMin: 0
- _DistortionBlurScale: 1
- _DistortionBlurSrcBlend: 1
- _DistortionDepthTest: 0
- _DistortionDstBlend: 1
- _DistortionEnable: 0
- _DistortionOnly: 0
- _DistortionScale: 1
- _DistortionSrcBlend: 1
- _DoubleSidedEnable: 0
- _DoubleSidedNormalMode: 1
- _Drag: 1
- _DstBlend: 10
- _EmissiveColorMode: 1
- _EmissiveIntensity: 0
- _EnableFog: 1
- _EnablePerPixelDisplacement: 0
- _EnableSpecularOcclusion: 0
- _EnableVertexDisplacement: 0
- _EnableWind: 0
- _HeightAmplitude: 0.01
- _HeightCenter: 0.5
- _HeightMax: 1
- _HeightMin: -1
- _IOR: 1.631
- _InitialBend: 1
- _InvTilingScale: 1
- _LinkDetailsWithBase: 1
- _MaterialID: 1
- _Metallic: 0
- _NormalMapSpace: 0
- _NormalScale: 1
- _PPDLodThreshold: 5
- _PPDMaxSamples: 15
- _PPDMinSamples: 5
- _PPDPrimitiveLength: 1
- _PPDPrimitiveWidth: 1
- _PerPixelDisplacementObjectScale: 1
- _PreRefractionPass: 0
- _RefractionMode: 3
- _ShiverDirectionality: 0.5
- _ShiverDrag: 0.2
- _Smoothness: 1
- _SmoothnessRemapMax: 1
- _SmoothnessRemapMin: 0
- _SrcBlend: 5
- _StencilRef: 2
- _Stiffness: 1
- _SubsurfaceProfile: 0
- _SubsurfaceRadius: 1
- _SurfaceType: 1
- _TexWorldScale: 1
- _Thickness: 1
- _ThicknessMultiplier: 1
- _UVBase: 0
- _UVDetail: 0
- _VertexDisplacementObjectScale: 1
- _VertexDisplacementTilingScale: 1
- _ZTestMode: 8
- _ZWrite: 0
m_Colors:
- _BaseColor: {r: 1, g: 0, b: 0, a: 0.741}
- _DoubleSidedConstants: {r: 1, g: 1, b: -1, a: 0}
- _EmissionColor: {r: 1, g: 1, b: 1, a: 1}
- _EmissiveColor: {r: 0, g: 0, b: 0, a: 1}
- _InvPrimScale: {r: 1, g: 1, b: 0, a: 0}
- _SpecularColor: {r: 1, g: 1, b: 1, a: 1}
- _TransmittanceColor: {r: 1, g: 1, b: 1, a: 1}
- _UVDetailsMappingMask: {r: 1, g: 0, b: 0, a: 0}
- _UVMappingMask: {r: 1, g: 0, b: 0, a: 0}

10
SampleScenes/HDTest/SkyFogTest/Rough_Refraction_Transparent.mat.meta


fileFormatVersion: 2
guid: 544a5d9e76974a740b92437acef58b62
timeCreated: 1507906791
licenseType: Pro
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 2100000
userData:
assetBundleName:
assetBundleVariant:
正在加载...
取消
保存