【问题标题】:Draw RenderTexture on screen in Unity3D在 Unity3D 中的屏幕上绘制 RenderTexture
【发布时间】:2017-05-18 11:43:55
【问题描述】:

请问,有什么问题吗?在编辑器中很好,但在 Galaxy S6 上我只有黑屏。

RenderTexture texture;

void Start () {
    texture = new RenderTexture (800, 480, 24);
    RenderTexture.active = texture;
}

void Update () {
}

void OnPreRender(){
    Camera.main.targetTexture = texture;
}

void OnPostRender() {
    Camera.main.targetTexture = null;
    Graphics.DrawTexture (new Rect (0, 0, Screen.width, Screen.height), texture);
}

【问题讨论】:

标签: android unity3d unityscript


【解决方案1】:

这是 Unity 的一个已知问题。您可以在以下位置找到更多详细信息:

https://forum.unity3d.com/threads/rendertexture-not-working-on-ios-and-android-unity-4-2-0f4.192561/

https://forum.unity3d.com/threads/render-texture-not-working-on-device-unity-5-2-1f1.358483/

https://forum.unity3d.com/threads/render-texture-works-in-editor-but-not-on-devices-after-upgrade-to-unity-5.362397/

还有一些其他的,版主和工作人员声称它已在未来的版本中得到修复,或者(带有一点不必要的傲慢)问题出在用户身上,并且根本不存在错误。

但是

这听起来很傻,但是在主摄像头上添加一个 ImageEffect。我制作了一个附加到我的主相机的虚拟效果,没有任何合乎逻辑的解释,它修复了移动设备上的 RenderTexture。

DummyEffect.cs:

using UnityEngine;

[ExecuteInEditMode]
[AddComponentMenu("Image Effects/Dummy Effect")]
public class DummyEffect : ImageEffectBase {

    // Called by camera to apply image effect
    void OnRenderImage (RenderTexture source, RenderTexture destination) {
        Graphics.Blit (source, destination, material);
    }
}

DummyEffect.shader:

Shader "Hidden/Dummy Effect" {
Properties {
    _MainTex ("Base (RGB)", RECT) = "white" {}
}

SubShader {
    Pass {
        ZTest Always Cull Off ZWrite Off
        Fog { Mode off }

CGPROGRAM
#pragma vertex vert_img
#pragma fragment frag
#pragma fragmentoption ARB_precision_hint_fastest
#include "UnityCG.cginc"

uniform sampler2D _MainTex;

float4 frag (v2f_img i) : COLOR {
    return tex2D(_MainTex, i.uv);
}
ENDCG

    }
}

Fallback off

}

【讨论】:

  • 您仍然可以指定一个先前制作的 RenderTexture 来代替两条创建线。我创建了一个新的,以消除 RenderTexture 本身是一个问题的可能性。
  • 您找到解决方案了吗?我有同样的问题
  • 你回复了。
【解决方案2】:

您不应该为此使用主摄像头。只需添加一个额外的,即可渲染纹理。

【讨论】:

    猜你喜欢
    • 2017-10-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-03-03
    • 2010-09-25
    • 1970-01-01
    相关资源
    最近更新 更多