diff options
author | Cosmic Linden <cosmic@lindenlab.com> | 2023-10-13 09:57:57 -0700 |
---|---|---|
committer | Cosmic Linden <cosmic@lindenlab.com> | 2023-10-13 09:57:57 -0700 |
commit | 5d046d8835563fcad9e8dcf948d889d9ccec41d7 (patch) | |
tree | ad223ccf798181611d23e470a8c186d1fd2e0cab /indra/newview/app_settings/shaders | |
parent | a7cd5f6ef9d80e77eaf87cfc605d32605f0916f1 (diff) |
DRTVWR-592: (WIP) (does not work) PBR terrain rendering - compiles, but doesn't render properly just yet
Diffstat (limited to 'indra/newview/app_settings/shaders')
-rw-r--r-- | indra/newview/app_settings/shaders/class1/deferred/pbrterrainF.glsl | 41 | ||||
-rw-r--r-- | indra/newview/app_settings/shaders/class1/deferred/pbrterrainV.glsl | 8 |
2 files changed, 31 insertions, 18 deletions
diff --git a/indra/newview/app_settings/shaders/class1/deferred/pbrterrainF.glsl b/indra/newview/app_settings/shaders/class1/deferred/pbrterrainF.glsl index 4a0b324558..60e5776bc6 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/pbrterrainF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/pbrterrainF.glsl @@ -27,7 +27,6 @@ out vec4 frag_data[4]; uniform sampler2D alpha_ramp; -// TODO: Bind the right textures and uniforms during shader setup // *TODO: Configurable quality level which disables PBR features on machines // with limited texture availability // https://registry.khronos.org/glTF/specs/2.0/glTF-2.0.html#additional-textures @@ -65,7 +64,7 @@ vec2 encode_normal(vec3 n); vec3 linear_to_srgb(vec3 c); vec3 srgb_to_linear(vec3 c); -// TODO: This mixing function feels like it can be optimized. The terrain code's use of texcoord1 is dubious. It feels like the same thing can be accomplished with less memory bandwidth by calculating the offsets on-the-fly +// *TODO: This mixing function feels like it can be optimized. The terrain code's use of texcoord1 is dubious. It feels like the same thing can be accomplished with less memory bandwidth by calculating the offsets on-the-fly float terrain_mix(vec4 samples, float alpha1, float alpha2, float alphaFinal) { return mix( mix(samples.w, samples.z, alpha2), mix(samples.y, samples.x, alpha1), alphaFinal ); @@ -81,13 +80,27 @@ vec4 terrain_mix(vec4[4] samples, float alpha1, float alpha2, float alphaFinal) return mix( mix(samples[3], samples[2], alpha2), mix(samples[1], samples[0], alpha1), alphaFinal ); } -vec4 sample_and_mix_color(float alpha1, float alpha2, float alphaFinal, vec2 texcoord, sampler2D tex0, sampler2D tex1, sampler2D tex2, sampler2D tex3) +vec3 sample_and_mix_color3(float alpha1, float alpha2, float alphaFinal, vec2 texcoord, sampler2D tex0, sampler2D tex1, sampler2D tex2, sampler2D tex3) +{ + vec3[4] samples; + samples[0] = srgb_to_linear(texture2D(tex0, texcoord).xyz); + samples[1] = srgb_to_linear(texture2D(tex1, texcoord).xyz); + samples[2] = srgb_to_linear(texture2D(tex2, texcoord).xyz); + samples[3] = srgb_to_linear(texture2D(tex3, texcoord).xyz); + return terrain_mix(samples, alpha1, alpha2, alphaFinal); +} + +vec4 sample_and_mix_color4(float alpha1, float alpha2, float alphaFinal, vec2 texcoord, sampler2D tex0, sampler2D tex1, sampler2D tex2, sampler2D tex3) { vec4[4] samples; - samples[0] = srgb_to_linear(texture2D(tex0, texcoord)); - samples[1] = srgb_to_linear(texture2D(tex1, texcoord)); - samples[2] = srgb_to_linear(texture2D(tex2, texcoord)); - samples[3] = srgb_to_linear(texture2D(tex3, texcoord)); + samples[0] = texture2D(tex0, texcoord); + samples[1] = texture2D(tex1, texcoord); + samples[2] = texture2D(tex2, texcoord); + samples[3] = texture2D(tex3, texcoord); + samples[0].xyz = srgb_to_linear(samples[0].xyz); + samples[1].xyz = srgb_to_linear(samples[1].xyz); + samples[2].xyz = srgb_to_linear(samples[2].xyz); + samples[3].xyz = srgb_to_linear(samples[3].xyz); return terrain_mix(samples, alpha1, alpha2, alphaFinal); } @@ -107,7 +120,7 @@ void main() float alpha2 = texture2D(alpha_ramp,vary_texcoord1.xy).a; float alphaFinal = texture2D(alpha_ramp, vary_texcoord1.zw).a; - vec4 base_color = sample_and_mix_color(alpha1, alpha2, alphaFinal, vary_texcoord0.xy, detail_0_basecolor, detail_1_basecolor, detail_2_basecolor, detail_3_basecolor); + vec4 base_color = sample_and_mix_color4(alpha1, alpha2, alphaFinal, vary_texcoord0.xy, detail_0_base_color, detail_1_base_color, detail_2_base_color, detail_3_base_color); float minimum_alpha = terrain_mix(minimum_alphas, alpha1, alpha2, alphaFinal); if (base_color.a < minimum_alpha) { @@ -116,14 +129,14 @@ void main() vec4 normal_texture = sample_and_mix_vector(alpha1, alpha2, alphaFinal, vary_texcoord0.xy, detail_0_normal, detail_1_normal, detail_2_normal, detail_3_normal); vec4 metallic_roughness = sample_and_mix_vector(alpha1, alpha2, alphaFinal, vary_texcoord0.xy, detail_0_metallic_roughness, detail_1_metallic_roughness, detail_2_metallic_roughness, detail_3_metallic_roughness); - vec4 emissive_texture = sample_and_mix_color(alpha1, alpha2, alphaFinal, vary_texcoord0.xy, detail_0_emissive, detail_1_emissive, detail_2_emissive, detail_3_emissive); + vec3 emissive_texture = sample_and_mix_color3(alpha1, alpha2, alphaFinal, vary_texcoord0.xy, detail_0_emissive, detail_1_emissive, detail_2_emissive, detail_3_emissive); vec4 baseColorFactor = terrain_mix(baseColorFactors, alpha1, alpha2, alphaFinal); float metallicFactor = terrain_mix(metallicFactors, alpha1, alpha2, alphaFinal); float roughnessFactor = terrain_mix(roughnessFactors, alpha1, alpha2, alphaFinal); vec3 emissiveColor = terrain_mix(emissiveColors, alpha1, alpha2, alphaFinal); - vec3 col = baseColorFactor.rgb * srgb_to_linear(basecolor.rgb); + vec3 col = baseColorFactor.rgb * srgb_to_linear(base_color.rgb); // from mikktspace.com vec3 vNt = normal_texture.xyz*2.0-1.0; @@ -141,10 +154,10 @@ void main() // metal 0.0 vec3 spec = metallic_roughness.rgb; - spec.g *= roughness_factor; - spec.b *= metallic_factor; + spec.g *= roughnessFactor; + spec.b *= metallicFactor; - vec3 emissive = emssive_color; + vec3 emissive = emissiveColor; emissive *= emissive_texture.rgb; tnorm *= gl_FrontFacing ? 1.0 : -1.0; @@ -152,7 +165,7 @@ void main() frag_data[0] = max(vec4(col, 0.0), vec4(0)); // Diffuse frag_data[1] = max(vec4(spec.rgb,baseColorFactor.a), vec4(0)); // PBR linear packed Occlusion, Roughness, Metal. - frag_data[2] = max(vec4(encode_normal(tnorm), baseColorFactor.a, GBUFFER_FLAG_HAS_PBR | GBUFFER_FLAG_HAS_ATMOS), vec4(0)); // normal, environment intensity, flags + frag_data[2] = max(vec4(encode_normal(tnorm), baseColorFactor.a, GBUFFER_FLAG_HAS_PBR), vec4(0)); // normal, environment intensity, flags frag_data[3] = max(vec4(emissive,0), vec4(0)); // PBR sRGB Emissive } diff --git a/indra/newview/app_settings/shaders/class1/deferred/pbrterrainV.glsl b/indra/newview/app_settings/shaders/class1/deferred/pbrterrainV.glsl index cbfe9f3ea5..6037a58c0d 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/pbrterrainV.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/pbrterrainV.glsl @@ -73,9 +73,9 @@ void main() // *NOTE: KHR texture transform is ignored for now vary_texcoord0.xy = texgen_object(vec4(position, 1.0), vec4(texcoord0,0,1), texture_matrix0, object_plane_s, object_plane_t).xy; - vec4 t = vec4(texcoord1,0,1); + vec4 tc = vec4(texcoord1,0,1); - vary_texcoord0.zw = t.xy; - vary_texcoord1.xy = t.xy-vec2(2.0, 0.0); - vary_texcoord1.zw = t.xy-vec2(1.0, 0.0); + vary_texcoord0.zw = tc.xy; + vary_texcoord1.xy = tc.xy-vec2(2.0, 0.0); + vary_texcoord1.zw = tc.xy-vec2(1.0, 0.0); } |