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

update

上级 68008b0e
......@@ -27,3 +27,6 @@ MonoBehaviour:
cascadeRatio3: 0.5
cascadeFade: 0.1
cascadeBlend: 1
other:
atlasSize: 1024
filter: 0
......@@ -50,6 +50,8 @@ public class Shadows
public float slopeScaleBias;
// 法线偏差
public float normalBias;
// 是否是点光源
public bool isPoint;
}
// 存储可投身阴影的非定向光源的数据
......@@ -185,7 +187,10 @@ public class Shadows
useShadowMask = true;
maskChannel = lightBaking.occlusionMaskChannel;
}
if (shadowedOtherLightCount >= maxShadowedOtherLightCount || !cullingResults.GetShadowCasterBounds(visibleLightIndex, out Bounds b))
bool isPoint = light.type == LightType.Point;
int newLightCount = shadowedOtherLightCount + (isPoint ? 6 : 1);
if (newLightCount >= maxShadowedOtherLightCount || !cullingResults.GetShadowCasterBounds(visibleLightIndex, out Bounds b))
{
return new Vector4(-light.shadowStrength, 0f, 0f, maskChannel);
}
......@@ -193,9 +198,12 @@ public class Shadows
shadowedOtherLights[shadowedOtherLightCount] = new ShadowedOtherLight{
visibleLightIndex = visibleLightIndex,
slopeScaleBias = light.shadowBias,
normalBias = light.shadowNormalBias
normalBias = light.shadowNormalBias,
isPoint = isPoint
};
return new Vector4(light.shadowStrength, shadowedOtherLightCount++, 0f, maskChannel);
Vector4 data = new Vector4(light.shadowStrength, shadowedOtherLightCount++, isPoint ? 1f : 0f, maskChannel);
shadowedOtherLightCount = newLightCount;
return data;
}
/// <summary>
......@@ -301,7 +309,16 @@ public class Shadows
// 遍历所有光源渲染阴影贴图
for (int i = 0; i < shadowedOtherLightCount; i++)
{
RenderSpotShadows(i, split, tileSize);
if (shadowedOtherLights[i].isPoint)
{
RenderPointShadows(i, split, tileSize);
i += 6;
}
else
{
RenderSpotShadows(i, split, tileSize);
i += 1;
}
}
// 阴影转换矩阵传入GPU
......@@ -400,6 +417,39 @@ public class Shadows
buffer.SetGlobalDepthBias(0f, 0f);
}
/// <summary>
/// 渲染点光源阴影
/// </summary>
/// <param name="index"></param>
/// <param name="split"></param>
/// <param name="tileSize"></param>
void RenderPointShadows(int index, int split, int tileSize)
{
ShadowedOtherLight light = shadowedOtherLights[index];
var newShadowSettings = new ShadowDrawingSettings(cullingResults, light.visibleLightIndex);
for (int i = 0; i < 6; i++)
{
cullingResults.ComputePointShadowMatricesAndCullingPrimitives(light.visibleLightIndex, (CubemapFace)i, 0f, out Matrix4x4 viewMatrix, out Matrix4x4 projectionMatrix, out ShadowSplitData splitData);
newShadowSettings.splitData = splitData;
int tileIndex = index + i;
// 计算法线偏差
float texelSize = 2f / (tileSize * projectionMatrix.m00);
float filterSize = texelSize * ((float)shadowSettings.other.filter + 1f);
float bias = light.normalBias * filterSize * 1.4142136f;
Vector2 offset = SetTileViewport(tileIndex, split, tileSize);
float tileScale = 1f / split;
SetOtherTileData(tileIndex, offset, tileScale, bias);
otherShadowMatrices[tileIndex] = ConvertToAtlasMatrix(projectionMatrix * viewMatrix, offset, tileScale);
buffer.SetViewProjectionMatrices(viewMatrix, projectionMatrix);
buffer.SetGlobalDepthBias(0f, light.slopeScaleBias);
ExecuteBuffer();
context.DrawShadows(ref newShadowSettings);
buffer.SetGlobalDepthBias(0f, 0f);
}
}
/// <summary>
/// 存储非定向光阴影图块数据
/// </summary>
......
......@@ -6459,7 +6459,7 @@ Transform:
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1175923569}
m_LocalRotation: {x: -0.27148798, y: -0.8180644, z: 0.3949701, w: -0.31790495}
m_LocalPosition: {x: -6.62, y: 2.7, z: 2.75}
m_LocalPosition: {x: -8.16, y: 2.7, z: 2.13}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 0}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册