Moved shaders to new directory
This commit is contained in:
parent
0b3f8340e3
commit
99b226237a
1244 changed files with 0 additions and 0 deletions
25
shaders/glsl/ssao/blur.frag
Normal file
25
shaders/glsl/ssao/blur.frag
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
#version 450
|
||||
|
||||
layout (binding = 0) uniform sampler2D samplerSSAO;
|
||||
|
||||
layout (location = 0) in vec2 inUV;
|
||||
|
||||
layout (location = 0) out float outFragColor;
|
||||
|
||||
void main()
|
||||
{
|
||||
const int blurRange = 2;
|
||||
int n = 0;
|
||||
vec2 texelSize = 1.0 / vec2(textureSize(samplerSSAO, 0));
|
||||
float result = 0.0;
|
||||
for (int x = -blurRange; x < blurRange; x++)
|
||||
{
|
||||
for (int y = -blurRange; y < blurRange; y++)
|
||||
{
|
||||
vec2 offset = vec2(float(x), float(y)) * texelSize;
|
||||
result += texture(samplerSSAO, inUV + offset).r;
|
||||
n++;
|
||||
}
|
||||
}
|
||||
outFragColor = result / (float(n));
|
||||
}
|
||||
BIN
shaders/glsl/ssao/blur.frag.spv
Normal file
BIN
shaders/glsl/ssao/blur.frag.spv
Normal file
Binary file not shown.
52
shaders/glsl/ssao/composition.frag
Normal file
52
shaders/glsl/ssao/composition.frag
Normal file
|
|
@ -0,0 +1,52 @@
|
|||
#version 450
|
||||
|
||||
layout (binding = 0) uniform sampler2D samplerposition;
|
||||
layout (binding = 1) uniform sampler2D samplerNormal;
|
||||
layout (binding = 2) uniform sampler2D samplerAlbedo;
|
||||
layout (binding = 3) uniform sampler2D samplerSSAO;
|
||||
layout (binding = 4) uniform sampler2D samplerSSAOBlur;
|
||||
layout (binding = 5) uniform UBO
|
||||
{
|
||||
mat4 _dummy;
|
||||
int ssao;
|
||||
int ssaoOnly;
|
||||
int ssaoBlur;
|
||||
} uboParams;
|
||||
|
||||
layout (location = 0) in vec2 inUV;
|
||||
|
||||
layout (location = 0) out vec4 outFragColor;
|
||||
|
||||
void main()
|
||||
{
|
||||
vec3 fragPos = texture(samplerposition, inUV).rgb;
|
||||
vec3 normal = normalize(texture(samplerNormal, inUV).rgb * 2.0 - 1.0);
|
||||
vec4 albedo = texture(samplerAlbedo, inUV);
|
||||
|
||||
float ssao = (uboParams.ssaoBlur == 1) ? texture(samplerSSAOBlur, inUV).r : texture(samplerSSAO, inUV).r;
|
||||
|
||||
vec3 lightPos = vec3(0.0);
|
||||
vec3 L = normalize(lightPos - fragPos);
|
||||
float NdotL = max(0.5, dot(normal, L));
|
||||
|
||||
if (uboParams.ssaoOnly == 1)
|
||||
{
|
||||
outFragColor.rgb = ssao.rrr;
|
||||
}
|
||||
else
|
||||
{
|
||||
vec3 baseColor = albedo.rgb * NdotL;
|
||||
|
||||
if (uboParams.ssao == 1)
|
||||
{
|
||||
outFragColor.rgb = ssao.rrr;
|
||||
|
||||
if (uboParams.ssaoOnly != 1)
|
||||
outFragColor.rgb *= baseColor;
|
||||
}
|
||||
else
|
||||
{
|
||||
outFragColor.rgb = baseColor;
|
||||
}
|
||||
}
|
||||
}
|
||||
BIN
shaders/glsl/ssao/composition.frag.spv
Normal file
BIN
shaders/glsl/ssao/composition.frag.spv
Normal file
Binary file not shown.
14
shaders/glsl/ssao/fullscreen.vert
Normal file
14
shaders/glsl/ssao/fullscreen.vert
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
#version 450
|
||||
|
||||
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);
|
||||
}
|
||||
BIN
shaders/glsl/ssao/fullscreen.vert.spv
Normal file
BIN
shaders/glsl/ssao/fullscreen.vert.spv
Normal file
Binary file not shown.
34
shaders/glsl/ssao/gbuffer.frag
Normal file
34
shaders/glsl/ssao/gbuffer.frag
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
#version 450
|
||||
|
||||
layout (location = 0) in vec3 inNormal;
|
||||
layout (location = 1) in vec2 inUV;
|
||||
layout (location = 2) in vec3 inColor;
|
||||
layout (location = 3) in vec3 inPos;
|
||||
|
||||
layout (location = 0) out vec4 outPosition;
|
||||
layout (location = 1) out vec4 outNormal;
|
||||
layout (location = 2) out vec4 outAlbedo;
|
||||
|
||||
layout (set = 0, binding = 0) uniform UBO
|
||||
{
|
||||
mat4 projection;
|
||||
mat4 model;
|
||||
mat4 view;
|
||||
float nearPlane;
|
||||
float farPlane;
|
||||
} ubo;
|
||||
|
||||
layout (set = 1, binding = 0) uniform sampler2D samplerColormap;
|
||||
|
||||
float linearDepth(float depth)
|
||||
{
|
||||
float z = depth * 2.0f - 1.0f;
|
||||
return (2.0f * ubo.nearPlane * ubo.farPlane) / (ubo.farPlane + ubo.nearPlane - z * (ubo.farPlane - ubo.nearPlane));
|
||||
}
|
||||
|
||||
void main()
|
||||
{
|
||||
outPosition = vec4(inPos, linearDepth(gl_FragCoord.z));
|
||||
outNormal = vec4(normalize(inNormal) * 0.5 + 0.5, 1.0);
|
||||
outAlbedo = texture(samplerColormap, inUV) * vec4(inColor, 1.0);
|
||||
}
|
||||
BIN
shaders/glsl/ssao/gbuffer.frag.spv
Normal file
BIN
shaders/glsl/ssao/gbuffer.frag.spv
Normal file
Binary file not shown.
34
shaders/glsl/ssao/gbuffer.vert
Normal file
34
shaders/glsl/ssao/gbuffer.vert
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
#version 450
|
||||
|
||||
layout (location = 0) in vec4 inPos;
|
||||
layout (location = 1) in vec2 inUV;
|
||||
layout (location = 2) in vec3 inColor;
|
||||
layout (location = 3) 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 vec2 outUV;
|
||||
layout (location = 2) out vec3 outColor;
|
||||
layout (location = 3) out vec3 outPos;
|
||||
|
||||
void main()
|
||||
{
|
||||
gl_Position = ubo.projection * ubo.view * ubo.model * inPos;
|
||||
|
||||
outUV = inUV;
|
||||
|
||||
// Vertex position in view space
|
||||
outPos = vec3(ubo.view * ubo.model * inPos);
|
||||
|
||||
// Normal in view space
|
||||
mat3 normalMatrix = transpose(inverse(mat3(ubo.view * ubo.model)));
|
||||
outNormal = normalMatrix * inNormal;
|
||||
|
||||
outColor = inColor;
|
||||
}
|
||||
BIN
shaders/glsl/ssao/gbuffer.vert.spv
Normal file
BIN
shaders/glsl/ssao/gbuffer.vert.spv
Normal file
Binary file not shown.
65
shaders/glsl/ssao/ssao.frag
Normal file
65
shaders/glsl/ssao/ssao.frag
Normal file
|
|
@ -0,0 +1,65 @@
|
|||
#version 450
|
||||
|
||||
layout (binding = 0) uniform sampler2D samplerPositionDepth;
|
||||
layout (binding = 1) uniform sampler2D samplerNormal;
|
||||
layout (binding = 2) uniform sampler2D ssaoNoise;
|
||||
|
||||
layout (constant_id = 0) const int SSAO_KERNEL_SIZE = 64;
|
||||
layout (constant_id = 1) const float SSAO_RADIUS = 0.5;
|
||||
|
||||
layout (binding = 3) uniform UBOSSAOKernel
|
||||
{
|
||||
vec4 samples[SSAO_KERNEL_SIZE];
|
||||
} uboSSAOKernel;
|
||||
|
||||
layout (binding = 4) uniform UBO
|
||||
{
|
||||
mat4 projection;
|
||||
} ubo;
|
||||
|
||||
layout (location = 0) in vec2 inUV;
|
||||
|
||||
layout (location = 0) out float outFragColor;
|
||||
|
||||
void main()
|
||||
{
|
||||
// Get G-Buffer values
|
||||
vec3 fragPos = texture(samplerPositionDepth, inUV).rgb;
|
||||
vec3 normal = normalize(texture(samplerNormal, inUV).rgb * 2.0 - 1.0);
|
||||
|
||||
// Get a random vector using a noise lookup
|
||||
ivec2 texDim = textureSize(samplerPositionDepth, 0);
|
||||
ivec2 noiseDim = textureSize(ssaoNoise, 0);
|
||||
const vec2 noiseUV = vec2(float(texDim.x)/float(noiseDim.x), float(texDim.y)/(noiseDim.y)) * inUV;
|
||||
vec3 randomVec = texture(ssaoNoise, noiseUV).xyz * 2.0 - 1.0;
|
||||
|
||||
// Create TBN matrix
|
||||
vec3 tangent = normalize(randomVec - normal * dot(randomVec, normal));
|
||||
vec3 bitangent = cross(tangent, normal);
|
||||
mat3 TBN = mat3(tangent, bitangent, normal);
|
||||
|
||||
// Calculate occlusion value
|
||||
float occlusion = 0.0f;
|
||||
// remove banding
|
||||
const float bias = 0.025f;
|
||||
for(int i = 0; i < SSAO_KERNEL_SIZE; i++)
|
||||
{
|
||||
vec3 samplePos = TBN * uboSSAOKernel.samples[i].xyz;
|
||||
samplePos = fragPos + samplePos * SSAO_RADIUS;
|
||||
|
||||
// project
|
||||
vec4 offset = vec4(samplePos, 1.0f);
|
||||
offset = ubo.projection * offset;
|
||||
offset.xyz /= offset.w;
|
||||
offset.xyz = offset.xyz * 0.5f + 0.5f;
|
||||
|
||||
float sampleDepth = -texture(samplerPositionDepth, offset.xy).w;
|
||||
|
||||
float rangeCheck = smoothstep(0.0f, 1.0f, SSAO_RADIUS / abs(fragPos.z - sampleDepth));
|
||||
occlusion += (sampleDepth >= samplePos.z + bias ? 1.0f : 0.0f) * rangeCheck;
|
||||
}
|
||||
occlusion = 1.0 - (occlusion / float(SSAO_KERNEL_SIZE));
|
||||
|
||||
outFragColor = occlusion;
|
||||
}
|
||||
|
||||
BIN
shaders/glsl/ssao/ssao.frag.spv
Normal file
BIN
shaders/glsl/ssao/ssao.frag.spv
Normal file
Binary file not shown.
Loading…
Add table
Add a link
Reference in a new issue