帮我在unity中写一个shader脚本,使用后物体高光闪烁效果
时间: 2024-03-22 16:42:52 浏览: 142
Unity用shader实现高亮
5星 · 资源好评率100%
好的,以下是一个简单的高光闪烁shader脚本:
```
Shader "Custom/Highlight" {
Properties {
_MainTex ("Texture", 2D) = "white" {}
_Color ("Color", Color) = (1,1,1,1)
_Shininess ("Shininess", Float) = 50
_Gloss ("Gloss", Range(0, 1)) = 1
_Frequency ("Frequency", Range(0, 5)) = 1.5
_Speed ("Speed", Range(0, 5)) = 1.5
}
SubShader {
Tags { "RenderType"="Opaque" }
LOD 100
CGPROGRAM
#pragma surface surf Standard
sampler2D _MainTex;
float4 _Color;
float _Shininess;
float _Gloss;
float _Frequency;
float _Speed;
struct Input {
float2 uv_MainTex;
};
void surf (Input IN, inout SurfaceOutputStandard o) {
float4 c = tex2D (_MainTex, IN.uv_MainTex) * _Color;
o.Albedo = c.rgb;
o.Metallic = 0;
o.Smoothness = pow(_Shininess/100, 2);
o.Alpha = c.a;
float t = _Time.y * _Speed;
float f = sin(IN.uv_MainTex.x * _Frequency + t) * sin(IN.uv_MainTex.y * _Frequency + t);
f = pow(f * _Gloss + 1 - _Gloss, 2);
o.Emission = c.rgb * f;
}
ENDCG
}
FallBack "Diffuse"
}
```
将此脚本保存为highlight.shader,并将其附加到您希望使用高光闪烁效果的材质上。通过调整属性来改变高光的颜色、频率和速度。
阅读全文