Moved shaders to new directory

This commit is contained in:
Sascha Willems 2023-05-09 21:03:02 +02:00
parent 0b3f8340e3
commit 99b226237a
1244 changed files with 0 additions and 0 deletions

View file

@ -0,0 +1,69 @@
// Copyright 2020 Google LLC
[[vk::input_attachment_index(0)]][[vk::binding(0)]] SubpassInput samplerposition;
[[vk::input_attachment_index(1)]][[vk::binding(1)]] SubpassInput samplerNormal;
[[vk::input_attachment_index(2)]][[vk::binding(2)]] SubpassInput samplerAlbedo;
#define MAX_NUM_LIGHTS 64
[[vk::constant_id(0)]] const int NUM_LIGHTS = 64;
struct Light {
float4 position;
float3 color;
float radius;
};
struct UBO
{
float4 viewPos;
Light lights[MAX_NUM_LIGHTS];
};
cbuffer ubo : register(b3) { UBO ubo; }
float4 main([[vk::location(0)]] float2 inUV : TEXCOORD) : SV_TARGET
{
// Read G-Buffer values from previous sub pass
float3 fragPos = samplerposition.SubpassLoad().rgb;
float3 normal = samplerNormal.SubpassLoad().rgb;
float4 albedo = samplerAlbedo.SubpassLoad();
#define ambient 0.15
// Ambient part
float3 fragcolor = albedo.rgb * ambient;
for(int i = 0; i < NUM_LIGHTS; ++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);
// 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, 32.0) * atten;
fragcolor += diff;// + spec;
}
return float4(fragcolor, 1.0);
}

Binary file not shown.

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;
}

Binary file not shown.

View file

@ -0,0 +1,45 @@
// Copyright 2020 Google LLC
struct VSOutput
{
float4 Pos : SV_POSITION;
[[vk::location(0)]] float3 Normal : NORMAL0;
[[vk::location(1)]] float3 Color : COLOR0;
[[vk::location(2)]] float3 WorldPos : POSITION0;
};
struct FSOutput
{
[[vk::location(0)]] float4 Color : SV_TARGET0;
[[vk::location(1)]] float4 Position : SV_TARGET1;
[[vk::location(2)]] float4 Normal : SV_TARGET2;
[[vk::location(3)]] float4 Albedo : SV_TARGET3;
};
[[vk::constant_id(0)]] const float NEAR_PLANE = 0.1f;
[[vk::constant_id(1)]] const float FAR_PLANE = 256.0f;
float linearDepth(float depth)
{
float z = depth * 2.0f - 1.0f;
return (2.0f * NEAR_PLANE * FAR_PLANE) / (FAR_PLANE + NEAR_PLANE - z * (FAR_PLANE - NEAR_PLANE));
}
FSOutput main(VSOutput input)
{
FSOutput output = (FSOutput)0;
output.Position = float4(input.WorldPos, 1.0);
float3 N = normalize(input.Normal);
N.y = -N.y;
output.Normal = float4(N, 1.0);
output.Albedo.rgb = input.Color;
// Store linearized depth in alpha component
output.Position.a = linearDepth(input.Pos.z);
// Write color attachments to avoid undefined behaviour (validation error)
output.Color = float4(0.0, 0.0, 0.0, 0.0);
return output;
}

Binary file not shown.

View file

@ -0,0 +1,44 @@
// Copyright 2020 Google LLC
struct VSInput
{
[[vk::location(0)]] float4 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 Normal : NORMAL0;
[[vk::location(1)]] float3 Color : COLOR0;
[[vk::location(2)]] float3 WorldPos : POSITION0;
[[vk::location(3)]] float3 Tangent : TEXCOORD1;
};
VSOutput main(VSInput input)
{
VSOutput output = (VSOutput)0;
output.Pos = mul(ubo.projection, mul(ubo.view, mul(ubo.model, input.Pos)));
// Vertex position in world space
output.WorldPos = mul(ubo.model, input.Pos).xyz;
// GL to Vulkan coord space
output.WorldPos.y = -output.WorldPos.y;
// Normal in world space
output.Normal = mul((float3x3)ubo.model, normalize(input.Normal));
// Currently just vertex color
output.Color = input.Color;
return output;
}

Binary file not shown.

View file

@ -0,0 +1,33 @@
// Copyright 2020 Google LLC
[[vk::input_attachment_index(0)]][[vk::binding(1)]] SubpassInput samplerPositionDepth;
Texture2D textureTexture : register(t2);
SamplerState samplerTexture : register(s2);
struct VSOutput
{
float4 Pos : SV_POSITION;
[[vk::location(0)]] float3 Color : COLOR0;
[[vk::location(1)]] float2 UV : TEXCOORD0;
};
[[vk::constant_id(0)]] const float NEAR_PLANE = 0.1f;
[[vk::constant_id(1)]] const float FAR_PLANE = 256.0f;
float linearDepth(float depth)
{
float z = depth * 2.0f - 1.0f;
return (2.0f * NEAR_PLANE * FAR_PLANE) / (FAR_PLANE + NEAR_PLANE - z * (FAR_PLANE - NEAR_PLANE));
}
float4 main (VSOutput input) : SV_TARGET
{
// Sample depth from deferred depth buffer and discard if obscured
float depth = samplerPositionDepth.SubpassLoad().a;
if ((depth != 0.0) && (linearDepth(input.Pos.z) > depth))
{
clip(-1);
};
return textureTexture.Sample(samplerTexture, input.UV);
}

Binary file not shown.

View file

@ -0,0 +1,35 @@
// Copyright 2020 Google LLC
struct VSInput
{
[[vk::location(0)]] float4 Pos : POSITION0;
[[vk::location(1)]] float3 Color : COLOR0;
[[vk::location(2)]] float3 Normal : NORMAL0;
[[vk::location(3)]] float2 UV : TEXCOORD0;
};
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)]] float2 UV : TEXCOORD0;
};
VSOutput main (VSInput input)
{
VSOutput output = (VSOutput)0;
output.Color = input.Color;
output.UV = input.UV;
output.Pos = mul(ubo.projection, mul(ubo.view, mul(ubo.model, float4(input.Pos.xyz, 1.0))));
return output;
}

Binary file not shown.