CommandBuffer.Blit BuiltinRenderTextureType.CameraTarget为空的问题

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/cubesky/article/details/76573279

Forward模式下,当使用CommandBuffer来实现后处理的时候,发现cb.Blit(BuiltinRenderTextureType.CameraTarget,...)无效,在FrameDebug中看到传入的_MainTex为Whilte,(在Deferred渲染模式下有效)

原因:

在Forward模式下,默认相机是渲染到BackBuffer,而在渲染的时候,无法直接读取BackBuffer(Deffered模式下有GBuffer,所以没有问题),解决办法,手动Grab一次(调用cb.Blit指定入材质即可,有额外性能消耗),或者相机开启forceIntoRenderTexture。(注:必须5.6以后才生效,如果开启了HDR或者使用了OnRenderImage则不需要开启(5.6以上))

类似问题:

So it seems that when OnRenderImage is being used, or when HDR rendering is on, or when anything that needs the camera to render to an intermediate buffer is enabled, the camera automatically renders to an intermediate buffer instead of the backbuffer (screen) directly. This is nice.

However when Unity cannot predict that the camera is going to need an intermediate buffer, and your command buffer does a Blit(), things go wrong: since Unity cannot know in advance what you're doing in the CB, it grabs the image from the back buffer again and the Blit() (which does not know where the input is coming from) flips it.

The issue can be fixed by enabling the camera's "forceIntoRenderTexture". This forces Unity to quit rendering to the back buffer directly and always render the camera to an intermediate buffer (regardless of HDR state, whether or not there are image effects present, etc.)


参考

https://forum.unity3d.com/threads/commandbuffer-rendering-scene-flipped-upside-down-in-forward-rendering.415922/

https://docs.unity3d.com/ScriptReference/Rendering.CommandBuffer.SetGlobalTexture.html


注:使用CommandBuffer.Blit的时候,_MainTex的传入需要手动调用CommandBuffer.SetGlobalTexture,并且Shader中的_MainTex属性设置成从外部设置(不暴露)。


阅读更多

Form 为空的问题

06-02

各位,本人是菜鸟,建了个工程测试struts登录,当点击subset时报空指针,哪位仁兄指点一下。rn[code=Java]package com.isoftstone.Test.form;rnimport javax.servlet.http.HttpServletRequest;rnimport org.apache.struts.action.ActionErrors;rnimport org.apache.struts.action.ActionMapping;rnimport org.apache.struts.validator.ValidatorForm;rnpublic class LoginForm extends ValidatorForm rn private String userName;rn private String password;rn @Override rn public void reset(ActionMapping mapping, HttpServletRequest request) rn System.out.println("--------LoginAcionForm.reset()--------"); rn rn /* (non-Javadoc) rn * @see org.apache.struts.action.ActionForm#validate(org.apache.struts.action.ActionMapping, javax.servlet.http.HttpServletRequest) rn */ rn @Override rn public ActionErrors validate(ActionMapping mapping, rn HttpServletRequest request) rn System.out.println("-----LoginAcitonForm.validate()"); rn// UserManager.getInstance().login(username, password); rn return null; rn rn rn rn public String getUserName() rn return userName;rn rn public void setUserName(String userName) rn this.userName = userName;rn rn public String getPassword() rn return password;rn rn public void setPassword(String password) rn this.password = password;rn rnrn[/code]rnrn下面是actionrn[code=Java]package com.isoftstone.Test.action;rnrnimport javax.servlet.http.HttpServletRequest;rnimport javax.servlet.http.HttpServletResponse;rnrnimport org.apache.struts.action.Action;rnimport org.apache.struts.action.ActionForm;rnimport org.apache.struts.action.ActionForward;rnimport org.apache.struts.action.ActionMapping;rnrnimport com.isoftstone.Test.dao.UserDAO;rnimport com.isoftstone.Test.form.LoginForm;rnrnpublic class LoginAction extends Actionrn rn public ActionForward execute(ActionMapping mapping, ActionForm form,rn HttpServletRequest request, HttpServletResponse response)rn LoginForm loginForm = (LoginForm)form;rn System.out.println(loginForm.getUserName());rn UserDAO dao = new UserDAO();rn if(dao.check(loginForm.getUserName()))rn return mapping.findForward("success");rn elsern return mapping.findForward("error");rn rn rnrn[/code]rnrn这是jsp页面rn[code=HTML]<%@ page language="java" pageEncoding="gb2312"%>rnrn<%@ taglib uri="http://struts.apache.org/tags-bean" prefix="bean" %>rn<%@ taglib uri="http://struts.apache.org/tags-html" prefix="html" %>rn<%@ taglib uri="http://struts.apache.org/tags-logic" prefix="logic" %>rn<%@ taglib uri="http://struts.apache.org/tags-tiles" prefix="tiles" %>rnrnrnrnrn rn rn login.jsprn rn rn rn username: rn password: rn rn rn rn rn[/code]rnrn

没有更多推荐了,返回首页