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,15 @@
// Copyright 2020 Google LLC
Texture2D colorMapTexture : register(t1);
SamplerState colorMapSampler : register(s1);
struct VSOutput
{
[[vk::location(0)]]float3 Color : COLOR0;
[[vk::location(1)]]float2 UV : TEXCOORD0;
};
float4 main(VSOutput input) : SV_TARGET
{
return float4(input.Color, 1);
}

View file

@ -0,0 +1,31 @@
// Copyright 2020 Google LLC
struct VSInput
{
[[vk::location(0)]]float4 Pos : POSITION0;
[[vk::location(1)]]float2 UV : TEXCOORD0;
[[vk::location(2)]]float3 Color : COLOR0;
};
struct VSOutput
{
float4 Pos : SV_POSITION;
[[vk::location(0)]]float3 Color : COLOR0;
[[vk::location(1)]]float2 UV : TEXCOORD0;
};
cbuffer UBO : register(b0)
{
float4x4 projection;
float4x4 view;
float4x4 model;
};
VSOutput main(VSInput input)
{
VSOutput output = (VSOutput)0;
output.UV = input.UV;
output.Color = input.Color;
output.Pos = mul(projection, mul(view, mul(model, input.Pos)));
return output;
}

View file

@ -0,0 +1,43 @@
// Copyright 2020 Google LLC
Texture2D textureColor : register(t1);
SamplerState samplerColor : register(s1);
cbuffer UBO : register(b0)
{
float blurScale;
float blurStrength;
};
[[vk::constant_id(0)]] const int blurdirection = 0;
float4 main([[vk::location(0)]] float2 inUV : TEXCOORD0) : SV_TARGET
{
float weight[5];
weight[0] = 0.227027;
weight[1] = 0.1945946;
weight[2] = 0.1216216;
weight[3] = 0.054054;
weight[4] = 0.016216;
float2 textureSize;
textureColor.GetDimensions(textureSize.x, textureSize.y);
float2 tex_offset = 1.0 / textureSize * blurScale; // gets size of single texel
float3 result = textureColor.Sample(samplerColor, inUV).rgb * weight[0]; // current fragment's contribution
for(int i = 1; i < 5; ++i)
{
if (blurdirection == 1)
{
// H
result += textureColor.Sample(samplerColor, inUV + float2(tex_offset.x * i, 0.0)).rgb * weight[i] * blurStrength;
result += textureColor.Sample(samplerColor, inUV - float2(tex_offset.x * i, 0.0)).rgb * weight[i] * blurStrength;
}
else
{
// V
result += textureColor.Sample(samplerColor, inUV + float2(0.0, tex_offset.y * i)).rgb * weight[i] * blurStrength;
result += textureColor.Sample(samplerColor, inUV - float2(0.0, tex_offset.y * i)).rgb * weight[i] * blurStrength;
}
}
return float4(result, 1.0);
}

View file

@ -0,0 +1,15 @@
// Copyright 2020 Google LLC
struct VSOutput
{
float4 Pos : SV_POSITION;
[[vk::location(0)]] float2 UV : TEXCOORD0;
};
VSOutput main(uint VertexIndex : SV_VertexID)
{
VSOutput output = (VSOutput)0;
output.UV = float2((VertexIndex << 1) & 2, VertexIndex & 2);
output.Pos = float4(output.UV * 2.0f - 1.0f, 0.0f, 1.0f);
return output;
}

View file

@ -0,0 +1,32 @@
// Copyright 2020 Google LLC
Texture2D colorMapTexture : register(t1);
SamplerState colorMapSampler : register(s1);
struct VSOutput
{
[[vk::location(0)]] float3 Normal : NORMAL0;
[[vk::location(1)]] float2 UV : TEXCOORD0;
[[vk::location(2)]] float3 Color : COLOR0;
[[vk::location(3)]] float3 ViewVec : TEXCOORD1;
[[vk::location(4)]] float3 LightVec : TEXCOORD2;
};
float4 main(VSOutput input) : SV_TARGET
{
float3 ambient = float3(0.0f, 0.0f, 0.0f);
// Adjust light calculations for glow color
if ((input.Color.r >= 0.9) || (input.Color.g >= 0.9) || (input.Color.b >= 0.9))
{
ambient = input.Color * 0.25;
}
float3 N = normalize(input.Normal);
float3 L = normalize(input.LightVec);
float3 V = normalize(input.ViewVec);
float3 R = reflect(-L, N);
float3 diffuse = max(dot(N, L), 0.0) * input.Color;
float3 specular = pow(max(dot(R, V), 0.0), 8.0) * float3(0.75f, 0.75f, 0.75f);
return float4(ambient + diffuse + specular, 1.0);
}

View file

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

View file

@ -0,0 +1,9 @@
// Copyright 2020 Google LLC
TextureCube textureCubeMap : register(t1);
SamplerState samplerCubeMap : register(s1);
float4 main([[vk::location(0)]] float3 inUVW : NORMAL0) : SV_TARGET
{
return textureCubeMap.Sample(samplerCubeMap, inUVW);
}

View file

@ -0,0 +1,22 @@
// Copyright 2020 Google LLC
cbuffer UBO : register(b0)
{
float4x4 projection;
float4x4 view;
float4x4 model;
};
struct VSOutput
{
float4 Pos : SV_POSITION;
[[vk::location(0)]] float3 UVW : NORMAL0;
};
VSOutput main([[vk::location(0)]] float3 inPos : POSITION0)
{
VSOutput output = (VSOutput)0;
output.UVW = inPos;
output.Pos = mul(projection, mul(view, mul(model, float4(inPos.xyz, 1.0))));
return output;
}