shader代码如下
Shader "Custom/insidevisible" {
Properties{
_MainTex("Base (RGB)", 2D) = "white" {}
}
SubShader{
Tags { "RenderType" = "Opaque" }
Cull front // ADDED BY BERNIE, TO FLIP THE SURFACES
LOD 100
Pass {
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"
struct appdata_t {
float4 vertex : POSITION;
float2 texcoord : TEXCOORD0;
};
struct v2f {
float4 vertex : SV_POSITION;
half2 texcoord : TEXCOORD0;
};
sampler2D _MainTex;
float4 _MainTex_ST;
v2f vert(appdata_t v)
{
v2f o;
o.vertex = UnityObjectToClipPos(v.vertex);
// ADDED BY BERNIE:
v.texcoord.x = 1 - v.texcoord.x;
o.texcoord = TRANSFORM_TEX(v.texcoord, _MainTex);
return o;
}
fixed4 frag(v2f i) : SV_Target
{
fixed4 col = tex2D(_MainTex, i.texcoord);
return col;
}
ENDCG
}
}
}
控制摄像机得代码
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class camcon : MonoBehaviour {
private bool isrotate;
float rotX = 0;
float rotY = 0;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
if (Input.GetMouseButtonDown(0))
{
isrotate = true;
}
if (Input.GetMouseButtonUp(0))
{
isrotate = false;
}
if (isrotate)
{
float h = Input.GetAxis("Mouse X");
rotX += h;
transform.localEulerAngles = new Vector3(transform.localEulerAngles.x, rotX, 0);
float v = Input.GetAxis("Mouse Y");
rotY += v;
rotY = Mathf.Clamp(rotY, -30, 30);//限制摄像机上下旋转得角度
transform.localEulerAngles = new Vector3(rotY, transform.localEulerAngles.y, 0);
}
}
}
接着需要创建一个sphere 球,和一个材质球,材质球得着色器使用上面写的shader,然后需要 让摄像机得位置和球得位置保持一致即可。