I write a urp shader, step the N Dot L, but result have aliasing.
How to smooth the ramp with smoothstep function and not use FXAA like?
This my code
Shader "test"
{
Properties
{
_Step ("_Step", Float) = 2
}
SubShader
{
Tags { "RenderType"="Opaque" "RenderPipeline"="UniversalRenderPipeline" "Queue"="Geometry"}
Pass
{
HLSLPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Lighting.hlsl"
struct Attributes
{
float4 positionOS : POSITION;
float3 normalOS : NORMAL;
};
struct Varyings
{
float4 positionHCS : SV_POSITION;
float3 normalWS : TEXCOORD0;
float3 viewWS : TEXCOORD1;
};
CBUFFER_START(UnityPerMaterial)
half _Step;
CBUFFER_END
Varyings vert(Attributes IN)
{
Varyings OUT;
float3 positionWS = TransformObjectToWorld(IN.positionOS.xyz);
OUT.positionHCS = TransformWorldToHClip(positionWS);
OUT.normalWS = TransformObjectToWorldNormal(IN.normalOS);
OUT.viewWS = GetWorldSpaceViewDir(positionWS);
return OUT;
}
half4 frag(Varyings IN) : SV_Target
{
Light light = GetMainLight();
half3 lightColor = light.color * light.distanceAttenuation;
half3 normalWS = normalize(IN.normalWS);
half3 viewWS = SafeNormalize(IN.viewWS);
half NdotL = saturate(dot(normalWS, light.direction));
half ramp = ceil(NdotL * 3) / 3;
half4 totalColor = half4(ramp.xxx,1);
return totalColor;
}
ENDHLSL
}
}
}
But result have Aliasing