// Here you can inject one or multiple render passes in the renderer. // This method is called when setting up the renderer once per-camera. public override void AddRenderPasses(RP.ScriptableRenderer renderer, ref RP.RenderingData renderingData) { if (renderingData.cameraData.camera != Camera.main) { return; } renderer.EnqueuePass(m_ScriptablePass); }
public override void Execute(ScriptableRenderContext context, ref RP.RenderingData renderingData) { if (MainCameraOnly) { return; } CommandBuffer buf = new CommandBuffer(); buf.Blit(splitRT, cameraRT); // copy splitRT into camera target texture context.ExecuteCommandBuffer(buf); }
public override void Execute(ScriptableRenderContext context, ref RenderingData renderingData) { SortingCriteria sortingCriteria = (renderQueueType == RenderQueueType.Transparent) ? SortingCriteria.CommonTransparent : renderingData.cameraData.defaultOpaqueSortFlags; DrawingSettings drawingSettings = CreateDrawingSettings(m_ShaderTagIdList, ref renderingData, sortingCriteria); drawingSettings.overrideMaterial = overrideMaterial; drawingSettings.overrideMaterialPassIndex = overrideMaterialPassIndex; Camera camera = renderingData.cameraData.camera; float cameraAspect = (float)camera.pixelWidth / (float)camera.pixelHeight; CommandBuffer cmd = CommandBufferPool.Get(m_ProfilerTag); using (new ProfilingSample(cmd, m_ProfilerTag)) { context.ExecuteCommandBuffer(cmd); cmd.Clear(); cmd.BeginSample("Copy Depth"); cmd.SetGlobalTexture("_CameraDepthAttachment", "_CameraDepthTexture"); // Copy the source depth buffer to the target render texture if (destination.Identifier() != source) { Blit(cmd, source, destination.Identifier(), m_CopyDepthMaterial); } cmd.EndSample("Copy Depth"); context.ExecuteCommandBuffer(cmd); cmd.Clear(); if (m_CameraSettings.overrideCamera) { Matrix4x4 projectionMatrix = Matrix4x4.Perspective(m_CameraSettings.cameraFieldOfView, cameraAspect, camera.nearClipPlane, camera.farClipPlane); Matrix4x4 viewMatrix = camera.worldToCameraMatrix; Vector4 cameraTranslation = viewMatrix.GetColumn(3); viewMatrix.SetColumn(3, cameraTranslation + m_CameraSettings.offset); cmd.SetViewProjectionMatrices(viewMatrix, projectionMatrix); context.ExecuteCommandBuffer(cmd); } context.DrawRenderers(renderingData.cullResults, ref drawingSettings, ref m_FilteringSettings, ref m_RenderStateBlock); if (m_CameraSettings.overrideCamera && m_CameraSettings.restoreCamera) { Matrix4x4 projectionMatrix = Matrix4x4.Perspective(camera.fieldOfView, cameraAspect, camera.nearClipPlane, camera.farClipPlane); cmd.Clear(); cmd.SetViewProjectionMatrices(camera.worldToCameraMatrix, projectionMatrix); } } context.ExecuteCommandBuffer(cmd); CommandBufferPool.Release(cmd); }
/// <inheritdoc/> public override void Execute(ScriptableRenderContext context, ref RenderingData renderingData) { RenderMainLightCascadeShadowmap(ref context, ref renderingData.cullResults, ref renderingData.lightData, ref renderingData.shadowData); }
/// <inheritdoc/> public override void Execute(ScriptableRenderContext context, ref RenderingData renderingData) { ref CameraData cameraData = ref renderingData.cameraData;
public bool Setup(ref RenderingData renderingData) { if (!renderingData.shadowData.supportsAdditionalLightShadows) { return(false); } Clear(); m_ShadowmapWidth = renderingData.shadowData.additionalLightsShadowmapWidth; m_ShadowmapHeight = renderingData.shadowData.additionalLightsShadowmapHeight; Bounds bounds; var visibleLights = renderingData.lightData.visibleLights; int additionalLightsCount = renderingData.lightData.additionalLightsCount; for (int i = 0; i < visibleLights.Length && m_AdditionalShadowCastingLightIndices.Count < additionalLightsCount; ++i) { if (i == renderingData.lightData.mainLightIndex) { continue; } VisibleLight shadowLight = visibleLights[i]; Light light = shadowLight.light; if (shadowLight.lightType == LightType.Spot && light != null && light.shadows != LightShadows.None) { if (renderingData.cullResults.GetShadowCasterBounds(i, out bounds)) { m_AdditionalShadowCastingLightIndices.Add(i); } } } int shadowCastingLightsCount = m_AdditionalShadowCastingLightIndices.Count; if (shadowCastingLightsCount == 0) { return(false); } // TODO: Add support to point light shadows. We make a simplification here that only works // for spot lights and with max spot shadows per pass. int atlasWidth = renderingData.shadowData.additionalLightsShadowmapWidth; int atlasHeight = renderingData.shadowData.additionalLightsShadowmapHeight; int sliceResolution = ShadowUtils.GetMaxTileResolutionInAtlas(atlasWidth, atlasHeight, shadowCastingLightsCount); bool anyShadows = false; int shadowSlicesPerRow = (atlasWidth / sliceResolution); for (int i = 0; i < shadowCastingLightsCount; ++i) { int shadowLightIndex = m_AdditionalShadowCastingLightIndices[i]; VisibleLight shadowLight = visibleLights[shadowLightIndex]; // Currently Only Spot Lights are supported in additional lights Debug.Assert(shadowLight.lightType == LightType.Spot); Matrix4x4 shadowTransform; bool success = ShadowUtils.ExtractSpotLightMatrix(ref renderingData.cullResults, ref renderingData.shadowData, shadowLightIndex, out shadowTransform, out m_AdditionalLightSlices[i].viewMatrix, out m_AdditionalLightSlices[i].projectionMatrix); if (success) { // TODO: We need to pass bias and scale list to shader to be able to support multiple // shadow casting additional lights. m_AdditionalLightSlices[i].offsetX = (i % shadowSlicesPerRow) * sliceResolution; m_AdditionalLightSlices[i].offsetY = (i / shadowSlicesPerRow) * sliceResolution; m_AdditionalLightSlices[i].resolution = sliceResolution; m_AdditionalLightSlices[i].shadowTransform = shadowTransform; m_AdditionalLightsShadowStrength[i] = shadowLight.light.shadowStrength; anyShadows = true; } else { m_AdditionalShadowCastingLightIndices.RemoveAt(i--); } } return(anyShadows); }
static void InitializeRenderingData(PipelineSettings settings, ref CameraData cameraData, ref CullingResults cullResults, int maxVisibleAdditionalLights, int maxPerObjectAdditionalLights, out RenderingData renderingData) { var visibleLights = cullResults.visibleLights; int mainLightIndex = GetMainLightIndex(settings, visibleLights); bool mainLightCastShadows = false; bool additionalLightsCastShadows = false; if (cameraData.maxShadowDistance > 0.0f) { mainLightCastShadows = (mainLightIndex != -1 && visibleLights[mainLightIndex].light != null && visibleLights[mainLightIndex].light.shadows != LightShadows.None); // If additional lights are shaded per-pixel they cannot cast shadows if (settings.additionalLightsRenderingMode == LightRenderingMode.PerPixel) { for (int i = 0; i < visibleLights.Length; ++i) { if (i == mainLightIndex) { continue; } Light light = visibleLights[i].light; // LWRP doesn't support additional directional lights or point light shadows yet if (visibleLights[i].lightType == LightType.Spot && light != null && light.shadows != LightShadows.None) { additionalLightsCastShadows = true; break; } } } } renderingData.cullResults = cullResults; renderingData.cameraData = cameraData; InitializeLightData(settings, visibleLights, mainLightIndex, maxVisibleAdditionalLights, maxPerObjectAdditionalLights, out renderingData.lightData); InitializeShadowData(settings, visibleLights, mainLightCastShadows, additionalLightsCastShadows && !renderingData.lightData.shadeAdditionalLightsPerVertex, out renderingData.shadowData); renderingData.supportsDynamicBatching = settings.supportsDynamicBatching; bool platformNeedsToKillAlpha = Application.platform == RuntimePlatform.IPhonePlayer || Application.platform == RuntimePlatform.Android || Application.platform == RuntimePlatform.tvOS; renderingData.killAlphaInFinalBlit = !Graphics.preserveFramebufferAlpha && platformNeedsToKillAlpha; }
public bool Setup(ref RenderingData renderingData) { if (!renderingData.shadowData.supportsMainLightShadows) { return(false); } Clear(); int shadowLightIndex = renderingData.lightData.mainLightIndex; if (shadowLightIndex == -1) { return(false); } VisibleLight shadowLight = renderingData.lightData.visibleLights[shadowLightIndex]; Light light = shadowLight.light; if (light.shadows == LightShadows.None) { return(false); } if (shadowLight.lightType != LightType.Directional) { Debug.LogWarning("Only directional lights are supported as main light."); } Bounds bounds; if (!renderingData.cullResults.GetShadowCasterBounds(shadowLightIndex, out bounds)) { return(false); } m_ShadowCasterCascadesCount = renderingData.shadowData.mainLightShadowCascadesCount; int shadowResolution = ShadowUtils.GetMaxTileResolutionInAtlas(renderingData.shadowData.mainLightShadowmapWidth, renderingData.shadowData.mainLightShadowmapHeight, m_ShadowCasterCascadesCount); m_ShadowmapWidth = renderingData.shadowData.mainLightShadowmapWidth; m_ShadowmapHeight = (m_ShadowCasterCascadesCount == 2) ? renderingData.shadowData.mainLightShadowmapHeight >> 1 : renderingData.shadowData.mainLightShadowmapHeight; for (int cascadeIndex = 0; cascadeIndex < m_ShadowCasterCascadesCount; ++cascadeIndex) { bool success = ShadowUtils.ExtractDirectionalLightMatrix(ref renderingData.cullResults, ref renderingData.shadowData, shadowLightIndex, cascadeIndex, m_ShadowmapWidth, m_ShadowmapHeight, shadowResolution, light.shadowNearPlane, out m_CascadeSplitDistances[cascadeIndex], out m_CascadeSlices[cascadeIndex], out m_CascadeSlices[cascadeIndex].viewMatrix, out m_CascadeSlices[cascadeIndex].projectionMatrix); if (!success) { return(false); } } //seongdae;vxsm if (renderingData.shadowData.supportsMainLightVxShadows) { var dirVxsm = light.GetComponent <DirectionalVxShadowMap>(); bool enabledVxsm = dirVxsm != null && dirVxsm.IsValid(); bool canNotCastDynamicShadows = enabledVxsm && dirVxsm.ShadowsBlend == ShadowsBlendMode.OnlyVxShadows; if (canNotCastDynamicShadows) { return(false); } } //seongdae;vxsm return(true); }