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
27
data/hlsl/indirectdraw/ground.frag
Normal file
27
data/hlsl/indirectdraw/ground.frag
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
// Copyright 2020 Google LLC
|
||||
|
||||
Texture2D textureColor : register(t2);
|
||||
SamplerState samplerColor : register(s2);
|
||||
|
||||
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
|
||||
{
|
||||
// Last array layer is terrain tex
|
||||
float4 color = textureColor.Sample(samplerColor, input.UV);
|
||||
float3 N = normalize(input.Normal);
|
||||
float3 L = normalize(input.LightVec);
|
||||
float3 V = normalize(input.ViewVec);
|
||||
float3 R = reflect(-L, N);
|
||||
float3 ambient = float3(0.65, 0.65, 0.65);
|
||||
float3 diffuse = max(dot(N, L), 0.0) * input.Color;
|
||||
float3 specular = pow(max(dot(R, V), 0.0), 16.0) * float3(0.1, 0.1, 0.1);
|
||||
return float4((ambient + diffuse) * color.rgb + specular, 1.0);
|
||||
}
|
||||
45
data/hlsl/indirectdraw/ground.vert
Normal file
45
data/hlsl/indirectdraw/ground.vert
Normal file
|
|
@ -0,0 +1,45 @@
|
|||
// Copyright 2020 Google LLC
|
||||
|
||||
struct VSInput
|
||||
{
|
||||
[[vk::location(0)]] float4 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 modelview;
|
||||
};
|
||||
|
||||
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.Color = input.Color;
|
||||
output.UV = input.UV * 32.0;
|
||||
output.Normal = input.Normal;
|
||||
|
||||
float4 pos = float4(input.Pos.xyz, 1.0);
|
||||
|
||||
output.Pos = mul(ubo.projection, mul(ubo.modelview, pos));
|
||||
|
||||
float4 wPos = mul(ubo.modelview, float4(pos.xyz, 1.0));
|
||||
float4 lPos = float4(0.0, -5.0, 0.0, 1.0);
|
||||
output.LightVec = lPos.xyz - pos.xyz;
|
||||
output.ViewVec = -pos.xyz;
|
||||
return output;
|
||||
}
|
||||
29
data/hlsl/indirectdraw/indirectdraw.frag
Normal file
29
data/hlsl/indirectdraw/indirectdraw.frag
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
// Copyright 2020 Google LLC
|
||||
|
||||
Texture2DArray textureArray : register(t1);
|
||||
SamplerState samplerArray : register(s1);
|
||||
|
||||
struct VSOutput
|
||||
{
|
||||
[[vk::location(0)]] float3 Normal : NORMAL0;
|
||||
[[vk::location(1)]] float3 Color : COLOR0;
|
||||
[[vk::location(2)]] float3 UV : TEXCOORD0;
|
||||
[[vk::location(3)]] float3 ViewVec : TEXCOORD1;
|
||||
[[vk::location(4)]] float3 LightVec : TEXCOORD2;
|
||||
};
|
||||
|
||||
float4 main(VSOutput input) : SV_TARGET
|
||||
{
|
||||
float4 color = textureArray.Sample(samplerArray, input.UV);
|
||||
|
||||
if (color.a < 0.5)
|
||||
{
|
||||
clip(-1);
|
||||
}
|
||||
|
||||
float3 N = normalize(input.Normal);
|
||||
float3 L = normalize(input.LightVec);
|
||||
float3 ambient = float3(0.65, 0.65, 0.65);
|
||||
float3 diffuse = max(dot(N, L), 0.0) * input.Color;
|
||||
return float4((ambient + diffuse) * color.rgb, 1.0);
|
||||
}
|
||||
82
data/hlsl/indirectdraw/indirectdraw.vert
Normal file
82
data/hlsl/indirectdraw/indirectdraw.vert
Normal file
|
|
@ -0,0 +1,82 @@
|
|||
// Copyright 2020 Google LLC
|
||||
|
||||
struct VSInput
|
||||
{
|
||||
[[vk::location(0)]] float4 Pos : POSITION0;
|
||||
[[vk::location(1)]] float3 Normal : NORMAL0;
|
||||
[[vk::location(2)]] float2 UV : TEXCOORD0;
|
||||
[[vk::location(3)]] float3 Color : COLOR0;
|
||||
[[vk::location(4)]] float3 instancePos : POSITION1;
|
||||
[[vk::location(5)]] float3 instanceRot : TEXCOORD1;
|
||||
[[vk::location(6)]] float instanceScale : TEXCOORD2;
|
||||
[[vk::location(7)]] int instanceTexIndex : TEXCOORD3;
|
||||
};
|
||||
|
||||
struct UBO
|
||||
{
|
||||
float4x4 projection;
|
||||
float4x4 modelview;
|
||||
};
|
||||
|
||||
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)]] float3 UV : TEXCOORD0;
|
||||
[[vk::location(3)]] float3 ViewVec : TEXCOORD1;
|
||||
[[vk::location(4)]] float3 LightVec : TEXCOORD2;
|
||||
};
|
||||
|
||||
VSOutput main(VSInput input)
|
||||
{
|
||||
VSOutput output = (VSOutput)0;
|
||||
output.Color = input.Color;
|
||||
output.UV = float3(input.UV, input.instanceTexIndex);
|
||||
output.UV.y = 1.0 - output.UV.y;
|
||||
|
||||
float4x4 mx, my, mz;
|
||||
|
||||
// rotate around x
|
||||
float s = sin(input.instanceRot.x);
|
||||
float c = cos(input.instanceRot.x);
|
||||
|
||||
mx[0] = float4(c, s, 0.0, 0.0);
|
||||
mx[1] = float4(-s, c, 0.0, 0.0);
|
||||
mx[2] = float4(0.0, 0.0, 1.0, 0.0);
|
||||
mx[3] = float4(0.0, 0.0, 0.0, 1.0);
|
||||
|
||||
// rotate around y
|
||||
s = sin(input.instanceRot.y);
|
||||
c = cos(input.instanceRot.y);
|
||||
|
||||
my[0] = float4(c, 0.0, s, 0.0);
|
||||
my[1] = float4(0.0, 1.0, 0.0, 0.0);
|
||||
my[2] = float4(-s, 0.0, c, 0.0);
|
||||
my[3] = float4(0.0, 0.0, 0.0, 1.0);
|
||||
|
||||
// rot around z
|
||||
s = sin(input.instanceRot.z);
|
||||
c = cos(input.instanceRot.z);
|
||||
|
||||
mz[0] = float4(1.0, 0.0, 0.0, 0.0);
|
||||
mz[1] = float4(0.0, c, s, 0.0);
|
||||
mz[2] = float4(0.0, -s, c, 0.0);
|
||||
mz[3] = float4(0.0, 0.0, 0.0, 1.0);
|
||||
|
||||
float4x4 rotMat = mul(mz, mul(my, mx));
|
||||
|
||||
output.Normal = mul((float4x3)rotMat, input.Normal).xyz;
|
||||
|
||||
float4 pos = mul(rotMat, float4((input.Pos.xyz * input.instanceScale) + input.instancePos, 1.0));
|
||||
|
||||
output.Pos = mul(ubo.projection, mul(ubo.modelview, pos));
|
||||
|
||||
float4 wPos = mul(ubo.modelview, float4(pos.xyz, 1.0));
|
||||
float4 lPos = float4(0.0, -5.0, 0.0, 1.0);
|
||||
output.LightVec = lPos.xyz - pos.xyz;
|
||||
output.ViewVec = -pos.xyz;
|
||||
return output;
|
||||
}
|
||||
11
data/hlsl/indirectdraw/skysphere.frag
Normal file
11
data/hlsl/indirectdraw/skysphere.frag
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
// Copyright 2020 Google LLC
|
||||
|
||||
Texture2D textureColor : register(t2);
|
||||
SamplerState samplerColor : register(s2);
|
||||
|
||||
float4 main([[vk::location(0)]] float2 inUV : TEXCOORD0) : SV_TARGET
|
||||
{
|
||||
const float4 gradientStart = float4(0.93, 0.9, 0.81, 1.0);
|
||||
const float4 gradientEnd = float4(0.35, 0.5, 1.0, 1.0);
|
||||
return lerp(gradientStart, gradientEnd, min(0.5 - inUV.y, 0.5)/0.15 + 0.5);
|
||||
}
|
||||
30
data/hlsl/indirectdraw/skysphere.vert
Normal file
30
data/hlsl/indirectdraw/skysphere.vert
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
// Copyright 2020 Google LLC
|
||||
|
||||
struct VSInput
|
||||
{
|
||||
[[vk::location(0)]] float4 Pos : POSITION0;
|
||||
[[vk::location(2)]] float2 UV : TEXCOORD0;
|
||||
};
|
||||
|
||||
struct UBO
|
||||
{
|
||||
float4x4 projection;
|
||||
float4x4 modelview;
|
||||
};
|
||||
|
||||
cbuffer ubo : register(b0) { UBO ubo; }
|
||||
|
||||
struct VSOutput
|
||||
{
|
||||
float4 Pos : SV_POSITION;
|
||||
[[vk::location(0)]] float2 UV : TEXCOORD0;
|
||||
};
|
||||
|
||||
VSOutput main(VSInput input)
|
||||
{
|
||||
VSOutput output = (VSOutput)0;
|
||||
output.UV = float2(input.UV.x, 1.0-input.UV.y);
|
||||
// Skysphere always at center, only use rotation part of modelview matrix
|
||||
output.Pos = mul(ubo.projection, float4(mul((float3x3)ubo.modelview, input.Pos.xyz), 1));
|
||||
return output;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue