Boat Attack使用了Universal RP的许多新图形功能,可以用于探索 Universal RP 的使用方式和技巧。
您最多选择25个主题 主题必须以中文或者字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
 
 
 

255 行
11 KiB

using System;
using System.Collections.Generic;
using Unity.Collections;
using UnityEngine.Scripting.APIUpdating;
using UnityEngine.Experimental.GlobalIllumination;
using Lightmapping = UnityEngine.Experimental.GlobalIllumination.Lightmapping;
namespace UnityEngine.Rendering.Universal
{
[MovedFrom("UnityEngine.Rendering.LWRP")] public enum MixedLightingSetup
{
None,
ShadowMask,
Subtractive,
};
[MovedFrom("UnityEngine.Rendering.LWRP")] public struct RenderingData
{
public CullingResults cullResults;
public CameraData cameraData;
public LightData lightData;
public ShadowData shadowData;
public PostProcessingData postProcessingData;
public bool supportsDynamicBatching;
public PerObjectData perObjectData;
public bool killAlphaInFinalBlit;
}
[MovedFrom("UnityEngine.Rendering.LWRP")] public struct LightData
{
public int mainLightIndex;
public int additionalLightsCount;
public int maxPerObjectAdditionalLightsCount;
public NativeArray<VisibleLight> visibleLights;
public bool shadeAdditionalLightsPerVertex;
public bool supportsMixedLighting;
}
[MovedFrom("UnityEngine.Rendering.LWRP")] public struct CameraData
{
public Camera camera;
public RenderTextureDescriptor cameraTargetDescriptor;
public float renderScale;
public bool isSceneViewCamera;
public bool isDefaultViewport;
public bool isHdrEnabled;
public bool requiresDepthTexture;
public bool requiresOpaqueTexture;
public SortingCriteria defaultOpaqueSortFlags;
public bool isStereoEnabled;
public float maxShadowDistance;
public bool postProcessEnabled;
#if POST_PROCESSING_STACK_2_0_0_OR_NEWER
[Obsolete("The use of the Post-processing Stack V2 is deprecated in the Universal Render Pipeline. Use the builtin post-processing effects instead.")]
public UnityEngine.Rendering.PostProcessing.PostProcessLayer postProcessLayer;
#endif
public IEnumerator<Action<RenderTargetIdentifier, CommandBuffer>> captureActions;
public LayerMask volumeLayerMask;
public Transform volumeTrigger;
public bool isStopNaNEnabled;
public bool isDitheringEnabled;
public AntialiasingMode antialiasing;
public AntialiasingQuality antialiasingQuality;
}
[MovedFrom("UnityEngine.Rendering.LWRP")] public struct ShadowData
{
public bool supportsMainLightShadows;
public bool requiresScreenSpaceShadowResolve;
public int mainLightShadowmapWidth;
public int mainLightShadowmapHeight;
public int mainLightShadowCascadesCount;
public Vector3 mainLightShadowCascadesSplit;
public bool supportsAdditionalLightShadows;
public int additionalLightsShadowmapWidth;
public int additionalLightsShadowmapHeight;
public bool supportsSoftShadows;
public int shadowmapDepthBufferBits;
public List<Vector4> bias;
}
public struct PostProcessingData
{
public ColorGradingMode gradingMode;
public int lutSize;
}
public static class ShaderKeywordStrings
{
public static readonly string MainLightShadows = "_MAIN_LIGHT_SHADOWS";
public static readonly string MainLightShadowCascades = "_MAIN_LIGHT_SHADOWS_CASCADE";
public static readonly string AdditionalLightsVertex = "_ADDITIONAL_LIGHTS_VERTEX";
public static readonly string AdditionalLightsPixel = "_ADDITIONAL_LIGHTS";
public static readonly string AdditionalLightShadows = "_ADDITIONAL_LIGHT_SHADOWS";
public static readonly string SoftShadows = "_SHADOWS_SOFT";
public static readonly string MixedLightingSubtractive = "_MIXED_LIGHTING_SUBTRACTIVE";
public static readonly string DepthNoMsaa = "_DEPTH_NO_MSAA";
public static readonly string DepthMsaa2 = "_DEPTH_MSAA_2";
public static readonly string DepthMsaa4 = "_DEPTH_MSAA_4";
public static readonly string LinearToSRGBConversion = "_LINEAR_TO_SRGB_CONVERSION";
public static readonly string KillAlpha = "_KILL_ALPHA";
public static readonly string SmaaLow = "_SMAA_PRESET_LOW";
public static readonly string SmaaMedium = "_SMAA_PRESET_MEDIUM";
public static readonly string SmaaHigh = "_SMAA_PRESET_HIGH";
public static readonly string PaniniGeneric = "_GENERIC";
public static readonly string PaniniUnitDistance = "_UNIT_DISTANCE";
public static readonly string BloomLQ = "_BLOOM_LQ";
public static readonly string BloomHQ = "_BLOOM_HQ";
public static readonly string BloomLQDirt = "_BLOOM_LQ_DIRT";
public static readonly string BloomHQDirt = "_BLOOM_HQ_DIRT";
public static readonly string UseRGBM = "_USE_RGBM";
public static readonly string Distortion = "_DISTORTION";
public static readonly string ChromaticAberration = "_CHROMATIC_ABERRATION";
public static readonly string HDRGrading = "_HDR_GRADING";
public static readonly string TonemapACES = "_TONEMAP_ACES";
public static readonly string TonemapNeutral = "_TONEMAP_NEUTRAL";
public static readonly string FilmGrain = "_FILM_GRAIN";
public static readonly string Fxaa = "_FXAA";
public static readonly string Dithering = "_DITHERING";
public static readonly string HighQualitySampling = "_HIGH_QUALITY_SAMPLING";
}
public sealed partial class UniversalRenderPipeline
{
static List<Vector4> m_ShadowBiasData = new List<Vector4>();
public static bool IsStereoEnabled(Camera camera)
{
if (camera == null)
throw new ArgumentNullException("camera");
bool isGameCamera = camera.cameraType == CameraType.Game || camera.cameraType == CameraType.VR;
return XRGraphics.enabled && isGameCamera && (camera.stereoTargetEye == StereoTargetEyeMask.Both);
}
void SortCameras(Camera[] cameras)
{
Array.Sort(cameras, (lhs, rhs) => (int)(lhs.depth - rhs.depth));
}
static RenderTextureDescriptor CreateRenderTextureDescriptor(Camera camera, float renderScale,
bool isStereoEnabled, bool isHdrEnabled, int msaaSamples, bool needsAlpha)
{
RenderTextureDescriptor desc;
RenderTextureFormat renderTextureFormatDefault = RenderTextureFormat.Default;
if (isStereoEnabled)
{
desc = XRGraphics.eyeTextureDesc;
renderTextureFormatDefault = desc.colorFormat;
}
else
{
desc = new RenderTextureDescriptor(camera.pixelWidth, camera.pixelHeight);
desc.width = (int)((float)desc.width * renderScale);
desc.height = (int)((float)desc.height * renderScale);
}
bool use32BitHDR = !needsAlpha && RenderingUtils.SupportsRenderTextureFormat(RenderTextureFormat.RGB111110Float);
RenderTextureFormat hdrFormat = (use32BitHDR) ? RenderTextureFormat.RGB111110Float : RenderTextureFormat.DefaultHDR;
if (camera.targetTexture != null)
{
desc.colorFormat = camera.targetTexture.descriptor.colorFormat;
desc.depthBufferBits = camera.targetTexture.descriptor.depthBufferBits;
desc.msaaSamples = camera.targetTexture.descriptor.msaaSamples;
desc.sRGB = camera.targetTexture.descriptor.sRGB;
}
else
{
desc.colorFormat = isHdrEnabled ? hdrFormat : renderTextureFormatDefault;
desc.depthBufferBits = 32;
desc.msaaSamples = msaaSamples;
desc.sRGB = (QualitySettings.activeColorSpace == ColorSpace.Linear);
}
desc.enableRandomWrite = false;
desc.bindMS = false;
desc.useDynamicScale = camera.allowDynamicResolution;
return desc;
}
static Lightmapping.RequestLightsDelegate lightsDelegate = (Light[] requests, NativeArray<LightDataGI> lightsOutput) =>
{
// Editor only.
#if UNITY_EDITOR
LightDataGI lightData = new LightDataGI();
for (int i = 0; i < requests.Length; i++)
{
Light light = requests[i];
switch (light.type)
{
case LightType.Directional:
DirectionalLight directionalLight = new DirectionalLight();
LightmapperUtils.Extract(light, ref directionalLight);
lightData.Init(ref directionalLight);
break;
case LightType.Point:
PointLight pointLight = new PointLight();
LightmapperUtils.Extract(light, ref pointLight);
lightData.Init(ref pointLight);
break;
case LightType.Spot:
SpotLight spotLight = new SpotLight();
LightmapperUtils.Extract(light, ref spotLight);
spotLight.innerConeAngle = light.innerSpotAngle * Mathf.Deg2Rad;
spotLight.angularFalloff = AngularFalloffType.AnalyticAndInnerAngle;
lightData.Init(ref spotLight);
break;
case LightType.Area:
RectangleLight rectangleLight = new RectangleLight();
LightmapperUtils.Extract(light, ref rectangleLight);
rectangleLight.mode = LightMode.Baked;
lightData.Init(ref rectangleLight);
break;
case LightType.Disc:
DiscLight discLight = new DiscLight();
LightmapperUtils.Extract(light, ref discLight);
discLight.mode = LightMode.Baked;
lightData.Init(ref discLight);
break;
default:
lightData.InitNoBake(light.GetInstanceID());
break;
}
lightData.falloff = FalloffType.InverseSquared;
lightsOutput[i] = lightData;
}
#else
LightDataGI lightData = new LightDataGI();
for (int i = 0; i < requests.Length; i++)
{
Light light = requests[i];
lightData.InitNoBake(light.GetInstanceID());
lightsOutput[i] = lightData;
}
Debug.LogWarning("Realtime GI is not supported in Universal Pipeline.");
#endif
};
}
}