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
22
data/hlsl/deferred/debug.frag
Normal file
22
data/hlsl/deferred/debug.frag
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
// Copyright 2020 Google LLC
|
||||
|
||||
Texture2D texturePosition : register(t1);
|
||||
SamplerState samplerPosition : register(s1);
|
||||
Texture2D textureNormal : register(t2);
|
||||
SamplerState samplerNormal : register(s2);
|
||||
Texture2D textureAlbedo : register(t3);
|
||||
SamplerState samplerAlbedo : register(s3);
|
||||
|
||||
float4 main([[vk::location(0)]] float3 inUV : TEXCOORD0) : SV_TARGET
|
||||
{
|
||||
float3 components[3];
|
||||
components[0] = texturePosition.Sample(samplerPosition, inUV.xy).rgb;
|
||||
components[1] = textureNormal.Sample(samplerNormal, inUV.xy).rgb;
|
||||
components[2] = textureAlbedo.Sample(samplerAlbedo, inUV.xy).rgb;
|
||||
// Uncomment to display specular component
|
||||
//components[2] = float3(textureAlbedo.Sample(samplerAlbedo, inUV.st).a);
|
||||
|
||||
// Select component depending on z coordinate of quad
|
||||
int index = int(inUV.z);
|
||||
return float4(components[index], 1);
|
||||
}
|
||||
30
data/hlsl/deferred/debug.vert
Normal file
30
data/hlsl/deferred/debug.vert
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
// Copyright 2020 Google LLC
|
||||
|
||||
struct VSInput
|
||||
{
|
||||
[[vk::location(0)]] float3 Pos : POSITION0;
|
||||
[[vk::location(1)]] float2 UV : TEXCOORD0;
|
||||
[[vk::location(3)]] float3 Normal : NORMAL0;
|
||||
};
|
||||
|
||||
struct UBO
|
||||
{
|
||||
float4x4 projection;
|
||||
float4x4 model;
|
||||
};
|
||||
|
||||
cbuffer ubo : register(b0) { UBO ubo; }
|
||||
|
||||
struct VSOutput
|
||||
{
|
||||
float4 Pos : SV_POSITION;
|
||||
[[vk::location(0)]] float3 UV : TEXCOORD0;
|
||||
};
|
||||
|
||||
VSOutput main(VSInput input)
|
||||
{
|
||||
VSOutput output = (VSOutput)0;
|
||||
output.UV = float3(input.UV.xy, input.Normal.z);
|
||||
output.Pos = mul(ubo.projection, mul(ubo.model, float4(input.Pos.xyz, 1.0)));
|
||||
return output;
|
||||
}
|
||||
73
data/hlsl/deferred/deferred.frag
Normal file
73
data/hlsl/deferred/deferred.frag
Normal file
|
|
@ -0,0 +1,73 @@
|
|||
// Copyright 2020 Google LLC
|
||||
|
||||
Texture2D textureposition : register(t1);
|
||||
SamplerState samplerposition : register(s1);
|
||||
Texture2D textureNormal : register(t2);
|
||||
SamplerState samplerNormal : register(s2);
|
||||
Texture2D textureAlbedo : register(t3);
|
||||
SamplerState samplerAlbedo : register(s3);
|
||||
|
||||
struct Light {
|
||||
float4 position;
|
||||
float3 color;
|
||||
float radius;
|
||||
};
|
||||
|
||||
struct UBO
|
||||
{
|
||||
Light lights[6];
|
||||
float4 viewPos;
|
||||
};
|
||||
|
||||
cbuffer ubo : register(b4) { UBO ubo; }
|
||||
|
||||
|
||||
float4 main([[vk::location(0)]] float2 inUV : TEXCOORD0) : SV_TARGET
|
||||
{
|
||||
// Get G-Buffer values
|
||||
float3 fragPos = textureposition.Sample(samplerposition, inUV).rgb;
|
||||
float3 normal = textureNormal.Sample(samplerNormal, inUV).rgb;
|
||||
float4 albedo = textureAlbedo.Sample(samplerAlbedo, inUV);
|
||||
|
||||
#define lightCount 6
|
||||
#define ambient 0.0
|
||||
|
||||
// Ambient part
|
||||
float3 fragcolor = albedo.rgb * ambient;
|
||||
|
||||
for(int i = 0; i < lightCount; ++i)
|
||||
{
|
||||
// Vector to light
|
||||
float3 L = ubo.lights[i].position.xyz - fragPos;
|
||||
// Distance from light to fragment position
|
||||
float dist = length(L);
|
||||
|
||||
// Viewer to fragment
|
||||
float3 V = ubo.viewPos.xyz - fragPos;
|
||||
V = normalize(V);
|
||||
|
||||
//if(dist < ubo.lights[i].radius)
|
||||
{
|
||||
// Light to fragment
|
||||
L = normalize(L);
|
||||
|
||||
// Attenuation
|
||||
float atten = ubo.lights[i].radius / (pow(dist, 2.0) + 1.0);
|
||||
|
||||
// Diffuse part
|
||||
float3 N = normalize(normal);
|
||||
float NdotL = max(0.0, dot(N, L));
|
||||
float3 diff = ubo.lights[i].color * albedo.rgb * NdotL * atten;
|
||||
|
||||
// Specular part
|
||||
// Specular map values are stored in alpha of albedo mrt
|
||||
float3 R = reflect(-L, N);
|
||||
float NdotR = max(0.0, dot(R, V));
|
||||
float3 spec = ubo.lights[i].color * albedo.a * pow(NdotR, 16.0) * atten;
|
||||
|
||||
fragcolor += diff + spec;
|
||||
}
|
||||
}
|
||||
|
||||
return float4(fragcolor, 1.0);
|
||||
}
|
||||
15
data/hlsl/deferred/deferred.vert
Normal file
15
data/hlsl/deferred/deferred.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 * 2.0f - 1.0f, 0.0f, 1.0f);
|
||||
return output;
|
||||
}
|
||||
40
data/hlsl/deferred/mrt.frag
Normal file
40
data/hlsl/deferred/mrt.frag
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
// Copyright 2020 Google LLC
|
||||
|
||||
Texture2D textureColor : register(t1);
|
||||
SamplerState samplerColor : register(s1);
|
||||
Texture2D textureNormalMap : register(t2);
|
||||
SamplerState samplerNormalMap : register(s2);
|
||||
|
||||
struct VSOutput
|
||||
{
|
||||
[[vk::location(0)]] float3 Normal : NORMAL0;
|
||||
[[vk::location(1)]] float2 UV : TEXCOORD0;
|
||||
[[vk::location(2)]] float3 Color : COLOR0;
|
||||
[[vk::location(3)]] float3 WorldPos : POSITION0;
|
||||
[[vk::location(4)]] float3 Tangent : TEXCOORD1;
|
||||
};
|
||||
|
||||
struct FSOutput
|
||||
{
|
||||
float4 Position : SV_TARGET0;
|
||||
float4 Normal : SV_TARGET1;
|
||||
float4 Albedo : SV_TARGET2;
|
||||
};
|
||||
|
||||
FSOutput main(VSOutput input)
|
||||
{
|
||||
FSOutput output = (FSOutput)0;
|
||||
output.Position = float4(input.WorldPos, 1.0);
|
||||
|
||||
// Calculate normal in tangent space
|
||||
float3 N = normalize(input.Normal);
|
||||
N.y = -N.y;
|
||||
float3 T = normalize(input.Tangent);
|
||||
float3 B = cross(N, T);
|
||||
float3x3 TBN = float3x3(T, B, N);
|
||||
float3 tnorm = mul(normalize(textureNormalMap.Sample(samplerNormalMap, input.UV).xyz * 2.0 - float3(1.0, 1.0, 1.0)), TBN);
|
||||
output.Normal = float4(tnorm, 1.0);
|
||||
|
||||
output.Albedo = textureColor.Sample(samplerColor, input.UV);
|
||||
return output;
|
||||
}
|
||||
54
data/hlsl/deferred/mrt.vert
Normal file
54
data/hlsl/deferred/mrt.vert
Normal file
|
|
@ -0,0 +1,54 @@
|
|||
// 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;
|
||||
[[vk::location(4)]] float3 Tangent : TEXCOORD1;
|
||||
};
|
||||
|
||||
struct UBO
|
||||
{
|
||||
float4x4 projection;
|
||||
float4x4 model;
|
||||
float4x4 view;
|
||||
float4 instancePos[3];
|
||||
};
|
||||
|
||||
cbuffer ubo : register(b0) { UBO ubo; }
|
||||
|
||||
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 WorldPos : POSITION0;
|
||||
[[vk::location(4)]] float3 Tangent : TEXCOORD1;
|
||||
};
|
||||
|
||||
VSOutput main(VSInput input, uint InstanceIndex : SV_InstanceID)
|
||||
{
|
||||
VSOutput output = (VSOutput)0;
|
||||
float4 tmpPos = input.Pos + ubo.instancePos[InstanceIndex];
|
||||
|
||||
output.Pos = mul(ubo.projection, mul(ubo.view, mul(ubo.model, tmpPos)));
|
||||
|
||||
output.UV = input.UV;
|
||||
output.UV.y = 1.0 - output.UV.y;
|
||||
|
||||
// Vertex position in world space
|
||||
output.WorldPos = mul(ubo.model, tmpPos).xyz;
|
||||
// GL to Vulkan coord space
|
||||
output.WorldPos.y = -output.WorldPos.y;
|
||||
|
||||
// Normal in world space
|
||||
output.Normal = normalize(input.Normal);
|
||||
output.Tangent = normalize(input.Tangent);
|
||||
|
||||
// Currently just vertex color
|
||||
output.Color = input.Color;
|
||||
return output;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue