上面这个脚本不行,挂上去物体洋红色
时间: 2023-07-08 13:50:30 浏览: 78
非常抱歉,我的代码有误。以下是经过修改的正确代码:
```
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 = float3(1, 1, 1) * f;
}
ENDCG
}
FallBack "Diffuse"
}
```
在 `surf` 函数中,我将 `o.Emission` 的颜色设为固定的白色,这样高光就不会被着色器误解释为物体的颜色。请将此脚本保存为highlight.shader并附加到您要使用高光闪烁效果的材质上。
阅读全文