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
+79
View File
@@ -0,0 +1,79 @@
#version 450
/* Copyright (c) 2019-2024, 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 (binding = 0) uniform sampler2D samplerColor0;
layout (binding = 1) uniform sampler2D samplerColor1;
layout (location = 0) in vec2 inUV;
layout (location = 0) out vec4 outColor;
layout (constant_id = 0) const int dir = 0;
void main(void)
{
// From the OpenGL Super bible
const float weights[] = float[](0.0024499299678342,
0.0043538453346397,
0.0073599963704157,
0.0118349786570722,
0.0181026699707781,
0.0263392293891488,
0.0364543006660986,
0.0479932050577658,
0.0601029809166942,
0.0715974486241365,
0.0811305381519717,
0.0874493212267511,
0.0896631113333857,
0.0874493212267511,
0.0811305381519717,
0.0715974486241365,
0.0601029809166942,
0.0479932050577658,
0.0364543006660986,
0.0263392293891488,
0.0181026699707781,
0.0118349786570722,
0.0073599963704157,
0.0043538453346397,
0.0024499299678342);
const float blurScale = 0.003;
const float blurStrength = 1.0;
float ar = 1.0;
// Aspect ratio for vertical blur pass
if (dir == 1)
{
vec2 ts = textureSize(samplerColor1, 0);
ar = ts.y / ts.x;
}
vec2 P = inUV.yx - vec2(0, (weights.length() >> 1) * ar * blurScale);
vec4 color = vec4(0.0);
for (int i = 0; i < weights.length(); i++)
{
vec2 dv = vec2(0.0, i * blurScale) * ar;
color += texture(samplerColor1, P + dv) * weights[i] * blurStrength;
}
outColor = color;
}
Binary file not shown.
+30
View File
@@ -0,0 +1,30 @@
#version 450
/* Copyright (c) 2019-2024, 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;
out gl_PerVertex
{
vec4 gl_Position;
};
void main()
{
outUV = vec2((gl_VertexIndex << 1) & 2, gl_VertexIndex & 2);
gl_Position = vec4(outUV * 2.0f - 1.0f, 0.0f, 1.0f);
}
Binary file not shown.
+29
View File
@@ -0,0 +1,29 @@
#version 450
/* Copyright (c) 2019-2024, 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 (binding = 0) uniform sampler2D samplerColor0;
layout (binding = 1) uniform sampler2D samplerColor1;
layout (location = 0) in vec2 inUV;
layout (location = 0) out vec4 outColor;
void main()
{
outColor = texture(samplerColor0, inUV);
}
Binary file not shown.
+30
View File
@@ -0,0 +1,30 @@
#version 450
/* Copyright (c) 2019-2024, 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;
out gl_PerVertex
{
vec4 gl_Position;
};
void main()
{
outUV = vec2((gl_VertexIndex << 1) & 2, gl_VertexIndex & 2);
gl_Position = vec4(outUV * 2.0f - 1.0f, 0.0f, 1.0f);
}
Binary file not shown.
+115
View File
@@ -0,0 +1,115 @@
#version 450
/* Copyright (c) 2019-2024, 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 (binding = 1) uniform samplerCube samplerEnvMap;
layout (location = 0) in vec3 inUVW;
layout (location = 1) in vec3 inPos;
layout (location = 2) in vec3 inNormal;
layout (location = 3) in vec3 inViewVec;
layout (location = 4) in vec3 inLightVec;
layout (location = 0) out vec4 outColor0;
layout (location = 1) out vec4 outColor1;
layout (constant_id = 0) const int type = 0;
#define PI 3.1415926
#define TwoPI (2.0 * PI)
layout (binding = 0) uniform UBOCamera {
mat4 projection;
mat4 modelview;
mat4 skybox_modelview;
mat4 inverse_modelview;
float modelscale;
} uboCamera;
layout (binding = 2) uniform UBO {
float exposure;
} ubo;
void main()
{
vec4 color;
vec3 wcNormal;
switch (type) {
case 0: // Skybox
{
vec3 normal = normalize(inUVW);
color = texture(samplerEnvMap, normal);
}
break;
case 1: // Reflect
{
vec3 wViewVec = mat3(uboCamera.inverse_modelview) * normalize(inViewVec);
vec3 normal = normalize(inNormal);
vec3 wNormal = mat3(uboCamera.inverse_modelview) * normal;
float NdotL = max(dot(normal, inLightVec), 0.0);
vec3 eyeDir = normalize(inViewVec);
vec3 halfVec = normalize(inLightVec + eyeDir);
float NdotH = max(dot(normal, halfVec), 0.0);
float NdotV = max(dot(normal, eyeDir), 0.0);
float VdotH = max(dot(eyeDir, halfVec), 0.0);
// Geometric attenuation
float NH2 = 2.0 * NdotH;
float g1 = (NH2 * NdotV) / VdotH;
float g2 = (NH2 * NdotL) / VdotH;
float geoAtt = min(1.0, min(g1, g2));
const float F0 = 0.6;
const float k = 0.2;
// Fresnel (schlick approximation)
float fresnel = pow(1.0 - VdotH, 5.0);
fresnel *= (1.0 - F0);
fresnel += F0;
// Note: clamp to zero to mitigate any divide by zero
float spec = max((fresnel * geoAtt) / (NdotV * NdotL * 3.14), 0.0);
color = texture(samplerEnvMap, reflect(-wViewVec, wNormal));
color = vec4(color.rgb * NdotL * (k + spec * (1.0 - k)), 1.0);
}
break;
case 2: // Refract
{
vec3 wViewVec = mat3(uboCamera.inverse_modelview) * normalize(inViewVec);
vec3 wNormal = mat3(uboCamera.inverse_modelview) * inNormal;
color = texture(samplerEnvMap, refract(-wViewVec, wNormal, 1.0/1.6));
}
break;
}
// Color with manual exposure into attachment 0
outColor0.rgb = vec3(1.0) - exp(-color.rgb * ubo.exposure);
// Bright parts for bloom into attachment 1
float l = dot(outColor0.rgb, vec3(0.2126, 0.7152, 0.0722));
float threshold = 0.75;
outColor1.rgb = (l > threshold) ? outColor0.rgb : vec3(0.0);
outColor1.a = 1.0;
}
Binary file not shown.
+57
View File
@@ -0,0 +1,57 @@
#version 450
/* Copyright (c) 2019-2024, 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 (constant_id = 0) const int type = 0;
layout (binding = 0) uniform UBO {
mat4 projection;
mat4 modelview;
mat4 skybox_modelview;
mat4 inverse_modelview;
float modelscale;
} ubo;
layout (location = 0) out vec3 outUVW;
layout (location = 1) out vec3 outPos;
layout (location = 2) out vec3 outNormal;
layout (location = 3) out vec3 outViewVec;
layout (location = 4) out vec3 outLightVec;
void main()
{
outUVW = inPos;
switch(type) {
case 0: // Skybox
outPos = vec3(mat3(ubo.skybox_modelview) * inPos);
gl_Position = vec4(ubo.projection * vec4(outPos, 1.0));
break;
case 1: // Object
outPos = vec3(ubo.modelview * vec4(inPos * ubo.modelscale, 1.0));
gl_Position = ubo.projection * ubo.modelview * vec4(inPos.xyz * ubo.modelscale, 1.0);
break;
}
outNormal = mat3(ubo.modelview) * inNormal;
vec3 lightPos = vec3(0.0f, -5.0f, 5.0f);
outLightVec = lightPos.xyz - outPos.xyz;
outViewVec = -outPos.xyz;
}
Binary file not shown.
+77
View File
@@ -0,0 +1,77 @@
/* Copyright (c) 2024, 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.
*/
Texture2D textureColor0 : register(t0);
SamplerState samplerColor0 : register(s0);
Texture2D textureColor1 : register(t1);
SamplerState samplerColor1 : register(s1);
[[vk::constant_id(0)]] const int dir = 0;
float4 main([[vk::location(0)]] float2 inUV : TEXCOORD0) : SV_TARGET
{
// From the OpenGL Super bible
const float weights[] = { 0.0024499299678342,
0.0043538453346397,
0.0073599963704157,
0.0118349786570722,
0.0181026699707781,
0.0263392293891488,
0.0364543006660986,
0.0479932050577658,
0.0601029809166942,
0.0715974486241365,
0.0811305381519717,
0.0874493212267511,
0.0896631113333857,
0.0874493212267511,
0.0811305381519717,
0.0715974486241365,
0.0601029809166942,
0.0479932050577658,
0.0364543006660986,
0.0263392293891488,
0.0181026699707781,
0.0118349786570722,
0.0073599963704157,
0.0043538453346397,
0.0024499299678342};
const float blurScale = 0.003;
const float blurStrength = 1.0;
float ar = 1.0;
// Aspect ratio for vertical blur pass
if (dir == 1)
{
float2 ts;
textureColor1.GetDimensions(ts.x, ts.y);
ar = ts.y / ts.x;
}
float2 P = inUV.yx - float2(0, (25 >> 1) * ar * blurScale);
float4 color = float4(0.0, 0.0, 0.0, 0.0);
for (int i = 0; i < 25; i++)
{
float2 dv = float2(0.0, i * blurScale) * ar;
color += textureColor1.Sample(samplerColor1, P + dv) * weights[i] * blurStrength;
}
return color;
}
Binary file not shown.
+30
View File
@@ -0,0 +1,30 @@
/* Copyright (c) 2024, 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.
*/
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.
+32
View File
@@ -0,0 +1,32 @@
/* Copyright (c) 2024, 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.
*/
Texture2D textureColor0 : register(t0);
SamplerState samplerColor0 : register(s0);
Texture2D textureColor1 : register(t1);
SamplerState samplerColor1 : register(s1);
struct VSOutput
{
float4 Pos : SV_POSITION;
[[vk::location(0)]] float2 UV : TEXCOORD0;
};
float4 main(VSOutput input) : SV_TARGET
{
return textureColor0.Sample(samplerColor0, input.UV);
}
Binary file not shown.
+30
View File
@@ -0,0 +1,30 @@
/* Copyright (c) 2024, 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.
*/
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.
+127
View File
@@ -0,0 +1,127 @@
/* Copyright (c) 2024, 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.
*/
TextureCube textureEnvMap : register(t1);
SamplerState samplerEnvMap : register(s1);
struct VSOutput
{
float4 Pos : SV_POSITION;
[[vk::location(0)]] float3 UVW : TEXCOORD0;
[[vk::location(1)]] float3 Normal : NORMAL0;
[[vk::location(2)]] float3 ViewVec : TEXCOORD1;
[[vk::location(3)]] float3 LightVec : TEXCOORD2;
};
struct FSOutput
{
float4 Color0 : SV_TARGET0;
float4 Color1 : SV_TARGET1;
};
[[vk::constant_id(0)]] const int type = 0;
#define PI 3.1415926
#define TwoPI (2.0 * PI)
struct UBOMatrices
{
float4x4 projection;
float4x4 modelview;
float4x4 skyboxModelview;
float4x4 inverseModelView;
float modelscale;
};
[[vk::binding(0, 0)]]
ConstantBuffer<UBOMatrices> uboMatrices : register(b0);
struct UBO {
float exposure;
};
[[vk::binding(2, 0)]]
ConstantBuffer<UBO> ubo : register(b2);
FSOutput main(VSOutput input)
{
FSOutput output = (FSOutput)0;
float4 color;
float3 wcNormal;
switch (type) {
case 0: // Skybox
{
float3 normal = normalize(input.UVW);
color = textureEnvMap.Sample(samplerEnvMap, normal);
}
break;
case 1: // Reflect
{
float3 wViewVec = mul((float3x3) uboMatrices.inverseModelView, normalize(input.ViewVec)).xyz;
float3 normal = normalize(input.Normal);
float3 wNormal = mul((float3x3) uboMatrices.inverseModelView, normal).xyz;
float NdotL = max(dot(normal, input.LightVec), 0.0);
float3 eyeDir = normalize(input.ViewVec);
float3 halfVec = normalize(input.LightVec + eyeDir);
float NdotH = max(dot(normal, halfVec), 0.0);
float NdotV = max(dot(normal, eyeDir), 0.0);
float VdotH = max(dot(eyeDir, halfVec), 0.0);
// Geometric attenuation
float NH2 = 2.0 * NdotH;
float g1 = (NH2 * NdotV) / VdotH;
float g2 = (NH2 * NdotL) / VdotH;
float geoAtt = min(1.0, min(g1, g2));
const float F0 = 0.6;
const float k = 0.2;
// Fresnel (schlick approximation)
float fresnel = pow(1.0 - VdotH, 5.0);
fresnel *= (1.0 - F0);
fresnel += F0;
float spec = (fresnel * geoAtt) / (NdotV * NdotL * 3.14);
color = textureEnvMap.Sample(samplerEnvMap, reflect(-wViewVec, wNormal));
color = float4(color.rgb * NdotL * (k + spec * (1.0 - k)), 1.0);
}
break;
case 2: // Refract
{
float3 wViewVec = mul((float4x3) uboMatrices.inverseModelView, normalize(input.ViewVec)).xyz;
float3 wNormal = mul((float4x3) uboMatrices.inverseModelView, input.Normal).xyz;
color = textureEnvMap.Sample(samplerEnvMap, refract(-wViewVec, wNormal, 1.0/1.6));
}
break;
}
// Color with manual exposure into attachment 0
output.Color0.rgb = float3(1.0, 1.0, 1.0) - exp(-color.rgb * ubo.exposure);
// Bright parts for bloom into attachment 1
float l = dot(output.Color0.rgb, float3(0.2126, 0.7152, 0.0722));
float threshold = 0.75;
output.Color1.rgb = (l > threshold) ? output.Color0.rgb : float3(0.0, 0.0, 0.0);
output.Color1.a = 1.0;
return output;
}
Binary file not shown.
+67
View File
@@ -0,0 +1,67 @@
/* Copyright (c) 2024, 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.
*/
struct VSInput
{
[[vk::location(0)]] float3 Pos : POSITION0;
[[vk::location(1)]] float3 Normal : NORMAL0;
};
[[vk::constant_id(0)]] const int type = 0;
struct UBO {
float4x4 projection;
float4x4 modelview;
float4x4 skyboxModelview;
float4x4 inverseModelView;
float modelscale;
};
[[vk::binding(0, 0)]]
ConstantBuffer<UBO> ubo : register(b0);
struct VSOutput
{
float4 Pos : SV_POSITION;
[[vk::location(0)]] float3 UVW : TEXCOORD0;
[[vk::location(1)]] float3 Normal : NORMAL0;
[[vk::location(2)]] float3 ViewVec : TEXCOORD1;
[[vk::location(3)]] float3 LightVec : TEXCOORD2;
};
VSOutput main(VSInput input)
{
VSOutput output = (VSOutput)0;
output.UVW = input.Pos;
float3 worldPos;
switch(type) {
case 0: // Skybox
worldPos = mul((float4x3) ubo.skyboxModelview, input.Pos).xyz;
output.Pos = mul(ubo.projection, float4(worldPos, 1.0));
break;
case 1: // Object
worldPos = mul(ubo.modelview, float4(input.Pos * ubo.modelscale, 1.0)).xyz;
output.Pos = mul(ubo.projection, mul(ubo.modelview, float4(input.Pos.xyz * ubo.modelscale, 1.0)));
break;
}
output.Normal = mul((float4x3)ubo.modelview, input.Normal).xyz;
float3 lightPos = float3(0.0f, -5.0f, 5.0f);
output.LightVec = lightPos.xyz - worldPos.xyz;
output.ViewVec = -worldPos.xyz;
return output;
}
Binary file not shown.