亲宝软件园·资讯

展开

Unity3D Shader镜子 Unity3D Shader实现镜子效果

忘夕 人气:0

/p>

Shader部分代码:

Shader "Custom/FanShe" {
Properties{
_MainTex("Albedo",2D) = "white"{}
_MainTint("Diffuse Color",Color)=(1,1,1,1)
_Cubemap("Cubemap",CUBE) = ""{}
_ReflAmount("Reflection Amount",Range(0.1,1.0))=0.5
}
SubShader{
Tags{"RenderType"="Opaque"}
LOD 200
 
 
CGPROGRAM
#pragma surface surf Lambert
#pragma target 3.0
struct Input {
float2 uv_MainTex;
float3 worldRefl;
};
sampler2D _MainTex;
samplerCUBE _Cubemap;
fixed4 _MainTint;
half _ReflAmount;
void surf(Input IN, inout SurfaceOutput o)
{
fixed4 c = tex2D(_MainTex, IN.uv_MainTex)*_MainTint;
o.Albedo = c.rgb;
o.Emission = texCUBE(_Cubemap, IN.worldRefl)*_ReflAmount;
o.Alpha = c.a;
}
ENDCG
}
 
FallBack "Diffuse"
 
}

C#部分代码:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
 
 
public class Shader_FanShe : MonoBehaviour {
  public Cubemap cubeMap;
  public Camera cam;
  Material curmat;
// Use this for initialization
void Start () {
    InvokeRepeating("change", 1, 0.1f);
    curmat = gameObject.GetComponent<Renderer>().material;
    if (curmat == null)
    {
      Debug.Log("cw");
    }
    
}
 
// Update is called once per frame
void Update () {
 
}
  void change()
  {
    cam.transform.rotation = Quaternion.identity;
    cam.RenderToCubemap(cubeMap);
    curmat.SetTexture("_Cubemap",cubeMap);
  }
 
}

加载全部内容

相关教程
猜你喜欢
用户评论