2015-12-12 58 views
1

我試圖做到這一點看在我的統一遊戲:如何淡化着色器程序中的顏色?

enter image description here

我喜歡山的顏色如何得到隨着海拔高度的增加較輕。

我對遊戲開發還不熟悉,雖然我明白着色器的作用,但我在實踐中嘗試使用它們時遇到了麻煩。

我知道我需要做這樣的事情在我的表面材質:

float4 mountainColor = lerp(_BottomColor,_TopColor,IN.vertex.z); 

...到較深的顏色,並基於z值較亮的顏色之間的線性插值。

但我不確定如何務實地減輕着色器中的顏色。我不使用頂點顏色,顏色來自紋理。任何幫助/指針將不勝感激。

編輯:

所以,咄,我意識到我只需要乘以RGB值要麼變亮或變暗它。

的問題是,如果我只是做這樣的事情:

o.Albedo = c.rgb * 1.5; 

...是的,它減輕了它,但它也略有改變色調和變得過於飽和。

我該如何解決這個問題?

回答

0

這裏是我的代碼:

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" 
} 

它適合我的需求不夠好。我將不得不繼續撥弄它以獲得我想要的確切外觀,但基地在這裏。

+0

這是爲了回答你自己的問題嗎?如果不是,則應該將其編輯到您的問題中。 – AquaGeneral

+0

@AquaGeneral是的,這是我的答案。 –