sebastien lagarde
6 年前
当前提交
c7b86128
共有 65 个文件被更改,包括 2409 次插入 和 928 次删除
-
35TestProjects/LWGraphicsTest/Packages/manifest.json
-
3TestProjects/LWGraphicsTest/ProjectSettings/EditorBuildSettings.asset
-
24com.unity.render-pipelines.high-definition/CHANGELOG.md
-
2com.unity.render-pipelines.high-definition/HDRP/RenderPipeline/HDRenderPipeline.cs
-
1com.unity.render-pipelines.lightweight/CHANGELOG.md
-
50com.unity.render-pipelines.lightweight/LWRP/LightweightConstantBuffer.cs
-
213com.unity.render-pipelines.lightweight/LWRP/LightweightForwardRenderer.cs
-
31com.unity.render-pipelines.lightweight/LWRP/LightweightPipeline.cs
-
49com.unity.render-pipelines.lightweight/LWRP/Passes/DepthOnlyPass.cs
-
28com.unity.render-pipelines.lightweight/LWRP/Passes/DirectionalShadowsPass.cs
-
579com.unity.render-pipelines.lightweight/LWRP/Passes/ForwardLitPass.cs
-
23com.unity.render-pipelines.lightweight/LWRP/Passes/LocalShadowsPass.cs
-
28com.unity.render-pipelines.lightweight/LWRP/Passes/ScreenSpaceShadowResolvePass.cs
-
82com.unity.render-pipelines.lightweight/LWRP/Passes/ScriptableRenderPass.cs
-
34TestProjects/LWGraphicsTest/Assets/ReferenceImages/Linear/OSXEditor/Metal/045_CustomLWPipe.png
-
88TestProjects/LWGraphicsTest/Assets/ReferenceImages/Linear/OSXEditor/Metal/045_CustomLWPipe.png.meta
-
36TestProjects/LWGraphicsTest/Assets/ReferenceImages/Linear/WindowsEditor/Direct3D11/045_CustomLWPipe.png
-
88TestProjects/LWGraphicsTest/Assets/ReferenceImages/Linear/WindowsEditor/Direct3D11/045_CustomLWPipe.png.meta
-
466TestProjects/LWGraphicsTest/Assets/Scenes/045_CustomLWPipe.unity
-
8TestProjects/LWGraphicsTest/Assets/Scenes/045_CustomLWPipe.unity.meta
-
206com.unity.render-pipelines.lightweight/LWRP/DefaultRendererSetup.cs
-
11com.unity.render-pipelines.lightweight/LWRP/DefaultRendererSetup.cs.meta
-
9com.unity.render-pipelines.lightweight/LWRP/IRendererSetup.cs
-
11com.unity.render-pipelines.lightweight/LWRP/IRendererSetup.cs.meta
-
12com.unity.render-pipelines.lightweight/LWRP/MaterialHandles.cs
-
11com.unity.render-pipelines.lightweight/LWRP/MaterialHandles.cs.meta
-
14com.unity.render-pipelines.lightweight/LWRP/Passes/BeginXRRenderingPass.cs
-
11com.unity.render-pipelines.lightweight/LWRP/Passes/BeginXRRenderingPass.cs.meta
-
70com.unity.render-pipelines.lightweight/LWRP/Passes/CopyColorPass.cs
-
11com.unity.render-pipelines.lightweight/LWRP/Passes/CopyColorPass.cs.meta
-
72com.unity.render-pipelines.lightweight/LWRP/Passes/CopyDepthPass.cs
-
11com.unity.render-pipelines.lightweight/LWRP/Passes/CopyDepthPass.cs.meta
-
69com.unity.render-pipelines.lightweight/LWRP/Passes/CreateLightweightRenderTexturesPass.cs
-
11com.unity.render-pipelines.lightweight/LWRP/Passes/CreateLightweightRenderTexturesPass.cs.meta
-
14com.unity.render-pipelines.lightweight/LWRP/Passes/DrawSkyboxPass.cs
-
11com.unity.render-pipelines.lightweight/LWRP/Passes/DrawSkyboxPass.cs.meta
-
15com.unity.render-pipelines.lightweight/LWRP/Passes/EndXRRenderingPass.cs
-
11com.unity.render-pipelines.lightweight/LWRP/Passes/EndXRRenderingPass.cs.meta
-
56com.unity.render-pipelines.lightweight/LWRP/Passes/FinalBlitPass.cs
-
11com.unity.render-pipelines.lightweight/LWRP/Passes/FinalBlitPass.cs.meta
-
99com.unity.render-pipelines.lightweight/LWRP/Passes/LightweightForwardPass.cs
-
11com.unity.render-pipelines.lightweight/LWRP/Passes/LightweightForwardPass.cs.meta
-
32com.unity.render-pipelines.lightweight/LWRP/Passes/OpaquePostProcessPass.cs
-
11com.unity.render-pipelines.lightweight/LWRP/Passes/OpaquePostProcessPass.cs.meta
-
42com.unity.render-pipelines.lightweight/LWRP/Passes/RenderOpaqueForwardPass.cs
-
11com.unity.render-pipelines.lightweight/LWRP/Passes/RenderOpaqueForwardPass.cs.meta
-
33com.unity.render-pipelines.lightweight/LWRP/Passes/RenderTransparentForwardPass.cs
-
11com.unity.render-pipelines.lightweight/LWRP/Passes/RenderTransparentForwardPass.cs.meta
-
32com.unity.render-pipelines.lightweight/LWRP/Passes/SceneViewDepthCopy.cs
-
11com.unity.render-pipelines.lightweight/LWRP/Passes/SceneViewDepthCopy.cs.meta
-
21com.unity.render-pipelines.lightweight/LWRP/Passes/SetupForwardRenderingPass.cs
-
11com.unity.render-pipelines.lightweight/LWRP/Passes/SetupForwardRenderingPass.cs.meta
-
272com.unity.render-pipelines.lightweight/LWRP/Passes/SetupLightweightConstanstPass.cs
-
11com.unity.render-pipelines.lightweight/LWRP/Passes/SetupLightweightConstanstPass.cs.meta
-
30com.unity.render-pipelines.lightweight/LWRP/Passes/TransparentPostProcessPass.cs
-
11com.unity.render-pipelines.lightweight/LWRP/Passes/TransparentPostProcessPass.cs.meta
-
52com.unity.render-pipelines.lightweight/LWRP/RenderTargetHandle.cs
-
11com.unity.render-pipelines.lightweight/LWRP/RenderTargetHandle.cs.meta
-
7com.unity.render-pipelines.lightweight/LWRP/RenderTargetHandles.cs
-
11com.unity.render-pipelines.lightweight/LWRP/RenderTargetHandles.cs.meta
-
9com.unity.render-pipelines.lightweight/LWRP/SampleCount.cs
-
11com.unity.render-pipelines.lightweight/LWRP/SampleCount.cs.meta
-
61TestProjects/LWGraphicsTest/Assets/TestScripts/CustomLWPipe.cs
-
11TestProjects/LWGraphicsTest/Assets/TestScripts/CustomLWPipe.cs.meta
|
|||
using System.Collections.Generic; |
|||
using System.Diagnostics; |
|||
using UnityEngine.Experimental.GlobalIllumination; |
|||
using UnityEngine.Rendering; |
|||
|
|||
namespace UnityEngine.Experimental.Rendering.LightweightPipeline |
|||
{ |
|||
public class ForwardLitPass : ScriptableRenderPass |
|||
{ |
|||
const int k_DepthStencilBufferBits = 32; |
|||
Vector4 k_DefaultLightPosition = new Vector4(0.0f, 0.0f, 1.0f, 0.0f); |
|||
Vector4 k_DefaultLightColor = Color.black; |
|||
Vector4 k_DefaultLightAttenuation = new Vector4(0.0f, 1.0f, 0.0f, 1.0f); |
|||
Vector4 k_DefaultLightSpotDirection = new Vector4(0.0f, 0.0f, 1.0f, 0.0f); |
|||
Vector4 k_DefaultLightSpotAttenuation = new Vector4(0.0f, 1.0f, 0.0f, 0.0f); |
|||
|
|||
Vector4[] m_LightPositions; |
|||
Vector4[] m_LightColors; |
|||
Vector4[] m_LightDistanceAttenuations; |
|||
Vector4[] m_LightSpotDirections; |
|||
Vector4[] m_LightSpotAttenuations; |
|||
|
|||
RenderTextureFormat m_ColorFormat; |
|||
MixedLightingSetup m_MixedLightingSetup; |
|||
Material m_BlitMaterial; |
|||
Material m_ErrorMaterial; |
|||
|
|||
// Depth Copy Pass
|
|||
Material m_DepthCopyMaterial; |
|||
|
|||
// Opaque Copy Pass
|
|||
Material m_SamplingMaterial; |
|||
float[] m_OpaqueScalerValues = {1.0f, 0.5f, 0.25f, 0.25f}; |
|||
int m_SampleOffsetShaderHandle; |
|||
|
|||
const string k_RenderOpaquesTag = "Render Opaques"; |
|||
const string k_RenderTransparentsTag = "Render Transparents"; |
|||
|
|||
List<ShaderPassName> m_LegacyShaderPassNames; |
|||
|
|||
public ForwardLitPass(LightweightForwardRenderer renderer) : base(renderer) |
|||
{ |
|||
RegisterShaderPassName("LightweightForward"); |
|||
RegisterShaderPassName("SRPDefaultUnlit"); |
|||
|
|||
m_LegacyShaderPassNames = new List<ShaderPassName>(); |
|||
m_LegacyShaderPassNames.Add(new ShaderPassName("Always")); |
|||
m_LegacyShaderPassNames.Add(new ShaderPassName("ForwardBase")); |
|||
m_LegacyShaderPassNames.Add(new ShaderPassName("PrepassBase")); |
|||
m_LegacyShaderPassNames.Add(new ShaderPassName("Vertex")); |
|||
m_LegacyShaderPassNames.Add(new ShaderPassName("VertexLMRGBM")); |
|||
m_LegacyShaderPassNames.Add(new ShaderPassName("VertexLM")); |
|||
|
|||
PerCameraBuffer._MainLightPosition = Shader.PropertyToID("_MainLightPosition"); |
|||
PerCameraBuffer._MainLightColor = Shader.PropertyToID("_MainLightColor"); |
|||
PerCameraBuffer._MainLightCookie = Shader.PropertyToID("_MainLightCookie"); |
|||
PerCameraBuffer._WorldToLight = Shader.PropertyToID("_WorldToLight"); |
|||
PerCameraBuffer._AdditionalLightCount = Shader.PropertyToID("_AdditionalLightCount"); |
|||
PerCameraBuffer._AdditionalLightPosition = Shader.PropertyToID("_AdditionalLightPosition"); |
|||
PerCameraBuffer._AdditionalLightColor = Shader.PropertyToID("_AdditionalLightColor"); |
|||
PerCameraBuffer._AdditionalLightDistanceAttenuation = Shader.PropertyToID("_AdditionalLightDistanceAttenuation"); |
|||
PerCameraBuffer._AdditionalLightSpotDir = Shader.PropertyToID("_AdditionalLightSpotDir"); |
|||
PerCameraBuffer._AdditionalLightSpotAttenuation = Shader.PropertyToID("_AdditionalLightSpotAttenuation"); |
|||
PerCameraBuffer._LightIndexBuffer = Shader.PropertyToID("_LightIndexBuffer"); |
|||
|
|||
int maxVisibleLocalLights = renderer.maxVisibleLocalLights; |
|||
m_LightPositions = new Vector4[maxVisibleLocalLights]; |
|||
m_LightColors = new Vector4[maxVisibleLocalLights]; |
|||
m_LightDistanceAttenuations = new Vector4[maxVisibleLocalLights]; |
|||
m_LightSpotDirections = new Vector4[maxVisibleLocalLights]; |
|||
m_LightSpotAttenuations = new Vector4[maxVisibleLocalLights]; |
|||
|
|||
m_ColorFormat = RenderTextureFormat.Default; |
|||
m_BlitMaterial = renderer.GetMaterial(MaterialHandles.Blit); |
|||
m_ErrorMaterial = renderer.GetMaterial(MaterialHandles.Error); |
|||
|
|||
// Copy Depth Pass
|
|||
m_DepthCopyMaterial = renderer.GetMaterial(MaterialHandles.DepthCopy); |
|||
|
|||
// Copy Opaque Color Pass
|
|||
m_SamplingMaterial = renderer.GetMaterial(MaterialHandles.Sampling); |
|||
m_SampleOffsetShaderHandle = Shader.PropertyToID("_SampleOffset"); |
|||
} |
|||
|
|||
public override void Setup(CommandBuffer cmd, RenderTextureDescriptor baseDescriptor, int[] colorAttachmentHandles, int depthAttachmentHandle = -1, int samples = 1) |
|||
{ |
|||
base.Setup(cmd, baseDescriptor, colorAttachmentHandles, depthAttachmentHandle, samples); |
|||
|
|||
m_ColorFormat = baseDescriptor.colorFormat; |
|||
if (colorAttachmentHandle != -1) |
|||
{ |
|||
var descriptor = baseDescriptor; |
|||
descriptor.depthBufferBits = k_DepthStencilBufferBits; // TODO: does the color RT always need depth?
|
|||
descriptor.sRGB = true; |
|||
descriptor.msaaSamples = samples; |
|||
cmd.GetTemporaryRT(colorAttachmentHandle, descriptor, FilterMode.Bilinear); |
|||
} |
|||
|
|||
if (depthAttachmentHandle != -1) |
|||
{ |
|||
var descriptor = baseDescriptor; |
|||
descriptor.colorFormat = RenderTextureFormat.Depth; |
|||
descriptor.depthBufferBits = k_DepthStencilBufferBits; |
|||
descriptor.msaaSamples = samples; |
|||
descriptor.bindMS = samples > 1; |
|||
cmd.GetTemporaryRT(depthAttachmentHandle, descriptor, FilterMode.Point); |
|||
} |
|||
} |
|||
|
|||
public override void Execute(ref ScriptableRenderContext context, ref CullResults cullResults, ref RenderingData renderingData) |
|||
{ |
|||
Camera camera = renderingData.cameraData.camera; |
|||
bool dynamicBatching = renderingData.supportsDynamicBatching; |
|||
SetupShaderConstants(ref context, ref renderingData.cameraData, ref renderingData.lightData, ref renderingData.shadowData); |
|||
RendererConfiguration rendererConfiguration = GetRendererConfiguration(renderingData.lightData.totalAdditionalLightsCount); |
|||
|
|||
if (renderingData.cameraData.isStereoEnabled) |
|||
context.StartMultiEye(camera); |
|||
|
|||
RenderOpaques(ref context, ref cullResults, ref renderingData.cameraData, rendererConfiguration, dynamicBatching); |
|||
|
|||
if (renderingData.cameraData.postProcessEnabled && |
|||
renderingData.cameraData.postProcessLayer.HasOpaqueOnlyEffects(renderer.postProcessRenderContext)) |
|||
OpaquePostProcessSubPass(ref context, ref renderingData.cameraData); |
|||
|
|||
if (depthAttachmentHandle != -1) |
|||
CopyDepthSubPass(ref context, ref renderingData.cameraData); |
|||
|
|||
if (renderingData.cameraData.requiresOpaqueTexture) |
|||
CopyColorSubpass(ref context, ref renderingData.cameraData); |
|||
|
|||
RenderTransparents(ref context, ref cullResults, ref renderingData.cameraData, rendererConfiguration, dynamicBatching); |
|||
|
|||
if (renderingData.cameraData.postProcessEnabled) |
|||
PostProcessPass(ref context, ref renderingData.cameraData); |
|||
else if (!renderingData.cameraData.isOffscreenRender && colorAttachmentHandle != -1) |
|||
FinalBlitPass(ref context, ref renderingData.cameraData); |
|||
|
|||
if (renderingData.cameraData.isStereoEnabled) |
|||
{ |
|||
context.StopMultiEye(camera); |
|||
context.StereoEndRender(camera); |
|||
} |
|||
} |
|||
|
|||
RendererConfiguration GetRendererConfiguration(int localLightsCount) |
|||
{ |
|||
RendererConfiguration configuration = RendererConfiguration.PerObjectReflectionProbes | RendererConfiguration.PerObjectLightmaps | RendererConfiguration.PerObjectLightProbe; |
|||
if (localLightsCount > 0) |
|||
{ |
|||
if (renderer.useComputeBufferForPerObjectLightIndices) |
|||
configuration |= RendererConfiguration.ProvideLightIndices; |
|||
else |
|||
configuration |= RendererConfiguration.PerObjectLightIndices8; |
|||
} |
|||
|
|||
return configuration; |
|||
} |
|||
|
|||
void SetupShaderConstants(ref ScriptableRenderContext context, ref CameraData cameraData, ref LightData lightData, ref ShadowData shadowData) |
|||
{ |
|||
CommandBuffer cmd = CommandBufferPool.Get("SetupShaderConstants"); |
|||
SetupShaderLightConstants(cmd, ref lightData); |
|||
SetShaderKeywords(cmd, ref cameraData, ref lightData, ref shadowData); |
|||
context.ExecuteCommandBuffer(cmd); |
|||
CommandBufferPool.Release(cmd); |
|||
} |
|||
|
|||
void SetupShaderLightConstants(CommandBuffer cmd, ref LightData lightData) |
|||
{ |
|||
// Clear to default all light constant data
|
|||
for (int i = 0; i < renderer.maxVisibleLocalLights; ++i) |
|||
InitializeLightConstants(lightData.visibleLights, -1, out m_LightPositions[i], |
|||
out m_LightColors[i], |
|||
out m_LightDistanceAttenuations[i], |
|||
out m_LightSpotDirections[i], |
|||
out m_LightSpotAttenuations[i]); |
|||
|
|||
m_MixedLightingSetup = MixedLightingSetup.None; |
|||
|
|||
// Main light has an optimized shader path for main light. This will benefit games that only care about a single light.
|
|||
// Lightweight pipeline also supports only a single shadow light, if available it will be the main light.
|
|||
SetupMainLightConstants(cmd, ref lightData); |
|||
SetupAdditionalLightConstants(cmd, ref lightData); |
|||
} |
|||
|
|||
void SetupMainLightConstants(CommandBuffer cmd, ref LightData lightData) |
|||
{ |
|||
Vector4 lightPos, lightColor, lightDistanceAttenuation, lightSpotDir, lightSpotAttenuation; |
|||
List<VisibleLight> lights = lightData.visibleLights; |
|||
InitializeLightConstants(lightData.visibleLights, lightData.mainLightIndex, out lightPos, out lightColor, out lightDistanceAttenuation, out lightSpotDir, out lightSpotAttenuation); |
|||
|
|||
if (lightData.mainLightIndex >= 0) |
|||
{ |
|||
VisibleLight mainLight = lights[lightData.mainLightIndex]; |
|||
Light mainLightRef = mainLight.light; |
|||
|
|||
if (LightweightPipeline.IsSupportedCookieType(mainLight.lightType) && mainLightRef.cookie != null) |
|||
{ |
|||
Matrix4x4 lightCookieMatrix; |
|||
LightweightPipeline.GetLightCookieMatrix(mainLight, out lightCookieMatrix); |
|||
cmd.SetGlobalTexture(PerCameraBuffer._MainLightCookie, mainLightRef.cookie); |
|||
cmd.SetGlobalMatrix(PerCameraBuffer._WorldToLight, lightCookieMatrix); |
|||
} |
|||
} |
|||
|
|||
cmd.SetGlobalVector(PerCameraBuffer._MainLightPosition, new Vector4(lightPos.x, lightPos.y, lightPos.z, lightDistanceAttenuation.w)); |
|||
cmd.SetGlobalVector(PerCameraBuffer._MainLightColor, lightColor); |
|||
} |
|||
|
|||
void SetupAdditionalLightConstants(CommandBuffer cmd, ref LightData lightData) |
|||
{ |
|||
int maxVisibleLocalLights = renderer.maxVisibleLocalLights; |
|||
List<VisibleLight> lights = lightData.visibleLights; |
|||
if (lightData.totalAdditionalLightsCount > 0) |
|||
{ |
|||
int localLightsCount = 0; |
|||
for (int i = 0; i < lights.Count && localLightsCount < maxVisibleLocalLights; ++i) |
|||
{ |
|||
VisibleLight light = lights[i]; |
|||
if (light.lightType != LightType.Directional) |
|||
{ |
|||
InitializeLightConstants(lights, i, out m_LightPositions[localLightsCount], |
|||
out m_LightColors[localLightsCount], |
|||
out m_LightDistanceAttenuations[localLightsCount], |
|||
out m_LightSpotDirections[localLightsCount], |
|||
out m_LightSpotAttenuations[localLightsCount]); |
|||
localLightsCount++; |
|||
} |
|||
} |
|||
|
|||
cmd.SetGlobalVector(PerCameraBuffer._AdditionalLightCount, new Vector4(lightData.pixelAdditionalLightsCount, |
|||
lightData.totalAdditionalLightsCount, 0.0f, 0.0f)); |
|||
|
|||
// if not using a compute buffer, engine will set indices in 2 vec4 constants
|
|||
// unity_4LightIndices0 and unity_4LightIndices1
|
|||
if (renderer.perObjectLightIndices != null) |
|||
cmd.SetGlobalBuffer("_LightIndexBuffer", renderer.perObjectLightIndices); |
|||
} |
|||
else |
|||
{ |
|||
cmd.SetGlobalVector(PerCameraBuffer._AdditionalLightCount, Vector4.zero); |
|||
} |
|||
|
|||
cmd.SetGlobalVectorArray(PerCameraBuffer._AdditionalLightPosition, m_LightPositions); |
|||
cmd.SetGlobalVectorArray(PerCameraBuffer._AdditionalLightColor, m_LightColors); |
|||
cmd.SetGlobalVectorArray(PerCameraBuffer._AdditionalLightDistanceAttenuation, m_LightDistanceAttenuations); |
|||
cmd.SetGlobalVectorArray(PerCameraBuffer._AdditionalLightSpotDir, m_LightSpotDirections); |
|||
cmd.SetGlobalVectorArray(PerCameraBuffer._AdditionalLightSpotAttenuation, m_LightSpotAttenuations); |
|||
} |
|||
|
|||
ClearFlag GetCameraClearFlag(Camera camera) |
|||
{ |
|||
ClearFlag clearFlag = ClearFlag.None; |
|||
CameraClearFlags cameraClearFlags = camera.clearFlags; |
|||
if (cameraClearFlags != CameraClearFlags.Nothing) |
|||
{ |
|||
clearFlag |= ClearFlag.Depth; |
|||
if (cameraClearFlags == CameraClearFlags.Color || cameraClearFlags == CameraClearFlags.Skybox) |
|||
clearFlag |= ClearFlag.Color; |
|||
} |
|||
|
|||
return clearFlag; |
|||
} |
|||
|
|||
void SetShaderKeywords(CommandBuffer cmd, ref CameraData cameraData, ref LightData lightData, ref ShadowData shadowData) |
|||
{ |
|||
int vertexLightsCount = lightData.totalAdditionalLightsCount - lightData.pixelAdditionalLightsCount; |
|||
|
|||
CoreUtils.SetKeyword(cmd, LightweightKeywordStrings.AdditionalLights, lightData.totalAdditionalLightsCount > 0); |
|||
CoreUtils.SetKeyword(cmd, LightweightKeywordStrings.MixedLightingSubtractive, m_MixedLightingSetup == MixedLightingSetup.Subtractive); |
|||
CoreUtils.SetKeyword(cmd, LightweightKeywordStrings.VertexLights, vertexLightsCount > 0); |
|||
|
|||
// TODO: We have to discuss cookie approach on LWRP.
|
|||
// CoreUtils.SetKeyword(cmd, LightweightKeywordStrings.MainLightCookieText, mainLightIndex != -1 && LightweightUtils.IsSupportedCookieType(visibleLights[mainLightIndex].lightType) && visibleLights[mainLightIndex].light.cookie != null);
|
|||
|
|||
LightShadows directionalShadowQuality = shadowData.renderedDirectionalShadowQuality; |
|||
LightShadows localShadowQuality = shadowData.renderedLocalShadowQuality; |
|||
|
|||
// Currently shadow filtering keyword is shared between local and directional shadows.
|
|||
bool hasSoftShadows = (directionalShadowQuality == LightShadows.Soft || localShadowQuality == LightShadows.Soft) && |
|||
shadowData.supportsSoftShadows; |
|||
|
|||
CoreUtils.SetKeyword(cmd, LightweightKeywordStrings.DirectionalShadows, directionalShadowQuality != LightShadows.None); |
|||
CoreUtils.SetKeyword(cmd, LightweightKeywordStrings.LocalShadows, localShadowQuality != LightShadows.None); |
|||
CoreUtils.SetKeyword(cmd, LightweightKeywordStrings.SoftShadows, hasSoftShadows); |
|||
CoreUtils.SetKeyword(cmd, LightweightKeywordStrings.CascadeShadows, shadowData.directionalLightCascadeCount > 1); |
|||
|
|||
// TODO: Remove this. legacy particles support will be removed from Unity in 2018.3. This should be a shader_feature instead with prop exposed in the Standard particles shader.
|
|||
CoreUtils.SetKeyword(cmd, "SOFTPARTICLES_ON", cameraData.requiresSoftParticles); |
|||
} |
|||
|
|||
void SetRenderTarget(CommandBuffer cmd, RenderBufferLoadAction loadOp, RenderBufferStoreAction storeOp, ClearFlag clearFlag, Color clearColor) |
|||
{ |
|||
if (colorAttachmentHandle != -1) |
|||
{ |
|||
if (depthAttachmentHandle != -1) |
|||
SetRenderTarget(cmd, GetSurface(colorAttachmentHandle), loadOp, storeOp, GetSurface(depthAttachmentHandle), loadOp, storeOp, clearFlag, clearColor); |
|||
else |
|||
SetRenderTarget(cmd, GetSurface(colorAttachmentHandle), loadOp, storeOp, clearFlag, clearColor); |
|||
} |
|||
else |
|||
{ |
|||
SetRenderTarget(cmd, BuiltinRenderTextureType.CameraTarget, loadOp, storeOp, clearFlag, clearColor); |
|||
} |
|||
} |
|||
|
|||
void RenderOpaques(ref ScriptableRenderContext context, ref CullResults cullResults, ref CameraData cameraData, RendererConfiguration rendererConfiguration, bool dynamicBatching) |
|||
{ |
|||
CommandBuffer cmd = CommandBufferPool.Get(k_RenderOpaquesTag); |
|||
using (new ProfilingSample(cmd, k_RenderOpaquesTag)) |
|||
{ |
|||
Camera camera = cameraData.camera; |
|||
ClearFlag clearFlag = GetCameraClearFlag(camera); |
|||
SetRenderTarget(cmd, RenderBufferLoadAction.DontCare, RenderBufferStoreAction.Store, clearFlag, CoreUtils.ConvertSRGBToActiveColorSpace(camera.backgroundColor)); |
|||
|
|||
// TODO: We need a proper way to handle multiple camera/ camera stack. Issue is: multiple cameras can share a same RT
|
|||
// (e.g, split screen games). However devs have to be dilligent with it and know when to clear/preserve color.
|
|||
// For now we make it consistent by resolving viewport with a RT until we can have a proper camera management system
|
|||
//if (colorAttachmentHandle == -1 && !cameraData.isDefaultViewport)
|
|||
// cmd.SetViewport(camera.pixelRect);
|
|||
|
|||
context.ExecuteCommandBuffer(cmd); |
|||
cmd.Clear(); |
|||
|
|||
var drawSettings = CreateDrawRendererSettings(camera, SortFlags.CommonOpaque, rendererConfiguration, dynamicBatching); |
|||
context.DrawRenderers(cullResults.visibleRenderers, ref drawSettings, renderer.opaqueFilterSettings); |
|||
|
|||
// Render objects that did not match any shader pass with error shader
|
|||
RenderObjectsWithError(ref context, ref cullResults, camera, renderer.opaqueFilterSettings, SortFlags.None); |
|||
|
|||
if (camera.clearFlags == CameraClearFlags.Skybox) |
|||
context.DrawSkybox(camera); |
|||
} |
|||
context.ExecuteCommandBuffer(cmd); |
|||
CommandBufferPool.Release(cmd); |
|||
} |
|||
|
|||
void RenderTransparents(ref ScriptableRenderContext context, ref CullResults cullResults, ref CameraData cameraData, RendererConfiguration rendererConfiguration, bool dynamicBatching) |
|||
{ |
|||
CommandBuffer cmd = CommandBufferPool.Get(k_RenderTransparentsTag); |
|||
using (new ProfilingSample(cmd, k_RenderTransparentsTag)) |
|||
{ |
|||
Camera camera = cameraData.camera; |
|||
SetRenderTarget(cmd, RenderBufferLoadAction.Load, RenderBufferStoreAction.Store, ClearFlag.None, Color.black); |
|||
context.ExecuteCommandBuffer(cmd); |
|||
cmd.Clear(); |
|||
|
|||
var drawSettings = CreateDrawRendererSettings(camera, SortFlags.CommonTransparent, rendererConfiguration, dynamicBatching); |
|||
context.DrawRenderers(cullResults.visibleRenderers, ref drawSettings, renderer.transparentFilterSettings); |
|||
|
|||
// Render objects that did not match any shader pass with error shader
|
|||
RenderObjectsWithError(ref context, ref cullResults, camera, renderer.transparentFilterSettings, SortFlags.None); |
|||
} |
|||
context.ExecuteCommandBuffer(cmd); |
|||
CommandBufferPool.Release(cmd); |
|||
} |
|||
|
|||
void FinalBlitPass(ref ScriptableRenderContext context, ref CameraData cameraData) |
|||
{ |
|||
Material material = cameraData.isStereoEnabled ? null : m_BlitMaterial; |
|||
RenderTargetIdentifier sourceRT = GetSurface(colorAttachmentHandle); |
|||
|
|||
CommandBuffer cmd = CommandBufferPool.Get("Final Blit Pass"); |
|||
cmd.SetGlobalTexture("_BlitTex", sourceRT); |
|||
|
|||
// We need to handle viewport on a RT. We do it by rendering a fullscreen quad + viewport
|
|||
if (!cameraData.isDefaultViewport) |
|||
{ |
|||
SetRenderTarget(cmd, BuiltinRenderTextureType.CameraTarget, RenderBufferLoadAction.DontCare, RenderBufferStoreAction.Store, ClearFlag.None, Color.black); |
|||
cmd.SetViewProjectionMatrices(Matrix4x4.identity, Matrix4x4.identity); |
|||
cmd.SetViewport(cameraData.camera.pixelRect); |
|||
LightweightPipeline.DrawFullScreen(cmd, material); |
|||
} |
|||
else |
|||
{ |
|||
cmd.Blit(GetSurface(colorAttachmentHandle), BuiltinRenderTextureType.CameraTarget, material); |
|||
} |
|||
|
|||
context.ExecuteCommandBuffer(cmd); |
|||
CommandBufferPool.Release(cmd); |
|||
} |
|||
|
|||
void InitializeLightConstants(List<VisibleLight> lights, int lightIndex, out Vector4 lightPos, out Vector4 lightColor, out Vector4 lightDistanceAttenuation, out Vector4 lightSpotDir, |
|||
out Vector4 lightSpotAttenuation) |
|||
{ |
|||
lightPos = k_DefaultLightPosition; |
|||
lightColor = k_DefaultLightColor; |
|||
lightDistanceAttenuation = k_DefaultLightSpotAttenuation; |
|||
lightSpotDir = k_DefaultLightSpotDirection; |
|||
lightSpotAttenuation = k_DefaultLightAttenuation; |
|||
|
|||
// When no lights are visible, main light will be set to -1.
|
|||
// In this case we initialize it to default values and return
|
|||
if (lightIndex < 0) |
|||
return; |
|||
|
|||
VisibleLight lightData = lights[lightIndex]; |
|||
if (lightData.lightType == LightType.Directional) |
|||
{ |
|||
Vector4 dir = -lightData.localToWorld.GetColumn(2); |
|||
lightPos = new Vector4(dir.x, dir.y, dir.z, 0.0f); |
|||
} |
|||
else |
|||
{ |
|||
Vector4 pos = lightData.localToWorld.GetColumn(3); |
|||
lightPos = new Vector4(pos.x, pos.y, pos.z, 1.0f); |
|||
} |
|||
|
|||
// VisibleLight.finalColor already returns color in active color space
|
|||
lightColor = lightData.finalColor; |
|||
|
|||
// Directional Light attenuation is initialize so distance attenuation always be 1.0
|
|||
if (lightData.lightType != LightType.Directional) |
|||
{ |
|||
// Light attenuation in lightweight matches the unity vanilla one.
|
|||
// attenuation = 1.0 / 1.0 + distanceToLightSqr * quadraticAttenuation
|
|||
// then a smooth factor is applied to linearly fade attenuation to light range
|
|||
// the attenuation smooth factor starts having effect at 80% of light range
|
|||
// smoothFactor = (lightRangeSqr - distanceToLightSqr) / (lightRangeSqr - fadeStartDistanceSqr)
|
|||
// We rewrite smoothFactor to be able to pre compute the constant terms below and apply the smooth factor
|
|||
// with one MAD instruction
|
|||
// smoothFactor = distanceSqr * (1.0 / (fadeDistanceSqr - lightRangeSqr)) + (-lightRangeSqr / (fadeDistanceSqr - lightRangeSqr)
|
|||
// distanceSqr * oneOverFadeRangeSqr + lightRangeSqrOverFadeRangeSqr
|
|||
float lightRangeSqr = lightData.range * lightData.range; |
|||
float fadeStartDistanceSqr = 0.8f * 0.8f * lightRangeSqr; |
|||
float fadeRangeSqr = (fadeStartDistanceSqr - lightRangeSqr); |
|||
float oneOverFadeRangeSqr = 1.0f / fadeRangeSqr; |
|||
float lightRangeSqrOverFadeRangeSqr = -lightRangeSqr / fadeRangeSqr; |
|||
float quadAtten = 25.0f / lightRangeSqr; |
|||
lightDistanceAttenuation = new Vector4(quadAtten, oneOverFadeRangeSqr, lightRangeSqrOverFadeRangeSqr, 1.0f); |
|||
} |
|||
|
|||
if (lightData.lightType == LightType.Spot) |
|||
{ |
|||
Vector4 dir = lightData.localToWorld.GetColumn(2); |
|||
lightSpotDir = new Vector4(-dir.x, -dir.y, -dir.z, 0.0f); |
|||
|
|||
// Spot Attenuation with a linear falloff can be defined as
|
|||
// (SdotL - cosOuterAngle) / (cosInnerAngle - cosOuterAngle)
|
|||
// This can be rewritten as
|
|||
// invAngleRange = 1.0 / (cosInnerAngle - cosOuterAngle)
|
|||
// SdotL * invAngleRange + (-cosOuterAngle * invAngleRange)
|
|||
// If we precompute the terms in a MAD instruction
|
|||
float cosOuterAngle = Mathf.Cos(Mathf.Deg2Rad * lightData.spotAngle * 0.5f); |
|||
// We neeed to do a null check for particle lights
|
|||
// This should be changed in the future
|
|||
// Particle lights will use an inline function
|
|||
float cosInnerAngle; |
|||
if (lightData.light != null) |
|||
cosInnerAngle = Mathf.Cos(LightmapperUtils.ExtractInnerCone(lightData.light) * 0.5f); |
|||
else |
|||
cosInnerAngle = Mathf.Cos((2.0f * Mathf.Atan(Mathf.Tan(lightData.spotAngle * 0.5f * Mathf.Deg2Rad) * (64.0f - 18.0f) / 64.0f)) * 0.5f); |
|||
float smoothAngleRange = Mathf.Max(0.001f, cosInnerAngle - cosOuterAngle); |
|||
float invAngleRange = 1.0f / smoothAngleRange; |
|||
float add = -cosOuterAngle * invAngleRange; |
|||
lightSpotAttenuation = new Vector4(invAngleRange, add, 0.0f); |
|||
} |
|||
|
|||
Light light = lightData.light; |
|||
|
|||
// TODO: Add support to shadow mask
|
|||
if (light != null && light.bakingOutput.mixedLightingMode == MixedLightingMode.Subtractive && light.bakingOutput.lightmapBakeType == LightmapBakeType.Mixed) |
|||
{ |
|||
if (m_MixedLightingSetup == MixedLightingSetup.None && lightData.light.shadows != LightShadows.None) |
|||
{ |
|||
m_MixedLightingSetup = MixedLightingSetup.Subtractive; |
|||
lightDistanceAttenuation.w = 0.0f; |
|||
} |
|||
} |
|||
} |
|||
|
|||
// TODO: move to postfx pass
|
|||
void PostProcessPass(ref ScriptableRenderContext context, ref CameraData cameraData) |
|||
{ |
|||
CommandBuffer cmd = CommandBufferPool.Get("Render PostProcess Effects"); |
|||
LightweightPipeline.RenderPostProcess(cmd, renderer.postProcessRenderContext, ref cameraData, m_ColorFormat, GetSurface(colorAttachmentHandle), BuiltinRenderTextureType.CameraTarget, false); |
|||
context.ExecuteCommandBuffer(cmd); |
|||
CommandBufferPool.Release(cmd); |
|||
} |
|||
|
|||
[Conditional("DEVELOPMENT_BUILD"), Conditional("UNITY_EDITOR")] |
|||
void RenderObjectsWithError(ref ScriptableRenderContext context, ref CullResults cullResults, Camera camera, FilterRenderersSettings filterSettings, SortFlags sortFlags) |
|||
{ |
|||
if (m_ErrorMaterial != null) |
|||
{ |
|||
DrawRendererSettings errorSettings = new DrawRendererSettings(camera, m_LegacyShaderPassNames[0]); |
|||
for (int i = 1; i < m_LegacyShaderPassNames.Count; ++i) |
|||
errorSettings.SetShaderPassName(i, m_LegacyShaderPassNames[i]); |
|||
|
|||
errorSettings.sorting.flags = sortFlags; |
|||
errorSettings.rendererConfiguration = RendererConfiguration.None; |
|||
errorSettings.SetOverrideMaterial(m_ErrorMaterial, 0); |
|||
context.DrawRenderers(cullResults.visibleRenderers, ref errorSettings, filterSettings); |
|||
} |
|||
} |
|||
|
|||
void OpaquePostProcessSubPass(ref ScriptableRenderContext context, ref CameraData cameraData) |
|||
{ |
|||
CommandBuffer cmd = CommandBufferPool.Get("Render Opaque PostProcess Effects"); |
|||
|
|||
RenderTargetIdentifier source = GetSurface(colorAttachmentHandle); |
|||
LightweightPipeline.RenderPostProcess(cmd, renderer.postProcessRenderContext, ref cameraData, m_ColorFormat, source, GetSurface(colorAttachmentHandle), true); |
|||
context.ExecuteCommandBuffer(cmd); |
|||
CommandBufferPool.Release(cmd); |
|||
} |
|||
|
|||
void CopyDepthSubPass(ref ScriptableRenderContext context, ref CameraData cameraData) |
|||
{ |
|||
CommandBuffer cmd = CommandBufferPool.Get("Depth Copy"); |
|||
RenderTargetIdentifier depthSurface = GetSurface(depthAttachmentHandle); |
|||
RenderTargetIdentifier copyDepthSurface = GetSurface(RenderTargetHandles.DepthTexture); |
|||
|
|||
RenderTextureDescriptor descriptor = renderer.CreateRTDesc(ref cameraData); |
|||
descriptor.colorFormat = RenderTextureFormat.Depth; |
|||
descriptor.depthBufferBits = k_DepthStencilBufferBits; |
|||
descriptor.msaaSamples = 1; |
|||
descriptor.bindMS = false; |
|||
cmd.GetTemporaryRT(RenderTargetHandles.DepthTexture, descriptor, FilterMode.Point); |
|||
|
|||
if (cameraData.msaaSamples > 1) |
|||
{ |
|||
cmd.DisableShaderKeyword(LightweightKeywordStrings.DepthNoMsaa); |
|||
if (cameraData.msaaSamples == 4) |
|||
{ |
|||
cmd.DisableShaderKeyword(LightweightKeywordStrings.DepthMsaa2); |
|||
cmd.EnableShaderKeyword(LightweightKeywordStrings.DepthMsaa4); |
|||
} |
|||
else |
|||
{ |
|||
cmd.EnableShaderKeyword(LightweightKeywordStrings.DepthMsaa2); |
|||
cmd.DisableShaderKeyword(LightweightKeywordStrings.DepthMsaa4); |
|||
} |
|||
cmd.Blit(depthSurface, copyDepthSurface, m_DepthCopyMaterial); |
|||
} |
|||
else |
|||
{ |
|||
cmd.EnableShaderKeyword(LightweightKeywordStrings.DepthNoMsaa); |
|||
cmd.DisableShaderKeyword(LightweightKeywordStrings.DepthMsaa2); |
|||
cmd.DisableShaderKeyword(LightweightKeywordStrings.DepthMsaa4); |
|||
LightweightPipeline.CopyTexture(cmd, depthSurface, copyDepthSurface, m_DepthCopyMaterial); |
|||
} |
|||
context.ExecuteCommandBuffer(cmd); |
|||
CommandBufferPool.Release(cmd); |
|||
} |
|||
|
|||
void CopyColorSubpass(ref ScriptableRenderContext context, ref CameraData cameraData) |
|||
{ |
|||
CommandBuffer cmd = CommandBufferPool.Get("Copy Opaque Color"); |
|||
Downsampling downsampling = cameraData.opaqueTextureDownsampling; |
|||
float opaqueScaler = m_OpaqueScalerValues[(int)downsampling]; |
|||
|
|||
RenderTextureDescriptor opaqueDesc = renderer.CreateRTDesc(ref cameraData, opaqueScaler); |
|||
RenderTargetIdentifier colorRT = GetSurface(colorAttachmentHandle); |
|||
RenderTargetIdentifier opaqueColorRT = GetSurface(RenderTargetHandles.OpaqueColor); |
|||
|
|||
cmd.GetTemporaryRT(RenderTargetHandles.OpaqueColor, opaqueDesc, cameraData.opaqueTextureDownsampling == Downsampling.None ? FilterMode.Point : FilterMode.Bilinear); |
|||
switch (downsampling) |
|||
{ |
|||
case Downsampling.None: |
|||
cmd.Blit(colorRT, opaqueColorRT); |
|||
break; |
|||
case Downsampling._2xBilinear: |
|||
cmd.Blit(colorRT, opaqueColorRT); |
|||
break; |
|||
case Downsampling._4xBox: |
|||
m_SamplingMaterial.SetFloat(m_SampleOffsetShaderHandle, 2); |
|||
cmd.Blit(colorRT, opaqueColorRT, m_SamplingMaterial, 0); |
|||
break; |
|||
case Downsampling._4xBilinear: |
|||
cmd.Blit(colorRT, opaqueColorRT); |
|||
break; |
|||
} |
|||
|
|||
context.ExecuteCommandBuffer(cmd); |
|||
CommandBufferPool.Release(cmd); |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: e8cb6d76b1ce24a4e97f88ab70abb6db |
|||
TextureImporter: |
|||
fileIDToRecycleName: {} |
|||
externalObjects: {} |
|||
serializedVersion: 7 |
|||
mipmaps: |
|||
mipMapMode: 0 |
|||
enableMipMap: 0 |
|||
sRGBTexture: 1 |
|||
linearTexture: 0 |
|||
fadeOut: 0 |
|||
borderMipMap: 0 |
|||
mipMapsPreserveCoverage: 0 |
|||
alphaTestReferenceValue: 0.5 |
|||
mipMapFadeDistanceStart: 1 |
|||
mipMapFadeDistanceEnd: 3 |
|||
bumpmap: |
|||
convertToNormalMap: 0 |
|||
externalNormalMap: 0 |
|||
heightScale: 0.25 |
|||
normalMapFilter: 0 |
|||
isReadable: 1 |
|||
streamingMipmaps: 0 |
|||
streamingMipmapsPriority: 0 |
|||
grayScaleToAlpha: 0 |
|||
generateCubemap: 6 |
|||
cubemapConvolution: 0 |
|||
seamlessCubemap: 0 |
|||
textureFormat: 1 |
|||
maxTextureSize: 2048 |
|||
textureSettings: |
|||
serializedVersion: 2 |
|||
filterMode: -1 |
|||
aniso: -1 |
|||
mipBias: -100 |
|||
wrapU: -1 |
|||
wrapV: -1 |
|||
wrapW: -1 |
|||
nPOTScale: 0 |
|||
lightmap: 0 |
|||
compressionQuality: 50 |
|||
spriteMode: 0 |
|||
spriteExtrude: 1 |
|||
spriteMeshType: 1 |
|||
alignment: 0 |
|||
spritePivot: {x: 0.5, y: 0.5} |
|||
spritePixelsToUnits: 100 |
|||
spriteBorder: {x: 0, y: 0, z: 0, w: 0} |
|||
spriteGenerateFallbackPhysicsShape: 1 |
|||
alphaUsage: 1 |
|||
alphaIsTransparency: 0 |
|||
spriteTessellationDetail: -1 |
|||
textureType: 0 |
|||
textureShape: 1 |
|||
singleChannelComponent: 0 |
|||
maxTextureSizeSet: 0 |
|||
compressionQualitySet: 0 |
|||
textureFormatSet: 0 |
|||
platformSettings: |
|||
- serializedVersion: 2 |
|||
buildTarget: DefaultTexturePlatform |
|||
maxTextureSize: 2048 |
|||
resizeAlgorithm: 0 |
|||
textureFormat: -1 |
|||
textureCompression: 0 |
|||
compressionQuality: 50 |
|||
crunchedCompression: 0 |
|||
allowsAlphaSplitting: 0 |
|||
overridden: 0 |
|||
androidETC2FallbackOverride: 0 |
|||
spriteSheet: |
|||
serializedVersion: 2 |
|||
sprites: [] |
|||
outline: [] |
|||
physicsShape: [] |
|||
bones: [] |
|||
spriteID: |
|||
vertices: [] |
|||
indices: |
|||
edges: [] |
|||
weights: [] |
|||
spritePackingTag: |
|||
pSDRemoveMatte: 0 |
|||
pSDShowRemoveMatteOption: 0 |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
fileFormatVersion: 2 |
|||
guid: 3633c62c6bb83e74baa40034bba66123 |
|||
TextureImporter: |
|||
fileIDToRecycleName: {} |
|||
externalObjects: {} |
|||
serializedVersion: 7 |
|||
mipmaps: |
|||
mipMapMode: 0 |
|||
enableMipMap: 0 |
|||
sRGBTexture: 1 |
|||
linearTexture: 0 |
|||
fadeOut: 0 |
|||
borderMipMap: 0 |
|||
mipMapsPreserveCoverage: 0 |
|||
alphaTestReferenceValue: 0.5 |
|||
mipMapFadeDistanceStart: 1 |
|||
mipMapFadeDistanceEnd: 3 |
|||
bumpmap: |
|||
convertToNormalMap: 0 |
|||
externalNormalMap: 0 |
|||
heightScale: 0.25 |
|||
normalMapFilter: 0 |
|||
isReadable: 1 |
|||
streamingMipmaps: 0 |
|||
streamingMipmapsPriority: 0 |
|||
grayScaleToAlpha: 0 |
|||
generateCubemap: 6 |
|||
cubemapConvolution: 0 |
|||
seamlessCubemap: 0 |
|||
textureFormat: 1 |
|||
maxTextureSize: 2048 |
|||
textureSettings: |
|||
serializedVersion: 2 |
|||
filterMode: -1 |
|||
aniso: -1 |
|||
mipBias: -100 |
|||
wrapU: -1 |
|||
wrapV: -1 |
|||
wrapW: -1 |
|||
nPOTScale: 0 |
|||
lightmap: 0 |
|||
compressionQuality: 50 |
|||
spriteMode: 0 |
|||
spriteExtrude: 1 |
|||
spriteMeshType: 1 |
|||
alignment: 0 |
|||
spritePivot: {x: 0.5, y: 0.5} |
|||
spritePixelsToUnits: 100 |
|||
spriteBorder: {x: 0, y: 0, z: 0, w: 0} |
|||
spriteGenerateFallbackPhysicsShape: 1 |
|||
alphaUsage: 1 |
|||
alphaIsTransparency: 0 |
|||
spriteTessellationDetail: -1 |
|||
textureType: 0 |
|||
textureShape: 1 |
|||
singleChannelComponent: 0 |
|||
maxTextureSizeSet: 0 |
|||
compressionQualitySet: 0 |
|||
textureFormatSet: 0 |
|||
platformSettings: |
|||
- serializedVersion: 2 |
|||
buildTarget: DefaultTexturePlatform |
|||
maxTextureSize: 2048 |
|||
resizeAlgorithm: 0 |
|||
textureFormat: -1 |
|||
textureCompression: 0 |
|||
compressionQuality: 50 |
|||
crunchedCompression: 0 |
|||
allowsAlphaSplitting: 0 |
|||
overridden: 0 |
|||
androidETC2FallbackOverride: 0 |
|||
spriteSheet: |
|||
serializedVersion: 2 |
|||
sprites: [] |
|||
outline: [] |
|||
physicsShape: [] |
|||
bones: [] |
|||
spriteID: |
|||
vertices: [] |
|||
indices: |
|||
edges: [] |
|||
weights: [] |
|||
spritePackingTag: |
|||
pSDRemoveMatte: 0 |
|||
pSDShowRemoveMatteOption: 0 |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
%YAML 1.1 |
|||
%TAG !u! tag:unity3d.com,2011: |
|||
--- !u!29 &1 |
|||
OcclusionCullingSettings: |
|||
m_ObjectHideFlags: 0 |
|||
serializedVersion: 2 |
|||
m_OcclusionBakeSettings: |
|||
smallestOccluder: 5 |
|||
smallestHole: 0.25 |
|||
backfaceThreshold: 100 |
|||
m_SceneGUID: 00000000000000000000000000000000 |
|||
m_OcclusionCullingData: {fileID: 0} |
|||
--- !u!104 &2 |
|||
RenderSettings: |
|||
m_ObjectHideFlags: 0 |
|||
serializedVersion: 9 |
|||
m_Fog: 0 |
|||
m_FogColor: {r: 0.5, g: 0.5, b: 0.5, a: 1} |
|||
m_FogMode: 3 |
|||
m_FogDensity: 0.01 |
|||
m_LinearFogStart: 0 |
|||
m_LinearFogEnd: 300 |
|||
m_AmbientSkyColor: {r: 0.212, g: 0.227, b: 0.259, a: 1} |
|||
m_AmbientEquatorColor: {r: 0.114, g: 0.125, b: 0.133, a: 1} |
|||
m_AmbientGroundColor: {r: 0.047, g: 0.043, b: 0.035, a: 1} |
|||
m_AmbientIntensity: 1 |
|||
m_AmbientMode: 0 |
|||
m_SubtractiveShadowColor: {r: 0.42, g: 0.478, b: 0.627, a: 1} |
|||
m_SkyboxMaterial: {fileID: 10304, guid: 0000000000000000f000000000000000, type: 0} |
|||
m_HaloStrength: 0.5 |
|||
m_FlareStrength: 1 |
|||
m_FlareFadeSpeed: 3 |
|||
m_HaloTexture: {fileID: 0} |
|||
m_SpotCookie: {fileID: 10001, guid: 0000000000000000e000000000000000, type: 0} |
|||
m_DefaultReflectionMode: 0 |
|||
m_DefaultReflectionResolution: 128 |
|||
m_ReflectionBounces: 1 |
|||
m_ReflectionIntensity: 1 |
|||
m_CustomReflection: {fileID: 0} |
|||
m_Sun: {fileID: 0} |
|||
m_IndirectSpecularColor: {r: 0.18029502, g: 0.22572649, b: 0.30692935, a: 1} |
|||
m_UseRadianceAmbientProbe: 0 |
|||
--- !u!157 &3 |
|||
LightmapSettings: |
|||
m_ObjectHideFlags: 0 |
|||
serializedVersion: 11 |
|||
m_GIWorkflowMode: 1 |
|||
m_GISettings: |
|||
serializedVersion: 2 |
|||
m_BounceScale: 1 |
|||
m_IndirectOutputScale: 1 |
|||
m_AlbedoBoost: 1 |
|||
m_TemporalCoherenceThreshold: 1 |
|||
m_EnvironmentLightingMode: 0 |
|||
m_EnableBakedLightmaps: 0 |
|||
m_EnableRealtimeLightmaps: 1 |
|||
m_LightmapEditorSettings: |
|||
serializedVersion: 10 |
|||
m_Resolution: 2 |
|||
m_BakeResolution: 40 |
|||
m_AtlasSize: 1024 |
|||
m_AO: 0 |
|||
m_AOMaxDistance: 1 |
|||
m_CompAOExponent: 1 |
|||
m_CompAOExponentDirect: 0 |
|||
m_Padding: 2 |
|||
m_LightmapParameters: {fileID: 0} |
|||
m_LightmapsBakeMode: 1 |
|||
m_TextureCompression: 1 |
|||
m_FinalGather: 0 |
|||
m_FinalGatherFiltering: 1 |
|||
m_FinalGatherRayCount: 256 |
|||
m_ReflectionCompression: 2 |
|||
m_MixedBakeMode: 2 |
|||
m_BakeBackend: 0 |
|||
m_PVRSampling: 1 |
|||
m_PVRDirectSampleCount: 32 |
|||
m_PVRSampleCount: 500 |
|||
m_PVRBounces: 2 |
|||
m_PVRFilterTypeDirect: 0 |
|||
m_PVRFilterTypeIndirect: 0 |
|||
m_PVRFilterTypeAO: 0 |
|||
m_PVRFilteringMode: 1 |
|||
m_PVRCulling: 1 |
|||
m_PVRFilteringGaussRadiusDirect: 1 |
|||
m_PVRFilteringGaussRadiusIndirect: 5 |
|||
m_PVRFilteringGaussRadiusAO: 2 |
|||
m_PVRFilteringAtrousPositionSigmaDirect: 0.5 |
|||
m_PVRFilteringAtrousPositionSigmaIndirect: 2 |
|||
m_PVRFilteringAtrousPositionSigmaAO: 1 |
|||
m_ShowResolutionOverlay: 1 |
|||
m_LightingDataAsset: {fileID: 112000002, guid: fd8f2c6386dc54f158818f3b4ce8a20d, type: 2} |
|||
m_UseShadowmask: 0 |
|||
--- !u!196 &4 |
|||
NavMeshSettings: |
|||
serializedVersion: 2 |
|||
m_ObjectHideFlags: 0 |
|||
m_BuildSettings: |
|||
serializedVersion: 2 |
|||
agentTypeID: 0 |
|||
agentRadius: 0.5 |
|||
agentHeight: 2 |
|||
agentSlope: 45 |
|||
agentClimb: 0.4 |
|||
ledgeDropHeight: 0 |
|||
maxJumpAcrossDistance: 0 |
|||
minRegionArea: 2 |
|||
manualCellSize: 0 |
|||
cellSize: 0.16666667 |
|||
manualTileSize: 0 |
|||
tileSize: 256 |
|||
accuratePlacement: 0 |
|||
debug: |
|||
m_Flags: 0 |
|||
m_NavMeshData: {fileID: 0} |
|||
--- !u!1 &234236910 |
|||
GameObject: |
|||
m_ObjectHideFlags: 0 |
|||
m_CorrespondingSourceObject: {fileID: 0} |
|||
m_PrefabInternal: {fileID: 0} |
|||
serializedVersion: 6 |
|||
m_Component: |
|||
- component: {fileID: 234236914} |
|||
- component: {fileID: 234236913} |
|||
- component: {fileID: 234236912} |
|||
- component: {fileID: 234236911} |
|||
m_Layer: 0 |
|||
m_Name: Cube (1) |
|||
m_TagString: Untagged |
|||
m_Icon: {fileID: 0} |
|||
m_NavMeshLayer: 0 |
|||
m_StaticEditorFlags: 0 |
|||
m_IsActive: 1 |
|||
--- !u!23 &234236911 |
|||
MeshRenderer: |
|||
m_ObjectHideFlags: 0 |
|||
m_CorrespondingSourceObject: {fileID: 0} |
|||
m_PrefabInternal: {fileID: 0} |
|||
m_GameObject: {fileID: 234236910} |
|||
m_Enabled: 1 |
|||
m_CastShadows: 1 |
|||
m_ReceiveShadows: 1 |
|||
m_DynamicOccludee: 1 |
|||
m_MotionVectors: 1 |
|||
m_LightProbeUsage: 1 |
|||
m_ReflectionProbeUsage: 1 |
|||
m_RenderingLayerMask: 4294967295 |
|||
m_Materials: |
|||
- {fileID: 2100000, guid: 14ba8c0a5d5381f4fb7ef200c8c10b26, type: 2} |
|||
m_StaticBatchInfo: |
|||
firstSubMesh: 0 |
|||
subMeshCount: 0 |
|||
m_StaticBatchRoot: {fileID: 0} |
|||
m_ProbeAnchor: {fileID: 0} |
|||
m_LightProbeVolumeOverride: {fileID: 0} |
|||
m_ScaleInLightmap: 1 |
|||
m_PreserveUVs: 1 |
|||
m_IgnoreNormalsForChartDetection: 0 |
|||
m_ImportantGI: 0 |
|||
m_StitchLightmapSeams: 0 |
|||
m_SelectedEditorRenderState: 3 |
|||
m_MinimumChartSize: 4 |
|||
m_AutoUVMaxDistance: 0.5 |
|||
m_AutoUVMaxAngle: 89 |
|||
m_LightmapParameters: {fileID: 0} |
|||
m_SortingLayerID: 0 |
|||
m_SortingLayer: 0 |
|||
m_SortingOrder: 0 |
|||
--- !u!65 &234236912 |
|||
BoxCollider: |
|||
m_ObjectHideFlags: 0 |
|||
m_CorrespondingSourceObject: {fileID: 0} |
|||
m_PrefabInternal: {fileID: 0} |
|||
m_GameObject: {fileID: 234236910} |
|||
m_Material: {fileID: 0} |
|||
m_IsTrigger: 0 |
|||
m_Enabled: 1 |
|||
serializedVersion: 2 |
|||
m_Size: {x: 1, y: 1, z: 1} |
|||
m_Center: {x: 0, y: 0, z: 0} |
|||
--- !u!33 &234236913 |
|||
MeshFilter: |
|||
m_ObjectHideFlags: 0 |
|||
m_CorrespondingSourceObject: {fileID: 0} |
|||
m_PrefabInternal: {fileID: 0} |
|||
m_GameObject: {fileID: 234236910} |
|||
m_Mesh: {fileID: 10202, guid: 0000000000000000e000000000000000, type: 0} |
|||
--- !u!4 &234236914 |
|||
Transform: |
|||
m_ObjectHideFlags: 0 |
|||
m_CorrespondingSourceObject: {fileID: 0} |
|||
m_PrefabInternal: {fileID: 0} |
|||
m_GameObject: {fileID: 234236910} |
|||
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} |
|||
m_LocalPosition: {x: -1.244, y: 0.82283884, z: 27.958} |
|||
m_LocalScale: {x: 1, y: 1, z: 1} |
|||
m_Children: [] |
|||
m_Father: {fileID: 0} |
|||
m_RootOrder: 3 |
|||
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} |
|||
--- !u!1 &380492249 |
|||
GameObject: |
|||
m_ObjectHideFlags: 0 |
|||
m_CorrespondingSourceObject: {fileID: 0} |
|||
m_PrefabInternal: {fileID: 0} |
|||
serializedVersion: 6 |
|||
m_Component: |
|||
- component: {fileID: 380492254} |
|||
- component: {fileID: 380492253} |
|||
- component: {fileID: 380492251} |
|||
- component: {fileID: 380492250} |
|||
- component: {fileID: 380492252} |
|||
- component: {fileID: 380492255} |
|||
m_Layer: 0 |
|||
m_Name: Main Camera |
|||
m_TagString: MainCamera |
|||
m_Icon: {fileID: 0} |
|||
m_NavMeshLayer: 0 |
|||
m_StaticEditorFlags: 0 |
|||
m_IsActive: 1 |
|||
--- !u!81 &380492250 |
|||
AudioListener: |
|||
m_ObjectHideFlags: 0 |
|||
m_CorrespondingSourceObject: {fileID: 0} |
|||
m_PrefabInternal: {fileID: 0} |
|||
m_GameObject: {fileID: 380492249} |
|||
m_Enabled: 1 |
|||
--- !u!124 &380492251 |
|||
Behaviour: |
|||
m_ObjectHideFlags: 0 |
|||
m_CorrespondingSourceObject: {fileID: 0} |
|||
m_PrefabInternal: {fileID: 0} |
|||
m_GameObject: {fileID: 380492249} |
|||
m_Enabled: 1 |
|||
--- !u!114 &380492252 |
|||
MonoBehaviour: |
|||
m_ObjectHideFlags: 0 |
|||
m_CorrespondingSourceObject: {fileID: 0} |
|||
m_PrefabInternal: {fileID: 0} |
|||
m_GameObject: {fileID: 380492249} |
|||
m_Enabled: 1 |
|||
m_EditorHideFlags: 0 |
|||
m_Script: {fileID: 11500000, guid: 73231aa468d81ea49bc3d914080de185, type: 3} |
|||
m_Name: |
|||
m_EditorClassIdentifier: |
|||
ImageComparisonSettings: |
|||
TargetWidth: 512 |
|||
TargetHeight: 512 |
|||
PerPixelCorrectnessThreshold: 0.005 |
|||
AverageCorrectnessThreshold: 0.005 |
|||
WaitFrames: 0 |
|||
--- !u!20 &380492253 |
|||
Camera: |
|||
m_ObjectHideFlags: 0 |
|||
m_CorrespondingSourceObject: {fileID: 0} |
|||
m_PrefabInternal: {fileID: 0} |
|||
m_GameObject: {fileID: 380492249} |
|||
m_Enabled: 1 |
|||
serializedVersion: 2 |
|||
m_ClearFlags: 1 |
|||
m_BackGroundColor: {r: 0.19215687, g: 0.3019608, b: 0.4745098, a: 1} |
|||
m_projectionMatrixMode: 1 |
|||
m_SensorSize: {x: 36, y: 24} |
|||
m_LensShift: {x: 0, y: 0} |
|||
m_FocalLength: 50 |
|||
m_NormalizedViewPortRect: |
|||
serializedVersion: 2 |
|||
x: 0 |
|||
y: 0 |
|||
width: 1 |
|||
height: 1 |
|||
near clip plane: 0.3 |
|||
far clip plane: 1000 |
|||
field of view: 60 |
|||
orthographic: 0 |
|||
orthographic size: 5 |
|||
m_Depth: -1 |
|||
m_CullingMask: |
|||
serializedVersion: 2 |
|||
m_Bits: 4294967295 |
|||
m_RenderingPath: -1 |
|||
m_TargetTexture: {fileID: 0} |
|||
m_TargetDisplay: 0 |
|||
m_TargetEye: 3 |
|||
m_HDR: 1 |
|||
m_AllowMSAA: 1 |
|||
m_AllowDynamicResolution: 0 |
|||
m_ForceIntoRT: 0 |
|||
m_OcclusionCulling: 1 |
|||
m_StereoConvergence: 10 |
|||
m_StereoSeparation: 0.022 |
|||
--- !u!4 &380492254 |
|||
Transform: |
|||
m_ObjectHideFlags: 0 |
|||
m_CorrespondingSourceObject: {fileID: 0} |
|||
m_PrefabInternal: {fileID: 0} |
|||
m_GameObject: {fileID: 380492249} |
|||
m_LocalRotation: {x: 0.24609356, y: 0.36251447, z: -0.099864565, w: 0.89333546} |
|||
m_LocalPosition: {x: -3.6031294, y: 2.2863412, z: 26.36942} |
|||
m_LocalScale: {x: 1, y: 1, z: 1} |
|||
m_Children: [] |
|||
m_Father: {fileID: 0} |
|||
m_RootOrder: 0 |
|||
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} |
|||
--- !u!114 &380492255 |
|||
MonoBehaviour: |
|||
m_ObjectHideFlags: 0 |
|||
m_CorrespondingSourceObject: {fileID: 0} |
|||
m_PrefabInternal: {fileID: 0} |
|||
m_GameObject: {fileID: 380492249} |
|||
m_Enabled: 1 |
|||
m_EditorHideFlags: 0 |
|||
m_Script: {fileID: 11500000, guid: 7e0da365be9e44c3bae8da691ccd8de6, type: 3} |
|||
m_Name: |
|||
m_EditorClassIdentifier: |
|||
--- !u!1 &707831285 |
|||
GameObject: |
|||
m_ObjectHideFlags: 0 |
|||
m_CorrespondingSourceObject: {fileID: 0} |
|||
m_PrefabInternal: {fileID: 0} |
|||
serializedVersion: 6 |
|||
m_Component: |
|||
- component: {fileID: 707831287} |
|||
- component: {fileID: 707831286} |
|||
m_Layer: 0 |
|||
m_Name: Directional Light |
|||
m_TagString: Untagged |
|||
m_Icon: {fileID: 0} |
|||
m_NavMeshLayer: 0 |
|||
m_StaticEditorFlags: 0 |
|||
m_IsActive: 1 |
|||
--- !u!108 &707831286 |
|||
Light: |
|||
m_ObjectHideFlags: 0 |
|||
m_CorrespondingSourceObject: {fileID: 0} |
|||
m_PrefabInternal: {fileID: 0} |
|||
m_GameObject: {fileID: 707831285} |
|||
m_Enabled: 1 |
|||
serializedVersion: 8 |
|||
m_Type: 1 |
|||
m_Color: {r: 1, g: 0.95686275, b: 0.8392157, a: 1} |
|||
m_Intensity: 1 |
|||
m_Range: 10 |
|||
m_SpotAngle: 30 |
|||
m_CookieSize: 10 |
|||
m_Shadows: |
|||
m_Type: 2 |
|||
m_Resolution: -1 |
|||
m_CustomResolution: -1 |
|||
m_Strength: 1 |
|||
m_Bias: 0.05 |
|||
m_NormalBias: 0.4 |
|||
m_NearPlane: 0.2 |
|||
m_Cookie: {fileID: 0} |
|||
m_DrawHalo: 0 |
|||
m_Flare: {fileID: 0} |
|||
m_RenderMode: 0 |
|||
m_CullingMask: |
|||
serializedVersion: 2 |
|||
m_Bits: 4294967295 |
|||
m_Lightmapping: 4 |
|||
m_LightShadowCasterMode: 0 |
|||
m_AreaSize: {x: 1, y: 1} |
|||
m_BounceIntensity: 1 |
|||
m_ColorTemperature: 6570 |
|||
m_UseColorTemperature: 0 |
|||
m_ShadowRadius: 0 |
|||
m_ShadowAngle: 0 |
|||
--- !u!4 &707831287 |
|||
Transform: |
|||
m_ObjectHideFlags: 0 |
|||
m_CorrespondingSourceObject: {fileID: 0} |
|||
m_PrefabInternal: {fileID: 0} |
|||
m_GameObject: {fileID: 707831285} |
|||
m_LocalRotation: {x: 0.40821788, y: -0.23456968, z: 0.10938163, w: 0.8754261} |
|||
m_LocalPosition: {x: 0, y: 3, z: 0} |
|||
m_LocalScale: {x: 1, y: 1, z: 1} |
|||
m_Children: [] |
|||
m_Father: {fileID: 0} |
|||
m_RootOrder: 1 |
|||
m_LocalEulerAnglesHint: {x: 50, y: -30, z: 0} |
|||
--- !u!1 &1203640971 |
|||
GameObject: |
|||
m_ObjectHideFlags: 0 |
|||
m_CorrespondingSourceObject: {fileID: 0} |
|||
m_PrefabInternal: {fileID: 0} |
|||
serializedVersion: 6 |
|||
m_Component: |
|||
- component: {fileID: 1203640975} |
|||
- component: {fileID: 1203640974} |
|||
- component: {fileID: 1203640973} |
|||
- component: {fileID: 1203640972} |
|||
m_Layer: 0 |
|||
m_Name: Cube |
|||
m_TagString: Untagged |
|||
m_Icon: {fileID: 0} |
|||
m_NavMeshLayer: 0 |
|||
m_StaticEditorFlags: 0 |
|||
m_IsActive: 1 |
|||
--- !u!23 &1203640972 |
|||
MeshRenderer: |
|||
m_ObjectHideFlags: 0 |
|||
m_CorrespondingSourceObject: {fileID: 0} |
|||
m_PrefabInternal: {fileID: 0} |
|||
m_GameObject: {fileID: 1203640971} |
|||
m_Enabled: 1 |
|||
m_CastShadows: 1 |
|||
m_ReceiveShadows: 1 |
|||
m_DynamicOccludee: 1 |
|||
m_MotionVectors: 1 |
|||
m_LightProbeUsage: 1 |
|||
m_ReflectionProbeUsage: 1 |
|||
m_RenderingLayerMask: 4294967295 |
|||
m_Materials: |
|||
- {fileID: 2100000, guid: 2875962f52041b64ab757b73da605810, type: 2} |
|||
m_StaticBatchInfo: |
|||
firstSubMesh: 0 |
|||
subMeshCount: 0 |
|||
m_StaticBatchRoot: {fileID: 0} |
|||
m_ProbeAnchor: {fileID: 0} |
|||
m_LightProbeVolumeOverride: {fileID: 0} |
|||
m_ScaleInLightmap: 1 |
|||
m_PreserveUVs: 1 |
|||
m_IgnoreNormalsForChartDetection: 0 |
|||
m_ImportantGI: 0 |
|||
m_StitchLightmapSeams: 0 |
|||
m_SelectedEditorRenderState: 3 |
|||
m_MinimumChartSize: 4 |
|||
m_AutoUVMaxDistance: 0.5 |
|||
m_AutoUVMaxAngle: 89 |
|||
m_LightmapParameters: {fileID: 0} |
|||
m_SortingLayerID: 0 |
|||
m_SortingLayer: 0 |
|||
m_SortingOrder: 0 |
|||
--- !u!65 &1203640973 |
|||
BoxCollider: |
|||
m_ObjectHideFlags: 0 |
|||
m_CorrespondingSourceObject: {fileID: 0} |
|||
m_PrefabInternal: {fileID: 0} |
|||
m_GameObject: {fileID: 1203640971} |
|||
m_Material: {fileID: 0} |
|||
m_IsTrigger: 0 |
|||
m_Enabled: 1 |
|||
serializedVersion: 2 |
|||
m_Size: {x: 1, y: 1, z: 1} |
|||
m_Center: {x: 0, y: 0, z: 0} |
|||
--- !u!33 &1203640974 |
|||
MeshFilter: |
|||
m_ObjectHideFlags: 0 |
|||
m_CorrespondingSourceObject: {fileID: 0} |
|||
m_PrefabInternal: {fileID: 0} |
|||
m_GameObject: {fileID: 1203640971} |
|||
m_Mesh: {fileID: 10202, guid: 0000000000000000e000000000000000, type: 0} |
|||
--- !u!4 &1203640975 |
|||
Transform: |
|||
m_ObjectHideFlags: 0 |
|||
m_CorrespondingSourceObject: {fileID: 0} |
|||
m_PrefabInternal: {fileID: 0} |
|||
m_GameObject: {fileID: 1203640971} |
|||
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} |
|||
m_LocalPosition: {x: -1.8925657, y: 0.82283884, z: 28.129997} |
|||
m_LocalScale: {x: 1, y: 1, z: 1} |
|||
m_Children: [] |
|||
m_Father: {fileID: 0} |
|||
m_RootOrder: 2 |
|||
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} |
|
|||
fileFormatVersion: 2 |
|||
guid: 349df85634812cd4e9157f31eace4abe |
|||
timeCreated: 1493133740 |
|||
licenseType: Pro |
|||
DefaultImporter: |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
using System; |
|||
using UnityEngine.Rendering; |
|||
|
|||
namespace UnityEngine.Experimental.Rendering.LightweightPipeline |
|||
{ |
|||
public class DefaultRendererSetup : IRendererSetup |
|||
{ |
|||
private DepthOnlyPass m_DepthOnlyPass; |
|||
private DirectionalShadowsPass m_DirectionalShadowPass; |
|||
private LocalShadowsPass m_LocalShadowPass; |
|||
private SetupForwardRenderingPass m_SetupForwardRenderingPass; |
|||
private ScreenSpaceShadowResolvePass m_ScreenSpaceShadowResovePass; |
|||
private CreateLightweightRenderTexturesPass m_CreateLightweightRenderTexturesPass; |
|||
private BeginXRRenderingPass m_BeginXrRenderingPass; |
|||
private SetupLightweightConstanstPass m_SetupLightweightConstants; |
|||
private RenderOpaqueForwardPass m_RenderOpaqueForwardPass; |
|||
private OpaquePostProcessPass m_OpaquePostProcessPass; |
|||
private DrawSkyboxPass m_DrawSkyboxPass; |
|||
private CopyDepthPass m_CopyDepthPass; |
|||
private CopyColorPass m_CopyColorPass; |
|||
private RenderTransparentForwardPass m_RenderTransparentForwardPass; |
|||
private TransparentPostProcessPass m_TransparentPostProcessPass; |
|||
private FinalBlitPass m_FinalBlitPass; |
|||
private EndXRRenderingPass m_EndXrRenderingPass; |
|||
|
|||
#if UNITY_EDITOR
|
|||
private SceneViewDepthCopyPass m_SceneViewDepthCopyPass; |
|||
#endif
|
|||
|
|||
|
|||
private RenderTargetHandle Color; |
|||
private RenderTargetHandle DepthAttachment; |
|||
private RenderTargetHandle DepthTexture; |
|||
private RenderTargetHandle OpaqueColor; |
|||
private RenderTargetHandle DirectionalShadowmap; |
|||
private RenderTargetHandle LocalShadowmap; |
|||
private RenderTargetHandle ScreenSpaceShadowmap; |
|||
|
|||
[NonSerialized] |
|||
private bool m_Initialized = false; |
|||
|
|||
private void Init(LightweightForwardRenderer renderer) |
|||
{ |
|||
if (m_Initialized) |
|||
return; |
|||
|
|||
m_DepthOnlyPass = new DepthOnlyPass(renderer); |
|||
m_DirectionalShadowPass = new DirectionalShadowsPass(renderer); |
|||
m_LocalShadowPass = new LocalShadowsPass(renderer); |
|||
m_SetupForwardRenderingPass = new SetupForwardRenderingPass(renderer); |
|||
m_ScreenSpaceShadowResovePass = new ScreenSpaceShadowResolvePass(renderer); |
|||
m_CreateLightweightRenderTexturesPass = new CreateLightweightRenderTexturesPass(renderer); |
|||
m_BeginXrRenderingPass = new BeginXRRenderingPass(renderer); |
|||
m_SetupLightweightConstants = new SetupLightweightConstanstPass(renderer); |
|||
m_RenderOpaqueForwardPass = new RenderOpaqueForwardPass(renderer); |
|||
m_OpaquePostProcessPass = new OpaquePostProcessPass(renderer); |
|||
m_DrawSkyboxPass = new DrawSkyboxPass(renderer); |
|||
m_CopyDepthPass = new CopyDepthPass(renderer); |
|||
m_CopyColorPass = new CopyColorPass(renderer); |
|||
m_RenderTransparentForwardPass = new RenderTransparentForwardPass(renderer); |
|||
m_TransparentPostProcessPass = new TransparentPostProcessPass(renderer); |
|||
m_FinalBlitPass = new FinalBlitPass(renderer); |
|||
m_EndXrRenderingPass = new EndXRRenderingPass(renderer); |
|||
|
|||
#if UNITY_EDITOR
|
|||
m_SceneViewDepthCopyPass = new SceneViewDepthCopyPass(renderer); |
|||
#endif
|
|||
|
|||
// RenderTexture format depends on camera and pipeline (HDR, non HDR, etc)
|
|||
// Samples (MSAA) depend on camera and pipeline
|
|||
Color.Init("_CameraColorTexture"); |
|||
DepthAttachment.Init("_CameraDepthAttachment"); |
|||
DepthTexture.Init("_CameraDepthTexture"); |
|||
OpaqueColor.Init("_CameraOpaqueTexture"); |
|||
DirectionalShadowmap.Init("_DirectionalShadowmapTexture"); |
|||
LocalShadowmap.Init("_LocalShadowmapTexture"); |
|||
ScreenSpaceShadowmap.Init("_ScreenSpaceShadowMapTexture"); |
|||
|
|||
m_Initialized = true; |
|||
} |
|||
|
|||
public void Setup(LightweightForwardRenderer renderer, ref ScriptableRenderContext context, |
|||
ref CullResults cullResults, ref RenderingData renderingData) |
|||
{ |
|||
Init(renderer); |
|||
|
|||
renderer.Clear(); |
|||
|
|||
renderer.SetupPerObjectLightIndices(ref cullResults, ref renderingData.lightData); |
|||
RenderTextureDescriptor baseDescriptor = renderer.CreateRTDesc(ref renderingData.cameraData); |
|||
RenderTextureDescriptor shadowDescriptor = baseDescriptor; |
|||
shadowDescriptor.dimension = TextureDimension.Tex2D; |
|||
|
|||
bool requiresCameraDepth = renderingData.cameraData.requiresDepthTexture; |
|||
bool requiresDepthPrepass = renderingData.shadowData.requiresScreenSpaceShadowResolve || |
|||
renderingData.cameraData.isSceneViewCamera || |
|||
(requiresCameraDepth && |
|||
!LightweightForwardRenderer.CanCopyDepth(ref renderingData.cameraData)); |
|||
|
|||
// For now VR requires a depth prepass until we figure out how to properly resolve texture2DMS in stereo
|
|||
requiresDepthPrepass |= renderingData.cameraData.isStereoEnabled; |
|||
|
|||
if (renderingData.shadowData.renderDirectionalShadows) |
|||
{ |
|||
m_DirectionalShadowPass.Setup(DirectionalShadowmap); |
|||
renderer.EnqueuePass(m_DirectionalShadowPass); |
|||
} |
|||
|
|||
if (renderingData.shadowData.renderLocalShadows) |
|||
{ |
|||
|
|||
m_LocalShadowPass.Setup(LocalShadowmap); |
|||
renderer.EnqueuePass(m_LocalShadowPass); |
|||
} |
|||
|
|||
renderer.EnqueuePass(m_SetupForwardRenderingPass); |
|||
|
|||
if (requiresDepthPrepass) |
|||
{ |
|||
m_DepthOnlyPass.Setup(baseDescriptor, DepthTexture, SampleCount.One); |
|||
renderer.EnqueuePass(m_DepthOnlyPass); |
|||
} |
|||
|
|||
if (renderingData.shadowData.renderDirectionalShadows && |
|||
renderingData.shadowData.requiresScreenSpaceShadowResolve) |
|||
{ |
|||
m_ScreenSpaceShadowResovePass.Setup(baseDescriptor, ScreenSpaceShadowmap); |
|||
renderer.EnqueuePass(m_ScreenSpaceShadowResovePass); |
|||
} |
|||
|
|||
bool requiresDepthAttachment = requiresCameraDepth && !requiresDepthPrepass; |
|||
bool requiresColorAttachment = |
|||
LightweightForwardRenderer.RequiresIntermediateColorTexture( |
|||
ref renderingData.cameraData, |
|||
baseDescriptor, |
|||
requiresDepthAttachment); |
|||
RenderTargetHandle colorHandle = (requiresColorAttachment) ? Color : RenderTargetHandle.CameraTarget; |
|||
RenderTargetHandle depthHandle = (requiresDepthAttachment) ? DepthAttachment : RenderTargetHandle.CameraTarget; |
|||
|
|||
var sampleCount = (SampleCount) renderingData.cameraData.msaaSamples; |
|||
m_CreateLightweightRenderTexturesPass.Setup(baseDescriptor, colorHandle, depthHandle, sampleCount); |
|||
renderer.EnqueuePass(m_CreateLightweightRenderTexturesPass); |
|||
|
|||
if (renderingData.cameraData.isStereoEnabled) |
|||
renderer.EnqueuePass(m_BeginXrRenderingPass); |
|||
|
|||
Camera camera = renderingData.cameraData.camera; |
|||
bool dynamicBatching = renderingData.supportsDynamicBatching; |
|||
RendererConfiguration rendererConfiguration = LightweightForwardRenderer.GetRendererConfiguration(renderingData.lightData.totalAdditionalLightsCount); |
|||
|
|||
renderer.EnqueuePass(m_SetupLightweightConstants); |
|||
|
|||
m_RenderOpaqueForwardPass.Setup(baseDescriptor, colorHandle, depthHandle, LightweightForwardRenderer.GetCameraClearFlag(camera), camera.backgroundColor, rendererConfiguration,dynamicBatching); |
|||
renderer.EnqueuePass(m_RenderOpaqueForwardPass); |
|||
|
|||
if (renderingData.cameraData.postProcessEnabled && |
|||
renderingData.cameraData.postProcessLayer.HasOpaqueOnlyEffects(renderer.postProcessRenderContext)) |
|||
{ |
|||
m_OpaquePostProcessPass.Setup(baseDescriptor, colorHandle); |
|||
renderer.EnqueuePass(m_OpaquePostProcessPass); |
|||
} |
|||
|
|||
if (camera.clearFlags == CameraClearFlags.Skybox) |
|||
renderer.EnqueuePass(m_DrawSkyboxPass); |
|||
|
|||
if (depthHandle != RenderTargetHandle.CameraTarget) |
|||
{ |
|||
m_CopyDepthPass.Setup(depthHandle, DepthTexture); |
|||
renderer.EnqueuePass(m_CopyDepthPass); |
|||
} |
|||
|
|||
if (renderingData.cameraData.requiresOpaqueTexture) |
|||
{ |
|||
m_CopyColorPass.Setup(colorHandle, OpaqueColor); |
|||
renderer.EnqueuePass(m_CopyColorPass); |
|||
} |
|||
|
|||
m_RenderTransparentForwardPass.Setup(baseDescriptor, colorHandle, depthHandle, ClearFlag.None, camera.backgroundColor, rendererConfiguration, dynamicBatching); |
|||
renderer.EnqueuePass(m_RenderTransparentForwardPass); |
|||
|
|||
if (renderingData.cameraData.postProcessEnabled) |
|||
{ |
|||
m_TransparentPostProcessPass.Setup(baseDescriptor, colorHandle); |
|||
renderer.EnqueuePass(m_TransparentPostProcessPass); |
|||
} |
|||
else if (!renderingData.cameraData.isOffscreenRender && colorHandle != RenderTargetHandle.CameraTarget) |
|||
{ |
|||
m_FinalBlitPass.Setup(baseDescriptor, colorHandle); |
|||
renderer.EnqueuePass(m_FinalBlitPass); |
|||
} |
|||
|
|||
if (renderingData.cameraData.isStereoEnabled) |
|||
{ |
|||
renderer.EnqueuePass(m_EndXrRenderingPass); |
|||
} |
|||
|
|||
#if UNITY_EDITOR
|
|||
if (renderingData.cameraData.isSceneViewCamera) |
|||
{ |
|||
m_SceneViewDepthCopyPass.Setup(DepthTexture); |
|||
renderer.EnqueuePass(m_SceneViewDepthCopyPass); |
|||
} |
|||
#endif
|
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 819a1532a6d186b4cb1272f8d6e80293 |
|||
MonoImporter: |
|||
externalObjects: {} |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
namespace UnityEngine.Experimental.Rendering.LightweightPipeline |
|||
{ |
|||
public interface IRendererSetup |
|||
{ |
|||
|
|||
void Setup(LightweightForwardRenderer renderer, ref ScriptableRenderContext context, ref CullResults cullResults, ref RenderingData renderingData); |
|||
|
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 9653fd959509ebd4892b1eae39e72882 |
|||
MonoImporter: |
|||
externalObjects: {} |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
namespace UnityEngine.Experimental.Rendering.LightweightPipeline |
|||
{ |
|||
public enum MaterialHandles |
|||
{ |
|||
Error, |
|||
DepthCopy, |
|||
Sampling, |
|||
Blit, |
|||
ScrenSpaceShadow, |
|||
Count, |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 226d74c5977657e4ea6e9e519545fcff |
|||
MonoImporter: |
|||
externalObjects: {} |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
namespace UnityEngine.Experimental.Rendering.LightweightPipeline |
|||
{ |
|||
public class BeginXRRenderingPass : ScriptableRenderPass |
|||
{ |
|||
public BeginXRRenderingPass(LightweightForwardRenderer renderer) : base(renderer) |
|||
{} |
|||
|
|||
public override void Execute(ref ScriptableRenderContext context, ref CullResults cullResults, ref RenderingData renderingData) |
|||
{ |
|||
Camera camera = renderingData.cameraData.camera; |
|||
context.StartMultiEye(camera); |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: f5b81f8e725d00545a683af3fd5e2f83 |
|||
MonoImporter: |
|||
externalObjects: {} |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
using UnityEngine.Rendering; |
|||
|
|||
namespace UnityEngine.Experimental.Rendering.LightweightPipeline |
|||
{ |
|||
public class CopyColorPass : ScriptableRenderPass |
|||
{ |
|||
Material m_SamplingMaterial; |
|||
float[] m_OpaqueScalerValues = {1.0f, 0.5f, 0.25f, 0.25f}; |
|||
int m_SampleOffsetShaderHandle; |
|||
|
|||
private RenderTargetHandle source { get; set; } |
|||
private RenderTargetHandle destination { get; set; } |
|||
|
|||
public CopyColorPass(LightweightForwardRenderer renderer) : base(renderer) |
|||
{ |
|||
m_SamplingMaterial = renderer.GetMaterial(MaterialHandles.Sampling); |
|||
m_SampleOffsetShaderHandle = Shader.PropertyToID("_SampleOffset"); |
|||
} |
|||
|
|||
public void Setup(RenderTargetHandle source, RenderTargetHandle destination) |
|||
{ |
|||
this.source = source; |
|||
this.destination = destination; |
|||
} |
|||
|
|||
public override void Execute(ref ScriptableRenderContext context, ref CullResults cullResults, ref RenderingData renderingData) |
|||
{ |
|||
|
|||
CommandBuffer cmd = CommandBufferPool.Get("Copy Color"); |
|||
Downsampling downsampling = renderingData.cameraData.opaqueTextureDownsampling; |
|||
float opaqueScaler = m_OpaqueScalerValues[(int)downsampling]; |
|||
|
|||
RenderTextureDescriptor opaqueDesc = renderer.CreateRTDesc(ref renderingData.cameraData, opaqueScaler); |
|||
RenderTargetIdentifier colorRT = source.Identifier(); |
|||
RenderTargetIdentifier opaqueColorRT = destination.Identifier(); |
|||
|
|||
cmd.GetTemporaryRT(destination.id, opaqueDesc, renderingData.cameraData.opaqueTextureDownsampling == Downsampling.None ? FilterMode.Point : FilterMode.Bilinear); |
|||
switch (downsampling) |
|||
{ |
|||
case Downsampling.None: |
|||
cmd.Blit(colorRT, opaqueColorRT); |
|||
break; |
|||
case Downsampling._2xBilinear: |
|||
cmd.Blit(colorRT, opaqueColorRT); |
|||
break; |
|||
case Downsampling._4xBox: |
|||
m_SamplingMaterial.SetFloat(m_SampleOffsetShaderHandle, 2); |
|||
cmd.Blit(colorRT, opaqueColorRT, m_SamplingMaterial, 0); |
|||
break; |
|||
case Downsampling._4xBilinear: |
|||
cmd.Blit(colorRT, opaqueColorRT); |
|||
break; |
|||
} |
|||
|
|||
context.ExecuteCommandBuffer(cmd); |
|||
CommandBufferPool.Release(cmd); |
|||
} |
|||
|
|||
|
|||
public override void Dispose(CommandBuffer cmd) |
|||
{ |
|||
if (destination != RenderTargetHandle.CameraTarget) |
|||
{ |
|||
cmd.ReleaseTemporaryRT(destination.id); |
|||
destination = RenderTargetHandle.CameraTarget; |
|||
} |
|||
} |
|||
|
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 7e18083ec47e7446fac286a4ecd439fc |
|||
MonoImporter: |
|||
externalObjects: {} |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
using UnityEngine.Rendering; |
|||
|
|||
namespace UnityEngine.Experimental.Rendering.LightweightPipeline |
|||
{ |
|||
public class CopyDepthPass : ScriptableRenderPass |
|||
{ |
|||
Material m_DepthCopyMaterial; |
|||
|
|||
private RenderTargetHandle source { get; set; } |
|||
private RenderTargetHandle destination { get; set; } |
|||
|
|||
|
|||
public CopyDepthPass(LightweightForwardRenderer renderer) : base(renderer) |
|||
{ |
|||
m_DepthCopyMaterial = renderer.GetMaterial(MaterialHandles.DepthCopy); |
|||
} |
|||
|
|||
public void Setup(RenderTargetHandle source, RenderTargetHandle destination) |
|||
{ |
|||
this.source = source; |
|||
this.destination = destination; |
|||
} |
|||
|
|||
public override void Execute(ref ScriptableRenderContext context, ref CullResults cullResults, ref RenderingData renderingData) |
|||
{ |
|||
CommandBuffer cmd = CommandBufferPool.Get("Depth Copy"); |
|||
RenderTargetIdentifier depthSurface = source.Identifier(); |
|||
RenderTargetIdentifier copyDepthSurface = destination.Identifier(); |
|||
|
|||
RenderTextureDescriptor descriptor = renderer.CreateRTDesc(ref renderingData.cameraData); |
|||
descriptor.colorFormat = RenderTextureFormat.Depth; |
|||
descriptor.depthBufferBits = 32; //TODO: fix this ;
|
|||
descriptor.msaaSamples = 1; |
|||
descriptor.bindMS = false; |
|||
cmd.GetTemporaryRT(destination.id, descriptor, FilterMode.Point); |
|||
|
|||
if (renderingData.cameraData.msaaSamples > 1) |
|||
{ |
|||
cmd.DisableShaderKeyword(LightweightKeywordStrings.DepthNoMsaa); |
|||
if (renderingData.cameraData.msaaSamples == 4) |
|||
{ |
|||
cmd.DisableShaderKeyword(LightweightKeywordStrings.DepthMsaa2); |
|||
cmd.EnableShaderKeyword(LightweightKeywordStrings.DepthMsaa4); |
|||
} |
|||
else |
|||
{ |
|||
cmd.EnableShaderKeyword(LightweightKeywordStrings.DepthMsaa2); |
|||
cmd.DisableShaderKeyword(LightweightKeywordStrings.DepthMsaa4); |
|||
} |
|||
cmd.Blit(depthSurface, copyDepthSurface, m_DepthCopyMaterial); |
|||
} |
|||
else |
|||
{ |
|||
cmd.EnableShaderKeyword(LightweightKeywordStrings.DepthNoMsaa); |
|||
cmd.DisableShaderKeyword(LightweightKeywordStrings.DepthMsaa2); |
|||
cmd.DisableShaderKeyword(LightweightKeywordStrings.DepthMsaa4); |
|||
LightweightPipeline.CopyTexture(cmd, depthSurface, copyDepthSurface, m_DepthCopyMaterial); |
|||
} |
|||
context.ExecuteCommandBuffer(cmd); |
|||
CommandBufferPool.Release(cmd); |
|||
} |
|||
|
|||
public override void Dispose(CommandBuffer cmd) |
|||
{ |
|||
if (destination != RenderTargetHandle.CameraTarget) |
|||
{ |
|||
cmd.ReleaseTemporaryRT(destination.id); |
|||
destination = RenderTargetHandle.CameraTarget; |
|||
} |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: d6268b3babfc1004c82ace3c407f46ef |
|||
MonoImporter: |
|||
externalObjects: {} |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
using UnityEngine.Rendering; |
|||
|
|||
namespace UnityEngine.Experimental.Rendering.LightweightPipeline |
|||
{ |
|||
public class CreateLightweightRenderTexturesPass : ScriptableRenderPass |
|||
{ |
|||
public CreateLightweightRenderTexturesPass(LightweightForwardRenderer renderer) : base(renderer) |
|||
{} |
|||
|
|||
const int k_DepthStencilBufferBits = 32; |
|||
private RenderTargetHandle colorAttachmentHandle { get; set; } |
|||
private RenderTargetHandle depthAttachmentHandle { get; set; } |
|||
private RenderTextureDescriptor descriptor { get; set; } |
|||
private SampleCount samples { get; set; } |
|||
|
|||
public void Setup( |
|||
RenderTextureDescriptor baseDescriptor, |
|||
RenderTargetHandle colorAttachmentHandle, |
|||
RenderTargetHandle depthAttachmentHandle, |
|||
SampleCount samples) |
|||
{ |
|||
this.colorAttachmentHandle = colorAttachmentHandle; |
|||
this.depthAttachmentHandle = depthAttachmentHandle; |
|||
this.samples = samples; |
|||
descriptor = baseDescriptor; |
|||
} |
|||
|
|||
public override void Execute(ref ScriptableRenderContext context, ref CullResults cullResults, ref RenderingData renderingData) |
|||
{ |
|||
CommandBuffer cmd = CommandBufferPool.Get(""); |
|||
if (colorAttachmentHandle != RenderTargetHandle.CameraTarget) |
|||
{ |
|||
var colorDescriptor = descriptor; |
|||
colorDescriptor.depthBufferBits = k_DepthStencilBufferBits; // TODO: does the color RT always need depth?
|
|||
colorDescriptor.sRGB = true; |
|||
colorDescriptor.msaaSamples = (int) samples; |
|||
cmd.GetTemporaryRT(colorAttachmentHandle.id, colorDescriptor, FilterMode.Bilinear); |
|||
} |
|||
|
|||
if (depthAttachmentHandle != RenderTargetHandle.CameraTarget) |
|||
{ |
|||
var depthDescriptor = descriptor; |
|||
depthDescriptor.colorFormat = RenderTextureFormat.Depth; |
|||
depthDescriptor.depthBufferBits = k_DepthStencilBufferBits; |
|||
depthDescriptor.msaaSamples = (int) samples; |
|||
depthDescriptor.bindMS = (int) samples > 1; |
|||
cmd.GetTemporaryRT(depthAttachmentHandle.id, depthDescriptor, FilterMode.Point); |
|||
} |
|||
|
|||
context.ExecuteCommandBuffer(cmd); |
|||
CommandBufferPool.Release(cmd); |
|||
} |
|||
|
|||
public override void Dispose(CommandBuffer cmd) |
|||
{ |
|||
if (colorAttachmentHandle != RenderTargetHandle.CameraTarget) |
|||
{ |
|||
cmd.ReleaseTemporaryRT(colorAttachmentHandle.id); |
|||
colorAttachmentHandle = RenderTargetHandle.CameraTarget; |
|||
} |
|||
|
|||
if (depthAttachmentHandle != RenderTargetHandle.CameraTarget) |
|||
{ |
|||
cmd.ReleaseTemporaryRT(depthAttachmentHandle.id); |
|||
depthAttachmentHandle = RenderTargetHandle.CameraTarget; |
|||
} |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: a21370e50e4157f47910af9d533bc811 |
|||
MonoImporter: |
|||
externalObjects: {} |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
namespace UnityEngine.Experimental.Rendering.LightweightPipeline |
|||
{ |
|||
public class DrawSkyboxPass : ScriptableRenderPass |
|||
{ |
|||
public DrawSkyboxPass(LightweightForwardRenderer renderer) : base(renderer) |
|||
{} |
|||
|
|||
public override void Execute(ref ScriptableRenderContext context, ref CullResults cullResults, |
|||
ref RenderingData renderingData) |
|||
{ |
|||
context.DrawSkybox(renderingData.cameraData.camera); |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: ae3e4e9915f7b6347b65203987c4f8b0 |
|||
MonoImporter: |
|||
externalObjects: {} |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
namespace UnityEngine.Experimental.Rendering.LightweightPipeline |
|||
{ |
|||
public class EndXRRenderingPass : ScriptableRenderPass |
|||
{ |
|||
public EndXRRenderingPass(LightweightForwardRenderer renderer) : base(renderer) |
|||
{} |
|||
|
|||
public override void Execute(ref ScriptableRenderContext context, ref CullResults cullResults, ref RenderingData renderingData) |
|||
{ |
|||
Camera camera = renderingData.cameraData.camera; |
|||
context.StopMultiEye(camera); |
|||
context.StereoEndRender(camera); |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 8f07d6beda37ef54da54bbbe9cfa080d |
|||
MonoImporter: |
|||
externalObjects: {} |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
using UnityEngine.Rendering; |
|||
|
|||
namespace UnityEngine.Experimental.Rendering.LightweightPipeline |
|||
{ |
|||
public class FinalBlitPass : ScriptableRenderPass |
|||
{ |
|||
Material m_BlitMaterial; |
|||
|
|||
private RenderTargetHandle colorAttachmentHandle { get; set; } |
|||
private RenderTextureDescriptor descriptor { get; set; } |
|||
|
|||
public FinalBlitPass(LightweightForwardRenderer renderer) : base(renderer) |
|||
{ |
|||
m_BlitMaterial = renderer.GetMaterial(MaterialHandles.Blit); |
|||
} |
|||
|
|||
public void Setup(RenderTextureDescriptor baseDescriptor, RenderTargetHandle colorAttachmentHandle) |
|||
{ |
|||
this.colorAttachmentHandle = colorAttachmentHandle; |
|||
this.descriptor = baseDescriptor; |
|||
} |
|||
|
|||
public override void Execute(ref ScriptableRenderContext context, ref CullResults cullResults, ref RenderingData renderingData) |
|||
{ |
|||
Material material = renderingData.cameraData.isStereoEnabled ? null : m_BlitMaterial; |
|||
RenderTargetIdentifier sourceRT = colorAttachmentHandle.Identifier(); |
|||
|
|||
CommandBuffer cmd = CommandBufferPool.Get("Final Blit Pass"); |
|||
cmd.SetGlobalTexture("_BlitTex", sourceRT); |
|||
|
|||
// We need to handle viewport on a RT. We do it by rendering a fullscreen quad + viewport
|
|||
if (!renderingData.cameraData.isDefaultViewport) |
|||
{ |
|||
SetRenderTarget( |
|||
cmd, |
|||
BuiltinRenderTextureType.CameraTarget, |
|||
RenderBufferLoadAction.DontCare, |
|||
RenderBufferStoreAction.Store, |
|||
ClearFlag.None, |
|||
Color.black, |
|||
descriptor.dimension); |
|||
|
|||
cmd.SetViewProjectionMatrices(Matrix4x4.identity, Matrix4x4.identity); |
|||
cmd.SetViewport(renderingData.cameraData.camera.pixelRect); |
|||
LightweightPipeline.DrawFullScreen(cmd, material); |
|||
} |
|||
else |
|||
{ |
|||
cmd.Blit(colorAttachmentHandle.Identifier(), BuiltinRenderTextureType.CameraTarget, material); |
|||
} |
|||
|
|||
context.ExecuteCommandBuffer(cmd); |
|||
CommandBufferPool.Release(cmd); |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: b66efce03c1804a4fbef78cccf176e4d |
|||
MonoImporter: |
|||
externalObjects: {} |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
using System.Collections.Generic; |
|||
using System.Diagnostics; |
|||
using UnityEngine.Rendering; |
|||
|
|||
namespace UnityEngine.Experimental.Rendering.LightweightPipeline |
|||
{ |
|||
public abstract class LightweightForwardPass : ScriptableRenderPass |
|||
{ |
|||
private RenderTargetHandle colorAttachmentHandle { get; set; } |
|||
private RenderTargetHandle depthAttachmentHandle { get; set; } |
|||
private RenderTextureDescriptor descriptor { get; set; } |
|||
protected ClearFlag clearFlag { get; set; } |
|||
protected Color clearColor { get; set; } |
|||
|
|||
const string k_SwitchRTs = "Switch RT"; |
|||
|
|||
Material m_ErrorMaterial; |
|||
|
|||
List<ShaderPassName> m_LegacyShaderPassNames; |
|||
protected RendererConfiguration rendererConfiguration; |
|||
protected bool dynamicBatching; |
|||
|
|||
protected LightweightForwardPass(LightweightForwardRenderer renderer) : base(renderer) |
|||
{ |
|||
|
|||
m_ErrorMaterial = renderer.GetMaterial(MaterialHandles.Error); |
|||
|
|||
m_LegacyShaderPassNames = new List<ShaderPassName>(); |
|||
m_LegacyShaderPassNames.Add(new ShaderPassName("Always")); |
|||
m_LegacyShaderPassNames.Add(new ShaderPassName("ForwardBase")); |
|||
m_LegacyShaderPassNames.Add(new ShaderPassName("PrepassBase")); |
|||
m_LegacyShaderPassNames.Add(new ShaderPassName("Vertex")); |
|||
m_LegacyShaderPassNames.Add(new ShaderPassName("VertexLMRGBM")); |
|||
m_LegacyShaderPassNames.Add(new ShaderPassName("VertexLM")); |
|||
|
|||
RegisterShaderPassName("LightweightForward"); |
|||
RegisterShaderPassName("SRPDefaultUnlit"); |
|||
} |
|||
|
|||
public void Setup( |
|||
RenderTextureDescriptor baseDescriptor, |
|||
RenderTargetHandle colorAttachmentHandle, |
|||
RenderTargetHandle depthAttachmentHandle, |
|||
ClearFlag clearFlag, |
|||
Color clearColor, |
|||
RendererConfiguration configuration, |
|||
bool dynamicbatching) |
|||
{ |
|||
this.colorAttachmentHandle = colorAttachmentHandle; |
|||
this.depthAttachmentHandle = depthAttachmentHandle; |
|||
this.clearColor = clearColor; |
|||
this.clearFlag = clearFlag; |
|||
descriptor = baseDescriptor; |
|||
this.rendererConfiguration = configuration; |
|||
this.dynamicBatching = dynamicbatching; |
|||
} |
|||
|
|||
protected void SetRenderTarget(CommandBuffer cmd, RenderBufferLoadAction loadOp, RenderBufferStoreAction storeOp, ClearFlag clearFlag, Color clearColor) |
|||
{ |
|||
if (colorAttachmentHandle != RenderTargetHandle.CameraTarget) |
|||
{ |
|||
if (depthAttachmentHandle != RenderTargetHandle.CameraTarget) |
|||
SetRenderTarget( |
|||
cmd, |
|||
colorAttachmentHandle.Identifier(), |
|||
loadOp, |
|||
storeOp, |
|||
depthAttachmentHandle.Identifier(), |
|||
loadOp, |
|||
storeOp, |
|||
clearFlag, |
|||
clearColor, |
|||
descriptor.dimension); |
|||
else |
|||
SetRenderTarget(cmd, colorAttachmentHandle.Identifier(), loadOp, storeOp, clearFlag, clearColor, descriptor.dimension); |
|||
} |
|||
else |
|||
{ |
|||
SetRenderTarget(cmd, BuiltinRenderTextureType.CameraTarget, loadOp, storeOp, clearFlag, clearColor, descriptor.dimension); |
|||
} |
|||
} |
|||
|
|||
[Conditional("DEVELOPMENT_BUILD"), Conditional("UNITY_EDITOR")] |
|||
protected void RenderObjectsWithError(ref ScriptableRenderContext context, ref CullResults cullResults, Camera camera, FilterRenderersSettings filterSettings, SortFlags sortFlags) |
|||
{ |
|||
if (m_ErrorMaterial != null) |
|||
{ |
|||
DrawRendererSettings errorSettings = new DrawRendererSettings(camera, m_LegacyShaderPassNames[0]); |
|||
for (int i = 1; i < m_LegacyShaderPassNames.Count; ++i) |
|||
errorSettings.SetShaderPassName(i, m_LegacyShaderPassNames[i]); |
|||
|
|||
errorSettings.sorting.flags = sortFlags; |
|||
errorSettings.rendererConfiguration = RendererConfiguration.None; |
|||
errorSettings.SetOverrideMaterial(m_ErrorMaterial, 0); |
|||
context.DrawRenderers(cullResults.visibleRenderers, ref errorSettings, filterSettings); |
|||
} |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 55fe4224e5c9e3a499307d28ede17d2b |
|||
MonoImporter: |
|||
externalObjects: {} |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
using UnityEngine.Rendering; |
|||
|
|||
namespace UnityEngine.Experimental.Rendering.LightweightPipeline |
|||
{ |
|||
public class OpaquePostProcessPass : ScriptableRenderPass |
|||
{ |
|||
|
|||
public OpaquePostProcessPass(LightweightForwardRenderer renderer) : base(renderer) |
|||
{} |
|||
|
|||
private RenderTargetHandle colorAttachmentHandle { get; set; } |
|||
private RenderTextureDescriptor descriptor { get; set; } |
|||
|
|||
public void Setup( |
|||
RenderTextureDescriptor baseDescriptor, |
|||
RenderTargetHandle colorAttachmentHandle) |
|||
{ |
|||
this.colorAttachmentHandle = colorAttachmentHandle; |
|||
descriptor = baseDescriptor; |
|||
} |
|||
|
|||
public override void Execute(ref ScriptableRenderContext context, ref CullResults cullResults, ref RenderingData renderingData) |
|||
{ |
|||
CommandBuffer cmd = CommandBufferPool.Get("Render Opaque PostProcess Effects"); |
|||
|
|||
RenderTargetIdentifier source = colorAttachmentHandle.Identifier(); |
|||
LightweightPipeline.RenderPostProcess(cmd, renderer.postProcessRenderContext, ref renderingData.cameraData, descriptor.colorFormat, source, colorAttachmentHandle.Identifier(), true); |
|||
context.ExecuteCommandBuffer(cmd); |
|||
CommandBufferPool.Release(cmd); |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 2bf2bbf0a7ac09c41bbbfd0a140cd15e |
|||
MonoImporter: |
|||
externalObjects: {} |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
using UnityEngine.Rendering; |
|||
|
|||
namespace UnityEngine.Experimental.Rendering.LightweightPipeline |
|||
{ |
|||
public class RenderOpaqueForwardPass : LightweightForwardPass |
|||
{ |
|||
|
|||
const string k_RenderOpaquesTag = "Render Opaques"; |
|||
|
|||
public RenderOpaqueForwardPass(LightweightForwardRenderer renderer) : base(renderer) |
|||
{} |
|||
|
|||
public override void Execute(ref ScriptableRenderContext context, ref CullResults cullResults, ref RenderingData renderingData) |
|||
{ |
|||
CommandBuffer cmd = CommandBufferPool.Get(k_RenderOpaquesTag); |
|||
using (new ProfilingSample(cmd, k_RenderOpaquesTag)) |
|||
{ |
|||
|
|||
SetRenderTarget(cmd, RenderBufferLoadAction.DontCare, RenderBufferStoreAction.Store, clearFlag, CoreUtils.ConvertSRGBToActiveColorSpace(clearColor)); |
|||
|
|||
// TODO: We need a proper way to handle multiple camera/ camera stack. Issue is: multiple cameras can share a same RT
|
|||
// (e.g, split screen games). However devs have to be dilligent with it and know when to clear/preserve color.
|
|||
// For now we make it consistent by resolving viewport with a RT until we can have a proper camera management system
|
|||
//if (colorAttachmentHandle == -1 && !cameraData.isDefaultViewport)
|
|||
// cmd.SetViewport(camera.pixelRect);
|
|||
|
|||
context.ExecuteCommandBuffer(cmd); |
|||
cmd.Clear(); |
|||
|
|||
|
|||
Camera camera = renderingData.cameraData.camera; |
|||
var drawSettings = CreateDrawRendererSettings(camera, SortFlags.CommonOpaque, rendererConfiguration, dynamicBatching); |
|||
context.DrawRenderers(cullResults.visibleRenderers, ref drawSettings, renderer.opaqueFilterSettings); |
|||
|
|||
// Render objects that did not match any shader pass with error shader
|
|||
RenderObjectsWithError(ref context, ref cullResults, camera, renderer.opaqueFilterSettings, SortFlags.None); |
|||
} |
|||
context.ExecuteCommandBuffer(cmd); |
|||
CommandBufferPool.Release(cmd); |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: d2138a73081d8c34d901cf7a321f1099 |
|||
MonoImporter: |
|||
externalObjects: {} |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
using UnityEngine.Rendering; |
|||
|
|||
namespace UnityEngine.Experimental.Rendering.LightweightPipeline |
|||
{ |
|||
public class RenderTransparentForwardPass : LightweightForwardPass |
|||
{ |
|||
const string k_RenderTransparentsTag = "Render Transparents"; |
|||
|
|||
public RenderTransparentForwardPass(LightweightForwardRenderer renderer) : base(renderer) |
|||
{} |
|||
|
|||
public override void Execute(ref ScriptableRenderContext context, ref CullResults cullResults, ref RenderingData renderingData) |
|||
{ |
|||
CommandBuffer cmd = CommandBufferPool.Get(k_RenderTransparentsTag); |
|||
using (new ProfilingSample(cmd, k_RenderTransparentsTag)) |
|||
{ |
|||
SetRenderTarget(cmd, RenderBufferLoadAction.Load, RenderBufferStoreAction.Store, clearFlag, CoreUtils.ConvertSRGBToActiveColorSpace(clearColor)); |
|||
context.ExecuteCommandBuffer(cmd); |
|||
cmd.Clear(); |
|||
|
|||
Camera camera = renderingData.cameraData.camera; |
|||
var drawSettings = CreateDrawRendererSettings(camera, SortFlags.CommonTransparent, rendererConfiguration, dynamicBatching); |
|||
context.DrawRenderers(cullResults.visibleRenderers, ref drawSettings, renderer.transparentFilterSettings); |
|||
|
|||
// Render objects that did not match any shader pass with error shader
|
|||
RenderObjectsWithError(ref context, ref cullResults, camera, renderer.transparentFilterSettings, SortFlags.None); |
|||
} |
|||
|
|||
context.ExecuteCommandBuffer(cmd); |
|||
CommandBufferPool.Release(cmd); |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 9d50e748efecb0a428f5b2faa520a2de |
|||
MonoImporter: |
|||
externalObjects: {} |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
using UnityEngine.Rendering; |
|||
|
|||
namespace UnityEngine.Experimental.Rendering.LightweightPipeline |
|||
{ |
|||
public class SceneViewDepthCopyPass : ScriptableRenderPass |
|||
{ |
|||
private RenderTargetHandle source { get; set; } |
|||
|
|||
|
|||
public SceneViewDepthCopyPass(LightweightForwardRenderer renderer) : base(renderer) |
|||
{} |
|||
|
|||
public void Setup(RenderTargetHandle source) |
|||
{ |
|||
this.source = source; |
|||
} |
|||
|
|||
public override void Execute(ref ScriptableRenderContext context, ref CullResults cullResults, ref RenderingData renderingData) |
|||
{ |
|||
// Restore Render target for additional editor rendering.
|
|||
// Note: Scene view camera always perform depth prepass
|
|||
CommandBuffer cmd = CommandBufferPool.Get("Copy Depth to Camera"); |
|||
CoreUtils.SetRenderTarget(cmd, BuiltinRenderTextureType.CameraTarget); |
|||
cmd.EnableShaderKeyword(LightweightKeywordStrings.DepthNoMsaa); |
|||
cmd.DisableShaderKeyword(LightweightKeywordStrings.DepthMsaa2); |
|||
cmd.DisableShaderKeyword(LightweightKeywordStrings.DepthMsaa4); |
|||
cmd.Blit(source.Identifier(), BuiltinRenderTextureType.CameraTarget, renderer.GetMaterial(MaterialHandles.DepthCopy)); |
|||
context.ExecuteCommandBuffer(cmd); |
|||
CommandBufferPool.Release(cmd); |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: b83946bd07350434993ad588e9c521af |
|||
MonoImporter: |
|||
externalObjects: {} |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
namespace UnityEngine.Experimental.Rendering.LightweightPipeline |
|||
{ |
|||
public class SetupForwardRenderingPass : ScriptableRenderPass |
|||
{ |
|||
public SetupForwardRenderingPass(LightweightForwardRenderer renderer) : base(renderer) |
|||
{} |
|||
|
|||
public override void Execute(ref ScriptableRenderContext context, ref CullResults cullResults, ref RenderingData renderingData) |
|||
{ |
|||
// SetupCameraProperties does the following:
|
|||
// Setup Camera RenderTarget and Viewport
|
|||
// VR Camera Setup and SINGLE_PASS_STEREO props
|
|||
// Setup camera view, proj and their inv matrices.
|
|||
// Setup properties: _WorldSpaceCameraPos, _ProjectionParams, _ScreenParams, _ZBufferParams, unity_OrthoParams
|
|||
// Setup camera world clip planes props
|
|||
// setup HDR keyword
|
|||
// Setup global time properties (_Time, _SinTime, _CosTime)
|
|||
context.SetupCameraProperties(renderingData.cameraData.camera, renderingData.cameraData.isStereoEnabled); |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 5ffbc31941942404c82d0caffb09cf41 |
|||
MonoImporter: |
|||
externalObjects: {} |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
using System.Collections.Generic; |
|||
using UnityEngine.Experimental.GlobalIllumination; |
|||
using UnityEngine.Rendering; |
|||
|
|||
namespace UnityEngine.Experimental.Rendering.LightweightPipeline |
|||
{ |
|||
public class SetupLightweightConstanstPass : ScriptableRenderPass |
|||
{ |
|||
public static class PerCameraBuffer |
|||
{ |
|||
public static int _MainLightPosition; |
|||
public static int _MainLightColor; |
|||
public static int _MainLightCookie; |
|||
public static int _WorldToLight; |
|||
|
|||
public static int _AdditionalLightCount; |
|||
public static int _AdditionalLightPosition; |
|||
public static int _AdditionalLightColor; |
|||
public static int _AdditionalLightDistanceAttenuation; |
|||
public static int _AdditionalLightSpotDir; |
|||
public static int _AdditionalLightSpotAttenuation; |
|||
|
|||
public static int _LightIndexBuffer; |
|||
|
|||
public static int _ScaledScreenParams; |
|||
} |
|||
|
|||
MixedLightingSetup m_MixedLightingSetup; |
|||
|
|||
Vector4 k_DefaultLightPosition = new Vector4(0.0f, 0.0f, 1.0f, 0.0f); |
|||
Vector4 k_DefaultLightColor = Color.black; |
|||
Vector4 k_DefaultLightAttenuation = new Vector4(0.0f, 1.0f, 0.0f, 1.0f); |
|||
Vector4 k_DefaultLightSpotDirection = new Vector4(0.0f, 0.0f, 1.0f, 0.0f); |
|||
Vector4 k_DefaultLightSpotAttenuation = new Vector4(0.0f, 1.0f, 0.0f, 0.0f); |
|||
|
|||
Vector4[] m_LightPositions; |
|||
Vector4[] m_LightColors; |
|||
Vector4[] m_LightDistanceAttenuations; |
|||
Vector4[] m_LightSpotDirections; |
|||
Vector4[] m_LightSpotAttenuations; |
|||
|
|||
public SetupLightweightConstanstPass(LightweightForwardRenderer renderer) : base(renderer) |
|||
{ |
|||
PerCameraBuffer._MainLightPosition = Shader.PropertyToID("_MainLightPosition"); |
|||
PerCameraBuffer._MainLightColor = Shader.PropertyToID("_MainLightColor"); |
|||
PerCameraBuffer._MainLightCookie = Shader.PropertyToID("_MainLightCookie"); |
|||
PerCameraBuffer._WorldToLight = Shader.PropertyToID("_WorldToLight"); |
|||
PerCameraBuffer._AdditionalLightCount = Shader.PropertyToID("_AdditionalLightCount"); |
|||
PerCameraBuffer._AdditionalLightPosition = Shader.PropertyToID("_AdditionalLightPosition"); |
|||
PerCameraBuffer._AdditionalLightColor = Shader.PropertyToID("_AdditionalLightColor"); |
|||
PerCameraBuffer._AdditionalLightDistanceAttenuation = Shader.PropertyToID("_AdditionalLightDistanceAttenuation"); |
|||
PerCameraBuffer._AdditionalLightSpotDir = Shader.PropertyToID("_AdditionalLightSpotDir"); |
|||
PerCameraBuffer._AdditionalLightSpotAttenuation = Shader.PropertyToID("_AdditionalLightSpotAttenuation"); |
|||
PerCameraBuffer._LightIndexBuffer = Shader.PropertyToID("_LightIndexBuffer"); |
|||
|
|||
int maxVisibleLocalLights = renderer.maxVisibleLocalLights; |
|||
m_LightPositions = new Vector4[maxVisibleLocalLights]; |
|||
m_LightColors = new Vector4[maxVisibleLocalLights]; |
|||
m_LightDistanceAttenuations = new Vector4[maxVisibleLocalLights]; |
|||
m_LightSpotDirections = new Vector4[maxVisibleLocalLights]; |
|||
m_LightSpotAttenuations = new Vector4[maxVisibleLocalLights]; |
|||
} |
|||
|
|||
void InitializeLightConstants(List<VisibleLight> lights, int lightIndex, out Vector4 lightPos, out Vector4 lightColor, out Vector4 lightDistanceAttenuation, out Vector4 lightSpotDir, |
|||
out Vector4 lightSpotAttenuation) |
|||
{ |
|||
lightPos = k_DefaultLightPosition; |
|||
lightColor = k_DefaultLightColor; |
|||
lightDistanceAttenuation = k_DefaultLightSpotAttenuation; |
|||
lightSpotDir = k_DefaultLightSpotDirection; |
|||
lightSpotAttenuation = k_DefaultLightAttenuation; |
|||
|
|||
// When no lights are visible, main light will be set to -1.
|
|||
// In this case we initialize it to default values and return
|
|||
if (lightIndex < 0) |
|||
return; |
|||
|
|||
VisibleLight lightData = lights[lightIndex]; |
|||
if (lightData.lightType == LightType.Directional) |
|||
{ |
|||
Vector4 dir = -lightData.localToWorld.GetColumn(2); |
|||
lightPos = new Vector4(dir.x, dir.y, dir.z, 0.0f); |
|||
} |
|||
else |
|||
{ |
|||
Vector4 pos = lightData.localToWorld.GetColumn(3); |
|||
lightPos = new Vector4(pos.x, pos.y, pos.z, 1.0f); |
|||
} |
|||
|
|||
// VisibleLight.finalColor already returns color in active color space
|
|||
lightColor = lightData.finalColor; |
|||
|
|||
// Directional Light attenuation is initialize so distance attenuation always be 1.0
|
|||
if (lightData.lightType != LightType.Directional) |
|||
{ |
|||
// Light attenuation in lightweight matches the unity vanilla one.
|
|||
// attenuation = 1.0 / 1.0 + distanceToLightSqr * quadraticAttenuation
|
|||
// then a smooth factor is applied to linearly fade attenuation to light range
|
|||
// the attenuation smooth factor starts having effect at 80% of light range
|
|||
// smoothFactor = (lightRangeSqr - distanceToLightSqr) / (lightRangeSqr - fadeStartDistanceSqr)
|
|||
// We rewrite smoothFactor to be able to pre compute the constant terms below and apply the smooth factor
|
|||
// with one MAD instruction
|
|||
// smoothFactor = distanceSqr * (1.0 / (fadeDistanceSqr - lightRangeSqr)) + (-lightRangeSqr / (fadeDistanceSqr - lightRangeSqr)
|
|||
// distanceSqr * oneOverFadeRangeSqr + lightRangeSqrOverFadeRangeSqr
|
|||
float lightRangeSqr = lightData.range * lightData.range; |
|||
float fadeStartDistanceSqr = 0.8f * 0.8f * lightRangeSqr; |
|||
float fadeRangeSqr = (fadeStartDistanceSqr - lightRangeSqr); |
|||
float oneOverFadeRangeSqr = 1.0f / fadeRangeSqr; |
|||
float lightRangeSqrOverFadeRangeSqr = -lightRangeSqr / fadeRangeSqr; |
|||
float quadAtten = 25.0f / lightRangeSqr; |
|||
lightDistanceAttenuation = new Vector4(quadAtten, oneOverFadeRangeSqr, lightRangeSqrOverFadeRangeSqr, 1.0f); |
|||
} |
|||
|
|||
if (lightData.lightType == LightType.Spot) |
|||
{ |
|||
Vector4 dir = lightData.localToWorld.GetColumn(2); |
|||
lightSpotDir = new Vector4(-dir.x, -dir.y, -dir.z, 0.0f); |
|||
|
|||
// Spot Attenuation with a linear falloff can be defined as
|
|||
// (SdotL - cosOuterAngle) / (cosInnerAngle - cosOuterAngle)
|
|||
// This can be rewritten as
|
|||
// invAngleRange = 1.0 / (cosInnerAngle - cosOuterAngle)
|
|||
// SdotL * invAngleRange + (-cosOuterAngle * invAngleRange)
|
|||
// If we precompute the terms in a MAD instruction
|
|||
float cosOuterAngle = Mathf.Cos(Mathf.Deg2Rad * lightData.spotAngle * 0.5f); |
|||
// We neeed to do a null check for particle lights
|
|||
// This should be changed in the future
|
|||
// Particle lights will use an inline function
|
|||
float cosInnerAngle; |
|||
if (lightData.light != null) |
|||
cosInnerAngle = Mathf.Cos(LightmapperUtils.ExtractInnerCone(lightData.light) * 0.5f); |
|||
else |
|||
cosInnerAngle = Mathf.Cos((2.0f * Mathf.Atan(Mathf.Tan(lightData.spotAngle * 0.5f * Mathf.Deg2Rad) * (64.0f - 18.0f) / 64.0f)) * 0.5f); |
|||
float smoothAngleRange = Mathf.Max(0.001f, cosInnerAngle - cosOuterAngle); |
|||
float invAngleRange = 1.0f / smoothAngleRange; |
|||
float add = -cosOuterAngle * invAngleRange; |
|||
lightSpotAttenuation = new Vector4(invAngleRange, add, 0.0f); |
|||
} |
|||
|
|||
Light light = lightData.light; |
|||
|
|||
// TODO: Add support to shadow mask
|
|||
if (light != null && light.bakingOutput.mixedLightingMode == MixedLightingMode.Subtractive && light.bakingOutput.lightmapBakeType == LightmapBakeType.Mixed) |
|||
{ |
|||
if (m_MixedLightingSetup == MixedLightingSetup.None && lightData.light.shadows != LightShadows.None) |
|||
{ |
|||
m_MixedLightingSetup = MixedLightingSetup.Subtractive; |
|||
lightDistanceAttenuation.w = 0.0f; |
|||
} |
|||
} |
|||
} |
|||
|
|||
void SetupShaderLightConstants(CommandBuffer cmd, ref LightData lightData) |
|||
{ |
|||
// Clear to default all light constant data
|
|||
for (int i = 0; i < renderer.maxVisibleLocalLights; ++i) |
|||
InitializeLightConstants(lightData.visibleLights, -1, out m_LightPositions[i], |
|||
out m_LightColors[i], |
|||
out m_LightDistanceAttenuations[i], |
|||
out m_LightSpotDirections[i], |
|||
out m_LightSpotAttenuations[i]); |
|||
|
|||
m_MixedLightingSetup = MixedLightingSetup.None; |
|||
|
|||
// Main light has an optimized shader path for main light. This will benefit games that only care about a single light.
|
|||
// Lightweight pipeline also supports only a single shadow light, if available it will be the main light.
|
|||
SetupMainLightConstants(cmd, ref lightData); |
|||
SetupAdditionalLightConstants(cmd, ref lightData); |
|||
} |
|||
|
|||
void SetupMainLightConstants(CommandBuffer cmd, ref LightData lightData) |
|||
{ |
|||
Vector4 lightPos, lightColor, lightDistanceAttenuation, lightSpotDir, lightSpotAttenuation; |
|||
List<VisibleLight> lights = lightData.visibleLights; |
|||
InitializeLightConstants(lightData.visibleLights, lightData.mainLightIndex, out lightPos, out lightColor, out lightDistanceAttenuation, out lightSpotDir, out lightSpotAttenuation); |
|||
|
|||
if (lightData.mainLightIndex >= 0) |
|||
{ |
|||
VisibleLight mainLight = lights[lightData.mainLightIndex]; |
|||
Light mainLightRef = mainLight.light; |
|||
|
|||
if (LightweightPipeline.IsSupportedCookieType(mainLight.lightType) && mainLightRef.cookie != null) |
|||
{ |
|||
Matrix4x4 lightCookieMatrix; |
|||
LightweightPipeline.GetLightCookieMatrix(mainLight, out lightCookieMatrix); |
|||
cmd.SetGlobalTexture(PerCameraBuffer._MainLightCookie, mainLightRef.cookie); |
|||
cmd.SetGlobalMatrix(PerCameraBuffer._WorldToLight, lightCookieMatrix); |
|||
} |
|||
} |
|||
|
|||
cmd.SetGlobalVector(PerCameraBuffer._MainLightPosition, new Vector4(lightPos.x, lightPos.y, lightPos.z, lightDistanceAttenuation.w)); |
|||
cmd.SetGlobalVector(PerCameraBuffer._MainLightColor, lightColor); |
|||
} |
|||
|
|||
void SetupAdditionalLightConstants(CommandBuffer cmd, ref LightData lightData) |
|||
{ |
|||
int maxVisibleLocalLights = renderer.maxVisibleLocalLights; |
|||
List<VisibleLight> lights = lightData.visibleLights; |
|||
if (lightData.totalAdditionalLightsCount > 0) |
|||
{ |
|||
int localLightsCount = 0; |
|||
for (int i = 0; i < lights.Count && localLightsCount < maxVisibleLocalLights; ++i) |
|||
{ |
|||
VisibleLight light = lights[i]; |
|||
if (light.lightType != LightType.Directional) |
|||
{ |
|||
InitializeLightConstants(lights, i, out m_LightPositions[localLightsCount], |
|||
out m_LightColors[localLightsCount], |
|||
out m_LightDistanceAttenuations[localLightsCount], |
|||
out m_LightSpotDirections[localLightsCount], |
|||
out m_LightSpotAttenuations[localLightsCount]); |
|||
localLightsCount++; |
|||
} |
|||
} |
|||
|
|||
cmd.SetGlobalVector(PerCameraBuffer._AdditionalLightCount, new Vector4(lightData.pixelAdditionalLightsCount, |
|||
lightData.totalAdditionalLightsCount, 0.0f, 0.0f)); |
|||
|
|||
// if not using a compute buffer, engine will set indices in 2 vec4 constants
|
|||
// unity_4LightIndices0 and unity_4LightIndices1
|
|||
if (renderer.perObjectLightIndices != null) |
|||
cmd.SetGlobalBuffer("_LightIndexBuffer", renderer.perObjectLightIndices); |
|||
} |
|||
else |
|||
{ |
|||
cmd.SetGlobalVector(PerCameraBuffer._AdditionalLightCount, Vector4.zero); |
|||
} |
|||
|
|||
cmd.SetGlobalVectorArray(PerCameraBuffer._AdditionalLightPosition, m_LightPositions); |
|||
cmd.SetGlobalVectorArray(PerCameraBuffer._AdditionalLightColor, m_LightColors); |
|||
cmd.SetGlobalVectorArray(PerCameraBuffer._AdditionalLightDistanceAttenuation, m_LightDistanceAttenuations); |
|||
cmd.SetGlobalVectorArray(PerCameraBuffer._AdditionalLightSpotDir, m_LightSpotDirections); |
|||
cmd.SetGlobalVectorArray(PerCameraBuffer._AdditionalLightSpotAttenuation, m_LightSpotAttenuations); |
|||
} |
|||
|
|||
void SetShaderKeywords(CommandBuffer cmd, ref CameraData cameraData, ref LightData lightData, ref ShadowData shadowData) |
|||
{ |
|||
int vertexLightsCount = lightData.totalAdditionalLightsCount - lightData.pixelAdditionalLightsCount; |
|||
|
|||
CoreUtils.SetKeyword(cmd, LightweightKeywordStrings.AdditionalLights, lightData.totalAdditionalLightsCount > 0); |
|||
CoreUtils.SetKeyword(cmd, LightweightKeywordStrings.MixedLightingSubtractive, m_MixedLightingSetup == MixedLightingSetup.Subtractive); |
|||
CoreUtils.SetKeyword(cmd, LightweightKeywordStrings.VertexLights, vertexLightsCount > 0); |
|||
|
|||
// TODO: We have to discuss cookie approach on LWRP.
|
|||
// CoreUtils.SetKeyword(cmd, LightweightKeywordStrings.MainLightCookieText, mainLightIndex != -1 && LightweightUtils.IsSupportedCookieType(visibleLights[mainLightIndex].lightType) && visibleLights[mainLightIndex].light.cookie != null);
|
|||
|
|||
LightShadows directionalShadowQuality = shadowData.renderedDirectionalShadowQuality; |
|||
LightShadows localShadowQuality = shadowData.renderedLocalShadowQuality; |
|||
|
|||
// Currently shadow filtering keyword is shared between local and directional shadows.
|
|||
bool hasSoftShadows = (directionalShadowQuality == LightShadows.Soft || localShadowQuality == LightShadows.Soft) && |
|||
shadowData.supportsSoftShadows; |
|||
|
|||
CoreUtils.SetKeyword(cmd, LightweightKeywordStrings.DirectionalShadows, directionalShadowQuality != LightShadows.None); |
|||
CoreUtils.SetKeyword(cmd, LightweightKeywordStrings.LocalShadows, localShadowQuality != LightShadows.None); |
|||
CoreUtils.SetKeyword(cmd, LightweightKeywordStrings.SoftShadows, hasSoftShadows); |
|||
CoreUtils.SetKeyword(cmd, LightweightKeywordStrings.CascadeShadows, shadowData.directionalLightCascadeCount > 1); |
|||
|
|||
// TODO: Remove this. legacy particles support will be removed from Unity in 2018.3. This should be a shader_feature instead with prop exposed in the Standard particles shader.
|
|||
CoreUtils.SetKeyword(cmd, "SOFTPARTICLES_ON", cameraData.requiresSoftParticles); |
|||
} |
|||
|
|||
public override void Execute(ref ScriptableRenderContext context, ref CullResults cullResults, ref RenderingData renderingData) |
|||
{ |
|||
CommandBuffer cmd = CommandBufferPool.Get("SetupShaderConstants"); |
|||
SetupShaderLightConstants(cmd, ref renderingData.lightData); |
|||
SetShaderKeywords(cmd, ref renderingData.cameraData, ref renderingData.lightData, ref renderingData.shadowData); |
|||
context.ExecuteCommandBuffer(cmd); |
|||
CommandBufferPool.Release(cmd); |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: d3f92ea5bea21364fae52e5c4e675ba7 |
|||
MonoImporter: |
|||
externalObjects: {} |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
using UnityEngine.Rendering; |
|||
|
|||
namespace UnityEngine.Experimental.Rendering.LightweightPipeline |
|||
{ |
|||
public class TransparentPostProcessPass : ScriptableRenderPass |
|||
{ |
|||
|
|||
public TransparentPostProcessPass(LightweightForwardRenderer renderer) : base(renderer) |
|||
{} |
|||
|
|||
private RenderTargetHandle colorAttachmentHandle { get; set; } |
|||
private RenderTextureDescriptor descriptor { get; set; } |
|||
|
|||
public void Setup( |
|||
RenderTextureDescriptor baseDescriptor, |
|||
RenderTargetHandle colorAttachmentHandle) |
|||
{ |
|||
this.colorAttachmentHandle = colorAttachmentHandle; |
|||
descriptor = baseDescriptor; |
|||
} |
|||
|
|||
public override void Execute(ref ScriptableRenderContext context, ref CullResults cullResults, ref RenderingData renderingData) |
|||
{ |
|||
CommandBuffer cmd = CommandBufferPool.Get("Render PostProcess Effects"); |
|||
LightweightPipeline.RenderPostProcess(cmd, renderer.postProcessRenderContext, ref renderingData.cameraData, descriptor.colorFormat, colorAttachmentHandle.Identifier(), BuiltinRenderTextureType.CameraTarget, false); |
|||
context.ExecuteCommandBuffer(cmd); |
|||
CommandBufferPool.Release(cmd); |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 858a96c3295017349ab0f956b9883bb9 |
|||
MonoImporter: |
|||
externalObjects: {} |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
using UnityEngine.Rendering; |
|||
|
|||
namespace UnityEngine.Experimental.Rendering.LightweightPipeline |
|||
{ |
|||
public struct RenderTargetHandle |
|||
{ |
|||
public int id { private set; get; } |
|||
|
|||
public static readonly RenderTargetHandle CameraTarget = new RenderTargetHandle {id = -1}; |
|||
|
|||
public void Init(string shaderProperty) |
|||
{ |
|||
id = Shader.PropertyToID(shaderProperty); |
|||
} |
|||
|
|||
public RenderTargetIdentifier Identifier() |
|||
{ |
|||
if (id == -1) |
|||
{ |
|||
return BuiltinRenderTextureType.CameraTarget; |
|||
} |
|||
return new RenderTargetIdentifier(id); |
|||
} |
|||
|
|||
public bool Equals(RenderTargetHandle other) |
|||
{ |
|||
return id == other.id; |
|||
} |
|||
|
|||
public override bool Equals(object obj) |
|||
{ |
|||
if (ReferenceEquals(null, obj)) return false; |
|||
return obj is RenderTargetHandle && Equals((RenderTargetHandle) obj); |
|||
} |
|||
|
|||
public override int GetHashCode() |
|||
{ |
|||
return id; |
|||
} |
|||
|
|||
|
|||
public static bool operator ==(RenderTargetHandle c1, RenderTargetHandle c2) |
|||
{ |
|||
return c1.Equals(c2); |
|||
} |
|||
|
|||
public static bool operator !=(RenderTargetHandle c1, RenderTargetHandle c2) |
|||
{ |
|||
return !c1.Equals(c2); |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: d7a47b64c248a9448845c28f15c6ca10 |
|||
MonoImporter: |
|||
externalObjects: {} |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
namespace UnityEngine.Experimental.Rendering.LightweightPipeline |
|||
{ |
|||
/*public static class RenderTargetHandles |
|||
{ |
|||
|
|||
}*/ |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 8ad204571bda59f4cae99ed240e49bd4 |
|||
MonoImporter: |
|||
externalObjects: {} |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
namespace UnityEngine.Experimental.Rendering.LightweightPipeline |
|||
{ |
|||
public enum SampleCount |
|||
{ |
|||
One = 1, |
|||
Two = 2, |
|||
Four = 4, |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 2cdbafc04e2383e4ca5c05e7f873e1fa |
|||
MonoImporter: |
|||
externalObjects: {} |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
using System; |
|||
using UnityEngine; |
|||
using UnityEngine.Experimental.Rendering; |
|||
using UnityEngine.Experimental.Rendering.LightweightPipeline; |
|||
using UnityEngine.Rendering; |
|||
|
|||
|
|||
public class CustomLWPipe : MonoBehaviour, IRendererSetup |
|||
{ |
|||
private SetupForwardRenderingPass m_SetupForwardRenderingPass; |
|||
private CreateLightweightRenderTexturesPass m_CreateLightweightRenderTexturesPass; |
|||
private SetupLightweightConstanstPass m_SetupLightweightConstants; |
|||
private RenderOpaqueForwardPass m_RenderOpaqueForwardPass; |
|||
|
|||
[NonSerialized] |
|||
private bool m_Initialized = false; |
|||
|
|||
private void Init(LightweightForwardRenderer renderer) |
|||
{ |
|||
if (m_Initialized) |
|||
return; |
|||
|
|||
m_SetupForwardRenderingPass = new SetupForwardRenderingPass(renderer); |
|||
m_CreateLightweightRenderTexturesPass = new CreateLightweightRenderTexturesPass(renderer); |
|||
m_SetupLightweightConstants = new SetupLightweightConstanstPass(renderer); |
|||
m_RenderOpaqueForwardPass = new RenderOpaqueForwardPass(renderer); |
|||
|
|||
m_Initialized = true; |
|||
} |
|||
|
|||
public void Setup(LightweightForwardRenderer renderer, ref ScriptableRenderContext context, |
|||
ref CullResults cullResults, ref RenderingData renderingData) |
|||
{ |
|||
Init(renderer); |
|||
|
|||
renderer.Clear(); |
|||
|
|||
renderer.SetupPerObjectLightIndices(ref cullResults, ref renderingData.lightData); |
|||
RenderTextureDescriptor baseDescriptor = renderer.CreateRTDesc(ref renderingData.cameraData); |
|||
RenderTextureDescriptor shadowDescriptor = baseDescriptor; |
|||
shadowDescriptor.dimension = TextureDimension.Tex2D; |
|||
|
|||
renderer.EnqueuePass(m_SetupForwardRenderingPass); |
|||
|
|||
RenderTargetHandle colorHandle = RenderTargetHandle.CameraTarget; |
|||
RenderTargetHandle depthHandle = RenderTargetHandle.CameraTarget; |
|||
|
|||
var sampleCount = (SampleCount)renderingData.cameraData.msaaSamples; |
|||
m_CreateLightweightRenderTexturesPass.Setup(baseDescriptor, colorHandle, depthHandle, sampleCount); |
|||
renderer.EnqueuePass(m_CreateLightweightRenderTexturesPass); |
|||
|
|||
Camera camera = renderingData.cameraData.camera; |
|||
bool dynamicBatching = renderingData.supportsDynamicBatching; |
|||
RendererConfiguration rendererConfiguration = LightweightForwardRenderer.GetRendererConfiguration(renderingData.lightData.totalAdditionalLightsCount); |
|||
|
|||
renderer.EnqueuePass(m_SetupLightweightConstants); |
|||
|
|||
m_RenderOpaqueForwardPass.Setup(baseDescriptor, colorHandle, depthHandle, LightweightForwardRenderer.GetCameraClearFlag(camera), camera.backgroundColor, rendererConfiguration, dynamicBatching); |
|||
renderer.EnqueuePass(m_RenderOpaqueForwardPass); |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 7e0da365be9e44c3bae8da691ccd8de6 |
|||
MonoImporter: |
|||
externalObjects: {} |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
撰写
预览
正在加载...
取消
保存
Reference in new issue