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.

MonoBehaviour.OnPostRender()

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

Switch to Manual

Description

OnPostRender is called after a camera finished rendering the scene.

This function is called only if the script is attached to the camera and is enabled. OnPostRender can be a co-routine, simply use the yield statement in the function.

OnPostRender is called after the camera renders all its objects. If you want to do something after all cameras and GUI is rendered, use WaitForEndOfFrame coroutine.

See Also: OnPreRender, WaitForEndOfFrame.

	// When attached to a camera, will clear alpha channel
	// of camera's render texture to pure white.
	// Useful if you have camera rendering into a texture and later
	// want to display it in GUI.

private var mat : Material;

function OnPostRender() { // Create a shader that renders white only to alpha channel if(!mat) { mat = new Material( "Shader \"Hidden/SetAlpha\" {" + "SubShader {" + " Pass {" + " ZTest Always Cull Off ZWrite Off" + " ColorMask A" + " Color (1,1,1,1)" + " }" + "}" + "}" ); } // Draw a quad over the whole screen with the above shader GL.PushMatrix (); GL.LoadOrtho (); for (var i = 0; i < mat.passCount; ++i) { mat.SetPass (i); GL.Begin( GL.QUADS ); GL.Vertex3( 0, 0, 0.1 ); GL.Vertex3( 1, 0, 0.1 ); GL.Vertex3( 1, 1, 0.1 ); GL.Vertex3( 0, 1, 0.1 ); GL.End(); } GL.PopMatrix (); }