Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
timchen1002
CustomSRP_10_PointAndSpotShadows
提交
3174debb
C
CustomSRP_10_PointAndSpotShadows
项目概览
timchen1002
/
CustomSRP_10_PointAndSpotShadows
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
C
CustomSRP_10_PointAndSpotShadows
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
3174debb
编写于
9月 18, 2021
作者:
timchen1002
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
update
上级
68008b0e
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
58 addition
and
5 deletion
+58
-5
Assets/Custom RP.asset
Assets/Custom RP.asset
+3
-0
Assets/Custom RP/Runtime/Shadows.cs
Assets/Custom RP/Runtime/Shadows.cs
+54
-4
Assets/Scenes/Baked Light.unity
Assets/Scenes/Baked Light.unity
+1
-1
未找到文件。
Assets/Custom RP.asset
浏览文件 @
3174debb
...
...
@@ -27,3 +27,6 @@ MonoBehaviour:
cascadeRatio3
:
0.5
cascadeFade
:
0.1
cascadeBlend
:
1
other
:
atlasSize
:
1024
filter
:
0
Assets/Custom RP/Runtime/Shadows.cs
浏览文件 @
3174debb
...
...
@@ -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>
...
...
Assets/Scenes/Baked Light.unity
浏览文件 @
3174debb
...
...
@@ -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.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录