Unity3d 如何在着色器程序中使颜色变亮?
我试图在我的Unity游戏中实现这种外观: 我喜欢山的颜色随着海拔的升高而变浅 我对游戏开发还是新手,虽然我了解着色器的功能,但在实践中使用它们时遇到了困难 我知道我需要在我的曲面着色器中执行以下操作:Unity3d 如何在着色器程序中使颜色变亮?,unity3d,shader,Unity3d,Shader,我试图在我的Unity游戏中实现这种外观: 我喜欢山的颜色随着海拔的升高而变浅 我对游戏开发还是新手,虽然我了解着色器的功能,但在实践中使用它们时遇到了困难 我知道我需要在我的曲面着色器中执行以下操作: float4 mountainColor = lerp(_BottomColor,_TopColor,IN.vertex.z); …根据z值在较深颜色和较浅颜色之间进行lerp 但我不知道如何在着色器中实际地使颜色变亮。我没有使用顶点颜色,颜色来自纹理。如有任何帮助/建议,将不胜感激 编辑:
float4 mountainColor = lerp(_BottomColor,_TopColor,IN.vertex.z);
…根据z值在较深颜色和较浅颜色之间进行lerp
但我不知道如何在着色器中实际地使颜色变亮。我没有使用顶点颜色,颜色来自纹理。如有任何帮助/建议,将不胜感激
编辑:
所以,duh,我意识到我只需要乘以rgb值就可以使它变亮或变暗
问题是,如果我只是这样做:
o.Albedo = c.rgb * 1.5;
。。。是的,它会使它变亮,但它也会稍微改变色调,变得过度饱和
如何修复此问题?以下是我的代码:
Shader "Custom/Altitude Gradient" {
Properties {
_Color ("Color", Color) = (1,1,1,1)
_MainTex ("Albedo (RGB)", 2D) = "white" {}
_Glossiness ("Smoothness", Range(0,1)) = 0.5
_Metallic ("Metallic", Range(0,1)) = 0.0
}
SubShader {
Tags { "RenderType"="Opaque" }
LOD 200
CGPROGRAM
// Physically based Standard lighting model, and enable shadows on all light types
#pragma surface surf Standard fullforwardshadows vertex:vert
// Use shader model 3.0 target, to get nicer looking lighting
#pragma target 3.0
sampler2D _MainTex;
struct Input {
float2 uv_MainTex;
float3 localPos;
};
half _Glossiness;
half _Metallic;
fixed4 _Color;
void vert(inout appdata_full v, out Input o) {
UNITY_INITIALIZE_OUTPUT(Input, o);
o.localPos = v.vertex.xyz;
}
void surf (Input IN, inout SurfaceOutputStandard o) {
// Albedo comes from a texture tinted by color
fixed4 c = tex2D (_MainTex, IN.uv_MainTex) * _Color;
o.Albedo = lerp(c.rgb * 0.5, 1, IN.localPos.y);
// Metallic and smoothness come from slider variables
o.Metallic = _Metallic;
o.Smoothness = _Glossiness;
o.Alpha = c.a;
}
ENDCG
}
FallBack "Diffuse"
}
它能满足我的需要。我将不得不继续摆弄它以获得我想要的准确外观,但底部在这里。这是为了回答您自己的问题吗?如果没有,应该编辑成你的问题。@A是的,这是我的答案。