81 lines
2.8 KiB
C#
81 lines
2.8 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using UnityEngine.Rendering;
|
|
using UnityEngine.Rendering.Universal;
|
|
|
|
namespace NiloToon.NiloToonURP
|
|
{
|
|
/// <summary>
|
|
/// Contains properties and helper functions that you can use when rendering.
|
|
/// </summary>
|
|
public static class NiloToonRenderingUtils
|
|
{
|
|
static Mesh s_FullscreenMesh = null;
|
|
|
|
/// <summary>
|
|
/// Returns a mesh that you can use with <see cref="CommandBuffer.DrawMesh(Mesh, Matrix4x4, Material)"/> to render full-screen effects.
|
|
/// </summary>
|
|
public static Mesh fullscreenMesh
|
|
{
|
|
// [NiloToon]
|
|
// Copy from URP 14.0.9's RenderingUtils.cs
|
|
get
|
|
{
|
|
if (s_FullscreenMesh != null)
|
|
return s_FullscreenMesh;
|
|
|
|
float topV = 1.0f;
|
|
float bottomV = 0.0f;
|
|
|
|
s_FullscreenMesh = new Mesh { name = "Fullscreen Quad" };
|
|
s_FullscreenMesh.SetVertices(new List<Vector3>
|
|
{
|
|
new Vector3(-1.0f, -1.0f, 0.0f),
|
|
new Vector3(-1.0f, 1.0f, 0.0f),
|
|
new Vector3(1.0f, -1.0f, 0.0f),
|
|
new Vector3(1.0f, 1.0f, 0.0f)
|
|
});
|
|
|
|
s_FullscreenMesh.SetUVs(0, new List<Vector2>
|
|
{
|
|
new Vector2(0.0f, bottomV),
|
|
new Vector2(0.0f, topV),
|
|
new Vector2(1.0f, bottomV),
|
|
new Vector2(1.0f, topV)
|
|
});
|
|
|
|
s_FullscreenMesh.SetIndices(new[] { 0, 1, 2, 2, 1, 3 }, MeshTopology.Triangles, 0, false);
|
|
s_FullscreenMesh.UploadMeshData(true);
|
|
return s_FullscreenMesh;
|
|
}
|
|
}
|
|
|
|
public static void DrawRendererListOrRenderers(
|
|
ScriptableRenderContext context,
|
|
CommandBuffer cmd,
|
|
CullingResults cullResults,
|
|
ref DrawingSettings drawingSettings,
|
|
ref FilteringSettings filteringSettings)
|
|
{
|
|
#if UNITY_6000_0_OR_NEWER
|
|
var rendererListParams = new RendererListParams(cullResults, drawingSettings, filteringSettings);
|
|
var rendererList = context.CreateRendererList(ref rendererListParams);
|
|
cmd.DrawRendererList(rendererList);
|
|
#else
|
|
context.DrawRenderers(cullResults, ref drawingSettings, ref filteringSettings);
|
|
#endif
|
|
}
|
|
|
|
public static void DrawRendererListOrRenderers(
|
|
ScriptableRenderContext context,
|
|
CommandBuffer cmd,
|
|
ref RenderingData renderingData,
|
|
ref DrawingSettings drawingSettings,
|
|
ref FilteringSettings filteringSettings)
|
|
{
|
|
DrawRendererListOrRenderers(context, cmd, renderingData.cullResults, ref drawingSettings, ref filteringSettings);
|
|
}
|
|
}
|
|
}
|