summaryrefslogtreecommitdiff
path: root/indra/newview
diff options
context:
space:
mode:
Diffstat (limited to 'indra/newview')
-rw-r--r--indra/newview/app_settings/shaders/class1/deferred/pbrterrainF.glsl25
-rw-r--r--indra/newview/app_settings/shaders/class1/deferred/pbrterrainV.glsl22
-rw-r--r--indra/newview/lldrawpoolterrain.cpp4
-rw-r--r--indra/newview/llsurfacepatch.cpp14
-rw-r--r--indra/newview/llsurfacepatch.h2
-rw-r--r--indra/newview/llviewercontrol.cpp10
-rw-r--r--indra/newview/llvlcomposition.cpp8
-rw-r--r--indra/newview/llvlcomposition.h2
-rw-r--r--indra/newview/llvosurfacepatch.cpp6
9 files changed, 71 insertions, 22 deletions
diff --git a/indra/newview/app_settings/shaders/class1/deferred/pbrterrainF.glsl b/indra/newview/app_settings/shaders/class1/deferred/pbrterrainF.glsl
index 73d4d9e3bc..5f94855963 100644
--- a/indra/newview/app_settings/shaders/class1/deferred/pbrterrainF.glsl
+++ b/indra/newview/app_settings/shaders/class1/deferred/pbrterrainF.glsl
@@ -70,6 +70,7 @@ vec2 encode_normal(vec3 n);
vec3 linear_to_srgb(vec3 c);
vec3 srgb_to_linear(vec3 c);
+in vec4 debug_pos; // TODO: Remove
// *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)
{
@@ -148,9 +149,8 @@ vec3 sample_and_mix_vector3_no_scale(float alpha1, float alpha2, float alphaFina
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;
+ vec2 terrain_texcoord = vary_texcoord0.xy;
+ terrain_texcoord -= vec2(21.0);// TODO: Remove
float alpha1 = texture(alpha_ramp, vary_texcoord0.zw).a;
float alpha2 = texture(alpha_ramp,vary_texcoord1.xy).a;
float alphaFinal = texture(alpha_ramp, vary_texcoord1.zw).a;
@@ -162,6 +162,25 @@ void main()
discard;
}
+ // TODO: Remove all of this
+ float debug_pos_x = debug_pos.x;
+ //float debug_pos_x = terrain_texcoord.y;
+ float debug_metric = debug_pos_x;
+ debug_metric = debug_metric - floor(debug_metric);
+ debug_metric *= debug_metric;
+ float debug_metric2 = debug_pos_x / 4.0;
+ debug_metric2 = debug_metric2 - floor(debug_metric2);
+ debug_metric2 *= debug_metric2;
+ debug_metric2 *= debug_metric2;
+ debug_metric2 *= 16.0;
+ float debug_metric3 = debug_pos_x / 16.0;
+ debug_metric3 = debug_metric3 - floor(debug_metric3);
+ debug_metric3 *= debug_metric3;
+ debug_metric3 *= debug_metric3;
+ debug_metric3 *= debug_metric3;
+ debug_metric3 *= 16.0;
+ //col.xyz = vec3(debug_metric3, debug_metric2, debug_metric);// TODO: Remove
+
vec3 normal_texture = sample_and_mix_vector3_no_scale(alpha1, alpha2, alphaFinal, terrain_texcoord, detail_0_normal, detail_1_normal, detail_2_normal, detail_3_normal);
vec3[4] orm_factors;
diff --git a/indra/newview/app_settings/shaders/class1/deferred/pbrterrainV.glsl b/indra/newview/app_settings/shaders/class1/deferred/pbrterrainV.glsl
index 6037a58c0d..fd80d1bb2c 100644
--- a/indra/newview/app_settings/shaders/class1/deferred/pbrterrainV.glsl
+++ b/indra/newview/app_settings/shaders/class1/deferred/pbrterrainV.glsl
@@ -43,24 +43,27 @@ out vec4 vary_texcoord1;
uniform vec4 object_plane_s;
uniform vec4 object_plane_t;
-vec4 texgen_object(vec4 vpos, vec4 tc, mat4 mat, vec4 tp0, vec4 tp1)
+vec4 texgen_object_pbr(vec4 tc, mat4 mat, vec4 tp0, vec4 tp1)
{
vec4 tcoord;
- tcoord.x = dot(vpos, tp0);
- tcoord.y = dot(vpos, tp1);
- tcoord.z = tc.z;
- tcoord.w = tc.w;
+ tcoord.x = dot(tc, tp0);
+ tcoord.y = dot(tc, tp1);
+ tcoord.z = tcoord.z;
+ tcoord.w = tcoord.w;
tcoord = mat * tcoord;
- return tcoord;
+ return tcoord;
}
+out vec4 debug_pos; // TODO: Remove
+
void main()
{
//transform vertex
gl_Position = modelview_projection_matrix * vec4(position.xyz, 1.0);
+ debug_pos = vec4(texcoord0, 0.0, 1.0);
vec3 n = normal_matrix * normal;
vec3 t = normal_matrix * tangent.xyz;
@@ -71,7 +74,12 @@ void main()
// Transform and pass tex coords
// *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;
+ vary_texcoord0.xy = texgen_object_pbr(vec4(texcoord0, 0, 1), texture_matrix0, object_plane_s, object_plane_t).xy;
+ // Adjust the texture repeats for a more sensible default.
+ // *TODO: Remove this extra factor when KHR texture transform is added
+ float texture_density_factor = 3.0;
+ //texture_density_factor /= 256.0; // TODO: Remove
+ vary_texcoord0.xy *= texture_density_factor;
vec4 tc = vec4(texcoord1,0,1);
diff --git a/indra/newview/lldrawpoolterrain.cpp b/indra/newview/lldrawpoolterrain.cpp
index 926d5e78d0..b4671963e1 100644
--- a/indra/newview/lldrawpoolterrain.cpp
+++ b/indra/newview/lldrawpoolterrain.cpp
@@ -253,7 +253,7 @@ void LLDrawPoolTerrain::renderFullShader()
// Hack! Get the region that this draw pool is rendering from!
LLViewerRegion *regionp = mDrawFace[0]->getDrawable()->getVObj()->getRegion();
LLVLComposition *compp = regionp->getComposition();
- const BOOL use_textures = !use_local_materials && (compp->getMaterialType() == LLTerrainMaterials::MaterialType::TEXTURE);
+ const BOOL use_textures = !use_local_materials && (compp->getMaterialType() == LLTerrainMaterials::Type::TEXTURE);
if (use_textures)
{
@@ -385,6 +385,8 @@ void LLDrawPoolTerrain::renderFullShaderPBR(BOOL local_materials)
materials = &gLocalTerrainMaterials.mDetailMaterials;
}
+ // *TODO: I'm seeing terrain still jump when switching regions. Might have something to do with the extra repeat factor in the shader. Or is it a numerical precision issue?...
+ // *TODO: If we want to change the tiling, we should change this offset modulo to prevent seams
LLVector3d region_origin_global = gAgent.getRegion()->getOriginGlobal();
F32 offset_x = (F32)fmod(region_origin_global.mdV[VX], 1.0/(F64)sDetailScale)*sDetailScale;
F32 offset_y = (F32)fmod(region_origin_global.mdV[VY], 1.0/(F64)sDetailScale)*sDetailScale;
diff --git a/indra/newview/llsurfacepatch.cpp b/indra/newview/llsurfacepatch.cpp
index 81fb4cf0cd..4f9911a11c 100644
--- a/indra/newview/llsurfacepatch.cpp
+++ b/indra/newview/llsurfacepatch.cpp
@@ -201,7 +201,7 @@ LLVector2 LLSurfacePatch::getTexCoords(const U32 x, const U32 y) const
void LLSurfacePatch::eval(const U32 x, const U32 y, const U32 stride, LLVector3 *vertex, LLVector3 *normal,
- LLVector2 *tex0, LLVector2 *tex1)
+ LLVector2 *tex0, LLVector2 *tex1, bool pbr)
{
if (!mSurfacep || !mSurfacep->getRegion() || !mSurfacep->getGridsPerEdge() || !mVObjp)
{
@@ -209,8 +209,15 @@ void LLSurfacePatch::eval(const U32 x, const U32 y, const U32 stride, LLVector3
}
llassert_always(vertex && normal && tex0 && tex1);
- // TODO: I think this is off by 1. Should use 1 less (which iirc is captured in another field member. See LLSurface::create). Do some hack to fix repeats for PBR only, while keeping legacy texture the same?
+ // TODO: I think this operation is being applied too early because it also affects the geometry - we only want to affect the UVs
+ // TODO: Figure out what correct scaling is needed to prevent seams at region borders - getPatchesPerEdge seems to not be the solution, nor is getGridsPerEdge on its own
U32 surface_stride = mSurfacep->getGridsPerEdge();
+ U32 texture_stride = mSurfacep->getGridsPerEdge() - 1;
+ if (!pbr)
+ {
+ // TODO: Re-enable legacy repeats
+ //texture_stride = mSurfacep->getGridsPerEdge();
+ }
U32 point_offset = x + y*surface_stride;
*normal = getNormal(x, y);
@@ -222,7 +229,8 @@ void LLSurfacePatch::eval(const U32 x, const U32 y, const U32 stride, LLVector3
*vertex = pos_agent-mVObjp->getRegion()->getOriginAgent();
LLVector3 rel_pos = pos_agent - mSurfacep->getOriginAgent();
- LLVector3 tex_pos = rel_pos * (1.f/surface_stride);
+ // TODO: Revert for non-PBR only here, and/or add note that non-PBR doesn't actually use it.
+ LLVector3 tex_pos = rel_pos * (1.f/(texture_stride * mSurfacep->getMetersPerGrid()));
tex0->mV[0] = tex_pos.mV[0];
tex0->mV[1] = tex_pos.mV[1];
tex1->mV[0] = mSurfacep->getRegion()->getCompositionXY(llfloor(mOriginRegion.mV[0])+x, llfloor(mOriginRegion.mV[1])+y);
diff --git a/indra/newview/llsurfacepatch.h b/indra/newview/llsurfacepatch.h
index 8c8f501dce..0e6c045145 100644
--- a/indra/newview/llsurfacepatch.h
+++ b/indra/newview/llsurfacepatch.h
@@ -106,7 +106,7 @@ public:
const LLVector3 &getNormal(const U32 x, const U32 y) const;
void eval(const U32 x, const U32 y, const U32 stride,
- LLVector3 *vertex, LLVector3 *normal, LLVector2 *tex0, LLVector2 *tex1);
+ LLVector3 *vertex, LLVector3 *normal, LLVector2 *tex0, LLVector2 *tex1, bool pbr);
diff --git a/indra/newview/llviewercontrol.cpp b/indra/newview/llviewercontrol.cpp
index 41b13cacbb..baf5480c6a 100644
--- a/indra/newview/llviewercontrol.cpp
+++ b/indra/newview/llviewercontrol.cpp
@@ -124,6 +124,15 @@ static bool handleTerrainDetailChanged(const LLSD& newvalue)
return true;
}
+static bool handleTerrainScaleChanged(const LLSD& newvalue)
+{
+ F64 scale = newvalue.asReal();
+ if (scale != 0.0)
+ {
+ LLDrawPoolTerrain::sDetailScale = F32(1.0 / scale);
+ }
+ return true;
+}
static bool handleDebugAvatarJointsChanged(const LLSD& newvalue)
{
@@ -702,6 +711,7 @@ void settings_setup_listeners()
setting_setup_signal_listener(gSavedSettings, "FirstPersonAvatarVisible", handleRenderAvatarMouselookChanged);
setting_setup_signal_listener(gSavedSettings, "RenderFarClip", handleRenderFarClipChanged);
setting_setup_signal_listener(gSavedSettings, "RenderTerrainDetail", handleTerrainDetailChanged);
+ setting_setup_signal_listener(gSavedSettings, "RenderTerrainScale", handleTerrainScaleChanged);
setting_setup_signal_listener(gSavedSettings, "RenderTerrainPBRDetail", handleSetShaderChanged);
setting_setup_signal_listener(gSavedSettings, "OctreeStaticObjectSizeFactor", handleRepartition);
setting_setup_signal_listener(gSavedSettings, "OctreeDistanceFactor", handleRepartition);
diff --git a/indra/newview/llvlcomposition.cpp b/indra/newview/llvlcomposition.cpp
index 8cd22e3bdb..130d74b286 100644
--- a/indra/newview/llvlcomposition.cpp
+++ b/indra/newview/llvlcomposition.cpp
@@ -119,7 +119,7 @@ void LLTerrainMaterials::setDetailAssetID(S32 asset, const LLUUID& id)
mMaterialTexturesSet[asset] = false;
}
-BOOL LLTerrainMaterials::getMaterialType()
+LLTerrainMaterials::Type LLTerrainMaterials::getMaterialType()
{
return mMaterialType;
}
@@ -132,7 +132,6 @@ void LLTerrainMaterials::updateMaterialType()
mMaterialType = use_textures ? Type::TEXTURE : Type::PBR;
}
-
BOOL LLTerrainMaterials::texturesReady(BOOL boost)
{
for (S32 i = 0; i < ASSET_COUNT; i++)
@@ -408,7 +407,7 @@ BOOL LLVLComposition::generateTexture(const F32 x, const F32 y,
U8* st_data[ASSET_COUNT];
S32 st_data_size[ASSET_COUNT]; // for debugging
- const bool use_textures = getMaterialType() != LLTerrainMaterial::Type::PBR;
+ const bool use_textures = getMaterialType() != LLTerrainMaterials::Type::PBR;
for (S32 i = 0; i < ASSET_COUNT; i++)
{
@@ -423,8 +422,9 @@ BOOL LLVLComposition::generateTexture(const F32 x, const F32 y,
else
{
tex = mDetailMaterials[i]->mBaseColorTexture;
- if (!tex) { tex = LLViewerFetchedTexture::sWhiteImagep; }
}
+ // TODO: Why are terrain textures (not terrain materials) not loading? (that is why there is a getComponents() check here)
+ if (!tex || tex->getComponents() == 0) { tex = LLViewerFetchedTexture::sWhiteImagep; }
S32 min_dim = llmin(tex->getFullWidth(), tex->getFullHeight());
S32 ddiscard = 0;
diff --git a/indra/newview/llvlcomposition.h b/indra/newview/llvlcomposition.h
index 882c3d89b2..a62302292f 100644
--- a/indra/newview/llvlcomposition.h
+++ b/indra/newview/llvlcomposition.h
@@ -61,6 +61,7 @@ public:
LLUUID getDetailAssetID(S32 asset);
virtual void setDetailAssetID(S32 asset, const LLUUID& id);
Type getMaterialType();
+ void updateMaterialType();
BOOL texturesReady(BOOL boost = FALSE);
BOOL materialsReady(BOOL boost = FALSE);
@@ -70,6 +71,7 @@ protected:
LLPointer<LLViewerFetchedTexture> mDetailTextures[ASSET_COUNT];
LLPointer<LLFetchedGLTFMaterial> mDetailMaterials[ASSET_COUNT];
bool mMaterialTexturesSet[ASSET_COUNT];
+ Type mMaterialType = Type::TEXTURE;
};
// Local materials to override all regions
diff --git a/indra/newview/llvosurfacepatch.cpp b/indra/newview/llvosurfacepatch.cpp
index 69b721c899..a672777914 100644
--- a/indra/newview/llvosurfacepatch.cpp
+++ b/indra/newview/llvosurfacepatch.cpp
@@ -1046,10 +1046,10 @@ void LLTerrainPartition::getGeometry(LLSpatialGroup* group)
const LLFace* region_facep = *mFaceList.begin();
const LLViewerObject* region_patchp = region_facep->getViewerObject();
- LLVLComposition* composition = region_patchp->mRegionp->getComposition();
+ LLVLComposition* composition = region_patchp->getRegion()->getComposition();
// TODO: This is not good; it will result in wrong texture repeats in cases where the assets have not loaded. Need to rebuild terrain on asset load event if it changes the composition type. Probably best to have a flag to bookkeep that, to know if the composition type has actually changed. Make sure the draw pool is boosting the textures so they load in a timely fashion.
composition->updateMaterialType();
- const bool pbr = composition->getMaterialType() == LLTerrainMaterial::Type::PBR;
+ const bool pbr = composition->getMaterialType() == LLTerrainMaterials::Type::PBR;
LLVertexBuffer* buffer = group->mVertexBuffer;
@@ -1087,7 +1087,7 @@ void LLTerrainPartition::getGeometry(LLSpatialGroup* group)
facep->setVertexBuffer(buffer);
LLVOSurfacePatch* patchp = (LLVOSurfacePatch*) facep->getViewerObject();
- patchp->getTerrainGeometry(vertices, normals, texcoords, texcoords2, indices);
+ patchp->getTerrainGeometry(vertices, normals, texcoords, texcoords2, indices, pbr);
indices_index += facep->getIndicesCount();
index_offset += facep->getGeomCount();