Hey. Iam learning shaders and now Iam stuck on this problem.
Iam trying to make ramp effect, but still I get this smoothed lighting.
I tried to look answers from this forum but cant find any help. Maybe it is Linux? If you spot what is wrong in this, please let me know. ![]()
Thank you!
Unity version 5.4.2
Ramp texture:
Wrap mode = Clamp
Filter mode = Point
And my shader:
// Upgrade NOTE: replaced '_World2Object' with 'unity_WorldToObject'
Shader "Unlit/test2"
{
Properties
{
_Color ("Color", Color) = (1,1,1,1)
_Float ("Value", Range(-100,100)) = 0
_MainTex ("Texture", 2D) = "white" {}
_RampTex ("Ramp", 2D) = "white" {}
}
SubShader
{
pass{
Tags{"LightMode" = "ForwardBase"}
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
float4 _Color;
float _Float;
sampler2D _RampTex;
sampler2D _MainTex;
float4 _LightColor0;
struct vertexInput{
float4 vertex : POSITION;
float3 normal : NORMAL;
float2 texcoord : TEXCOORD0;
};
struct vertexOutput{
float4 pos : SV_POSITION;
float4 col : COLOR;
float2 texcoord : TEXCOORD0;
};
vertexOutput vert(vertexInput v){
vertexOutput o;
float3 normalDirection = normalize(mul(float4(v.normal, 1), unity_WorldToObject).xyz);
float3 lightDirection;
float atten = 1.0;
lightDirection = normalize(_WorldSpaceLightPos0.xyz);
float3 diffuseReflection = atten * _LightColor0.xyz * _Color.rgb * max(0.0,dot(normalDirection, lightDirection));
float3 lightFinal = diffuseReflection + UNITY_LIGHTMODEL_AMBIENT.xyz;
lightFinal = tex2D(_RampTex, float2(lightFinal)).rgb * _LightColor0.xyz;
o.texcoord = v.texcoord;
o.col = float4((lightFinal), 1),
o.pos = mul(UNITY_MATRIX_MVP, v.vertex);
return o;
}
float4 frag(vertexOutput i) : COLOR{
fixed4 texColor = tex2D(_MainTex, i.texcoord);
return texColor * i.col;
}
ENDCG
}
}
}
