unity3d shader实现镜子效果-kb88凯时官网登录

时间:2020-05-04
阅读:
免费资源网,https://freexyz.cn/

本文实例为大家分享了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().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://freexyz.cn/
返回顶部
顶部
网站地图