欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

Unity3D Shader实现镜子效果

程序员文章站 2022-11-19 19:12:08
本文实例为大家分享了unity3d shader实现镜子效果的具体代码,供大家参考,具体内容如下/p>shader部分代码:shader "custom/fanshe" {properties{...

本文实例为大家分享了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实现镜子效果

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。