软件编程
位置:首页>> 软件编程>> C#编程>> Unity3D Shader实现镜子效果

Unity3D Shader实现镜子效果

作者:忘夕  发布时间:2023-03-17 04:16:07 

标签:Unity3D,Shader,镜子

本文实例为大家分享了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);
 }

}

Unity3D Shader实现镜子效果

来源:https://blog.csdn.net/weixin_42452001/article/details/80681147

0
投稿

猜你喜欢

手机版 软件编程 asp之家 www.aspxhome.com