diff options
| author | Cosmic Linden <cosmic@lindenlab.com> | 2023-10-13 10:41:19 -0700 | 
|---|---|---|
| committer | Cosmic Linden <cosmic@lindenlab.com> | 2023-10-13 10:41:19 -0700 | 
| commit | be39e92f7d3c6df80eeb1f183723978ce1bf1b52 (patch) | |
| tree | 881f2c3a52d1e9527fc3d5661e3a6d83fbe3038f | |
| parent | fb12fb4bf7bbbf457b4f81356b0d0fadf2b42664 (diff) | |
DRTVWR-592: (WIP) (has debug) Fix "ant trail" seams in terrain caused by multiple texture lookups in a switch..case block
| -rw-r--r-- | indra/newview/app_settings/shaders/class1/deferred/pbrterrainF.glsl | 2 | ||||
| -rw-r--r-- | indra/newview/app_settings/shaders/class1/deferred/pbrterrainUtilF.glsl | 44 | 
2 files changed, 44 insertions, 2 deletions
diff --git a/indra/newview/app_settings/shaders/class1/deferred/pbrterrainF.glsl b/indra/newview/app_settings/shaders/class1/deferred/pbrterrainF.glsl index 19de8568b8..ba917416ce 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/pbrterrainF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/pbrterrainF.glsl @@ -135,7 +135,7 @@ void main()      tnorm *= gl_FrontFacing ? 1.0 : -1.0; -#if 1 // TODO: Remove debug +#if 0 // TODO: Remove debug      //col.xyz = (tnorm + 1.0) / 2.0;// TODO: Remove      //col.xyz = (vary_normal + 1.0) / 2.0;// TODO: Remove      //col.xyz = spec; // TODO: Remove diff --git a/indra/newview/app_settings/shaders/class1/deferred/pbrterrainUtilF.glsl b/indra/newview/app_settings/shaders/class1/deferred/pbrterrainUtilF.glsl index a40f70a9e2..fc04afe513 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/pbrterrainUtilF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/pbrterrainUtilF.glsl @@ -131,7 +131,7 @@ TerrainSample _t_sample(sampler2D tex, TerrainCoord terrain_coord, TerrainWeight  {      TerrainSample ts; -#if 1 +#if 0  // This demonstrates the case when the bug occurs: Sampling in switch..case  #if 0  #define do_sample_x() _t_texture(tex, terrain_coord[0].zw, sign(vary_vertex_normal.x)) @@ -142,7 +142,12 @@ TerrainSample _t_sample(sampler2D tex, TerrainCoord terrain_coord, TerrainWeight  #define do_sample_y() _t_texture(tex, terrain_coord[0].xy, sign(vary_vertex_normal.z))  #endif  #define do_sample_z() _t_texture(tex, terrain_coord[0].xy, sign(vary_vertex_normal.z)) +#if 0      switch (tw.type) +#else // TODO: Remove debug +// Bug still occurs when the type is masked +    switch (tw.type & (SAMPLE_X | SAMPLE_Y | SAMPLE_Z)) +#endif      {          case (SAMPLE_X | SAMPLE_Y | SAMPLE_Z):              ts.x = do_sample_x(); @@ -186,6 +191,7 @@ TerrainSample _t_sample(sampler2D tex, TerrainCoord terrain_coord, TerrainWeight              break;      }  #else // TODO: Remove debug +#if 0  // This demonstrates the case when the bug does not occur: Sampling beforehand and assigning in switch..case  // This otherwise uses the same logic as in the case that reproduces the bug.  #define do_sample_x() _t_texture(tex, terrain_coord[0].zw, sign(vary_vertex_normal.x)) @@ -237,6 +243,42 @@ TerrainSample _t_sample(sampler2D tex, TerrainCoord terrain_coord, TerrainWeight              ts.z = ts.x;              break;      } +#else // TODO: Keep? +// Test case where the switch..case is broken up into three parts +// This fixes unexplained, "ant trail" seams in terrain. (as seen on Nvidia/Windows 10) +// The extra two branches are not free, but it's still a performance win +// compared to sampling along all three axes for every terrain fragment. +#define do_sample_x() _t_texture(tex, terrain_coord[0].zw, sign(vary_vertex_normal.x)) +#define do_sample_y() _t_texture(tex, terrain_coord[1].xy, sign(vary_vertex_normal.y)) +#define do_sample_z() _t_texture(tex, terrain_coord[0].xy, sign(vary_vertex_normal.z)) +switch (tw.type & SAMPLE_X) +{ +    case SAMPLE_X: +        ts.x = do_sample_x(); +    break; +    default: +        ts.x = vec4(1.0, 0.0, 1.0, 1.0); +    break; +} +switch (tw.type & SAMPLE_Y) +{ +    case SAMPLE_Y: +        ts.y = do_sample_y(); +    break; +    default: +        ts.y = vec4(1.0, 0.0, 1.0, 1.0); +    break; +} +switch (tw.type & SAMPLE_Z) +{ +    case SAMPLE_Z: +        ts.z = do_sample_z(); +    break; +    default: +        ts.z = vec4(1.0, 0.0, 1.0, 1.0); +    break; +} +#endif  #endif      return ts;  | 
