提交 c4e702b9 编写于 作者: timchen1002's avatar timchen1002

update

上级 f25931c4
......@@ -16,7 +16,7 @@ MonoBehaviour:
useGPUInstancing: 1
useSRPBatcher: 1
shadows:
maxDistance: 12.06
maxDistance: 16
distanceFade: 0.1
directional:
atlasSize: 4096
......
......@@ -9,7 +9,7 @@ Material:
m_PrefabAsset: {fileID: 0}
m_Name: Lit Clip
m_Shader: {fileID: 4800000, guid: 6848ac66b88696c4ea2f1389e0877b8e, type: 3}
m_ShaderKeywords: _CLIPPING _RECEIVE_SHADOWS _SHADOWS_CLIP
m_ShaderKeywords: _CLIPPING _RECEIVE_SHADOWS _SHADOWS_DITHER
m_LightmapFlags: 4
m_EnableInstancingVariants: 1
m_DoubleSidedGI: 0
......@@ -44,7 +44,7 @@ Material:
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _MainTex:
m_Texture: {fileID: 0}
m_Texture: {fileID: 2800000, guid: 5c8805d759cc642b5845cd761592c0c0, type: 3}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _MetallicGlossMap:
......@@ -76,7 +76,7 @@ Material:
- _PremulAlpha: 0
- _PremulAlphax: 0
- _ReceiveShadows: 1
- _Shadows: 1
- _Shadows: 2
- _Smoothness: 0.5
- _SmoothnessTextureChannel: 0
- _SpecularHighlights: 1
......@@ -85,6 +85,6 @@ Material:
- _ZWrite: 1
m_Colors:
- _BaseColor: {r: 0.5, g: 0.5, b: 0.5, a: 1}
- _Color: {r: 1, g: 1, b: 1, a: 1}
- _Color: {r: 0.9647059, g: 0.7058823, b: 0.9921569, a: 1}
- _EmissionColor: {r: 0, g: 0, b: 0, a: 1}
m_BuildTextureStacks: []
......@@ -85,5 +85,5 @@ Material:
m_Colors:
- _BaseColor: {r: 0.5019608, g: 0.5019608, b: 0.5019608, a: 1}
- _Color: {r: 1, g: 1, b: 1, a: 1}
- _EmissionColor: {r: 1, g: 1, b: 1, a: 1}
- _EmissionColor: {r: 0, g: 1, b: 1, a: 1}
m_BuildTextureStacks: []
......@@ -83,7 +83,7 @@ Material:
- _UVSec: 0
- _ZWrite: 1
m_Colors:
- _BaseColor: {r: 0.14901961, g: 0.76470596, b: 0.15294118, a: 1}
- _Color: {r: 0.14901961, g: 0.76470596, b: 0.15294118, a: 1}
- _BaseColor: {r: 0.5019608, g: 0.5019608, b: 0.5019608, a: 1}
- _Color: {r: 0.5019608, g: 0.5019608, b: 0.5019608, a: 1}
- _EmissionColor: {r: 0, g: 0, b: 0, a: 1}
m_BuildTextureStacks: []
......@@ -44,7 +44,7 @@ Material:
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _MainTex:
m_Texture: {fileID: 0}
m_Texture: {fileID: 2800000, guid: 5c8805d759cc642b5845cd761592c0c0, type: 3}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _MetallicGlossMap:
......@@ -75,6 +75,7 @@ Material:
- _Parallax: 0.02
- _PremulAlpha: 1
- _PremulAlphax: 0
- _ReceiveShadows: 1
- _Shadows: 2
- _Smoothness: 0.5
- _SmoothnessTextureChannel: 0
......@@ -84,6 +85,6 @@ Material:
- _ZWrite: 0
m_Colors:
- _BaseColor: {r: 0.5, g: 0.5, b: 0.5, a: 1}
- _Color: {r: 1, g: 1, b: 1, a: 1}
- _Color: {r: 0.7294118, g: 0.8588236, b: 1, a: 1}
- _EmissionColor: {r: 0, g: 0, b: 0, a: 1}
m_BuildTextureStacks: []
此差异已折叠。
......@@ -47,7 +47,7 @@ LightingSettings:
m_LightProbeSampleCountMultiplier: 4
m_PVRBounces: 2
m_PVRMinBounces: 2
m_PVREnvironmentMIS: 1
m_PVREnvironmentMIS: 0
m_PVRFilteringMode: 2
m_PVRDenoiserTypeDirect: 0
m_PVRDenoiserTypeIndirect: 0
......
......@@ -67,10 +67,12 @@ public class MeshBall : MonoBehaviour
positions[i] = matrices[i].GetColumn(3);
}
var lightProbes = new SphericalHarmonicsL2[1023];
var occlusionProbes = new Vector4[1023];
LightProbes.CalculateInterpolatedLightAndOcclusionProbes(
positions, lightProbes, null
positions, lightProbes, occlusionProbes
);
block.CopySHCoefficientArraysFrom(lightProbes);
block.CopyProbeOcclusionArrayFrom(occlusionProbes);
}
}
// 绘制网格实例
......
......@@ -129,7 +129,7 @@ public partial class CameraRenderer
{
enableDynamicBatching = useDynamicBatching,
enableInstancing = useGPUInstancing,
perObjectData = PerObjectData.Lightmaps | PerObjectData.ShadowMask | PerObjectData.LightProbe | PerObjectData.LightProbeProxyVolume,
perObjectData = PerObjectData.Lightmaps | PerObjectData.ShadowMask | PerObjectData.LightProbe | PerObjectData.OcclusionProbe | PerObjectData.LightProbeProxyVolume,
};
// 渲染CustomLit表示的pass块
drawingSettings.SetShaderPassName(1, litShaderTagId);
......
......@@ -69,7 +69,8 @@ public class Shadows
};
static string[] shadowMaskKeywords =
{
"_SHADOW_MASK_DISTANCE"
"_SHADOW_MASK_ALWAYS",
"_SHADOW_MASK_DISTANCE",
};
public void Setup(ScriptableRenderContext context, CullingResults cullingResults, ShadowSettings shadowSettings)
......@@ -96,28 +97,35 @@ public class Shadows
/// <param name="light"></param>
/// <param name="visibleLightIndex"></param>
/// <returns></returns>
public Vector3 ReserveDirectionalShadows(Light light, int visibleLightIndex)
public Vector4 ReserveDirectionalShadows(Light light, int visibleLightIndex)
{
if (shadowedDirectionalLightCount < maxShadowedDirLightCount && light.shadows != LightShadows.None && light.shadowStrength > 0f && cullingResults.GetShadowCasterBounds(visibleLightIndex, out Bounds b))
if (shadowedDirectionalLightCount < maxShadowedDirLightCount && light.shadows != LightShadows.None && light.shadowStrength > 0f)
{
float maskChannel = -1;
// 如果使用了ShadowMask
LightBakingOutput lightBaking = light.bakingOutput;
if (lightBaking.lightmapBakeType == LightmapBakeType.Mixed && lightBaking.mixedLightingMode == MixedLightingMode.Shadowmask)
{
useShadowMask = true;
maskChannel = lightBaking.occlusionMaskChannel;
}
if (!cullingResults.GetShadowCasterBounds(visibleLightIndex, out Bounds b))
{
return new Vector4(-light.shadowStrength, 0f, 0f, maskChannel);
}
shadowedDirectionalLights[shadowedDirectionalLightCount] = new ShadowedDirectionalLight{
visibleLightIndex = visibleLightIndex,
slopeScaleBias = light.shadowBias,
nearPlaneOffset = light.shadowNearPlane
};
return new Vector3(
return new Vector4(
light.shadowStrength,
shadowSettings.directional.cascadeCount * shadowedDirectionalLightCount++,
light.shadowNormalBias
light.shadowNormalBias,
maskChannel
);
}
return Vector3.zero;
return new Vector4(0f, 0f, 0f, -1f);
}
/// <summary>
......
......@@ -13,6 +13,10 @@
#define UNITY_MATRIX_VP unity_MatrixVP
#define UNITY_MATRIX_P glstate_matrix_projection
#if defined(_SHADOW_MASK_ALWAYS) || defined(_SHADOW_MASK_DISTANCE)
#define SHADOWS_SHADOWMASK
#endif
#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/UnityInstancing.hlsl"
#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/SpaceTransforms.hlsl"
......
......@@ -85,13 +85,29 @@ float3 SampleLightProbe(Surface surfaceWS)
#endif
}
// 采样灯光遮挡探针
float4 SampleLightProbeOcclusion()
{
return unity_ProbesOcclusion;
}
// 采样shadowMask得到烘焙阴影数据
float4 SampleBakedShadows(float2 lightMapUV)
float4 SampleBakedShadows(float2 lightMapUV, Surface surfaceWS)
{
#if defined(LIGHTMAP_ON)
return SAMPLE_TEXTURE2D(unity_ShadowMask, samplerunity_ShadowMask, lightMapUV);
#else
return 1.0;
if (unity_ProbeVolumeParams.x) {
return SampleProbeOcclusion(
TEXTURE3D_ARGS(unity_ProbeVolumeSH, samplerunity_ProbeVolumeSH),
surfaceWS.position, unity_ProbeVolumeWorldToObject,
unity_ProbeVolumeParams.y, unity_ProbeVolumeParams.z,
unity_ProbeVolumeMin.xyz, unity_ProbeVolumeSizeInv.xyz
);
}
else {
return unity_ProbesOcclusion;
}
#endif
}
......@@ -99,11 +115,15 @@ GI GetGI(float2 lightMapUV, Surface surfaceWS)
{
GI gi;
gi.diffuse = SampleLightMap(lightMapUV) + SampleLightProbe(surfaceWS);
gi.shadowMask.always = false;
gi.shadowMask.distance = false;
gi.shadowMask.shadows = 1.0;
#if defined(_SHADOW_MASK_DISTANCE)
#if defined(_SHADOW_MASK_ALWAYS)
gi.shadowMask.always = true;
gi.shadowMask.shadows = SampleBakedShadows(lightMapUV, surfaceWS);
#elif defined(_SHADOW_MASK_DISTANCE)
gi.shadowMask.distance = true;
gi.shadowMask.shadows = SampleBakedShadows(lightMapUV);
gi.shadowMask.shadows = SampleBakedShadows(lightMapUV, surfaceWS);
#endif
return gi;
}
......
......@@ -31,9 +31,10 @@ int GetDirectionalLightCount()
DirectionalShadowData GetDirectionalShadowData(int lightIndex, ShadowData shadowData)
{
DirectionalShadowData data;
data.strength = _DirectionalLightShadowData[lightIndex].x * shadowData.strength;
data.strength = _DirectionalLightShadowData[lightIndex].x;
data.tileIndex = _DirectionalLightShadowData[lightIndex].y + shadowData.cascadeIndex;
data.normalBias = _DirectionalLightShadowData[lightIndex].z;
data.shadowMaskChannel = _DirectionalLightShadowData[lightIndex].w;
return data;
}
......
......@@ -20,7 +20,6 @@ float3 GetLighting(Surface surfaceWS, BRDF brdf, GI gi)
// 得到表面阴影数据
ShadowData shadowData = GetShadowData(surfaceWS);
shadowData.shadowMask = gi.shadowMask;
// return gi.shadowMask.shadows.rgb;
// 可见光的光照结果进行累加得到最终光照结果
float3 color = gi.diffuse * brdf.diffuse;
......
......@@ -48,11 +48,13 @@ struct DirectionalShadowData
int tileIndex;
// 法线偏差
float normalBias;
int shadowMaskChannel;
};
// 烘焙阴影数据
struct ShadowMask
{
bool always;
bool distance;
float4 shadows;
};
......@@ -100,17 +102,50 @@ float FilterDirectionalShadow(float3 positionSTS)
#endif
}
// 获取阴影的衰减
float GetDirectionalShadowAttenuation(DirectionalShadowData directional, ShadowData global, Surface surfaceWS)
// 获取烘焙阴影的衰减值
float GetBakedShadow(ShadowMask mask, int channel)
{
// 如果不接受阴影,阴影衰减为1
#if !defined(_RECEIVE_SHADOWS)
return 1.0;
#endif
if (directional.strength <= 0.0)
float shadow = 1.0;
if (mask.always || mask.distance)
{
return 1.0;
if (channel > 0)
{
shadow = mask.shadows[channel];
}
}
return shadow;
}
float GetBakedShadow(ShadowMask mask, int channel, float strength)
{
if (mask.always || mask.distance)
{
return lerp(1.0, GetBakedShadow(mask, channel), strength);
}
return 1.0;
}
// 混合烘焙和实时阴影
float MixBakedAndRealtimeShadows(ShadowData global, float shadow, int shadowMaskChannel, float strength)
{
float baked = GetBakedShadow(global.shadowMask, shadowMaskChannel);
if (global.shadowMask.always)
{
shadow = lerp(1.0, shadow, global.strength);
shadow = min(baked, shadow);
return lerp(1.0, shadow, strength);
}
if (global.shadowMask.distance)
{
shadow = lerp(baked, shadow, global.strength);
return lerp(1.0, shadow, strength);
}
return lerp(1.0, shadow, strength * global.strength);
}
// 获取级联阴影
float GetCascadedShadow(DirectionalShadowData directional, ShadowData global, Surface surfaceWS)
{
// 计算法线偏移
float3 normalBias = surfaceWS.normal * (directional.normalBias * _CascadeData[global.cascadeIndex].y);
float3 positionSTS = mul(
......@@ -128,8 +163,29 @@ float GetDirectionalShadowAttenuation(DirectionalShadowData directional, ShadowD
).xyz;
shadow = lerp(FilterDirectionalShadow(positionSTS), shadow, global.cascadeBlend);
}
// 最终衰减结果是阴影强度和采样衰减的线性差值
return lerp(1.0, shadow, directional.strength);
return shadow;
}
// 获取阴影的衰减
float GetDirectionalShadowAttenuation(DirectionalShadowData directional, ShadowData global, Surface surfaceWS)
{
// 如果不接受阴影,阴影衰减为1
#if !defined(_RECEIVE_SHADOWS)
return 1.0;
#endif
float shadow;
if (directional.strength * global.strength <= 0.0)
{
shadow = GetBakedShadow(global.shadowMask, directional.shadowMaskChannel, abs(directional.strength));
}
else
{
shadow = GetCascadedShadow(directional, global, surfaceWS);
// 最终衰减结果是阴影强度和采样衰减的线性差值
shadow = MixBakedAndRealtimeShadows(global, shadow, directional.shadowMaskChannel, directional.strength);
}
return shadow;
}
// 公式计算阴影过渡时的强度
......@@ -142,6 +198,7 @@ float FadedShadowStrength(float distance, float scale, float fade)
ShadowData GetShadowData(Surface surfaceWS)
{
ShadowData data;
data.shadowMask.always= false;
data.shadowMask.distance = false;
data.shadowMask.shadows = 1.0;
data.cascadeBlend = 1.0;
......
......@@ -9,6 +9,8 @@ CBUFFER_START(UnityPerDraw)
// 这个矩阵包含一些在这里我们不需要的转换信息
real4 unity_WorldTransformParams;
float4 unity_ProbesOcclusion;
float4 unity_LightmapST;
float4 unity_DynamicLightmapST;
......
......@@ -56,7 +56,7 @@ Shader "Custom RP/Lit"
#pragma shader_feature _PREMULTIPLY_ALPHA
#pragma multi_compile _ _DIRECTIONAL_PCF3 _DIRECTIONAL_PCF5 _DIRECTIONAL_PCF7
#pragma multi_compile _ _CASCADE_BLEND_SOFT _CASCADE_BLEND_DITHER
#pragma multi_compile _ _SHADOW_MASK_DISTANCE
#pragma multi_compile _ _SHADOW_MASK_ALWAYS _SHADOW_MASK_DISTANCE
#pragma multi_compile _ LIGHTMAP_ON
#pragma multi_compile_instancing
#pragma vertex LitPassVertex
......
......@@ -18,7 +18,7 @@ QualitySettings:
shadowCascade2Split: 0.33333334
shadowCascade4Split: {x: 0.06666667, y: 0.2, z: 0.46666667}
shadowmaskMode: 0
blendWeights: 1
skinWeights: 1
textureQuality: 1
anisotropicTextures: 0
antiAliasing: 0
......@@ -40,6 +40,7 @@ QualitySettings:
asyncUploadBufferSize: 16
asyncUploadPersistentBuffer: 1
resolutionScalingFixedDPIFactor: 1
customRenderPipeline: {fileID: 0}
excludedTargetPlatforms: []
- serializedVersion: 2
name: Low
......@@ -53,7 +54,7 @@ QualitySettings:
shadowCascade2Split: 0.33333334
shadowCascade4Split: {x: 0.06666667, y: 0.2, z: 0.46666667}
shadowmaskMode: 0
blendWeights: 2
skinWeights: 2
textureQuality: 0
anisotropicTextures: 0
antiAliasing: 0
......@@ -75,6 +76,7 @@ QualitySettings:
asyncUploadBufferSize: 16
asyncUploadPersistentBuffer: 1
resolutionScalingFixedDPIFactor: 1
customRenderPipeline: {fileID: 0}
excludedTargetPlatforms: []
- serializedVersion: 2
name: Medium
......@@ -88,7 +90,7 @@ QualitySettings:
shadowCascade2Split: 0.33333334
shadowCascade4Split: {x: 0.06666667, y: 0.2, z: 0.46666667}
shadowmaskMode: 0
blendWeights: 2
skinWeights: 2
textureQuality: 0
anisotropicTextures: 1
antiAliasing: 0
......@@ -110,6 +112,7 @@ QualitySettings:
asyncUploadBufferSize: 16
asyncUploadPersistentBuffer: 1
resolutionScalingFixedDPIFactor: 1
customRenderPipeline: {fileID: 0}
excludedTargetPlatforms: []
- serializedVersion: 2
name: High
......@@ -123,7 +126,7 @@ QualitySettings:
shadowCascade2Split: 0.33333334
shadowCascade4Split: {x: 0.06666667, y: 0.2, z: 0.46666667}
shadowmaskMode: 1
blendWeights: 2
skinWeights: 2
textureQuality: 0
anisotropicTextures: 1
antiAliasing: 0
......@@ -145,6 +148,7 @@ QualitySettings:
asyncUploadBufferSize: 16
asyncUploadPersistentBuffer: 1
resolutionScalingFixedDPIFactor: 1
customRenderPipeline: {fileID: 0}
excludedTargetPlatforms: []
- serializedVersion: 2
name: Very High
......@@ -158,7 +162,7 @@ QualitySettings:
shadowCascade2Split: 0.33333334
shadowCascade4Split: {x: 0.06666667, y: 0.2, z: 0.46666667}
shadowmaskMode: 1
blendWeights: 4
skinWeights: 4
textureQuality: 0
anisotropicTextures: 2
antiAliasing: 2
......@@ -180,6 +184,7 @@ QualitySettings:
asyncUploadBufferSize: 16
asyncUploadPersistentBuffer: 1
resolutionScalingFixedDPIFactor: 1
customRenderPipeline: {fileID: 0}
excludedTargetPlatforms: []
- serializedVersion: 2
name: Ultra
......@@ -193,7 +198,7 @@ QualitySettings:
shadowCascade2Split: 0.33333334
shadowCascade4Split: {x: 0.06666667, y: 0.2, z: 0.46666667}
shadowmaskMode: 1
blendWeights: 4
skinWeights: 4
textureQuality: 0
anisotropicTextures: 2
antiAliasing: 2
......@@ -215,6 +220,7 @@ QualitySettings:
asyncUploadBufferSize: 16
asyncUploadPersistentBuffer: 1
resolutionScalingFixedDPIFactor: 1
customRenderPipeline: {fileID: 0}
excludedTargetPlatforms: []
m_PerPlatformDefaultQuality:
Android: 2
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册