test: add vulkan renderer scene coverage

This commit is contained in:
2026-04-02 04:00:58 +08:00
parent 4c167bec0e
commit 7404108a4b
21 changed files with 258 additions and 14 deletions

View File

@@ -160,6 +160,65 @@ void main() {
}
)";
const char kBuiltinForwardVulkanVertexShader[] = R"(#version 450
layout(location = 0) in vec3 aPosition;
layout(location = 1) in vec3 aNormal;
layout(location = 2) in vec2 aTexCoord;
layout(set = 1, binding = 0, std140) uniform PerObjectConstants {
mat4 gProjectionMatrix;
mat4 gViewMatrix;
mat4 gModelMatrix;
mat4 gNormalMatrix;
vec4 gMainLightDirectionAndIntensity;
vec4 gMainLightColorAndFlags;
};
layout(location = 0) out vec3 vNormalWS;
layout(location = 1) out vec2 vTexCoord;
void main() {
vec4 positionWS = gModelMatrix * vec4(aPosition, 1.0);
vec4 positionVS = gViewMatrix * positionWS;
gl_Position = gProjectionMatrix * positionVS;
vNormalWS = mat3(gNormalMatrix) * aNormal;
vTexCoord = aTexCoord;
}
)";
const char kBuiltinForwardVulkanFragmentShader[] = R"(#version 450
layout(set = 2, binding = 0) uniform texture2D uBaseColorTexture;
layout(set = 3, binding = 0) uniform sampler uLinearSampler;
layout(set = 1, binding = 0, std140) uniform PerObjectConstants {
mat4 gProjectionMatrix;
mat4 gViewMatrix;
mat4 gModelMatrix;
mat4 gNormalMatrix;
vec4 gMainLightDirectionAndIntensity;
vec4 gMainLightColorAndFlags;
};
layout(location = 0) in vec3 vNormalWS;
layout(location = 1) in vec2 vTexCoord;
layout(location = 0) out vec4 fragColor;
void main() {
vec4 baseColor = texture(sampler2D(uBaseColorTexture, uLinearSampler), vTexCoord);
if (gMainLightColorAndFlags.w < 0.5) {
fragColor = baseColor;
return;
}
vec3 normalWS = normalize(vNormalWS);
vec3 directionToLightWS = normalize(gMainLightDirectionAndIntensity.xyz);
float diffuse = max(dot(normalWS, directionToLightWS), 0.0);
vec3 lighting = vec3(0.28) +
gMainLightColorAndFlags.rgb * (diffuse * gMainLightDirectionAndIntensity.w);
fragColor = vec4(baseColor.rgb * lighting, baseColor.a);
}
)";
RHI::GraphicsPipelineDesc CreatePipelineDesc(
RHI::RHIType backendType,
RHI::RHIPipelineLayout* pipelineLayout,
@@ -189,6 +248,18 @@ RHI::GraphicsPipelineDesc CreatePipelineDesc(
pipelineDesc.fragmentShader.sourceLanguage = RHI::ShaderLanguage::HLSL;
pipelineDesc.fragmentShader.entryPoint = L"MainPS";
pipelineDesc.fragmentShader.profile = L"ps_5_0";
} else if (backendType == RHI::RHIType::Vulkan) {
pipelineDesc.vertexShader.source.assign(
kBuiltinForwardVulkanVertexShader,
kBuiltinForwardVulkanVertexShader + std::strlen(kBuiltinForwardVulkanVertexShader));
pipelineDesc.vertexShader.sourceLanguage = RHI::ShaderLanguage::GLSL;
pipelineDesc.vertexShader.profile = L"vs_4_50";
pipelineDesc.fragmentShader.source.assign(
kBuiltinForwardVulkanFragmentShader,
kBuiltinForwardVulkanFragmentShader + std::strlen(kBuiltinForwardVulkanFragmentShader));
pipelineDesc.fragmentShader.sourceLanguage = RHI::ShaderLanguage::GLSL;
pipelineDesc.fragmentShader.profile = L"fs_4_50";
} else {
pipelineDesc.vertexShader.source.assign(
kBuiltinForwardVertexShader,