post processing, FXAA and MSAA 2x-8x
This commit is contained in:
parent
fa266ee48d
commit
8ce30cae83
46 changed files with 1749 additions and 350 deletions
|
|
@ -0,0 +1,55 @@
|
|||
#version 450
|
||||
|
||||
layout(constant_id = 0) const int USE_AA = 0;
|
||||
|
||||
const float GAMMA_CONST = 0.4545;
|
||||
const float SPAN_MAX = 8.0;
|
||||
const float REDUCE_MIN = 1.0/128.0;
|
||||
const float REDUCE_MUL = 1.0/32.0;
|
||||
|
||||
layout(location = 0) in vec2 inTextCoord;
|
||||
layout(location = 0) out vec4 outFragColor;
|
||||
|
||||
layout(set = 0, binding = 0) uniform sampler2DMS inputTexture;
|
||||
|
||||
layout(set = 1, binding = 0) uniform ScreenSize{
|
||||
vec2 size;
|
||||
} screenSize;
|
||||
|
||||
vec4 gamma(vec4 color){
|
||||
return color = vec4(pow(color.rgb,vec3(GAMMA_CONST)),color.a);
|
||||
}
|
||||
|
||||
|
||||
vec4 msaa(int sampleCount, sampler2DMS textureIn,vec2 TextCoord){
|
||||
ivec2 pixelCoords = ivec2(TextCoord * textureSize(textureIn));
|
||||
vec4 colorSum = vec4(0.0);
|
||||
|
||||
for(int i = 0; i < sampleCount; ++i) {
|
||||
vec4 sampleColor = texelFetch(textureIn, pixelCoords, i);
|
||||
sampleColor.rgb = sampleColor.rgb / (sampleColor.rgb + vec3(1.0));
|
||||
colorSum += sampleColor;
|
||||
}
|
||||
return colorSum / float(sampleCount);
|
||||
}
|
||||
|
||||
void main(){
|
||||
ivec2 pixelCoords = ivec2(inTextCoord * textureSize(inputTexture));
|
||||
|
||||
if(USE_AA == 0){
|
||||
outFragColor = texelFetch(inputTexture,pixelCoords,0);
|
||||
}
|
||||
if(USE_AA == 1){
|
||||
outFragColor = texelFetch(inputTexture,pixelCoords,0);
|
||||
}
|
||||
if(USE_AA == 2){
|
||||
outFragColor = msaa(2,inputTexture,inTextCoord);
|
||||
}
|
||||
if(USE_AA == 3){
|
||||
outFragColor = msaa(4,inputTexture,inTextCoord);
|
||||
}
|
||||
if(USE_AA == 4){
|
||||
outFragColor = msaa(8,inputTexture,inTextCoord);
|
||||
}
|
||||
outFragColor = gamma(outFragColor);
|
||||
}
|
||||
91
resources/EngineResources/shaders/post_process_frag.glsl
Normal file
91
resources/EngineResources/shaders/post_process_frag.glsl
Normal file
|
|
@ -0,0 +1,91 @@
|
|||
#version 450
|
||||
|
||||
layout(constant_id = 0) const int USE_AA = 0;
|
||||
|
||||
const float GAMMA_CONST = 0.4545;
|
||||
const float SPAN_MAX = 8.0;
|
||||
const float REDUCE_MIN = 1.0/128.0;
|
||||
const float REDUCE_MUL = 1.0/32.0;
|
||||
|
||||
layout(location = 0) in vec2 inTextCoord;
|
||||
layout(location = 0) out vec4 outFragColor;
|
||||
|
||||
layout(set = 0, binding = 0) uniform sampler2D inputTexture;
|
||||
|
||||
layout(set = 1, binding = 0) uniform ScreenSize{
|
||||
vec2 size;
|
||||
} screenSize;
|
||||
|
||||
vec4 gamma(vec4 color){
|
||||
return color = vec4(pow(color.rgb,vec3(GAMMA_CONST)),color.a);
|
||||
}
|
||||
|
||||
// Sourced from: https://mini.gmshaders.com/p/gm-shaders-mini-fxaa
|
||||
|
||||
vec4 fxaa(sampler2D tex, vec2 uv) {
|
||||
vec2 u_texel = 1.0 / screenSize.size;
|
||||
|
||||
//Sample center and 4 corners
|
||||
vec3 rgbCC = texture(tex, uv).rgb;
|
||||
vec3 rgb00 = texture(tex, uv+vec2(-0.5,-0.5)*u_texel).rgb;
|
||||
vec3 rgb10 = texture(tex, uv+vec2(+0.5,-0.5)*u_texel).rgb;
|
||||
vec3 rgb01 = texture(tex, uv+vec2(-0.5,+0.5)*u_texel).rgb;
|
||||
vec3 rgb11 = texture(tex, uv+vec2(+0.5,+0.5)*u_texel).rgb;
|
||||
|
||||
//Luma coefficients
|
||||
const vec3 luma = vec3(0.299, 0.587, 0.114);
|
||||
//Get luma from the 5 samples
|
||||
float lumaCC = dot(rgbCC, luma);
|
||||
float luma00 = dot(rgb00, luma);
|
||||
float luma10 = dot(rgb10, luma);
|
||||
float luma01 = dot(rgb01, luma);
|
||||
float luma11 = dot(rgb11, luma);
|
||||
|
||||
//Compute gradient from luma values
|
||||
vec2 dir = vec2((luma01 + luma11) - (luma00 + luma10), (luma00 + luma01) - (luma10 + luma11));
|
||||
//Diminish dir length based on total luma
|
||||
float dirReduce = max((luma00 + luma10 + luma01 + luma11) * REDUCE_MUL, REDUCE_MIN);
|
||||
//Divide dir by the distance to nearest edge plus dirReduce
|
||||
float rcpDir = 1.0 / (min(abs(dir.x), abs(dir.y)) + dirReduce);
|
||||
//Multiply by reciprocal and limit to pixel span
|
||||
dir = clamp(dir * rcpDir, -SPAN_MAX, SPAN_MAX) * u_texel.xy;
|
||||
|
||||
//Average middle texels along dir line
|
||||
vec4 A = 0.5 * (
|
||||
texture(tex, uv - dir * (1.0/6.0)) +
|
||||
texture(tex, uv + dir * (1.0/6.0)));
|
||||
|
||||
//Average with outer texels along dir line
|
||||
vec4 B = A * 0.5 + 0.25 * (
|
||||
texture(tex, uv - dir * (0.5)) +
|
||||
texture(tex, uv + dir * (0.5)));
|
||||
|
||||
|
||||
//Get lowest and highest luma values
|
||||
float lumaMin = min(lumaCC, min(min(luma00, luma10), min(luma01, luma11)));
|
||||
float lumaMax = max(lumaCC, max(max(luma00, luma10), max(luma01, luma11)));
|
||||
|
||||
//Get average luma
|
||||
float lumaB = dot(B.rgb, luma);
|
||||
//If the average is outside the luma range, using the middle average
|
||||
return ((lumaB < lumaMin) || (lumaB > lumaMax)) ? A : B;
|
||||
}
|
||||
|
||||
void main(){
|
||||
|
||||
if(USE_AA == 1){
|
||||
outFragColor = fxaa(inputTexture, inTextCoord);
|
||||
outFragColor = gamma(outFragColor);
|
||||
return;
|
||||
}
|
||||
if(USE_AA == 2){
|
||||
|
||||
}
|
||||
if(USE_AA == 3){
|
||||
|
||||
}
|
||||
if(USE_AA == 4){
|
||||
|
||||
}
|
||||
outFragColor = gamma(texture(inputTexture,inTextCoord));
|
||||
}
|
||||
9
resources/EngineResources/shaders/post_process_vtx.glsl
Normal file
9
resources/EngineResources/shaders/post_process_vtx.glsl
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
#version 450
|
||||
|
||||
layout(location = 0 ) out vec2 outTextCoord;
|
||||
|
||||
void main()
|
||||
{
|
||||
outTextCoord = vec2((gl_VertexIndex << 1) & 2, gl_VertexIndex & 2);
|
||||
gl_Position = vec4(outTextCoord.x * 2.0f - 1.0f, outTextCoord.y * -2.0f + 1.0f,0.0f,1.0f);
|
||||
}
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
#version 450
|
||||
|
||||
const int MAX_TEXTURES = 100;
|
||||
const int MAX_TEXTURES = 500;
|
||||
|
||||
layout(location = 0) in vec2 inTextCoords;
|
||||
layout(location = 0) out vec4 outFragColor;
|
||||
|
|
@ -26,7 +26,9 @@ void main()
|
|||
{
|
||||
Material material = matUniform.materials[push_constants.materialIdx];
|
||||
if(material.hasTexture == 1){
|
||||
outFragColor = texture(textSampler[material.textureIdx],inTextCoords);
|
||||
vec4 texColor = texture(textSampler[material.textureIdx],inTextCoords);
|
||||
if(texColor.a < 0.1){discard;}
|
||||
outFragColor = texColor;
|
||||
} else{
|
||||
outFragColor = material.diffuseColor;
|
||||
}
|
||||
10
resources/EngineResources/shaders/swap_frag.glsl
Normal file
10
resources/EngineResources/shaders/swap_frag.glsl
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
#version 450
|
||||
layout(location = 0) in vec2 inTextCoord;
|
||||
layout(location = 0) out vec4 outFragColor;
|
||||
|
||||
layout(set = 0, binding = 0) uniform sampler2D albedoSampler;
|
||||
|
||||
void main() {
|
||||
vec3 albedo = texture(albedoSampler, inTextCoord).rgb;
|
||||
outFragColor = vec4(albedo,1.0);
|
||||
}
|
||||
8
resources/EngineResources/shaders/swap_vtx.glsl
Normal file
8
resources/EngineResources/shaders/swap_vtx.glsl
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
#version 450
|
||||
|
||||
layout(location = 0) out vec2 outTextCoord;
|
||||
|
||||
void main() {
|
||||
outTextCoord = vec2((gl_VertexIndex << 1) & 2, gl_VertexIndex & 2);
|
||||
gl_Position = vec4(outTextCoord.x * 2.0f - 1.0f, outTextCoord.y * -2.0f + 1.0f,0.0f,1.0f);
|
||||
}
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 96 KiB After Width: | Height: | Size: 64 KiB |
Loading…
Add table
Add a link
Reference in a new issue