DRTVWR-592: (WIP) Roughly working draft of PBR terrain

master
Cosmic Linden 2023-10-13 09:58:05 -07:00
parent 5d046d8835
commit 039116abd4
4 changed files with 20 additions and 13 deletions

View File

@ -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);

View File

@ -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]);

View File

@ -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)

View File

@ -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)
{