69 lines
1.8 KiB
Plaintext
69 lines
1.8 KiB
Plaintext
import Bindless;
|
|
|
|
struct VertexOut {
|
|
float4 outPosition : SV_Position;
|
|
float4 screenPosition : ScreenPosition;
|
|
float4 normal : CoarseNormal;
|
|
float2 texCoord0 : TexCoord0;
|
|
float2 texCoord1 : TexCoord1;
|
|
float4 vertexColor0 : VertexColor;
|
|
};
|
|
|
|
struct CameraData {
|
|
float4x4 view;
|
|
float4x4 proj;
|
|
};
|
|
|
|
uniform ParameterBlock<CameraData> camera;
|
|
|
|
struct PerInstanceData {
|
|
float4x4 transform;
|
|
Sampler2D.RID textureID;
|
|
uint _padding;
|
|
float metallic;
|
|
float roughness;
|
|
float4 baseColor;
|
|
}
|
|
|
|
[[vk::push_constant]]
|
|
uniform ConstantBuffer<PerInstanceData> pcb;
|
|
|
|
[shader("vertex")]
|
|
VertexOut VertexMain(
|
|
uint vertexId: SV_VertexID,
|
|
float3 position,
|
|
float3 normal,
|
|
float2 texCoord0,
|
|
float2 texCoord1,
|
|
float4 vertexColor0,
|
|
) {
|
|
VertexOut output;
|
|
output.outPosition = mul(camera.proj, mul(camera.view, mul(pcb.transform, float4(position, 1.0f))));
|
|
output.screenPosition = mul(camera.proj, mul(camera.view, mul(pcb.transform, float4(position, 1.0f))));
|
|
output.normal = mul(pcb.transform, float4(normalize(normal.rgb), 0.0f));
|
|
output.texCoord0 = texCoord0;
|
|
output.texCoord1 = texCoord1;
|
|
output.vertexColor0 = vertexColor0;
|
|
return output;
|
|
}
|
|
|
|
[shader("fragment")]
|
|
float4 FragmentMain(
|
|
float4 interpolatePosition : ScreenPosition,
|
|
float4 interpolatedNormal : CoarseNormal,
|
|
float2 uv0 : TexCoord0,
|
|
float2 uv1 : TexCoord1,
|
|
float4 interpolatedColor : VertexColor,
|
|
) : SV_Target0 {
|
|
|
|
let N = interpolatedNormal.xyz;
|
|
let L = dot(normalize(N), float3(1.0f, 1.0f, -1.0f));
|
|
|
|
if (let texture = pcb.textureID) {
|
|
return float4(texture.Sample(uv0).rgb, 1.0f) * pcb.baseColor * interpolatedColor * L;
|
|
} else {
|
|
return pcb.baseColor * interpolatedColor * L;
|
|
}
|
|
}
|
|
|