Add shaders re-implemented in HLSL

These were written against the shaders at revision eddd724e7.
There have been changes made since then, which will need to be mirrored.

See `data/hlsl/README.md` for the current status of each sample.
This commit is contained in:
Ben Clayton 2020-05-21 10:20:19 +00:00
parent 10a1ecaf7b
commit cce75f1859
287 changed files with 11263 additions and 0 deletions

View file

@ -0,0 +1,35 @@
// Copyright 2020 Google LLC
[[vk::input_attachment_index(0)]][[vk::binding(0)]] SubpassInput inputColor;
[[vk::input_attachment_index(1)]][[vk::binding(1)]] SubpassInput inputDepth;
struct UBO {
float2 brightnessContrast;
float2 range;
int attachmentIndex;
};
cbuffer ubo : register(b2) { UBO ubo; }
float3 brightnessContrast(float3 color, float brightness, float contrast) {
return (color - 0.5) * contrast + 0.5 + brightness;
}
float4 main() : SV_TARGET
{
// Apply brightness and contrast filer to color input
if (ubo.attachmentIndex == 0) {
// Read color from previous color input attachment
float3 color = inputColor.SubpassLoad().rgb;
return float4(brightnessContrast(color, ubo.brightnessContrast[0], ubo.brightnessContrast[1]), 1);
}
// Visualize depth input range
if (ubo.attachmentIndex == 1) {
// Read depth from previous depth input attachment
float depth = inputDepth.SubpassLoad().r;
return float4((depth - ubo.range[0]) * 1.0 / (ubo.range[1] - ubo.range[0]).xxx, 1);
}
return 0.xxxx;
}

View file

@ -0,0 +1,6 @@
// Copyright 2020 Google LLC
float4 main(uint VertexIndex : SV_VertexID) : SV_POSITION
{
return float4(float2((VertexIndex << 1) & 2, VertexIndex & 2) * 2.0f - 1.0f, 0.0f, 1.0f);
}

View file

@ -0,0 +1,24 @@
// Copyright 2020 Google LLC
struct VSOutput
{
[[vk::location(0)]] float3 Color : COLOR0;
[[vk::location(1)]] float3 Normal : NORMAL0;
[[vk::location(2)]] float3 ViewVec : TEXCOORD1;
[[vk::location(3)]] float3 LightVec : TEXCOORD2;
};
float4 main(VSOutput input) : SV_TARGET
{
// Toon shading color attachment output
float intensity = dot(normalize(input.Normal), normalize(input.LightVec));
float shade = 1.0;
shade = intensity < 0.5 ? 0.75 : shade;
shade = intensity < 0.35 ? 0.6 : shade;
shade = intensity < 0.25 ? 0.5 : shade;
shade = intensity < 0.1 ? 0.25 : shade;
return float4(input.Color * 3.0 * shade, 1);
// Depth attachment does not need to be explicitly written
}

View file

@ -0,0 +1,36 @@
// Copyright 2020 Google LLC
struct VSInput
{
[[vk::location(0)]] float3 Pos : POSITION0;
[[vk::location(1)]] float3 Color : COLOR0;
[[vk::location(2)]] float3 Normal : NORMAL0;
};
struct UBO {
float4x4 projection;
float4x4 model;
float4x4 view;
};
cbuffer ubo : register(b0) { UBO ubo; }
struct VSOutput
{
float4 Pos : SV_POSITION;
[[vk::location(0)]] float3 Color : COLOR0;
[[vk::location(1)]] float3 Normal : NORMAL0;
[[vk::location(2)]] float3 ViewVec : TEXCOORD1;
[[vk::location(3)]] float3 LightVec : TEXCOORD2;
};
VSOutput main(VSInput input)
{
VSOutput output = (VSOutput)0;
output.Pos = mul(ubo.projection, mul(ubo.view, mul(ubo.model, float4(input.Pos, 1.0))));
output.Color = input.Color;
output.Normal = input.Normal;
output.LightVec = float3(0.0f, 5.0f, 15.0f) - input.Pos;
output.ViewVec = -input.Pos.xyz;
return output;
}