This commit is contained in:
xsl
2025-09-04 10:54:47 +08:00
commit 6bc8f61b18
1808 changed files with 208268 additions and 0 deletions
@@ -0,0 +1,65 @@
#version 450
/* Copyright (c) 2024-2025, Sascha Willems
*
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 the "License";
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
layout (input_attachment_index = 0, binding = 0) uniform subpassInput positionDepthAttachment;
layout (input_attachment_index = 1, binding = 1) uniform subpassInput normalAttachment;
layout (input_attachment_index = 2, binding = 2) uniform subpassInput albedoAttachment;
layout (location = 0) in vec2 inUV;
layout (location = 0) out vec4 outColor;
struct Light {
vec4 position;
vec3 color;
float radius;
};
layout(std140, binding = 3) readonly buffer LightsBuffer
{
Light lights[ ];
};
void main()
{
// Read G-Buffer values from previous sub pass
vec3 fragPos = subpassLoad(positionDepthAttachment).rgb;
vec3 normal = subpassLoad(normalAttachment).rgb;
vec4 albedo = subpassLoad(albedoAttachment);
#define ambient 0.005
// Ambient part
vec3 fragcolor = albedo.rgb * ambient;
for(int i = 0; i < lights.length(); ++i)
{
vec3 L = lights[i].position.xyz - fragPos;
float dist = length(L);
float attenuation = lights[i].radius / (pow(dist, 8.0) + 1.0);
float NdotL = max(0.0, dot(normalize(normal), normalize(L)));
vec3 diffuse = lights[i].color * albedo.rgb * NdotL * attenuation;
fragcolor += diffuse;
}
outColor = vec4(fragcolor, 1.0);
}
@@ -0,0 +1,25 @@
#version 450
/* Copyright (c) 2024-2025, Sascha Willems
*
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 the "License";
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
layout (location = 0) out vec2 outUV;
void main()
{
outUV = vec2((gl_VertexIndex << 1) & 2, gl_VertexIndex & 2);
gl_Position = vec4(outUV * 2.0f - 1.0f, 0.0f, 1.0f);
}
@@ -0,0 +1,52 @@
#version 450
/* Copyright (c) 2024-2025, Sascha Willems
*
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 the "License";
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
layout (location = 0) in vec3 inNormal;
layout (location = 1) in vec4 inColor;
layout (location = 2) in vec3 inWorldPos;
layout (location = 0) out vec4 outColor;
layout (location = 1) out vec4 outPositionDepth;
layout (location = 2) out vec4 outNormal;
layout (location = 3) out vec4 outAlbedo;
layout (constant_id = 0) const float NEAR_PLANE = 0.1f;
layout (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));
}
void main()
{
outPositionDepth = vec4(inWorldPos, 1.0);
vec3 N = normalize(inNormal);
N.y = -N.y;
outNormal = vec4(N, 1.0);
outAlbedo = inColor;
// Store linearized depth in alpha component
outPositionDepth.a = linearDepth(gl_FragCoord.z);
// Write color attachments to avoid undefined behaviour (validation error)
outColor = vec4(0.0);
}
@@ -0,0 +1,54 @@
#version 450
/* Copyright (c) 2024-2025, Sascha Willems
*
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 the "License";
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
layout (location = 0) in vec3 inPos;
layout (location = 1) in vec3 inNormal;
layout (binding = 0) uniform UBO
{
mat4 projection;
mat4 model;
mat4 view;
} ubo;
layout (location = 0) out vec3 outNormal;
layout (location = 1) out vec4 outColor;
layout (location = 2) out vec3 outWorldPos;
layout(push_constant) uniform SceneNode {
mat4 matrix;
vec4 color;
} sceneNode;
void main()
{
mat4 nodeMat = ubo.model * sceneNode.matrix;
gl_Position = ubo.projection * ubo.view * nodeMat * vec4(inPos, 1.0);
// Vertex position in world space
outWorldPos = vec3(sceneNode.matrix * vec4(inPos, 1.0));
// GL to Vulkan coord space
outWorldPos.y = -outWorldPos.y;
// Normal in world space
mat3 mNormal = transpose(inverse(mat3(mat3(nodeMat))));
outNormal = normalize(mNormal * inNormal);
outColor = sceneNode.color;
}
@@ -0,0 +1,53 @@
#version 450
/* Copyright (c) 2024-2025, Sascha Willems
*
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 the "License";
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
// Should be zero, also rename in other shader
layout (input_attachment_index = 0, binding = 0) uniform subpassInput positionDepthAttachment;
layout (binding = 2) uniform sampler2D samplerTexture;
layout (location = 0) in vec4 inColor;
layout (location = 1) in vec2 inUV;
layout (location = 0) out vec4 outColor;
layout (constant_id = 0) const float NEAR_PLANE = 0.1f;
layout (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));
}
void main ()
{
// Sample depth from deferred depth buffer and discard if obscured
float depth = subpassLoad(positionDepthAttachment).a;
// Save the sampled texture color before discarding.
// This is to avoid implicit derivatives in non-uniform control flow.
// @todo: reversed depth
vec4 sampledColor = texture(samplerTexture, inUV);
if ((depth != 0.0) && (linearDepth(gl_FragCoord.z) < depth))
{
// discard;
};
outColor = sampledColor;
}
@@ -0,0 +1,45 @@
#version 450
/* Copyright (c) 2024-2025, Sascha Willems
*
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 the "License";
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
layout (location = 0) in vec3 inPos;
layout (location = 1) in vec3 inNormal;
layout (location = 2) in vec2 inUV;
layout (binding = 1) uniform UBO
{
mat4 projection;
mat4 model;
mat4 view;
} ubo;
layout (location = 0) out vec4 outColor;
layout (location = 1) out vec2 outUV;
layout(push_constant) uniform SceneNode {
mat4 matrix;
vec4 color;
} sceneNode;
void main ()
{
outColor = vec4(1.0);
outUV = inUV;
gl_Position = ubo.projection * ubo.view * ubo.model * sceneNode.matrix * vec4(inPos.xyz, 1.0);
}