private void CameraPreCull(Camera camera) { if (ReflectMaterial == null || camera == null || WeatherMakerLightManagerScript.Instance == null || (ReflectRenderer != null && !ReflectRenderer.enabled) || !gameObject.activeInHierarchy || WeatherMakerCommandBufferManagerScript.CameraStack > 1 || WeatherMakerScript.ShouldIgnoreCamera(this, camera, true)) { return; } // HACK: Reflections need to ensure the frustum planes and corners are up to date. This is normally done in a pre-render // event, but we cannot do that as rendering a reflection in pre-render mucks up state and such WeatherMakerLightManagerScript.Instance.CalculateFrustumPlanes(camera); // this frustum cull test is expensive, but well worth it if it prevents a reflection from needing to be rendered // get up to date frustum info if (ReflectRenderer != null && !WeatherMakerGeometryUtility.BoxIntersectsFrustum(camera, WeatherMakerLightManagerScript.Instance.CurrentCameraFrustumPlanes, WeatherMakerLightManagerScript.Instance.CurrentCameraFrustumCorners, ReflectRenderer.bounds)) { return; } // render the reflection in pre-cull, pre-render is when shader properties and other such things are set Camera reflectionCamera = GetOrCreateReflectionCamera(camera); RenderReflectionCamera(camera, reflectionCamera); }
/// <summary> /// Queue a reflection camera /// </summary> /// <param name="sourceCamera">Viewing camera</param> /// <returns>Reflection camera info</returns> public ReflectionCameraInfo QueueReflection(Camera sourceCamera) { bool isReflection; if (ReflectMaterial == null || sourceCamera == null || WeatherMakerLightManagerScript.Instance == null || ShouldIgnoreCamera(sourceCamera, out isReflection)) { return(null); } // HACK: Reflections need to ensure the frustum planes and corners are up to date. This is normally done in a pre-render // event, but we cannot do that as rendering a reflection in pre-render mucks up state and such WeatherMakerLightManagerScript.Instance.CalculateFrustumPlanes(sourceCamera); // this frustum cull test is expensive, but well worth it if it prevents a reflection from needing to be rendered // get up to date frustum info if (ReflectRenderer != null && !WeatherMakerGeometryUtility.BoxIntersectsFrustum(sourceCamera, WeatherMakerLightManagerScript.Instance.CurrentCameraFrustumPlanes, WeatherMakerLightManagerScript.Instance.CurrentCameraFrustumCorners, ReflectRenderer.bounds)) { return(null); } // Debug.LogFormat("WeatherMakerReflectionScript rendering in {0}, bounds: {1}", sourceCamera.name, ReflectMaterial.bounds); // start off some render textures for the reflection KeyValuePair <RenderTexture, RenderTexture> kv = new KeyValuePair <RenderTexture, RenderTexture> ( ReflectMaterial.GetTexture(ReflectionSamplerName) as RenderTexture, ReflectMaterial.GetTexture(ReflectionSamplerName2) as RenderTexture ); currentRenderTextures.Add(kv); ReflectionCameraInfo cam = CreateReflectionCamera(sourceCamera, isReflection); RenderReflectionCamera(cam); return(cam); }