Пример #1
0
    public static void Render(ScriptableRenderContext context, IEnumerable <Camera> cameras, SRP07CustomParameter SRP07CP)
    {
        string tx = "";

        foreach (Camera camera in cameras)
        {
            ScriptableCullingParameters cullingParams;

            // Stereo-aware culling parameters are configured to perform a single cull for both eyes
            if (!CullResults.GetCullingParameters(camera, out cullingParams))
            {
                continue;
            }
            CullResults cull = new CullResults();
            CullResults.Cull(ref cullingParams, context, ref cull);

            // Setup camera for rendering (sets render target, view/projection matrices and other
            // per-camera built-in shader variables).
            context.SetupCameraProperties(camera);

            // clear depth buffer
            CommandBuffer cmd = new CommandBuffer();
            cmd.ClearRenderTarget(true, !SRP07CP.DrawSkybox, SRP07CP.ClearColor);
            context.ExecuteCommandBuffer(cmd);
            cmd.Release();

            // Setup global lighting shader variables
            SetupLightShaderVariables(cull.visibleLights, context);

            if (SRP07CP.DrawSkybox)
            {
                // Draw skybox
                context.DrawSkybox(camera);
            }

            // Setup DrawSettings and FilterSettings
            ShaderPassName          passName       = new ShaderPassName("BasicPass");
            DrawRendererSettings    drawSettings   = new DrawRendererSettings(camera, passName);
            FilterRenderersSettings filterSettings = new FilterRenderersSettings(true);

            // ////////////////////////////////////////////////////////////
            VisibleLight[]        ls = cull.visibleLights.ToArray();
            DrawShadowsSettings[] shadowsSettings = new DrawShadowsSettings[ls.Length];

            for (int i = 0; i < shadowsSettings.Length; i++)
            {
                shadowsSettings[i] = new DrawShadowsSettings(cull, i);
            }

            /*
             * if(camera == Camera.main) //Only generate result from main cam
             * {
             *  tx += "DrawShadowsSettings" + "\n"+ "\n";
             *
             *  for (int i=0; i<ls.Length; i++)
             *  {
             *      tx += "lightIndex = " + shadowsSettings[i].lightIndex + " (" + ls[i].light.name + ") " + "\n";
             *      tx += "splitData.cullingPlaneCount = " + shadowsSettings[i].splitData.cullingPlaneCount + "\n";
             *      tx += "splitData.cullingSphere = " + shadowsSettings[i].splitData.cullingSphere + "\n"+ "\n";
             *  }
             *
             *  // Output to text
             *  if (textMesh != null)
             *  {
             *      textMesh.text = tx;
             *      Debug.Log("<color=#0F0>TextMesh is updated</color>");
             *  }
             *  else
             *  {
             *      tx = "<color=#F00>TextMesh is null</color> Please hit play if you hasn't";
             *      Debug.Log(tx);
             *  }
             * }
             */
            // ////////////////////////////////////////////////////////////

            if (SRP07CP.DrawOpaque)
            {
                // Draw opaque objects using BasicPass shader pass
                drawSettings.sorting.flags      = SortFlags.CommonOpaque;
                filterSettings.renderQueueRange = RenderQueueRange.opaque;
                context.DrawRenderers(cull.visibleRenderers, ref drawSettings, filterSettings);

                for (int i = 0; i < shadowsSettings.Length; i++)
                {
                    //if(ls[i].light.shadows != LightShadows.None)
                    //context.DrawShadows(ref shadowsSettings[i]);
                }
            }

            if (SRP07CP.DrawTransparent)
            {
                // Draw transparent objects using BasicPass shader pass
                drawSettings.sorting.flags      = SortFlags.CommonTransparent;
                filterSettings.renderQueueRange = RenderQueueRange.transparent;
                context.DrawRenderers(cull.visibleRenderers, ref drawSettings, filterSettings);
            }

            context.Submit();
        }
    }
Пример #2
0
 public SRP07Instance(SRP07CustomParameter SRP07CustomParameter)
 {
     SRP07CP = SRP07CustomParameter;
 }