コード例 #1
0
 private void CameraPreCull(Camera camera)
 {
     if (!WeatherMakerScript.ShouldIgnoreCamera(this, camera))
     {
         commandBuffer.Clear();
         if (BlurMaterial != null)
         {
             RenderTextureFormat     format = (camera.allowHDR ? RenderTextureFormat.DefaultHDR : RenderTextureFormat.Default);
             RenderTextureDescriptor desc1  = WeatherMakerFullScreenEffect.GetRenderTextureDescriptor((int)Scale, 1, 1, format, 0, camera);
             RenderTextureDescriptor desc2  = WeatherMakerFullScreenEffect.GetRenderTextureDescriptor(1, 1, 1, format, 0, camera);
             commandBuffer.GetTemporaryRT(WMS._MainTex2, desc1);
             commandBuffer.GetTemporaryRT(WMS._MainTex3, desc2);
             commandBuffer.SetRenderTarget(WMS._MainTex2);
             commandBuffer.ClearRenderTarget(true, true, Color.clear);
             commandBuffer.SetGlobalFloat(WMS._WeatherMakerDownsampleScale, (float)Scale);
             commandBuffer.DrawRenderer(Renderer, Renderer.sharedMaterial, 0, 0); // draw pass
             commandBuffer.SetRenderTarget(WMS._MainTex3);
             commandBuffer.ClearRenderTarget(true, true, Color.clear);
             commandBuffer.DrawRenderer(Renderer, Renderer.sharedMaterial, 0, 1); // depth pass
             commandBuffer.SetGlobalTexture(WMS._WeatherMakerTemporaryDepthTexture, WMS._MainTex3);
             commandBuffer.SetGlobalFloat(WMS._DstBlendMode, (float)BlendMode.OneMinusSrcAlpha);
             commandBuffer.Blit(WMS._MainTex2, WeatherMakerFullScreenEffect.CameraTargetIdentifier(), BlurMaterial, 0);
             commandBuffer.ReleaseTemporaryRT(WMS._MainTex2);
             commandBuffer.ReleaseTemporaryRT(WMS._MainTex3);
             camera.AddCommandBuffer(CameraEvent, commandBuffer);
         }
     }
 }
コード例 #2
0
        private void AddScreenSpaceShadowsCommandBuffer(Camera camera)
        {
            if (CloudShadowMaterial != null && _light != null && _light.type == LightType.Directional &&
                _light.shadows != LightShadows.None && WeatherMakerLightManagerScript.Instance != null &&
                WeatherMakerLightManagerScript.ScreenSpaceShadowMode != BuiltinShaderMode.Disabled &&
                (WeatherMakerScript.Instance == null || WeatherMakerScript.Instance.PerformanceProfile == null ||
                 (WeatherMakerScript.Instance.PerformanceProfile.VolumetricCloudShadowDownsampleScale != WeatherMakerDownsampleScale.Disabled &&
                  WeatherMakerScript.Instance.PerformanceProfile.VolumetricCloudShadowSampleCount > 0)))
            {
                if (_commandBufferScreenSpaceShadows1 == null)
                {
                    // copy the screen space shadow texture for re-use later
                    _commandBufferScreenSpaceShadows1 = new CommandBuffer {
                        name = "WeatherMakerShadowMapScreensSpaceShadowScriptBlur_" + gameObject.name
                    };
                }
                if (_commandBufferScreenSpaceShadows2 == null)
                {
                    // copy the screen space shadow texture for re-use later
                    _commandBufferScreenSpaceShadows2 = new CommandBuffer {
                        name = "WeatherMakerShadowMapScreensSpaceShadowScriptBlit_" + gameObject.name
                    };
                }

                _commandBufferScreenSpaceShadows1.Clear();
                _commandBufferScreenSpaceShadows1.SetGlobalFloat(WMS._BlendOp, (float)BlendOp.Add);
                _commandBufferScreenSpaceShadows1.SetGlobalFloat(WMS._SrcBlendMode, (float)BlendMode.One);
                _commandBufferScreenSpaceShadows1.SetGlobalFloat(WMS._DstBlendMode, (float)BlendMode.Zero);

#if UNITY_LWRP
                _commandBufferScreenSpaceShadows1.SetGlobalTexture(WMS._MainTex5, WMS._ScreenSpaceShadowmapTexture);
                _commandBufferScreenSpaceShadows1.Blit(WMS._ScreenSpaceShadowmapTexture, tempShadowBuffer, CloudShadowMaterial, 0);
                camera.AddCommandBuffer(CameraEvent.BeforeForwardOpaque, _commandBufferScreenSpaceShadows1);
#else
                _commandBufferScreenSpaceShadows1.SetGlobalTexture(WMS._MainTex5, BuiltinRenderTextureType.CurrentActive);
                _commandBufferScreenSpaceShadows1.Blit(BuiltinRenderTextureType.CurrentActive, tempShadowBuffer, CloudShadowMaterial, 0);
                _light.AddCommandBuffer(LightEvent.AfterScreenspaceMask, _commandBufferScreenSpaceShadows1);
#endif

                // screen space shadow mask does not use concept of stereo, so turn it off
                _commandBufferScreenSpaceShadows2.Clear();
                _commandBufferScreenSpaceShadows2.SetGlobalFloat(WMS._SrcBlendMode, (float)BlendMode.One);
                _commandBufferScreenSpaceShadows2.SetGlobalFloat(WMS._DstBlendMode, (float)BlendMode.One);
                _commandBufferScreenSpaceShadows2.SetGlobalFloat(WMS._WeatherMakerAdjustFullScreenUVStereoDisable, 1.0f);

#if UNITY_LWRP
                _commandBufferScreenSpaceShadows2.Blit(tempShadowBuffer, WMS._ScreenSpaceShadowmapTexture, BlurMaterial, 0);
                _commandBufferScreenSpaceShadows2.SetGlobalTexture(WeatherMakerLightManagerScript.Instance.ScreenSpaceShadowsRenderTextureName, WMS._ScreenSpaceShadowmapTexture);
#else
                _commandBufferScreenSpaceShadows2.Blit(tempShadowBuffer, BuiltinRenderTextureType.CurrentActive, BlurMaterial, 0);
                _commandBufferScreenSpaceShadows2.SetGlobalTexture(WeatherMakerLightManagerScript.Instance.ScreenSpaceShadowsRenderTextureName, BuiltinRenderTextureType.CurrentActive);
#endif

                // must be set back to 0 after the blit
                _commandBufferScreenSpaceShadows2.SetGlobalFloat(WMS._WeatherMakerAdjustFullScreenUVStereoDisable, 0.0f);

#if UNITY_LWRP
                _commandBufferScreenSpaceShadows2.SetRenderTarget(WeatherMakerFullScreenEffect.CameraTargetIdentifier());
                camera.AddCommandBuffer(CameraEvent.BeforeForwardOpaque, _commandBufferScreenSpaceShadows2);
#else
                _light.AddCommandBuffer(LightEvent.AfterScreenspaceMask, _commandBufferScreenSpaceShadows2);
#endif
            }
            else
            {
                CleanupCommandBuffers();
            }
        }