diff options
Diffstat (limited to 'indra/newview/app_settings/shaders/class1/deferred/pbrterrainUtilF.glsl')
-rw-r--r-- | indra/newview/app_settings/shaders/class1/deferred/pbrterrainUtilF.glsl | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/indra/newview/app_settings/shaders/class1/deferred/pbrterrainUtilF.glsl b/indra/newview/app_settings/shaders/class1/deferred/pbrterrainUtilF.glsl index 5098de717e..dc43007dca 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/pbrterrainUtilF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/pbrterrainUtilF.glsl @@ -51,7 +51,12 @@ #define TERRAIN_PBR_DETAIL_NORMAL -2 #define TERRAIN_PBR_DETAIL_METALLIC_ROUGHNESS -3 +#define TERRAIN_PAINT_TYPE_HEIGHTMAP_WITH_NOISE 0 +#define TERRAIN_PAINT_TYPE_PBR_PAINTMAP 1 + +#if TERRAIN_PLANAR_TEXTURE_SAMPLE_COUNT == 3 in vec3 vary_vertex_normal; +#endif vec3 srgb_to_linear(vec3 c); @@ -202,6 +207,45 @@ TerrainMix get_terrain_mix_weights(float alpha1, float alpha2, float alphaFinal) return tm; } +// A paintmap weight applier for 4 swatches. The input saves a channel by not +// storing swatch 1, and assuming the weights of the 4 swatches add to 1. +// The components of weight3 should be between 0 and 1 +// The sum of the components of weight3 should be between 0 and 1 +TerrainMix get_terrain_usage_from_weight3(vec3 weight3) +{ + // These steps ensure the output weights add to between 0 and 1 + weight3.xyz = max(vec3(0.0), weight3.xyz); + weight3.xyz /= max(1.0, weight3.x + weight3.y + weight3.z); + + TerrainMix tm; + + // Extract the first weight from the other weights + tm.weight.x = 1.0 - (weight3.x + weight3.y + weight3.z); + tm.weight.yzw = weight3.xyz; + ivec4 usage = max(ivec4(0), ivec4(ceil(tm.weight))); + + tm.type = (usage.x * MIX_X) | + (usage.y * MIX_Y) | + (usage.z * MIX_Z) | + (usage.w * MIX_W); + return tm; +} + +// Inverse of get_terrain_usage_from_weight3, excluding usage flags +// The components of weight should be between 0 and 1 +// The sum of the components of weight should be 1 +vec3 get_weight3_from_terrain_weight(vec4 weight) +{ + // These steps ensure the input weights add to 1 + weight = max(vec4(0.0), weight); + weight.x += 1.0 - sign(weight.x + weight.y + weight.z + weight.w); + weight /= weight.x + weight.y + weight.z + weight.w; + + // Then return the input weights with the first weight truncated + return weight.yzw; +} + +#if TERRAIN_PLANAR_TEXTURE_SAMPLE_COUNT == 3 TerrainTriplanar _t_triplanar() { float sharpness = TERRAIN_TRIPLANAR_BLEND_FACTOR; @@ -219,6 +263,8 @@ TerrainTriplanar _t_triplanar() ((usage.z) * SAMPLE_Z); return tw; } +#endif + // Assume weights add to 1 float terrain_mix(TerrainMix tm, vec4 tms4) |