调整目录,添加 screen space shadow 优化
This commit is contained in:
parent
052294ae82
commit
ec312c498e
@ -37,29 +37,29 @@ MonoBehaviour:
|
||||
m_ShEvalMode: 0
|
||||
m_MainLightRenderingMode: 1
|
||||
m_MainLightShadowsSupported: 1
|
||||
m_MainLightShadowmapResolution: 1024
|
||||
m_AdditionalLightsRenderingMode: 2
|
||||
m_MainLightShadowmapResolution: 2048
|
||||
m_AdditionalLightsRenderingMode: 1
|
||||
m_AdditionalLightsPerObjectLimit: 4
|
||||
m_AdditionalLightShadowsSupported: 0
|
||||
m_AdditionalLightShadowsSupported: 1
|
||||
m_AdditionalLightsShadowmapResolution: 2048
|
||||
m_AdditionalLightsShadowResolutionTierLow: 256
|
||||
m_AdditionalLightsShadowResolutionTierMedium: 512
|
||||
m_AdditionalLightsShadowResolutionTierHigh: 1024
|
||||
m_ReflectionProbeBlending: 1
|
||||
m_ReflectionProbeBoxProjection: 1
|
||||
m_ShadowDistance: 50
|
||||
m_ShadowCascadeCount: 1
|
||||
m_ShadowDistance: 100
|
||||
m_ShadowCascadeCount: 4
|
||||
m_Cascade2Split: 0.25
|
||||
m_Cascade3Split: {x: 0.1, y: 0.3}
|
||||
m_Cascade4Split: {x: 0.067, y: 0.2, z: 0.467}
|
||||
m_CascadeBorder: 0.2
|
||||
m_CascadeBorder: 0.48867315
|
||||
m_ShadowDepthBias: 1
|
||||
m_ShadowNormalBias: 1
|
||||
m_AnyShadowsSupported: 1
|
||||
m_SoftShadowsSupported: 0
|
||||
m_SoftShadowsSupported: 1
|
||||
m_ConservativeEnclosingSphere: 1
|
||||
m_NumIterationsEnclosingSphere: 64
|
||||
m_SoftShadowQuality: 2
|
||||
m_SoftShadowQuality: 3
|
||||
m_AdditionalLightsCookieResolution: 1024
|
||||
m_AdditionalLightsCookieFormat: 1
|
||||
m_UseSRPBatcher: 1
|
||||
|
||||
@ -234,10 +234,10 @@ MonoBehaviour:
|
||||
m_Script: {fileID: 11500000, guid: 9f7bf3c01c632d044877a67f9e9abb21, type: 3}
|
||||
m_Name: HierarchicalZFeature
|
||||
m_EditorClassIdentifier:
|
||||
m_Active: 1
|
||||
m_Active: 0
|
||||
settings:
|
||||
PyramidFunc: 0
|
||||
SkipThreeMip: 1
|
||||
SkipThreeMip: 0
|
||||
UseThreeFrameReadback: 1
|
||||
ComputeShader: {fileID: 7200000, guid: b10c09f63c5a5864ca12e07b1b361d56, type: 3}
|
||||
Spd: {fileID: 7200000, guid: 2c0519b45f80f5c47b4ee3edb2e7931b, type: 3}
|
||||
@ -311,7 +311,9 @@ MonoBehaviour:
|
||||
- {fileID: 4071882023117421450}
|
||||
- {fileID: -7284859345190182597}
|
||||
- {fileID: -1629415145513658388}
|
||||
m_RendererFeatureMap: bc3f630842f2e70dd6a559c442a94bfd4529d15534f2d3de228858dca8d12222716523fbf3439fdb7a327b7bff4bdd446ac59dfa966ffa88ca6373cd5da9013d6cff55ca297e5e908a7b3653203b82383b2141bb05fbe69aec5704e48e2763e9
|
||||
- {fileID: 7541218312462517771}
|
||||
- {fileID: 5808157236138506604}
|
||||
m_RendererFeatureMap: bc3f630842f2e70dd6a559c442a94bfd4529d15534f2d3de228858dca8d12222716523fbf3439fdb7a327b7bff4bdd446ac59dfa966ffa88ca6373cd5da9013d6cff55ca297e5e908a7b3653203b82383b2141bb05fbe69aec5704e48e2763e90bc6ff9f19caa7686c79a6bb3bb89a50
|
||||
m_UseNativeRenderPass: 0
|
||||
postProcessData: {fileID: 11400000, guid: 41439944d30ece34e96484bdb6645b55, type: 2}
|
||||
shaders:
|
||||
@ -526,6 +528,24 @@ MonoBehaviour:
|
||||
m_Active: 1
|
||||
IsEnabled: 0
|
||||
m_fsrURP: {fileID: 0}
|
||||
--- !u!114 &5808157236138506604
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 0}
|
||||
m_Enabled: 1
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: 11500000, guid: eab40a9966087544f860c63893896a09, type: 3}
|
||||
m_Name: SoftShadowMask
|
||||
m_EditorClassIdentifier:
|
||||
m_Active: 1
|
||||
settings:
|
||||
BlurMask: 0
|
||||
Use16Samples: 0
|
||||
MaskMat: {fileID: 2100000, guid: 1368366248809f24e9a110be3075d1b8, type: 2}
|
||||
BlurMat: {fileID: 0}
|
||||
--- !u!114 &6334271670068977784
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
@ -539,3 +559,20 @@ MonoBehaviour:
|
||||
m_Name: FSR
|
||||
m_EditorClassIdentifier:
|
||||
m_Active: 0
|
||||
--- !u!114 &7541218312462517771
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 0}
|
||||
m_Enabled: 1
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: 11500000, guid: e32e72b6a3f58a24c9033e2b9275eea0, type: 3}
|
||||
m_Name: ScreenSpaceShadows
|
||||
m_EditorClassIdentifier:
|
||||
m_Active: 1
|
||||
m_Shader: {fileID: 4800000, guid: 0f854b35a0cf61a429bd5dcfea30eddd, type: 3}
|
||||
m_Settings:
|
||||
UseLowResolution: 1
|
||||
UseLowResolutionPCF: 0
|
||||
|
||||
@ -6,6 +6,9 @@ namespace UnityEngine.Rendering.Universal
|
||||
public Camera targetCamera;
|
||||
public bool showCullingSpheres = true;
|
||||
public bool showCameraFrustums = true;
|
||||
public bool showCascadeFrustums = true;
|
||||
[Range(0f, 4f)]
|
||||
public int showMaxCascade = 4;
|
||||
public Color[] cascadeColors = new Color[]
|
||||
{
|
||||
new Color(1, 0, 0, 0.5f), // 红
|
||||
@ -16,15 +19,122 @@ namespace UnityEngine.Rendering.Universal
|
||||
|
||||
public static Vector3 cascadeSplits;
|
||||
public static Vector4[] cullingSpheres = new Vector4[4];
|
||||
public static Matrix4x4[] cascadeVps = new Matrix4x4[4];
|
||||
Plane[][] planes = new Plane[][]
|
||||
{
|
||||
new Plane[] { new(),new(),new(),new(),new(),new() },
|
||||
new Plane[] { new(),new(),new(),new(),new(),new() },
|
||||
new Plane[] { new(),new(),new(),new(),new(),new() },
|
||||
new Plane[] { new(),new(),new(),new(),new(),new() },
|
||||
};
|
||||
|
||||
void ExtractFrustumPlanes(in Matrix4x4 VP, in Plane[] planes)
|
||||
{
|
||||
// Left clipping plane
|
||||
planes[0] = new Plane(
|
||||
new Vector3(VP.m30 + VP.m00, VP.m31 + VP.m01, VP.m32 + VP.m02),
|
||||
VP.m33 + VP.m03);
|
||||
// Right clipping plane
|
||||
planes[1] = new Plane(
|
||||
new Vector3(VP.m30 - VP.m00, VP.m31 - VP.m01, VP.m32 - VP.m02),
|
||||
VP.m33 - VP.m03);
|
||||
// Top clipping plane
|
||||
planes[2] = new Plane(
|
||||
new Vector3(VP.m30 - VP.m10, VP.m31 - VP.m11, VP.m32 - VP.m12),
|
||||
VP.m33 - VP.m13);
|
||||
// Bottom clipping plane
|
||||
planes[3] = new Plane(
|
||||
new Vector3(VP.m30 + VP.m10, VP.m31 + VP.m11, VP.m32 + VP.m12),
|
||||
VP.m33 + VP.m13);
|
||||
// Near clipping plane
|
||||
planes[4] = new Plane(
|
||||
new Vector3(VP.m20, VP.m21, VP.m22),
|
||||
VP.m23);
|
||||
// Far clipping plane
|
||||
planes[5] = new Plane(
|
||||
new Vector3(VP.m30 - VP.m20, VP.m31 - VP.m21, VP.m32 - VP.m22),
|
||||
VP.m33 - VP.m23);
|
||||
}
|
||||
|
||||
protected static void ExtractFrustumPlanesStereo(in Matrix4x4 leftVP, in Matrix4x4 rightVP, in Plane[] planes)
|
||||
{
|
||||
// Left clipping plane
|
||||
planes[0] = new Plane(
|
||||
new Vector3(leftVP.m30 + leftVP.m00, leftVP.m31 + leftVP.m01, leftVP.m32 + leftVP.m02),
|
||||
leftVP.m33 + leftVP.m03);
|
||||
// Right clipping plane
|
||||
planes[1] = new Plane(
|
||||
new Vector3(rightVP.m30 - rightVP.m00, rightVP.m31 - rightVP.m01, rightVP.m32 - rightVP.m02),
|
||||
rightVP.m33 - rightVP.m03);
|
||||
// Top clipping plane
|
||||
planes[2] = new Plane(
|
||||
new Vector3(leftVP.m30 - leftVP.m10, leftVP.m31 - leftVP.m11, leftVP.m32 - leftVP.m12),
|
||||
leftVP.m33 - leftVP.m13);
|
||||
// Bottom clipping plane
|
||||
planes[3] = new Plane(
|
||||
new Vector3(leftVP.m30 + leftVP.m10, leftVP.m31 + leftVP.m11, leftVP.m32 + leftVP.m12),
|
||||
leftVP.m33 + leftVP.m13);
|
||||
// Near clipping plane
|
||||
planes[4] = new Plane(
|
||||
new Vector3(leftVP.m20, leftVP.m21, leftVP.m22),
|
||||
leftVP.m23);
|
||||
// Far clipping plane
|
||||
planes[5] = new Plane(
|
||||
new Vector3(leftVP.m30 - leftVP.m20, leftVP.m31 - leftVP.m21, leftVP.m32 - leftVP.m22),
|
||||
leftVP.m33 - leftVP.m23);
|
||||
}
|
||||
|
||||
protected void DrawFrustum(in Matrix4x4 vp)
|
||||
{
|
||||
Matrix4x4 clip2world = vp.inverse;
|
||||
|
||||
Vector4[] corners =
|
||||
{
|
||||
new(-1, -1, -1, 1),
|
||||
new(1, -1, -1, 1),
|
||||
new(1, 1, -1, 1),
|
||||
new(-1, 1, -1, 1),
|
||||
|
||||
new(-1, -1, 1, 1),
|
||||
new(1, -1, 1, 1),
|
||||
new(1, 1, 1, 1),
|
||||
new(-1, 1, 1, 1),
|
||||
};
|
||||
|
||||
for (int i = 0; i < corners.Length; i++)
|
||||
{
|
||||
corners[i] = clip2world * corners[i];
|
||||
corners[i] /= corners[i].w;
|
||||
}
|
||||
|
||||
Gizmos.DrawLine(corners[0], corners[1]);
|
||||
Gizmos.DrawLine(corners[1], corners[2]);
|
||||
Gizmos.DrawLine(corners[2], corners[3]);
|
||||
Gizmos.DrawLine(corners[3], corners[0]);
|
||||
|
||||
Gizmos.DrawLine(corners[4], corners[5]);
|
||||
Gizmos.DrawLine(corners[5], corners[6]);
|
||||
Gizmos.DrawLine(corners[6], corners[7]);
|
||||
Gizmos.DrawLine(corners[7], corners[4]);
|
||||
|
||||
Gizmos.DrawLine(corners[0], corners[4]);
|
||||
Gizmos.DrawLine(corners[1], corners[5]);
|
||||
Gizmos.DrawLine(corners[2], corners[6]);
|
||||
Gizmos.DrawLine(corners[3], corners[7]);
|
||||
}
|
||||
|
||||
void OnDrawGizmos()
|
||||
{
|
||||
if (targetCamera == null) return;
|
||||
// 可视化Culling Spheres
|
||||
|
||||
if (showCullingSpheres)
|
||||
{
|
||||
for (int i = 0; i < cullingSpheres.Length; i++)
|
||||
{
|
||||
if (i > showMaxCascade - 1)
|
||||
{
|
||||
break;
|
||||
}
|
||||
if (cullingSpheres[i].w <= 0) continue;
|
||||
|
||||
Gizmos.color = cascadeColors[i % cascadeColors.Length];
|
||||
@ -33,13 +143,34 @@ namespace UnityEngine.Rendering.Universal
|
||||
Gizmos.DrawWireSphere(sphereCenter, sphereRadius);
|
||||
}
|
||||
}
|
||||
// 可视化相机视锥体级联
|
||||
|
||||
if (showCascadeFrustums)
|
||||
{
|
||||
for (int i = 0; i < cascadeVps.Length; i++)
|
||||
{
|
||||
if (i > showMaxCascade - 1)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
var vp = cascadeVps[i];
|
||||
Gizmos.color = cascadeColors[i % cascadeVps.Length];
|
||||
DrawFrustum(vp);
|
||||
ExtractFrustumPlanes(vp, planes[i]);
|
||||
}
|
||||
}
|
||||
|
||||
if (showCameraFrustums)
|
||||
{
|
||||
float lastSplit = targetCamera.nearClipPlane;
|
||||
|
||||
for (int i = 0; i < 3; i++)
|
||||
{
|
||||
if (i > showMaxCascade - 1)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
if (cascadeSplits[i] <= 0) break;
|
||||
|
||||
Gizmos.color = cascadeColors[i % cascadeColors.Length];
|
||||
@ -49,8 +180,6 @@ namespace UnityEngine.Rendering.Universal
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
private void DrawCascadeFrustum(Camera cam, float startDist, float endDist)
|
||||
{
|
||||
// 计算视锥体角点
|
||||
|
||||
@ -144,6 +144,10 @@ namespace UnityEngine.Rendering.Universal.Internal
|
||||
{
|
||||
DebugCascadeShadow.cascadeSplits = renderingData.shadowData.mainLightShadowCascadesSplit * renderingData.cameraData.maxShadowDistance;
|
||||
Array.Copy(m_CascadeSplitDistances, DebugCascadeShadow.cullingSpheres, 4);
|
||||
for (int i = 0; i < 4; i++)
|
||||
{
|
||||
DebugCascadeShadow.cascadeVps[i] = m_CascadeSlices[i].projectionMatrix * m_CascadeSlices[i].viewMatrix;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
m_MaxShadowDistanceSq = renderingData.cameraData.maxShadowDistance * renderingData.cameraData.maxShadowDistance;
|
||||
|
||||
@ -6,6 +6,8 @@ namespace UnityEngine.Rendering.Universal
|
||||
[Serializable]
|
||||
internal class ScreenSpaceShadowsSettings
|
||||
{
|
||||
public bool UseLowResolution;
|
||||
public bool UseLowResolutionPCF;
|
||||
}
|
||||
|
||||
[DisallowMultipleRendererFeature("Screen Space Shadows")]
|
||||
@ -142,6 +144,14 @@ namespace UnityEngine.Rendering.Universal
|
||||
desc.graphicsFormat = RenderingUtils.SupportsGraphicsFormat(GraphicsFormat.R8_UNorm, FormatUsage.Linear | FormatUsage.Render)
|
||||
? GraphicsFormat.R8_UNorm
|
||||
: GraphicsFormat.B8G8R8A8_UNorm;
|
||||
if (m_CurrentSettings.UseLowResolution)
|
||||
{
|
||||
desc.width /= 2;
|
||||
desc.height /= 2;
|
||||
desc.useMipMap = true;
|
||||
desc.autoGenerateMips = true;
|
||||
desc.mipCount = 3;
|
||||
}
|
||||
|
||||
RenderingUtils.ReAllocateIfNeeded(ref m_RenderTarget, desc, FilterMode.Point, TextureWrapMode.Clamp, name: "_ScreenSpaceShadowmapTexture");
|
||||
cmd.SetGlobalTexture(m_RenderTarget.name, m_RenderTarget.nameID);
|
||||
@ -164,9 +174,21 @@ namespace UnityEngine.Rendering.Universal
|
||||
var cmd = renderingData.commandBuffer;
|
||||
using (new ProfilingScope(cmd, m_ProfilingSampler))
|
||||
{
|
||||
if (m_CurrentSettings.UseLowResolution)
|
||||
{
|
||||
CoreUtils.SetKeyword(cmd, "_SCREEN_SPACE_SHADOW_LOW_RESOLUTION", true);
|
||||
}
|
||||
if (m_CurrentSettings.UseLowResolutionPCF)
|
||||
{
|
||||
CoreUtils.SetKeyword(cmd, "_SCREEN_SPACE_SHADOW_LOW_RESOLUTION_PCF", true);
|
||||
}
|
||||
|
||||
Blitter.BlitCameraTexture(cmd, m_RenderTarget, m_RenderTarget, m_Material, 0);
|
||||
CoreUtils.SetKeyword(cmd, ShaderKeywordStrings.MainLightShadows, false);
|
||||
if (!m_CurrentSettings.UseLowResolutionPCF)
|
||||
{
|
||||
CoreUtils.SetKeyword(cmd, ShaderKeywordStrings.MainLightShadowCascades, false);
|
||||
}
|
||||
CoreUtils.SetKeyword(cmd, ShaderKeywordStrings.MainLightShadowScreen, true);
|
||||
}
|
||||
}
|
||||
@ -197,6 +219,8 @@ namespace UnityEngine.Rendering.Universal
|
||||
|
||||
// Before transparent object pass, force to disable screen space shadow of main light
|
||||
CoreUtils.SetKeyword(cmd, ShaderKeywordStrings.MainLightShadowScreen, false);
|
||||
CoreUtils.SetKeyword(cmd, "_SCREEN_SPACE_SHADOW_LOW_RESOLUTION", false);
|
||||
CoreUtils.SetKeyword(cmd, "_SCREEN_SPACE_SHADOW_LOW_RESOLUTION_PCF", false);
|
||||
|
||||
// then enable main light shadows with or without cascades
|
||||
CoreUtils.SetKeyword(cmd, ShaderKeywordStrings.MainLightShadows, receiveShadowsNoCascade);
|
||||
|
||||
8
Packages/com.unity.render-pipelines.universal@14.0.11/Runtime/XRenderFeatures.meta
vendored
Normal file
8
Packages/com.unity.render-pipelines.universal@14.0.11/Runtime/XRenderFeatures.meta
vendored
Normal file
@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 913cc152ad5580044a896b67a4ede544
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
8
Packages/com.unity.render-pipelines.universal@14.0.11/Runtime/XRenderFeatures/Shaders.meta
vendored
Normal file
8
Packages/com.unity.render-pipelines.universal@14.0.11/Runtime/XRenderFeatures/Shaders.meta
vendored
Normal file
@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a7b2a3b5af500254190b654e11e07ac7
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@ -0,0 +1,109 @@
|
||||
Shader "Unlit/SoftShadowMask"
|
||||
{
|
||||
SubShader
|
||||
{
|
||||
Pass
|
||||
{
|
||||
ZTest Always
|
||||
ZWrite Off
|
||||
Cull Off
|
||||
|
||||
HLSLPROGRAM
|
||||
#pragma vertex vert
|
||||
#pragma fragment frag
|
||||
|
||||
#pragma enable_d3d11_debug_symbols
|
||||
#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Common.hlsl"
|
||||
#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/CommonMaterial.hlsl"
|
||||
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Shadows.hlsl"
|
||||
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/DeclareDepthTexture.hlsl"
|
||||
|
||||
#pragma multi_compile _MAIN_LIGHT_SHADOWS _MAIN_LIGHT_SHADOWS_CASCADE
|
||||
|
||||
#pragma multi_compile_fragment _ _Use16Samples
|
||||
|
||||
struct Varyings
|
||||
{
|
||||
float2 uv : TEXCOORD0;
|
||||
float4 vertex : SV_POSITION;
|
||||
};
|
||||
|
||||
Varyings vert(uint vertexID: SV_VertexID)
|
||||
{
|
||||
Varyings o;
|
||||
o.vertex = GetFullScreenTriangleVertexPosition(vertexID);
|
||||
o.uv = GetFullScreenTriangleTexCoord(vertexID);
|
||||
return o;
|
||||
}
|
||||
|
||||
#ifdef _Use16Samples
|
||||
float4 _Offset16[8];
|
||||
#else
|
||||
float4 _Offset5[2];
|
||||
#endif
|
||||
|
||||
half GetDepth(float2 uv)
|
||||
{
|
||||
#if UNITY_REVERSED_Z
|
||||
float deviceDepth = SAMPLE_TEXTURE2D_X(_CameraDepthTexture, sampler_PointClamp, uv).r;
|
||||
#else
|
||||
float deviceDepth = SAMPLE_TEXTURE2D_X(_CameraDepthTexture, sampler_PointClamp, uv).r;
|
||||
deviceDepth = deviceDepth * 2.0 - 1.0;
|
||||
#endif
|
||||
return deviceDepth;
|
||||
}
|
||||
|
||||
half frag(Varyings input) : SV_Target
|
||||
{
|
||||
float2 uv = input.uv;
|
||||
|
||||
//Fetch shadow coordinates for cascade.
|
||||
float3 wpos = ComputeWorldSpacePosition(uv, GetDepth(uv), unity_MatrixInvVP);
|
||||
float4 coords = TransformWorldToShadowCoord(wpos);
|
||||
|
||||
if(BEYOND_SHADOW_FAR(coords))
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
half shadow = SAMPLE_TEXTURE2D_SHADOW(_MainLightShadowmapTexture, sampler_LinearClampCompare,
|
||||
coords.xyz);
|
||||
#ifdef _Use16Samples
|
||||
for (int i = 0; i < 8; ++i)
|
||||
{
|
||||
uv = input.uv+ _Offset16[i].xy;
|
||||
wpos = ComputeWorldSpacePosition(uv, GetDepth(uv), unity_MatrixInvVP);
|
||||
coords = TransformWorldToShadowCoord(wpos);
|
||||
shadow += BEYOND_SHADOW_FAR(coords) ? 1 : SAMPLE_TEXTURE2D_SHADOW(_MainLightShadowmapTexture, sampler_LinearClampCompare,coords.xyz);
|
||||
|
||||
uv = input.uv+ _Offset16[i].zw;
|
||||
wpos = ComputeWorldSpacePosition(uv, GetDepth(uv), unity_MatrixInvVP);
|
||||
coords = TransformWorldToShadowCoord(wpos);
|
||||
shadow += BEYOND_SHADOW_FAR(coords) ? 1 : SAMPLE_TEXTURE2D_SHADOW(_MainLightShadowmapTexture, sampler_LinearClampCompare, coords.xyz );
|
||||
}
|
||||
#else
|
||||
for (int i = 0; i < 2; ++i)
|
||||
{
|
||||
uv = input.uv + _Offset5[i].xy;
|
||||
wpos = ComputeWorldSpacePosition(uv, GetDepth(uv), unity_MatrixInvVP);
|
||||
coords = TransformWorldToShadowCoord(wpos);
|
||||
|
||||
shadow += BEYOND_SHADOW_FAR(coords) ? 1 : SAMPLE_TEXTURE2D_SHADOW(_MainLightShadowmapTexture, sampler_LinearClampCompare,
|
||||
coords.xyz);
|
||||
uv = input.uv + _Offset5[i].zw;
|
||||
wpos = ComputeWorldSpacePosition(uv, GetDepth(uv), unity_MatrixInvVP);
|
||||
coords = TransformWorldToShadowCoord(wpos);
|
||||
|
||||
shadow += BEYOND_SHADOW_FAR(coords) ? 1 : SAMPLE_TEXTURE2D_SHADOW(_MainLightShadowmapTexture, sampler_LinearClampCompare,
|
||||
coords.xyz);
|
||||
}
|
||||
|
||||
shadow *= 0.2f;
|
||||
#endif
|
||||
|
||||
return shadow;
|
||||
}
|
||||
ENDHLSL
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,9 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 9e7a31ad298da624eb60b9e1f9dcd787
|
||||
ShaderImporter:
|
||||
externalObjects: {}
|
||||
defaultTextures: []
|
||||
nonModifiableTextures: []
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@ -0,0 +1,33 @@
|
||||
%YAML 1.1
|
||||
%TAG !u! tag:unity3d.com,2011:
|
||||
--- !u!21 &2100000
|
||||
Material:
|
||||
serializedVersion: 8
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_Name: Unlit_SoftShadowMask
|
||||
m_Shader: {fileID: 4800000, guid: 9e7a31ad298da624eb60b9e1f9dcd787, type: 3}
|
||||
m_Parent: {fileID: 0}
|
||||
m_ModifiedSerializedProperties: 0
|
||||
m_ValidKeywords: []
|
||||
m_InvalidKeywords: []
|
||||
m_LightmapFlags: 4
|
||||
m_EnableInstancingVariants: 0
|
||||
m_DoubleSidedGI: 0
|
||||
m_CustomRenderQueue: -1
|
||||
stringTagMap: {}
|
||||
disabledShaderPasses: []
|
||||
m_LockedProperties:
|
||||
m_SavedProperties:
|
||||
serializedVersion: 3
|
||||
m_TexEnvs:
|
||||
- _MainTex:
|
||||
m_Texture: {fileID: 0}
|
||||
m_Scale: {x: 1, y: 1}
|
||||
m_Offset: {x: 0, y: 0}
|
||||
m_Ints: []
|
||||
m_Floats: []
|
||||
m_Colors: []
|
||||
m_BuildTextureStacks: []
|
||||
@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1368366248809f24e9a110be3075d1b8
|
||||
NativeFormatImporter:
|
||||
externalObjects: {}
|
||||
mainObjectFileID: 2100000
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
104
Packages/com.unity.render-pipelines.universal@14.0.11/Runtime/XRenderFeatures/SoftShadowMask.cs
vendored
Normal file
104
Packages/com.unity.render-pipelines.universal@14.0.11/Runtime/XRenderFeatures/SoftShadowMask.cs
vendored
Normal file
@ -0,0 +1,104 @@
|
||||
using System;
|
||||
using Unity.Mathematics;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Rendering;
|
||||
using UnityEngine.Rendering.Universal;
|
||||
|
||||
namespace X.Rendering.Feature
|
||||
{
|
||||
public class SoftShadowMask : ScriptableRendererFeature
|
||||
{
|
||||
[Serializable]
|
||||
private class Settings
|
||||
{
|
||||
public bool BlurMask = false;
|
||||
public bool Use16Samples = true;
|
||||
public Material MaskMat = null;
|
||||
public Material BlurMat = null;
|
||||
}
|
||||
|
||||
[SerializeField]
|
||||
private Settings settings = new();
|
||||
SoftShadowMaskPass shadowMaskPass;
|
||||
|
||||
public override void Create()
|
||||
{
|
||||
shadowMaskPass = new(settings);
|
||||
}
|
||||
|
||||
public override void AddRenderPasses(ScriptableRenderer renderer, ref RenderingData renderingData)
|
||||
{
|
||||
renderer.EnqueuePass(shadowMaskPass);
|
||||
}
|
||||
|
||||
|
||||
class SoftShadowMaskPass : ScriptableRenderPass
|
||||
{
|
||||
internal static readonly int SoftShadowMaskTextureId = Shader.PropertyToID("_SoftShadowMaskTexture");
|
||||
internal static readonly GlobalKeyword softShadowMaskKeyword = GlobalKeyword.Create("_SOFTSHADOW_MASK");
|
||||
|
||||
private Settings settings;
|
||||
private ProfilingSampler profiler;
|
||||
Vector4[] offset16Array = new Vector4[8];
|
||||
Vector4[] offset5Array = new Vector4[2];
|
||||
RTHandle softShadowMask;
|
||||
|
||||
public SoftShadowMaskPass(Settings settings)
|
||||
{
|
||||
this.settings = settings;
|
||||
renderPassEvent = RenderPassEvent.AfterRenderingPrePasses;
|
||||
profiler = new(nameof(SoftShadowMaskPass));
|
||||
}
|
||||
|
||||
public override void Execute(ScriptableRenderContext context, ref RenderingData renderingData)
|
||||
{
|
||||
var cmd = renderingData.commandBuffer;
|
||||
using var scp = new ProfilingScope(cmd, profiler);
|
||||
cmd.EnableKeyword(softShadowMaskKeyword);
|
||||
var w = renderingData.cameraData.cameraTargetDescriptor.width;
|
||||
var h = renderingData.cameraData.cameraTargetDescriptor.height;
|
||||
float2 wh = new float2 { x = w, y = h };
|
||||
if (settings.Use16Samples)
|
||||
{
|
||||
cmd.EnableShaderKeyword("_Use16Samples");
|
||||
for (int i = 0; i < 8; ++i)
|
||||
{
|
||||
|
||||
}
|
||||
cmd.SetGlobalVectorArray("_Offset16", offset16Array);
|
||||
}
|
||||
else
|
||||
{
|
||||
cmd.DisableShaderKeyword("_Use16Samples");
|
||||
for (int i = 0; i < 2; ++i)
|
||||
{
|
||||
|
||||
offset5Array[i] = new float4(new float2(-1, 1) / wh, new float2(1, 1) / wh);
|
||||
offset5Array[i] = new float4(new float2(-1, -1) / wh, new float2(1, -1) / wh);
|
||||
}
|
||||
cmd.SetGlobalVectorArray("_Offset5", offset5Array);
|
||||
}
|
||||
RenderingUtils.ReAllocateIfNeeded(ref softShadowMask, new RenderTextureDescriptor()
|
||||
{
|
||||
bindMS = false,
|
||||
colorFormat = RenderTextureFormat.R8,
|
||||
width = w / 4,
|
||||
height = h / 4,
|
||||
enableRandomWrite = false,
|
||||
depthBufferBits = 0,
|
||||
dimension = TextureDimension.Tex2D,
|
||||
msaaSamples = 1,
|
||||
});
|
||||
cmd.SetRenderTarget(softShadowMask);
|
||||
cmd.DrawProcedural(Matrix4x4.identity, settings.MaskMat, 0, MeshTopology.Triangles, 3);
|
||||
cmd.SetGlobalTexture(SoftShadowMaskTextureId, softShadowMask);
|
||||
}
|
||||
|
||||
public override void OnFinishCameraStackRendering(CommandBuffer cmd)
|
||||
{
|
||||
base.OnFinishCameraStackRendering(cmd);
|
||||
cmd.DisableKeyword(softShadowMaskKeyword);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: eab40a9966087544f860c63893896a09
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user