-
Notifications
You must be signed in to change notification settings - Fork 666
Expand file tree
/
Copy pathFGUIHDRPRenderPass.cs
More file actions
63 lines (53 loc) · 2.02 KB
/
FGUIHDRPRenderPass.cs
File metadata and controls
63 lines (53 loc) · 2.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
using UnityEngine.Rendering;
using UnityEngine;
#if HDRP
using UnityEngine.Rendering.HighDefinition;
#endif
#if HDRP
class FGUIHDRPRenderPass : CustomPass
{
public LayerMask layer;
Matrix4x4 worldToCameraMatrix;
Matrix4x4 projectionMatrix;
Matrix4x4 cullingMatrix;
Plane[] planes = new Plane[6];
public void ApplyChange(Transform stage)
{
var v3 = stage.position;
worldToCameraMatrix = Matrix4x4.TRS(-stage.position, Quaternion.identity, new Vector3(1, 1, -1));
projectionMatrix = Matrix4x4.TRS(Vector3.zero, Quaternion.identity, new Vector3(2 / (v3.x * 2 - 0), 2 / -(v3.y * 2 - 0), 0));
cullingMatrix = projectionMatrix * worldToCameraMatrix;
GeometryUtility.CalculateFrustumPlanes(cullingMatrix, planes);
}
protected override void Setup(ScriptableRenderContext renderContext, CommandBuffer cmd)
{
}
protected override void AggregateCullingParameters(ref ScriptableCullingParameters cullingParameters, HDCamera hdCamera)
{
if (hdCamera.camera.cameraType == CameraType.Game)
{
cullingParameters.cullingMask |= (uint)layer.value;
cullingParameters.origin = new Vector3(0, 0, -100);
cullingParameters.cullingMatrix = cullingMatrix;
for (int i = 0; i < 6; i++)
cullingParameters.SetCullingPlane(i, planes[i]);
}
}
protected override void Execute(CustomPassContext ctx)
{
if (ctx.hdCamera.camera.cameraType == CameraType.Game)
{
var pm = ctx.hdCamera.camera.projectionMatrix;
var vm = ctx.hdCamera.camera.worldToCameraMatrix;
ctx.cmd.SetViewProjectionMatrices(worldToCameraMatrix, projectionMatrix);
CustomPassUtils.DrawRenderers(ctx, layer);
CoreUtils.SetRenderTarget(ctx.cmd, ctx.cameraColorBuffer, ClearFlag.None);
//还原矩阵
ctx.cmd.SetViewProjectionMatrices(vm, pm);
}
}
protected override void Cleanup()
{
}
}
#endif