浏览代码

Merge pull request #1739 from Unity-Technologies/Add-opacity-on-contact-shadow

Add opacity on contact shadow
/main
GitHub 6 年前
当前提交
b3641a55
共有 6 个文件被更改,包括 19 次插入17 次删除
  1. 1
      com.unity.render-pipelines.high-definition/CHANGELOG.md
  2. 11
      com.unity.render-pipelines.high-definition/HDRP/Editor/Shadows/ContactShadowsEditor.cs
  3. 4
      com.unity.render-pipelines.high-definition/HDRP/Lighting/LightLoop/LightLoop.cs
  4. 16
      com.unity.render-pipelines.high-definition/HDRP/Lighting/ScreenSpaceShadow.compute
  5. 3
      com.unity.render-pipelines.high-definition/HDRP/RenderPipeline/HDStringConstants.cs
  6. 1
      com.unity.render-pipelines.high-definition/HDRP/Shadows/ContactShadows.cs

1
com.unity.render-pipelines.high-definition/CHANGELOG.md


- Added support for RendererPriority on Renderer. This allow to control order of transparent rendering manually. HDRP have now two stage of sorting for transparent in addition to bact to front. Material have a priority then Renderer have a priority.
- Add Coupling of (HD)Camera and HDAdditionalCameraData for reset and remove in inspector contextual menu of Camera
- Add macro to forbid unity_ObjectToWorld/unity_WorldToObject to be use as it doesn't handle camera relative rendering
- Add opacity control on contact shadow
## [3.0.0-preview]

11
com.unity.render-pipelines.high-definition/HDRP/Editor/Shadows/ContactShadowsEditor.cs


[VolumeComponentEditor(typeof(ContactShadows))]
public class ContactShadowsEditor : VolumeComponentEditor
{
public readonly GUIContent contactShadow = new GUIContent("Contact Shadows");
public readonly GUIContent contactShadowLength = new GUIContent("Length", "Length of rays used to gather contact shadows in world units.\nZero will disable the feature.");
public readonly GUIContent contactShadowDistanceScaleFactor = new GUIContent("Distance Scale Factor", "Contact Shadows are scaled up with distance. Use this parameter to dampen this effect.");
public readonly GUIContent contactShadowMaxDistance = new GUIContent("Max Distance", "Distance from the camera in world units at which contact shadows are faded out to zero.");
public readonly GUIContent contactShadowFadeDistance = new GUIContent("Fade Distance", "Distance in world units over which the contact shadows are faded out (see Max Distance).");
public readonly GUIContent contactShadowSampleCount = new GUIContent("Sample Count", "Number of samples when ray casting.");
SerializedDataParameter m_Enable;
SerializedDataParameter m_Length;
SerializedDataParameter m_DistanceScaleFactor;

SerializedDataParameter m_Opacity;
public override void OnEnable()

m_MaxDistance = Unpack(o.Find(x => x.maxDistance));
m_FadeDistance = Unpack(o.Find(x => x.fadeDistance));
m_SampleCount = Unpack(o.Find(x => x.sampleCount));
m_Opacity = Unpack(o.Find(x => x.opacity));
}
public override void OnInspectorGUI()

PropertyField(m_MaxDistance, CoreEditorUtils.GetContent("Max Distance|Distance from the camera in world units at which contact shadows are faded out to zero."));
PropertyField(m_FadeDistance, CoreEditorUtils.GetContent("Fade Distance|Distance in world units over which the contact shadows fade out (see Max Distance)."));
PropertyField(m_SampleCount, CoreEditorUtils.GetContent("Sample Count|Number of samples when ray casting."));
PropertyField(m_Opacity, CoreEditorUtils.GetContent("Opacity|Opacity of the resulting contact shadow."));
}
}
}

4
com.unity.render-pipelines.high-definition/HDRP/Lighting/LightLoop/LightLoop.cs


float contactShadowFadeEnd = m_ContactShadows.maxDistance;
float contactShadowOneOverFadeRange = 1.0f / (contactShadowRange);
Vector4 contactShadowParams = new Vector4(m_ContactShadows.length, m_ContactShadows.distanceScaleFactor, contactShadowFadeEnd, contactShadowOneOverFadeRange);
cmd.SetComputeVectorParam(screenSpaceShadowComputeShader, HDShaderIDs._DirectionalContactShadowParams, contactShadowParams);
Vector4 contactShadowParams2 = new Vector4(m_ContactShadows.opacity, 0.0f, 0.0f, 0.0f);
cmd.SetComputeVectorParam(screenSpaceShadowComputeShader, HDShaderIDs._ContactShadowParamsParameters, contactShadowParams);
cmd.SetComputeVectorParam(screenSpaceShadowComputeShader, HDShaderIDs._ContactShadowParamsParameters2, contactShadowParams2);
cmd.SetComputeIntParam(screenSpaceShadowComputeShader, HDShaderIDs._DirectionalContactShadowSampleCount, m_ContactShadows.sampleCount);
}

16
com.unity.render-pipelines.high-definition/HDRP/Lighting/ScreenSpaceShadow.compute


uint _DirectionalShadowIndex;
float4 _DirectionalLightDirection;
float4 _PunctualLightPosition;
float4 _ScreenSpaceShadowsParameters;
float4 _ContactShadowParamsParameters;
float4 _ContactShadowParamsParameters2;
#define _ContactShadowLength _ScreenSpaceShadowsParameters.x
#define _ContactShadowDistanceScaleFactor _ScreenSpaceShadowsParameters.y
#define _ContactShadowFadeEnd _ScreenSpaceShadowsParameters.z
#define _ContactShadowFadeOneOverRange _ScreenSpaceShadowsParameters.w
#define _ContactShadowLength _ContactShadowParamsParameters.x
#define _ContactShadowDistanceScaleFactor _ContactShadowParamsParameters.y
#define _ContactShadowFadeEnd _ContactShadowParamsParameters.z
#define _ContactShadowFadeOneOverRange _ContactShadowParamsParameters.w
#define _ContactShadowOpacity _ContactShadowParamsParameters2.x
#define DEFERRED_SHADOW_TILE_SIZE 16

contactShadow = 1.0 - result.x * saturate((_ContactShadowFadeEnd - posInput.linearDepth) * _ContactShadowFadeOneOverRange);
}
return contactShadow;
return lerp(1.0, contactShadow, _ContactShadowOpacity);
}
[numthreads(DEFERRED_SHADOW_TILE_SIZE, DEFERRED_SHADOW_TILE_SIZE, 1)]

contactShadow = ComputeContactShadow(posInput, direction);
_DeferredShadowTextureUAV[pixelCoord] = float4(1.0, contactShadow, 1.0, 1.0);
}
}

3
com.unity.render-pipelines.high-definition/HDRP/RenderPipeline/HDStringConstants.cs


public static readonly int _DeferredShadowTexture = Shader.PropertyToID("_DeferredShadowTexture");
public static readonly int _DeferredShadowTextureUAV = Shader.PropertyToID("_DeferredShadowTextureUAV");
public static readonly int _DirectionalShadowIndex = Shader.PropertyToID("_DirectionalShadowIndex");
public static readonly int _DirectionalContactShadowParams = Shader.PropertyToID("_ScreenSpaceShadowsParameters");
public static readonly int _ContactShadowParamsParameters = Shader.PropertyToID("_ContactShadowParamsParameters");
public static readonly int _ContactShadowParamsParameters2 = Shader.PropertyToID("_ContactShadowParamsParameters2");
public static readonly int _DirectionalContactShadowSampleCount = Shader.PropertyToID("_SampleCount");
public static readonly int _DirectionalLightDirection = Shader.PropertyToID("_DirectionalLightDirection");
public static readonly int _PunctualLightPosition = Shader.PropertyToID("_PunctualLightPosition");

1
com.unity.render-pipelines.high-definition/HDRP/Shadows/ContactShadows.cs


// Contact shadows
public BoolParameter enable = new BoolParameter(false);
public ClampedFloatParameter length = new ClampedFloatParameter(0.15f, 0.0f, 1.0f);
public ClampedFloatParameter opacity = new ClampedFloatParameter(1.0f, 0.0f, 1.0f);
public ClampedFloatParameter distanceScaleFactor = new ClampedFloatParameter(0.5f, 0.0f, 1.0f);
public MinFloatParameter maxDistance = new MinFloatParameter(50.0f, 0.0f);
public MinFloatParameter fadeDistance = new MinFloatParameter(5.0f, 0.0f);

正在加载...
取消
保存