Legacy Documentation: Version 4.6(go to latest)
Language: English
  • C#
  • JS
  • Boo

Script language

Select your preferred scripting language. All code snippets will be displayed in this language.

GL.SetRevertBackfacing

Suggest a change

Success!

Thank you for helping us improve the quality of Unity Documentation. Although we cannot accept all submissions, we do read each suggested change from our users and will make updates where applicable.

Close

Sumbission failed

For some reason your suggested change could not be submitted. Please try again in a few minutes. And thank you for taking the time to help us improve the quality of Unity Documentation.

Close

Cancel

public static function SetRevertBackfacing(revertBackFaces: bool): void;
public static void SetRevertBackfacing(bool revertBackFaces);
public static def SetRevertBackfacing(revertBackFaces as bool) as void

Description

Select whether to invert the backface culling (true) or not (false).

Unlike most other calls, this is not only related to stuff you draw via GL class. It changes culling of triangles globally. 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 that the Water script in Pro Standard Assets does that.

	// Draws 2 yellow triangles and makes them appear/dissapear
	// depending on the vertex draw order
	// Notice that everything on the scene will suffer from the revert
	// backfacing as well
	var mat : Material;

var swap : boolean = false; function Update() { if(Input.GetKeyDown(KeyCode.Space)) { if(swap) { swap = false; } else { swap = true; } } }

function OnPostRender() { if (!mat) { Debug.LogError("Please Assign a material on the inspector"); return; } GL.PushMatrix(); mat.SetPass(0); GL.LoadOrtho(); GL.Color(Color.yellow); GL.Begin(GL.TRIANGLES); GL.SetRevertBackfacing(swap); GL.Vertex3(0,0,0); GL.Vertex3(1,1,0); GL.Vertex3(0,1,0); GL.Vertex3(0,0,0); GL.Vertex3(1,1,0); GL.Vertex3(1,0,0); GL.End(); GL.PopMatrix(); }
using UnityEngine;
using System.Collections;

public class ExampleClass : MonoBehaviour {
    public Material mat;
    public bool swap = false;
    void Update() {
        if (Input.GetKeyDown(KeyCode.Space))
            if (swap)
                swap = false;
            else
                swap = true;
        
    }
    void OnPostRender() {
        if (!mat) {
            Debug.LogError("Please Assign a material on the inspector");
            return;
        }
        GL.PushMatrix();
        mat.SetPass(0);
        GL.LoadOrtho();
        GL.Color(Color.yellow);
        GL.Begin(GL.TRIANGLES);
        GL.SetRevertBackfacing(swap);
        GL.Vertex3(0, 0, 0);
        GL.Vertex3(1, 1, 0);
        GL.Vertex3(0, 1, 0);
        GL.Vertex3(0, 0, 0);
        GL.Vertex3(1, 1, 0);
        GL.Vertex3(1, 0, 0);
        GL.End();
        GL.PopMatrix();
    }
}
import UnityEngine
import System.Collections

public class ExampleClass(MonoBehaviour):

	public mat as Material

	public swap as bool = false

	def Update() as void:
		if Input.GetKeyDown(KeyCode.Space):
			if swap:
				swap = false
			else:
				swap = true

	def OnPostRender() as void:
		if not mat:
			Debug.LogError('Please Assign a material on the inspector')
			return
		GL.PushMatrix()
		mat.SetPass(0)
		GL.LoadOrtho()
		GL.Color(Color.yellow)
		GL.Begin(GL.TRIANGLES)
		GL.SetRevertBackfacing(swap)
		GL.Vertex3(0, 0, 0)
		GL.Vertex3(1, 1, 0)
		GL.Vertex3(0, 1, 0)
		GL.Vertex3(0, 0, 0)
		GL.Vertex3(1, 1, 0)
		GL.Vertex3(1, 0, 0)
		GL.End()
		GL.PopMatrix()