美文网首页Unity Shader分享
3D打印机shader特效简单实现(转)

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

作者: 树上的cat_ee3c | 来源:发表于2017-10-16 08:40 被阅读24次

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

[html]view plaincopy

print?

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 200

Cull 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;

floats= +sin((IN.worldPos.x * IN.worldPos.z) * 60 + _Time[3] + o.Normal) / 120;

if(IN.worldPos.y>_ConstructY)

{

fixed4c=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#的控制部分代码:

[html]view plaincopy

print?

using UnityEngine;

using System.Collections;

public class _3Dprinter : MonoBehaviour

{

private Material mat;

public floattimer=0;

public floatvalue=1;

void Start()

{

mat=GetComponent().material;

}

void Update()

{

timer += Time.deltaTime;

if (timer>0.1f)

{

if (value<= 3)

{

mat.SetFloat("_ConstructY", value += 0.05f);

timer=0;

}

}

}

}

相关文章

网友评论

    本文标题:3D打印机shader特效简单实现(转)

    本文链接:https://www.haomeiwen.com/subject/ifahuxtx.html