public static void RenderSingleCamera(DoomSRPPipeline pipelineInstance, ScriptableRenderContext context, Camera camera, ref CullResults cullResults, IRendererSetup setup = null) { if (pipelineInstance == null) { Debug.LogError("Trying to render a camera with an invalid render pipeline instance."); return; } ScriptableCullingParameters cullingParameters; if (!CullResults.GetCullingParameters(camera, out cullingParameters)) { return; } CommandBuffer cmd = CommandBufferPool.Get(k_RenderCameraTag); using (new ProfilingSample(cmd, k_RenderCameraTag)) { CameraData cameraData; PipelineSettings settings = pipelineInstance.settings; ScriptableRenderer renderer = pipelineInstance.renderer; LightLoop lightloop = pipelineInstance.GetLightLoop(); InitializeCameraData(pipelineInstance.settings, camera, out cameraData); SetupPerCameraShaderConstants(cameraData); cullingParameters.shadowDistance = Mathf.Min(cameraData.maxShadowDistance, camera.farClipPlane); context.ExecuteCommandBuffer(cmd); cmd.Clear(); #if UNITY_EDITOR // Emit scene view UI if (cameraData.isSceneViewCamera) { ScriptableRenderContext.EmitWorldGeometryForSceneView(camera); } #endif CullResults.Cull(ref cullingParameters, context, ref cullResults); RenderingData renderingData; InitializeRenderingData(settings, ref cameraData, ref cullResults, ref lightloop, out renderingData); var setupToUse = setup; if (setupToUse == null) { setupToUse = defaultRendererSetup; } renderer.Clear(); setupToUse.Setup(renderer, ref renderingData); renderer.Execute(context, ref renderingData); } context.ExecuteCommandBuffer(cmd); CommandBufferPool.Release(cmd); context.Submit(); #if UNITY_EDITOR Handles.DrawGizmos(camera); #endif }
private void Set(CameraData cameraData, PipelineSettings pipelineSettings, LightLoop lightLoop) { generateClusterJob.ClusterCB_GridDimX = pipelineSettings.NumClusterX; generateClusterJob.ClusterCB_GridDimY = pipelineSettings.NumClusterY; generateClusterJob.ClusterCB_GridDimZ = pipelineSettings.NumClusterZ; generateClusterJob.ClusterCB_ViewNear = cameraData.zNear; generateClusterJob.ClusterCB_SizeX = ((float)cameraData.pixelWidth / (float)pipelineSettings.NumClusterX); generateClusterJob.ClusterCB_SizeY = ((float)cameraData.pixelHeight / (float)pipelineSettings.NumClusterY); generateClusterJob.ClusterCB_NearK = 1.0f + cameraData.sD; generateClusterJob.ClusterCB_ScreenDimensions = new Vector4( cameraData.pixelWidth, cameraData.pixelHeight, 1.0f / (float)cameraData.pixelWidth, 1.0f / (float)cameraData.pixelHeight ); generateClusterJob.ClusterCB_InverseProjectionMatrix = cameraData.GPUProjectMatrix.inverse; generateClusterJob.cameraToWorldMatrix = cameraData.cameraToWorldMatrix; generateClusterJob._CameraWorldMatrix = cameraData._CameraWorldMatrix; generateClusterJob.ScreenSizeX = cameraData.pixelWidth; generateClusterJob.ScreenSizeY = cameraData.pixelHeight; generateClusterJob.NearZ = cameraData.zNear; generateClusterJob.FarZ = cameraData.zFar; generateClusterJob.ClusterCG_ZDIV = cameraData.ClusterdLighting.z; generateClusterJob.ClusterdLighting = cameraData.ClusterdLighting; generateClusterJob.ResultClusterAABBS = ClustersAABBs; pointLightListGenJobSingleLine.NumClusters = pipelineSettings.NumClusters; pointLightListGenJobSingleLine.VisibleLightsCount = lightLoop.VisibleLight; pointLightListGenJobSingleLine.LightBounds = lightLoop.LigtsBoundList; pointLightListGenJobSingleLine.IsClusterEditorHelper = pipelineSettings.IsClusterEditorHelper; pointLightListGenJobSingleLine._CameraWorldMatrix = cameraData._CameraWorldMatrix; pointLightListGenJobSingleLine.NumItemsPerCluster = LightDefins.MaxItemsPerCluster; pointLightListGenJobSingleLine.InputClusterAABBS = ClustersAABBs; pointLightListGenJobSingleLine.ResultClusterNumItems = ResultClusterNumItems; pointLightListGenJobSingleLine.ResultItemsIDList = ResultItemsIDList; pointLightListGenJob.NumClusters = pipelineSettings.NumClusters; pointLightListGenJob.VisibleLightsCount = lightLoop.VisibleLight; pointLightListGenJob.LightBounds = lightLoop.LigtsBoundList; pointLightListGenJob.IsClusterEditorHelper = pipelineSettings.IsClusterEditorHelper; pointLightListGenJob._CameraWorldMatrix = cameraData._CameraWorldMatrix; pointLightListGenJob.NumItemsPerCluster = LightDefins.MaxItemsPerCluster; pointLightListGenJob.InputClusterAABBS = ClustersAABBs; pointLightListGenJob.ResultClusterNumItems = ResultClusterNumItems; pointLightListGenJob.ResultItemsIDVec = ResultItemsIDVec.ToConcurrent(); }
static void InitializeShadowData(PipelineSettings settings, LightLoop lightLoop, ref ShadowData shadowData) { m_ShadowBiasData.Clear(); var lights = lightLoop.lights; for (int i = 0; i < lights.size; ++i) { var light = lights[i]; m_ShadowBiasData.Add(new Vector4(light.shadowBias, light.shadowNormalBias, 0.0f, 0.0f)); } shadowData.bias = m_ShadowBiasData; // Until we can have keyword stripping forcing single cascade hard shadows on gles2 bool supportsScreenSpaceShadows = SystemInfo.graphicsDeviceType != GraphicsDeviceType.OpenGLES2; // we resolve shadows in screenspace when cascades are enabled to save ALU as computing cascade index + shadowCoord on fragment is expensive shadowData.requiresScreenSpaceShadowResolve = supportsScreenSpaceShadows; shadowData.supportsSoftShadows = settings.supportsSoftShadows && shadowData.supportsSoftShadows; shadowData.shadowmapDepthBufferBits = 16; }
static void InitializeRenderingData(PipelineSettings settings, ref CameraData cameraData, ref CullResults cullResults, ref LightLoop lightloop, out RenderingData renderingData) { List <VisibleLight> visibleLights = cullResults.visibleLights; renderingData.cullResults = cullResults; renderingData.cameraData = cameraData; renderingData.settings = settings; //todo 自定义光源裁剪,因为这个光源是projector光源 InitializeLightData(settings, visibleLights, lightloop, out renderingData.lightData); renderingData.supportsDynamicBatching = false;// settings.supportsDynamicBatching; //todo: settings renderingData.shadowData = new ShadowData(); renderingData.shadowData.lightsShadowmapHeight = 1024; renderingData.shadowData.lightsShadowmapWidth = 1024; renderingData.shadowData.supportsLightShadows = true; renderingData.shadowData.supportsSoftShadows = false; renderingData.shadowData.shadowmapDepthBufferBits = 24; lightloop.RebuildLightsList(cullResults.visibleLights, cameraData, settings, ref renderingData); InitializeShadowData(settings, lightloop, ref renderingData.shadowData); }
static void InitializeLightData(PipelineSettings settings, List <VisibleLight> visibleLights, LightLoop lightloop, out LightsData lightData) { // public int mainLightIndex; //public int additionalLightsCount; //public int maxPerObjectAdditionalLightsCount; //public List<VisibleLight> visibleLights; //public bool shadeAdditionalLightsPerVertex; //public bool supportsMixedLighting; lightData.visibleLights = visibleLights; lightData.lightLoop = lightloop; //lightData.mainLightIndex = 0; }
public void Run(/*Camera camera*/ CameraData cameraData, PipelineSettings pipelineSettings, LightLoop lightLoop) { UnityEngine.Profiling.Profiler.BeginSample("RebuildLightsList run"); Set(cameraData, pipelineSettings, lightLoop); UnityEngine.Profiling.Profiler.BeginSample("RebuildLightsList run generateClusterJob"); // Schedule the job with one Execute per index in the results array and only 1 item per processing batch generateClusterJob.Run(pipelineSettings.NumClusters); JobHandle generateClusterJobHandle = generateClusterJob.Schedule(pipelineSettings.NumClusters, 1); UnityEngine.Profiling.Profiler.EndSample(); UnityEngine.Profiling.Profiler.BeginSample("RebuildLightsList run pointLightListGenJobSingleLine"); //pointLightListGenJob.Run(pipelineSettings.NumClusters); JobHandle pointLightListGenJobHandle = pointLightListGenJob.Schedule(pipelineSettings.NumClusters, 8, generateClusterJobHandle); JobHandle.ScheduleBatchedJobs(); pointLightListGenJobHandle.Complete(); UnityEngine.Profiling.Profiler.EndSample(); //JobHandle pointLightListGenJobSingleLineHandle = pointLightListGenJobSingleLine.Schedule(pipelineSettings.NumClusters, 1, generateClusterJobHandle); //pointLightListGenJobSingleLineHandle.Complete(); #if UNITY_EDITOR if (ClusterDebug.selectCamera == cameraData.camera) { ClustersAABBsCache.CopyFrom(ClustersAABBs); } #endif int index = 0; for (int i = 0; i < pipelineSettings.NumClusters; ++i) { index = 0; bool found = ResultItemsIDVec.TryGetFirstValue(i, out uint item, out NativeMultiHashMapIterator <int> it); while (found && index < pipelineSettings.MaxItemsPerCluster) { ResultItemsIDList[i * pipelineSettings.MaxItemsPerCluster + index] = item; index++; found = ResultItemsIDVec.TryGetNextValue(out item, ref it); } } ResultItemsIDVec.Dispose(); UnityEngine.Profiling.Profiler.EndSample(); }