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:
parent
10a1ecaf7b
commit
cce75f1859
287 changed files with 11263 additions and 0 deletions
6
data/hlsl/debugmarker/colorpass.frag
Normal file
6
data/hlsl/debugmarker/colorpass.frag
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
// Copyright 2020 Google LLC
|
||||
|
||||
float4 main([[vk::location(0)]] float3 Color : COLOR0) : SV_TARGET
|
||||
{
|
||||
return float4(Color, 1);
|
||||
}
|
||||
29
data/hlsl/debugmarker/colorpass.vert
Normal file
29
data/hlsl/debugmarker/colorpass.vert
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
// Copyright 2020 Google LLC
|
||||
|
||||
struct VSInput
|
||||
{
|
||||
[[vk::location(0)]] float4 Pos : POSITION0;
|
||||
[[vk::location(3)]] float3 Color : COLOR0;
|
||||
};
|
||||
|
||||
struct UBO
|
||||
{
|
||||
float4x4 projection;
|
||||
float4x4 model;
|
||||
};
|
||||
|
||||
cbuffer ubo : register(b0) { UBO ubo; }
|
||||
|
||||
struct VSOutput
|
||||
{
|
||||
float4 Pos : SV_POSITION;
|
||||
[[vk::location(0)]] float3 Color : COLOR0;
|
||||
};
|
||||
|
||||
VSOutput main(VSInput input)
|
||||
{
|
||||
VSOutput output = (VSOutput)0;
|
||||
output.Color = input.Color;
|
||||
output.Pos = mul(ubo.projection, mul(ubo.model, input.Pos));
|
||||
return output;
|
||||
}
|
||||
36
data/hlsl/debugmarker/postprocess.frag
Normal file
36
data/hlsl/debugmarker/postprocess.frag
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
// Copyright 2020 Google LLC
|
||||
|
||||
Texture2D textureColor : register(t1);
|
||||
SamplerState samplerColor : register(s1);
|
||||
|
||||
float4 main([[vk::location(0)]] float2 inUV : TEXCOORD0) : SV_TARGET
|
||||
{
|
||||
// Single pass gauss blur
|
||||
|
||||
const float2 texOffset = float2(0.01, 0.01);
|
||||
|
||||
float2 tc0 = inUV + float2(-texOffset.x, -texOffset.y);
|
||||
float2 tc1 = inUV + float2( 0.0, -texOffset.y);
|
||||
float2 tc2 = inUV + float2(+texOffset.x, -texOffset.y);
|
||||
float2 tc3 = inUV + float2(-texOffset.x, 0.0);
|
||||
float2 tc4 = inUV + float2( 0.0, 0.0);
|
||||
float2 tc5 = inUV + float2(+texOffset.x, 0.0);
|
||||
float2 tc6 = inUV + float2(-texOffset.x, +texOffset.y);
|
||||
float2 tc7 = inUV + float2( 0.0, +texOffset.y);
|
||||
float2 tc8 = inUV + float2(+texOffset.x, +texOffset.y);
|
||||
|
||||
float4 col0 = textureColor.Sample(samplerColor, tc0);
|
||||
float4 col1 = textureColor.Sample(samplerColor, tc1);
|
||||
float4 col2 = textureColor.Sample(samplerColor, tc2);
|
||||
float4 col3 = textureColor.Sample(samplerColor, tc3);
|
||||
float4 col4 = textureColor.Sample(samplerColor, tc4);
|
||||
float4 col5 = textureColor.Sample(samplerColor, tc5);
|
||||
float4 col6 = textureColor.Sample(samplerColor, tc6);
|
||||
float4 col7 = textureColor.Sample(samplerColor, tc7);
|
||||
float4 col8 = textureColor.Sample(samplerColor, tc8);
|
||||
|
||||
float4 sum = (1.0 * col0 + 2.0 * col1 + 1.0 * col2 +
|
||||
2.0 * col3 + 4.0 * col4 + 2.0 * col5 +
|
||||
1.0 * col6 + 2.0 * col7 + 1.0 * col8) / 16.0;
|
||||
return float4(sum.rgb, 1.0);
|
||||
}
|
||||
15
data/hlsl/debugmarker/postprocess.vert
Normal file
15
data/hlsl/debugmarker/postprocess.vert
Normal 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 * float2(2.0f, 2.0f) + float2(-1.0f, -1.0f), 0.0f, 1.0f);
|
||||
return output;
|
||||
}
|
||||
37
data/hlsl/debugmarker/toon.frag
Normal file
37
data/hlsl/debugmarker/toon.frag
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
// Copyright 2020 Google LLC
|
||||
|
||||
Texture2D textureColorMap : register(t1);
|
||||
SamplerState samplerColorMap : register(s1);
|
||||
|
||||
struct VSOutput
|
||||
{
|
||||
[[vk::location(0)]] float3 Normal : NORMAL0;
|
||||
[[vk::location(1)]] float3 Color : COLOR0;
|
||||
[[vk::location(2)]] float2 UV : TEXCOORD0;
|
||||
[[vk::location(3)]] float3 ViewVec : TEXCOORD1;
|
||||
[[vk::location(4)]] float3 LightVec : TEXCOORD2;
|
||||
};
|
||||
|
||||
float4 main(VSOutput input) : SV_TARGET
|
||||
{
|
||||
// Desaturate color
|
||||
float3 color = float3(lerp(input.Color, dot(float3(0.2126,0.7152,0.0722), input.Color).xxx, 0.65));
|
||||
|
||||
// High ambient colors because mesh materials are pretty dark
|
||||
float3 ambient = color * float3(1.0, 1.0, 1.0);
|
||||
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) * color;
|
||||
float3 specular = pow(max(dot(R, V), 0.0), 16.0) * float3(0.75, 0.75, 0.75);
|
||||
|
||||
float intensity = dot(N,L);
|
||||
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);
|
||||
}
|
||||
44
data/hlsl/debugmarker/toon.vert
Normal file
44
data/hlsl/debugmarker/toon.vert
Normal file
|
|
@ -0,0 +1,44 @@
|
|||
// Copyright 2020 Google LLC
|
||||
|
||||
struct VSInput
|
||||
{
|
||||
[[vk::location(0)]] float3 Pos : POSITION0;
|
||||
[[vk::location(1)]] float3 Normal : NORMAL0;
|
||||
[[vk::location(2)]] float2 UV : TEXCOORD0;
|
||||
[[vk::location(3)]] float3 Color : COLOR0;
|
||||
};
|
||||
|
||||
struct UBO
|
||||
{
|
||||
float4x4 projection;
|
||||
float4x4 model;
|
||||
float4 lightPos;
|
||||
};
|
||||
|
||||
cbuffer ubo : register(b0) { UBO ubo; }
|
||||
|
||||
struct VSOutput
|
||||
{
|
||||
float4 Pos : SV_POSITION;
|
||||
[[vk::location(0)]] float3 Normal : NORMAL0;
|
||||
[[vk::location(1)]] float3 Color : COLOR0;
|
||||
[[vk::location(2)]] float2 UV : TEXCOORD0;
|
||||
[[vk::location(3)]] float3 ViewVec : TEXCOORD1;
|
||||
[[vk::location(4)]] float3 LightVec : TEXCOORD2;
|
||||
};
|
||||
|
||||
VSOutput main(VSInput input)
|
||||
{
|
||||
VSOutput output = (VSOutput)0;
|
||||
output.Normal = input.Normal;
|
||||
output.Color = input.Color;
|
||||
output.UV = input.UV;
|
||||
output.Pos = mul(ubo.projection, mul(ubo.model, float4(input.Pos.xyz, 1.0)));
|
||||
|
||||
float4 pos = mul(ubo.model, float4(input.Pos, 1.0));
|
||||
output.Normal = mul((float4x3)ubo.model, input.Normal).xyz;
|
||||
float3 lPos = mul((float4x3)ubo.model, ubo.lightPos.xyz).xyz;
|
||||
output.LightVec = lPos - pos.xyz;
|
||||
output.ViewVec = -pos.xyz;
|
||||
return output;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue