public static PipelineSettings Create(LightweightPipelineAsset asset) { var cache = new PipelineSettings(); cache.msaaSampleCount = asset.msaaSampleCount; cache.supportsHDR = asset.supportsHDR; cache.savedXRGraphicsConfig = asset.savedXRGraphicsConfig; cache.renderScale = asset.renderScale; cache.supportsCameraDepthTexture = asset.supportsCameraDepthTexture; cache.opaqueDownsampling = asset.opaqueDownsampling; cache.supportsCameraOpaqueTexture = asset.supportsCameraOpaqueTexture; cache.supportsDynamicBatching = asset.supportsDynamicBatching; cache.maxPixelLights = asset.maxPixelLights; cache.supportsDirectionalShadows = asset.supportsDirectionalShadows; cache.supportsSoftParticles = asset.supportsSoftParticles; cache.supportsLocalShadows = asset.supportsLocalShadows; cache.shadowDistance = asset.shadowDistance; cache.cascadeCount = asset.cascadeCount; cache.directionalShadowAtlasResolution = asset.directionalShadowAtlasResolution; cache.cascade2Split = asset.cascade2Split; cache.cascade4Split = asset.cascade4Split; cache.supportsVertexLight = asset.supportsVertexLight; cache.localShadowAtlasResolution = asset.localShadowAtlasResolution; cache.supportsSoftShadows = asset.supportsSoftShadows; cache.savedXRGraphicsConfig.renderScale = cache.renderScale; cache.savedXRGraphicsConfig.viewportScale = 1.0f; // Placeholder until viewportScale is all hooked up // Apply any changes to XRGConfig prior to this point cache.savedXRGraphicsConfig.SetConfig(); return(cache); }
static void SetPipelineCapabilities(LightweightPipelineAsset pipelineAsset) { s_PipelineCapabilities = 0U; if (pipelineAsset.MaxPixelLights > 1 || pipelineAsset.SupportsVertexLight) { s_PipelineCapabilities |= PipelineCapabilities.AdditionalLights; } if (pipelineAsset.SupportsVertexLight) { s_PipelineCapabilities |= PipelineCapabilities.VertexLights; } if (pipelineAsset.SupportsDirectionalShadows) { s_PipelineCapabilities |= PipelineCapabilities.DirectionalShadows; } if (pipelineAsset.SupportsLocalShadows) { s_PipelineCapabilities |= PipelineCapabilities.LocalShadows; } bool anyShadows = pipelineAsset.SupportsDirectionalShadows || pipelineAsset.SupportsLocalShadows; if (pipelineAsset.SupportsSoftShadows && anyShadows) { s_PipelineCapabilities |= PipelineCapabilities.SoftShadows; } }
static void SetSupportedShaderFeatures(LightweightPipelineAsset pipelineAsset) { s_ShaderFeatures = 0U; // Strip variants based on selected pipeline features if (pipelineAsset.maxPixelLights > 1 || pipelineAsset.supportsVertexLight) { s_ShaderFeatures |= ShaderFeatures.AdditionalLights; } if (pipelineAsset.supportsVertexLight) { s_ShaderFeatures |= ShaderFeatures.VertexLights; } if (pipelineAsset.supportsDirectionalShadows) { s_ShaderFeatures |= ShaderFeatures.DirectionalShadows; } if (pipelineAsset.supportsLocalShadows) { s_ShaderFeatures |= ShaderFeatures.LocalShadows; } bool anyShadows = pipelineAsset.supportsDirectionalShadows || pipelineAsset.supportsLocalShadows; if (pipelineAsset.supportsSoftShadows && anyShadows) { s_ShaderFeatures |= ShaderFeatures.SoftShadows; } }
public static PipelineSettings Create(LightweightPipelineAsset asset) { var cache = new PipelineSettings(); cache.msaaSampleCount = asset.msaaSampleCount; cache.supportsHDR = asset.supportsHDR; cache.savedXRGraphicsConfig = asset.savedXRGraphicsConfig; cache.renderScale = asset.renderScale; cache.supportsCameraDepthTexture = asset.supportsCameraDepthTexture; cache.opaqueDownsampling = asset.opaqueDownsampling; cache.supportsCameraOpaqueTexture = asset.supportsCameraOpaqueTexture; cache.supportsDynamicBatching = asset.supportsDynamicBatching; cache.maxPixelLights = asset.maxPixelLights; cache.supportsDirectionalShadows = asset.supportsDirectionalShadows; cache.supportsSoftParticles = asset.supportsSoftParticles; cache.supportsLocalShadows = asset.supportsLocalShadows; cache.shadowDistance = asset.shadowDistance; cache.cascadeCount = asset.cascadeCount; cache.directionalShadowAtlasResolution = asset.directionalShadowAtlasResolution; cache.cascade2Split = asset.cascade2Split; cache.cascade4Split = asset.cascade4Split; cache.supportsVertexLight = asset.supportsVertexLight; cache.localShadowAtlasResolution = asset.localShadowAtlasResolution; cache.supportsSoftShadows = asset.supportsSoftShadows; return(cache); }
public LightweightPipeline(LightweightPipelineAsset asset) { m_Asset = asset; BuildShadowSettings(); m_ShadowMapProperty = Shader.PropertyToID("_ShadowMap"); m_ShadowMapRTID = new RenderTargetIdentifier(m_ShadowMapProperty); Shader.globalRenderPipeline = "LightweightPipeline"; }
public ScriptableRenderer(LightweightPipelineAsset pipelineAsset) { m_Materials = new[] { CoreUtils.CreateEngineMaterial("Hidden/InternalErrorShader"), CoreUtils.CreateEngineMaterial(pipelineAsset.copyDepthShader), CoreUtils.CreateEngineMaterial(pipelineAsset.samplingShader), CoreUtils.CreateEngineMaterial(pipelineAsset.blitShader), CoreUtils.CreateEngineMaterial(pipelineAsset.screenSpaceShadowShader), }; postProcessingContext = new PostProcessRenderContext(); }
public LightweightShadowPass(LightweightPipelineAsset pipelineAsset, int maxLocalLightsCount) { BuildShadowSettings(pipelineAsset); m_DirectionalShadowMatrices = new Matrix4x4[kMaxCascades + 1]; m_CascadeSlices = new ShadowSliceData[kMaxCascades]; m_CascadeSplitDistances = new Vector4[kMaxCascades]; m_LocalShadowMatrices = new Matrix4x4[maxLocalLightsCount]; m_LocalLightSlices = new ShadowSliceData[maxLocalLightsCount]; m_LocalShadowStrength = new float[maxLocalLightsCount]; DirectionalShadowConstantBuffer._WorldToShadow = Shader.PropertyToID("_WorldToShadow"); DirectionalShadowConstantBuffer._ShadowData = Shader.PropertyToID("_ShadowData"); DirectionalShadowConstantBuffer._DirShadowSplitSpheres = Shader.PropertyToID("_DirShadowSplitSpheres"); DirectionalShadowConstantBuffer._DirShadowSplitSphereRadii = Shader.PropertyToID("_DirShadowSplitSphereRadii"); DirectionalShadowConstantBuffer._ShadowOffset0 = Shader.PropertyToID("_ShadowOffset0"); DirectionalShadowConstantBuffer._ShadowOffset1 = Shader.PropertyToID("_ShadowOffset1"); DirectionalShadowConstantBuffer._ShadowOffset2 = Shader.PropertyToID("_ShadowOffset2"); DirectionalShadowConstantBuffer._ShadowOffset3 = Shader.PropertyToID("_ShadowOffset3"); DirectionalShadowConstantBuffer._ShadowmapSize = Shader.PropertyToID("_ShadowmapSize"); LocalShadowConstantBuffer._LocalWorldToShadowAtlas = Shader.PropertyToID("_LocalWorldToShadowAtlas"); LocalShadowConstantBuffer._LocalShadowStrength = Shader.PropertyToID("_LocalShadowStrength"); LocalShadowConstantBuffer._LocalShadowOffset0 = Shader.PropertyToID("_LocalShadowOffset0"); LocalShadowConstantBuffer._LocalShadowOffset1 = Shader.PropertyToID("_LocalShadowOffset1"); LocalShadowConstantBuffer._LocalShadowOffset2 = Shader.PropertyToID("_LocalShadowOffset2"); LocalShadowConstantBuffer._LocalShadowOffset3 = Shader.PropertyToID("_LocalShadowOffset3"); LocalShadowConstantBuffer._LocalShadowmapSize = Shader.PropertyToID("_LocalShadowmapSize"); m_DirectionalShadowmapID = Shader.PropertyToID("_ShadowMap"); m_LocalShadowmapID = Shader.PropertyToID("_LocalShadowMapAtlas"); m_ScreenSpaceShadowmapID = Shader.PropertyToID("_ScreenSpaceShadowMap"); m_ScreenSpaceShadowmapTexture = new RenderTargetIdentifier(m_ScreenSpaceShadowmapID); m_DirectionalShadowmapDescriptor = new RenderTextureDescriptor(m_ShadowSettings.directionalShadowAtlasWidth, m_ShadowSettings.directionalShadowAtlasHeight, m_ShadowSettings.shadowmapTextureFormat, m_ShadowSettings.bufferBitCount); m_LocalShadowmapDescriptor = new RenderTextureDescriptor(m_ShadowSettings.localShadowAtlasWidth, m_ShadowSettings.localShadowAtlasHeight, m_ShadowSettings.shadowmapTextureFormat, m_ShadowSettings.bufferBitCount); m_ScreenSpaceShadowsMaterial = CoreUtils.CreateEngineMaterial(pipelineAsset.ScreenSpaceShadowShader); Clear(); }
private Camera CreateMirrorObjects(Camera currentCamera) { LightweightPipelineAsset lwAsset = (LightweightPipelineAsset)GraphicsSettings.renderPipelineAsset; var resMulti = lwAsset.renderScale * GetScaleValue(); m_TextureSize.x = (int)Mathf.Pow(2, Mathf.RoundToInt(Mathf.Log(currentCamera.pixelWidth * resMulti, 2))); m_TextureSize.y = (int)Mathf.Pow(2, Mathf.RoundToInt(Mathf.Log(currentCamera.pixelHeight * resMulti, 2))); // Reflection render texture if (Int2Compare(m_TextureSize, m_OldReflectionTextureSize) || !m_ReflectionTexture) { if (m_ReflectionTexture) { DestroyImmediate(m_ReflectionTexture); } m_ReflectionTexture = new RenderTexture(m_TextureSize.x, m_TextureSize.y, 16, currentCamera.allowHDR ? RenderTextureFormat.DefaultHDR : RenderTextureFormat.Default); m_ReflectionTexture.useMipMap = m_ReflectionTexture.autoGenerateMips = false; m_ReflectionTexture.autoGenerateMips = false; // no need for mips(unless wanting cheap roughness) m_ReflectionTexture.name = "_PlanarReflection" + GetInstanceID(); m_ReflectionTexture.isPowerOfTwo = true; m_ReflectionTexture.hideFlags = HideFlags.DontSave; m_OldReflectionTextureSize = m_TextureSize; } m_ReflectionTexture.DiscardContents(); GameObject go = new GameObject("Planar Refl Camera id" + GetInstanceID() + " for " + currentCamera.GetInstanceID(), typeof(Camera), typeof(Skybox)); LightweightAdditionalCameraData lwrpCamData = go.AddComponent(typeof(LightweightAdditionalCameraData)) as LightweightAdditionalCameraData; lwrpCamData.renderShadows = false; // turn off shadows for the reflection camera var reflectionCamera = go.GetComponent <Camera>(); reflectionCamera.transform.SetPositionAndRotation(transform.position, transform.rotation); reflectionCamera.targetTexture = m_ReflectionTexture; reflectionCamera.allowMSAA = true; reflectionCamera.depth = -10; reflectionCamera.enabled = false; go.hideFlags = HideFlags.HideAndDontSave; Shader.SetGlobalTexture("_PlanarReflectionTexture", m_ReflectionTexture); return(reflectionCamera); }
public LightweightPipeline(LightweightPipelineAsset asset) { m_Asset = asset; BuildShadowSettings(); m_ShadowMapProperty = Shader.PropertyToID("_ShadowMap"); m_CameraRTProperty = Shader.PropertyToID("_CameraRT"); m_ShadowMapRTID = new RenderTargetIdentifier(m_ShadowMapProperty); m_CameraRTID = new RenderTargetIdentifier(m_CameraRTProperty); // Let engine know we have MSAA on for cases where we support MSAA backbuffer if (QualitySettings.antiAliasing != m_Asset.MSAASampleCount) { QualitySettings.antiAliasing = m_Asset.MSAASampleCount; } Shader.globalRenderPipeline = "LightweightPipeline"; }
private void BuildShadowSettings(LightweightPipelineAsset pipelineAsset) { // Until we can have keyword stripping forcing single cascade hard shadows on gles2 bool supportsScreenSpaceShadows = SystemInfo.graphicsDeviceType != GraphicsDeviceType.OpenGLES2; m_ShadowSettings = ShadowSettings.Default; m_ShadowSettings.supportsDirectionalShadows = pipelineAsset.SupportsDirectionalShadows; m_ShadowSettings.screenSpace = m_ShadowSettings.supportsDirectionalShadows && supportsScreenSpaceShadows; m_ShadowSettings.directionalLightCascadeCount = (m_ShadowSettings.screenSpace) ? pipelineAsset.CascadeCount : 1; m_ShadowSettings.directionalShadowAtlasWidth = pipelineAsset.DirectionalShadowAtlasResolution; m_ShadowSettings.directionalShadowAtlasHeight = pipelineAsset.DirectionalShadowAtlasResolution; m_ShadowSettings.maxShadowDistance = pipelineAsset.ShadowDistance; switch (m_ShadowSettings.directionalLightCascadeCount) { case 1: m_ShadowSettings.directionalLightCascades = new Vector3(1.0f, 0.0f, 0.0f); break; case 2: m_ShadowSettings.directionalLightCascades = new Vector3(pipelineAsset.Cascade2Split, 1.0f, 0.0f); break; default: m_ShadowSettings.directionalLightCascades = pipelineAsset.Cascade4Split; break; } m_ShadowSettings.supportsLocalShadows = pipelineAsset.SupportsLocalShadows; m_ShadowSettings.localShadowAtlasWidth = m_ShadowSettings.localShadowAtlasHeight = pipelineAsset.LocalShadowAtlasResolution; m_ShadowSettings.supportsSoftShadows = pipelineAsset.SupportsSoftShadows; m_ShadowSettings.bufferBitCount = 16; m_ShadowSettings.shadowmapTextureFormat = SystemInfo.SupportsRenderTextureFormat(RenderTextureFormat.Shadowmap) ? RenderTextureFormat.Shadowmap : RenderTextureFormat.Depth; m_ShadowSettings.screenspaceShadowmapTextureFormat = SystemInfo.SupportsRenderTextureFormat(RenderTextureFormat.R8) ? RenderTextureFormat.R8 : RenderTextureFormat.ARGB32; }
public LightweightForwardRenderer(LightweightPipelineAsset pipelineAsset) { // RenderTexture format depends on camera and pipeline (HDR, non HDR, etc) // Samples (MSAA) depend on camera and pipeline RegisterSurface("_CameraColorTexture", out RenderTargetHandles.Color); RegisterSurface("_CameraDepthAttachment", out RenderTargetHandles.DepthAttachment); RegisterSurface("_CameraDepthTexture", out RenderTargetHandles.DepthTexture); RegisterSurface("_CameraOpaqueTexture", out RenderTargetHandles.OpaqueColor); RegisterSurface("_DirectionalShadowmapTexture", out RenderTargetHandles.DirectionalShadowmap); RegisterSurface("_LocalShadowmapTexture", out RenderTargetHandles.LocalShadowmap); RegisterSurface("_ScreenSpaceShadowMapTexture", out RenderTargetHandles.ScreenSpaceShadowmap); m_Materials = new Material[(int)MaterialHandles.Count] { CoreUtils.CreateEngineMaterial("Hidden/InternalErrorShader"), CoreUtils.CreateEngineMaterial(pipelineAsset.copyDepthShader), CoreUtils.CreateEngineMaterial(pipelineAsset.samplingShader), CoreUtils.CreateEngineMaterial(pipelineAsset.blitShader), CoreUtils.CreateEngineMaterial(pipelineAsset.screenSpaceShadowShader), }; m_RenderPassSet = new ScriptableRenderPass[(int)RenderPassHandles.Count] { new DepthOnlyPass(this), new DirectionalShadowsPass(this), new LocalShadowsPass(this), new ScreenSpaceShadowResolvePass(this), new ForwardLitPass(this), }; postProcessRenderContext = new PostProcessRenderContext(); opaqueFilterSettings = new FilterRenderersSettings(true) { renderQueueRange = RenderQueueRange.opaque, }; transparentFilterSettings = new FilterRenderersSettings(true) { renderQueueRange = RenderQueueRange.transparent, }; }
public LightweightPipeline(LightweightPipelineAsset asset) { pipelineAsset = asset; SetSupportedRenderingFeatures(); SetPipelineCapabilities(asset); PerFrameBuffer._GlossyEnvironmentColor = Shader.PropertyToID("_GlossyEnvironmentColor"); PerFrameBuffer._SubtractiveShadowColor = Shader.PropertyToID("_SubtractiveShadowColor"); PerCameraBuffer._ScaledScreenParams = Shader.PropertyToID("_ScaledScreenParams"); m_Renderer = new LightweightForwardRenderer(asset); // Let engine know we have MSAA on for cases where we support MSAA backbuffer if (QualitySettings.antiAliasing != pipelineAsset.msaaSampleCount) QualitySettings.antiAliasing = pipelineAsset.msaaSampleCount; Shader.globalRenderPipeline = "LightweightPipeline"; m_IsCameraRendering = false; }
private void BuildShadowSettings(LightweightPipelineAsset pipelineAsset) { // Until we can have keyword stripping forcing single cascade hard shadows on gles2 bool supportsScreenSpaceShadows = SystemInfo.graphicsDeviceType != GraphicsDeviceType.OpenGLES2; bool supportsLocalShadows = Application.isMobilePlatform || Application.platform == RuntimePlatform.WebGLPlayer; m_ShadowSettings = ShadowSettings.Default; m_ShadowSettings.directionalShadowQuality = (LightShadows)pipelineAsset.ShadowSetting; m_ShadowSettings.screenSpace = supportsScreenSpaceShadows; m_ShadowSettings.directionalLightCascadeCount = (m_ShadowSettings.screenSpace) ? pipelineAsset.CascadeCount : 1; m_ShadowSettings.directionalShadowAtlasWidth = pipelineAsset.ShadowAtlasResolution; m_ShadowSettings.directionalShadowAtlasHeight = pipelineAsset.ShadowAtlasResolution; m_ShadowSettings.maxShadowDistance = pipelineAsset.ShadowDistance; m_ShadowSettings.shadowmapTextureFormat = SystemInfo.SupportsRenderTextureFormat(RenderTextureFormat.Shadowmap) ? RenderTextureFormat.Shadowmap : RenderTextureFormat.Depth; m_ShadowSettings.screenspaceShadowmapTextureFormat = SystemInfo.SupportsRenderTextureFormat(RenderTextureFormat.R8) ? RenderTextureFormat.R8 : RenderTextureFormat.ARGB32; switch (m_ShadowSettings.directionalLightCascadeCount) { case 1: m_ShadowSettings.directionalLightCascades = new Vector3(1.0f, 0.0f, 0.0f); break; case 2: m_ShadowSettings.directionalLightCascades = new Vector3(pipelineAsset.Cascade2Split, 1.0f, 0.0f); break; default: m_ShadowSettings.directionalLightCascades = pipelineAsset.Cascade4Split; break; } // Until we can have keyword stripping we disable local light shadows on mobile m_ShadowSettings.localLightsShadowQuality = (supportsLocalShadows) ? LightShadows.Hard : LightShadows.None; }
public LightweightPipeline(LightweightPipelineAsset asset) { m_PipelineSettings = PipelineSettings.Create(asset); SetSupportedRenderingFeatures(); SetPipelineCapabilities(asset); PerFrameBuffer._GlossyEnvironmentColor = Shader.PropertyToID("_GlossyEnvironmentColor"); PerFrameBuffer._SubtractiveShadowColor = Shader.PropertyToID("_SubtractiveShadowColor"); PerCameraBuffer._InvCameraViewProj = Shader.PropertyToID("_InvCameraViewProj"); PerCameraBuffer._ScaledScreenParams = Shader.PropertyToID("_ScaledScreenParams"); m_Renderer = new ScriptableRenderer(asset); // Let engine know we have MSAA on for cases where we support MSAA backbuffer if (QualitySettings.antiAliasing != m_PipelineSettings.msaaSampleCount) { QualitySettings.antiAliasing = m_PipelineSettings.msaaSampleCount; } Shader.globalRenderPipeline = "LightweightPipeline"; }
public LightweightForwardRenderer(LightweightPipelineAsset pipelineAsset) { m_Materials = new Material[(int)MaterialHandles.Count] { CoreUtils.CreateEngineMaterial("Hidden/InternalErrorShader"), CoreUtils.CreateEngineMaterial(pipelineAsset.copyDepthShader), CoreUtils.CreateEngineMaterial(pipelineAsset.samplingShader), CoreUtils.CreateEngineMaterial(pipelineAsset.blitShader), CoreUtils.CreateEngineMaterial(pipelineAsset.screenSpaceShadowShader), }; postProcessRenderContext = new PostProcessRenderContext(); opaqueFilterSettings = new FilterRenderersSettings(true) { renderQueueRange = RenderQueueRange.opaque, }; transparentFilterSettings = new FilterRenderersSettings(true) { renderQueueRange = RenderQueueRange.transparent, }; }
static void SetPipelineCapabilities(LightweightPipelineAsset pipelineAsset) { s_PipelineCapabilities = 0U; // Strip variants based on selected pipeline features if (!pipelineAsset.customShaderVariantStripping) { if (pipelineAsset.maxPixelLights > 1 || pipelineAsset.supportsVertexLight) { s_PipelineCapabilities |= PipelineCapabilities.AdditionalLights; } if (pipelineAsset.supportsVertexLight) { s_PipelineCapabilities |= PipelineCapabilities.VertexLights; } if (pipelineAsset.supportsDirectionalShadows) { s_PipelineCapabilities |= PipelineCapabilities.DirectionalShadows; } if (pipelineAsset.supportsLocalShadows) { s_PipelineCapabilities |= PipelineCapabilities.LocalShadows; } bool anyShadows = pipelineAsset.supportsDirectionalShadows || pipelineAsset.supportsLocalShadows; if (pipelineAsset.supportsSoftShadows && anyShadows) { s_PipelineCapabilities |= PipelineCapabilities.SoftShadows; } } else { if (pipelineAsset.keepAdditionalLightVariants) { s_PipelineCapabilities |= PipelineCapabilities.AdditionalLights; } if (pipelineAsset.keepVertexLightVariants) { s_PipelineCapabilities |= PipelineCapabilities.VertexLights; } if (pipelineAsset.keepDirectionalShadowVariants) { s_PipelineCapabilities |= PipelineCapabilities.DirectionalShadows; } if (pipelineAsset.keepLocalShadowVariants) { s_PipelineCapabilities |= PipelineCapabilities.LocalShadows; } if (pipelineAsset.keepSoftShadowVariants) { s_PipelineCapabilities |= PipelineCapabilities.SoftShadows; } } }