summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCosmic Linden <cosmic@lindenlab.com>2023-10-13 09:58:05 -0700
committerCosmic Linden <cosmic@lindenlab.com>2023-10-13 09:58:05 -0700
commit039116abd4166903005b8de6fa5d64f0fdf75422 (patch)
tree4c5a18c44372620ac58fd6200ea25693cfb98878
parent5d046d8835563fcad9e8dcf948d889d9ccec41d7 (diff)
DRTVWR-592: (WIP) Roughly working draft of PBR terrain
-rw-r--r--indra/newview/app_settings/shaders/class1/deferred/pbrterrainF.glsl20
-rw-r--r--indra/newview/lldrawpoolterrain.cpp11
-rw-r--r--indra/newview/llfloaterregioninfo.cpp1
-rw-r--r--indra/newview/llvlcomposition.cpp1
4 files changed, 20 insertions, 13 deletions
diff --git a/indra/newview/app_settings/shaders/class1/deferred/pbrterrainF.glsl b/indra/newview/app_settings/shaders/class1/deferred/pbrterrainF.glsl
index 60e5776bc6..4de6b9609c 100644
--- a/indra/newview/app_settings/shaders/class1/deferred/pbrterrainF.glsl
+++ b/indra/newview/app_settings/shaders/class1/deferred/pbrterrainF.glsl
@@ -97,10 +97,11 @@ vec4 sample_and_mix_color4(float alpha1, float alpha2, float alphaFinal, vec2 te
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);
+ // TODO: Why is this needed for pbropaqueF but not here? (and is there different behavior with base color vs emissive color, that also needs to be corrected?)
+ //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);
}
@@ -116,20 +117,23 @@ vec4 sample_and_mix_vector(float alpha1, float alpha2, float alphaFinal, vec2 te
void main()
{
+ // Adjust the texture repeats for a more sensible default.
+ float texture_density_factor = 2.0;
+ vec2 terrain_texcoord = texture_density_factor * vary_texcoord0.xy;
float alpha1 = texture2D(alpha_ramp, vary_texcoord0.zw).a;
float alpha2 = texture2D(alpha_ramp,vary_texcoord1.xy).a;
float alphaFinal = texture2D(alpha_ramp, vary_texcoord1.zw).a;
- 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);
+ vec4 base_color = sample_and_mix_color4(alpha1, alpha2, alphaFinal, terrain_texcoord, 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)
{
discard;
}
- 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);
- 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 normal_texture = sample_and_mix_vector(alpha1, alpha2, alphaFinal, terrain_texcoord, detail_0_normal, detail_1_normal, detail_2_normal, detail_3_normal);
+ vec4 metallic_roughness = sample_and_mix_vector(alpha1, alpha2, alphaFinal, terrain_texcoord, detail_0_metallic_roughness, detail_1_metallic_roughness, detail_2_metallic_roughness, detail_3_metallic_roughness);
+ vec3 emissive_texture = sample_and_mix_color3(alpha1, alpha2, alphaFinal, terrain_texcoord, 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);
diff --git a/indra/newview/lldrawpoolterrain.cpp b/indra/newview/lldrawpoolterrain.cpp
index 2a0a7bad1c..204fbc56fd 100644
--- a/indra/newview/lldrawpoolterrain.cpp
+++ b/indra/newview/lldrawpoolterrain.cpp
@@ -370,6 +370,7 @@ void LLDrawPoolTerrain::renderFullShaderTextures()
gGL.getTexUnit(detail0)->activate();
}
+// TODO: Investigate use of bindFast for PBR terrain textures
void LLDrawPoolTerrain::renderFullShaderPBR()
{
// Hack! Get the region that this draw pool is rendering from!
@@ -386,7 +387,7 @@ void LLDrawPoolTerrain::renderFullShaderPBR()
tp0.setVec(sDetailScale, 0.0f, 0.0f, offset_x);
tp1.setVec(0.0f, sDetailScale, 0.0f, offset_y);
- constexpr U32 terrain_material_count = LLViewerShaderMgr::TERRAIN_DETAIL3_BASE_COLOR - LLViewerShaderMgr::TERRAIN_DETAIL0_BASE_COLOR;
+ constexpr U32 terrain_material_count = 1 + LLViewerShaderMgr::TERRAIN_DETAIL3_BASE_COLOR - LLViewerShaderMgr::TERRAIN_DETAIL0_BASE_COLOR;
S32 detail_basecolor[terrain_material_count];
S32 detail_normal[terrain_material_count];
S32 detail_metalrough[terrain_material_count];
@@ -456,12 +457,14 @@ void LLDrawPoolTerrain::renderFullShaderPBR()
// mAlphaCutoff is only valid for LLGLTFMaterial::ALPHA_MODE_MASK
// Use 0 here due to GLTF terrain blending (LLGLTFMaterial::bind uses
// -1 for easier debugging)
- F32 min_alpha = 0.f;
+ F32 min_alpha = -0.0f;
if (material->mAlphaMode == LLGLTFMaterial::ALPHA_MODE_MASK)
{
- min_alpha = material->mAlphaCutoff;
+ // dividing the alpha cutoff by transparency here allows the shader to compare against
+ // the alpha value of the texture without needing the transparency value
+ min_alpha = material->mAlphaCutoff/material->mBaseColor.mV[3];
}
-
+ minimum_alphas[i] = min_alpha;
}
shader->uniform4fv(LLShaderMgr::TERRAIN_BASE_COLOR_FACTORS, terrain_material_count, (F32*)base_color_factors);
shader->uniform4f(LLShaderMgr::TERRAIN_METALLIC_FACTORS, metallic_factors[0], metallic_factors[1], metallic_factors[2], metallic_factors[3]);
diff --git a/indra/newview/llfloaterregioninfo.cpp b/indra/newview/llfloaterregioninfo.cpp
index b5698c1d65..2635ac3a71 100644
--- a/indra/newview/llfloaterregioninfo.cpp
+++ b/indra/newview/llfloaterregioninfo.cpp
@@ -1531,7 +1531,6 @@ bool LLPanelRegionTerrainInfo::refreshFromRegion(LLViewerRegion* region)
LLVLComposition* compp = region->getComposition();
// Are these 4 texture IDs or 4 material IDs? Who knows! Let's set the IDs on both pickers for now.
- // *TODO: Determine the asset type of IDs, to determine which editing mode to display.
LLTextureCtrl* asset_ctrl;
std::string buffer;
for(S32 i = 0; i < TERRAIN_TEXTURE_COUNT; ++i)
diff --git a/indra/newview/llvlcomposition.cpp b/indra/newview/llvlcomposition.cpp
index 5d711f4e5d..815489f753 100644
--- a/indra/newview/llvlcomposition.cpp
+++ b/indra/newview/llvlcomposition.cpp
@@ -360,6 +360,7 @@ BOOL LLVLComposition::generateComposition()
return FALSE;
}
+// TODO: Re-evaluate usefulness of this function in the PBR case. There is currently a hack here to treat the material base color like a legacy terrain texture, but I'm not sure if that's useful.
BOOL LLVLComposition::generateTexture(const F32 x, const F32 y,
const F32 width, const F32 height)
{