我正在尝试制作360渲染纹理。在游戏处于游戏模式时,一个牧羊人模型向我们展示了渲染的内容。我不想录制视频。就像2D渲染纹理一样显示。
我正在使用此着色器:
Shader “Unlit/Pano360Shader”
{
Properties
{
_MainTex (“Base (RGB)”, 2D) = “white” {}
_Color (“Main Color”, Color) = (1,1,1,0.5)
}
SubShader
{
Tags { “RenderType” = “Opaque” }
//This is used to print the texture inside of the sphere
Cull Front
CGPROGRAM
#pragma surface surf SimpleLambert
half4 LightingSimpleLambert (SurfaceOutput s, half3 lightDir, half atten)
{
half4 c;
c.rgb = s.Albedo;
return c;
}
sampler2D _MainTex;
struct Input
{
float2 uv_MainTex;
float4 myColor : COLOR;
};
fixed3 _Color;
void surf (Input IN, inout SurfaceOutput o)
{
//This is used to mirror the image correctly when printing it inside of the sphere
IN.uv_MainTex.x = 1 — IN.uv_MainTex.x;
fixed3 result = tex2D(_MainTex, IN.uv_MainTex)*_Color;
o.Albedo = result.rgb;
o.Alpha = 1;
}
ENDCG
}
Fallback “Diffuse”
}
正在工作,但只显示照片。当我尝试渲染纹理时,它什么也没显示。 如何在Unity中创建360渲染纹理?
答案 0 :(得分:0)
Unity相机可以渲染为立方体贴图纹理。不需要自定义着色器。
您需要创建一个渲染纹理,将其设置为cubemap:
并在相机上创建一个简单的脚本:
public class RenderCameraToCubemap : Monobehaviour {
public RenderTexture rt;
void LateUpdate() {
GetComponent<Camera>().RenderToCubemap(rt);
}
}
警告:不会呈现UI(已知错误)。
答案 1 :(得分:0)
我这样解决我的问题;
这是相机代码;
public RenderTexture cubemapLeft;
public RenderTexture cubemapRight;
public RenderTexture equirect;
public bool renderStereo = true;
public float stereoSeparation = 0.064f;
void LateUpdate()
{
Camera cam = GetComponent<Camera>();
if (cam == null)
{
cam = GetComponentInParent<Camera>();
}
if (cam == null)
{
Debug.Log("stereo 360 capture node has no camera or parent camera");
}
if (renderStereo)
{
cam.stereoSeparation = stereoSeparation;
cam.RenderToCubemap(cubemapLeft, 63, Camera.MonoOrStereoscopicEye.Left);
cam.RenderToCubemap(cubemapRight, 63, Camera.MonoOrStereoscopicEye.Right);
}
else
{
cam.RenderToCubemap(cubemapLeft, 63, Camera.MonoOrStereoscopicEye.Mono);
}
//optional: convert cubemaps to equirect
if (equirect == null)
{
return;
}
if (renderStereo)
{
cubemapLeft.ConvertToEquirect(equirect, Camera.MonoOrStereoscopicEye.Left);
cubemapRight.ConvertToEquirect(equirect, Camera.MonoOrStereoscopicEye.Right);
}
else
{
cubemapLeft.ConvertToEquirect(equirect, Camera.MonoOrStereoscopicEye.Mono);
}
}
这是代码:
public RenderTexture rt;
public Renderer renderer;
// Use this for initialization
void Start () {
renderer = this.GetComponent<Renderer>();
renderer.material.SetTexture("_MainTex", rt);
}
相机脚本具有左眼和右眼。使用渲染器纹理类型的“多维数据集”和“相机”脚本的值名称等于。将其用于2D渲染器纹理。并为Shephere脚本使用2D渲染器纹理。而牧羊犬的耕作值必须为x:1 y:0.5
这是我的解决方案。 我没有写这些代码。