rendering: migrate object id shader to unity-style single source

This commit is contained in:
2026-04-07 00:38:00 +08:00
parent 87533e08f6
commit 998df9013a
2 changed files with 44 additions and 19 deletions

View File

@@ -6,16 +6,44 @@ Shader "Builtin Object Id"
{
Name "ObjectId"
Tags { "LightMode" = "ObjectId" }
Resources
{
PerObjectConstants (ConstantBuffer, 0, 0) [Semantic(PerObject)]
}
Cull Back
ZWrite On
ZTest LEqual
HLSLPROGRAM
#pragma target 4.5
#pragma vertex MainVS
#pragma fragment MainPS
#pragma backend D3D12 HLSL "object-id.vs.hlsl" "object-id.ps.hlsl" vs_5_0 ps_5_0
#pragma backend OpenGL GLSL "object-id.vert.glsl" "object-id.frag.glsl"
#pragma backend Vulkan GLSL "object-id.vert.vk.glsl" "object-id.frag.vk.glsl"
cbuffer PerObjectConstants : register(b0)
{
float4x4 gProjectionMatrix;
float4x4 gViewMatrix;
float4x4 gModelMatrix;
float4 gObjectIdColor;
};
struct VSInput
{
float3 position : POSITION;
};
struct PSInput
{
float4 position : SV_POSITION;
};
PSInput MainVS(VSInput input)
{
PSInput output;
const float4 positionWS = mul(gModelMatrix, float4(input.position, 1.0));
const float4 positionVS = mul(gViewMatrix, positionWS);
output.position = mul(gProjectionMatrix, positionVS);
return output;
}
float4 MainPS(PSInput input) : SV_TARGET
{
return gObjectIdColor;
}
ENDHLSL
}
}