97干视频,99国产精品懂色,亚洲精品99久久久久中文字幕,伊人五月丁香综合AⅤ,国产精品成人免费999

當前位置: 移動互聯(lián)網(wǎng)學院 > VR開發(fā) > Unity3D實現(xiàn)全景圖
Unity3D實現(xiàn)全景圖 時間:2017-05-11     來源:移動互聯(lián)網(wǎng)學院

全景圖是我們非常實用的場景,會增加顯示的場景效果,現(xiàn)在我們就來查看全景圖的添加方法。

首先 我們準備一張全景圖圖片。 這個圖片怎么做的呢, 這個要問你們的美術了,他們會做的的。 我本來想給準備一張, 奈何, 蠻牛上圖大小限制, 我沒辦法上傳了。 

然后呢 ,我們在場景中創(chuàng)建一個 球體。 

然后再創(chuàng)建一個空的物體 ,名字你隨便起,我就起了個很長的名字, 畢竟一寸長一寸強

第三部,我們就要把一個攝像機放在這個 新建的空的物體里面,作為子物體。

然后 把 球體, 攝像機, 和這個空的物體 都reset 下 位置, 也就是位置都是 0,0,0  

這樣 攝像機就在球體里面了。

下面就是寫腳本和shader了 

[code]phpcode:

01 Shader "Unlit/Pano360Shader"

02 {

03    Properties

04 {

05    _MainTex("Base(RGB)", 2D) = "white"{}

06    _Color("Main Color", Color) = (1,1,1,0.5)

07 }

08 SubShader

09 {

10    Tags{ "RenderType" = "Opaque" }

11    //This is used to print the texture inside of the sphere

12    Cull Front

13    CGPROGRAM

14 #pragma surface surf SimpleLambert

15    half4 LightingSimpleLambert(SurfaceOutput s, half3 lightDir, half atten)

16 {

17    half4 c;

18    c.rgb = s.Albedo;

19    return c;

20 }

21

22 sampler2D _MainTex;

23 struct Input

24 {

25    float2 uv_MainTex;

26    float4 myColor : COLOR;

27 };

28

29 fixed3 _Color;

30 void surf(Input IN, inout SurfaceOutput o)

31 {

32    //This is used to mirror the image correctly when printing it inside of the sphere

33    IN.uv_MainTex.x= 1-IN.uv_MainTex.x;

34    fixed3 result = tex2D(_MainTex,IN.uv_MainTex)*_Color;

35    o.Albedo = result.rgb;

36    o.Alpha = 1;

37 }

38 ENDCG

39 }

40 Fallback "Diffuse"

41 }

這個shader 意思就是把圖片做一個翻轉(zhuǎn) ,這樣在球體內(nèi)部看到圖片也是正的。 

下面寫一個控制攝像機旋轉(zhuǎn)腳本

[code]csharpcode:

01 using UnityEngine;

02 using System.Collections;

03

04 public class Move : MonoBehaviour {

05

06    // Use this for initialization

07    void Start () {

08     

09    }

10     

11    // Update is called once per frame

12    void Update () {

13     

14        if(Input.GetKey(KeyCode.A))

15        {

16            transform.Rotate(new Vector3(0,1,0));

17        }

18        if (Input.GetKey(KeyCode.D))

19        {

20            transform.Rotate(new Vector3(0, -1, 0));

21        }

22    }

23 }