这篇文章主要讲解了Unity3D Shader实现镜子效果的方法,内容清晰明了,对此有兴趣的小伙伴可以学习一下,相信大家阅读完之后会有帮助。

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.0struct 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 initializationvoid Start () { InvokeRepeating("change", 1, 0.1f); curmat = gameObject.GetComponent<Renderer>().material; if (curmat == null) { Debug.Log("cw"); } } // Update is called once per framevoid Update () { } void change() { cam.transform.rotation = Quaternion.identity; cam.RenderToCubemap(cubeMap); curmat.SetTexture("_Cubemap",cubeMap); } }

看完上述内容,是不是对Unity3D Shader实现镜子效果的方法有进一步的了解,如果还想学习更多内容,欢迎关注亿速云行业资讯频道。