本文实例为大家分享了Unity3D Shader实现镜子效果的具体代码,供大家参考,具体内容如下/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);
}
}
您可能感兴趣的文章:unity实现玻璃效果unity shader实现玻璃折射效果Unity Shader实现玻璃材质效果