FXAA + Fiddling
Signed-off-by: Robear Selwans <robear.selwans@outlook.com>
This commit is contained in:
@@ -37,4 +37,9 @@ vec3 fresnelSchlick(float cosTheta, vec3 F0)
|
||||
return F0 + (1.0 - F0) * pow(1.0 - cosTheta, 5.0);
|
||||
}
|
||||
|
||||
vec3 fresnelSchlickRoughness(float cosTheta, vec3 F0, float roughness)
|
||||
{
|
||||
return F0 + (max(vec3(1.0 - roughness), F0) - F0) * pow(max(1.0 - cosTheta, 0.0), 5.0);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -41,16 +41,16 @@ void main()
|
||||
vec3 normal = gnormal.xyz;
|
||||
vec3 albedo = galbedo.xyz;
|
||||
vec3 spec = gspec.xyz;
|
||||
float specFactor = gspec.w;
|
||||
|
||||
float metallicFactor = gspec.w;
|
||||
float metallicFactor = gposition.w;
|
||||
float roughnessFactor = galbedo.w;
|
||||
float ao = gnormal.w;
|
||||
|
||||
vec3 V = normalize(cameraPos - position);
|
||||
|
||||
vec3 F0 = vec3(0.04);
|
||||
F0 = mix(F0, albedo, metallicFactor);
|
||||
float reflectance = max(max(F0.x,F0.y),F0.z);
|
||||
vec3 F0 = mix(vec3(0.04), albedo, metallicFactor);
|
||||
vec3 F = fresnelSchlickRoughness(max(dot(normal, V), 0.0), F0, roughnessFactor);
|
||||
|
||||
vec3 Lo = vec3(0);
|
||||
for(int i = 0; i < PushConstants.lightCount; ++i)
|
||||
@@ -63,12 +63,12 @@ void main()
|
||||
float attenuation = 1.0 / (distance * distance);
|
||||
vec3 radiance = l.color.xyz * attenuation * l.intensity;
|
||||
|
||||
vec3 F = fresnelSchlick(max(dot(H, V), 0.0), F0);
|
||||
float NDF = DistributionGGX(normal, H, roughnessFactor);
|
||||
float G = GeometrySmith(normal, V, L, roughnessFactor);
|
||||
|
||||
vec3 numerator = NDF * G * F;
|
||||
float denominator = 4.0 * max(dot(normal, V), 0.0) * max(dot(normal, L), 0.0);
|
||||
|
||||
vec3 specular = numerator / max(denominator, 0.001);
|
||||
|
||||
vec3 kS = F;
|
||||
@@ -83,11 +83,13 @@ void main()
|
||||
|
||||
vec3 color = ambient + Lo;
|
||||
|
||||
//color = color + spec * reflectance;
|
||||
color = mix(color, spec, reflectance);
|
||||
color += spec * specFactor;
|
||||
// color = mix(color, spec, specFactor);
|
||||
|
||||
//color = color / (color + vec3(1.0));
|
||||
// float reflectance = max(max(F.x, F.y), F.z);
|
||||
// float reflectance = max(max(F0.x, F0.y), F0.z);
|
||||
|
||||
//outColor = vec4(color, 1.0);
|
||||
outColor = vec4(color, 1.0);
|
||||
// outColor = vec4(vec3(reflectance), 1.0);
|
||||
}
|
||||
|
||||
@@ -1,13 +1,69 @@
|
||||
#version 450
|
||||
|
||||
layout(set = 0, binding = 0) uniform sampler2D ppIN;
|
||||
layout(set = 0, binding = 0) uniform sampler2D ppIn;
|
||||
|
||||
layout (location = 0) in vec2 outUV;
|
||||
// layout (location = 0) in vec2 uv;
|
||||
|
||||
layout(location = 0) out vec4 outColor;
|
||||
|
||||
const vec2 resolution = vec2(1920, 1080);
|
||||
|
||||
#define FXAA_SUBPIX_SHIFT (1.0/4.0)
|
||||
#define FXAA_SPAN_MAX 32.0
|
||||
#define FXAA_REDUCE_MUL (1.0/FXAA_SPAN_MAX)
|
||||
#define FXAA_REDUCE_MIN (1.0/256.0)
|
||||
|
||||
void main()
|
||||
{
|
||||
vec3 color = texture(ppIN, outUV).rgb;
|
||||
outColor = vec4(color, 1.0);
|
||||
vec2 rcpFrame = 1./resolution.xy;
|
||||
vec2 uv2 = gl_FragCoord.xy / resolution.xy;
|
||||
|
||||
vec4 uv = vec4(uv2, uv2 - (rcpFrame * (0.5 + FXAA_SUBPIX_SHIFT)));
|
||||
|
||||
vec3 luma = vec3(0.299, 0.587, 0.114);
|
||||
|
||||
vec3 rgbNW = texture(ppIn, uv.zw).xyz;
|
||||
vec3 rgbNE = texture(ppIn, uv.zw + vec2(1,0)*rcpFrame.xy).xyz;
|
||||
vec3 rgbSW = texture(ppIn, uv.zw + vec2(0,1)*rcpFrame.xy).xyz;
|
||||
vec3 rgbSE = texture(ppIn, uv.zw + vec2(1,1)*rcpFrame.xy).xyz;
|
||||
vec3 rgbM = texture(ppIn, uv.xy).xyz;
|
||||
|
||||
float lumaNW = dot(rgbNW, luma);
|
||||
float lumaNE = dot(rgbNE, luma);
|
||||
float lumaSW = dot(rgbSW, luma);
|
||||
float lumaSE = dot(rgbSE, luma);
|
||||
float lumaM = dot(rgbM, luma);
|
||||
|
||||
float lumaMin = min(lumaM, min(min(lumaNW, lumaNE), min(lumaSW, lumaSE)));
|
||||
float lumaMax = max(lumaM, max(max(lumaNW, lumaNE), max(lumaSW, lumaSE)));
|
||||
|
||||
vec2 dir;
|
||||
dir.x = -((lumaNW + lumaNE) - (lumaSW + lumaSE));
|
||||
dir.y = ((lumaNW + lumaSW) - (lumaNE + lumaSE));
|
||||
|
||||
float dirReduce = max(
|
||||
(lumaNW + lumaNE + lumaSW + lumaSE) * (0.25 * FXAA_REDUCE_MUL),
|
||||
FXAA_REDUCE_MIN);
|
||||
float rcpDirMin = 1.0/(min(abs(dir.x), abs(dir.y)) + dirReduce);
|
||||
|
||||
dir = min(vec2( FXAA_SPAN_MAX, FXAA_SPAN_MAX),
|
||||
max(vec2(-FXAA_SPAN_MAX, -FXAA_SPAN_MAX),
|
||||
dir * rcpDirMin)) * rcpFrame.xy;
|
||||
|
||||
vec3 rgbA = (1.0/2.0) * (
|
||||
texture(ppIn, uv.xy + dir * (1.0/3.0 - 0.5)).xyz +
|
||||
texture(ppIn, uv.xy + dir * (2.0/3.0 - 0.5)).xyz);
|
||||
vec3 rgbB = rgbA * (1.0/2.0) + (1.0/4.0) * (
|
||||
texture(ppIn, uv.xy + dir * (0.0/3.0 - 0.5)).xyz +
|
||||
texture(ppIn, uv.xy + dir * (3.0/3.0 - 0.5)).xyz);
|
||||
|
||||
float lumaB = dot(rgbB, luma);
|
||||
|
||||
if((lumaB < lumaMin) || (lumaB > lumaMax))
|
||||
outColor = vec4(rgbA, 1.0);
|
||||
else
|
||||
outColor = vec4(rgbB, 1.0);
|
||||
|
||||
if(uv.x < 0.5)
|
||||
outColor = vec4(rgbM, 1.0);
|
||||
}
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
#version 450
|
||||
|
||||
layout (location = 0) out vec2 outUV;
|
||||
/* layout (location = 0) out vec2 outUV; */
|
||||
|
||||
void main()
|
||||
{
|
||||
outUV = vec2((gl_VertexIndex << 1) & 2, gl_VertexIndex & 2);
|
||||
vec2 outUV = vec2((gl_VertexIndex << 1) & 2, gl_VertexIndex & 2);
|
||||
gl_Position = vec4(outUV * 2.0f - 1.0f, 0.0f, 1.0f);
|
||||
}
|
||||
|
||||
+11
-11
@@ -61,15 +61,6 @@ layout (location = 1) out vec4 gNormal;
|
||||
layout (location = 2) out vec4 gAlbedo;
|
||||
layout (location = 3) out vec4 gSpecular;
|
||||
|
||||
float near = 0.001;
|
||||
float far = 50.0;
|
||||
|
||||
float LinearizeDepth(float depth)
|
||||
{
|
||||
float z = depth * 2.0 - 1.0; // back to NDC
|
||||
return (2.0 * near * far) / (far + near - z * (far - near));
|
||||
}
|
||||
|
||||
void main() {
|
||||
Material material = MaterialBuffers.materials[ PushConstants.materialBufferIndex ];
|
||||
|
||||
@@ -99,9 +90,17 @@ void main() {
|
||||
} else {
|
||||
outSpecular = LinearToSRGB(texture(texSampler[material.metallicRoughnessTexture], uv)).xyz;
|
||||
|
||||
float metallicFactor = outSpecular.z;
|
||||
float roughnessFactor = outSpecular.y;
|
||||
// vec3 F0 = mix(vec3(0.04), outColor, (metallicFactor - roughnessFactor));
|
||||
// float reflectance = max(max(F0.x, F0.y), F0.z);
|
||||
// float reflectance = (metallicFactor + roughnessFactor) * 0.5;
|
||||
float reflectance = 1.0 - roughnessFactor;
|
||||
|
||||
gNormal.w = outSpecular.x;
|
||||
gAlbedo.w = outSpecular.y;
|
||||
gSpecular.w = outSpecular.z;
|
||||
gAlbedo.w = roughnessFactor;
|
||||
gPosition.w = metallicFactor;
|
||||
gSpecular.w = reflectance;
|
||||
}
|
||||
|
||||
vec3 I = normalize(outpos.xyz - cameraPos);
|
||||
@@ -109,6 +108,7 @@ void main() {
|
||||
//R = R * -1;
|
||||
outSpecular = texture(skybox, R).rgb;
|
||||
|
||||
|
||||
gPosition = outpos;
|
||||
gNormal.xyz = outNormal;
|
||||
gAlbedo.xyz = outColor;
|
||||
|
||||
Reference in New Issue
Block a user