3D打印机shader特效简单实现

来源:互联网 发布:java简单售票系统 编辑:程序博客网 时间:2024/04/30 00:01

原文链接 : http://www.manew.com/thread-97539-1-1.html





Shader "Custom/3Dprinter" {Properties {_Color("Color", Color) = (1, 1, 1, 1)_MainTex("Adbedo(RGB)", 2D) = "white" {}_Glossiness("Smoothness", Range(0, 1)) = 0.5_Metallic("Metallic", Range(0, 1)) = 0.0_ConstructY("constructY", float) = 0_ConstructGap("constructGap", float) = 1_ConstructColor("constructColor", Color) = (0.5, 0.5, 0.5, 0.5)}SubShader {Tags { "RenderType"="Opaque" }LOD 200Cull Off CGPROGRAM#pragma surface surf Standard fullforwardshadows#pragma target 3.0 sampler2D _MainTex;float _ConstructY;fixed4 _ConstructColor;float _ConstructGap;float3 viewDir;int building;half _Glossiness;half _Metallic;fixed4 _Color;struct Input{float2 uv_MainTex;float3 worldPos;float3 viewDir;};void surf(Input IN, inout SurfaceOutputStandard o){viewDir = IN.viewDir;float s = +sin((IN.worldPos.x * IN.worldPos.z) * 60 + _Time[3] + o.Normal) / 120;if(IN.worldPos.y > _ConstructY){fixed4 c = tex2D(_MainTex, IN.uv_MainTex) * _Color;o.Albedo = c.rgb;o.Alpha = c.a;building = 0;}else {o.Albedo = _ConstructColor.rgb;o.Alpha = _ConstructColor.a;building = 1;}o.Metallic = _Metallic;o.Smoothness = _Glossiness;}//inline void LightingCustom_GI(SurfaceOutputStandard s, UnityGIInput  data, inout UniI gi)//{//LightingStandard_GI(s, data, gi);//} inline void LightingCustom_GI(SurfaceOutputStandard s, UnityGIInput data,inout UnityGI gi) {            LightingStandard_GI(s,data,gi);        }inline half4 LightingCustom(SurfaceOutputStandard s, half3 lightDir, UnityGI gi){if(building)return _ConstructColor;if(dot(s.Normal, viewDir) > 0)return _ConstructColor;return LightingStandard(s, lightDir, gi);}ENDCG }FallBack "Diffuse"}



c#的控制部分代码:

using UnityEngine;using System.Collections;public class _3Dprinter : MonoBehaviour {    private Material mat;    public float timer = 0;    public float value = 1;    void Start()    {        mat = GetComponent<MeshRenderer>().material;    }    void Update()    {        timer += Time.deltaTime;        if (timer > 0.1f)        {            if (value <= 3)            {                mat.SetFloat("_ConstructY", value += 0.05f);                timer = 0;            }        }    }}




0 0