1
0
mirror of https://github.com/godotengine/godot.git synced 2025-11-22 15:06:45 +00:00

Use best fit normals for storing screen space normals

This commit is contained in:
clayjohn
2023-12-18 15:35:26 -07:00
parent bf8dd73e9d
commit 43cf21cb71
19 changed files with 207 additions and 41 deletions

View File

@@ -20,6 +20,7 @@
#define FLAG_SRGB (1 << 4)
#define FLAG_ALPHA_TO_ONE (1 << 5)
#define FLAG_LINEAR (1 << 6)
#define FLAG_NORMAL (1 << 7)
#ifdef MULTIVIEW
layout(location = 0) out vec3 uv_interp;
@@ -77,6 +78,7 @@ void main() {
#define FLAG_SRGB (1 << 4)
#define FLAG_ALPHA_TO_ONE (1 << 5)
#define FLAG_LINEAR (1 << 6)
#define FLAG_NORMAL (1 << 7)
layout(push_constant, std430) uniform Params {
vec4 section;
@@ -192,6 +194,9 @@ void main() {
if (bool(params.flags & FLAG_LINEAR)) {
color.rgb = srgb_to_linear(color.rgb);
}
if (bool(params.flags & FLAG_NORMAL)) {
color.rgb = normalize(color.rgb * 2.0 - 1.0) * 0.5 + 0.5;
}
frag_color = color / params.luminance_multiplier;
#endif // MODE_SET_COLOR

View File

@@ -65,8 +65,12 @@ void main() {
vec3 vertex = reconstructCSPosition(uv * vec2(params.screen_size), base_depth);
vec4 normal_roughness = imageLoad(source_normal_roughness, ssC);
vec3 normal = normal_roughness.xyz * 2.0 - 1.0;
vec3 normal = normalize(normal_roughness.xyz * 2.0 - 1.0);
float roughness = normal_roughness.w;
if (roughness > 0.5) {
roughness = 1.0 - roughness;
}
roughness /= (127.0 / 255.0);
// The roughness cutoff of 0.6 is chosen to match the roughness fadeout from GH-69828.
if (roughness > 0.6) {

View File

@@ -59,8 +59,13 @@ void main() {
color += texelFetch(source_ssr, ofs, 0);
float d = texelFetch(source_depth, ofs, 0).r;
vec4 nr = texelFetch(source_normal, ofs, 0);
normal.xyz += nr.xyz * 2.0 - 1.0;
normal.w += nr.w;
normal.xyz += normalize(nr.xyz * 2.0 - 1.0);
float roughness = normal.w;
if (roughness > 0.5) {
roughness = 1.0 - roughness;
}
roughness /= (127.0 / 255.0);
normal.w += roughness;
if (sc_multiview) {
// we're doing a full unproject so we need the value as is.
@@ -81,6 +86,7 @@ void main() {
depth /= 4.0;
normal.xyz = normalize(normal.xyz / 4.0) * 0.5 + 0.5;
normal.w /= 4.0;
normal.w = normal.w * (127.0 / 255.0);
} else {
ivec2 ofs = ssC << 1;

View File

@@ -158,21 +158,16 @@ vec4 calculate_edges(const float p_center_z, const float p_left_z, const float p
return clamp((1.3 - edgesLRTB / (p_center_z * 0.040)), 0.0, 1.0);
}
vec3 decode_normal(vec3 p_encoded_normal) {
vec3 normal = p_encoded_normal * 2.0 - 1.0;
return normal;
}
vec3 load_normal(ivec2 p_pos) {
vec3 encoded_normal = imageLoad(source_normal, p_pos).xyz;
encoded_normal.z = 1.0 - encoded_normal.z;
return decode_normal(encoded_normal);
vec3 encoded_normal = normalize(imageLoad(source_normal, p_pos).xyz * 2.0 - 1.0);
encoded_normal.z = -encoded_normal.z;
return encoded_normal;
}
vec3 load_normal(ivec2 p_pos, ivec2 p_offset) {
vec3 encoded_normal = imageLoad(source_normal, p_pos + p_offset).xyz;
encoded_normal.z = 1.0 - encoded_normal.z;
return decode_normal(encoded_normal);
vec3 encoded_normal = normalize(imageLoad(source_normal, p_pos + p_offset).xyz * 2.0 - 1.0);
encoded_normal.z = -encoded_normal.z;
return encoded_normal;
}
// all vectors in viewspace

View File

@@ -159,21 +159,16 @@ vec4 calculate_edges(const float p_center_z, const float p_left_z, const float p
return clamp((1.3 - edgesLRTB / (p_center_z * 0.040)), 0.0, 1.0);
}
vec3 decode_normal(vec3 p_encoded_normal) {
vec3 normal = p_encoded_normal * 2.0 - 1.0;
return normal;
}
vec3 load_normal(ivec2 p_pos) {
vec3 encoded_normal = imageLoad(source_normal, p_pos).xyz;
encoded_normal.z = 1.0 - encoded_normal.z;
return decode_normal(encoded_normal);
vec3 encoded_normal = normalize(imageLoad(source_normal, p_pos).xyz * 2.0 - 1.0);
encoded_normal.z = -encoded_normal.z;
return encoded_normal;
}
vec3 load_normal(ivec2 p_pos, ivec2 p_offset) {
vec3 encoded_normal = imageLoad(source_normal, p_pos + p_offset).xyz;
encoded_normal.z = 1.0 - encoded_normal.z;
return decode_normal(encoded_normal);
vec3 encoded_normal = normalize(imageLoad(source_normal, p_pos + p_offset).xyz * 2.0 - 1.0);
encoded_normal.z = -encoded_normal.z;
return encoded_normal;
}
// all vectors in viewspace