浏览代码

Merge pull request #504 from Unity-Technologies/feature/transparentSpecularBlending

Feature/transparent specular blending
/Yibing-Project-2
GitHub 7 年前
当前提交
6773024c
共有 6 个文件被更改,包括 38 次插入10 次删除
  1. 3
      ScriptableRenderPipeline/HDRenderPipeline/Material/LayeredLit/LayeredLit.shader
  2. 3
      ScriptableRenderPipeline/HDRenderPipeline/Material/LayeredLit/LayeredLitTessellation.shader
  3. 7
      ScriptableRenderPipeline/HDRenderPipeline/Material/Lit/Editor/LitUI.cs
  4. 1
      ScriptableRenderPipeline/HDRenderPipeline/Material/Lit/Lit.shader
  5. 9
      ScriptableRenderPipeline/HDRenderPipeline/Material/Unlit/Editor/BaseUnlitUI.cs
  6. 25
      ScriptableRenderPipeline/HDRenderPipeline/ShaderPass/ShaderPassForward.hlsl

3
ScriptableRenderPipeline/HDRenderPipeline/Material/LayeredLit/LayeredLit.shader


[HideInInspector] _ShowLayer1("_ShowLayer1", Float) = 0
[HideInInspector] _ShowLayer2("_ShowLayer2", Float) = 0
[HideInInspector] _ShowLayer3("_ShowLayer3", Float) = 0
// Transparency
[ToggleOff] _PreRefractionPass("PreRefractionPass", Float) = 0.0
}
HLSLINCLUDE

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


_TessellationShapeFactor("Tessellation shape factor", Range(0.0, 1.0)) = 0.75 // Only use with Phong
_TessellationBackFaceCullEpsilon("Tessellation back face epsilon", Range(-1.0, 0.0)) = -0.25
// TODO: Handle culling mode for backface culling
// Transparency
[ToggleOff] _PreRefractionPass("PreRefractionPass", Float) = 0.0
}
HLSLINCLUDE

7
ScriptableRenderPipeline/HDRenderPipeline/Material/Lit/Editor/LitUI.cs


protected MaterialProperty refractionMode = null;
protected const string kRefractionMode = "_RefractionMode";
protected override bool showBlendModePopup
{
get { return refractionMode == null || refractionMode.floatValue == 0f; }
}
protected void FindMaterialLayerProperties(MaterialProperty[] props)
{
for (int i = 0; i < m_LayerCount; ++i)

++EditorGUI.indentLevel;
m_MaterialEditor.ShaderProperty(ior, Styles.refractionIORText);
blendMode.floatValue = (float)BlendMode.Lerp;
if (mode != Lit.RefractionMode.ThinPlane)
{

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


_DistortionVectorMap("DistortionVectorMap", 2D) = "black" {}
[ToggleOff] _DistortionEnable("Enable Distortion", Float) = 0.0
[ToggleOff] _DistortionOnly("Distortion Only", Float) = 0.0
[ToggleOff] _DistortionDepthTest("Distortion Depth Test Enable", Float) = 0.0
[Enum(Add, 0, Multiply, 1)] _DistortionBlendMode("Distortion Blend Mode", Int) = 0
[HideInInspector] _DistortionSrcBlend("Distortion Blend Src", Int) = 0

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


// See comment in LitProperties.hlsl
const string kEmissionColor = "_EmissionColor";
bool m_ShowBlendModePopup = true;
protected virtual bool showBlendModePopup { get { return m_ShowBlendModePopup; } }
// The following set of functions are call by the ShaderGraph
// It will allow to display our common parameters + setup keyword correctly for them
protected abstract void FindMaterialProperties(MaterialProperty[] props);

SurfaceTypePopup();
if ((SurfaceType)surfaceType.floatValue == SurfaceType.Transparent)
{
BlendModePopup();
if (showBlendModePopup)
BlendModePopup();
m_MaterialEditor.ShaderProperty(enableFog, StylesBaseUnlit.enableFogText);

{
EditorGUI.indentLevel++;
m_MaterialEditor.ShaderProperty(distortionBlendMode, StylesBaseUnlit.distortionBlendModeText);
m_MaterialEditor.ShaderProperty(distortionOnly, StylesBaseUnlit.distortionOnlyText);
if (distortionOnly != null)
m_MaterialEditor.ShaderProperty(distortionOnly, StylesBaseUnlit.distortionOnlyText);
m_MaterialEditor.ShaderProperty(distortionDepthTest, StylesBaseUnlit.distortionDepthTestText);
EditorGUI.indentLevel++;

25
ScriptableRenderPipeline/HDRenderPipeline/ShaderPass/ShaderPassForward.hlsl


#endif // TESSELLATION_ON
float4 BlendDiffuseSpecular(float3 diffuse, float3 specular, float opacity)
{
return float4(diffuse + specular, opacity);
}
float4 BlendDiffuseWithConsistentSpecular(float3 diffuse, float3 specular, float opacity)
{
#ifdef _BLENDMODE_ALPHA
return float4(diffuse + (specular / max(opacity, 0.01)), opacity);
#elif defined(_BLENDMODE_ADD) || defined(_BLENDMODE_PRE_MULTIPLY)
return float4(diffuse * opacity + specular, opacity);
#else
return BlendDiffuseSpecular(diffuse, specular, opacity);
#endif
}
void Frag(PackedVaryingsToPS packedInput,
out float4 outColor : SV_Target0
#ifdef _DEPTHOFFSET_ON

float3 bakeDiffuseLighting = GetBakedDiffuseLigthing(surfaceData, builtinData, bsdfData, preLightData);
LightLoop(V, posInput, preLightData, bsdfData, bakeDiffuseLighting, featureFlags, diffuseLighting, specularLighting);
#ifdef _BLENDMODE_ALPHA
outColor = float4(diffuseLighting + (specularLighting / max(builtinData.opacity, 0.01)), builtinData.opacity);
#else
outColor = float4(diffuseLighting + specularLighting, builtinData.opacity);
#endif
outColor = EvaluateAtmosphericScattering(posInput, outColor);
}
outColor = BlendDiffuseWithConsistentSpecular(diffuseLighting, specularLighting, builtinData.opacity);
}
#ifdef _DEPTHOFFSET_ON
outputDepth = posInput.depthRaw;

正在加载...
取消
保存