im making a mmo/open-world voxel game and are trying to optimize it as much as i can and i figured out a way but i need to make my own custom shader that has to be URP Compatible.
custom shader code:
Shader "Custom/URP/VertexColorShaderWithLighting"
{
Properties
{
_MainTex ("Texture", 2D) = "white" {}
}
SubShader
{
Tags { "RenderType"="Opaque" "Queue"="Geometry" }
LOD 100
Pass
{
Name "ForwardLit"
Tags { "LightMode"="UniversalForward" }
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"
// Texture and sampler declaration for URP
TEXTURE2D(_MainTex);
SAMPLER(sampler_MainTex);
struct Attributes
{
float4 positionOS : POSITION;
float3 normalOS : NORMAL;
float4 color : COLOR;
};
struct Varyings
{
float4 positionCS : SV_POSITION;
float4 color : COLOR;
float3 normalWS : TEXCOORD0;
float3 worldPos : TEXCOORD1;
float4 shadowCoord : TEXCOORD2; // For shadows
};
Varyings vert (Attributes IN)
{
Varyings OUT;
OUT.positionCS = TransformObjectToHClip(IN.positionOS);
OUT.worldPos = TransformObjectToWorld(IN.positionOS).xyz;
OUT.normalWS = TransformObjectToWorldNormal(IN.normalOS);
OUT.color = IN.color;
// Calculate shadow coordinates
OUT.shadowCoord = TransformWorldToShadowCoord(OUT.worldPos);
return OUT;
}
half4 frag (Varyings IN) : SV_Target
{
// Sample the vertex color
half4 color = IN.color;
// Apply simple Lambert lighting using main light direction and color
Light mainLight = GetMainLight(); // Get the main URP light
half3 lightDir = normalize(mainLight.direction);
half lambertTerm = saturate(dot(IN.normalWS, lightDir));
// Calculate shadow attenuation
half shadow = MainLightRealtimeShadow(IN.shadowCoord);
// Combine vertex color with lighting and shadow
color.rgb *= mainLight.color * lambertTerm * shadow;
return color;
}
ENDHLSL
}
}
FallBack "Diffuse"
}
i have gotten some shadow working but its not really looking how i want it to.
how its looking
i cannot add another media embed but it should look like it has depth and are not so plain.
discord: x0bscur3x

