FXAA + Fiddling

Signed-off-by: Robear Selwans <robear.selwans@outlook.com>
This commit is contained in:
2021-07-21 11:58:18 +02:00
parent b50a22f4bf
commit 53e1385cfe
10 changed files with 95 additions and 32 deletions
+5
View File
@@ -37,4 +37,9 @@ vec3 fresnelSchlick(float cosTheta, vec3 F0)
return F0 + (1.0 - F0) * pow(1.0 - cosTheta, 5.0); 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 #endif
+10 -8
View File
@@ -41,16 +41,16 @@ void main()
vec3 normal = gnormal.xyz; vec3 normal = gnormal.xyz;
vec3 albedo = galbedo.xyz; vec3 albedo = galbedo.xyz;
vec3 spec = gspec.xyz; vec3 spec = gspec.xyz;
float specFactor = gspec.w;
float metallicFactor = gspec.w; float metallicFactor = gposition.w;
float roughnessFactor = galbedo.w; float roughnessFactor = galbedo.w;
float ao = gnormal.w; float ao = gnormal.w;
vec3 V = normalize(cameraPos - position); vec3 V = normalize(cameraPos - position);
vec3 F0 = vec3(0.04); vec3 F0 = mix(vec3(0.04), albedo, metallicFactor);
F0 = mix(F0, albedo, metallicFactor); vec3 F = fresnelSchlickRoughness(max(dot(normal, V), 0.0), F0, roughnessFactor);
float reflectance = max(max(F0.x,F0.y),F0.z);
vec3 Lo = vec3(0); vec3 Lo = vec3(0);
for(int i = 0; i < PushConstants.lightCount; ++i) for(int i = 0; i < PushConstants.lightCount; ++i)
@@ -63,12 +63,12 @@ void main()
float attenuation = 1.0 / (distance * distance); float attenuation = 1.0 / (distance * distance);
vec3 radiance = l.color.xyz * attenuation * l.intensity; 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 NDF = DistributionGGX(normal, H, roughnessFactor);
float G = GeometrySmith(normal, V, L, roughnessFactor); float G = GeometrySmith(normal, V, L, roughnessFactor);
vec3 numerator = NDF * G * F; vec3 numerator = NDF * G * F;
float denominator = 4.0 * max(dot(normal, V), 0.0) * max(dot(normal, L), 0.0); float denominator = 4.0 * max(dot(normal, V), 0.0) * max(dot(normal, L), 0.0);
vec3 specular = numerator / max(denominator, 0.001); vec3 specular = numerator / max(denominator, 0.001);
vec3 kS = F; vec3 kS = F;
@@ -83,11 +83,13 @@ void main()
vec3 color = ambient + Lo; vec3 color = ambient + Lo;
//color = color + spec * reflectance; color += spec * specFactor;
color = mix(color, spec, reflectance); // color = mix(color, spec, specFactor);
//color = color / (color + vec3(1.0)); //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(color, 1.0);
// outColor = vec4(vec3(reflectance), 1.0);
} }
+60 -4
View File
@@ -1,13 +1,69 @@
#version 450 #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; 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() void main()
{ {
vec3 color = texture(ppIN, outUV).rgb; vec2 rcpFrame = 1./resolution.xy;
outColor = vec4(color, 1.0); 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);
} }
+2 -2
View File
@@ -1,9 +1,9 @@
#version 450 #version 450
layout (location = 0) out vec2 outUV; /* layout (location = 0) out vec2 outUV; */
void main() 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); gl_Position = vec4(outUV * 2.0f - 1.0f, 0.0f, 1.0f);
} }
+11 -11
View File
@@ -61,15 +61,6 @@ layout (location = 1) out vec4 gNormal;
layout (location = 2) out vec4 gAlbedo; layout (location = 2) out vec4 gAlbedo;
layout (location = 3) out vec4 gSpecular; 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() { void main() {
Material material = MaterialBuffers.materials[ PushConstants.materialBufferIndex ]; Material material = MaterialBuffers.materials[ PushConstants.materialBufferIndex ];
@@ -99,9 +90,17 @@ void main() {
} else { } else {
outSpecular = LinearToSRGB(texture(texSampler[material.metallicRoughnessTexture], uv)).xyz; 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; gNormal.w = outSpecular.x;
gAlbedo.w = outSpecular.y; gAlbedo.w = roughnessFactor;
gSpecular.w = outSpecular.z; gPosition.w = metallicFactor;
gSpecular.w = reflectance;
} }
vec3 I = normalize(outpos.xyz - cameraPos); vec3 I = normalize(outpos.xyz - cameraPos);
@@ -109,6 +108,7 @@ void main() {
//R = R * -1; //R = R * -1;
outSpecular = texture(skybox, R).rgb; outSpecular = texture(skybox, R).rgb;
gPosition = outpos; gPosition = outpos;
gNormal.xyz = outNormal; gNormal.xyz = outNormal;
gAlbedo.xyz = outColor; gAlbedo.xyz = outColor;
+1 -1
View File
@@ -45,5 +45,5 @@
"path": "scenes://CesiumMilkTruck.evsc" "path": "scenes://CesiumMilkTruck.evsc"
} }
], ],
"activeScene": "CesiumMilkTruck" "activeScene": "DamagedHelmetScene"
} }
+2 -2
View File
@@ -66,9 +66,9 @@
}, },
{ {
"color": [1.0, 1.0, 1.0, 1.0], "color": [1.0, 1.0, 1.0, 1.0],
"intensity": 200, "intensity": 20,
"type": "LightComponent" "type": "LightComponent"
}, }
] ]
}, },
{ {
+2 -2
View File
@@ -3260,7 +3260,7 @@
}, },
{ {
"color": [1.0, 1.0, 1.0, 1.0], "color": [1.0, 1.0, 1.0, 1.0],
"intensity": 200, "intensity": 10,
"type": "LightComponent" "type": "LightComponent"
} }
], ],
@@ -3338,7 +3338,7 @@
}, },
{ {
"color": [1.0, 1.0, 1.0, 1.0], "color": [1.0, 1.0, 1.0, 1.0],
"intensity": 2, "intensity": 10,
"type": "LightComponent" "type": "LightComponent"
} }
], ],
+1 -1
View File
@@ -1,5 +1,5 @@
this.on_init = function() this.on_init = function()
this.speed = 0.1 this.speed = 0.01
this.angles = Vec3:new() this.angles = Vec3:new()
this.mouse_sens = 0.01 this.mouse_sens = 0.01
end end
+1 -1
View File
@@ -5,5 +5,5 @@ end
this.on_update = function() this.on_update = function()
rotationSpeed = 0.001 rotationSpeed = 0.001
this.angles.y = this.angles.y - rotationSpeed this.angles.y = this.angles.y - rotationSpeed
this.eulerAngles = this.angles -- this.eulerAngles = this.angles
end end