返回介绍

MonoBehaviour.OnPostRender() 当渲染之后

发布于 2019-12-18 15:38:03 字数 3750 浏览 1097 评论 0 收藏 0

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可以是一个协同程序,在函数中调用yield语句。

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.

OnPostRender在相机渲染完所有物体之后被调用。如果你想在相机和GUI渲染完成后做些什么,就用WaitForEndOfFrame协同程序。

参见:OnPreRender , WaitForEndOfFrame

JavaScript:

// 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 (); 
} 

C#:

using UnityEngine;
using System.Collections;
 
public class Sample : MonoBehaviour {
 
	// 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.
 
	Material mat;
 
	void 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.1f ); 
			GL.Vertex3( 1, 0, 0.1f ); 
			GL.Vertex3( 1, 1, 0.1f );
			GL.Vertex3( 0, 1, 0.1f ); 
			GL.End(); 
		} 
		GL.PopMatrix (); 
	} 
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文