invertCulling
Select whether to invert the backface culling (true) or not (false).
Read time 1 minuteLast updated 5 days ago
Definition
- Type: Property
- Namespace: UnityEngine
- Assembly: UnityEngine.CoreModule
public static bool invertCulling { get; set; }
Remarks
This flag can "flip" the culling mode of all rendered objects. Major use case: rendering reflections for mirrors, water etc. Since virtual camera for rendering the reflection is mirrored, the culling order has to be inverted. You can see how the Water script in Effects standard package does that.
Examples
// Attach this script to a camera to render the back faces of objects// instead of the front faces.using UnityEngine;using UnityEngine.Rendering;[ExecuteInEditMode]public class ExampleScript : MonoBehaviour{ private bool oldCulling; void OnEnable() { RenderPipelineManager.beginCameraRendering += OnBeginCamera; RenderPipelineManager.endCameraRendering += OnEndCamera; } void OnDisable() { RenderPipelineManager.beginCameraRendering -= OnBeginCamera; RenderPipelineManager.endCameraRendering -= OnEndCamera; } void OnBeginCamera(ScriptableRenderContext context, Camera camera) { if (camera != GetComponent<Camera>()) return; oldCulling = GL.invertCulling; GL.invertCulling = true; } void OnEndCamera(ScriptableRenderContext context, Camera camera) { if (camera != GetComponent<Camera>()) return; GL.invertCulling = oldCulling; }}