summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.github/workflows/build.yaml12
-rw-r--r--autobuild.xml234
-rw-r--r--doc/testplans/optimize_away_alpha.md5
-rw-r--r--doc/testplans/pbr_terrain_feature_gating.md22
-rw-r--r--indra/llcommon/indra_constants.cpp6
-rw-r--r--indra/llcommon/indra_constants.h5
-rw-r--r--indra/llcommon/llsingleton.h2
-rw-r--r--indra/llimage/llimage.cpp55
-rw-r--r--indra/llimage/llimage.h14
-rw-r--r--indra/llmath/llcamera.h1
-rw-r--r--indra/llmath/llvolume.cpp7
-rw-r--r--indra/llmath/llvolume.h2
-rw-r--r--indra/llplugin/llpluginprocessparent.cpp2
-rw-r--r--indra/llprimitive/llprimitive.cpp34
-rw-r--r--indra/llprimitive/llprimitive.h11
-rw-r--r--indra/llprimitive/lltextureentry.cpp1
-rw-r--r--indra/llprimitive/lltextureentry.h2
-rw-r--r--indra/llrender/llglslshader.cpp4
-rw-r--r--indra/llrender/llglslshader.h2
-rw-r--r--indra/llrender/llgltexture.h2
-rw-r--r--indra/llrender/llrendernavprim.cpp10
-rw-r--r--indra/llrender/llshadermgr.cpp69
-rw-r--r--indra/llrender/llshadermgr.h32
-rw-r--r--indra/llrender/llvertexbuffer.cpp4
-rw-r--r--indra/llrender/llvertexbuffer.h5
-rw-r--r--indra/newview/CMakeLists.txt4
-rw-r--r--indra/newview/app_settings/settings.xml230
-rw-r--r--indra/newview/app_settings/shaders/class1/deferred/materialV.glsl17
-rw-r--r--indra/newview/app_settings/shaders/class1/deferred/pbropaqueF.glsl27
-rw-r--r--indra/newview/app_settings/shaders/class1/deferred/pbrterrainF.glsl344
-rw-r--r--indra/newview/app_settings/shaders/class1/deferred/pbrterrainUtilF.glsl473
-rw-r--r--indra/newview/app_settings/shaders/class1/deferred/pbrterrainV.glsl93
-rw-r--r--indra/newview/app_settings/shaders/class1/deferred/terrainV.glsl9
-rw-r--r--indra/newview/app_settings/shaders/class1/deferred/textureUtilV.glsl2
-rw-r--r--indra/newview/app_settings/shaders/class1/interface/normaldebugF.glsl33
-rw-r--r--indra/newview/app_settings/shaders/class1/interface/normaldebugG.glsl76
-rw-r--r--indra/newview/app_settings/shaders/class1/interface/normaldebugV.glsl74
-rw-r--r--indra/newview/app_settings/shaders/class1/interface/radianceGenF.glsl2
-rw-r--r--indra/newview/app_settings/shaders/class3/deferred/materialF.glsl30
-rw-r--r--indra/newview/app_settings/shaders/class3/deferred/reflectionProbeF.glsl1
-rw-r--r--indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl22
-rw-r--r--indra/newview/featuretable.txt20
-rw-r--r--indra/newview/featuretable_mac.txt21
-rw-r--r--indra/newview/llappviewer.cpp3
-rw-r--r--indra/newview/lldrawable.h1
-rw-r--r--indra/newview/lldrawpool.cpp17
-rw-r--r--indra/newview/lldrawpool.h14
-rw-r--r--indra/newview/lldrawpoolmaterials.cpp13
-rw-r--r--indra/newview/lldrawpoolterrain.cpp302
-rw-r--r--indra/newview/lldrawpoolterrain.h10
-rw-r--r--indra/newview/lldrawpooltree.cpp13
-rw-r--r--indra/newview/lldynamictexture.cpp29
-rw-r--r--indra/newview/llenvironment.cpp10
-rw-r--r--indra/newview/llface.cpp2
-rw-r--r--indra/newview/llfeaturemanager.cpp4
-rw-r--r--indra/newview/llfetchedgltfmaterial.cpp58
-rw-r--r--indra/newview/llfetchedgltfmaterial.h15
-rw-r--r--indra/newview/llfloaterchangeitemthumbnail.cpp3
-rw-r--r--indra/newview/llfloatereditextdaycycle.cpp4
-rw-r--r--indra/newview/llfloaterenvironmentadjust.cpp2
-rw-r--r--indra/newview/llfloaterfixedenvironment.cpp3
-rw-r--r--indra/newview/llfloaterregioninfo.cpp171
-rw-r--r--indra/newview/llfloaterregioninfo.h76
-rw-r--r--indra/newview/llgltfmateriallist.cpp175
-rw-r--r--indra/newview/llgltfmateriallist.h4
-rw-r--r--indra/newview/llgltfmaterialpreviewmgr.cpp560
-rw-r--r--indra/newview/llgltfmaterialpreviewmgr.h82
-rw-r--r--indra/newview/llheroprobemanager.cpp584
-rw-r--r--indra/newview/llheroprobemanager.h142
-rw-r--r--indra/newview/llinventoryfunctions.cpp6
-rw-r--r--indra/newview/llinventoryfunctions.h22
-rw-r--r--indra/newview/llmaterialeditor.cpp34
-rw-r--r--indra/newview/llpaneleditwater.cpp2
-rw-r--r--indra/newview/llpanelface.cpp18
-rw-r--r--indra/newview/llpanelface.h3
-rw-r--r--indra/newview/llpanelprofile.cpp6
-rw-r--r--indra/newview/llpanelvolume.cpp29
-rw-r--r--indra/newview/llpanelvolume.h2
-rw-r--r--indra/newview/llreflectionmap.cpp7
-rw-r--r--indra/newview/llreflectionmap.h13
-rw-r--r--indra/newview/llreflectionmapmanager.cpp68
-rw-r--r--indra/newview/llreflectionmapmanager.h16
-rw-r--r--indra/newview/llselectmgr.cpp38
-rw-r--r--indra/newview/llsettingsvo.cpp4
-rw-r--r--indra/newview/llspatialpartition.cpp171
-rw-r--r--indra/newview/llstartup.cpp3
-rw-r--r--indra/newview/llsurface.cpp14
-rw-r--r--indra/newview/llsurface.h6
-rw-r--r--indra/newview/llsurfacepatch.cpp203
-rw-r--r--indra/newview/llsurfacepatch.h13
-rw-r--r--indra/newview/lltexturectrl.cpp239
-rw-r--r--indra/newview/lltexturectrl.h39
-rw-r--r--indra/newview/lltinygltfhelper.cpp1
-rw-r--r--indra/newview/llviewercontrol.cpp38
-rw-r--r--indra/newview/llviewerdisplay.cpp4
-rw-r--r--indra/newview/llviewermenu.cpp18
-rw-r--r--indra/newview/llviewerobject.cpp56
-rw-r--r--indra/newview/llviewerobject.h5
-rwxr-xr-xindra/newview/llviewerregion.cpp76
-rw-r--r--indra/newview/llviewerregion.h5
-rw-r--r--indra/newview/llviewershadermgr.cpp87
-rw-r--r--indra/newview/llviewershadermgr.h24
-rw-r--r--indra/newview/llviewertexture.cpp8
-rw-r--r--indra/newview/llviewertexturelist.cpp13
-rw-r--r--indra/newview/llviewerwindow.cpp15
-rw-r--r--indra/newview/llviewerwindow.h3
-rw-r--r--indra/newview/llvlcomposition.cpp447
-rw-r--r--indra/newview/llvlcomposition.h72
-rw-r--r--indra/newview/llvosurfacepatch.cpp225
-rw-r--r--indra/newview/llvosurfacepatch.h10
-rw-r--r--indra/newview/llvovolume.cpp57
-rw-r--r--indra/newview/llvovolume.h7
-rw-r--r--indra/newview/pipeline.cpp69
-rw-r--r--indra/newview/pipeline.h8
-rw-r--r--indra/newview/skins/default/xui/en/floater_tools.xml10
-rw-r--r--indra/newview/skins/default/xui/en/menu_viewer.xml7
-rw-r--r--indra/newview/skins/default/xui/en/notifications.xml4
-rw-r--r--indra/newview/skins/default/xui/en/panel_region_terrain.xml90
-rw-r--r--indra/newview/skins/default/xui/en/strings.xml1
119 files changed, 5521 insertions, 1113 deletions
diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml
index 1dd2c1d5df..70a3747b71 100644
--- a/.github/workflows/build.yaml
+++ b/.github/workflows/build.yaml
@@ -33,6 +33,9 @@ jobs:
AUTOBUILD_GITHUB_TOKEN: ${{ secrets.SHARED_AUTOBUILD_GITHUB_TOKEN }}
AUTOBUILD_INSTALLABLE_CACHE: ${{ github.workspace }}/.autobuild-installables
AUTOBUILD_VARIABLES_FILE: ${{ github.workspace }}/.build-variables/variables
+ # Direct autobuild to store vcs_url, vcs_branch and vcs_revision in
+ # autobuild-package.xml.
+ AUTOBUILD_VCS_INFO: "true"
AUTOBUILD_VSVER: "170"
DEVELOPER_DIR: ${{ matrix.developer_dir }}
# Ensure that Linden viewer builds engage Bugsplat.
@@ -96,10 +99,17 @@ jobs:
if: runner.os == 'Windows'
run: choco install nsis-unicode
+ - name: Determine source branch
+ id: which-branch
+ uses: secondlife/viewer-build-util/which-branch@v1
+ with:
+ token: ${{ github.token }}
+
- name: Build
id: build
shell: bash
env:
+ AUTOBUILD_VCS_BRANCH: ${{ steps.which-branch.outputs.branch }}
RUNNER_OS: ${{ runner.os }}
run: |
# set up things the viewer's build.sh script expects
@@ -150,7 +160,7 @@ jobs:
}
repo_branch()
{
- git -C "$1" branch | grep '^* ' | cut -c 3-
+ echo "$AUTOBUILD_VCS_BRANCH"
}
record_dependencies_graph()
{
diff --git a/autobuild.xml b/autobuild.xml
index 0e5a5a2a25..531b3586d6 100644
--- a/autobuild.xml
+++ b/autobuild.xml
@@ -1501,11 +1501,11 @@
<key>creds</key>
<string>github</string>
<key>hash</key>
- <string>48bca5d0233d1e724a59f649a2c6c7ac5f40ec3c</string>
+ <string>b037cc0b29ea70ee834cfae6dda5b7a25cd57174</string>
<key>hash_algorithm</key>
<string>sha1</string>
<key>url</key>
- <string>https://api.github.com/repos/secondlife/llphysicsextensions_source/releases/assets/117009335</string>
+ <string>https://api.github.com/repos/secondlife/llphysicsextensions_source/releases/assets/144851460</string>
</map>
<key>name</key>
<string>darwin64</string>
@@ -1517,11 +1517,11 @@
<key>creds</key>
<string>github</string>
<key>hash</key>
- <string>39f52d0350e130f41c5c758f7cb94e87b962c223</string>
+ <string>bdea1fd5c4da9da5afde088d16188b45d0853e04</string>
<key>hash_algorithm</key>
<string>sha1</string>
<key>url</key>
- <string>https://api.github.com/repos/secondlife/llphysicsextensions_source/releases/assets/117009336</string>
+ <string>https://api.github.com/repos/secondlife/llphysicsextensions_source/releases/assets/144851461</string>
</map>
<key>name</key>
<string>linux64</string>
@@ -1533,11 +1533,11 @@
<key>creds</key>
<string>github</string>
<key>hash</key>
- <string>7b5e645fb7eb399abbea63bd21e8063bbb32a911</string>
+ <string>f652ce0d6aef864689f0ed44255da4d9cd65a43f</string>
<key>hash_algorithm</key>
<string>sha1</string>
<key>url</key>
- <string>https://api.github.com/repos/secondlife/llphysicsextensions_source/releases/assets/117009339</string>
+ <string>https://api.github.com/repos/secondlife/llphysicsextensions_source/releases/assets/144851463</string>
</map>
<key>name</key>
<string>windows64</string>
@@ -1550,7 +1550,7 @@
<key>copyright</key>
<string>Copyright (c) 2010, Linden Research, Inc.</string>
<key>version</key>
- <string>1.0.565768</string>
+ <string>1.0.479d20a</string>
<key>name</key>
<string>llphysicsextensions_source</string>
</map>
@@ -1582,18 +1582,6 @@
<key>name</key>
<string>linux64</string>
</map>
- <key>windows</key>
- <map>
- <key>archive</key>
- <map>
- <key>hash</key>
- <string>2e5f1f7046a49d8b0bc295aa878116bc</string>
- <key>url</key>
- <string>http://automated-builds-secondlife-com.s3.amazonaws.com/ct2/60043/564063/llphysicsextensions_stub-1.0.542456-windows-542456.tar.bz2</string>
- </map>
- <key>name</key>
- <string>windows</string>
- </map>
</map>
<key>license</key>
<string>internal</string>
@@ -1734,18 +1722,6 @@
</map>
<key>mikktspace</key>
<map>
- <key>canonical_repo</key>
- <string>https://bitbucket.org/lindenlab/3p-mikktspace</string>
- <key>copyright</key>
- <string>Copyright (C) 2011 by Morten S. Mikkelsen</string>
- <key>description</key>
- <string>Mikktspace Tangent Generator</string>
- <key>license</key>
- <string>Copyright (C) 2011 by Morten S. Mikkelsen</string>
- <key>license_file</key>
- <string>mikktspace.txt</string>
- <key>name</key>
- <string>mikktspace</string>
<key>platforms</key>
<map>
<key>darwin64</key>
@@ -1753,40 +1729,58 @@
<key>archive</key>
<map>
<key>hash</key>
- <string>b48b7ac0792d3ea8f087d99d9e4a29d8</string>
+ <string>6cc1585dba85b0226a2e7033a7e2a2ceaae7c983</string>
+ <key>hash_algorithm</key>
+ <string>sha1</string>
<key>url</key>
- <string>https://automated-builds-secondlife-com.s3.amazonaws.com/ct2/104415/914944/mikktspace-1-darwin64-574859.tar.bz2</string>
+ <string>https://github.com/secondlife/3p-mikktspace/releases/download/v1-5cee1f4/mikktspace-1-darwin64-5cee1f4.tar.zst</string>
</map>
<key>name</key>
<string>darwin64</string>
</map>
- <key>windows</key>
+ <key>windows64</key>
<map>
<key>archive</key>
<map>
<key>hash</key>
- <string>0a016b9c0c1e2c0b557e0124094da6c5</string>
+ <string>6b7d01ad54e4a88a001f66840c32329cedb28202</string>
+ <key>hash_algorithm</key>
+ <string>sha1</string>
<key>url</key>
- <string>https://automated-builds-secondlife-com.s3.amazonaws.com/ct2/104407/914918/mikktspace-1-windows-574859.tar.bz2</string>
+ <string>https://github.com/secondlife/3p-mikktspace/releases/download/v1-5cee1f4/mikktspace-1-windows64-5cee1f4.tar.zst</string>
</map>
<key>name</key>
- <string>windows</string>
+ <string>windows64</string>
</map>
- <key>windows64</key>
+ <key>linux64</key>
<map>
<key>archive</key>
<map>
<key>hash</key>
- <string>02e9e5b6fe6788f4d2babb83ec544843</string>
+ <string>edc9782bf209e17ad1845498b42f16d733582082</string>
+ <key>hash_algorithm</key>
+ <string>sha1</string>
<key>url</key>
- <string>https://automated-builds-secondlife-com.s3.amazonaws.com/ct2/104406/914909/mikktspace-1-windows64-574859.tar.bz2</string>
+ <string>https://github.com/secondlife/3p-mikktspace/releases/download/v1-5cee1f4/mikktspace-1-linux64-5cee1f4.tar.zst</string>
</map>
<key>name</key>
- <string>windows64</string>
+ <string>linux64</string>
</map>
</map>
+ <key>license</key>
+ <string>Copyright (C) 2011 by Morten S. Mikkelsen</string>
+ <key>license_file</key>
+ <string>mikktspace.txt</string>
+ <key>copyright</key>
+ <string>Copyright (C) 2011 by Morten S. Mikkelsen</string>
<key>version</key>
<string>1</string>
+ <key>name</key>
+ <string>mikktspace</string>
+ <key>canonical_repo</key>
+ <string>https://bitbucket.org/lindenlab/3p-mikktspace</string>
+ <key>description</key>
+ <string>Mikktspace Tangent Generator</string>
</map>
<key>minizip-ng</key>
<map>
@@ -2376,18 +2370,6 @@ Copyright (c) 2012, 2014, 2015, 2016 nghttp2 contributors</string>
</map>
<key>tinygltf</key>
<map>
- <key>canonical_repo</key>
- <string>https://bitbucket.org/lindenlab/3p-tinygltf</string>
- <key>copyright</key>
- <string>// Copyright (c) 2015 - Present Syoyo Fujita, Aurélien Chatelain and many contributors.</string>
- <key>description</key>
- <string>tinygltf import library</string>
- <key>license</key>
- <string>MIT</string>
- <key>license_file</key>
- <string>LICENSES/tinygltf_license.txt</string>
- <key>name</key>
- <string>tinygltf</string>
<key>platforms</key>
<map>
<key>common</key>
@@ -2395,20 +2377,34 @@ Copyright (c) 2012, 2014, 2015, 2016 nghttp2 contributors</string>
<key>archive</key>
<map>
<key>hash</key>
- <string>4dad1c0948141e1667c01a3ee755e4dc</string>
+ <string>2c47ae2d0c38c86b8c2db8d9317f0ab15edfc74f</string>
+ <key>hash_algorithm</key>
+ <string>sha1</string>
<key>url</key>
- <string>https://automated-builds-secondlife-com.s3.amazonaws.com/ct2/105849/926137/tinygltf-v2.5.0-common-575729.tar.bz2</string>
+ <string>https://github.com/secondlife/3p-tinygltf/releases/download/v2.5.0-1ae57fd/tinygltf-v2.5.0-common-1ae57fd.tar.zst</string>
</map>
<key>name</key>
<string>common</string>
</map>
</map>
+ <key>license</key>
+ <string>MIT</string>
+ <key>license_file</key>
+ <string>LICENSES/tinygltf_license.txt</string>
+ <key>copyright</key>
+ <string>// Copyright (c) 2015 - Present Syoyo Fujita, Aurélien Chatelain and many contributors.</string>
+ <key>version</key>
+ <string>v2.5.0</string>
+ <key>name</key>
+ <string>tinygltf</string>
+ <key>canonical_repo</key>
+ <string>https://bitbucket.org/lindenlab/3p-tinygltf</string>
+ <key>description</key>
+ <string>tinygltf import library</string>
<key>source</key>
<string>https://bitbucket.org/lindenlab/3p-tinygltf</string>
<key>source_type</key>
<string>git</string>
- <key>version</key>
- <string>v2.5.0</string>
</map>
<key>tracy</key>
<map>
@@ -2419,9 +2415,11 @@ Copyright (c) 2012, 2014, 2015, 2016 nghttp2 contributors</string>
<key>archive</key>
<map>
<key>hash</key>
- <string>9b6e1a1f4b0969d38a1ca8ee00aeb548</string>
+ <string>49650353442698c3e05102676fe427d0ebe02f0b</string>
+ <key>hash_algorithm</key>
+ <string>sha1</string>
<key>url</key>
- <string>https://automated-builds-secondlife-com.s3.amazonaws.com/ct2/110584/960613/tracy-v0.8.1.578241-darwin64-578241.tar.bz2</string>
+ <string>https://github.com/secondlife/3p-tracy/releases/download/v0.8.1-eecbf72/tracy-v0.8.1-eecbf72-darwin64-eecbf72.tar.zst</string>
</map>
<key>name</key>
<string>darwin64</string>
@@ -2431,11 +2429,11 @@ Copyright (c) 2012, 2014, 2015, 2016 nghttp2 contributors</string>
<key>archive</key>
<map>
<key>hash</key>
- <string>05b72ae5d733aed7d3bf142287601cc6</string>
+ <string>2b80e7407e4f3e82eff3879add0e9ad63e7fcace</string>
<key>hash_algorithm</key>
- <string>md5</string>
+ <string>sha1</string>
<key>url</key>
- <string>https://automated-builds-secondlife-com.s3.amazonaws.com/ct2/110586/960637/tracy-v0.8.1.578241-windows64-578241.tar.bz2</string>
+ <string>https://github.com/secondlife/3p-tracy/releases/download/v0.8.1-eecbf72/tracy-v0.8.1-eecbf72-windows64-eecbf72.tar.zst</string>
</map>
<key>name</key>
<string>windows64</string>
@@ -2448,7 +2446,7 @@ Copyright (c) 2012, 2014, 2015, 2016 nghttp2 contributors</string>
<key>copyright</key>
<string>Copyright (c) 2017-2022, Bartosz Taudul (wolf@nereid.pl)</string>
<key>version</key>
- <string>v0.8.1.235e98f</string>
+ <string>v0.8.1-eecbf72</string>
<key>name</key>
<string>tracy</string>
<key>canonical_repo</key>
@@ -2459,8 +2457,6 @@ Copyright (c) 2012, 2014, 2015, 2016 nghttp2 contributors</string>
<string>https://bitbucket.org/lindenlab/3p-tracy</string>
<key>source_type</key>
<string>git</string>
- <key>version</key>
- <string>v0.8.1.578241</string>
</map>
<key>tut</key>
<map>
@@ -2724,59 +2720,37 @@ Copyright (c) 2012, 2014, 2015, 2016 nghttp2 contributors</string>
</map>
<key>vulkan_gltf</key>
<map>
- <key>canonical_repo</key>
- <string>https://bitbucket.org/lindenlab/3p-vulkan-gltf-pbr</string>
- <key>copyright</key>
- <string>Copyright (c) 2018 Sascha Willems</string>
- <key>description</key>
- <string>Vulkan GLTF Sample Implementation</string>
- <key>license</key>
- <string>Copyright (c) 2018 Sascha Willems</string>
- <key>license_file</key>
- <string>LICENSES/vulkan_gltf.txt</string>
- <key>name</key>
- <string>vulkan_gltf</string>
<key>platforms</key>
<map>
- <key>darwin64</key>
- <map>
- <key>archive</key>
- <map>
- <key>hash</key>
- <string>8cff2060843db3db788511ee34a8e8cc</string>
- <key>url</key>
- <string>https://automated-builds-secondlife-com.s3.amazonaws.com/ct2/101316/891509/vulkan_gltf-1-darwin64-572743.tar.bz2</string>
- </map>
- <key>name</key>
- <string>darwin64</string>
- </map>
- <key>windows</key>
- <map>
- <key>archive</key>
- <map>
- <key>hash</key>
- <string>58eea384be49ba756ce9c5e66669540b</string>
- <key>url</key>
- <string>https://automated-builds-secondlife-com.s3.amazonaws.com/ct2/101318/891520/vulkan_gltf-1-windows-572743.tar.bz2</string>
- </map>
- <key>name</key>
- <string>windows</string>
- </map>
- <key>windows64</key>
+ <key>common</key>
<map>
<key>archive</key>
<map>
<key>hash</key>
- <string>79b6a11622c2f83cfc2b7cd1fafb867b</string>
+ <string>8e365eff8dcace48d91e2530f8b13e420849aefc</string>
+ <key>hash_algorithm</key>
+ <string>sha1</string>
<key>url</key>
- <string>https://automated-builds-secondlife-com.s3.amazonaws.com/ct2/101319/891521/vulkan_gltf-1-windows64-572743.tar.bz2</string>
+ <string>https://github.com/secondlife/3p-vulkan-gltf-pbr/releases/download/v1.0.0-d7c372f/vulkan_gltf-1.0.0-common-d7c372f.tar.zst</string>
</map>
<key>name</key>
- <string>windows64</string>
+ <string>common</string>
</map>
</map>
+ <key>license</key>
+ <string>Copyright (c) 2018 Sascha Willems</string>
+ <key>license_file</key>
+ <string>vulkan_gltf.txt</string>
+ <key>copyright</key>
+ <string>Copyright (c) 2018 Sascha Willems</string>
<key>version</key>
- <string>1</string>
+ <string>1.0.0</string>
+ <key>name</key>
+ <string>vulkan_gltf</string>
+ <key>canonical_repo</key>
+ <string>https://bitbucket.org/lindenlab/3p-vulkan-gltf-pbr</string>
+ <key>description</key>
+ <string>Vulkan GLTF Sample Implementation</string>
</map>
<key>xxhash</key>
<map>
@@ -2787,54 +2761,14 @@ Copyright (c) 2012, 2014, 2015, 2016 nghttp2 contributors</string>
<key>archive</key>
<map>
<key>hash</key>
- <string>e4f77ba0a9b8ec3cc3fabc51c4da81d2</string>
- <key>url</key>
- <string>https://automated-builds-secondlife-com.s3.amazonaws.com/ct2/110070/956941/xxhash-0.8.1.578006-windows-578006.tar.bz2</string>
- </map>
- <key>name</key>
- <string>common</string>
- </map>
- <key>darwin64</key>
- <map>
- <key>archive</key>
- <map>
- <key>hash</key>
- <string>fdcc803a76a3359bb426db7dac161406676d51e7</string>
+ <string>1a73c476b371b62066d1c3eced249660e9467e53</string>
<key>hash_algorithm</key>
<string>sha1</string>
<key>url</key>
- <string>https://github.com/secondlife/3p-xxhash/releases/download/v0.8.1.7501c90/xxhash-0.8.1.7501c90-darwin64-7501c90.tar.zst</string>
+ <string>https://github.com/secondlife/3p-xxhash/releases/download/v0.8.1-69ff69a/xxhash-0.8.1-69ff69a-common-69ff69a.tar.zst</string>
</map>
<key>name</key>
- <string>darwin64</string>
- </map>
- <key>linux64</key>
- <map>
- <key>archive</key>
- <map>
- <key>hash</key>
- <string>7acb3f94a549fbb9bd7bc16604e34f33c5365a9b</string>
- <key>hash_algorithm</key>
- <string>sha1</string>
- <key>url</key>
- <string>https://github.com/secondlife/3p-xxhash/releases/download/v0.8.1.7501c90/xxhash-0.8.1.7501c90-linux64-7501c90.tar.zst</string>
- </map>
- <key>name</key>
- <string>linux64</string>
- </map>
- <key>windows64</key>
- <map>
- <key>archive</key>
- <map>
- <key>hash</key>
- <string>4522d075ea4703ef4b527c3039864ef735ea7953</string>
- <key>hash_algorithm</key>
- <string>sha1</string>
- <key>url</key>
- <string>https://github.com/secondlife/3p-xxhash/releases/download/v0.8.1.7501c90/xxhash-0.8.1.7501c90-windows64-7501c90.tar.zst</string>
- </map>
- <key>name</key>
- <string>windows64</string>
+ <string>common</string>
</map>
</map>
<key>license</key>
@@ -2844,7 +2778,7 @@ Copyright (c) 2012, 2014, 2015, 2016 nghttp2 contributors</string>
<key>copyright</key>
<string>Copyright (c) 2012-2021 Yann Collet</string>
<key>version</key>
- <string>0.8.1.7501c90</string>
+ <string>0.8.1-69ff69a</string>
<key>name</key>
<string>xxhash</string>
<key>description</key>
diff --git a/doc/testplans/optimize_away_alpha.md b/doc/testplans/optimize_away_alpha.md
new file mode 100644
index 0000000000..f0c8d1e8d6
--- /dev/null
+++ b/doc/testplans/optimize_away_alpha.md
@@ -0,0 +1,5 @@
+Textures imported via Build->Upload->Material that have an all opaque (255) alpha channel should have their alpha channel removed before upload.
+
+1. Make 4 images that have different colors but all 255 alpha channels
+2. Upload them all using Build->Upload->Material, with one in each of the material texture slots
+3. Verify that using the textures as a blinn-phong diffuse map does not make the corresponding face render in the alpha pass (face should stay visible after disabling alpha pass by unchecking Advanced->Render Types->Alpha).
diff --git a/doc/testplans/pbr_terrain_feature_gating.md b/doc/testplans/pbr_terrain_feature_gating.md
new file mode 100644
index 0000000000..13108c1534
--- /dev/null
+++ b/doc/testplans/pbr_terrain_feature_gating.md
@@ -0,0 +1,22 @@
+# PBR Terrain Feature Gating
+
+PBR terrain should have lower detail on lower graphics settings. PBR terrain will also not show emissive textures on some machines (like Macs) which do not support more than 16 textures.
+
+## Triplanar Mapping
+
+Triplanar mapping improves the texture repeats on the sides of terrain slopes.
+
+Availability of Triplanar mapping:
+
+- Medium-High and below: No triplanar mapping
+- High and above: Triplanar mapping
+
+## PBR Textures
+
+At the highest graphics support level, PBR terrain supports all PBR textures.
+
+Availability of PBR textures varies by machine and graphics setting:
+
+- Low: Base color only (looks similar to texture terrain)
+- Medium-Low, and machines that do not support greater than 16 textures such as Macs: All PBR textures enabled except emissive textures.
+- Medium: All PBR textures enabled
diff --git a/indra/llcommon/indra_constants.cpp b/indra/llcommon/indra_constants.cpp
index 1b48e4daf3..473b3ebdc9 100644
--- a/indra/llcommon/indra_constants.cpp
+++ b/indra/llcommon/indra_constants.cpp
@@ -50,6 +50,7 @@ const LLUUID IMG_FIRE ("aca40aa8-44cf-44ca-a0fa-93e1a2986f82"); // dataserver
const LLUUID IMG_FACE_SELECT ("a85ac674-cb75-4af6-9499-df7c5aaf7a28"); // face selector
const LLUUID IMG_DEFAULT_AVATAR ("c228d1cf-4b5d-4ba8-84f4-899a0796aa97"); // dataserver
const LLUUID IMG_INVISIBLE ("3a367d1c-bef1-6d43-7595-e88c1e3aadb3"); // dataserver
+const LLUUID IMG_WHITE ("3a367d1c-bef1-6d43-7595-e88c1e3aadb3"); // dataserver
const LLUUID IMG_EXPLOSION ("68edcf47-ccd7-45b8-9f90-1649d7f12806"); // On dataserver
const LLUUID IMG_EXPLOSION_2 ("21ce046c-83fe-430a-b629-c7660ac78d7c"); // On dataserver
@@ -71,6 +72,11 @@ const LLUUID TERRAIN_ROCK_DETAIL ("53a2f406-4895-1d13-d541-d2e3b86bc19c"); // V
const LLUUID DEFAULT_WATER_NORMAL ("822ded49-9a6c-f61c-cb89-6df54f42cdf4"); // VIEWER
+const LLUUID DEFAULT_OBJECT_TEXTURE ("89556747-24cb-43ed-920b-47caed15465f"); // On dataserver
+const LLUUID DEFAULT_OBJECT_SPECULAR ("87e0e8f7-8729-1ea8-cfc9-8915773009db"); // On dataserver
+const LLUUID DEFAULT_OBJECT_NORMAL ("85f28839-7a1c-b4e3-d71d-967792970a7b"); // On dataserver
+const LLUUID BLANK_OBJECT_NORMAL ("5b53359e-59dd-d8a2-04c3-9e65134da47a"); // VIEWER (has a verion on dataserver, but with compression artifacts)
+
const LLUUID IMG_USE_BAKED_HEAD ("5a9f4a74-30f2-821c-b88d-70499d3e7183");
const LLUUID IMG_USE_BAKED_UPPER ("ae2de45c-d252-50b8-5c6e-19f39ce79317");
const LLUUID IMG_USE_BAKED_LOWER ("24daea5f-0539-cfcf-047f-fbc40b2786ba");
diff --git a/indra/llcommon/indra_constants.h b/indra/llcommon/indra_constants.h
index 679f79039b..a16cfac2b9 100644
--- a/indra/llcommon/indra_constants.h
+++ b/indra/llcommon/indra_constants.h
@@ -197,6 +197,7 @@ LL_COMMON_API extern const LLUUID IMG_FIRE;
LL_COMMON_API extern const LLUUID IMG_FACE_SELECT;
LL_COMMON_API extern const LLUUID IMG_DEFAULT_AVATAR;
LL_COMMON_API extern const LLUUID IMG_INVISIBLE;
+LL_COMMON_API extern const LLUUID IMG_WHITE;
LL_COMMON_API extern const LLUUID IMG_EXPLOSION;
LL_COMMON_API extern const LLUUID IMG_EXPLOSION_2;
@@ -230,6 +231,10 @@ LL_COMMON_API extern const LLUUID IMG_USE_BAKED_AUX3;
LL_COMMON_API extern const LLUUID DEFAULT_WATER_NORMAL;
+LL_COMMON_API extern const LLUUID DEFAULT_OBJECT_TEXTURE;
+LL_COMMON_API extern const LLUUID DEFAULT_OBJECT_SPECULAR;
+LL_COMMON_API extern const LLUUID DEFAULT_OBJECT_NORMAL;
+LL_COMMON_API extern const LLUUID BLANK_OBJECT_NORMAL;
// radius within which a chat message is fully audible
const F32 CHAT_NORMAL_RADIUS = 20.f;
diff --git a/indra/llcommon/llsingleton.h b/indra/llcommon/llsingleton.h
index 51ef514cf7..fba8301c4d 100644
--- a/indra/llcommon/llsingleton.h
+++ b/indra/llcommon/llsingleton.h
@@ -455,7 +455,7 @@ public:
static DERIVED_TYPE* getInstance()
{
- LL_PROFILE_ZONE_SCOPED_CATEGORY_THREAD;
+ //LL_PROFILE_ZONE_SCOPED_CATEGORY_THREAD; // TODO -- reenable this when we have a fix for using Tracy with coroutines
// We know the viewer has LLSingleton dependency circularities. If you
// feel strongly motivated to eliminate them, cheers and good luck.
// (At that point we could consider a much simpler locking mechanism.)
diff --git a/indra/llimage/llimage.cpp b/indra/llimage/llimage.cpp
index 031471d1fe..acfc254b65 100644
--- a/indra/llimage/llimage.cpp
+++ b/indra/llimage/llimage.cpp
@@ -31,6 +31,7 @@
#include "llmath.h"
#include "v4coloru.h"
+#include "v3color.h"
#include "llimagebmp.h"
#include "llimagetga.h"
@@ -1026,6 +1027,34 @@ bool LLImageRaw::optimizeAwayAlpha()
return false;
}
+bool LLImageRaw::makeAlpha()
+{
+ if (getComponents() == 3)
+ {
+ U8* data = getData();
+ U32 pixels = getWidth() * getHeight();
+
+ // alpha channel doesn't exist, make a new copy of data with alpha channel
+ U8* new_data = (U8*) ll_aligned_malloc_16(getWidth() * getHeight() * 4);
+
+ for (U32 i = 0; i < pixels; ++i)
+ {
+ U32 di = i * 4;
+ U32 si = i * 3;
+ for (U32 j = 0; j < 3; ++j)
+ {
+ new_data[di+j] = data[si+j];
+ }
+ }
+
+ setDataAndSize(new_data, getWidth(), getHeight(), 3);
+
+ return true;
+ }
+
+ return false;
+}
+
void LLImageRaw::expandToPowerOfTwo(S32 max_dim, bool scale_image)
{
// Find new sizes
@@ -1110,7 +1139,7 @@ void LLImageRaw::composite( LLImageRaw* src )
return;
}
- llassert(3 == src->getComponents());
+ llassert((3 == src->getComponents()) || (4 == src->getComponents()));
llassert(3 == dst->getComponents());
if( 3 == dst->getComponents() )
@@ -1268,6 +1297,30 @@ void LLImageRaw::fill( const LLColor4U& color )
}
}
+void LLImageRaw::tint( const LLColor3& color )
+{
+ llassert( (3 == getComponents()) || (4 == getComponents()) );
+ if (isBufferInvalid())
+ {
+ LL_WARNS() << "Invalid image buffer" << LL_ENDL;
+ return;
+ }
+
+ S32 pixels = getWidth() * getHeight();
+ const S32 components = getComponents();
+ U8* data = getData();
+ for( S32 i = 0; i < pixels; i++ )
+ {
+ const float c0 = data[0] * color.mV[0];
+ const float c1 = data[1] * color.mV[1];
+ const float c2 = data[2] * color.mV[2];
+ data[0] = llclamp((U8)c0, 0, 255);
+ data[1] = llclamp((U8)c1, 0, 255);
+ data[2] = llclamp((U8)c2, 0, 255);
+ data += components;
+ }
+}
+
LLPointer<LLImageRaw> LLImageRaw::duplicate()
{
if(getNumRefs() < 2)
diff --git a/indra/llimage/llimage.h b/indra/llimage/llimage.h
index 8f9e1b3c54..fc8d62cc96 100644
--- a/indra/llimage/llimage.h
+++ b/indra/llimage/llimage.h
@@ -33,7 +33,7 @@
#include "lltrace.h"
const S32 MIN_IMAGE_MIP = 2; // 4x4, only used for expand/contract power of 2
-const S32 MAX_IMAGE_MIP = 11; // 2048x2048
+const S32 MAX_IMAGE_MIP = 12; // 4096x4096
// *TODO : Use MAX_IMAGE_MIP as max discard level and modify j2c management so that the number
// of levels is read from the header's file, not inferred from its size.
@@ -44,7 +44,7 @@ const S32 MAX_DISCARD_LEVEL = 5;
// and declared right here. Some come from the JPEG2000 spec, some conventions specific to SL.
const S32 MAX_DECOMPOSITION_LEVELS = 32; // Number of decomposition levels cannot exceed 32 according to jpeg2000 spec
const S32 MIN_DECOMPOSITION_LEVELS = 5; // the SL viewer will *crash* trying to decode images with fewer than 5 decomposition levels (unless image is small that is)
-const S32 MAX_PRECINCT_SIZE = 2048; // No reason to be bigger than MAX_IMAGE_SIZE
+const S32 MAX_PRECINCT_SIZE = 4096; // No reason to be bigger than MAX_IMAGE_SIZE
const S32 MIN_PRECINCT_SIZE = 4; // Can't be smaller than MIN_BLOCK_SIZE
const S32 MAX_BLOCK_SIZE = 64; // Max total block size is 4096, hence 64x64 when using square blocks
const S32 MIN_BLOCK_SIZE = 4; // Min block dim is 4 according to jpeg2000 spec
@@ -52,11 +52,11 @@ const S32 MIN_LAYER_SIZE = 2000; // Size of the first quality layer (after hea
const S32 MAX_NB_LAYERS = 64; // Max number of layers we'll entertain in SL (practical limit)
const S32 MIN_IMAGE_SIZE = (1<<MIN_IMAGE_MIP); // 4, only used for expand/contract power of 2
-const S32 MAX_IMAGE_SIZE = (1<<MAX_IMAGE_MIP); // 2048
+const S32 MAX_IMAGE_SIZE = (1<<MAX_IMAGE_MIP); // 4096
const S32 MIN_IMAGE_AREA = MIN_IMAGE_SIZE * MIN_IMAGE_SIZE;
const S32 MAX_IMAGE_AREA = MAX_IMAGE_SIZE * MAX_IMAGE_SIZE;
const S32 MAX_IMAGE_COMPONENTS = 8;
-const S32 MAX_IMAGE_DATA_SIZE = MAX_IMAGE_AREA * MAX_IMAGE_COMPONENTS; //2048 * 2048 * 8 = 16 MB
+const S32 MAX_IMAGE_DATA_SIZE = MAX_IMAGE_AREA * MAX_IMAGE_COMPONENTS; //4096 * 4096 * 8 = 128 MB
// Note! These CANNOT be changed without modifying simulator code
// *TODO: change both to 1024 when SIM texture fetching is deprecated
@@ -71,6 +71,7 @@ const S32 HTTP_PACKET_SIZE = 1496;
class LLImageFormatted;
class LLImageRaw;
class LLColor4U;
+class LLColor3;
typedef enum e_image_codec
{
@@ -212,6 +213,8 @@ public:
// if the alpha channel is all 100% opaque, delete it
// returns true if alpha channel was deleted
bool optimizeAwayAlpha();
+ // Create an alpha channel if this image doesn't have one
+ bool makeAlpha();
static S32 biasedDimToPowerOfTwo(S32 curr_dim, S32 max_dim = MAX_IMAGE_SIZE);
static S32 expandDimToPowerOfTwo(S32 curr_dim, S32 max_dim = MAX_IMAGE_SIZE);
@@ -225,6 +228,9 @@ public:
// Fill the buffer with a constant color
void fill( const LLColor4U& color );
+ // Multiply this raw image by the given color
+ void tint( const LLColor3& color );
+
// Copy operations
//duplicate this raw image if refCount > 1.
diff --git a/indra/llmath/llcamera.h b/indra/llmath/llcamera.h
index c4d04f5d02..e1d3536f66 100644
--- a/indra/llmath/llcamera.h
+++ b/indra/llmath/llcamera.h
@@ -65,7 +65,6 @@ class LLCamera
: public LLCoordFrame
{
public:
-
LLCamera(const LLCamera& rhs)
{
*this = rhs;
diff --git a/indra/llmath/llvolume.cpp b/indra/llmath/llvolume.cpp
index 6d36daa92a..a5f047d207 100644
--- a/indra/llmath/llvolume.cpp
+++ b/indra/llmath/llvolume.cpp
@@ -6465,9 +6465,6 @@ BOOL LLVolumeFace::createCap(LLVolume* volume, BOOL partial_build)
return TRUE;
}
-void CalculateTangentArray(U32 vertexCount, const LLVector4a *vertex, const LLVector4a *normal,
- const LLVector2 *texcoord, U32 triangleCount, const U16* index_array, LLVector4a *tangent);
-
void LLVolumeFace::createTangents()
{
LL_PROFILE_ZONE_SCOPED_CATEGORY_VOLUME;
@@ -6485,7 +6482,7 @@ void LLVolumeFace::createTangents()
(*ptr++).clear();
}
- CalculateTangentArray(mNumVertices, mPositions, mNormals, mTexCoords, mNumIndices / 3, mIndices, mTangents);
+ LLCalculateTangentArray(mNumVertices, mPositions, mNormals, mTexCoords, mNumIndices / 3, mIndices, mTangents);
//normalize normals
for (U32 i = 0; i < mNumVertices; i++)
@@ -7195,7 +7192,7 @@ BOOL LLVolumeFace::createSide(LLVolume* volume, BOOL partial_build)
}
//adapted from Lengyel, Eric. "Computing Tangent Space Basis Vectors for an Arbitrary Mesh". Terathon Software 3D Graphics Library, 2001. http://www.terathon.com/code/tangent.html
-void CalculateTangentArray(U32 vertexCount, const LLVector4a *vertex, const LLVector4a *normal,
+void LLCalculateTangentArray(U32 vertexCount, const LLVector4a *vertex, const LLVector4a *normal,
const LLVector2 *texcoord, U32 triangleCount, const U16* index_array, LLVector4a *tangent)
{
LL_PROFILE_ZONE_SCOPED_CATEGORY_VOLUME
diff --git a/indra/llmath/llvolume.h b/indra/llmath/llvolume.h
index afed98ff36..c2586601ae 100644
--- a/indra/llmath/llvolume.h
+++ b/indra/llmath/llvolume.h
@@ -1142,6 +1142,8 @@ public:
std::ostream& operator<<(std::ostream &s, const LLVolumeParams &volume_params);
+void LLCalculateTangentArray(U32 vertexCount, const LLVector4a *vertex, const LLVector4a *normal, const LLVector2 *texcoord, U32 triangleCount, const U16* index_array, LLVector4a *tangent);
+
BOOL LLLineSegmentBoxIntersect(const F32* start, const F32* end, const F32* center, const F32* size);
BOOL LLLineSegmentBoxIntersect(const LLVector3& start, const LLVector3& end, const LLVector3& center, const LLVector3& size);
BOOL LLLineSegmentBoxIntersect(const LLVector4a& start, const LLVector4a& end, const LLVector4a& center, const LLVector4a& size);
diff --git a/indra/llplugin/llpluginprocessparent.cpp b/indra/llplugin/llpluginprocessparent.cpp
index 756d0b5db8..f5966b71de 100644
--- a/indra/llplugin/llpluginprocessparent.cpp
+++ b/indra/llplugin/llpluginprocessparent.cpp
@@ -582,7 +582,7 @@ void LLPluginProcessParent::idle(void)
params.args.add("-e");
params.args.add("tell application \"Terminal\"");
params.args.add("-e");
- params.args.add(STRINGIZE("set win to do script \"gdb -pid "
+ params.args.add(STRINGIZE("set win to do script \"lldb -pid "
<< mProcess->getProcessID() << "\""));
params.args.add("-e");
params.args.add("do script \"continue\" in win");
diff --git a/indra/llprimitive/llprimitive.cpp b/indra/llprimitive/llprimitive.cpp
index 904747af2d..f67959de5b 100644
--- a/indra/llprimitive/llprimitive.cpp
+++ b/indra/llprimitive/llprimitive.cpp
@@ -1825,6 +1825,40 @@ bool LLLightParams::fromLLSD(LLSD& sd)
//============================================================================
+LLMirrorParams::LLMirrorParams()
+{
+ mType = PARAMS_MIRROR;
+}
+
+BOOL LLMirrorParams::pack(LLDataPacker &dp) const
+{
+ return TRUE;
+}
+
+BOOL LLMirrorParams::unpack(LLDataPacker &dp)
+{
+ return TRUE;
+}
+
+bool LLMirrorParams::operator==(const LLNetworkData& data) const
+{
+ if (data.mType != PARAMS_REFLECTION_PROBE)
+ {
+ return false;
+ }
+ return true;
+}
+
+void LLMirrorParams::copy(const LLNetworkData& data)
+{
+ const LLMirrorParams *param = (LLMirrorParams*)&data;
+ mType = param->mType;
+}
+
+//============================================================================
+
+//============================================================================
+
LLReflectionProbeParams::LLReflectionProbeParams()
{
mType = PARAMS_REFLECTION_PROBE;
diff --git a/indra/llprimitive/llprimitive.h b/indra/llprimitive/llprimitive.h
index 0b7dbd703a..88bac34ef2 100644
--- a/indra/llprimitive/llprimitive.h
+++ b/indra/llprimitive/llprimitive.h
@@ -109,6 +109,7 @@ public:
PARAMS_EXTENDED_MESH = 0x70,
PARAMS_RENDER_MATERIAL = 0x80,
PARAMS_REFLECTION_PROBE = 0x90,
+ PARAMS_MIRROR = 0x100,
};
public:
@@ -172,6 +173,16 @@ public:
F32 getCutoff() const { return mCutoff; }
};
+class LLMirrorParams : public LLNetworkData
+{
+public:
+ LLMirrorParams();
+ /*virtual*/ BOOL pack(LLDataPacker &dp) const;
+ /*virtual*/ BOOL unpack(LLDataPacker &dp);
+ /*virtual*/ bool operator==(const LLNetworkData& data) const;
+ /*virtual*/ void copy(const LLNetworkData& data);
+};
+
extern const F32 REFLECTION_PROBE_MIN_AMBIANCE;
extern const F32 REFLECTION_PROBE_MAX_AMBIANCE;
extern const F32 REFLECTION_PROBE_DEFAULT_AMBIANCE;
diff --git a/indra/llprimitive/lltextureentry.cpp b/indra/llprimitive/lltextureentry.cpp
index 71caff1686..ee2a4c769a 100644
--- a/indra/llprimitive/lltextureentry.cpp
+++ b/indra/llprimitive/lltextureentry.cpp
@@ -685,6 +685,7 @@ S32 LLTextureEntry::setMaterialParams(const LLMaterialPtr pMaterialParams)
mMaterialUpdatePending = true;
}
mMaterial = pMaterialParams;
+
return TEM_CHANGE_TEXTURE;
}
diff --git a/indra/llprimitive/lltextureentry.h b/indra/llprimitive/lltextureentry.h
index f5f2c0172d..0935147688 100644
--- a/indra/llprimitive/lltextureentry.h
+++ b/indra/llprimitive/lltextureentry.h
@@ -134,7 +134,7 @@ public:
S32 setGlow(F32 glow);
S32 setMaterialID(const LLMaterialID& pMaterialID);
S32 setMaterialParams(const LLMaterialPtr pMaterialParams);
-
+
virtual const LLUUID &getID() const { return mID; }
const LLColor4 &getColor() const { return mColor; }
const F32 getAlpha() const { return mColor.mV[VALPHA]; }
diff --git a/indra/llrender/llglslshader.cpp b/indra/llrender/llglslshader.cpp
index ccfb8f69be..be5ad08fbe 100644
--- a/indra/llrender/llglslshader.cpp
+++ b/indra/llrender/llglslshader.cpp
@@ -1184,12 +1184,14 @@ S32 LLGLSLShader::getTextureChannel(S32 uniform) const
S32 LLGLSLShader::enableTexture(S32 uniform, LLTexUnit::eTextureType mode, LLTexUnit::eTextureColorSpace space)
{
LL_PROFILE_ZONE_SCOPED_CATEGORY_SHADER;
-
+
if (uniform < 0 || uniform >= (S32)mTexture.size())
{
LL_SHADER_UNIFORM_ERRS() << "Uniform out of range: " << uniform << LL_ENDL;
return -1;
}
+
+
S32 index = mTexture[uniform];
if (index != -1)
{
diff --git a/indra/llrender/llglslshader.h b/indra/llrender/llglslshader.h
index 43d095f73a..e8529ebadc 100644
--- a/indra/llrender/llglslshader.h
+++ b/indra/llrender/llglslshader.h
@@ -56,6 +56,8 @@ public:
bool hasAlphaMask = false;
bool hasReflectionProbes = false;
bool attachNothing = false;
+ bool hasHeroProbes = false;
+ bool isPBRTerrain = false;
};
// ============= Structure for caching shader uniforms ===============
diff --git a/indra/llrender/llgltexture.h b/indra/llrender/llgltexture.h
index 24849d1d1b..1cc8fbe523 100644
--- a/indra/llrender/llgltexture.h
+++ b/indra/llrender/llgltexture.h
@@ -42,7 +42,7 @@ class LLGLTexture : public LLTexture
public:
enum
{
- MAX_IMAGE_SIZE_DEFAULT = 1024,
+ MAX_IMAGE_SIZE_DEFAULT = 2048,
INVALID_DISCARD_LEVEL = 0x7fff
};
diff --git a/indra/llrender/llrendernavprim.cpp b/indra/llrender/llrendernavprim.cpp
index d610a44bc6..eea3077632 100644
--- a/indra/llrender/llrendernavprim.cpp
+++ b/indra/llrender/llrendernavprim.cpp
@@ -40,20 +40,20 @@ LLRenderNavPrim gRenderNav;
//=============================================================================
void LLRenderNavPrim::renderLLTri( const LLVector3& a, const LLVector3& b, const LLVector3& c, const LLColor4U& color ) const
{
- LLColor4 cV(color);
- gGL.color4fv( cV.mV );
- gGL.begin(LLRender::TRIANGLES);
+ gGL.color4ubv(color.mV);
+
+ gGL.begin(LLRender::TRIANGLES);
{
gGL.vertex3fv( a.mV );
gGL.vertex3fv( b.mV );
gGL.vertex3fv( c.mV );
}
- gGL.end();
+ gGL.end();
}
//=============================================================================
void LLRenderNavPrim::renderNavMeshVB( U32 mode, LLVertexBuffer* pVBO, int vertCnt )
{
pVBO->setBuffer();
- pVBO->drawArrays( mode, 0, vertCnt );
+ pVBO->drawArrays( mode, 0, vertCnt );
}
//=============================================================================
diff --git a/indra/llrender/llshadermgr.cpp b/indra/llrender/llshadermgr.cpp
index f78be910d2..33d229bcc9 100644
--- a/indra/llrender/llshadermgr.cpp
+++ b/indra/llrender/llshadermgr.cpp
@@ -224,6 +224,14 @@ BOOL LLShaderMgr::attachShaderFeatures(LLGLSLShader * shader)
return FALSE;
}
}
+
+ if (features->hasHeroProbes)
+ {
+ if (!shader->attachFragmentObject("deferred/heroProbesUtil.glsl"))
+ {
+ return FALSE;
+ }
+ }
if (features->hasShadows)
{
@@ -277,6 +285,14 @@ BOOL LLShaderMgr::attachShaderFeatures(LLGLSLShader * shader)
}
}
+ if (features->isPBRTerrain)
+ {
+ if (!shader->attachFragmentObject("deferred/pbrterrainUtilF.glsl"))
+ {
+ return FALSE;
+ }
+ }
+
// NOTE order of shader object attaching is VERY IMPORTANT!!!
if (features->hasAtmospherics)
{
@@ -572,11 +588,22 @@ GLuint LLShaderMgr::loadShaderFile(const std::string& filename, S32 & shader_lev
}
else
{
- //set version to 1.40
- shader_code_text[shader_code_count++] = strdup("#version 140\n");
- //some implementations of GLSL 1.30 require integer precision be explicitly declared
- extra_code_text[extra_code_count++] = strdup("precision mediump int;\n");
- extra_code_text[extra_code_count++] = strdup("precision highp float;\n");
+ if (type == GL_GEOMETRY_SHADER)
+ {
+ //set version to 1.50
+ shader_code_text[shader_code_count++] = strdup("#version 150\n");
+ //some implementations of GLSL 1.30 require integer precision be explicitly declared
+ extra_code_text[extra_code_count++] = strdup("precision mediump int;\n");
+ extra_code_text[extra_code_count++] = strdup("precision highp float;\n");
+ }
+ else
+ {
+ //set version to 1.40
+ shader_code_text[shader_code_count++] = strdup("#version 140\n");
+ //some implementations of GLSL 1.30 require integer precision be explicitly declared
+ extra_code_text[extra_code_count++] = strdup("precision mediump int;\n");
+ extra_code_text[extra_code_count++] = strdup("precision highp float;\n");
+ }
}
extra_code_text[extra_code_count++] = strdup("#define FXAA_GLSL_130 1\n");
@@ -587,6 +614,7 @@ GLuint LLShaderMgr::loadShaderFile(const std::string& filename, S32 & shader_lev
extra_code_text[extra_code_count++] = strdup("#define GBUFFER_FLAG_SKIP_ATMOS 0.0 \n"); // atmo kill
extra_code_text[extra_code_count++] = strdup("#define GBUFFER_FLAG_HAS_ATMOS 0.34\n"); // bit 0
extra_code_text[extra_code_count++] = strdup("#define GBUFFER_FLAG_HAS_PBR 0.67\n"); // bit 1
+ extra_code_text[extra_code_count++] = strdup("#define GBUFFER_FLAG_HAS_MIRROR 1.0\n"); // bit 2
extra_code_text[extra_code_count++] = strdup("#define GET_GBUFFER_FLAG(flag) (abs(norm.w-flag)< 0.1)\n");
if (defines)
@@ -1192,6 +1220,9 @@ void LLShaderMgr::initAttribsAndUniforms()
mReservedUniforms.push_back("emissiveColor");
mReservedUniforms.push_back("metallicFactor");
mReservedUniforms.push_back("roughnessFactor");
+ mReservedUniforms.push_back("mirror_flag");
+ mReservedUniforms.push_back("clipPlane");
+ mReservedUniforms.push_back("clipSign");
mReservedUniforms.push_back("diffuseMap");
mReservedUniforms.push_back("altDiffuseMap");
@@ -1204,6 +1235,7 @@ void LLShaderMgr::initAttribsAndUniforms()
mReservedUniforms.push_back("sceneDepth");
mReservedUniforms.push_back("reflectionProbes");
mReservedUniforms.push_back("irradianceProbes");
+ mReservedUniforms.push_back("heroProbes");
mReservedUniforms.push_back("cloud_noise_texture");
mReservedUniforms.push_back("cloud_noise_texture_next");
mReservedUniforms.push_back("fullbright");
@@ -1374,8 +1406,32 @@ void LLShaderMgr::initAttribsAndUniforms()
mReservedUniforms.push_back("detail_1");
mReservedUniforms.push_back("detail_2");
mReservedUniforms.push_back("detail_3");
+
mReservedUniforms.push_back("alpha_ramp");
+ mReservedUniforms.push_back("detail_0_base_color");
+ mReservedUniforms.push_back("detail_1_base_color");
+ mReservedUniforms.push_back("detail_2_base_color");
+ mReservedUniforms.push_back("detail_3_base_color");
+ mReservedUniforms.push_back("detail_0_normal");
+ mReservedUniforms.push_back("detail_1_normal");
+ mReservedUniforms.push_back("detail_2_normal");
+ mReservedUniforms.push_back("detail_3_normal");
+ mReservedUniforms.push_back("detail_0_metallic_roughness");
+ mReservedUniforms.push_back("detail_1_metallic_roughness");
+ mReservedUniforms.push_back("detail_2_metallic_roughness");
+ mReservedUniforms.push_back("detail_3_metallic_roughness");
+ mReservedUniforms.push_back("detail_0_emissive");
+ mReservedUniforms.push_back("detail_1_emissive");
+ mReservedUniforms.push_back("detail_2_emissive");
+ mReservedUniforms.push_back("detail_3_emissive");
+
+ mReservedUniforms.push_back("baseColorFactors");
+ mReservedUniforms.push_back("metallicFactors");
+ mReservedUniforms.push_back("roughnessFactors");
+ mReservedUniforms.push_back("emissiveColors");
+ mReservedUniforms.push_back("minimum_alphas");
+
mReservedUniforms.push_back("origin");
mReservedUniforms.push_back("display_gamma");
@@ -1397,6 +1453,7 @@ void LLShaderMgr::initAttribsAndUniforms()
mReservedUniforms.push_back("cloud_variance");
mReservedUniforms.push_back("reflection_probe_ambiance");
mReservedUniforms.push_back("max_probe_lod");
+ mReservedUniforms.push_back("probe_strength");
mReservedUniforms.push_back("sh_input_r");
mReservedUniforms.push_back("sh_input_g");
@@ -1407,6 +1464,8 @@ void LLShaderMgr::initAttribsAndUniforms()
mReservedUniforms.push_back("sun_up_factor");
mReservedUniforms.push_back("moonlight_color");
+ mReservedUniforms.push_back("debug_normal_draw_length");
+
llassert(mReservedUniforms.size() == END_RESERVED_UNIFORMS);
std::set<std::string> dupe_check;
diff --git a/indra/llrender/llshadermgr.h b/indra/llrender/llshadermgr.h
index 79a24773e1..4ee5c8ef47 100644
--- a/indra/llrender/llshadermgr.h
+++ b/indra/llrender/llshadermgr.h
@@ -85,6 +85,9 @@ public:
EMISSIVE_COLOR, // "emissiveColor"
METALLIC_FACTOR, // "metallicFactor"
ROUGHNESS_FACTOR, // "roughnessFactor"
+ MIRROR_FLAG, // "mirror_flag"
+ CLIP_PLANE, // "clipPlane"
+ CLIP_SIGN, // "clipSign"
DIFFUSE_MAP, // "diffuseMap"
ALTERNATE_DIFFUSE_MAP, // "altDiffuseMap"
SPECULAR_MAP, // "specularMap"
@@ -96,6 +99,7 @@ public:
SCENE_DEPTH, // "sceneDepth"
REFLECTION_PROBES, // "reflectionProbes"
IRRADIANCE_PROBES, // "irradianceProbes"
+ HERO_PROBE, // "heroProbes"
CLOUD_NOISE_MAP, // "cloud_noise_texture"
CLOUD_NOISE_MAP_NEXT, // "cloud_noise_texture_next"
FULLBRIGHT, // "fullbright"
@@ -251,8 +255,32 @@ public:
TERRAIN_DETAIL1, // "detail_1"
TERRAIN_DETAIL2, // "detail_2"
TERRAIN_DETAIL3, // "detail_3"
+
TERRAIN_ALPHARAMP, // "alpha_ramp"
+ TERRAIN_DETAIL0_BASE_COLOR, // "detail_0_base_color" (GLTF)
+ TERRAIN_DETAIL1_BASE_COLOR, // "detail_1_base_color" (GLTF)
+ TERRAIN_DETAIL2_BASE_COLOR, // "detail_2_base_color" (GLTF)
+ TERRAIN_DETAIL3_BASE_COLOR, // "detail_3_base_color" (GLTF)
+ TERRAIN_DETAIL0_NORMAL, // "detail_0_normal" (GLTF)
+ TERRAIN_DETAIL1_NORMAL, // "detail_1_normal" (GLTF)
+ TERRAIN_DETAIL2_NORMAL, // "detail_2_normal" (GLTF)
+ TERRAIN_DETAIL3_NORMAL, // "detail_3_normal" (GLTF)
+ TERRAIN_DETAIL0_METALLIC_ROUGHNESS, // "detail_0_metallic_roughness" (GLTF)
+ TERRAIN_DETAIL1_METALLIC_ROUGHNESS, // "detail_1_metallic_roughness" (GLTF)
+ TERRAIN_DETAIL2_METALLIC_ROUGHNESS, // "detail_2_metallic_roughness" (GLTF)
+ TERRAIN_DETAIL3_METALLIC_ROUGHNESS, // "detail_3_metallic_roughness" (GLTF)
+ TERRAIN_DETAIL0_EMISSIVE, // "detail_0_emissive" (GLTF)
+ TERRAIN_DETAIL1_EMISSIVE, // "detail_1_emissive" (GLTF)
+ TERRAIN_DETAIL2_EMISSIVE, // "detail_2_emissive" (GLTF)
+ TERRAIN_DETAIL3_EMISSIVE, // "detail_3_emissive" (GLTF)
+
+ TERRAIN_BASE_COLOR_FACTORS, // "baseColorFactors" (GLTF)
+ TERRAIN_METALLIC_FACTORS, // "metallicFactors" (GLTF)
+ TERRAIN_ROUGHNESS_FACTORS, // "roughnessFactors" (GLTF)
+ TERRAIN_EMISSIVE_COLORS, // "emissiveColors" (GLTF)
+ TERRAIN_MINIMUM_ALPHAS, // "minimum_alphas" (GLTF)
+
SHINY_ORIGIN, // "origin"
DISPLAY_GAMMA, // "display_gamma"
@@ -279,6 +307,7 @@ public:
REFLECTION_PROBE_AMBIANCE, // "reflection_probe_ambiance"
REFLECTION_PROBE_MAX_LOD, // "max_probe_lod"
+ REFLECTION_PROBE_STRENGTH, // "probe_strength"
SH_INPUT_L1R, // "sh_input_r"
SH_INPUT_L1G, // "sh_input_g"
SH_INPUT_L1B, // "sh_input_b"
@@ -287,6 +316,9 @@ public:
WATER_EDGE_FACTOR, // "water_edge"
SUN_UP_FACTOR, // "sun_up_factor"
MOONLIGHT_COLOR, // "moonlight_color"
+
+ DEBUG_NORMAL_DRAW_LENGTH, // "debug_normal_draw_length"
+
END_RESERVED_UNIFORMS
} eGLSLReservedUniforms;
// clang-format on
diff --git a/indra/llrender/llvertexbuffer.cpp b/indra/llrender/llvertexbuffer.cpp
index de27636c33..4f5f30d7c2 100644
--- a/indra/llrender/llvertexbuffer.cpp
+++ b/indra/llrender/llvertexbuffer.cpp
@@ -1319,6 +1319,10 @@ bool LLVertexBuffer::getNormalStrider(LLStrider<LLVector3>& strider, U32 index,
{
return VertexBufferStrider<LLVector3,TYPE_NORMAL>::get(*this, strider, index, count);
}
+bool LLVertexBuffer::getNormalStrider(LLStrider<LLVector4a>& strider, U32 index, S32 count)
+{
+ return VertexBufferStrider<LLVector4a, TYPE_NORMAL>::get(*this, strider, index, count);
+}
bool LLVertexBuffer::getTangentStrider(LLStrider<LLVector3>& strider, U32 index, S32 count)
{
return VertexBufferStrider<LLVector3,TYPE_TANGENT>::get(*this, strider, index, count);
diff --git a/indra/llrender/llvertexbuffer.h b/indra/llrender/llvertexbuffer.h
index f2d146d4bb..cc59e322ed 100644
--- a/indra/llrender/llvertexbuffer.h
+++ b/indra/llrender/llvertexbuffer.h
@@ -180,6 +180,7 @@ public:
bool getTexCoord1Strider(LLStrider<LLVector2>& strider, U32 index=0, S32 count = -1);
bool getTexCoord2Strider(LLStrider<LLVector2>& strider, U32 index=0, S32 count = -1);
bool getNormalStrider(LLStrider<LLVector3>& strider, U32 index=0, S32 count = -1);
+ bool getNormalStrider(LLStrider<LLVector4a>& strider, U32 index = 0, S32 count = -1);
bool getTangentStrider(LLStrider<LLVector3>& strider, U32 index=0, S32 count = -1);
bool getTangentStrider(LLStrider<LLVector4a>& strider, U32 index=0, S32 count = -1);
bool getColorStrider(LLStrider<LLColor4U>& strider, U32 index=0, S32 count = -1);
@@ -187,10 +188,6 @@ public:
bool getWeightStrider(LLStrider<F32>& strider, U32 index=0, S32 count = -1);
bool getWeight4Strider(LLStrider<LLVector4>& strider, U32 index=0, S32 count = -1);
bool getClothWeightStrider(LLStrider<LLVector4>& strider, U32 index=0, S32 count = -1);
- bool getBasecolorTexcoordStrider(LLStrider<LLVector2>& strider, U32 index=0, S32 count = -1);
- bool getNormalTexcoordStrider(LLStrider<LLVector2>& strider, U32 index=0, S32 count = -1);
- bool getMetallicRoughnessTexcoordStrider(LLStrider<LLVector2>& strider, U32 index=0, S32 count = -1);
- bool getEmissiveTexcoordStrider(LLStrider<LLVector2>& strider, U32 index=0, S32 count = -1);
void setPositionData(const LLVector4a* data);
void setTexCoordData(const LLVector2* data);
diff --git a/indra/newview/CMakeLists.txt b/indra/newview/CMakeLists.txt
index 7a70d0b6e6..04d3b64d5c 100644
--- a/indra/newview/CMakeLists.txt
+++ b/indra/newview/CMakeLists.txt
@@ -310,6 +310,7 @@ set(viewer_SOURCE_FILES
llgiveinventory.cpp
llglsandbox.cpp
llgltfmateriallist.cpp
+ llgltfmaterialpreviewmgr.cpp
llgroupactions.cpp
llgroupiconctrl.cpp
llgrouplist.cpp
@@ -519,6 +520,7 @@ set(viewer_SOURCE_FILES
llrecentpeople.cpp
llreflectionmap.cpp
llreflectionmapmanager.cpp
+ llheroprobemanager.cpp
llregioninfomodel.cpp
llregionposition.cpp
llremoteparcelrequest.cpp
@@ -963,6 +965,7 @@ set(viewer_HEADER_FILES
llgesturemgr.h
llgiveinventory.h
llgltfmateriallist.h
+ llgltfmaterialpreviewmgr.h
llgroupactions.h
llgroupiconctrl.h
llgrouplist.h
@@ -1158,6 +1161,7 @@ set(viewer_HEADER_FILES
llrecentpeople.h
llreflectionmap.h
llreflectionmapmanager.h
+ llheroprobemanager.h
llregioninfomodel.h
llregionposition.h
llremoteparcelrequest.h
diff --git a/indra/newview/app_settings/settings.xml b/indra/newview/app_settings/settings.xml
index 00b59f9a4d..85b90a8da5 100644
--- a/indra/newview/app_settings/settings.xml
+++ b/indra/newview/app_settings/settings.xml
@@ -3244,17 +3244,6 @@
<key>Value</key>
<integer>0</integer>
</map>
- <key>DefaultBlankNormalTexture</key>
- <map>
- <key>Comment</key>
- <string>Texture used as 'Blank' in texture picker for normal maps. (UUID texture reference)</string>
- <key>Persist</key>
- <integer>1</integer>
- <key>Type</key>
- <string>String</string>
- <key>Value</key>
- <string>5b53359e-59dd-d8a2-04c3-9e65134da47a</string>
- </map>
<key>DefaultFemaleAvatar</key>
<map>
<key>Comment</key>
@@ -3288,39 +3277,6 @@
<key>Value</key>
<string>Male Shape &amp; Outfit</string>
</map>
- <key>DefaultObjectNormalTexture</key>
- <map>
- <key>Comment</key>
- <string>Texture used as 'Default' in texture picker for normal map. (UUID texture reference)</string>
- <key>Persist</key>
- <integer>1</integer>
- <key>Type</key>
- <string>String</string>
- <key>Value</key>
- <string>85f28839-7a1c-b4e3-d71d-967792970a7b</string>
- </map>
- <key>DefaultObjectSpecularTexture</key>
- <map>
- <key>Comment</key>
- <string>Texture used as 'Default' in texture picker for specular map. (UUID texture reference)</string>
- <key>Persist</key>
- <integer>1</integer>
- <key>Type</key>
- <string>String</string>
- <key>Value</key>
- <string>87e0e8f7-8729-1ea8-cfc9-8915773009db</string>
- </map>
- <key>DefaultObjectTexture</key>
- <map>
- <key>Comment</key>
- <string>Texture used as 'Default' in texture picker. (UUID texture reference)</string>
- <key>Persist</key>
- <integer>1</integer>
- <key>Type</key>
- <string>String</string>
- <key>Value</key>
- <string>89556747-24cb-43ed-920b-47caed15465f</string>
- </map>
<key>DefaultUploadCost</key>
<map>
<key>Comment</key>
@@ -9197,6 +9153,17 @@
<real>0.00</real>
</array>
</map>
+ <key>RenderMirrors</key>
+ <map>
+ <key>Comment</key>
+ <string>Renders realtime mirrors.</string>
+ <key>Persist</key>
+ <integer>1</integer>
+ <key>Type</key>
+ <string>Boolean</string>
+ <key>Value</key>
+ <integer>0</integer>
+ </map>
<key>RenderScreenSpaceReflections</key>
<map>
<key>Comment</key>
@@ -10401,6 +10368,39 @@
<key>Value</key>
<integer>0</integer>
</map>
+ <key>RenderHeroProbeResolution</key>
+ <map>
+ <key>Comment</key>
+ <string>Resolution to render hero probes used for mirrors, water, etc.</string>
+ <key>Persist</key>
+ <integer>1</integer>
+ <key>Type</key>
+ <string>S32</string>
+ <key>Value</key>
+ <integer>1024</integer>
+ </map>
+ <key>RenderHeroProbeDistance</key>
+ <map>
+ <key>Comment</key>
+ <string>Distance in meters for hero probes to render out to.</string>
+ <key>Persist</key>
+ <integer>1</integer>
+ <key>Type</key>
+ <string>F32</string>
+ <key>Value</key>
+ <real>16</real>
+ </map>
+ <key>RenderHeroProbeNearClipOffset</key>
+ <map>
+ <key>Comment</key>
+ <string>Distance offset in meters for hero probes to near clip.</string>
+ <key>Persist</key>
+ <integer>1</integer>
+ <key>Type</key>
+ <string>F32</string>
+ <key>Value</key>
+ <real>2.1</real>
+ </map>
<key>RenderReflectionProbeVolumes</key>
<map>
<key>Comment</key>
@@ -10676,7 +10676,7 @@
<key>Type</key>
<string>F32</string>
<key>Value</key>
- <real>2.0</real>
+ <real>1.0</real>
</map>
<key>RendeSkyAutoAdjustBlueHorizonScale</key>
<map>
@@ -10720,7 +10720,7 @@
<key>Type</key>
<string>F32</string>
<key>Value</key>
- <real>0.001</real>
+ <real>0.01</real>
</map>
<key>RenderSkySunlightScale</key>
<map>
@@ -10825,7 +10825,7 @@
<key>RenderTerrainScale</key>
<map>
<key>Comment</key>
- <string>Terrain detail texture scale</string>
+ <string>Terrain detail texture scale (meters)</string>
<key>Persist</key>
<integer>1</integer>
<key>Type</key>
@@ -10833,6 +10833,83 @@
<key>Value</key>
<real>12.0</real>
</map>
+ <key>RenderTerrainPBREnabled</key>
+ <map>
+ <key>Comment</key>
+ <string>EXPERIMENTAL: Enable PBR Terrain features. Requires restart.</string>
+ <key>Persist</key>
+ <integer>1</integer>
+ <key>Type</key>
+ <string>Boolean</string>
+ <key>Value</key>
+ <integer>0</integer>
+ </map>
+ <key>RenderTerrainPBRForce</key>
+ <map>
+ <key>Comment</key>
+ <string>Force-load PBR terrain if enabled</string>
+ <key>Persist</key>
+ <integer>0</integer>
+ <key>Type</key>
+ <string>Boolean</string>
+ <key>Value</key>
+ <integer>0</integer>
+ </map>
+ <key>RenderTerrainPBRDetail</key>
+ <map>
+ <key>Comment</key>
+ <string>Detail level for PBR terrain. 0 is full detail. Negative values drop rendering features, in accordance with the GLTF specification when possible, which reduces the number of texture binds.</string>
+ <key>Persist</key>
+ <integer>1</integer>
+ <key>Type</key>
+ <string>S32</string>
+ <key>Value</key>
+ <integer>0</integer>
+ </map>
+ <key>RenderTerrainPBRScale</key>
+ <map>
+ <key>Comment</key>
+ <string>PBR terrain detail texture scale (meters)</string>
+ <key>Persist</key>
+ <integer>1</integer>
+ <key>Type</key>
+ <string>F32</string>
+ <key>Value</key>
+ <real>4.0</real>
+ </map>
+ <key>RenderTerrainPBRPlanarSampleCount</key>
+ <map>
+ <key>Comment</key>
+ <string>How many UV planes to sample PBR terrain textures from. 1 is "flat", 3 is triplanar mapping (aka box mapping)</string>
+ <key>Persist</key>
+ <integer>1</integer>
+ <key>Type</key>
+ <string>S32</string>
+ <key>Value</key>
+ <real>3</real>
+ </map>
+ <key>RenderTerrainPBRTriplanarBlendFactor</key>
+ <map>
+ <key>Comment</key>
+ <string>Higher values create sharper transitions, but are more likely to produce artifacts.</string>
+ <key>Persist</key>
+ <integer>1</integer>
+ <key>Type</key>
+ <string>F32</string>
+ <key>Value</key>
+ <real>8.0</real>
+ </map>
+ <key>RenderTerrainPBRNormalsEnabled</key>
+ <map>
+ <key>Comment</key>
+ <string>EXPERIMENTAL: Change normal gen for PBR Terrain.</string>
+ <key>Persist</key>
+ <integer>1</integer>
+ <key>Type</key>
+ <string>Boolean</string>
+ <key>Value</key>
+ <integer>0</integer>
+ </map>
<key>RenderTrackerBeacon</key>
<map>
<key>Comment</key>
@@ -13620,17 +13697,6 @@
<key>Value</key>
<string>F3E07BC8-A973-476D-8C7F-F3B7293975D1</string>
</map>
- <key>UIImgWhiteUUID</key>
- <map>
- <key>Comment</key>
- <string />
- <key>Persist</key>
- <integer>0</integer>
- <key>Type</key>
- <string>String</string>
- <key>Value</key>
- <string>5748decc-f629-461c-9a36-a35a221fe21f</string>
- </map>
<key>UILineEditorCursorThickness</key>
<map>
<key>Comment</key>
@@ -15689,7 +15755,7 @@
<key>Type</key>
<string>S32</string>
<key>Value</key>
- <integer>2048</integer>
+ <integer>1024</integer>
</map>
<key>max_texture_dimension_Y</key>
<map>
@@ -15700,7 +15766,7 @@
<key>Type</key>
<string>S32</string>
<key>Value</key>
- <integer>2048</integer>
+ <integer>1024</integer>
</map>
<!-- End of back compatibility settings -->
<key>teleport_offer_invitation_max_length</key>
@@ -16576,6 +16642,50 @@
<key>Value</key>
<integer>0</integer>
</map>
+ <key>LocalTerrainAsset1</key>
+ <map>
+ <key>Comment</key>
+ <string>If set to a non-null UUID, overrides the terrain asset locally for all regions with material assets. Local terrain assets are not visible to others. Please keep in mind that this debug setting may be temporary. Do not rely on this setting existing in future viewer builds.</string>
+ <key>Persist</key>
+ <integer>0</integer>
+ <key>Type</key>
+ <string>String</string>
+ <key>Value</key>
+ <string>00000000-0000-0000-0000-000000000000</string>
+ </map>
+ <key>LocalTerrainAsset2</key>
+ <map>
+ <key>Comment</key>
+ <string>If set to a non-null UUID, overrides the terrain asset locally for all regions with material assets. Local terrain assets are not visible to others. Please keep in mind that this debug setting may be temporary. Do not rely on this setting existing in future viewer builds.</string>
+ <key>Persist</key>
+ <integer>0</integer>
+ <key>Type</key>
+ <string>String</string>
+ <key>Value</key>
+ <string>00000000-0000-0000-0000-000000000000</string>
+ </map>
+ <key>LocalTerrainAsset3</key>
+ <map>
+ <key>Comment</key>
+ <string>If set to a non-null UUID, overrides the terrain asset locally for all regions with material assets. Local terrain assets are not visible to others. Please keep in mind that this debug setting may be temporary. Do not rely on this setting existing in future viewer builds.</string>
+ <key>Persist</key>
+ <integer>0</integer>
+ <key>Type</key>
+ <string>String</string>
+ <key>Value</key>
+ <string>00000000-0000-0000-0000-000000000000</string>
+ </map>
+ <key>LocalTerrainAsset4</key>
+ <map>
+ <key>Comment</key>
+ <string>If set to a non-null UUID, overrides the terrain asset locally for all regions with material assets. Local terrain assets are not visible to others. Please keep in mind that this debug setting may be temporary. Do not rely on this setting existing in future viewer builds.</string>
+ <key>Persist</key>
+ <integer>0</integer>
+ <key>Type</key>
+ <string>String</string>
+ <key>Value</key>
+ <string>00000000-0000-0000-0000-000000000000</string>
+ </map>
<key>PathfindingRetrieveNeighboringRegion</key>
<map>
<key>Comment</key>
diff --git a/indra/newview/app_settings/shaders/class1/deferred/materialV.glsl b/indra/newview/app_settings/shaders/class1/deferred/materialV.glsl
index 7cdddfe8db..65706e2c3f 100644
--- a/indra/newview/app_settings/shaders/class1/deferred/materialV.glsl
+++ b/indra/newview/app_settings/shaders/class1/deferred/materialV.glsl
@@ -28,25 +28,18 @@
#define DIFFUSE_ALPHA_MODE_MASK 2
#define DIFFUSE_ALPHA_MODE_EMISSIVE 3
-#ifdef HAS_SKIN
uniform mat4 modelview_matrix;
uniform mat4 projection_matrix;
+uniform mat4 modelview_projection_matrix;
+
+#ifdef HAS_SKIN
mat4 getObjectSkinnedTransform();
#else
uniform mat3 normal_matrix;
-uniform mat4 modelview_projection_matrix;
-#endif
-
-#if (DIFFUSE_ALPHA_MODE == DIFFUSE_ALPHA_MODE_BLEND)
-
-#if !defined(HAS_SKIN)
-uniform mat4 modelview_matrix;
#endif
out vec3 vary_position;
-#endif
-
uniform mat4 texture_matrix0;
in vec3 position;
@@ -133,10 +126,8 @@ void main()
vertex_color = diffuse_color;
-#if (DIFFUSE_ALPHA_MODE == DIFFUSE_ALPHA_MODE_BLEND)
#if !defined(HAS_SKIN)
- vary_position = (modelview_matrix*vec4(position.xyz, 1.0)).xyz;
-#endif
+ vary_position = (projection_matrix*vec4(position.xyz, 1.0)).xyz;
#endif
}
diff --git a/indra/newview/app_settings/shaders/class1/deferred/pbropaqueF.glsl b/indra/newview/app_settings/shaders/class1/deferred/pbropaqueF.glsl
index faa273b834..9b98a37925 100644
--- a/indra/newview/app_settings/shaders/class1/deferred/pbropaqueF.glsl
+++ b/indra/newview/app_settings/shaders/class1/deferred/pbropaqueF.glsl
@@ -58,10 +58,37 @@ vec2 encode_normal(vec3 n);
vec3 linear_to_srgb(vec3 c);
vec3 srgb_to_linear(vec3 c);
+uniform vec4 clipPlane;
+uniform float clipSign;
+uniform float mirror_flag;
+void applyClip(vec3 pos)
+{
+ if (mirror_flag > 0)
+ {
+ // TODO: make this less branchy
+ if (clipSign > 0)
+ {
+ if ((dot(pos.xyz, clipPlane.xyz) + clipPlane.w) < 0.0)
+ {
+ discard;
+ }
+ }
+ else
+ {
+ if ((dot(pos.xyz, clipPlane.xyz) + clipPlane.w) > 0.0)
+ {
+ discard;
+ }
+ }
+ }
+}
+
uniform mat3 normal_matrix;
void main()
{
+ applyClip(vary_position);
+
vec4 basecolor = texture(diffuseMap, base_color_texcoord.xy).rgba;
if (basecolor.a < minimum_alpha)
{
diff --git a/indra/newview/app_settings/shaders/class1/deferred/pbrterrainF.glsl b/indra/newview/app_settings/shaders/class1/deferred/pbrterrainF.glsl
new file mode 100644
index 0000000000..c83a6be85d
--- /dev/null
+++ b/indra/newview/app_settings/shaders/class1/deferred/pbrterrainF.glsl
@@ -0,0 +1,344 @@
+/**
+ * @file class1\deferred\terrainF.glsl
+ *
+ * $LicenseInfo:firstyear=2023&license=viewerlgpl$
+ * Second Life Viewer Source Code
+ * Copyright (C) 2023, Linden Research, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation;
+ * version 2.1 of the License only.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
+ * $/LicenseInfo$
+ */
+
+/*[EXTRA_CODE_HERE]*/
+
+#define TERRAIN_PBR_DETAIL_EMISSIVE 0
+#define TERRAIN_PBR_DETAIL_OCCLUSION -1
+#define TERRAIN_PBR_DETAIL_NORMAL -2
+#define TERRAIN_PBR_DETAIL_METALLIC_ROUGHNESS -3
+
+#if TERRAIN_PLANAR_TEXTURE_SAMPLE_COUNT == 3
+#define TerrainCoord vec4[2]
+#elif TERRAIN_PLANAR_TEXTURE_SAMPLE_COUNT == 1
+#define TerrainCoord vec2
+#endif
+
+#define MIX_X 1 << 3
+#define MIX_Y 1 << 4
+#define MIX_Z 1 << 5
+#define MIX_W 1 << 6
+
+struct TerrainMix
+{
+ vec4 weight;
+ int type;
+};
+
+TerrainMix get_terrain_mix_weights(float alpha1, float alpha2, float alphaFinal);
+
+struct PBRMix
+{
+ vec4 col; // RGB color with alpha, linear space
+#if (TERRAIN_PBR_DETAIL >= TERRAIN_PBR_DETAIL_OCCLUSION)
+ vec3 orm; // Occlusion, roughness, metallic
+#elif (TERRAIN_PBR_DETAIL >= TERRAIN_PBR_DETAIL_METALLIC_ROUGHNESS)
+ vec2 rm; // Roughness, metallic
+#endif
+#if (TERRAIN_PBR_DETAIL >= TERRAIN_PBR_DETAIL_NORMAL)
+ vec3 vNt; // Unpacked normal texture sample, vector
+#endif
+#if (TERRAIN_PBR_DETAIL >= TERRAIN_PBR_DETAIL_EMISSIVE)
+ vec3 emissive; // RGB emissive color, linear space
+#endif
+};
+
+PBRMix init_pbr_mix();
+
+PBRMix terrain_sample_and_multiply_pbr(
+ TerrainCoord terrain_coord
+ , sampler2D tex_col
+#if (TERRAIN_PBR_DETAIL >= TERRAIN_PBR_DETAIL_METALLIC_ROUGHNESS)
+ , sampler2D tex_orm
+#endif
+#if (TERRAIN_PBR_DETAIL >= TERRAIN_PBR_DETAIL_NORMAL)
+ , sampler2D tex_vNt
+#endif
+#if (TERRAIN_PBR_DETAIL >= TERRAIN_PBR_DETAIL_EMISSIVE)
+ , sampler2D tex_emissive
+#endif
+ , vec4 factor_col
+#if (TERRAIN_PBR_DETAIL >= TERRAIN_PBR_DETAIL_OCCLUSION)
+ , vec3 factor_orm
+#elif (TERRAIN_PBR_DETAIL >= TERRAIN_PBR_DETAIL_METALLIC_ROUGHNESS)
+ , vec2 factor_rm
+#endif
+#if (TERRAIN_PBR_DETAIL >= TERRAIN_PBR_DETAIL_EMISSIVE)
+ , vec3 factor_emissive
+#endif
+ );
+
+PBRMix mix_pbr(PBRMix mix1, PBRMix mix2, float mix2_weight);
+
+out vec4 frag_data[4];
+
+uniform sampler2D alpha_ramp;
+
+// https://registry.khronos.org/glTF/specs/2.0/glTF-2.0.html#additional-textures
+uniform sampler2D detail_0_base_color;
+uniform sampler2D detail_1_base_color;
+uniform sampler2D detail_2_base_color;
+uniform sampler2D detail_3_base_color;
+#if (TERRAIN_PBR_DETAIL >= TERRAIN_PBR_DETAIL_NORMAL)
+uniform sampler2D detail_0_normal;
+uniform sampler2D detail_1_normal;
+uniform sampler2D detail_2_normal;
+uniform sampler2D detail_3_normal;
+#endif
+#if (TERRAIN_PBR_DETAIL >= TERRAIN_PBR_DETAIL_METALLIC_ROUGHNESS)
+uniform sampler2D detail_0_metallic_roughness;
+uniform sampler2D detail_1_metallic_roughness;
+uniform sampler2D detail_2_metallic_roughness;
+uniform sampler2D detail_3_metallic_roughness;
+#endif
+#if (TERRAIN_PBR_DETAIL >= TERRAIN_PBR_DETAIL_EMISSIVE)
+uniform sampler2D detail_0_emissive;
+uniform sampler2D detail_1_emissive;
+uniform sampler2D detail_2_emissive;
+uniform sampler2D detail_3_emissive;
+#endif
+
+uniform vec4[4] baseColorFactors; // See also vertex_color in pbropaqueV.glsl
+#if (TERRAIN_PBR_DETAIL >= TERRAIN_PBR_DETAIL_METALLIC_ROUGHNESS)
+uniform vec4 metallicFactors;
+uniform vec4 roughnessFactors;
+#endif
+#if (TERRAIN_PBR_DETAIL >= TERRAIN_PBR_DETAIL_EMISSIVE)
+uniform vec3[4] emissiveColors;
+#endif
+uniform vec4 minimum_alphas; // PBR alphaMode: MASK, See: mAlphaCutoff, setAlphaCutoff()
+
+#if TERRAIN_PLANAR_TEXTURE_SAMPLE_COUNT == 3
+in vec4[2] vary_coords;
+#endif
+in vec3 vary_normal;
+in vec3 vary_tangent;
+flat in float vary_sign;
+in vec4 vary_texcoord0;
+in vec4 vary_texcoord1;
+
+vec2 encode_normal(vec3 n);
+
+float terrain_mix(TerrainMix tm, vec4 tms4);
+
+void main()
+{
+
+#if TERRAIN_PLANAR_TEXTURE_SAMPLE_COUNT == 3
+ TerrainCoord terrain_texcoord = vary_coords;
+#elif TERRAIN_PLANAR_TEXTURE_SAMPLE_COUNT == 1
+ TerrainCoord terrain_texcoord = vary_texcoord0.xy;
+#endif
+
+ 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;
+
+ TerrainMix tm = get_terrain_mix_weights(alpha1, alpha2, alphaFinal);
+
+#if (TERRAIN_PBR_DETAIL >= TERRAIN_PBR_DETAIL_OCCLUSION)
+ // RGB = Occlusion, Roughness, Metal
+ // default values, see LLViewerTexture::sDefaultPBRORMImagep
+ // occlusion 1.0
+ // roughness 0.0
+ // metal 0.0
+ vec3[4] orm_factors;
+ orm_factors[0] = vec3(1.0, roughnessFactors.x, metallicFactors.x);
+ orm_factors[1] = vec3(1.0, roughnessFactors.y, metallicFactors.y);
+ orm_factors[2] = vec3(1.0, roughnessFactors.z, metallicFactors.z);
+ orm_factors[3] = vec3(1.0, roughnessFactors.w, metallicFactors.w);
+#elif (TERRAIN_PBR_DETAIL >= TERRAIN_PBR_DETAIL_METALLIC_ROUGHNESS)
+ vec2[4] rm_factors;
+ rm_factors[0] = vec2(roughnessFactors.x, metallicFactors.x);
+ rm_factors[1] = vec2(roughnessFactors.y, metallicFactors.y);
+ rm_factors[2] = vec2(roughnessFactors.z, metallicFactors.z);
+ rm_factors[3] = vec2(roughnessFactors.w, metallicFactors.w);
+#endif
+
+ PBRMix mix = init_pbr_mix();
+ PBRMix mix2;
+ switch (tm.type & MIX_X)
+ {
+ case MIX_X:
+ mix2 = terrain_sample_and_multiply_pbr(
+ terrain_texcoord
+ , detail_0_base_color
+#if (TERRAIN_PBR_DETAIL >= TERRAIN_PBR_DETAIL_METALLIC_ROUGHNESS)
+ , detail_0_metallic_roughness
+#endif
+#if (TERRAIN_PBR_DETAIL >= TERRAIN_PBR_DETAIL_NORMAL)
+ , detail_0_normal
+#endif
+#if (TERRAIN_PBR_DETAIL >= TERRAIN_PBR_DETAIL_EMISSIVE)
+ , detail_0_emissive
+#endif
+ , baseColorFactors[0]
+#if (TERRAIN_PBR_DETAIL >= TERRAIN_PBR_DETAIL_OCCLUSION)
+ , orm_factors[0]
+#elif (TERRAIN_PBR_DETAIL >= TERRAIN_PBR_DETAIL_METALLIC_ROUGHNESS)
+ , rm_factors[0]
+#endif
+#if (TERRAIN_PBR_DETAIL >= TERRAIN_PBR_DETAIL_EMISSIVE)
+ , emissiveColors[0]
+#endif
+ );
+ mix = mix_pbr(mix, mix2, tm.weight.x);
+ break;
+ default:
+ break;
+ }
+ switch (tm.type & MIX_Y)
+ {
+ case MIX_Y:
+ mix2 = terrain_sample_and_multiply_pbr(
+ terrain_texcoord
+ , detail_1_base_color
+#if (TERRAIN_PBR_DETAIL >= TERRAIN_PBR_DETAIL_METALLIC_ROUGHNESS)
+ , detail_1_metallic_roughness
+#endif
+#if (TERRAIN_PBR_DETAIL >= TERRAIN_PBR_DETAIL_NORMAL)
+ , detail_1_normal
+#endif
+#if (TERRAIN_PBR_DETAIL >= TERRAIN_PBR_DETAIL_EMISSIVE)
+ , detail_1_emissive
+#endif
+ , baseColorFactors[1]
+#if (TERRAIN_PBR_DETAIL >= TERRAIN_PBR_DETAIL_OCCLUSION)
+ , orm_factors[1]
+#elif (TERRAIN_PBR_DETAIL >= TERRAIN_PBR_DETAIL_METALLIC_ROUGHNESS)
+ , rm_factors[1]
+#endif
+#if (TERRAIN_PBR_DETAIL >= TERRAIN_PBR_DETAIL_EMISSIVE)
+ , emissiveColors[1]
+#endif
+ );
+ mix = mix_pbr(mix, mix2, tm.weight.y);
+ break;
+ default:
+ break;
+ }
+ switch (tm.type & MIX_Z)
+ {
+ case MIX_Z:
+ mix2 = terrain_sample_and_multiply_pbr(
+ terrain_texcoord
+ , detail_2_base_color
+#if (TERRAIN_PBR_DETAIL >= TERRAIN_PBR_DETAIL_METALLIC_ROUGHNESS)
+ , detail_2_metallic_roughness
+#endif
+#if (TERRAIN_PBR_DETAIL >= TERRAIN_PBR_DETAIL_NORMAL)
+ , detail_2_normal
+#endif
+#if (TERRAIN_PBR_DETAIL >= TERRAIN_PBR_DETAIL_EMISSIVE)
+ , detail_2_emissive
+#endif
+ , baseColorFactors[2]
+#if (TERRAIN_PBR_DETAIL >= TERRAIN_PBR_DETAIL_OCCLUSION)
+ , orm_factors[2]
+#elif (TERRAIN_PBR_DETAIL >= TERRAIN_PBR_DETAIL_METALLIC_ROUGHNESS)
+ , rm_factors[2]
+#endif
+#if (TERRAIN_PBR_DETAIL >= TERRAIN_PBR_DETAIL_EMISSIVE)
+ , emissiveColors[2]
+#endif
+ );
+ mix = mix_pbr(mix, mix2, tm.weight.z);
+ break;
+ default:
+ break;
+ }
+ switch (tm.type & MIX_W)
+ {
+ case MIX_W:
+ mix2 = terrain_sample_and_multiply_pbr(
+ terrain_texcoord
+ , detail_3_base_color
+#if (TERRAIN_PBR_DETAIL >= TERRAIN_PBR_DETAIL_METALLIC_ROUGHNESS)
+ , detail_3_metallic_roughness
+#endif
+#if (TERRAIN_PBR_DETAIL >= TERRAIN_PBR_DETAIL_NORMAL)
+ , detail_3_normal
+#endif
+#if (TERRAIN_PBR_DETAIL >= TERRAIN_PBR_DETAIL_EMISSIVE)
+ , detail_3_emissive
+#endif
+ , baseColorFactors[3]
+#if (TERRAIN_PBR_DETAIL >= TERRAIN_PBR_DETAIL_OCCLUSION)
+ , orm_factors[3]
+#elif (TERRAIN_PBR_DETAIL >= TERRAIN_PBR_DETAIL_METALLIC_ROUGHNESS)
+ , rm_factors[3]
+#endif
+#if (TERRAIN_PBR_DETAIL >= TERRAIN_PBR_DETAIL_EMISSIVE)
+ , emissiveColors[3]
+#endif
+ );
+ mix = mix_pbr(mix, mix2, tm.weight.w);
+ break;
+ default:
+ break;
+ }
+
+ float minimum_alpha = terrain_mix(tm, minimum_alphas);
+ if (mix.col.a < minimum_alpha)
+ {
+ discard;
+ }
+ float base_color_factor_alpha = terrain_mix(tm, vec4(baseColorFactors[0].z, baseColorFactors[1].z, baseColorFactors[2].z, baseColorFactors[3].z));
+
+#if (TERRAIN_PBR_DETAIL >= TERRAIN_PBR_DETAIL_NORMAL)
+ // from mikktspace.com
+ vec3 vNt = mix.vNt;
+ vec3 vN = vary_normal;
+ vec3 vT = vary_tangent.xyz;
+
+ vec3 vB = vary_sign * cross(vN, vT);
+ vec3 tnorm = normalize( vNt.x * vT + vNt.y * vB + vNt.z * vN );
+
+ tnorm *= gl_FrontFacing ? 1.0 : -1.0;
+#else
+ vec3 tnorm = vary_normal;
+ tnorm *= gl_FrontFacing ? 1.0 : -1.0;
+#endif
+
+
+#if (TERRAIN_PBR_DETAIL >= TERRAIN_PBR_DETAIL_EMISSIVE)
+#define emissive mix.emissive
+#else
+#define emissive vec3(0)
+#endif
+#if (TERRAIN_PBR_DETAIL >= TERRAIN_PBR_DETAIL_OCCLUSION)
+#define orm mix.orm
+#elif (TERRAIN_PBR_DETAIL >= TERRAIN_PBR_DETAIL_METALLIC_ROUGHNESS)
+#define orm vec3(1.0, mix.rm)
+#else
+// Matte plastic potato terrain
+#define orm vec3(1.0, 1.0, 0.0)
+#endif
+ frag_data[0] = max(vec4(mix.col.xyz, 0.0), vec4(0)); // Diffuse
+ frag_data[1] = max(vec4(orm.rgb, base_color_factor_alpha), vec4(0)); // PBR linear packed Occlusion, Roughness, Metal.
+ frag_data[2] = max(vec4(encode_normal(tnorm), base_color_factor_alpha, GBUFFER_FLAG_HAS_PBR), vec4(0)); // normal, environment intensity, flags
+ frag_data[3] = max(vec4(emissive,0), vec4(0)); // PBR sRGB Emissive
+}
+
diff --git a/indra/newview/app_settings/shaders/class1/deferred/pbrterrainUtilF.glsl b/indra/newview/app_settings/shaders/class1/deferred/pbrterrainUtilF.glsl
new file mode 100644
index 0000000000..935c3f9301
--- /dev/null
+++ b/indra/newview/app_settings/shaders/class1/deferred/pbrterrainUtilF.glsl
@@ -0,0 +1,473 @@
+/**
+ * @file class1\deferred\pbrterrainUtilF.glsl
+ *
+ * $LicenseInfo:firstyear=2023&license=viewerlgpl$
+ * Second Life Viewer Source Code
+ * Copyright (C) 2023, Linden Research, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation;
+ * version 2.1 of the License only.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
+ * $/LicenseInfo$
+ */
+
+/*[EXTRA_CODE_HERE]*/
+
+/**
+ * Triplanar mapping implementation adapted from Inigo Quilez' example shader,
+ * MIT license.
+ * https://www.shadertoy.com/view/MtsGWH
+ * Copyright © 2015 Inigo Quilez
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to
+ * deal in the Software without restriction, including without limitation the
+ * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
+ * sell copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions: The above copyright
+ * notice and this permission notice shall be included in all copies or
+ * substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS",
+ * WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
+ * TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+ * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
+ * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+#define TERRAIN_PBR_DETAIL_EMISSIVE 0
+#define TERRAIN_PBR_DETAIL_OCCLUSION -1
+#define TERRAIN_PBR_DETAIL_NORMAL -2
+#define TERRAIN_PBR_DETAIL_METALLIC_ROUGHNESS -3
+
+in vec3 vary_vertex_normal;
+
+vec3 srgb_to_linear(vec3 c);
+
+// A relatively agressive threshold for terrain material mixing sampling
+// cutoff. This ensures that only one or two materials are used in most places,
+// making PBR terrain blending more performant. Should be greater than 0 to work.
+#define TERRAIN_RAMP_MIX_THRESHOLD 0.1
+// A small threshold for triplanar mapping sampling cutoff. This and
+// TERRAIN_TRIPLANAR_BLEND_FACTOR together ensures that only one or two samples
+// per texture are used in most places, making triplanar mapping more
+// performant. Should be greater than 0 to work.
+// There's also an artistic design choice in the use of these factors, and the
+// use of triplanar generally. Don't take these triplanar constants for granted.
+#define TERRAIN_TRIPLANAR_MIX_THRESHOLD 0.01
+
+#define SAMPLE_X 1 << 0
+#define SAMPLE_Y 1 << 1
+#define SAMPLE_Z 1 << 2
+#define MIX_X 1 << 3
+#define MIX_Y 1 << 4
+#define MIX_Z 1 << 5
+#define MIX_W 1 << 6
+
+struct PBRMix
+{
+ vec4 col; // RGB color with alpha, linear space
+#if (TERRAIN_PBR_DETAIL >= TERRAIN_PBR_DETAIL_OCCLUSION)
+ vec3 orm; // Occlusion, roughness, metallic
+#elif (TERRAIN_PBR_DETAIL >= TERRAIN_PBR_DETAIL_METALLIC_ROUGHNESS)
+ vec2 rm; // Roughness, metallic
+#endif
+#if (TERRAIN_PBR_DETAIL >= TERRAIN_PBR_DETAIL_NORMAL)
+ vec3 vNt; // Unpacked normal texture sample, vector
+#endif
+#if (TERRAIN_PBR_DETAIL >= TERRAIN_PBR_DETAIL_EMISSIVE)
+ vec3 emissive; // RGB emissive color, linear space
+#endif
+};
+
+PBRMix init_pbr_mix()
+{
+ PBRMix mix;
+ mix.col = vec4(0);
+#if (TERRAIN_PBR_DETAIL >= TERRAIN_PBR_DETAIL_OCCLUSION)
+ mix.orm = vec3(0);
+#elif (TERRAIN_PBR_DETAIL >= TERRAIN_PBR_DETAIL_METALLIC_ROUGHNESS)
+ mix.rm = vec2(0);
+#endif
+#if (TERRAIN_PBR_DETAIL >= TERRAIN_PBR_DETAIL_NORMAL)
+ mix.vNt = vec3(0);
+#endif
+#if (TERRAIN_PBR_DETAIL >= TERRAIN_PBR_DETAIL_EMISSIVE)
+ mix.emissive = vec3(0);
+#endif
+ return mix;
+}
+
+// Usage example, for two weights:
+// vec2 weights = ... // Weights must add up to 1
+// PBRMix mix = init_pbr_mix();
+// PBRMix mix1 = ...
+// mix = mix_pbr(mix, mix1, weights.x);
+// PBRMix mix2 = ...
+// mix = mix_pbr(mix, mix2, weights.y);
+PBRMix mix_pbr(PBRMix mix1, PBRMix mix2, float mix2_weight)
+{
+ PBRMix mix;
+ mix.col = mix1.col + (mix2.col * mix2_weight);
+#if (TERRAIN_PBR_DETAIL >= TERRAIN_PBR_DETAIL_OCCLUSION)
+ mix.orm = mix1.orm + (mix2.orm * mix2_weight);
+#elif (TERRAIN_PBR_DETAIL >= TERRAIN_PBR_DETAIL_METALLIC_ROUGHNESS)
+ mix.rm = mix1.rm + (mix2.rm * mix2_weight);
+#endif
+#if (TERRAIN_PBR_DETAIL >= TERRAIN_PBR_DETAIL_NORMAL)
+ mix.vNt = mix1.vNt + (mix2.vNt * mix2_weight);
+#endif
+#if (TERRAIN_PBR_DETAIL >= TERRAIN_PBR_DETAIL_EMISSIVE)
+ mix.emissive = mix1.emissive + (mix2.emissive * mix2_weight);
+#endif
+ return mix;
+}
+
+PBRMix sample_pbr(
+ vec2 uv
+ , sampler2D tex_col
+#if (TERRAIN_PBR_DETAIL >= TERRAIN_PBR_DETAIL_METALLIC_ROUGHNESS)
+ , sampler2D tex_orm
+#endif
+#if (TERRAIN_PBR_DETAIL >= TERRAIN_PBR_DETAIL_NORMAL)
+ , sampler2D tex_vNt
+#endif
+#if (TERRAIN_PBR_DETAIL >= TERRAIN_PBR_DETAIL_EMISSIVE)
+ , sampler2D tex_emissive
+#endif
+ )
+{
+ PBRMix mix;
+ mix.col = texture(tex_col, uv);
+ mix.col.rgb = srgb_to_linear(mix.col.rgb);
+#if (TERRAIN_PBR_DETAIL >= TERRAIN_PBR_DETAIL_OCCLUSION)
+ mix.orm = texture(tex_orm, uv).xyz;
+#elif (TERRAIN_PBR_DETAIL >= TERRAIN_PBR_DETAIL_METALLIC_ROUGHNESS)
+ mix.rm = texture(tex_orm, uv).yz;
+#endif
+#if (TERRAIN_PBR_DETAIL >= TERRAIN_PBR_DETAIL_NORMAL)
+ mix.vNt = texture(tex_vNt, uv).xyz*2.0-1.0;
+#endif
+#if (TERRAIN_PBR_DETAIL >= TERRAIN_PBR_DETAIL_EMISSIVE)
+ mix.emissive = srgb_to_linear(texture(tex_emissive, uv).xyz);
+#endif
+ return mix;
+}
+
+struct TerrainTriplanar
+{
+ vec3 weight;
+ int type;
+};
+
+struct TerrainMix
+{
+ vec4 weight;
+ int type;
+};
+
+#define TerrainMixSample vec4[4]
+#define TerrainMixSample3 vec3[4]
+
+TerrainMix get_terrain_mix_weights(float alpha1, float alpha2, float alphaFinal)
+{
+ TerrainMix tm;
+ vec4 sample_x = vec4(1,0,0,0);
+ vec4 sample_y = vec4(0,1,0,0);
+ vec4 sample_z = vec4(0,0,1,0);
+ vec4 sample_w = vec4(0,0,0,1);
+
+ tm.weight = mix( mix(sample_w, sample_z, alpha2), mix(sample_y, sample_x, alpha1), alphaFinal );
+ tm.weight -= TERRAIN_RAMP_MIX_THRESHOLD;
+ ivec4 usage = max(ivec4(0), ivec4(ceil(tm.weight)));
+ // Prevent negative weights and keep weights balanced
+ tm.weight = tm.weight*vec4(usage);
+ tm.weight /= (tm.weight.x + tm.weight.y + tm.weight.z + tm.weight.w);
+
+ tm.type = (usage.x * MIX_X) |
+ (usage.y * MIX_Y) |
+ (usage.z * MIX_Z) |
+ (usage.w * MIX_W);
+ return tm;
+}
+
+TerrainTriplanar _t_triplanar()
+{
+ float sharpness = TERRAIN_TRIPLANAR_BLEND_FACTOR;
+ float threshold = TERRAIN_TRIPLANAR_MIX_THRESHOLD;
+ vec3 weight_signed = pow(abs(vary_vertex_normal), vec3(sharpness));
+ weight_signed /= (weight_signed.x + weight_signed.y + weight_signed.z);
+ weight_signed -= vec3(threshold);
+ TerrainTriplanar tw;
+ // *NOTE: Make sure the threshold doesn't affect the materials
+ tw.weight = max(vec3(0), weight_signed);
+ tw.weight /= (tw.weight.x + tw.weight.y + tw.weight.z);
+ ivec3 usage = ivec3(round(max(vec3(0), sign(weight_signed))));
+ tw.type = ((usage.x) * SAMPLE_X) |
+ ((usage.y) * SAMPLE_Y) |
+ ((usage.z) * SAMPLE_Z);
+ return tw;
+}
+
+// Assume weights add to 1
+float terrain_mix(TerrainMix tm, vec4 tms4)
+{
+ return (tm.weight.x * tms4[0]) +
+ (tm.weight.y * tms4[1]) +
+ (tm.weight.z * tms4[2]) +
+ (tm.weight.w * tms4[3]);
+}
+
+#if TERRAIN_PLANAR_TEXTURE_SAMPLE_COUNT == 3
+// Triplanar mapping
+
+// Pre-transformed texture coordinates for each axial uv slice (Packing: xy, yz, (-x)z, unused)
+#define TerrainCoord vec4[2]
+
+vec2 _t_uv(vec2 uv_unflipped, float sign_or_zero)
+{
+ // Handle case where sign is 0
+ float sign = (2.0*sign_or_zero) + 1.0;
+ sign /= abs(sign);
+ // If the vertex normal is negative, flip the texture back
+ // right-side up.
+ vec2 uv = uv_unflipped * vec2(sign, 1);
+ return uv;
+}
+
+vec3 _t_normal_post_1(vec3 vNt0, float sign_or_zero)
+{
+ // Assume normal is unpacked
+ vec3 vNt1 = vNt0;
+ // Get sign
+ float sign = sign_or_zero;
+ // Handle case where sign is 0
+ sign = (2.0*sign) + 1.0;
+ sign /= abs(sign);
+ // If the sign is negative, rotate normal by 180 degrees
+ vNt1.xy = (min(0, sign) * vNt1.xy) + (min(0, -sign) * -vNt1.xy);
+ return vNt1;
+}
+
+// Triplanar-specific normal texture fixes
+vec3 _t_normal_post_x(vec3 vNt0)
+{
+ vec3 vNt_x = _t_normal_post_1(vNt0, sign(vary_vertex_normal.x));
+ // *HACK: Transform normals according to orientation of the UVs
+ vNt_x.xy = vec2(-vNt_x.y, vNt_x.x);
+ return vNt_x;
+}
+vec3 _t_normal_post_y(vec3 vNt0)
+{
+ vec3 vNt_y = _t_normal_post_1(vNt0, sign(vary_vertex_normal.y));
+ // *HACK: Transform normals according to orientation of the UVs
+ vNt_y.xy = -vNt_y.xy;
+ return vNt_y;
+}
+vec3 _t_normal_post_z(vec3 vNt0)
+{
+ vec3 vNt_z = _t_normal_post_1(vNt0, sign(vary_vertex_normal.z));
+ return vNt_z;
+}
+
+PBRMix terrain_sample_pbr(
+ TerrainCoord terrain_coord
+ , TerrainTriplanar tw
+ , sampler2D tex_col
+#if (TERRAIN_PBR_DETAIL >= TERRAIN_PBR_DETAIL_METALLIC_ROUGHNESS)
+ , sampler2D tex_orm
+#endif
+#if (TERRAIN_PBR_DETAIL >= TERRAIN_PBR_DETAIL_NORMAL)
+ , sampler2D tex_vNt
+#endif
+#if (TERRAIN_PBR_DETAIL >= TERRAIN_PBR_DETAIL_EMISSIVE)
+ , sampler2D tex_emissive
+#endif
+ )
+{
+ PBRMix mix = init_pbr_mix();
+
+#define get_uv_x() _t_uv(terrain_coord[0].zw, sign(vary_vertex_normal.x))
+#define get_uv_y() _t_uv(terrain_coord[1].xy, sign(vary_vertex_normal.y))
+#define get_uv_z() _t_uv(terrain_coord[0].xy, sign(vary_vertex_normal.z))
+ switch (tw.type & SAMPLE_X)
+ {
+ case SAMPLE_X:
+ PBRMix mix_x = sample_pbr(
+ get_uv_x()
+ , tex_col
+#if (TERRAIN_PBR_DETAIL >= TERRAIN_PBR_DETAIL_METALLIC_ROUGHNESS)
+ , tex_orm
+#endif
+#if (TERRAIN_PBR_DETAIL >= TERRAIN_PBR_DETAIL_NORMAL)
+ , tex_vNt
+#endif
+#if (TERRAIN_PBR_DETAIL >= TERRAIN_PBR_DETAIL_EMISSIVE)
+ , tex_emissive
+#endif
+ );
+#if (TERRAIN_PBR_DETAIL >= TERRAIN_PBR_DETAIL_NORMAL)
+ // Triplanar-specific normal texture fix
+ mix_x.vNt = _t_normal_post_x(mix_x.vNt);
+#endif
+ mix = mix_pbr(mix, mix_x, tw.weight.x);
+ break;
+ default:
+ break;
+ }
+
+ switch (tw.type & SAMPLE_Y)
+ {
+ case SAMPLE_Y:
+ PBRMix mix_y = sample_pbr(
+ get_uv_y()
+ , tex_col
+#if (TERRAIN_PBR_DETAIL >= TERRAIN_PBR_DETAIL_METALLIC_ROUGHNESS)
+ , tex_orm
+#endif
+#if (TERRAIN_PBR_DETAIL >= TERRAIN_PBR_DETAIL_NORMAL)
+ , tex_vNt
+#endif
+#if (TERRAIN_PBR_DETAIL >= TERRAIN_PBR_DETAIL_EMISSIVE)
+ , tex_emissive
+#endif
+ );
+#if (TERRAIN_PBR_DETAIL >= TERRAIN_PBR_DETAIL_NORMAL)
+ // Triplanar-specific normal texture fix
+ mix_y.vNt = _t_normal_post_y(mix_y.vNt);
+#endif
+ mix = mix_pbr(mix, mix_y, tw.weight.y);
+ break;
+ default:
+ break;
+ }
+
+ switch (tw.type & SAMPLE_Z)
+ {
+ case SAMPLE_Z:
+ PBRMix mix_z = sample_pbr(
+ get_uv_z()
+ , tex_col
+#if (TERRAIN_PBR_DETAIL >= TERRAIN_PBR_DETAIL_METALLIC_ROUGHNESS)
+ , tex_orm
+#endif
+#if (TERRAIN_PBR_DETAIL >= TERRAIN_PBR_DETAIL_NORMAL)
+ , tex_vNt
+#endif
+#if (TERRAIN_PBR_DETAIL >= TERRAIN_PBR_DETAIL_EMISSIVE)
+ , tex_emissive
+#endif
+ );
+#if (TERRAIN_PBR_DETAIL >= TERRAIN_PBR_DETAIL_NORMAL)
+ // Triplanar-specific normal texture fix
+ // *NOTE: Bottom face has not been tested
+ mix_z.vNt = _t_normal_post_z(mix_z.vNt);
+#endif
+ mix = mix_pbr(mix, mix_z, tw.weight.z);
+ break;
+ default:
+ break;
+ }
+
+ return mix;
+}
+
+#elif TERRAIN_PLANAR_TEXTURE_SAMPLE_COUNT == 1
+
+#define TerrainCoord vec2
+
+#define terrain_sample_pbr sample_pbr
+
+#endif
+
+PBRMix multiply_factors_pbr(
+ PBRMix mix_in
+ , vec4 factor_col
+#if (TERRAIN_PBR_DETAIL >= TERRAIN_PBR_DETAIL_OCCLUSION)
+ , vec3 factor_orm
+#elif (TERRAIN_PBR_DETAIL >= TERRAIN_PBR_DETAIL_METALLIC_ROUGHNESS)
+ , vec2 factor_rm
+#endif
+#if (TERRAIN_PBR_DETAIL >= TERRAIN_PBR_DETAIL_EMISSIVE)
+ , vec3 factor_emissive
+#endif
+ )
+{
+ PBRMix mix = mix_in;
+ mix.col *= factor_col;
+#if (TERRAIN_PBR_DETAIL >= TERRAIN_PBR_DETAIL_OCCLUSION)
+ mix.orm *= factor_orm;
+#elif (TERRAIN_PBR_DETAIL >= TERRAIN_PBR_DETAIL_METALLIC_ROUGHNESS)
+ mix.rm *= factor_rm;
+#endif
+#if (TERRAIN_PBR_DETAIL >= TERRAIN_PBR_DETAIL_EMISSIVE)
+ mix.emissive *= factor_emissive;
+#endif
+ return mix;
+}
+
+PBRMix terrain_sample_and_multiply_pbr(
+ TerrainCoord terrain_coord
+ , sampler2D tex_col
+#if (TERRAIN_PBR_DETAIL >= TERRAIN_PBR_DETAIL_METALLIC_ROUGHNESS)
+ , sampler2D tex_orm
+#endif
+#if (TERRAIN_PBR_DETAIL >= TERRAIN_PBR_DETAIL_NORMAL)
+ , sampler2D tex_vNt
+#endif
+#if (TERRAIN_PBR_DETAIL >= TERRAIN_PBR_DETAIL_EMISSIVE)
+ , sampler2D tex_emissive
+#endif
+ , vec4 factor_col
+#if (TERRAIN_PBR_DETAIL >= TERRAIN_PBR_DETAIL_OCCLUSION)
+ , vec3 factor_orm
+#elif (TERRAIN_PBR_DETAIL >= TERRAIN_PBR_DETAIL_METALLIC_ROUGHNESS)
+ , vec2 factor_rm
+#endif
+#if (TERRAIN_PBR_DETAIL >= TERRAIN_PBR_DETAIL_EMISSIVE)
+ , vec3 factor_emissive
+#endif
+ )
+{
+ PBRMix mix = terrain_sample_pbr(
+ terrain_coord
+#if TERRAIN_PLANAR_TEXTURE_SAMPLE_COUNT == 3
+ , _t_triplanar()
+#endif
+ , tex_col
+#if (TERRAIN_PBR_DETAIL >= TERRAIN_PBR_DETAIL_METALLIC_ROUGHNESS)
+ , tex_orm
+#endif
+#if (TERRAIN_PBR_DETAIL >= TERRAIN_PBR_DETAIL_NORMAL)
+ , tex_vNt
+#endif
+#if (TERRAIN_PBR_DETAIL >= TERRAIN_PBR_DETAIL_EMISSIVE)
+ , tex_emissive
+#endif
+ );
+
+ mix = multiply_factors_pbr(mix
+ , factor_col
+#if (TERRAIN_PBR_DETAIL >= TERRAIN_PBR_DETAIL_OCCLUSION)
+ , factor_orm
+#elif (TERRAIN_PBR_DETAIL >= TERRAIN_PBR_DETAIL_METALLIC_ROUGHNESS)
+ , factor_rm
+#endif
+#if (TERRAIN_PBR_DETAIL >= TERRAIN_PBR_DETAIL_EMISSIVE)
+ , factor_emissive
+#endif
+ );
+
+ return mix;
+}
diff --git a/indra/newview/app_settings/shaders/class1/deferred/pbrterrainV.glsl b/indra/newview/app_settings/shaders/class1/deferred/pbrterrainV.glsl
new file mode 100644
index 0000000000..dbb9404219
--- /dev/null
+++ b/indra/newview/app_settings/shaders/class1/deferred/pbrterrainV.glsl
@@ -0,0 +1,93 @@
+/**
+ * @file class1\environment\pbrterrainV.glsl
+ *
+ * $LicenseInfo:firstyear=2023&license=viewerlgpl$
+ * Second Life Viewer Source Code
+ * Copyright (C) 2023, Linden Research, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation;
+ * version 2.1 of the License only.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
+ * $/LicenseInfo$
+ */
+
+uniform mat3 normal_matrix;
+uniform mat4 texture_matrix0;
+uniform mat4 modelview_projection_matrix;
+
+in vec3 position;
+in vec3 normal;
+in vec4 tangent;
+in vec4 diffuse_color;
+in vec2 texcoord1;
+
+#if TERRAIN_PLANAR_TEXTURE_SAMPLE_COUNT == 3
+out vec4[2] vary_coords;
+#endif
+out vec3 vary_vertex_normal; // Used by pbrterrainUtilF.glsl
+out vec3 vary_normal;
+out vec3 vary_tangent;
+flat out float vary_sign;
+out vec4 vary_texcoord0;
+out vec4 vary_texcoord1;
+
+// *HACK: tangent_space_transform should use texture_normal_transform, or maybe
+// we shouldn't use tangent_space_transform at all. See the call to
+// tangent_space_transform below.
+uniform vec4[2] texture_base_color_transform;
+
+vec2 texture_transform(vec2 vertex_texcoord, vec4[2] khr_gltf_transform, mat4 sl_animation_transform);
+vec3 tangent_space_transform(vec4 vertex_tangent, vec3 vertex_normal, vec4[2] khr_gltf_transform, mat4 sl_animation_transform);
+
+void main()
+{
+ //transform vertex
+ gl_Position = modelview_projection_matrix * vec4(position.xyz, 1.0);
+
+ vec3 n = normal_matrix * normal;
+ vary_vertex_normal = normal;
+ vec3 t = normal_matrix * tangent.xyz;
+
+ vary_tangent = normalize(t);
+ // *TODO: Decide if we want this. It may be better to just calculate the
+ // tangents on-the-fly in the fragment shader, due to the subtleties of the
+ // effect of triplanar mapping on UVs.
+ // *HACK: Should be using texture_normal_transform here. The KHR texture
+ // transform spec requires handling texture transforms separately for each
+ // individual texture.
+ vary_tangent = normalize(tangent_space_transform(vec4(t, tangent.w), n, texture_base_color_transform, texture_matrix0));
+ vary_sign = tangent.w;
+ vary_normal = normalize(n);
+
+ // Transform and pass tex coords
+ // *HACK: texture_base_color_transform is used for all of these here, but
+ // the KHR texture transform spec requires handling texture transforms
+ // separately for each individual texture.
+#if TERRAIN_PLANAR_TEXTURE_SAMPLE_COUNT == 3
+ // xy
+ vary_coords[0].xy = texture_transform(position.xy, texture_base_color_transform, texture_matrix0);
+ // yz
+ vary_coords[0].zw = texture_transform(position.yz, texture_base_color_transform, texture_matrix0);
+ // (-x)z
+ vary_coords[1].xy = texture_transform(position.xz * vec2(-1, 1), texture_base_color_transform, texture_matrix0);
+#elif TERRAIN_PLANAR_TEXTURE_SAMPLE_COUNT == 1
+ vary_texcoord0.xy = texture_transform(position.xy, texture_base_color_transform, texture_matrix0);
+#endif
+
+ vec4 tc = vec4(texcoord1,0,1);
+ vary_texcoord0.zw = tc.xy;
+ vary_texcoord1.xy = tc.xy-vec2(2.0, 0.0);
+ vary_texcoord1.zw = tc.xy-vec2(1.0, 0.0);
+}
diff --git a/indra/newview/app_settings/shaders/class1/deferred/terrainV.glsl b/indra/newview/app_settings/shaders/class1/deferred/terrainV.glsl
index f6d3b59e85..33a78fd26d 100644
--- a/indra/newview/app_settings/shaders/class1/deferred/terrainV.glsl
+++ b/indra/newview/app_settings/shaders/class1/deferred/terrainV.glsl
@@ -30,7 +30,6 @@ uniform mat4 modelview_projection_matrix;
in vec3 position;
in vec3 normal;
in vec4 diffuse_color;
-in vec2 texcoord0;
in vec2 texcoord1;
out vec3 pos;
@@ -41,18 +40,16 @@ 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)
+vec2 texgen_object(vec4 vpos, 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 = mat * tcoord;
- return tcoord;
+ return tcoord.xy;
}
void main()
@@ -67,7 +64,7 @@ void main()
vary_normal = normalize(normal_matrix * normal);
// Transform and pass tex coords
- 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(vec4(position, 1.0), texture_matrix0, object_plane_s, object_plane_t);
vec4 t = vec4(texcoord1,0,1);
diff --git a/indra/newview/app_settings/shaders/class1/deferred/textureUtilV.glsl b/indra/newview/app_settings/shaders/class1/deferred/textureUtilV.glsl
index 636dfed4ba..732333311c 100644
--- a/indra/newview/app_settings/shaders/class1/deferred/textureUtilV.glsl
+++ b/indra/newview/app_settings/shaders/class1/deferred/textureUtilV.glsl
@@ -65,7 +65,7 @@ vec2 texture_transform(vec2 vertex_texcoord, vec4[2] khr_gltf_transform, mat4 sl
// Apply texture animation first to avoid shearing and other artifacts
texcoord = (sl_animation_transform * vec4(texcoord, 0, 1)).xy;
// Convert to left-handed coordinate system. The offset of 1 is necessary
- // for rotations to be applied correctly.
+ // for rotation and scale to be applied correctly.
texcoord.y = 1.0 - texcoord.y;
texcoord = khr_texture_transform(texcoord, khr_gltf_transform[0].xy, khr_gltf_transform[0].z, khr_gltf_transform[1].xy);
// Convert back to right-handed coordinate system
diff --git a/indra/newview/app_settings/shaders/class1/interface/normaldebugF.glsl b/indra/newview/app_settings/shaders/class1/interface/normaldebugF.glsl
new file mode 100644
index 0000000000..388042e7e0
--- /dev/null
+++ b/indra/newview/app_settings/shaders/class1/interface/normaldebugF.glsl
@@ -0,0 +1,33 @@
+/**
+ * @file normaldebugF.glsl
+ *
+ * $LicenseInfo:firstyear=2023&license=viewerlgpl$
+ * Second Life Viewer Source Code
+ * Copyright (C) 2023, Linden Research, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation;
+ * version 2.1 of the License only.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
+ * $/LicenseInfo$
+ */
+
+out vec4 frag_color;
+
+in vec4 vertex_color;
+
+void main()
+{
+ frag_color = max(vertex_color, vec4(0));
+}
diff --git a/indra/newview/app_settings/shaders/class1/interface/normaldebugG.glsl b/indra/newview/app_settings/shaders/class1/interface/normaldebugG.glsl
new file mode 100644
index 0000000000..ea04ce1cae
--- /dev/null
+++ b/indra/newview/app_settings/shaders/class1/interface/normaldebugG.glsl
@@ -0,0 +1,76 @@
+/**
+ * @file normaldebugG.glsl
+ *
+ * $LicenseInfo:firstyear=2023&license=viewerlgpl$
+ * Second Life Viewer Source Code
+ * Copyright (C) 2023, Linden Research, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation;
+ * version 2.1 of the License only.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
+ * $/LicenseInfo$
+ */
+
+// *NOTE: Geometry shaders have a reputation for being slow. Consider using
+// compute shaders instead, which have a reputation for being fast. This
+// geometry shader in particular seems to run fine on my machine, but I won't
+// vouch for this in performance-critical areas.
+// -Cosmic,2023-09-28
+
+out vec4 vertex_color;
+
+in vec4 normal_g[];
+#if HAS_ATTRIBUTE_TANGENT == 1
+in vec4 tangent_g[];
+#endif
+
+layout(TRIANGLES) in;
+#if HAS_ATTRIBUTE_TANGENT == 1
+layout(LINE_STRIP, max_vertices = 12) out;
+#else
+layout(LINE_STRIP, max_vertices = 6) out;
+#endif
+
+void triangle_normal_debug(int i)
+{
+ // Normal
+ vec4 normal_color = vec4(1.0, 1.0, 0.0, 1.0);
+ gl_Position = gl_in[i].gl_Position;
+ vertex_color = normal_color;
+ EmitVertex();
+ gl_Position = normal_g[i];
+ vertex_color = normal_color;
+ EmitVertex();
+ EndPrimitive();
+
+#if HAS_ATTRIBUTE_TANGENT == 1
+ // Tangent
+ vec4 tangent_color = vec4(0.0, 1.0, 1.0, 1.0);
+ gl_Position = gl_in[i].gl_Position;
+ vertex_color = tangent_color;
+ EmitVertex();
+ gl_Position = tangent_g[i];
+ vertex_color = tangent_color;
+ EmitVertex();
+ EndPrimitive();
+#endif
+}
+
+void main()
+{
+ triangle_normal_debug(0);
+ triangle_normal_debug(1);
+ triangle_normal_debug(2);
+}
diff --git a/indra/newview/app_settings/shaders/class1/interface/normaldebugV.glsl b/indra/newview/app_settings/shaders/class1/interface/normaldebugV.glsl
new file mode 100644
index 0000000000..d1596b9d2a
--- /dev/null
+++ b/indra/newview/app_settings/shaders/class1/interface/normaldebugV.glsl
@@ -0,0 +1,74 @@
+/**
+ * @file normaldebugV.glsl
+ *
+ * $LicenseInfo:firstyear=2023&license=viewerlgpl$
+ * Second Life Viewer Source Code
+ * Copyright (C) 2023, Linden Research, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation;
+ * version 2.1 of the License only.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
+ * $/LicenseInfo$
+ */
+
+in vec3 position;
+in vec3 normal;
+out vec4 normal_g;
+#if HAS_ATTRIBUTE_TANGENT == 1
+in vec4 tangent;
+out vec4 tangent_g;
+#endif
+
+uniform float debug_normal_draw_length;
+
+#ifdef HAS_SKIN
+mat4 getObjectSkinnedTransform();
+#else
+uniform mat3 normal_matrix;
+#endif
+uniform mat4 projection_matrix;
+uniform mat4 modelview_matrix;
+
+// *NOTE: Should use the modelview_projection_matrix here in the non-skinned
+// case for efficiency, but opting for the simplier implementation for now as
+// this is debug code. Also, the skinned version hasn't beeen tested yet.
+// world_pos = mat * vec4(position.xyz, 1.0)
+vec4 get_screen_normal(vec3 position, vec4 world_pos, vec3 normal, mat4 mat)
+{
+ vec4 world_norm = mat * vec4((position + normal), 1.0);
+ world_norm.xyz -= world_pos.xyz;
+ world_norm.xyz = debug_normal_draw_length * normalize(world_norm.xyz);
+ world_norm.xyz += world_pos.xyz;
+ return projection_matrix * world_norm;
+}
+
+void main()
+{
+#ifdef HAS_SKIN
+ mat4 mat = getObjectSkinnedTransform();
+ mat = modelview_matrix * mat;
+#else
+#define mat modelview_matrix
+#endif
+
+ vec4 world_pos = mat * vec4(position.xyz,1.0);
+
+ gl_Position = projection_matrix * world_pos;
+ normal_g = get_screen_normal(position.xyz, world_pos, normal.xyz, mat);
+#if HAS_ATTRIBUTE_TANGENT == 1
+ tangent_g = get_screen_normal(position.xyz, world_pos, tangent.xyz, mat);
+#endif
+}
+
diff --git a/indra/newview/app_settings/shaders/class1/interface/radianceGenF.glsl b/indra/newview/app_settings/shaders/class1/interface/radianceGenF.glsl
index 9ecdf0bf77..cb6f34713c 100644
--- a/indra/newview/app_settings/shaders/class1/interface/radianceGenF.glsl
+++ b/indra/newview/app_settings/shaders/class1/interface/radianceGenF.glsl
@@ -38,6 +38,7 @@ in vec3 vary_dir;
uniform float mipLevel;
uniform int u_width;
uniform float max_probe_lod;
+uniform float probe_strength;
// =============================================================================================================
@@ -163,5 +164,6 @@ void main()
{
vec3 N = normalize(vary_dir);
frag_color = max(prefilterEnvMap(N), vec4(0));
+ frag_color.a *= probe_strength;
}
// =============================================================================================================
diff --git a/indra/newview/app_settings/shaders/class3/deferred/materialF.glsl b/indra/newview/app_settings/shaders/class3/deferred/materialF.glsl
index ec1e49eeb4..b3b1aaed56 100644
--- a/indra/newview/app_settings/shaders/class3/deferred/materialF.glsl
+++ b/indra/newview/app_settings/shaders/class3/deferred/materialF.glsl
@@ -45,6 +45,23 @@ void calcHalfVectors(vec3 lv, vec3 n, vec3 v, out vec3 h, out vec3 l, out float
vec3 srgb_to_linear(vec3 cs);
vec3 linear_to_srgb(vec3 cs);
+uniform vec4 clipPlane;
+uniform float clipSign;
+uniform float mirror_flag;
+void applyClip(vec3 pos)
+{
+ float funnyClip = 0;
+ if (mirror_flag > 0)
+ {
+ if ((dot(pos.xyz, clipPlane.xyz) + clipPlane.w) > 0.0)
+ {
+ discard;
+ }
+ }
+}
+
+in vec3 vary_position;
+
#if (DIFFUSE_ALPHA_MODE == DIFFUSE_ALPHA_MODE_BLEND)
out vec4 frag_color;
@@ -66,12 +83,12 @@ uniform vec4 morphFactor;
uniform vec3 camPosLocal;
uniform mat3 env_mat;
+uniform float is_mirror;
+
uniform vec3 sun_dir;
uniform vec3 moon_dir;
in vec2 vary_fragcoord;
-in vec3 vary_position;
-
uniform mat4 proj_mat;
uniform mat4 inv_proj;
uniform vec2 screen_res;
@@ -285,6 +302,7 @@ float getShadow(vec3 pos, vec3 norm)
void main()
{
+ applyClip(vary_position);
waterClip();
// diffcol == diffuse map combined with vertex color
@@ -407,9 +425,15 @@ void main()
#else // mode is not DIFFUSE_ALPHA_MODE_BLEND, encode to gbuffer
// deferred path // See: C++: addDeferredAttachment(), shader: softenLightF.glsl
+
+ float flag = GBUFFER_FLAG_HAS_ATMOS;
+
+ if (mirror_flag > 0)
+ flag = 1;
+
frag_data[0] = vec4(diffcol.rgb, emissive); // gbuffer is sRGB for legacy materials
frag_data[1] = vec4(spec.rgb, glossiness); // XYZ = Specular color. W = Specular exponent.
- frag_data[2] = vec4(encode_normal(norm), env, GBUFFER_FLAG_HAS_ATMOS);; // XY = Normal. Z = Env. intensity. W = 1 skip atmos (mask off fog)
+ frag_data[2] = vec4(encode_normal(norm), env, flag);; // XY = Normal. Z = Env. intensity. W = 1 skip atmos (mask off fog)
frag_data[3] = vec4(0);
#endif
}
diff --git a/indra/newview/app_settings/shaders/class3/deferred/reflectionProbeF.glsl b/indra/newview/app_settings/shaders/class3/deferred/reflectionProbeF.glsl
index 906e66ecc8..d9dc83bb10 100644
--- a/indra/newview/app_settings/shaders/class3/deferred/reflectionProbeF.glsl
+++ b/indra/newview/app_settings/shaders/class3/deferred/reflectionProbeF.glsl
@@ -31,6 +31,7 @@ float tapScreenSpaceReflection(int totalSamples, vec2 tc, vec3 viewPos, vec3 n,
uniform samplerCubeArray reflectionProbes;
uniform samplerCubeArray irradianceProbes;
+
uniform sampler2D sceneMap;
uniform int cube_snapshot;
uniform float max_probe_lod;
diff --git a/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl
index 5e8fe9301a..f1de0b88d6 100644
--- a/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl
+++ b/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl
@@ -32,6 +32,16 @@ uniform sampler2D specularRect;
uniform sampler2D normalMap;
uniform sampler2D emissiveRect; // PBR linear packed Occlusion, Roughness, Metal. See: pbropaqueF.glsl
+uniform samplerCubeArray heroProbes;
+
+#if defined(HERO_PROBES)
+layout (std140) uniform HeroProbeData
+{
+ vec4 heroPosition[1];
+ int heroProbeCount;
+};
+#endif
+
const float M_PI = 3.14159265;
#if defined(HAS_SUN_SHADOW) || defined(HAS_SSAO)
@@ -187,6 +197,13 @@ void main()
vec3 v = -normalize(pos.xyz);
color = pbrBaseLight(diffuseColor, specularColor, metallic, v, norm.xyz, perceptualRoughness, light_dir, sunlit_linear, scol, radiance, irradiance, colorEmissive, ao, additive, atten);
+
+ #ifdef HERO_PROBES
+ vec3 refnormpersp = reflect(pos.xyz, norm.xyz);
+
+ if (GET_GBUFFER_FLAG(GBUFFER_FLAG_HAS_MIRROR))
+ color = textureLod(heroProbes, vec4(env_mat * refnormpersp, 0), (1.0 - gloss) * 11).xyz * specularColor;
+ #endif
}
else if (!GET_GBUFFER_FLAG(GBUFFER_FLAG_HAS_ATMOS))
{
@@ -244,6 +261,11 @@ void main()
// add radiance map
applyGlossEnv(color, glossenv, spec, pos.xyz, norm.xyz);
+
+ #ifdef HERO_PROBES
+ color = textureLod(heroProbes, vec4(env_mat * refnormpersp, 0), (1.0 - spec.a) * 11).xyz * spec.rgb;
+ #endif
+
}
color.rgb = mix(color.rgb, baseColor.rgb, baseColor.a);
diff --git a/indra/newview/featuretable.txt b/indra/newview/featuretable.txt
index f92d9a2a0e..965391b5cf 100644
--- a/indra/newview/featuretable.txt
+++ b/indra/newview/featuretable.txt
@@ -1,4 +1,4 @@
-version 59
+version 60
// The version number above should be incremented IF AND ONLY IF some
// change has been made that is sufficiently important to justify
// resetting the graphics preferences of all users to the recommended
@@ -48,6 +48,8 @@ RenderReflectionsEnabled 1 1
RenderReflectionProbeDetail 1 2
RenderTerrainDetail 1 1
RenderTerrainLODFactor 1 2.0
+RenderTerrainPBRDetail 1 0
+RenderTerrainPBRPlanarSampleCount 1 3
RenderTreeLODFactor 1 1.0
RenderVBOEnable 1 1
RenderVBOMappingDisable 1 1
@@ -94,6 +96,8 @@ RenderReflectionsEnabled 1 1
RenderReflectionProbeDetail 1 0
RenderTerrainDetail 1 0
RenderTerrainLODFactor 1 1
+RenderTerrainPBRDetail 1 -4
+RenderTerrainPBRPlanarSampleCount 1 1
RenderTreeLODFactor 1 0
RenderVolumeLODFactor 1 1.125
RenderDeferredSSAO 1 0
@@ -123,6 +127,8 @@ RenderReflectionsEnabled 1 1
RenderReflectionProbeDetail 1 0
RenderTerrainDetail 1 1
RenderTerrainLODFactor 1 1.0
+RenderTerrainPBRDetail 1 -1
+RenderTerrainPBRPlanarSampleCount 1 1
RenderTreeLODFactor 1 0.5
RenderVolumeLODFactor 1 1.125
RenderDeferredSSAO 1 0
@@ -150,6 +156,8 @@ RenderLocalLightCount 1 512
RenderTransparentWater 1 0
RenderTerrainDetail 1 1
RenderTerrainLODFactor 1 2.0
+RenderTerrainPBRDetail 1 0
+RenderTerrainPBRPlanarSampleCount 1 1
RenderTreeLODFactor 1 0.5
RenderVolumeLODFactor 1 1.25
RenderDeferredSSAO 1 0
@@ -179,6 +187,8 @@ RenderLocalLightCount 1 1024
RenderTransparentWater 1 1
RenderTerrainDetail 1 1
RenderTerrainLODFactor 1 2.0
+RenderTerrainPBRDetail 1 0
+RenderTerrainPBRPlanarSampleCount 1 1
RenderTreeLODFactor 1 0.5
RenderVolumeLODFactor 1 1.375
RenderDeferredSSAO 1 0
@@ -208,6 +218,8 @@ RenderLocalLightCount 1 2048
RenderTransparentWater 1 1
RenderTerrainDetail 1 1
RenderTerrainLODFactor 1 2.0
+RenderTerrainPBRDetail 1 0
+RenderTerrainPBRPlanarSampleCount 1 3
RenderTreeLODFactor 1 0.5
RenderVolumeLODFactor 1 1.5
RenderDeferredSSAO 1 1
@@ -236,6 +248,8 @@ RenderMaxPartCount 1 4096
RenderLocalLightCount 1 4096
RenderTerrainDetail 1 1
RenderTerrainLODFactor 1 2.0
+RenderTerrainPBRDetail 1 0
+RenderTerrainPBRPlanarSampleCount 1 3
RenderTransparentWater 1 1
RenderTreeLODFactor 1 0.5
RenderVolumeLODFactor 1 1.75
@@ -264,6 +278,8 @@ RenderLocalLightCount 1 8192
RenderMaxPartCount 1 8192
RenderTerrainDetail 1 1
RenderTerrainLODFactor 1 2.0
+RenderTerrainPBRDetail 1 0
+RenderTerrainPBRPlanarSampleCount 1 3
RenderTransparentWater 1 1
RenderTreeLODFactor 1 1.0
RenderVolumeLODFactor 1 2.0
@@ -321,3 +337,5 @@ RenderFSAASamples 0 0
RenderReflectionsEnabled 0 0
RenderReflectionProbeDetail 0 0
+list TexUnit16orLess
+RenderTerrainPBRDetail 1 -1
diff --git a/indra/newview/featuretable_mac.txt b/indra/newview/featuretable_mac.txt
index 40aaccc8cb..61cde82512 100644
--- a/indra/newview/featuretable_mac.txt
+++ b/indra/newview/featuretable_mac.txt
@@ -1,4 +1,4 @@
-version 56
+version 57
// The version number above should be incremented IF AND ONLY IF some
// change has been made that is sufficiently important to justify
// resetting the graphics preferences of all users to the recommended
@@ -45,6 +45,8 @@ RenderObjectBump 1 1
RenderLocalLightCount 1 4096
RenderTerrainDetail 1 1
RenderTerrainLODFactor 1 2.0
+RenderTerrainPBRDetail 1 0
+RenderTerrainPBRPlanarSampleCount 1 3
RenderTransparentWater 1 1
RenderTreeLODFactor 1 1.0
RenderVBOEnable 1 1
@@ -89,6 +91,8 @@ RenderLocalLightCount 1 8
RenderMaxPartCount 1 0
RenderTerrainDetail 1 0
RenderTerrainLODFactor 1 1
+RenderTerrainPBRDetail 1 -4
+RenderTerrainPBRPlanarSampleCount 1 1
RenderTransparentWater 1 0
RenderTreeLODFactor 1 0
RenderVolumeLODFactor 1 1.125
@@ -118,6 +122,8 @@ RenderMaxPartCount 1 2048
RenderLocalLightCount 1 256
RenderTerrainDetail 1 1
RenderTerrainLODFactor 1 1.0
+RenderTerrainPBRDetail 1 -1
+RenderTerrainPBRPlanarSampleCount 1 1
RenderTransparentWater 1 1
RenderTreeLODFactor 1 0.5
RenderVolumeLODFactor 1 1.125
@@ -147,6 +153,8 @@ RenderMaxPartCount 1 4096
RenderLocalLightCount 1 512
RenderTerrainDetail 1 1
RenderTerrainLODFactor 1 2.0
+RenderTerrainPBRDetail 1 0
+RenderTerrainPBRPlanarSampleCount 1 1
RenderTransparentWater 1 1
RenderTreeLODFactor 1 0.5
RenderVolumeLODFactor 1 1.25
@@ -176,6 +184,8 @@ RenderMaxPartCount 1 4096
RenderLocalLightCount 1 1024
RenderTerrainDetail 1 1
RenderTerrainLODFactor 1 2.0
+RenderTerrainPBRDetail 1 0
+RenderTerrainPBRPlanarSampleCount 1 1
RenderTransparentWater 1 1
RenderTreeLODFactor 1 0.5
RenderVolumeLODFactor 1 1.375
@@ -205,6 +215,8 @@ RenderMaxPartCount 1 4096
RenderLocalLightCount 1 2048
RenderTerrainDetail 1 1
RenderTerrainLODFactor 1 2.0
+RenderTerrainPBRDetail 1 0
+RenderTerrainPBRPlanarSampleCount 1 3
RenderTransparentWater 1 1
RenderTreeLODFactor 1 0.5
RenderVolumeLODFactor 1 1.5
@@ -234,6 +246,8 @@ RenderMaxPartCount 1 4096
RenderLocalLightCount 1 4096
RenderTerrainDetail 1 1
RenderTerrainLODFactor 1 2.0
+RenderTerrainPBRDetail 1 0
+RenderTerrainPBRPlanarSampleCount 1 3
RenderTransparentWater 1 1
RenderTreeLODFactor 1 0.5
RenderVolumeLODFactor 1 1.75
@@ -262,6 +276,8 @@ RenderLocalLightCount 1 8192
RenderMaxPartCount 1 8192
RenderTerrainDetail 1 1
RenderTerrainLODFactor 1 2.0
+RenderTerrainPBRDetail 1 0
+RenderTerrainPBRPlanarSampleCount 1 3
RenderTransparentWater 1 1
RenderTreeLODFactor 1 1.0
RenderVolumeLODFactor 1 2.0
@@ -308,6 +324,9 @@ RenderShadowDetail 0 0
list TexUnit8orLess
RenderDeferredSSAO 0 0
+list TexUnit16orLess
+RenderTerrainPBRDetail 1 -1
+
list AMD
RenderDeferredSSAO 1 0
diff --git a/indra/newview/llappviewer.cpp b/indra/newview/llappviewer.cpp
index 4a43133ff6..038858321c 100644
--- a/indra/newview/llappviewer.cpp
+++ b/indra/newview/llappviewer.cpp
@@ -229,6 +229,7 @@
#include "pipeline.h"
#include "llgesturemgr.h"
#include "llsky.h"
+#include "llvlcomposition.h"
#include "llvlmanager.h"
#include "llviewercamera.h"
#include "lldrawpoolbump.h"
@@ -1519,6 +1520,7 @@ bool LLAppViewer::doFrame()
LL_PROFILE_ZONE_NAMED_CATEGORY_APP("df Snapshot");
pingMainloopTimeout("Main:Snapshot");
gPipeline.mReflectionMapManager.update();
+ gPipeline.mHeroProbeManager.update();
LLFloaterSnapshot::update(); // take snapshots
LLFloaterSimpleSnapshot::update();
gGLActive = FALSE;
@@ -3328,7 +3330,6 @@ LLSD LLAppViewer::getViewerInfo() const
info["NET_BANDWITH"] = gSavedSettings.getF32("ThrottleBandwidthKBPS");
info["LOD_FACTOR"] = gSavedSettings.getF32("RenderVolumeLODFactor");
info["RENDER_QUALITY"] = (F32)gSavedSettings.getU32("RenderQualityPerformance");
- info["GPU_SHADERS"] = gSavedSettings.getBOOL("RenderDeferred") ? "Enabled" : "Disabled";
info["TEXTURE_MEMORY"] = gGLManager.mVRAM;
#if LL_DARWIN
diff --git a/indra/newview/lldrawable.h b/indra/newview/lldrawable.h
index 970e8c8b2a..fc182fc2e2 100644
--- a/indra/newview/lldrawable.h
+++ b/indra/newview/lldrawable.h
@@ -286,6 +286,7 @@ public:
ANIMATED_CHILD = 0x01000000,
ACTIVE_CHILD = 0x02000000,
FOR_UNLOAD = 0x04000000, //should be unload from memory
+ MIRROR = 0x08000000, // Used as a mirror, needs a hero probe position to be calculated.
} EDrawableFlags;
public:
diff --git a/indra/newview/lldrawpool.cpp b/indra/newview/lldrawpool.cpp
index 50210b06c4..556760632a 100644
--- a/indra/newview/lldrawpool.cpp
+++ b/indra/newview/lldrawpool.cpp
@@ -567,14 +567,19 @@ void LLRenderPass::pushRiggedMaskBatches(U32 type, bool texture, bool batch_text
void LLRenderPass::applyModelMatrix(const LLDrawInfo& params)
{
- if (params.mModelMatrix != gGLLastMatrix)
+ applyModelMatrix(params.mModelMatrix);
+}
+
+void LLRenderPass::applyModelMatrix(const LLMatrix4* model_matrix)
+{
+ if (model_matrix != gGLLastMatrix)
{
- gGLLastMatrix = params.mModelMatrix;
+ gGLLastMatrix = model_matrix;
gGL.matrixMode(LLRender::MM_MODELVIEW);
gGL.loadMatrix(gGLModelView);
- if (params.mModelMatrix)
+ if (model_matrix)
{
- gGL.multMatrix((GLfloat*) params.mModelMatrix->mMatrix);
+ gGL.multMatrix((GLfloat*) model_matrix->mMatrix);
}
gPipeline.mMatrixOpCount++;
}
@@ -746,6 +751,7 @@ void LLRenderPass::pushUntexturedGLTFBatches(U32 type)
}
}
+// static
void LLRenderPass::pushGLTFBatch(LLDrawInfo& params)
{
auto& mat = params.mGLTFMaterial;
@@ -764,6 +770,7 @@ void LLRenderPass::pushGLTFBatch(LLDrawInfo& params)
teardown_texture_matrix(params);
}
+// static
void LLRenderPass::pushUntexturedGLTFBatch(LLDrawInfo& params)
{
auto& mat = params.mGLTFMaterial;
@@ -825,6 +832,7 @@ void LLRenderPass::pushUntexturedRiggedGLTFBatches(U32 type)
}
+// static
void LLRenderPass::pushRiggedGLTFBatch(LLDrawInfo& params, LLVOAvatar*& lastAvatar, U64& lastMeshId)
{
if (params.mAvatar.notNull() && (lastAvatar != params.mAvatar || lastMeshId != params.mSkinInfo->mHash))
@@ -837,6 +845,7 @@ void LLRenderPass::pushRiggedGLTFBatch(LLDrawInfo& params, LLVOAvatar*& lastAvat
pushGLTFBatch(params);
}
+// static
void LLRenderPass::pushUntexturedRiggedGLTFBatch(LLDrawInfo& params, LLVOAvatar*& lastAvatar, U64& lastMeshId)
{
if (params.mAvatar.notNull() && (lastAvatar != params.mAvatar || lastMeshId != params.mSkinInfo->mHash))
diff --git a/indra/newview/lldrawpool.h b/indra/newview/lldrawpool.h
index 0925a01439..c69f386c6d 100644
--- a/indra/newview/lldrawpool.h
+++ b/indra/newview/lldrawpool.h
@@ -58,9 +58,9 @@ public:
POOL_SIMPLE,
POOL_FULLBRIGHT,
POOL_BUMP,
- POOL_TERRAIN,
POOL_MATERIALS,
POOL_GLTF_PBR,
+ POOL_TERRAIN,
POOL_GRASS,
POOL_GLTF_PBR_ALPHA_MASK,
POOL_TREE,
@@ -349,8 +349,8 @@ public:
void resetDrawOrders() { }
static void applyModelMatrix(const LLDrawInfo& params);
- // Use before a non-GLTF batch if it is interleaved with GLTF batches that share the same shader
- static void resetGLTFTextureTransform();
+ // For rendering that doesn't use LLDrawInfo for some reason
+ static void applyModelMatrix(const LLMatrix4* model_matrix);
void pushBatches(U32 type, bool texture = true, bool batch_textures = false);
void pushUntexturedBatches(U32 type);
@@ -374,10 +374,10 @@ public:
void pushUntexturedRiggedGLTFBatches(U32 type);
// push a single GLTF draw call
- void pushGLTFBatch(LLDrawInfo& params);
- void pushRiggedGLTFBatch(LLDrawInfo& params, LLVOAvatar*& lastAvatar, U64& lastMeshId);
- void pushUntexturedGLTFBatch(LLDrawInfo& params);
- void pushUntexturedRiggedGLTFBatch(LLDrawInfo& params, LLVOAvatar*& lastAvatar, U64& lastMeshId);
+ static void pushGLTFBatch(LLDrawInfo& params);
+ static void pushRiggedGLTFBatch(LLDrawInfo& params, LLVOAvatar*& lastAvatar, U64& lastMeshId);
+ static void pushUntexturedGLTFBatch(LLDrawInfo& params);
+ static void pushUntexturedRiggedGLTFBatch(LLDrawInfo& params, LLVOAvatar*& lastAvatar, U64& lastMeshId);
void pushMaskBatches(U32 type, bool texture = true, bool batch_textures = false);
void pushRiggedMaskBatches(U32 type, bool texture = true, bool batch_textures = false);
diff --git a/indra/newview/lldrawpoolmaterials.cpp b/indra/newview/lldrawpoolmaterials.cpp
index c0e4ed38c1..ec229711ea 100644
--- a/indra/newview/lldrawpoolmaterials.cpp
+++ b/indra/newview/lldrawpoolmaterials.cpp
@@ -183,6 +183,19 @@ void LLDrawPoolMaterials::renderDeferred(S32 pass)
glUniform4fv(specular, 1, lastSpecular.mV);
}
+ if (gPipeline.mHeroProbeManager.isMirrorPass())
+ {
+ glUniform1f(LLShaderMgr::MIRROR_FLAG, 1);
+ }
+
+ LLVector4 clipPlane = LLVector4(gPipeline.mHeroProbeManager.currentMirrorClip()[0],
+ gPipeline.mHeroProbeManager.currentMirrorClip()[1],
+ gPipeline.mHeroProbeManager.currentMirrorClip()[2],
+ gPipeline.mHeroProbeManager.currentMirrorClip()[3]);
+
+ mShader->uniform4fv(LLShaderMgr::CLIP_PLANE,
+ 1, clipPlane.mV);
+
LLVOAvatar* lastAvatar = nullptr;
for (LLCullResult::drawinfo_iterator i = begin; i != end; )
diff --git a/indra/newview/lldrawpoolterrain.cpp b/indra/newview/lldrawpoolterrain.cpp
index 77189dceae..3a943f27f6 100644
--- a/indra/newview/lldrawpoolterrain.cpp
+++ b/indra/newview/lldrawpoolterrain.cpp
@@ -54,8 +54,9 @@
const F32 DETAIL_SCALE = 1.f/16.f;
int DebugDetailMap = 0;
-S32 LLDrawPoolTerrain::sDetailMode = 1;
+S32 LLDrawPoolTerrain::sPBRDetailMode = 0;
F32 LLDrawPoolTerrain::sDetailScale = DETAIL_SCALE;
+F32 LLDrawPoolTerrain::sPBRDetailScale = DETAIL_SCALE;
static LLGLSLShader* sShader = NULL;
static LLTrace::BlockTimerStatHandle FTM_SHADOW_TERRAIN("Terrain Shadow");
@@ -66,7 +67,8 @@ LLDrawPoolTerrain::LLDrawPoolTerrain(LLViewerTexture *texturep) :
{
// Hack!
sDetailScale = 1.f/gSavedSettings.getF32("RenderTerrainScale");
- sDetailMode = gSavedSettings.getS32("RenderTerrainDetail");
+ sPBRDetailScale = 1.f/gSavedSettings.getF32("RenderTerrainPBRScale");
+ sPBRDetailMode = gSavedSettings.getS32("RenderTerrainPBRDetail");
mAlphaRampImagep = LLViewerTextureManager::getFetchedTexture(IMG_ALPHA_GRAD);
//gGL.getTexUnit(0)->bind(mAlphaRampImagep.get());
@@ -105,13 +107,7 @@ U32 LLDrawPoolTerrain::getVertexDataMask()
void LLDrawPoolTerrain::prerender()
{
- sDetailMode = gSavedSettings.getS32("RenderTerrainDetail");
-}
-
-//static
-S32 LLDrawPoolTerrain::getDetailMode()
-{
- return sDetailMode;
+ sPBRDetailMode = gSavedSettings.getS32("RenderTerrainPBRDetail");
}
void LLDrawPoolTerrain::boostTerrainDetailTextures()
@@ -121,8 +117,36 @@ void LLDrawPoolTerrain::boostTerrainDetailTextures()
LLVLComposition *compp = regionp->getComposition();
for (S32 i = 0; i < 4; i++)
{
- compp->mDetailTextures[i]->setBoostLevel(LLGLTexture::BOOST_TERRAIN);
- compp->mDetailTextures[i]->addTextureStats(1024.f * 1024.f);
+ constexpr LLGLTexture::EBoostLevel level = LLGLTexture::BOOST_TERRAIN;
+ constexpr float stats = 1024.f * 1024.f;
+
+ LLPointer<LLViewerFetchedTexture>& tex = compp->mDetailTextures[i];
+ llassert(tex.notNull());
+ tex->setBoostLevel(level);
+ tex->addTextureStats(stats);
+
+ LLPointer<LLFetchedGLTFMaterial>& mat = compp->mDetailMaterials[i];
+ llassert(mat.notNull());
+ if (mat->mBaseColorTexture)
+ {
+ mat->mBaseColorTexture->setBoostLevel(level);
+ mat->mBaseColorTexture->addTextureStats(stats);
+ }
+ if (mat->mNormalTexture)
+ {
+ mat->mNormalTexture->setBoostLevel(level);
+ mat->mNormalTexture->addTextureStats(stats);
+ }
+ if (mat->mMetallicRoughnessTexture)
+ {
+ mat->mMetallicRoughnessTexture->setBoostLevel(level);
+ mat->mMetallicRoughnessTexture->addTextureStats(stats);
+ }
+ if (mat->mEmissiveTexture)
+ {
+ mat->mEmissiveTexture->setBoostLevel(level);
+ mat->mEmissiveTexture->addTextureStats(stats);
+ }
}
}
@@ -130,10 +154,6 @@ void LLDrawPoolTerrain::beginDeferredPass(S32 pass)
{
LL_PROFILE_ZONE_SCOPED_CATEGORY_DRAWPOOL; //LL_RECORD_BLOCK_TIME(FTM_RENDER_TERRAIN);
LLFacePool::beginRenderPass(pass);
-
- sShader = &gDeferredTerrainProgram;
-
- sShader->bind();
}
void LLDrawPoolTerrain::endDeferredPass(S32 pass)
@@ -204,19 +224,8 @@ void LLDrawPoolTerrain::drawLoop()
{
LLFace *facep = *iter;
- LLMatrix4* model_matrix = &(facep->getDrawable()->getRegion()->mRenderMatrix);
-
- if (model_matrix != gGLLastMatrix)
- {
- llassert(gGL.getMatrixMode() == LLRender::MM_MODELVIEW);
- gGLLastMatrix = model_matrix;
- gGL.loadMatrix(gGLModelView);
- if (model_matrix)
- {
- gGL.multMatrix((GLfloat*) model_matrix->mMatrix);
- }
- gPipeline.mMatrixOpCount++;
- }
+ llassert(gGL.getMatrixMode() == LLRender::MM_MODELVIEW);
+ LLRenderPass::applyModelMatrix(&facep->getDrawable()->getRegion()->mRenderMatrix);
facep->renderIndexed();
}
@@ -225,9 +234,34 @@ void LLDrawPoolTerrain::drawLoop()
void LLDrawPoolTerrain::renderFullShader()
{
+ const BOOL use_local_materials = gLocalTerrainMaterials.materialsReady(TRUE);
+ // 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::Type::TEXTURE);
+
+ if (use_textures)
+ {
+ // Use textures
+ sShader = &gDeferredTerrainProgram;
+ sShader->bind();
+ renderFullShaderTextures();
+ }
+ else
+ {
+ // Use materials
+ sShader = &gDeferredPBRTerrainProgram;
+ sShader->bind();
+ renderFullShaderPBR(use_local_materials);
+ }
+}
+
+void LLDrawPoolTerrain::renderFullShaderTextures()
+{
// Hack! Get the region that this draw pool is rendering from!
LLViewerRegion *regionp = mDrawFace[0]->getDrawable()->getVObj()->getRegion();
LLVLComposition *compp = regionp->getComposition();
+
LLViewerTexture *detail_texture0p = compp->mDetailTextures[0];
LLViewerTexture *detail_texture1p = compp->mDetailTextures[1];
LLViewerTexture *detail_texture2p = compp->mDetailTextures[2];
@@ -322,6 +356,218 @@ void LLDrawPoolTerrain::renderFullShader()
gGL.getTexUnit(detail0)->activate();
}
+// *TODO: Investigate use of bindFast for PBR terrain textures
+void LLDrawPoolTerrain::renderFullShaderPBR(BOOL local_materials)
+{
+ // Hack! Get the region that this draw pool is rendering from!
+ LLViewerRegion *regionp = mDrawFace[0]->getDrawable()->getVObj()->getRegion();
+ LLVLComposition *compp = regionp->getComposition();
+ LLPointer<LLFetchedGLTFMaterial> (*materials)[LLVLComposition::ASSET_COUNT] = &compp->mDetailMaterials;
+
+ if (local_materials)
+ {
+ // Override region terrain with the global local override terrain
+ materials = &gLocalTerrainMaterials.mDetailMaterials;
+ }
+
+ 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];
+ S32 detail_emissive[terrain_material_count];
+
+ for (U32 i = 0; i < terrain_material_count; ++i)
+ {
+ const LLFetchedGLTFMaterial* material = (*materials)[i].get();
+
+ LLViewerTexture *detail_basecolor_texturep = material->mBaseColorTexture;
+ LLViewerTexture *detail_normal_texturep = material->mNormalTexture;
+ LLViewerTexture *detail_metalrough_texturep = material->mMetallicRoughnessTexture;
+ LLViewerTexture *detail_emissive_texturep = material->mEmissiveTexture;
+
+ detail_basecolor[i] = sShader->enableTexture(LLViewerShaderMgr::TERRAIN_DETAIL0_BASE_COLOR + i);
+ if (detail_basecolor_texturep)
+ {
+ gGL.getTexUnit(detail_basecolor[i])->bind(detail_basecolor_texturep);
+ }
+ else
+ {
+ gGL.getTexUnit(detail_basecolor[i])->bind(LLViewerFetchedTexture::sWhiteImagep);
+ }
+ gGL.getTexUnit(detail_basecolor[i])->setTextureAddressMode(LLTexUnit::TAM_WRAP);
+ gGL.getTexUnit(detail_basecolor[i])->activate();
+
+ if (sPBRDetailMode >= TERRAIN_PBR_DETAIL_NORMAL)
+ {
+ detail_normal[i] = sShader->enableTexture(LLViewerShaderMgr::TERRAIN_DETAIL0_NORMAL + i);
+ if (detail_normal_texturep)
+ {
+ gGL.getTexUnit(detail_normal[i])->bind(detail_normal_texturep);
+ }
+ else
+ {
+ gGL.getTexUnit(detail_normal[i])->bind(LLViewerFetchedTexture::sFlatNormalImagep);
+ }
+ gGL.getTexUnit(detail_normal[i])->setTextureAddressMode(LLTexUnit::TAM_WRAP);
+ gGL.getTexUnit(detail_normal[i])->activate();
+ }
+
+ if (sPBRDetailMode >= TERRAIN_PBR_DETAIL_METALLIC_ROUGHNESS)
+ {
+ detail_metalrough[i] = sShader->enableTexture(LLViewerShaderMgr::TERRAIN_DETAIL0_METALLIC_ROUGHNESS + i);
+ if (detail_metalrough_texturep)
+ {
+ gGL.getTexUnit(detail_metalrough[i])->bind(detail_metalrough_texturep);
+ }
+ else
+ {
+ gGL.getTexUnit(detail_metalrough[i])->bind(LLViewerFetchedTexture::sWhiteImagep);
+ }
+ gGL.getTexUnit(detail_metalrough[i])->setTextureAddressMode(LLTexUnit::TAM_WRAP);
+ gGL.getTexUnit(detail_metalrough[i])->activate();
+ }
+
+ if (sPBRDetailMode >= TERRAIN_PBR_DETAIL_EMISSIVE)
+ {
+ detail_emissive[i] = sShader->enableTexture(LLViewerShaderMgr::TERRAIN_DETAIL0_EMISSIVE + i);
+ if (detail_emissive_texturep)
+ {
+ gGL.getTexUnit(detail_emissive[i])->bind(detail_emissive_texturep);
+ }
+ else
+ {
+ gGL.getTexUnit(detail_emissive[i])->bind(LLViewerFetchedTexture::sWhiteImagep);
+ }
+ gGL.getTexUnit(detail_emissive[i])->setTextureAddressMode(LLTexUnit::TAM_WRAP);
+ gGL.getTexUnit(detail_emissive[i])->activate();
+ }
+ }
+
+ LLGLSLShader* shader = LLGLSLShader::sCurBoundShaderPtr;
+ llassert(shader);
+
+
+ // *TODO: Figure out why this offset is *sometimes* producing seams at the
+ // region edge, and repeat jumps when crossing regions, when
+ // RenderTerrainPBRScale is not a factor of the region scale.
+ LLVector3d region_origin_global = gAgent.getRegion()->getOriginGlobal();
+ F32 offset_x = (F32)fmod(region_origin_global.mdV[VX], 1.0/(F64)sPBRDetailScale)*sPBRDetailScale;
+ F32 offset_y = (F32)fmod(region_origin_global.mdV[VY], 1.0/(F64)sPBRDetailScale)*sPBRDetailScale;
+
+ LLGLTFMaterial::TextureTransform base_color_transform;
+ base_color_transform.mScale = LLVector2(sPBRDetailScale, sPBRDetailScale);
+ base_color_transform.mOffset = LLVector2(offset_x, offset_y);
+ F32 base_color_packed[8];
+ base_color_transform.getPacked(base_color_packed);
+ // *HACK: Use the same texture repeats for all PBR terrain textures for now
+ // (not compliant with KHR texture transform spec)
+ shader->uniform4fv(LLShaderMgr::TEXTURE_BASE_COLOR_TRANSFORM, 2, (F32*)base_color_packed);
+
+ LLSettingsWater::ptr_t pwater = LLEnvironment::instance().getCurrentWater();
+
+ //
+ // Alpha Ramp
+ //
+ S32 alpha_ramp = sShader->enableTexture(LLViewerShaderMgr::TERRAIN_ALPHARAMP);
+ gGL.getTexUnit(alpha_ramp)->bind(m2DAlphaRampImagep);
+ gGL.getTexUnit(alpha_ramp)->setTextureAddressMode(LLTexUnit::TAM_CLAMP);
+
+ //
+ // GLTF uniforms
+ //
+
+ LLColor4 base_color_factors[terrain_material_count];
+ F32 metallic_factors[terrain_material_count];
+ F32 roughness_factors[terrain_material_count];
+ LLColor3 emissive_colors[terrain_material_count];
+ F32 minimum_alphas[terrain_material_count];
+ for (U32 i = 0; i < terrain_material_count; ++i)
+ {
+ const LLFetchedGLTFMaterial* material = (*materials)[i].get();
+
+ base_color_factors[i] = material->mBaseColor;
+ metallic_factors[i] = material->mMetallicFactor;
+ roughness_factors[i] = material->mRoughnessFactor;
+ emissive_colors[i] = material->mEmissiveColor;
+ // glTF 2.0 Specification 3.9.4. Alpha Coverage
+ // 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.0f;
+ if (material->mAlphaMode == LLGLTFMaterial::ALPHA_MODE_MASK)
+ {
+ // 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);
+ if (sPBRDetailMode >= TERRAIN_PBR_DETAIL_METALLIC_ROUGHNESS)
+ {
+ shader->uniform4f(LLShaderMgr::TERRAIN_METALLIC_FACTORS, metallic_factors[0], metallic_factors[1], metallic_factors[2], metallic_factors[3]);
+ shader->uniform4f(LLShaderMgr::TERRAIN_ROUGHNESS_FACTORS, roughness_factors[0], roughness_factors[1], roughness_factors[2], roughness_factors[3]);
+ }
+ if (sPBRDetailMode >= TERRAIN_PBR_DETAIL_EMISSIVE)
+ {
+ shader->uniform3fv(LLShaderMgr::TERRAIN_EMISSIVE_COLORS, terrain_material_count, (F32*)emissive_colors);
+ }
+ shader->uniform4f(LLShaderMgr::TERRAIN_MINIMUM_ALPHAS, minimum_alphas[0], minimum_alphas[1], minimum_alphas[2], minimum_alphas[3]);
+
+ // GL_BLEND disabled by default
+ drawLoop();
+
+ // Disable multitexture
+
+ sShader->disableTexture(LLViewerShaderMgr::TERRAIN_ALPHARAMP);
+
+ gGL.getTexUnit(alpha_ramp)->unbind(LLTexUnit::TT_TEXTURE);
+ gGL.getTexUnit(alpha_ramp)->disable();
+ gGL.getTexUnit(alpha_ramp)->activate();
+
+ for (U32 i = 0; i < terrain_material_count; ++i)
+ {
+ sShader->disableTexture(LLViewerShaderMgr::TERRAIN_DETAIL0_BASE_COLOR + i);
+ if (sPBRDetailMode >= TERRAIN_PBR_DETAIL_NORMAL)
+ {
+ sShader->disableTexture(LLViewerShaderMgr::TERRAIN_DETAIL0_NORMAL + i);
+ }
+ if (sPBRDetailMode >= TERRAIN_PBR_DETAIL_METALLIC_ROUGHNESS)
+ {
+ sShader->disableTexture(LLViewerShaderMgr::TERRAIN_DETAIL0_METALLIC_ROUGHNESS + i);
+ }
+ if (sPBRDetailMode >= TERRAIN_PBR_DETAIL_EMISSIVE)
+ {
+ sShader->disableTexture(LLViewerShaderMgr::TERRAIN_DETAIL0_EMISSIVE + i);
+ }
+
+ gGL.getTexUnit(detail_basecolor[i])->unbind(LLTexUnit::TT_TEXTURE);
+ gGL.getTexUnit(detail_basecolor[i])->disable();
+ gGL.getTexUnit(detail_basecolor[i])->activate();
+
+ if (sPBRDetailMode >= TERRAIN_PBR_DETAIL_NORMAL)
+ {
+ gGL.getTexUnit(detail_normal[i])->unbind(LLTexUnit::TT_TEXTURE);
+ gGL.getTexUnit(detail_normal[i])->disable();
+ gGL.getTexUnit(detail_normal[i])->activate();
+ }
+
+ if (sPBRDetailMode >= TERRAIN_PBR_DETAIL_METALLIC_ROUGHNESS)
+ {
+ gGL.getTexUnit(detail_metalrough[i])->unbind(LLTexUnit::TT_TEXTURE);
+ gGL.getTexUnit(detail_metalrough[i])->disable();
+ gGL.getTexUnit(detail_metalrough[i])->activate();
+ }
+
+ if (sPBRDetailMode >= TERRAIN_PBR_DETAIL_EMISSIVE)
+ {
+ gGL.getTexUnit(detail_emissive[i])->unbind(LLTexUnit::TT_TEXTURE);
+ gGL.getTexUnit(detail_emissive[i])->disable();
+ gGL.getTexUnit(detail_emissive[i])->activate();
+ }
+ }
+}
+
void LLDrawPoolTerrain::hilightParcelOwners()
{
{ //use fullbright shader for highlighting
diff --git a/indra/newview/lldrawpoolterrain.h b/indra/newview/lldrawpoolterrain.h
index 03bef31541..13f031c8e7 100644
--- a/indra/newview/lldrawpoolterrain.h
+++ b/indra/newview/lldrawpoolterrain.h
@@ -37,13 +37,12 @@ public:
{
VERTEX_DATA_MASK = LLVertexBuffer::MAP_VERTEX |
LLVertexBuffer::MAP_NORMAL |
+ LLVertexBuffer::MAP_TANGENT | // Only PBR terrain uses this currently
LLVertexBuffer::MAP_TEXCOORD0 |
LLVertexBuffer::MAP_TEXCOORD1
};
virtual U32 getVertexDataMask();
- static S32 getDetailMode();
-
LLDrawPoolTerrain(LLViewerTexture *texturep);
virtual ~LLDrawPoolTerrain();
@@ -67,8 +66,9 @@ public:
LLPointer<LLViewerTexture> m2DAlphaRampImagep;
LLPointer<LLViewerTexture> mAlphaNoiseImagep;
- static S32 sDetailMode;
- static F32 sDetailScale; // meters per texture
+ static S32 sPBRDetailMode;
+ static F32 sDetailScale; // textures per meter
+ static F32 sPBRDetailScale; // textures per meter
protected:
void boostTerrainDetailTextures();
@@ -79,6 +79,8 @@ protected:
void renderFull2TU();
void renderFull4TU();
void renderFullShader();
+ void renderFullShaderTextures();
+ void renderFullShaderPBR(BOOL local_materials = false);
void drawLoop();
private:
diff --git a/indra/newview/lldrawpooltree.cpp b/indra/newview/lldrawpooltree.cpp
index 9dcbc48697..50c4a2c1b3 100644
--- a/indra/newview/lldrawpooltree.cpp
+++ b/indra/newview/lldrawpooltree.cpp
@@ -85,17 +85,8 @@ void LLDrawPoolTree::renderDeferred(S32 pass)
{
LLMatrix4* model_matrix = &(face->getDrawable()->getRegion()->mRenderMatrix);
- if (model_matrix != gGLLastMatrix)
- {
- gGLLastMatrix = model_matrix;
- gGL.loadMatrix(gGLModelView);
- if (model_matrix)
- {
- llassert(gGL.getMatrixMode() == LLRender::MM_MODELVIEW);
- gGL.multMatrix((GLfloat*)model_matrix->mMatrix);
- }
- gPipeline.mMatrixOpCount++;
- }
+ llassert(gGL.getMatrixMode() == LLRender::MM_MODELVIEW);
+ LLRenderPass::applyModelMatrix(model_matrix);
buff->setBuffer();
buff->drawRange(LLRender::TRIANGLES, 0, buff->getNumVerts() - 1, buff->getNumIndices(), 0);
diff --git a/indra/newview/lldynamictexture.cpp b/indra/newview/lldynamictexture.cpp
index 425acd3392..a66c3876fc 100644
--- a/indra/newview/lldynamictexture.cpp
+++ b/indra/newview/lldynamictexture.cpp
@@ -181,19 +181,26 @@ void LLViewerDynamicTexture::postRender(BOOL success)
//-----------------------------------------------------------------------------
BOOL LLViewerDynamicTexture::updateAllInstances()
{
+ LL_PROFILE_ZONE_SCOPED_CATEGORY_UI;
+
sNumRenders = 0;
if (gGLManager.mIsDisabled)
{
return TRUE;
}
- bool use_fbo = gPipeline.mBake.isComplete() && !gGLManager.mIsAMD;
+ LLRenderTarget& bake_target = gPipeline.mAuxillaryRT.deferredScreen;
- if (use_fbo)
- {
- gPipeline.mBake.bindTarget();
- gPipeline.mBake.clear();
- }
+ if (!bake_target.isComplete())
+ {
+ llassert(false);
+ return FALSE;
+ }
+ llassert(bake_target.getWidth() >= LLPipeline::MAX_BAKE_WIDTH);
+ llassert(bake_target.getHeight() >= LLPipeline::MAX_BAKE_WIDTH);
+
+ bake_target.bindTarget();
+ bake_target.clear();
LLGLSLShader::unbind();
LLVertexBuffer::unbind();
@@ -208,11 +215,14 @@ BOOL LLViewerDynamicTexture::updateAllInstances()
LLViewerDynamicTexture *dynamicTexture = *iter;
if (dynamicTexture->needsRender())
{
+ llassert(dynamicTexture->getFullWidth() <= LLPipeline::MAX_BAKE_WIDTH);
+ llassert(dynamicTexture->getFullHeight() <= LLPipeline::MAX_BAKE_WIDTH);
+
glClear(GL_DEPTH_BUFFER_BIT);
gDepthDirty = TRUE;
gGL.color4f(1,1,1,1);
- dynamicTexture->setBoundTarget(use_fbo ? &gPipeline.mBake : nullptr);
+ dynamicTexture->setBoundTarget(&bake_target);
dynamicTexture->preRender(); // Must be called outside of startRender()
result = FALSE;
if (dynamicTexture->render())
@@ -229,10 +239,7 @@ BOOL LLViewerDynamicTexture::updateAllInstances()
}
}
- if (use_fbo)
- {
- gPipeline.mBake.flush();
- }
+ bake_target.flush();
gGL.flush();
diff --git a/indra/newview/llenvironment.cpp b/indra/newview/llenvironment.cpp
index edc7bdef5f..60c2682078 100644
--- a/indra/newview/llenvironment.cpp
+++ b/indra/newview/llenvironment.cpp
@@ -815,7 +815,7 @@ const F64Seconds LLEnvironment::TRANSITION_SLOW(10.0f);
const F64Seconds LLEnvironment::TRANSITION_ALTITUDE(5.0f);
const LLUUID LLEnvironment::KNOWN_SKY_SUNRISE("01e41537-ff51-2f1f-8ef7-17e4df760bfb");
-const LLUUID LLEnvironment::KNOWN_SKY_MIDDAY("651510b8-5f4d-8991-1592-e7eeab2a5a06");
+const LLUUID LLEnvironment::KNOWN_SKY_MIDDAY("c46226b4-0e43-5a56-9708-d27ca1df3292");
const LLUUID LLEnvironment::KNOWN_SKY_LEGACY_MIDDAY("cef49723-0292-af49-9b14-9598a616b8a3");
const LLUUID LLEnvironment::KNOWN_SKY_SUNSET("084e26cd-a900-28e8-08d0-64a9de5c15e2");
const LLUUID LLEnvironment::KNOWN_SKY_MIDNIGHT("8a01b97a-cb20-c1ea-ac63-f7ea84ad0090");
@@ -895,6 +895,14 @@ void LLEnvironment::initSingleton()
gGenericDispatcher.addHandler(MESSAGE_PUSHENVIRONMENT, &environment_push_dispatch_handler);
}
+ gSavedSettings.getControl("RenderSkyAutoAdjustProbeAmbiance")->getSignal()->connect(
+ [](LLControlVariable*, const LLSD& new_val, const LLSD& old_val)
+ {
+ LLSettingsSky::sAutoAdjustProbeAmbiance = new_val.asReal();
+ }
+ );
+ LLSettingsSky::sAutoAdjustProbeAmbiance = gSavedSettings.getF32("RenderSkyAutoAdjustProbeAmbiance");
+
LLEventPumps::instance().obtain(PUMP_EXPERIENCE).stopListening(LISTENER_NAME);
LLEventPumps::instance().obtain(PUMP_EXPERIENCE).listen(LISTENER_NAME, [this](LLSD message) { listenExperiencePump(message); return false; });
}
diff --git a/indra/newview/llface.cpp b/indra/newview/llface.cpp
index c1776705f9..69e43bb458 100644
--- a/indra/newview/llface.cpp
+++ b/indra/newview/llface.cpp
@@ -1889,7 +1889,7 @@ BOOL LLFace::getGeometryVolume(const LLVolume& volume,
F32* normals = (F32*) norm.get();
LLVector4a* src = vf.mNormals;
LLVector4a* end = src+num_vertices;
-
+
while (src < end)
{
LLVector4a normal;
diff --git a/indra/newview/llfeaturemanager.cpp b/indra/newview/llfeaturemanager.cpp
index f482d5a37d..9fff505c2a 100644
--- a/indra/newview/llfeaturemanager.cpp
+++ b/indra/newview/llfeaturemanager.cpp
@@ -664,6 +664,10 @@ void LLFeatureManager::applyBaseMasks()
{
maskFeatures("TexUnit8orLess");
}
+ if (gGLManager.mNumTextureImageUnits <= 16)
+ {
+ maskFeatures("TexUnit16orLess");
+ }
if (gGLManager.mVRAM > 512)
{
maskFeatures("VRAMGT512");
diff --git a/indra/newview/llfetchedgltfmaterial.cpp b/indra/newview/llfetchedgltfmaterial.cpp
index 46b9dffae9..6bd613622e 100644
--- a/indra/newview/llfetchedgltfmaterial.cpp
+++ b/indra/newview/llfetchedgltfmaterial.cpp
@@ -37,8 +37,6 @@
LLFetchedGLTFMaterial::LLFetchedGLTFMaterial()
: LLGLTFMaterial()
, mExpectedFlusTime(0.f)
- , mActive(true)
- , mFetching(false)
{
}
@@ -130,6 +128,7 @@ void LLFetchedGLTFMaterial::bind(LLViewerTexture* media_tex)
shader->uniform1f(LLShaderMgr::ROUGHNESS_FACTOR, mRoughnessFactor);
shader->uniform1f(LLShaderMgr::METALLIC_FACTOR, mMetallicFactor);
shader->uniform3fv(LLShaderMgr::EMISSIVE_COLOR, 1, mEmissiveColor.mV);
+ shader->uniform1f(LLShaderMgr::MIRROR_FLAG, 0);
F32 normal_packed[8];
mTextureTransform[GLTF_TEXTURE_INFO_NORMAL].getPacked(normal_packed);
@@ -242,10 +241,11 @@ void LLFetchedGLTFMaterial::onMaterialComplete(std::function<void()> material_co
materialCompleteCallbacks.push_back(material_complete);
}
-void LLFetchedGLTFMaterial::materialComplete()
+void LLFetchedGLTFMaterial::materialComplete(bool success)
{
llassert(mFetching);
mFetching = false;
+ mFetchSuccess = success;
for (std::function<void()> material_complete : materialCompleteCallbacks)
{
@@ -254,55 +254,3 @@ void LLFetchedGLTFMaterial::materialComplete()
materialCompleteCallbacks.clear();
materialCompleteCallbacks.shrink_to_fit();
}
-
-LLPointer<LLViewerFetchedTexture> LLFetchedGLTFMaterial::getUITexture()
-{
- if (mFetching)
- {
- return nullptr;
- }
-
- auto fetch_texture_for_ui = [](LLPointer<LLViewerFetchedTexture>& img, const LLUUID& id)
- {
- if (id.notNull())
- {
- if (LLAvatarAppearanceDefines::LLAvatarAppearanceDictionary::isBakedImageId(id))
- {
- LLViewerObject* obj = LLSelectMgr::getInstance()->getSelection()->getFirstObject();
- if (obj)
- {
- LLViewerTexture* viewerTexture = obj->getBakedTextureForMagicId(id);
- img = viewerTexture ? dynamic_cast<LLViewerFetchedTexture*>(viewerTexture) : NULL;
- }
-
- }
- else
- {
- img = LLViewerTextureManager::getFetchedTexture(id, FTT_DEFAULT, TRUE, LLGLTexture::BOOST_NONE, LLViewerTexture::LOD_TEXTURE);
- }
- }
- if (img)
- {
- img->setBoostLevel(LLGLTexture::BOOST_PREVIEW);
- img->forceToSaveRawImage(0);
- }
- };
-
- fetch_texture_for_ui(mBaseColorTexture, mTextureId[LLGLTFMaterial::GLTF_TEXTURE_INFO_BASE_COLOR]);
- fetch_texture_for_ui(mNormalTexture, mTextureId[LLGLTFMaterial::GLTF_TEXTURE_INFO_NORMAL]);
- fetch_texture_for_ui(mMetallicRoughnessTexture, mTextureId[LLGLTFMaterial::GLTF_TEXTURE_INFO_METALLIC_ROUGHNESS]);
- fetch_texture_for_ui(mEmissiveTexture, mTextureId[LLGLTFMaterial::GLTF_TEXTURE_INFO_EMISSIVE]);
-
- if ((mBaseColorTexture && (mBaseColorTexture->getRawImageLevel() != 0)) ||
- (mNormalTexture && (mNormalTexture->getRawImageLevel() != 0)) ||
- (mMetallicRoughnessTexture && (mMetallicRoughnessTexture->getRawImageLevel() != 0)) ||
- (mEmissiveTexture && (mEmissiveTexture->getRawImageLevel() != 0)))
- {
- return nullptr;
- }
-
- // *HACK: Use one of the PBR texture components as the preview texture for now
- mPreviewTexture = mBaseColorTexture;
-
- return mPreviewTexture;
-}
diff --git a/indra/newview/llfetchedgltfmaterial.h b/indra/newview/llfetchedgltfmaterial.h
index a9e539633d..42c835a416 100644
--- a/indra/newview/llfetchedgltfmaterial.h
+++ b/indra/newview/llfetchedgltfmaterial.h
@@ -40,6 +40,8 @@ public:
virtual ~LLFetchedGLTFMaterial();
LLFetchedGLTFMaterial& operator=(const LLFetchedGLTFMaterial& rhs);
+ // LLGLTFMaterial::operator== is defined, but LLFetchedGLTFMaterial::operator== is not.
+ bool operator==(const LLGLTFMaterial& rhs) const = delete;
// If this material is loaded, fire the given function
void onMaterialComplete(std::function<void()> material_complete);
@@ -49,8 +51,7 @@ public:
void bind(LLViewerTexture* media_tex = nullptr);
bool isFetching() const { return mFetching; }
-
- LLPointer<LLViewerFetchedTexture> getUITexture();
+ bool isLoaded() const { return !mFetching && mFetchSuccess; }
void addTextureEntry(LLTextureEntry* te) override;
void removeTextureEntry(LLTextureEntry* te) override;
@@ -65,18 +66,16 @@ public:
std::set<LLTextureEntry*> mTextureEntires;
- // Texture used for previewing the material in the UI
- LLPointer<LLViewerFetchedTexture> mPreviewTexture;
-
protected:
// Lifetime management
void materialBegin();
- void materialComplete();
+ void materialComplete(bool success);
F64 mExpectedFlusTime; // since epoch in seconds
- bool mActive;
- bool mFetching;
+ bool mActive = true;
+ bool mFetching = false;
+ bool mFetchSuccess = false;
std::vector<std::function<void()>> materialCompleteCallbacks;
};
diff --git a/indra/newview/llfloaterchangeitemthumbnail.cpp b/indra/newview/llfloaterchangeitemthumbnail.cpp
index 0301627c15..776f8dc785 100644
--- a/indra/newview/llfloaterchangeitemthumbnail.cpp
+++ b/indra/newview/llfloaterchangeitemthumbnail.cpp
@@ -751,7 +751,8 @@ void LLFloaterChangeItemThumbnail::showTexturePicker(const LLUUID &thumbnail_id)
PERM_NONE,
PERM_NONE,
FALSE,
- NULL);
+ NULL,
+ PICK_TEXTURE);
mPickerHandle = floaterp->getHandle();
diff --git a/indra/newview/llfloatereditextdaycycle.cpp b/indra/newview/llfloatereditextdaycycle.cpp
index bb47feaa95..4e764674e5 100644
--- a/indra/newview/llfloatereditextdaycycle.cpp
+++ b/indra/newview/llfloatereditextdaycycle.cpp
@@ -1724,7 +1724,9 @@ void LLFloaterEditExtDayCycle::showHDRNotification(const LLSettingsDay::ptr_t &p
while (iter != end)
{
LLSettingsSky::ptr_t sky = std::static_pointer_cast<LLSettingsSky>(iter->second);
- if (sky && sky->canAutoAdjust())
+ if (sky
+ && sky->canAutoAdjust()
+ && sky->getReflectionProbeAmbiance(true) != 0.f)
{
LLNotificationsUtil::add("AutoAdjustHDRSky");
return;
diff --git a/indra/newview/llfloaterenvironmentadjust.cpp b/indra/newview/llfloaterenvironmentadjust.cpp
index c64ee5a69c..c98afefa65 100644
--- a/indra/newview/llfloaterenvironmentadjust.cpp
+++ b/indra/newview/llfloaterenvironmentadjust.cpp
@@ -116,7 +116,7 @@ BOOL LLFloaterEnvironmentAdjust::postBuild()
getChild<LLTextureCtrl>(FIELD_SKY_CLOUD_MAP)->setAllowNoTexture(TRUE);
getChild<LLTextureCtrl>(FIELD_WATER_NORMAL_MAP)->setDefaultImageAssetID(LLSettingsWater::GetDefaultWaterNormalAssetId());
- getChild<LLTextureCtrl>(FIELD_WATER_NORMAL_MAP)->setBlankImageAssetID(LLUUID(gSavedSettings.getString("DefaultBlankNormalTexture")));
+ getChild<LLTextureCtrl>(FIELD_WATER_NORMAL_MAP)->setBlankImageAssetID(BLANK_OBJECT_NORMAL);
getChild<LLTextureCtrl>(FIELD_WATER_NORMAL_MAP)->setCommitCallback([this](LLUICtrl *, const LLSD &) { onWaterMapChanged(); });
getChild<LLUICtrl>(FIELD_REFLECTION_PROBE_AMBIANCE)->setCommitCallback([this](LLUICtrl*, const LLSD&) { onReflectionProbeAmbianceChanged(); });
diff --git a/indra/newview/llfloaterfixedenvironment.cpp b/indra/newview/llfloaterfixedenvironment.cpp
index 8e28fd6234..3e8bad3ef5 100644
--- a/indra/newview/llfloaterfixedenvironment.cpp
+++ b/indra/newview/llfloaterfixedenvironment.cpp
@@ -186,7 +186,8 @@ void LLFloaterFixedEnvironment::setEditSettingsAndUpdate(const LLSettingsBase::p
// teach user about HDR settings
if (mSettings
&& mSettings->getSettingsType() == "sky"
- && ((LLSettingsSky*)mSettings.get())->canAutoAdjust())
+ && ((LLSettingsSky*)mSettings.get())->canAutoAdjust()
+ && ((LLSettingsSky*)mSettings.get())->getReflectionProbeAmbiance(true) != 0.f)
{
LLNotificationsUtil::add("AutoAdjustHDRSky");
}
diff --git a/indra/newview/llfloaterregioninfo.cpp b/indra/newview/llfloaterregioninfo.cpp
index d4eb40ff92..2c743d596e 100644
--- a/indra/newview/llfloaterregioninfo.cpp
+++ b/indra/newview/llfloaterregioninfo.cpp
@@ -605,6 +605,26 @@ LLPanelRegionEnvironment* LLFloaterRegionInfo::getPanelEnvironment()
return panel;
}
+enum class TerrainMaterialType
+{
+ TEXTURE,
+ PBR_MATERIAL,
+ COUNT
+};
+
+TerrainMaterialType material_type_from_index(S32 index)
+{
+ if (index == 0)
+ {
+ return TerrainMaterialType::TEXTURE;
+ }
+ if (index == 1)
+ {
+ return TerrainMaterialType::PBR_MATERIAL;
+ }
+ return TerrainMaterialType::COUNT;
+}
+
// static
LLPanelRegionTerrainInfo* LLFloaterRegionInfo::getPanelRegionTerrain()
{
@@ -1307,6 +1327,17 @@ void LLPanelRegionDebugInfo::onClickDebugConsole(void* data)
BOOL LLPanelRegionTerrainInfo::validateTextureSizes()
{
+ // *TODO: Don't early-exit in PBR material terrain editing mode, and
+ // instead do some reasonable checks that the PBR material is compatible
+ // with the terrain rendering pipeline. Err on the side of permissive.
+ LLComboBox* material_type_ctrl = getChild<LLComboBox>("terrain_material_type");
+ if (material_type_ctrl)
+ {
+ const TerrainMaterialType material_type = material_type_from_index(material_type_ctrl->getCurrentIndex());
+ const bool is_material_selected = material_type == TerrainMaterialType::PBR_MATERIAL;
+ if (is_material_selected) { return TRUE; }
+ }
+
static const S32 MAX_TERRAIN_TEXTURE_SIZE = 1024;
for(S32 i = 0; i < TERRAIN_TEXTURE_COUNT; ++i)
{
@@ -1324,7 +1355,7 @@ BOOL LLPanelRegionTerrainInfo::validateTextureSizes()
//LL_INFOS() << "texture detail " << i << " is " << width << "x" << height << "x" << components << LL_ENDL;
- if (components != 3)
+ if (components != 3 && components != 4)
{
LLSD args;
args["TEXTURE_NUM"] = i+1;
@@ -1380,12 +1411,20 @@ BOOL LLPanelRegionTerrainInfo::postBuild()
initCtrl("terrain_raise_spin");
initCtrl("terrain_lower_spin");
+ getChild<LLUICtrl>("terrain_material_type")->setCommitCallback(boost::bind(&LLPanelRegionTerrainInfo::onSelectMaterialType, this));
+
std::string buffer;
+
for(S32 i = 0; i < TERRAIN_TEXTURE_COUNT; ++i)
{
buffer = llformat("texture_detail_%d", i);
initCtrl(buffer);
}
+ for(S32 i = 0; i < TERRAIN_TEXTURE_COUNT; ++i)
+ {
+ buffer = llformat("material_detail_%d", i);
+ initCtrl(buffer);
+ }
for(S32 i = 0; i < CORNER_COUNT; ++i)
{
@@ -1402,10 +1441,78 @@ BOOL LLPanelRegionTerrainInfo::postBuild()
mAskedTextureHeights = false;
mConfirmedTextureHeights = false;
+ refresh();
+
return LLPanelRegionInfo::postBuild();
}
// virtual
+void LLPanelRegionTerrainInfo::refresh()
+{
+ // For simplicity, require restart
+ static BOOL feature_pbr_terrain_enabled = gSavedSettings.getBOOL("RenderTerrainPBREnabled");
+
+ LLTextBox* texture_text = getChild<LLTextBox>("detail_texture_text");
+ if (texture_text) { texture_text->setVisible(!feature_pbr_terrain_enabled); }
+
+ LLComboBox* material_type_ctrl = getChild<LLComboBox>("terrain_material_type");
+ if (material_type_ctrl)
+ {
+ material_type_ctrl->setVisible(feature_pbr_terrain_enabled);
+
+ bool has_material_assets = false;
+
+ std::string buffer;
+ for(S32 i = 0; i < TERRAIN_TEXTURE_COUNT; ++i)
+ {
+ buffer = llformat("material_detail_%d", i);
+ LLTextureCtrl* material_ctrl = getChild<LLTextureCtrl>(buffer);
+ if (material_ctrl && material_ctrl->getImageAssetID().notNull())
+ {
+ has_material_assets = true;
+ break;
+ }
+ }
+
+ TerrainMaterialType material_type = material_type_from_index(material_type_ctrl->getCurrentIndex());
+
+ if (!feature_pbr_terrain_enabled) { material_type = TerrainMaterialType::TEXTURE; }
+
+ const bool is_material_selected = material_type == TerrainMaterialType::PBR_MATERIAL;
+ material_type_ctrl->setEnabled(feature_pbr_terrain_enabled && !(is_material_selected && has_material_assets));
+ }
+}
+
+void LLPanelRegionTerrainInfo::onSelectMaterialType()
+{
+ LLComboBox* material_type_ctrl = getChild<LLComboBox>("terrain_material_type");
+ if (!material_type_ctrl) { return; }
+ const TerrainMaterialType material_type = material_type_from_index(material_type_ctrl->getCurrentIndex());
+ const bool show_texture_controls = material_type == TerrainMaterialType::TEXTURE;
+ const bool show_material_controls = material_type == TerrainMaterialType::PBR_MATERIAL;
+ std::string buffer;
+ LLTextureCtrl* texture_ctrl;
+ for(S32 i = 0; i < TERRAIN_TEXTURE_COUNT; ++i)
+ {
+ buffer = llformat("texture_detail_%d", i);
+ texture_ctrl = getChild<LLTextureCtrl>(buffer);
+ if (texture_ctrl)
+ {
+ texture_ctrl->setVisible(show_texture_controls);
+ }
+ }
+ for(S32 i = 0; i < TERRAIN_TEXTURE_COUNT; ++i)
+ {
+ buffer = llformat("material_detail_%d", i);
+ texture_ctrl = getChild<LLTextureCtrl>(buffer);
+ if (texture_ctrl)
+ {
+ texture_ctrl->setVisible(show_material_controls);
+ }
+ }
+}
+
+// virtual
bool LLPanelRegionTerrainInfo::refreshFromRegion(LLViewerRegion* region)
{
BOOL owner_or_god = gAgent.isGodlike()
@@ -1421,18 +1528,30 @@ bool LLPanelRegionTerrainInfo::refreshFromRegion(LLViewerRegion* region)
getChild<LLUICtrl>("region_text")->setValue(LLSD(region->getName()));
LLVLComposition* compp = region->getComposition();
- LLTextureCtrl* texture_ctrl;
+
+ // Are these 4 texture IDs or 4 material IDs? Who knows! Let's set the IDs on both pickers for now.
+ LLTextureCtrl* asset_ctrl;
std::string buffer;
for(S32 i = 0; i < TERRAIN_TEXTURE_COUNT; ++i)
{
buffer = llformat("texture_detail_%d", i);
- texture_ctrl = getChild<LLTextureCtrl>(buffer);
- if(texture_ctrl)
+ asset_ctrl = getChild<LLTextureCtrl>(buffer);
+ if(asset_ctrl)
{
LL_DEBUGS() << "Detail Texture " << i << ": "
- << compp->getDetailTextureID(i) << LL_ENDL;
- LLUUID tmp_id(compp->getDetailTextureID(i));
- texture_ctrl->setImageAssetID(tmp_id);
+ << compp->getDetailAssetID(i) << LL_ENDL;
+ LLUUID tmp_id(compp->getDetailAssetID(i));
+ asset_ctrl->setImageAssetID(tmp_id);
+ }
+ }
+ for(S32 i = 0; i < TERRAIN_TEXTURE_COUNT; ++i)
+ {
+ buffer = llformat("material_detail_%d", i);
+ asset_ctrl = getChild<LLTextureCtrl>(buffer);
+ if(asset_ctrl)
+ {
+ LLUUID tmp_id(compp->getDetailAssetID(i));
+ asset_ctrl->setImageAssetID(tmp_id);
}
}
@@ -1499,17 +1618,45 @@ BOOL LLPanelRegionTerrainInfo::sendUpdate()
}
}
- LLTextureCtrl* texture_ctrl;
+ LLTextureCtrl* asset_ctrl;
std::string id_str;
LLMessageSystem* msg = gMessageSystem;
+ // Use material IDs instead of texture IDs if all material IDs are set, AND the mode is set to PBR materials.
+ S32 materials_used = 0;
+ LLComboBox* material_type_ctrl = getChild<LLComboBox>("terrain_material_type");
+ if (material_type_ctrl)
+ {
+ const TerrainMaterialType material_type = material_type_from_index(material_type_ctrl->getCurrentIndex());
+ const bool is_material_selected = material_type == TerrainMaterialType::PBR_MATERIAL;
+ if (is_material_selected)
+ {
+ for(S32 i = 0; i < TERRAIN_TEXTURE_COUNT; ++i)
+ {
+ buffer = llformat("material_detail_%d", i);
+ asset_ctrl = getChild<LLTextureCtrl>(buffer);
+ if(asset_ctrl && asset_ctrl->getImageAssetID().notNull())
+ {
+ ++materials_used;
+ }
+ }
+ }
+ }
for(S32 i = 0; i < TERRAIN_TEXTURE_COUNT; ++i)
{
- buffer = llformat("texture_detail_%d", i);
- texture_ctrl = getChild<LLTextureCtrl>(buffer);
- if(texture_ctrl)
+ if (materials_used == TERRAIN_TEXTURE_COUNT)
+ {
+ buffer = llformat("material_detail_%d", i);
+ asset_ctrl = getChild<LLTextureCtrl>(buffer);
+ }
+ else
+ {
+ buffer = llformat("texture_detail_%d", i);
+ asset_ctrl = getChild<LLTextureCtrl>(buffer);
+ }
+ if(asset_ctrl)
{
- LLUUID tmp_id(texture_ctrl->getImageAssetID());
+ LLUUID tmp_id(asset_ctrl->getImageAssetID());
tmp_id.toString(id_str);
buffer = llformat("%d %s", i, id_str.c_str());
strings.push_back(buffer);
diff --git a/indra/newview/llfloaterregioninfo.h b/indra/newview/llfloaterregioninfo.h
index 3eb39b250f..91fd54fcf9 100644
--- a/indra/newview/llfloaterregioninfo.h
+++ b/indra/newview/llfloaterregioninfo.h
@@ -75,9 +75,9 @@ class LLFloaterRegionInfo : public LLFloater
public:
- /*virtual*/ void onOpen(const LLSD& key);
- /*virtual*/ void onClose(bool app_quitting);
- /*virtual*/ BOOL postBuild();
+ void onOpen(const LLSD& key) override;
+ void onClose(bool app_quitting) override;
+ BOOL postBuild() override;
static void processEstateOwnerRequest(LLMessageSystem* msg, void**);
@@ -98,7 +98,7 @@ public:
static LLPanelRegionEnvironment* getPanelEnvironment();
// from LLPanel
- virtual void refresh();
+ void refresh() override;
void onRegionChanged();
void requestRegionInfo();
@@ -144,7 +144,7 @@ public:
virtual bool refreshFromRegion(LLViewerRegion* region);
virtual bool estateUpdate(LLMessageSystem* msg) { return true; }
- virtual BOOL postBuild();
+ BOOL postBuild() override;
virtual void updateChild(LLUICtrl* child_ctrl);
void enableButton(const std::string& btn_name, BOOL enable = TRUE);
@@ -184,16 +184,15 @@ public:
: LLPanelRegionInfo() {}
~LLPanelRegionGeneralInfo() {}
- virtual bool refreshFromRegion(LLViewerRegion* region);
+ bool refreshFromRegion(LLViewerRegion* region) override;
- // LLPanel
- virtual BOOL postBuild();
+ BOOL postBuild() override;
void onBtnSet();
void setObjBonusFactor(F32 object_bonus_factor) {mObjBonusFactor = object_bonus_factor;}
protected:
- virtual BOOL sendUpdate();
+ BOOL sendUpdate() override;
void onClickKick();
void onKickCommit(const uuid_vec_t& ids);
static void onClickKickAll(void* userdata);
@@ -214,13 +213,13 @@ public:
LLPanelRegionDebugInfo()
: LLPanelRegionInfo(), mTargetAvatar() {}
~LLPanelRegionDebugInfo() {}
- // LLPanel
- virtual BOOL postBuild();
+
+ BOOL postBuild() override;
- virtual bool refreshFromRegion(LLViewerRegion* region);
+ bool refreshFromRegion(LLViewerRegion* region) override;
protected:
- virtual BOOL sendUpdate();
+ BOOL sendUpdate() override;
void onClickChooseAvatar();
void callbackAvatarID(const uuid_vec_t& ids, const std::vector<LLAvatarName> names);
@@ -247,9 +246,9 @@ public:
LLPanelRegionTerrainInfo() : LLPanelRegionInfo() {}
~LLPanelRegionTerrainInfo() {}
- virtual BOOL postBuild(); // LLPanel
+ BOOL postBuild() override;
- virtual bool refreshFromRegion(LLViewerRegion* region); // refresh local settings from region update from simulator
+ bool refreshFromRegion(LLViewerRegion* region) override; // refresh local settings from region update from simulator
void setEnvControls(bool available); // Whether environment settings are available for this region
BOOL validateTextureSizes();
@@ -257,7 +256,8 @@ public:
//static void onChangeAnything(LLUICtrl* ctrl, void* userData); // callback for any change, to enable commit button
- virtual BOOL sendUpdate();
+ void refresh() override;
+ void onSelectMaterialType();
static void onClickDownloadRaw(void*);
static void onClickUploadRaw(void*);
@@ -265,6 +265,9 @@ public:
bool callbackBakeTerrain(const LLSD& notification, const LLSD& response);
bool callbackTextureHeights(const LLSD& notification, const LLSD& response);
+protected:
+ BOOL sendUpdate() override;
+
private:
bool mConfirmedTextureHeights;
bool mAskedTextureHeights;
@@ -303,13 +306,12 @@ public:
static void updateEstateName(const std::string& name);
static void updateEstateOwnerName(const std::string& name);
- virtual bool refreshFromRegion(LLViewerRegion* region);
- virtual bool estateUpdate(LLMessageSystem* msg);
+ bool refreshFromRegion(LLViewerRegion* region) override;
+ bool estateUpdate(LLMessageSystem* msg) override;
- // LLPanel
- virtual BOOL postBuild();
- virtual void updateChild(LLUICtrl* child_ctrl);
- virtual void refresh();
+ BOOL postBuild() override;
+ void updateChild(LLUICtrl* child_ctrl) override;
+ void refresh() override;
void refreshFromEstate();
@@ -319,7 +321,7 @@ public:
void setOwnerName(const std::string& name);
protected:
- virtual BOOL sendUpdate();
+ BOOL sendUpdate() override;
// confirmation dialog callback
bool callbackChangeLindenEstate(const LLSD& notification, const LLSD& response);
@@ -339,17 +341,16 @@ public:
LLPanelEstateCovenant();
~LLPanelEstateCovenant() {}
- // LLPanel
- virtual BOOL postBuild();
- virtual void updateChild(LLUICtrl* child_ctrl);
- virtual bool refreshFromRegion(LLViewerRegion* region);
- virtual bool estateUpdate(LLMessageSystem* msg);
+ BOOL postBuild() override;
+ void updateChild(LLUICtrl* child_ctrl) override;
+ bool refreshFromRegion(LLViewerRegion* region) override;
+ bool estateUpdate(LLMessageSystem* msg) override;
// LLView overrides
BOOL handleDragAndDrop(S32 x, S32 y, MASK mask,
BOOL drop, EDragAndDropType cargo_type,
void *cargo_data, EAcceptance *accept,
- std::string& tooltip_msg);
+ std::string& tooltip_msg) override;
static bool confirmChangeCovenantCallback(const LLSD& notification, const LLSD& response);
static void resetCovenantID(void* userdata);
static bool confirmResetCovenantCallback(const LLSD& notification, const LLSD& response);
@@ -382,7 +383,7 @@ public:
} EAssetStatus;
protected:
- virtual BOOL sendUpdate();
+ BOOL sendUpdate() override;
LLTextBox* mEstateNameText;
LLTextBox* mEstateOwnerText;
LLTextBox* mLastModifiedText;
@@ -401,16 +402,19 @@ class LLPanelRegionExperiences : public LLPanelRegionInfo
public:
LLPanelRegionExperiences(){}
- /*virtual*/ BOOL postBuild();
- virtual BOOL sendUpdate();
+ BOOL postBuild() override;
static bool experienceCoreConfirm(const LLSD& notification, const LLSD& response);
static void sendEstateExperienceDelta(U32 flags, const LLUUID& agent_id);
static void infoCallback(LLHandle<LLPanelRegionExperiences> handle, const LLSD& content);
- bool refreshFromRegion(LLViewerRegion* region);
+ bool refreshFromRegion(LLViewerRegion* region) override;
void sendPurchaseRequest()const;
void processResponse( const LLSD& content );
+
+protected:
+ BOOL sendUpdate() override;
+
private:
void refreshRegionExperiences();
@@ -435,8 +439,8 @@ class LLPanelEstateAccess : public LLPanelRegionInfo
public:
LLPanelEstateAccess();
- virtual BOOL postBuild();
- virtual void updateChild(LLUICtrl* child_ctrl);
+ BOOL postBuild() override;
+ void updateChild(LLUICtrl* child_ctrl) override;
void updateControls(LLViewerRegion* region);
void updateLists();
@@ -444,7 +448,7 @@ public:
void setPendingUpdate(bool pending) { mPendingUpdate = pending; }
bool getPendingUpdate() { return mPendingUpdate; }
- virtual bool refreshFromRegion(LLViewerRegion* region);
+ bool refreshFromRegion(LLViewerRegion* region) override;
private:
void onClickAddAllowedAgent();
diff --git a/indra/newview/llgltfmateriallist.cpp b/indra/newview/llgltfmateriallist.cpp
index 8919229c78..a9216ae656 100644
--- a/indra/newview/llgltfmateriallist.cpp
+++ b/indra/newview/llgltfmateriallist.cpp
@@ -139,69 +139,18 @@ static bool is_valid_update(const LLSD& data)
}
#endif
-class LLGLTFMaterialOverrideDispatchHandler : public LLDispatchHandler
+class LLGLTFMaterialOverrideDispatchHandler
{
LOG_CLASS(LLGLTFMaterialOverrideDispatchHandler);
public:
LLGLTFMaterialOverrideDispatchHandler() = default;
- ~LLGLTFMaterialOverrideDispatchHandler() override = default;
+ ~LLGLTFMaterialOverrideDispatchHandler() = default;
void addCallback(void(*callback)(const LLUUID& object_id, S32 side))
{
mSelectionCallbacks.push_back(callback);
}
- bool operator()(const LLDispatcher* dispatcher, const std::string& key, const LLUUID& invoice, const sparam_t& strings) override
- {
- LL_PROFILE_ZONE_SCOPED;
- // receive override data from simulator via LargeGenericMessage
- // message should have:
- // object_id - UUID of LLViewerObject
- // sides - array of S32 indices of texture entries
- // gltf_json - array of corresponding Strings of GLTF json for override data
-
- LLSD message;
- bool success = true;
-#if 0 //deprecated
- for(const std::string& llsdRaw : strings)
- {
- std::istringstream llsdData(llsdRaw);
- if (!LLSDSerialize::deserialize(message, llsdData, llsdRaw.length()))
- {
- LL_WARNS() << "LLGLTFMaterialOverrideDispatchHandler: Attempted to read parameter data into LLSD but failed:" << llsdRaw << LL_ENDL;
- success = false;
- continue;
- }
-
- LLGLTFOverrideCacheEntry object_override;
- if (!object_override.fromLLSD(message))
- {
- // malformed message, nothing we can do to handle it
- LL_DEBUGS("GLTF") << "Message without id:" << message << LL_ENDL;
- success = false;
- continue;
- }
-
- // Cache the data
- {
- LLViewerRegion * region = LLWorld::instance().getRegionFromHandle(object_override.mRegionHandle);
-
- if (region)
- {
- region->cacheFullUpdateGLTFOverride(object_override);
- }
- else
- {
- LL_WARNS("GLTF") << "could not access region for material overrides message cache, region_handle: " << LL_ENDL;
- }
- }
- applyData(object_override);
- }
-
-#endif
- return success;
- }
-
void doSelectionCallbacks(const LLUUID& object_id, S32 side)
{
for (auto& callback : mSelectionCallbacks)
@@ -210,112 +159,6 @@ public:
}
}
- void applyData(const LLGLTFOverrideCacheEntry &object_override)
- {
- // Parse the data
-
-#if 0 // DEPRECATED
- LL::WorkQueue::ptr_t main_queue = LL::WorkQueue::getInstance("mainloop");
- LL::WorkQueue::ptr_t general_queue = LL::WorkQueue::getInstance("General");
-
- struct ReturnData
- {
- public:
- LLGLTFMaterial mMaterial;
- S32 mSide;
- bool mSuccess;
- };
-
- if (!object_override.mSides.empty())
- {
- // fromJson() is performance heavy offload to a thread.
- main_queue->postTo(
- general_queue,
- [sides=object_override.mSides]() // Work done on general queue
- {
- std::vector<ReturnData> results;
-
- results.reserve(sides.size());
- // parse json
- std::unordered_map<S32, LLSD>::const_iterator iter = sides.begin();
- std::unordered_map<S32, LLSD>::const_iterator end = sides.end();
- while (iter != end)
- {
- ReturnData result;
-
- result.mMaterial.applyOverrideLLSD(iter->second);
-
- result.mSuccess = true;
- result.mSide = iter->first;
-
- results.push_back(result);
- iter++;
- }
- return results;
- },
- [object_id=object_override.mObjectId, this](std::vector<ReturnData> results) // Callback to main thread
- {
- LLViewerObject * obj = gObjectList.findObject(object_id);
-
- if (results.size() > 0 )
- {
- std::unordered_set<S32> side_set;
-
- for (auto const & result : results)
- {
- S32 side = result.mSide;
- if (result.mSuccess)
- {
- // copy to heap here because LLTextureEntry is going to take ownership with an LLPointer
- LLGLTFMaterial * material = new LLGLTFMaterial(result.mMaterial);
-
- // flag this side to not be nulled out later
- side_set.insert(side);
-
- if (obj)
- {
- obj->setTEGLTFMaterialOverride(side, material);
- }
- }
-
- // unblock material editor
- if (obj && obj->getTE(side) && obj->getTE(side)->isSelected())
- {
- doSelectionCallbacks(object_id, side);
- }
- }
-
- if (obj && side_set.size() != obj->getNumTEs())
- { // object exists and at least one texture entry needs to have its override data nulled out
- for (int i = 0; i < obj->getNumTEs(); ++i)
- {
- if (side_set.find(i) == side_set.end())
- {
- obj->setTEGLTFMaterialOverride(i, nullptr);
- if (obj->getTE(i) && obj->getTE(i)->isSelected())
- {
- doSelectionCallbacks(object_id, i);
- }
- }
- }
- }
- }
- else if (obj)
- { // override list was empty or an error occurred, null out all overrides for this object
- for (int i = 0; i < obj->getNumTEs(); ++i)
- {
- obj->setTEGLTFMaterialOverride(i, nullptr);
- if (obj->getTE(i) && obj->getTE(i)->isSelected())
- {
- doSelectionCallbacks(obj->getID(), i);
- }
- }
- }
- });
- }
-#endif
- }
-
private:
std::vector<void(*)(const LLUUID& object_id, S32 side)> mSelectionCallbacks;
@@ -628,7 +471,7 @@ void LLGLTFMaterialList::onAssetLoadComplete(const LLUUID& id, LLAssetType::ETyp
if (status != LL_ERR_NOERR)
{
LL_WARNS("GLTF") << "Error getting material asset data: " << LLAssetStorage::getErrorString(status) << " (" << status << ")" << LL_ENDL;
- asset_data->mMaterial->materialComplete();
+ asset_data->mMaterial->materialComplete(false);
delete asset_data;
}
else
@@ -713,7 +556,7 @@ void LLGLTFMaterialList::onAssetLoadComplete(const LLUUID& id, LLAssetType::ETyp
LL_DEBUGS("GLTF") << "Failed to get material " << id << LL_ENDL;
}
- asset_data->mMaterial->materialComplete();
+ asset_data->mMaterial->materialComplete(true);
delete asset_data;
});
@@ -822,12 +665,6 @@ void LLGLTFMaterialList::flushMaterials()
}
// static
-void LLGLTFMaterialList::registerCallbacks()
-{
- gGenericDispatcher.addHandler("GLTFMaterialOverride", &handle_gltf_override_message);
-}
-
-// static
void LLGLTFMaterialList::modifyMaterialCoro(std::string cap_url, LLSD overrides, void(*done_callback)(bool) )
{
LLCore::HttpRequest::policy_t httpPolicy(LLCore::HttpRequest::DEFAULT_POLICY_ID);
@@ -864,7 +701,3 @@ void LLGLTFMaterialList::modifyMaterialCoro(std::string cap_url, LLSD overrides,
}
}
-void LLGLTFMaterialList::loadCacheOverrides(const LLGLTFOverrideCacheEntry& override)
-{
- handle_gltf_override_message.applyData(override);
-}
diff --git a/indra/newview/llgltfmateriallist.h b/indra/newview/llgltfmateriallist.h
index 7317214019..f1c4ce20f9 100644
--- a/indra/newview/llgltfmateriallist.h
+++ b/indra/newview/llgltfmateriallist.h
@@ -52,8 +52,6 @@ public:
void flushMaterials();
- static void registerCallbacks();
-
// Queue an modification of a material that we want to send to the simulator. Call "flushUpdates" to flush pending updates.
// id - ID of object to modify
// side - TexureEntry index to modify, or -1 for all sides
@@ -99,8 +97,6 @@ public:
// any override data that arrived before the object was ready to receive it
void applyQueuedOverrides(LLViewerObject* obj);
- static void loadCacheOverrides(const LLGLTFOverrideCacheEntry& override);
-
// Apply an override update with the given data
void applyOverrideMessage(LLMessageSystem* msg, const std::string& data);
diff --git a/indra/newview/llgltfmaterialpreviewmgr.cpp b/indra/newview/llgltfmaterialpreviewmgr.cpp
new file mode 100644
index 0000000000..53d9d7d0ba
--- /dev/null
+++ b/indra/newview/llgltfmaterialpreviewmgr.cpp
@@ -0,0 +1,560 @@
+/**
+ * @file llgltfmaterialpreviewmgr.cpp
+ *
+ * $LicenseInfo:firstyear=2023&license=viewerlgpl$
+ * Second Life Viewer Source Code
+ * Copyright (C) 2023, Linden Research, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation;
+ * version 2.1 of the License only.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
+ * $/LicenseInfo$
+ */
+
+#include "llviewerprecompiledheaders.h"
+
+#include "llgltfmaterialpreviewmgr.h"
+
+#include <memory>
+#include <vector>
+
+#include "llavatarappearancedefines.h"
+#include "llenvironment.h"
+#include "llselectmgr.h"
+#include "llviewercamera.h"
+#include "llviewercontrol.h"
+#include "llviewerobject.h"
+#include "llviewershadermgr.h"
+#include "llviewertexturelist.h"
+#include "llviewerwindow.h"
+#include "llvolumemgr.h"
+#include "pipeline.h"
+
+LLGLTFMaterialPreviewMgr gGLTFMaterialPreviewMgr;
+
+namespace
+{
+ constexpr S32 FULLY_LOADED = 0;
+ constexpr S32 NOT_LOADED = 99;
+};
+
+LLGLTFPreviewTexture::MaterialLoadLevels::MaterialLoadLevels()
+{
+ for (U32 i = 0; i < LLGLTFMaterial::GLTF_TEXTURE_INFO_COUNT; ++i)
+ {
+ levels[i] = NOT_LOADED;
+ }
+}
+
+S32& LLGLTFPreviewTexture::MaterialLoadLevels::operator[](size_t i)
+{
+ llassert(i >= 0 && i < LLGLTFMaterial::GLTF_TEXTURE_INFO_COUNT);
+ return levels[i];
+}
+
+const S32& LLGLTFPreviewTexture::MaterialLoadLevels::operator[](size_t i) const
+{
+ llassert(i >= 0 && i < LLGLTFMaterial::GLTF_TEXTURE_INFO_COUNT);
+ return levels[i];
+}
+
+bool LLGLTFPreviewTexture::MaterialLoadLevels::operator<(const MaterialLoadLevels& other) const
+{
+ bool less = false;
+ for (U32 i = 0; i < LLGLTFMaterial::GLTF_TEXTURE_INFO_COUNT; ++i)
+ {
+ if (((*this)[i] > other[i])) { return false; }
+ less = less || ((*this)[i] < other[i]);
+ }
+ return less;
+}
+
+bool LLGLTFPreviewTexture::MaterialLoadLevels::operator>(const MaterialLoadLevels& other) const
+{
+ bool great = false;
+ for (U32 i = 0; i < LLGLTFMaterial::GLTF_TEXTURE_INFO_COUNT; ++i)
+ {
+ if (((*this)[i] < other[i])) { return false; }
+ great = great || ((*this)[i] > other[i]);
+ }
+ return great;
+}
+
+namespace
+{
+ void fetch_texture_for_ui(LLPointer<LLViewerFetchedTexture>& img, const LLUUID& id)
+ {
+ if (!img && id.notNull())
+ {
+ if (LLAvatarAppearanceDefines::LLAvatarAppearanceDictionary::isBakedImageId(id))
+ {
+ LLViewerObject* obj = LLSelectMgr::getInstance()->getSelection()->getFirstObject();
+ if (obj)
+ {
+ LLViewerTexture* viewerTexture = obj->getBakedTextureForMagicId(id);
+ img = viewerTexture ? dynamic_cast<LLViewerFetchedTexture*>(viewerTexture) : NULL;
+ }
+ }
+ else
+ {
+ img = LLViewerTextureManager::getFetchedTexture(id, FTT_DEFAULT, TRUE, LLGLTexture::BOOST_NONE, LLViewerTexture::LOD_TEXTURE);
+ }
+ }
+ if (img)
+ {
+ img->setBoostLevel(LLGLTexture::BOOST_PREVIEW);
+ img->forceToSaveRawImage(0);
+ }
+ };
+
+ // *NOTE: Does not use the same conventions as texture discard level. Lower is better.
+ S32 get_texture_load_level(const LLPointer<LLViewerFetchedTexture>& texture)
+ {
+ if (!texture) { return FULLY_LOADED; }
+ const S32 raw_level = texture->getDiscardLevel();
+ if (raw_level < 0) { return NOT_LOADED; }
+ return raw_level;
+ }
+
+ LLGLTFPreviewTexture::MaterialLoadLevels get_material_load_levels(LLFetchedGLTFMaterial& material)
+ {
+ llassert(!material.isFetching());
+
+ using MaterialTextures = LLPointer<LLViewerFetchedTexture>*[LLGLTFMaterial::GLTF_TEXTURE_INFO_COUNT];
+
+ MaterialTextures textures;
+
+ textures[LLGLTFMaterial::GLTF_TEXTURE_INFO_BASE_COLOR] = &material.mBaseColorTexture;
+ textures[LLGLTFMaterial::GLTF_TEXTURE_INFO_NORMAL] = &material.mNormalTexture;
+ textures[LLGLTFMaterial::GLTF_TEXTURE_INFO_METALLIC_ROUGHNESS] = &material.mMetallicRoughnessTexture;
+ textures[LLGLTFMaterial::GLTF_TEXTURE_INFO_EMISSIVE] = &material.mEmissiveTexture;
+
+ LLGLTFPreviewTexture::MaterialLoadLevels levels;
+
+ for (U32 i = 0; i < LLGLTFMaterial::GLTF_TEXTURE_INFO_COUNT; ++i)
+ {
+ fetch_texture_for_ui(*textures[i], material.mTextureId[i]);
+ levels[i] = get_texture_load_level(*textures[i]);
+ }
+
+ return levels;
+ }
+
+ // Is the material loaded enough to start rendering a preview?
+ bool is_material_loaded_enough_for_ui(LLFetchedGLTFMaterial& material)
+ {
+ if (material.isFetching())
+ {
+ return false;
+ }
+
+ LLGLTFPreviewTexture::MaterialLoadLevels levels = get_material_load_levels(material);
+
+ for (U32 i = 0; i < LLGLTFMaterial::GLTF_TEXTURE_INFO_COUNT; ++i)
+ {
+ if (levels[i] == NOT_LOADED)
+ {
+ return false;
+ }
+ }
+
+ return true;
+ }
+
+}; // namespace
+
+LLGLTFPreviewTexture::LLGLTFPreviewTexture(LLPointer<LLFetchedGLTFMaterial> material, S32 width)
+ : LLViewerDynamicTexture(width, width, 4, EOrder::ORDER_MIDDLE, FALSE)
+ , mGLTFMaterial(material)
+{
+}
+
+// static
+LLPointer<LLGLTFPreviewTexture> LLGLTFPreviewTexture::create(LLPointer<LLFetchedGLTFMaterial> material)
+{
+ return new LLGLTFPreviewTexture(material, LLPipeline::MAX_BAKE_WIDTH);
+}
+
+void LLGLTFPreviewTexture::preRender(BOOL clear_depth)
+{
+ LL_PROFILE_ZONE_SCOPED_CATEGORY_UI;
+
+ MaterialLoadLevels current_load = get_material_load_levels(*mGLTFMaterial.get());
+ if (current_load < mBestLoad)
+ {
+ mShouldRender = true;
+ mBestLoad = current_load;
+ }
+
+ if (!mShouldRender) { return; }
+
+ LLViewerDynamicTexture::preRender(clear_depth);
+}
+
+
+namespace {
+
+struct GLTFPreviewModel
+{
+ GLTFPreviewModel(LLPointer<LLDrawInfo>& info, const LLMatrix4& mat)
+ : mDrawInfo(info)
+ , mModelMatrix(mat)
+ {
+ mDrawInfo->mModelMatrix = &mModelMatrix;
+ }
+ GLTFPreviewModel(GLTFPreviewModel&) = delete;
+ ~GLTFPreviewModel()
+ {
+ // No model matrix necromancy
+ llassert(gGLLastMatrix != &mModelMatrix);
+ gGLLastMatrix = nullptr;
+ }
+ LLPointer<LLDrawInfo> mDrawInfo;
+ LLMatrix4 mModelMatrix; // Referenced by mDrawInfo
+};
+
+using PreviewSpherePart = std::unique_ptr<GLTFPreviewModel>;
+using PreviewSphere = std::vector<PreviewSpherePart>;
+
+// Like LLVolumeGeometryManager::registerFace but without batching or too-many-indices/vertices checking.
+PreviewSphere create_preview_sphere(LLPointer<LLFetchedGLTFMaterial>& material, const LLMatrix4& model_matrix)
+{
+ LL_PROFILE_ZONE_SCOPED_CATEGORY_UI;
+
+ const LLColor4U vertex_color(material->mBaseColor);
+
+ LLPrimitive prim;
+ prim.init_primitive(LL_PCODE_VOLUME);
+ LLVolumeParams params;
+ params.setType(LL_PCODE_PROFILE_CIRCLE_HALF, LL_PCODE_PATH_CIRCLE);
+ params.setBeginAndEndS(0.f, 1.f);
+ params.setBeginAndEndT(0.f, 1.f);
+ params.setRatio(1, 1);
+ params.setShear(0, 0);
+ constexpr auto MAX_LOD = LLVolumeLODGroup::NUM_LODS - 1;
+ prim.setVolume(params, MAX_LOD);
+
+ LLVolume* volume = prim.getVolume();
+ llassert(volume);
+ for (LLVolumeFace& face : volume->getVolumeFaces())
+ {
+ face.createTangents();
+ }
+
+ PreviewSphere preview_sphere;
+ preview_sphere.reserve(volume->getNumFaces());
+
+ LLPointer<LLVertexBuffer> buf = new LLVertexBuffer(
+ LLVertexBuffer::MAP_VERTEX |
+ LLVertexBuffer::MAP_NORMAL |
+ LLVertexBuffer::MAP_TEXCOORD0 |
+ LLVertexBuffer::MAP_COLOR |
+ LLVertexBuffer::MAP_TANGENT
+ );
+ U32 nv = 0;
+ U32 ni = 0;
+ for (LLVolumeFace& face : volume->getVolumeFaces())
+ {
+ nv += face.mNumVertices;
+ ni += face.mNumIndices;
+ }
+ buf->allocateBuffer(nv, ni);
+
+ // UV hacks
+ // Higher factor helps to see more details on the preview sphere
+ const LLVector2 uv_factor(2.0f, 2.0f);
+ // Offset places center of material in center of view
+ const LLVector2 uv_offset(-0.5f, -0.5f);
+
+ LLStrider<U16> indices;
+ LLStrider<LLVector4a> positions;
+ LLStrider<LLVector4a> normals;
+ LLStrider<LLVector2> texcoords;
+ LLStrider<LLColor4U> colors;
+ LLStrider<LLVector4a> tangents;
+ buf->getIndexStrider(indices);
+ buf->getVertexStrider(positions);
+ buf->getNormalStrider(normals);
+ buf->getTexCoord0Strider(texcoords);
+ buf->getColorStrider(colors);
+ buf->getTangentStrider(tangents);
+ U32 index_offset = 0;
+ U32 vertex_offset = 0;
+ for (const LLVolumeFace& face : volume->getVolumeFaces())
+ {
+ for (S32 i = 0; i < face.mNumIndices; ++i)
+ {
+ *indices++ = face.mIndices[i] + vertex_offset;
+ }
+ for (S32 v = 0; v < face.mNumVertices; ++v)
+ {
+ *positions++ = face.mPositions[v];
+ *normals++ = face.mNormals[v];
+ LLVector2 uv(face.mTexCoords[v]);
+ uv.scaleVec(uv_factor);
+ uv += uv_offset;
+ *texcoords++ = uv;
+ *colors++ = vertex_color;
+ *tangents++ = face.mTangents[v];
+ }
+
+ constexpr LLViewerTexture* no_media = nullptr;
+ LLPointer<LLDrawInfo> info = new LLDrawInfo(U16(vertex_offset), U16(vertex_offset + face.mNumVertices - 1), face.mNumIndices, index_offset, no_media, buf.get());
+ info->mGLTFMaterial = material;
+ preview_sphere.emplace_back(std::make_unique<GLTFPreviewModel>(info, model_matrix));
+ index_offset += face.mNumIndices;
+ vertex_offset += face.mNumVertices;
+ }
+
+ buf->unmapBuffer();
+
+ return preview_sphere;
+}
+
+void set_preview_sphere_material(PreviewSphere& preview_sphere, LLPointer<LLFetchedGLTFMaterial>& material)
+{
+ llassert(!preview_sphere.empty());
+ if (preview_sphere.empty()) { return; }
+
+ const LLColor4U vertex_color(material->mBaseColor);
+
+ // See comments about unmapBuffer in llvertexbuffer.h
+ for (PreviewSpherePart& part : preview_sphere)
+ {
+ LLDrawInfo* info = part->mDrawInfo.get();
+ info->mGLTFMaterial = material;
+ LLVertexBuffer* buf = info->mVertexBuffer.get();
+ LLStrider<LLColor4U> colors;
+ const S32 count = info->mEnd - info->mStart + 1;
+ buf->getColorStrider(colors, info->mStart, count);
+ for (S32 i = 0; i < count; ++i)
+ {
+ *colors++ = vertex_color;
+ }
+ buf->unmapBuffer();
+ }
+}
+
+PreviewSphere& get_preview_sphere(LLPointer<LLFetchedGLTFMaterial>& material, const LLMatrix4& model_matrix)
+{
+ static PreviewSphere preview_sphere;
+ if (preview_sphere.empty())
+ {
+ preview_sphere = create_preview_sphere(material, model_matrix);
+ }
+ else
+ {
+ set_preview_sphere_material(preview_sphere, material);
+ }
+ return preview_sphere;
+}
+
+// Final, direct modifications to shader constants, just before render
+void fixup_shader_constants(LLGLSLShader& shader)
+{
+ // Sunlight intensity of 0 no matter what
+ shader.uniform1i(LLShaderMgr::SUN_UP_FACTOR, 1);
+ shader.uniform3fv(LLShaderMgr::SUNLIGHT_COLOR, 1, LLColor3::white.mV);
+ shader.uniform1f(LLShaderMgr::DENSITY_MULTIPLIER, 0.0f);
+
+ // Ignore sun shadow (if enabled)
+ for (U32 i = 0; i < 6; i++)
+ {
+ const S32 channel = shader.getTextureChannel(LLShaderMgr::DEFERRED_SHADOW0+i);
+ if (channel != -1)
+ {
+ gGL.getTexUnit(channel)->bind(LLViewerFetchedTexture::sWhiteImagep, TRUE);
+ }
+ }
+}
+
+// Set a variable to a value temporarily, and restor the variable's old value
+// when this object leaves scope.
+template<typename T>
+struct SetTemporarily
+{
+ T* mRef;
+ T mOldVal;
+ SetTemporarily(T* var, T temp_val)
+ {
+ mRef = var;
+ mOldVal = *mRef;
+ *mRef = temp_val;
+ }
+ ~SetTemporarily()
+ {
+ *mRef = mOldVal;
+ }
+};
+
+}; // namespace
+
+BOOL LLGLTFPreviewTexture::render()
+{
+ LL_PROFILE_ZONE_SCOPED_CATEGORY_UI;
+
+ if (!mShouldRender) { return FALSE; }
+
+ glClearColor(0, 0, 0, 0);
+ glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
+
+ LLGLDepthTest(GL_FALSE);
+ LLGLDisable stencil(GL_STENCIL_TEST);
+ LLGLDisable scissor(GL_SCISSOR_TEST);
+ SetTemporarily<bool> no_dof(&LLPipeline::RenderDepthOfField, false);
+ SetTemporarily<bool> no_glow(&LLPipeline::sRenderGlow, false);
+ SetTemporarily<bool> no_ssr(&LLPipeline::RenderScreenSpaceReflections, false);
+ SetTemporarily<U32> no_fxaa(&LLPipeline::RenderFSAASamples, U32(0));
+ SetTemporarily<LLPipeline::RenderTargetPack*> use_auxiliary_render_target(&gPipeline.mRT, &gPipeline.mAuxillaryRT);
+
+ LLVector3 light_dir3(1.0f, 1.0f, 1.0f);
+ light_dir3.normalize();
+ const LLVector4 light_dir = LLVector4(light_dir3, 0);
+ const S32 old_local_light_count = gSavedSettings.get<S32>("RenderLocalLightCount");
+ gSavedSettings.set<S32>("RenderLocalLightCount", 0);
+
+ gPipeline.mReflectionMapManager.forceDefaultProbeAndUpdateUniforms();
+
+ LLViewerCamera camera;
+
+ // Calculate the object distance at which the object of a given radius will
+ // span the partial width of the screen given by fill_ratio.
+ // Assume the primitive has a scale of 1 (this is the default).
+ constexpr F32 fill_ratio = 0.8f;
+ constexpr F32 object_radius = 0.5f;
+ const F32 object_distance = (object_radius / fill_ratio) * tan(camera.getDefaultFOV());
+ // Negative coordinate shows the textures on the sphere right-side up, when
+ // combined with the UV hacks in create_preview_sphere
+ const LLVector3 object_position(0.0, -object_distance, 0.0);
+ LLMatrix4 object_transform;
+ object_transform.translate(object_position);
+
+ // Set up camera and viewport
+ const LLVector3 origin(0.0, 0.0, 0.0);
+ camera.lookAt(origin, object_position);
+ camera.setAspect(mFullHeight / mFullWidth);
+ const LLRect texture_rect(0, mFullHeight, mFullWidth, 0);
+ camera.setPerspective(NOT_FOR_SELECTION, texture_rect.mLeft, texture_rect.mBottom, texture_rect.getWidth(), texture_rect.getHeight(), FALSE, camera.getNear(), MAX_FAR_CLIP*2.f);
+
+ // Generate sphere object on-the-fly. Discard afterwards. (Vertex buffer is
+ // discarded, but the sphere should be cached in LLVolumeMgr.)
+ PreviewSphere& preview_sphere = get_preview_sphere(mGLTFMaterial, object_transform);
+
+ gPipeline.setupHWLights();
+ glh::matrix4f mat = copy_matrix(gGLModelView);
+ glh::vec4f transformed_light_dir(light_dir.mV);
+ mat.mult_matrix_vec(transformed_light_dir);
+ SetTemporarily<LLVector4> force_sun_direction_high_graphics(&gPipeline.mTransformedSunDir, LLVector4(transformed_light_dir.v));
+ // Override lights to ensure the sun is always shining from a certain direction (low graphics)
+ // See also force_sun_direction_high_graphics and fixup_shader_constants
+ {
+ LLLightState* light = gGL.getLight(0);
+ light->setPosition(light_dir);
+ constexpr bool sun_up = true;
+ light->setSunPrimary(sun_up);
+ }
+
+ LLRenderTarget& screen = gPipeline.mAuxillaryRT.screen;
+
+ // *HACK: Force reset of the model matrix
+ gGLLastMatrix = nullptr;
+
+#if 0
+ if (mGLTFMaterial->mAlphaMode == LLGLTFMaterial::ALPHA_MODE_OPAQUE || mGLTFMaterial->mAlphaMode == LLGLTFMaterial::ALPHA_MODE_MASK)
+ {
+ // *TODO: Opaque/alpha mask rendering
+ }
+ else
+#endif
+ {
+ // Alpha blend rendering
+
+ screen.bindTarget();
+ glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
+
+ LLGLSLShader& shader = gDeferredPBRAlphaProgram;
+
+ gPipeline.bindDeferredShader(shader);
+ fixup_shader_constants(shader);
+
+ for (PreviewSpherePart& part : preview_sphere)
+ {
+ LLRenderPass::pushGLTFBatch(*part->mDrawInfo);
+ }
+
+ gPipeline.unbindDeferredShader(shader);
+
+ screen.flush();
+ }
+
+ gPipeline.copyScreenSpaceReflections(&screen, &gPipeline.mSceneMap);
+ gPipeline.generateLuminance(&screen, &gPipeline.mLuminanceMap);
+ gPipeline.generateExposure(&gPipeline.mLuminanceMap, &gPipeline.mExposureMap);
+ gPipeline.gammaCorrect(&screen, &gPipeline.mPostMap);
+ LLVertexBuffer::unbind();
+ gPipeline.generateGlow(&gPipeline.mPostMap);
+ gPipeline.combineGlow(&gPipeline.mPostMap, &screen);
+ gPipeline.renderDoF(&screen, &gPipeline.mPostMap);
+ gPipeline.applyFXAA(&gPipeline.mPostMap, &screen);
+
+ // Final render
+
+ gDeferredPostNoDoFProgram.bind();
+
+ // From LLPipeline::renderFinalize: "Whatever is last in the above post processing chain should _always_ be rendered directly here. If not, expect problems."
+ gDeferredPostNoDoFProgram.bindTexture(LLShaderMgr::DEFERRED_DIFFUSE, &screen);
+ gDeferredPostNoDoFProgram.bindTexture(LLShaderMgr::DEFERRED_DEPTH, mBoundTarget, true);
+
+ {
+ LLGLDepthTest depth_test(GL_TRUE, GL_TRUE, GL_ALWAYS);
+ gPipeline.mScreenTriangleVB->setBuffer();
+ gPipeline.mScreenTriangleVB->drawArrays(LLRender::TRIANGLES, 0, 3);
+ }
+
+ gDeferredPostNoDoFProgram.unbind();
+
+ // Clean up
+ gPipeline.setupHWLights();
+ gPipeline.mReflectionMapManager.forceDefaultProbeAndUpdateUniforms(false);
+ gSavedSettings.set<S32>("RenderLocalLightCount", old_local_light_count);
+
+ return TRUE;
+}
+
+void LLGLTFPreviewTexture::postRender(BOOL success)
+{
+ LL_PROFILE_ZONE_SCOPED_CATEGORY_UI;
+
+ if (!mShouldRender) { return; }
+ mShouldRender = false;
+
+ LLViewerDynamicTexture::postRender(success);
+}
+
+// static
+LLPointer<LLViewerTexture> LLGLTFMaterialPreviewMgr::getPreview(LLPointer<LLFetchedGLTFMaterial> &material)
+{
+ if (!material)
+ {
+ return nullptr;
+ }
+
+ if (!is_material_loaded_enough_for_ui(*material))
+ {
+ return nullptr;
+ }
+
+ return LLGLTFPreviewTexture::create(material);
+}
diff --git a/indra/newview/llgltfmaterialpreviewmgr.h b/indra/newview/llgltfmaterialpreviewmgr.h
new file mode 100644
index 0000000000..cc40a6f2e2
--- /dev/null
+++ b/indra/newview/llgltfmaterialpreviewmgr.h
@@ -0,0 +1,82 @@
+/**
+ * @file llgltfmaterialpreviewmgr.h
+ *
+ * $LicenseInfo:firstyear=2023&license=viewerlgpl$
+ * Second Life Viewer Source Code
+ * Copyright (C) 2023, Linden Research, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation;
+ * version 2.1 of the License only.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
+ * $/LicenseInfo$
+ */
+
+#pragma once
+
+#include "lldrawpool.h"
+#include "lldynamictexture.h"
+#include "llfetchedgltfmaterial.h"
+#include "llsingleton.h"
+#include "lltexture.h"
+
+class LLGLTFPreviewTexture : public LLViewerDynamicTexture
+{
+protected:
+ LLGLTFPreviewTexture(LLPointer<LLFetchedGLTFMaterial> material, S32 width);
+
+public:
+ // Width scales with size of material's textures
+ static LLPointer<LLGLTFPreviewTexture> create(LLPointer<LLFetchedGLTFMaterial> material);
+
+ BOOL needsRender() override { return mNeedsRender; }
+ void preRender(BOOL clear_depth = TRUE) override;
+ BOOL render() override;
+ void postRender(BOOL success) override;
+
+ struct MaterialLoadLevels
+ {
+ S32 levels[LLGLTFMaterial::GLTF_TEXTURE_INFO_COUNT];
+
+ MaterialLoadLevels();
+
+ S32& operator[](size_t i);
+
+ const S32& operator[](size_t i) const;
+
+ // Less is better
+ // Returns false if lhs is not strictly less or equal for all levels
+ bool operator<(const MaterialLoadLevels& other) const;
+
+ // Less is better
+ // Returns false if lhs is not strictly greater or equal for all levels
+ bool operator>(const MaterialLoadLevels& other) const;
+ };
+
+private:
+ LLPointer<LLFetchedGLTFMaterial> mGLTFMaterial;
+ bool mNeedsRender = true;
+ bool mShouldRender = true;
+ MaterialLoadLevels mBestLoad;
+};
+
+class LLGLTFMaterialPreviewMgr
+{
+ public:
+ // Returns null if the material is not loaded yet.
+ // *NOTE: User should cache the texture if the same material is being previewed
+ LLPointer<LLViewerTexture> getPreview(LLPointer<LLFetchedGLTFMaterial> &material);
+};
+
+extern LLGLTFMaterialPreviewMgr gGLTFMaterialPreviewMgr;
diff --git a/indra/newview/llheroprobemanager.cpp b/indra/newview/llheroprobemanager.cpp
new file mode 100644
index 0000000000..1ecafd4f54
--- /dev/null
+++ b/indra/newview/llheroprobemanager.cpp
@@ -0,0 +1,584 @@
+/**
+ * @file LLHeroProbeManager.cpp
+ * @brief LLHeroProbeManager class implementation
+ *
+ * $LicenseInfo:firstyear=2022&license=viewerlgpl$
+ * Second Life Viewer Source Code
+ * Copyright (C) 2022, Linden Research, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation;
+ * version 2.1 of the License only.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
+ * $/LicenseInfo$
+ */
+
+#include "llviewerprecompiledheaders.h"
+
+#include "llheroprobemanager.h"
+#include "llreflectionmapmanager.h"
+#include "llviewercamera.h"
+#include "llspatialpartition.h"
+#include "llviewerregion.h"
+#include "pipeline.h"
+#include "llviewershadermgr.h"
+#include "llviewercontrol.h"
+#include "llenvironment.h"
+#include "llstartup.h"
+#include "llagent.h"
+#include "llagentcamera.h"
+#include "llviewerwindow.h"
+#include "llviewerjoystick.h"
+#include "llviewermediafocus.h"
+
+extern BOOL gCubeSnapshot;
+extern BOOL gTeleportDisplay;
+
+// get the next highest power of two of v (or v if v is already a power of two)
+//defined in llvertexbuffer.cpp
+extern U32 nhpo2(U32 v);
+
+static void touch_default_probe(LLReflectionMap* probe)
+{
+ if (LLViewerCamera::getInstance())
+ {
+ LLVector3 origin = LLViewerCamera::getInstance()->getOrigin();
+ origin.mV[2] += 64.f;
+
+ probe->mOrigin.load3(origin.mV);
+ }
+}
+
+LLHeroProbeManager::LLHeroProbeManager()
+{
+}
+
+// helper class to seed octree with probes
+void LLHeroProbeManager::update()
+{
+ if (!LLPipeline::RenderMirrors || gTeleportDisplay || LLStartUp::getStartupState() < STATE_PRECACHE)
+ {
+ return;
+ }
+
+ LL_PROFILE_ZONE_SCOPED_CATEGORY_DISPLAY;
+ llassert(!gCubeSnapshot); // assert a snapshot is not in progress
+ if (LLAppViewer::instance()->logoutRequestSent())
+ {
+ return;
+ }
+
+ initReflectionMaps();
+
+ if (!mRenderTarget.isComplete())
+ {
+ U32 color_fmt = GL_RGBA16F;
+ U32 targetRes = mProbeResolution; // super sample
+ mRenderTarget.allocate(targetRes, targetRes, color_fmt, true);
+ }
+
+ if (mMipChain.empty())
+ {
+ U32 res = mProbeResolution;
+ U32 count = log2((F32)res) + 0.5f;
+
+ mMipChain.resize(count);
+ for (int i = 0; i < count; ++i)
+ {
+ mMipChain[i].allocate(res, res, GL_RGBA16F);
+ res /= 2;
+ }
+ }
+
+ llassert(mProbes[0] == mDefaultProbe);
+
+ LLVector4a probe_pos;
+ LLVector3 camera_pos = LLViewerCamera::instance().mOrigin;
+ F32 near_clip = 0.1f;
+ if (mHeroVOList.size() > 0)
+ {
+ // Find our nearest hero candidate.
+
+ float last_distance = 99999.f;
+
+ for (auto vo : mHeroVOList)
+ {
+ if (vo)
+ {
+ if (vo->mDrawable.notNull())
+ {
+ if (vo->mDrawable->mDistanceWRTCamera < last_distance)
+ {
+ mNearestHero = vo;
+ last_distance = vo->mDrawable->mDistanceWRTCamera;
+ }
+ }
+ else
+ {
+ // Valid drawables only please. Unregister this one.
+ unregisterHeroDrawable(vo);
+ }
+ }
+ else
+ {
+ unregisterHeroDrawable(vo);
+ }
+ }
+
+ if (mNearestHero != nullptr && mNearestHero->mDrawable.notNull())
+ {
+ U8 mode = mNearestHero->mirrorFace();
+ mode = llmin(mNearestHero->mDrawable->getNumFaces() - 1, mode);
+
+ mCurrentFace = mNearestHero->mDrawable->getFace(mode);
+ LLVector3 hero_pos = mCurrentFace->getPositionAgent();
+
+
+ // Calculate the average normal.
+ LLVector4a *posp = mCurrentFace->getViewerObject()->getVolume()->getVolumeFace(mCurrentFace->getTEOffset()).mPositions;
+ U16 *indp = mCurrentFace->getViewerObject()->getVolume()->getVolumeFace(mCurrentFace->getTEOffset()).mIndices;
+ // get first three vertices (first triangle)
+ LLVector4a v0 = posp[indp[0]];
+ LLVector4a v1 = posp[indp[1]];
+ LLVector4a v2 = posp[indp[2]];
+
+ v1.sub(v0);
+ v2.sub(v0);
+ LLVector3 face_normal = LLVector3(v1[0], v1[1], v1[2]) % LLVector3(v2[0], v2[1], v2[2]);
+
+ face_normal.normalize();
+ face_normal *= mCurrentFace->getXform()->getWorldRotation();
+
+ LLVector3 offset = camera_pos - hero_pos;
+ LLVector3 project = face_normal * (offset * face_normal);
+ LLVector3 reject = offset - project;
+ LLVector3 point = (reject - project) + hero_pos;
+
+ glh::matrix4f mat = copy_matrix(gGLModelView);
+ glh::vec4f tc(face_normal.mV);
+ mat.mult_matrix_vec(tc);
+
+ LLVector3 mirror_normal;
+ mirror_normal.set(tc.v);
+
+ LLVector3 hero_pos_render;
+ tc = glh::vec4f(hero_pos.mV);
+
+ mat.mult_matrix_vec(tc);
+ hero_pos_render.set(tc.v);
+
+ mCurrentClipPlane.setVec(hero_pos_render, mirror_normal);
+
+ probe_pos.load3(point.mV);
+ }
+
+ mHeroProbeStrength = 1;
+ }
+ else
+ {
+ probe_pos.load3(camera_pos.mV);
+ }
+
+
+ static LLCachedControl<S32> sDetail(gSavedSettings, "RenderHeroReflectionProbeDetail", -1);
+ static LLCachedControl<S32> sLevel(gSavedSettings, "RenderHeroReflectionProbeLevel", 3);
+
+ {
+ LL_PROFILE_ZONE_NAMED_CATEGORY_DISPLAY("hpmu - realtime");
+ // Probe 0 is always our mirror probe.
+ mProbes[0]->mOrigin = probe_pos;
+
+ bool radiance_pass = gPipeline.mReflectionMapManager.isRadiancePass();
+
+ gPipeline.mReflectionMapManager.mRadiancePass = true;
+ mRenderingMirror = true;
+ for (U32 j = 0; j < mProbes.size(); j++)
+ {
+ for (U32 i = 0; i < 6; ++i)
+ {
+ updateProbeFace(mProbes[j], i, near_clip);
+ }
+ }
+ mRenderingMirror = false;
+
+ gPipeline.mReflectionMapManager.mRadiancePass = radiance_pass;
+ }
+}
+
+// Do the reflection map update render passes.
+// For every 12 calls of this function, one complete reflection probe radiance map and irradiance map is generated
+// First six passes render the scene with direct lighting only into a scratch space cube map at the end of the cube map array and generate
+// a simple mip chain (not convolution filter).
+// At the end of these passes, an irradiance map is generated for this probe and placed into the irradiance cube map array at the index for this probe
+// The next six passes render the scene with both radiance and irradiance into the same scratch space cube map and generate a simple mip chain.
+// At the end of these passes, a radiance map is generated for this probe and placed into the radiance cube map array at the index for this probe.
+// In effect this simulates single-bounce lighting.
+void LLHeroProbeManager::updateProbeFace(LLReflectionMap* probe, U32 face, F32 near_clip)
+{
+ // hacky hot-swap of camera specific render targets
+ gPipeline.mRT = &gPipeline.mAuxillaryRT;
+
+ probe->update(mRenderTarget.getWidth(), face, true, near_clip);
+
+ gPipeline.mRT = &gPipeline.mMainRT;
+
+ S32 sourceIdx = mReflectionProbeCount;
+
+
+ // Unlike the reflectionmap manager, all probes are considered "realtime" for hero probes.
+ sourceIdx += 1;
+
+ gGL.setColorMask(true, true);
+ LLGLDepthTest depth(GL_FALSE, GL_FALSE);
+ LLGLDisable cull(GL_CULL_FACE);
+ LLGLDisable blend(GL_BLEND);
+
+ // downsample to placeholder map
+ {
+ gGL.matrixMode(gGL.MM_MODELVIEW);
+ gGL.pushMatrix();
+ gGL.loadIdentity();
+
+ gGL.matrixMode(gGL.MM_PROJECTION);
+ gGL.pushMatrix();
+ gGL.loadIdentity();
+
+ gGL.flush();
+ U32 res = mProbeResolution * 2;
+
+ static LLStaticHashedString resScale("resScale");
+ static LLStaticHashedString direction("direction");
+ static LLStaticHashedString znear("znear");
+ static LLStaticHashedString zfar("zfar");
+
+ LLRenderTarget *screen_rt = &gPipeline.mAuxillaryRT.screen;
+ LLRenderTarget *depth_rt = &gPipeline.mAuxillaryRT.deferredScreen;
+
+ // perform a gaussian blur on the super sampled render before downsampling
+ {
+ gGaussianProgram.bind();
+ gGaussianProgram.uniform1f(resScale, 1.f / mProbeResolution);
+ S32 diffuseChannel = gGaussianProgram.enableTexture(LLShaderMgr::DEFERRED_DIFFUSE, LLTexUnit::TT_TEXTURE);
+
+ // horizontal
+ gGaussianProgram.uniform2f(direction, 1.f, 0.f);
+ gGL.getTexUnit(diffuseChannel)->bind(screen_rt);
+ mRenderTarget.bindTarget();
+ gPipeline.mScreenTriangleVB->setBuffer();
+ gPipeline.mScreenTriangleVB->drawArrays(LLRender::TRIANGLES, 0, 3);
+ mRenderTarget.flush();
+
+ // vertical
+ gGaussianProgram.uniform2f(direction, 0.f, 1.f);
+ gGL.getTexUnit(diffuseChannel)->bind(&mRenderTarget);
+ screen_rt->bindTarget();
+ gPipeline.mScreenTriangleVB->setBuffer();
+ gPipeline.mScreenTriangleVB->drawArrays(LLRender::TRIANGLES, 0, 3);
+ screen_rt->flush();
+ }
+
+
+ S32 mips = log2((F32)mProbeResolution) + 0.5f;
+
+ gReflectionMipProgram.bind();
+ S32 diffuseChannel = gReflectionMipProgram.enableTexture(LLShaderMgr::DEFERRED_DIFFUSE, LLTexUnit::TT_TEXTURE);
+ S32 depthChannel = gReflectionMipProgram.enableTexture(LLShaderMgr::DEFERRED_DEPTH, LLTexUnit::TT_TEXTURE);
+
+ for (int i = 0; i < mMipChain.size(); ++i)
+ {
+ LL_PROFILE_GPU_ZONE("probe mip");
+ mMipChain[i].bindTarget();
+ if (i == 0)
+ {
+ gGL.getTexUnit(diffuseChannel)->bind(screen_rt);
+ }
+ else
+ {
+ gGL.getTexUnit(diffuseChannel)->bind(&(mMipChain[i - 1]));
+ }
+
+ gGL.getTexUnit(depthChannel)->bind(depth_rt, true);
+
+ gReflectionMipProgram.uniform1f(resScale, 1.f / (mProbeResolution * 2));
+ gReflectionMipProgram.uniform1f(znear, probe->getNearClip());
+ gReflectionMipProgram.uniform1f(zfar, MAX_FAR_CLIP);
+
+ gPipeline.mScreenTriangleVB->setBuffer();
+ gPipeline.mScreenTriangleVB->drawArrays(LLRender::TRIANGLES, 0, 3);
+
+ res /= 2;
+
+ S32 mip = i - (mMipChain.size() - mips);
+
+ if (mip >= 0)
+ {
+ LL_PROFILE_GPU_ZONE("probe mip copy");
+ mTexture->bind(0);
+
+ glCopyTexSubImage3D(GL_TEXTURE_CUBE_MAP_ARRAY, mip, 0, 0, sourceIdx * 6 + face, 0, 0, res, res);
+
+ mTexture->unbind();
+ }
+ mMipChain[i].flush();
+ }
+
+ gGL.popMatrix();
+ gGL.matrixMode(gGL.MM_MODELVIEW);
+ gGL.popMatrix();
+
+ gGL.getTexUnit(diffuseChannel)->unbind(LLTexUnit::TT_TEXTURE);
+ gReflectionMipProgram.unbind();
+ }
+
+ if (face == 5)
+ {
+ mMipChain[0].bindTarget();
+ static LLStaticHashedString sSourceIdx("sourceIdx");
+
+ {
+ //generate radiance map (even if this is not the irradiance map, we need the mip chain for the irradiance map)
+ gRadianceGenProgram.bind();
+ mVertexBuffer->setBuffer();
+
+ S32 channel = gRadianceGenProgram.enableTexture(LLShaderMgr::REFLECTION_PROBES, LLTexUnit::TT_CUBE_MAP_ARRAY);
+ mTexture->bind(channel);
+ gRadianceGenProgram.uniform1i(sSourceIdx, sourceIdx);
+ gRadianceGenProgram.uniform1f(LLShaderMgr::REFLECTION_PROBE_MAX_LOD, mMaxProbeLOD);
+ gRadianceGenProgram.uniform1f(LLShaderMgr::REFLECTION_PROBE_STRENGTH, mHeroProbeStrength);
+
+ U32 res = mMipChain[0].getWidth();
+
+ for (int i = 0; i < mMipChain.size(); ++i)
+ {
+ LL_PROFILE_GPU_ZONE("probe radiance gen");
+ static LLStaticHashedString sMipLevel("mipLevel");
+ static LLStaticHashedString sRoughness("roughness");
+ static LLStaticHashedString sWidth("u_width");
+ static LLStaticHashedString sStrength("probe_strength");
+
+ gRadianceGenProgram.uniform1f(sRoughness, (F32)i / (F32)(mMipChain.size() - 1));
+ gRadianceGenProgram.uniform1f(sMipLevel, i);
+ gRadianceGenProgram.uniform1i(sWidth, mProbeResolution);
+ gRadianceGenProgram.uniform1f(sStrength, 1);
+
+ for (int cf = 0; cf < 6; ++cf)
+ { // for each cube face
+ LLCoordFrame frame;
+ frame.lookAt(LLVector3(0, 0, 0), LLCubeMapArray::sClipToCubeLookVecs[cf], LLCubeMapArray::sClipToCubeUpVecs[cf]);
+
+ F32 mat[16];
+ frame.getOpenGLRotation(mat);
+ gGL.loadMatrix(mat);
+
+ mVertexBuffer->drawArrays(gGL.TRIANGLE_STRIP, 0, 4);
+
+ glCopyTexSubImage3D(GL_TEXTURE_CUBE_MAP_ARRAY, i, 0, 0, probe->mCubeIndex * 6 + cf, 0, 0, res, res);
+ }
+
+ if (i != mMipChain.size() - 1)
+ {
+ res /= 2;
+ glViewport(0, 0, res, res);
+ }
+ }
+
+ gRadianceGenProgram.unbind();
+ }
+
+ mMipChain[0].flush();
+ }
+}
+
+void LLHeroProbeManager::updateUniforms()
+{
+ if (!LLPipeline::sReflectionProbesEnabled)
+ {
+ return;
+ }
+
+ LL_PROFILE_ZONE_SCOPED_CATEGORY_DISPLAY;
+
+ struct HeroProbeData
+ {
+ LLVector4 heroPosition[1];
+ GLint heroProbeCount = 1;
+ };
+
+ HeroProbeData hpd;
+
+ LLMatrix4a modelview;
+ modelview.loadu(gGLModelView);
+ LLVector4a oa; // scratch space for transformed origin
+ oa.set(0, 0, 0, 0);
+ hpd.heroProbeCount = 1;
+ modelview.affineTransform(mProbes[0]->mOrigin, oa);
+ hpd.heroPosition[0].set(oa.getF32ptr());
+
+ //copy rpd into uniform buffer object
+ if (mUBO == 0)
+ {
+ glGenBuffers(1, &mUBO);
+ }
+
+ {
+ LL_PROFILE_ZONE_NAMED_CATEGORY_DISPLAY("rmmsu - update buffer");
+ glBindBuffer(GL_UNIFORM_BUFFER, mUBO);
+ glBufferData(GL_UNIFORM_BUFFER, sizeof(HeroProbeData), &hpd, GL_STREAM_DRAW);
+ glBindBuffer(GL_UNIFORM_BUFFER, 0);
+ }
+}
+
+void LLHeroProbeManager::setUniforms()
+{
+ if (!LLPipeline::sReflectionProbesEnabled)
+ {
+ return;
+ }
+
+ if (mUBO == 0)
+ {
+ updateUniforms();
+ }
+ glBindBufferBase(GL_UNIFORM_BUFFER, 1, mUBO);
+}
+
+void LLHeroProbeManager::renderDebug()
+{
+ gDebugProgram.bind();
+
+ for (auto& probe : mProbes)
+ {
+ renderReflectionProbe(probe);
+ }
+
+ gDebugProgram.unbind();
+}
+
+void LLHeroProbeManager::initReflectionMaps()
+{
+ U32 count = LL_MAX_HERO_PROBE_COUNT;
+
+ if (mTexture.isNull() || mReflectionProbeCount != count || mReset)
+ {
+ mReset = false;
+ mReflectionProbeCount = count;
+ mProbeResolution = gSavedSettings.getS32("RenderHeroProbeResolution");
+ mMaxProbeLOD = log2f(mProbeResolution) - 1.f; // number of mips - 1
+
+ mTexture = new LLCubeMapArray();
+
+ // store mReflectionProbeCount+2 cube maps, final two cube maps are used for render target and radiance map generation source)
+ mTexture->allocate(mProbeResolution, 3, mReflectionProbeCount + 2);
+
+ if (mDefaultProbe.isNull())
+ {
+ llassert(mProbes.empty()); // default probe MUST be the first probe created
+ mDefaultProbe = new LLReflectionMap();
+ mProbes.push_back(mDefaultProbe);
+ }
+
+ llassert(mProbes[0] == mDefaultProbe);
+
+ // For hero probes, we treat this as the main mirror probe.
+
+ mDefaultProbe->mCubeIndex = 0;
+ mDefaultProbe->mCubeArray = mTexture;
+ mDefaultProbe->mDistance = gSavedSettings.getF32("RenderHeroProbeDistance");
+ mDefaultProbe->mRadius = 4096.f;
+ mDefaultProbe->mProbeIndex = 0;
+ touch_default_probe(mDefaultProbe);
+
+ mProbes.push_back(mDefaultProbe);
+ }
+
+ if (mVertexBuffer.isNull())
+ {
+ U32 mask = LLVertexBuffer::MAP_VERTEX;
+ LLPointer<LLVertexBuffer> buff = new LLVertexBuffer(mask);
+ buff->allocateBuffer(4, 0);
+
+ LLStrider<LLVector3> v;
+
+ buff->getVertexStrider(v);
+
+ v[0] = LLVector3(-1, -1, -1);
+ v[1] = LLVector3(1, -1, -1);
+ v[2] = LLVector3(-1, 1, -1);
+ v[3] = LLVector3(1, 1, -1);
+
+ buff->unmapBuffer();
+
+ mVertexBuffer = buff;
+ }
+}
+
+void LLHeroProbeManager::cleanup()
+{
+ mVertexBuffer = nullptr;
+ mRenderTarget.release();
+ mHeroRenderTarget.release();
+
+ mMipChain.clear();
+
+ mTexture = nullptr;
+
+ mProbes.clear();
+
+ mReflectionMaps.clear();
+
+ mDefaultProbe = nullptr;
+ mUpdatingProbe = nullptr;
+
+ glDeleteBuffers(1, &mUBO);
+ mUBO = 0;
+
+ mHeroVOList.clear();
+ mNearestHero = nullptr;
+}
+
+void LLHeroProbeManager::doOcclusion()
+{
+ LLVector4a eye;
+ eye.load3(LLViewerCamera::instance().getOrigin().mV);
+
+ for (auto& probe : mProbes)
+ {
+ if (probe != nullptr && probe != mDefaultProbe)
+ {
+ probe->doOcclusion(eye);
+ }
+ }
+}
+
+void LLHeroProbeManager::registerHeroDrawable(LLVOVolume* drawablep)
+{
+ if (mHeroVOList.find(drawablep) == mHeroVOList.end())
+ {
+ mHeroVOList.insert(drawablep);
+ LL_INFOS() << "Mirror drawable registered." << LL_ENDL;
+ }
+}
+
+void LLHeroProbeManager::unregisterHeroDrawable(LLVOVolume* drawablep)
+{
+ if (mHeroVOList.find(drawablep) != mHeroVOList.end())
+ {
+ mHeroVOList.erase(drawablep);
+ }
+}
+
+bool LLHeroProbeManager::isViableMirror(LLFace* face) const
+{
+ return face == mCurrentFace;
+}
diff --git a/indra/newview/llheroprobemanager.h b/indra/newview/llheroprobemanager.h
new file mode 100644
index 0000000000..68cfdbfd99
--- /dev/null
+++ b/indra/newview/llheroprobemanager.h
@@ -0,0 +1,142 @@
+/**
+ * @file llheroprobemanager.h
+ * @brief LLHeroProbeManager class declaration
+ *
+ * $LicenseInfo:firstyear=2022&license=viewerlgpl$
+ * Second Life Viewer Source Code
+ * Copyright (C) 2022, Linden Research, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation;
+ * version 2.1 of the License only.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
+ * $/LicenseInfo$
+ */
+
+#pragma once
+
+#include "llreflectionmap.h"
+#include "llrendertarget.h"
+#include "llcubemaparray.h"
+#include "llcubemap.h"
+#include "lldrawable.h"
+
+class LLSpatialGroup;
+class LLViewerObject;
+
+// number of reflection probes to keep in vram
+#define LL_MAX_HERO_PROBE_COUNT 2
+
+class alignas(16) LLHeroProbeManager
+{
+ LL_ALIGN_NEW
+public:
+ enum class DetailLevel
+ {
+ STATIC_ONLY = 0,
+ STATIC_AND_DYNAMIC,
+ REALTIME = 2
+ };
+
+ // allocate an environment map of the given resolution
+ LLHeroProbeManager();
+
+ // release any GL state
+ void cleanup();
+
+ // maintain reflection probes
+ void update();
+
+ // debug display, called from llspatialpartition if reflection
+ // probe debug display is active
+ void renderDebug();
+
+ // call once at startup to allocate cubemap arrays
+ void initReflectionMaps();
+
+ // perform occlusion culling on all active reflection probes
+ void doOcclusion();
+
+ void registerHeroDrawable(LLVOVolume* drawablep);
+ void unregisterHeroDrawable(LLVOVolume* drawablep);
+
+ bool isViableMirror(LLFace* face) const;
+
+ bool isMirrorPass() const { return mRenderingMirror; }
+
+ LLPlane currentMirrorClip() const { return mCurrentClipPlane; }
+
+private:
+ friend class LLPipeline;
+
+ // update UBO used for rendering (call only once per render pipe flush)
+ void updateUniforms();
+
+ // bind UBO used for rendering
+ void setUniforms();
+
+ // render target for cube snapshots
+ // used to generate mipmaps without doing a copy-to-texture
+ LLRenderTarget mRenderTarget;
+
+ LLRenderTarget mHeroRenderTarget;
+
+ std::vector<LLRenderTarget> mMipChain;
+
+ // storage for reflection probe radiance maps (plus two scratch space cubemaps)
+ LLPointer<LLCubeMapArray> mTexture;
+
+ // vertex buffer for pushing verts to filter shaders
+ LLPointer<LLVertexBuffer> mVertexBuffer;
+
+ LLPlane mCurrentClipPlane;
+
+ // update the specified face of the specified probe
+ void updateProbeFace(LLReflectionMap* probe, U32 face, F32 near_clip);
+
+ // list of active reflection maps
+ std::vector<LLPointer<LLReflectionMap> > mProbes;
+
+ // handle to UBO
+ U32 mUBO = 0;
+
+ // list of maps being used for rendering
+ std::vector<LLReflectionMap*> mReflectionMaps;
+
+ LLReflectionMap* mUpdatingProbe = nullptr;
+
+ LLPointer<LLReflectionMap> mDefaultProbe; // default reflection probe to fall back to for pixels with no probe influences (should always be at cube index 0)
+
+ // number of reflection probes to use for rendering
+ U32 mReflectionProbeCount;
+
+ // resolution of reflection probes
+ U32 mProbeResolution = 1024;
+
+ // maximum LoD of reflection probes (mip levels - 1)
+ F32 mMaxProbeLOD = 6.f;
+
+ F32 mHeroProbeStrength = 1.f;
+ bool mIsInTransition = false;
+
+ // if true, reset all probe render state on the next update (for teleports and sky changes)
+ bool mReset = false;
+
+ bool mRenderingMirror = false;
+
+ std::set<LLVOVolume*> mHeroVOList;
+ LLVOVolume* mNearestHero;
+ LLFace* mCurrentFace;
+};
+
diff --git a/indra/newview/llinventoryfunctions.cpp b/indra/newview/llinventoryfunctions.cpp
index 4aeacae6ed..207dd692a8 100644
--- a/indra/newview/llinventoryfunctions.cpp
+++ b/indra/newview/llinventoryfunctions.cpp
@@ -2554,6 +2554,12 @@ bool LLIsOfAssetType::operator()(LLInventoryCategory* cat, LLInventoryItem* item
return FALSE;
}
+bool LLAssetIDAndTypeMatches::operator()(LLInventoryCategory* cat, LLInventoryItem* item)
+{
+ if (!item) return false;
+ return (item->getActualType() == mType && item->getAssetUUID() == mAssetID);
+}
+
bool LLIsValidItemLink::operator()(LLInventoryCategory* cat, LLInventoryItem* item)
{
LLViewerInventoryItem *vitem = dynamic_cast<LLViewerInventoryItem*>(item);
diff --git a/indra/newview/llinventoryfunctions.h b/indra/newview/llinventoryfunctions.h
index 925217dda3..2056a7f6a3 100644
--- a/indra/newview/llinventoryfunctions.h
+++ b/indra/newview/llinventoryfunctions.h
@@ -278,6 +278,28 @@ protected:
LLAssetType::EType mType;
};
+//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+// Class LLAssetIDAndTypeMatches
+//
+// Implementation of a LLInventoryCollectFunctor which returns TRUE if
+// the item matches both asset type and asset id.
+// This is needed in case you are looking for a specific type with default id
+// (since null is default for multiple asset types)
+//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+class LLAssetIDAndTypeMatches: public LLInventoryCollectFunctor
+{
+public:
+ LLAssetIDAndTypeMatches(const LLUUID& asset_id, LLAssetType::EType type): mAssetID(asset_id), mType(type) {}
+ virtual ~LLAssetIDAndTypeMatches() {}
+ bool operator()(LLInventoryCategory* cat,
+ LLInventoryItem* item);
+
+protected:
+ LLUUID mAssetID;
+ LLAssetType::EType mType;
+};
+
class LLIsValidItemLink : public LLInventoryCollectFunctor
{
public:
diff --git a/indra/newview/llmaterialeditor.cpp b/indra/newview/llmaterialeditor.cpp
index 292ddb765f..f939418893 100644
--- a/indra/newview/llmaterialeditor.cpp
+++ b/indra/newview/llmaterialeditor.cpp
@@ -43,6 +43,7 @@
#include "llnotificationsutil.h"
#include "lltexturectrl.h"
#include "lltrans.h"
+#include "llviewercontrol.h"
#include "llviewermenufile.h"
#include "llviewertexture.h"
#include "llsdutil.h"
@@ -448,6 +449,8 @@ BOOL LLMaterialEditor::postBuild()
mEmissiveTextureCtrl->setCommitCallback(boost::bind(&LLMaterialEditor::onCommitTexture, this, _1, _2, MATERIAL_EMISIVE_TEX_DIRTY));
mNormalTextureCtrl->setCommitCallback(boost::bind(&LLMaterialEditor::onCommitTexture, this, _1, _2, MATERIAL_NORMAL_TEX_DIRTY));
+ mNormalTextureCtrl->setBlankImageAssetID(BLANK_OBJECT_NORMAL);
+
if (mIsOverride)
{
// Live editing needs a recovery mechanism on cancel
@@ -1376,10 +1379,23 @@ bool LLMaterialEditor::saveIfNeeded()
LLPermissions local_permissions;
local_permissions.init(gAgent.getID(), gAgent.getID(), LLUUID::null, LLUUID::null);
- U32 everyone_perm = LLFloaterPerms::getEveryonePerms("Materials");
- U32 group_perm = LLFloaterPerms::getGroupPerms("Materials");
- U32 next_owner_perm = LLFloaterPerms::getNextOwnerPerms("Materials");
- local_permissions.initMasks(PERM_ALL, PERM_ALL, everyone_perm, group_perm, next_owner_perm);
+ if (mIsOverride)
+ {
+ // Shouldn't happen, but just in case it ever changes
+ U32 everyone_perm = LLFloaterPerms::getEveryonePerms("Materials");
+ U32 group_perm = LLFloaterPerms::getGroupPerms("Materials");
+ U32 next_owner_perm = LLFloaterPerms::getNextOwnerPerms("Materials");
+ local_permissions.initMasks(PERM_ALL, PERM_ALL, everyone_perm, group_perm, next_owner_perm);
+
+ }
+ else
+ {
+ // Uploads are supposed to use Upload permissions, not material permissions
+ U32 everyone_perm = LLFloaterPerms::getEveryonePerms("Uploads");
+ U32 group_perm = LLFloaterPerms::getGroupPerms("Uploads");
+ U32 next_owner_perm = LLFloaterPerms::getNextOwnerPerms("Uploads");
+ local_permissions.initMasks(PERM_ALL, PERM_ALL, everyone_perm, group_perm, next_owner_perm);
+ }
std::string res_desc = buildMaterialDescription();
createInventoryItem(buffer, mMaterialName, res_desc, local_permissions);
@@ -1854,7 +1870,7 @@ static void pack_textures(
if (normal_img)
{
// create a losslessly compressed version of the normal map
- normal_j2c = LLViewerTextureList::convertToUploadFile(normal_img, 1024, false, true);
+ normal_j2c = LLViewerTextureList::convertToUploadFile(normal_img, 2048, false, true);
LL_DEBUGS("MaterialEditor") << "Normal: " << normal_j2c->getDataSize() << LL_ENDL;
}
@@ -2228,7 +2244,7 @@ bool LLMaterialEditor::canModifyObjectsMaterial()
LLSelectedTEGetMatData func(true);
LLPermissions permissions;
LLViewerInventoryItem* item_out;
- return can_use_objects_material(func, std::vector({PERM_MODIFY}), ItemSource::OBJECT, permissions, item_out);
+ return can_use_objects_material(func, std::vector<PermissionBit>({PERM_MODIFY}), ItemSource::OBJECT, permissions, item_out);
}
bool LLMaterialEditor::canSaveObjectsMaterial()
@@ -2236,7 +2252,7 @@ bool LLMaterialEditor::canSaveObjectsMaterial()
LLSelectedTEGetMatData func(true);
LLPermissions permissions;
LLViewerInventoryItem* item_out;
- return can_use_objects_material(func, std::vector({PERM_COPY, PERM_MODIFY}), ItemSource::AGENT, permissions, item_out);
+ return can_use_objects_material(func, std::vector<PermissionBit>({PERM_COPY, PERM_MODIFY}), ItemSource::AGENT, permissions, item_out);
}
bool LLMaterialEditor::canClipboardObjectsMaterial()
@@ -2262,7 +2278,7 @@ bool LLMaterialEditor::canClipboardObjectsMaterial()
LLSelectedTEGetMatData func(true);
LLPermissions permissions;
LLViewerInventoryItem* item_out;
- return can_use_objects_material(func, std::vector({PERM_COPY, PERM_MODIFY, PERM_TRANSFER}), ItemSource::OBJECT, permissions, item_out);
+ return can_use_objects_material(func, std::vector<PermissionBit>({PERM_COPY, PERM_MODIFY, PERM_TRANSFER}), ItemSource::OBJECT, permissions, item_out);
}
void LLMaterialEditor::saveObjectsMaterialAs()
@@ -2270,7 +2286,7 @@ void LLMaterialEditor::saveObjectsMaterialAs()
LLSelectedTEGetMatData func(true);
LLPermissions permissions;
LLViewerInventoryItem* item = nullptr;
- bool allowed = can_use_objects_material(func, std::vector({PERM_COPY, PERM_MODIFY}), ItemSource::AGENT, permissions, item);
+ bool allowed = can_use_objects_material(func, std::vector<PermissionBit>({PERM_COPY, PERM_MODIFY}), ItemSource::AGENT, permissions, item);
if (!allowed)
{
LL_WARNS("MaterialEditor") << "Failed to save GLTF material from object" << LL_ENDL;
diff --git a/indra/newview/llpaneleditwater.cpp b/indra/newview/llpaneleditwater.cpp
index a09964e17d..cf536dd87e 100644
--- a/indra/newview/llpaneleditwater.cpp
+++ b/indra/newview/llpaneleditwater.cpp
@@ -89,7 +89,7 @@ BOOL LLPanelSettingsWaterMainTab::postBuild()
getChild<LLUICtrl>(FIELD_WATER_UNDERWATER_MOD)->setCommitCallback([this](LLUICtrl *, const LLSD &) { onFogUnderWaterChanged(); });
mTxtNormalMap->setDefaultImageAssetID(LLSettingsWater::GetDefaultWaterNormalAssetId());
- mTxtNormalMap->setBlankImageAssetID(LLUUID( gSavedSettings.getString( "DefaultBlankNormalTexture" )));
+ mTxtNormalMap->setBlankImageAssetID(BLANK_OBJECT_NORMAL);
mTxtNormalMap->setCommitCallback([this](LLUICtrl *, const LLSD &) { onNormalMapChanged(); });
getChild<LLUICtrl>(FIELD_WATER_WAVE2_XY)->setCommitCallback([this](LLUICtrl *, const LLSD &) { onSmallWaveChanged(); });
diff --git a/indra/newview/llpanelface.cpp b/indra/newview/llpanelface.cpp
index 5f8071d3eb..753601d98e 100644
--- a/indra/newview/llpanelface.cpp
+++ b/indra/newview/llpanelface.cpp
@@ -330,13 +330,13 @@ BOOL LLPanelFace::postBuild()
pbr_ctrl->setImmediateFilterPermMask(PERM_NONE);
pbr_ctrl->setDnDFilterPermMask(PERM_COPY | PERM_TRANSFER);
pbr_ctrl->setBakeTextureEnabled(false);
- pbr_ctrl->setInventoryPickType(LLTextureCtrl::PICK_MATERIAL);
+ pbr_ctrl->setInventoryPickType(PICK_MATERIAL);
}
mTextureCtrl = getChild<LLTextureCtrl>("texture control");
if(mTextureCtrl)
{
- mTextureCtrl->setDefaultImageAssetID(LLUUID( gSavedSettings.getString( "DefaultObjectTexture" )));
+ mTextureCtrl->setDefaultImageAssetID(DEFAULT_OBJECT_TEXTURE);
mTextureCtrl->setCommitCallback( boost::bind(&LLPanelFace::onCommitTexture, this, _2) );
mTextureCtrl->setOnCancelCallback( boost::bind(&LLPanelFace::onCancelTexture, this, _2) );
mTextureCtrl->setOnSelectCallback( boost::bind(&LLPanelFace::onSelectTexture, this, _2) );
@@ -353,7 +353,7 @@ BOOL LLPanelFace::postBuild()
mShinyTextureCtrl = getChild<LLTextureCtrl>("shinytexture control");
if(mShinyTextureCtrl)
{
- mShinyTextureCtrl->setDefaultImageAssetID(LLUUID( gSavedSettings.getString( "DefaultObjectSpecularTexture" )));
+ mShinyTextureCtrl->setDefaultImageAssetID(DEFAULT_OBJECT_SPECULAR);
mShinyTextureCtrl->setCommitCallback( boost::bind(&LLPanelFace::onCommitSpecularTexture, this, _2) );
mShinyTextureCtrl->setOnCancelCallback( boost::bind(&LLPanelFace::onCancelSpecularTexture, this, _2) );
mShinyTextureCtrl->setOnSelectCallback( boost::bind(&LLPanelFace::onSelectSpecularTexture, this, _2) );
@@ -370,8 +370,8 @@ BOOL LLPanelFace::postBuild()
mBumpyTextureCtrl = getChild<LLTextureCtrl>("bumpytexture control");
if(mBumpyTextureCtrl)
{
- mBumpyTextureCtrl->setDefaultImageAssetID(LLUUID( gSavedSettings.getString( "DefaultObjectNormalTexture" )));
- mBumpyTextureCtrl->setBlankImageAssetID(LLUUID( gSavedSettings.getString( "DefaultBlankNormalTexture" )));
+ mBumpyTextureCtrl->setDefaultImageAssetID(DEFAULT_OBJECT_NORMAL);
+ mBumpyTextureCtrl->setBlankImageAssetID(BLANK_OBJECT_NORMAL);
mBumpyTextureCtrl->setCommitCallback( boost::bind(&LLPanelFace::onCommitNormalTexture, this, _2) );
mBumpyTextureCtrl->setOnCancelCallback( boost::bind(&LLPanelFace::onCancelNormalTexture, this, _2) );
mBumpyTextureCtrl->setOnSelectCallback( boost::bind(&LLPanelFace::onSelectNormalTexture, this, _2) );
@@ -1782,6 +1782,7 @@ void LLPanelFace::updateUI(bool force_set_values /*false*/)
getChild<LLUICtrl>("shinyOffsetV")->setValue(offset_y);
getChild<LLUICtrl>("glossiness")->setValue(material->getSpecularLightExponent());
getChild<LLUICtrl>("environment")->setValue(material->getEnvironmentIntensity());
+ getChild<LLUICtrl>("mirror")->setValue(material->getEnvironmentIntensity());
updateShinyControls(!material->getSpecularID().isNull(), true);
}
@@ -4413,7 +4414,7 @@ void LLPanelFace::onCopyTexture()
LLUUID id = mat_data["NormMap"].asUUID();
if (id.notNull() && !get_can_copy_texture(id))
{
- mat_data["NormMap"] = LLUUID(gSavedSettings.getString("DefaultObjectTexture"));
+ mat_data["NormMap"] = DEFAULT_OBJECT_TEXTURE;
mat_data["NormMapNoCopy"] = true;
}
@@ -4423,7 +4424,7 @@ void LLPanelFace::onCopyTexture()
LLUUID id = mat_data["SpecMap"].asUUID();
if (id.notNull() && !get_can_copy_texture(id))
{
- mat_data["SpecMap"] = LLUUID(gSavedSettings.getString("DefaultObjectTexture"));
+ mat_data["SpecMap"] = DEFAULT_OBJECT_TEXTURE;
mat_data["SpecMapNoCopy"] = true;
}
@@ -5176,8 +5177,9 @@ void LLPanelFace::onPbrSelectionChanged(LLInventoryItem* itemp)
bool can_modify = itemp->getPermissions().allowOperationBy(PERM_MODIFY, gAgentID); // do we have perm to transfer this material?
bool is_object_owner = gAgentID == obj_owner_id; // does object for which we are going to apply material belong to the agent?
bool not_for_sale = !sale_info.isForSale(); // is object for which we are going to apply material not for sale?
+ bool from_library = ALEXANDRIA_LINDEN_ID == itemp->getPermissions().getOwner();
- if (can_copy && can_transfer && can_modify)
+ if ((can_copy && can_transfer && can_modify) || from_library)
{
pbr_ctrl->setCanApply(true, true);
return;
diff --git a/indra/newview/llpanelface.h b/indra/newview/llpanelface.h
index 5ca6a95699..774a32efb4 100644
--- a/indra/newview/llpanelface.h
+++ b/indra/newview/llpanelface.h
@@ -144,6 +144,7 @@ protected:
void sendTexGen(); // applies and sends bump map
void sendShiny(U32 shininess); // applies and sends shininess
void sendFullbright(); // applies and sends full bright
+
void sendGlow();
void alignTestureLayer();
@@ -233,7 +234,7 @@ protected:
static void onCommitShiny( LLUICtrl* ctrl, void* userdata);
static void onCommitAlphaMode( LLUICtrl* ctrl, void* userdata);
static void onCommitFullbright( LLUICtrl* ctrl, void* userdata);
- static void onCommitGlow( LLUICtrl* ctrl, void *userdata);
+ static void onCommitGlow( LLUICtrl* ctrl, void *userdata);
static void onCommitPlanarAlign( LLUICtrl* ctrl, void* userdata);
static void onCommitRepeatsPerMeter( LLUICtrl* ctrl, void* userinfo);
diff --git a/indra/newview/llpanelprofile.cpp b/indra/newview/llpanelprofile.cpp
index ffbed778c1..8114e05a94 100644
--- a/indra/newview/llpanelprofile.cpp
+++ b/indra/newview/llpanelprofile.cpp
@@ -1969,7 +1969,8 @@ void LLPanelProfileSecondLife::onShowTexturePicker()
PERM_NONE,
PERM_NONE,
FALSE,
- NULL);
+ NULL,
+ PICK_TEXTURE);
mFloaterTexturePickerHandle = texture_floaterp->getHandle();
@@ -2304,7 +2305,8 @@ void LLPanelProfileFirstLife::onChangePhoto()
PERM_NONE,
PERM_NONE,
FALSE,
- NULL);
+ NULL,
+ PICK_TEXTURE);
mFloaterTexturePickerHandle = texture_floaterp->getHandle();
diff --git a/indra/newview/llpanelvolume.cpp b/indra/newview/llpanelvolume.cpp
index 595609b4de..a306a0a9ac 100644
--- a/indra/newview/llpanelvolume.cpp
+++ b/indra/newview/llpanelvolume.cpp
@@ -114,6 +114,11 @@ BOOL LLPanelVolume::postBuild()
getChild<LLUICtrl>("FlexForceZ")->setValidateBeforeCommit(precommitValidate);
}
+ // Mirror Parameters
+ {
+ childSetCommitCallback("Mirror Checkbox Ctrl", onCommitIsMirror, this);
+ }
+
// LIGHT Parameters
{
childSetCommitCallback("Light Checkbox Ctrl",onCommitIsLight,this);
@@ -305,6 +310,10 @@ void LLPanelVolume::getState( )
getChildView("select_single")->setEnabled(true);
}
+ BOOL is_mirror = volobjp && volobjp->isMirror();
+ getChild<LLUICtrl>("Mirror Checkbox Ctrl")->setValue(is_mirror);
+ getChildView("Mirror Checkbox Ctrl")->setEnabled(editable && single_volume && volobjp);
+
// Light properties
BOOL is_light = volobjp && volobjp->getIsLight();
getChild<LLUICtrl>("Light Checkbox Ctrl")->setValue(is_light);
@@ -746,6 +755,20 @@ void LLPanelVolume::sendIsLight()
LL_INFOS() << "update light sent" << LL_ENDL;
}
+void LLPanelVolume::sendIsMirror()
+{
+ LLViewerObject* objectp = mObject;
+ if (!objectp || (objectp->getPCode() != LL_PCODE_VOLUME))
+ {
+ return;
+ }
+ LLVOVolume *volobjp = (LLVOVolume *)objectp;
+
+ BOOL value = getChild<LLUICtrl>("Mirror Checkbox Ctrl")->getValue();
+ volobjp->setIsMirror(value);
+ LL_INFOS() << "update mirror sent" << LL_ENDL;
+}
+
void notify_cant_select_reflection_probe()
{
if (!gSavedSettings.getBOOL("SelectReflectionProbes"))
@@ -1446,6 +1469,12 @@ void LLPanelVolume::onCommitIsLight( LLUICtrl* ctrl, void* userdata )
self->sendIsLight();
}
+void LLPanelVolume::onCommitIsMirror( LLUICtrl* ctrl, void* userdata )
+{
+ LLPanelVolume* self = (LLPanelVolume*) userdata;
+ self->sendIsMirror();
+}
+
// static
void LLPanelVolume::setLightTextureID(const LLUUID &asset_id, const LLUUID &item_id, LLVOVolume* volobjp)
{
diff --git a/indra/newview/llpanelvolume.h b/indra/newview/llpanelvolume.h
index 01b7ebb75c..a658351624 100644
--- a/indra/newview/llpanelvolume.h
+++ b/indra/newview/llpanelvolume.h
@@ -58,6 +58,7 @@ public:
void sendIsLight();
+ void sendIsMirror();
// when an object is becoming a refleciton probe, present a dialog asking for confirmation
// otherwise, send the reflection probe update immediately
void sendIsReflectionProbe();
@@ -71,6 +72,7 @@ public:
static void onCommitIsLight( LLUICtrl* ctrl, void* userdata);
static void onCommitLight( LLUICtrl* ctrl, void* userdata);
+ static void onCommitIsMirror( LLUICtrl* ctrl, void* userdata);
static void onCommitIsReflectionProbe(LLUICtrl* ctrl, void* userdata);
static void onCommitProbe(LLUICtrl* ctrl, void* userdata);
void onCommitIsFlexible( LLUICtrl* ctrl, void* userdata);
diff --git a/indra/newview/llreflectionmap.cpp b/indra/newview/llreflectionmap.cpp
index a26445b4bc..6d5797395c 100644
--- a/indra/newview/llreflectionmap.cpp
+++ b/indra/newview/llreflectionmap.cpp
@@ -49,7 +49,7 @@ LLReflectionMap::~LLReflectionMap()
}
}
-void LLReflectionMap::update(U32 resolution, U32 face)
+void LLReflectionMap::update(U32 resolution, U32 face, bool force_dynamic, F32 near_clip, bool useClipPlane, LLPlane clipPlane)
{
LL_PROFILE_ZONE_SCOPED_CATEGORY_DISPLAY;
mLastUpdateTime = gFrameTimeSeconds;
@@ -63,7 +63,10 @@ void LLReflectionMap::update(U32 resolution, U32 face)
{
resolution /= 2;
}
- gViewerWindow->cubeSnapshot(LLVector3(mOrigin), mCubeArray, mCubeIndex, face, getNearClip(), getIsDynamic());
+
+ F32 clip = (near_clip > 0) ? near_clip : getNearClip();
+
+ gViewerWindow->cubeSnapshot(LLVector3(mOrigin), mCubeArray, mCubeIndex, face, clip, getIsDynamic() || force_dynamic, useClipPlane, clipPlane);
}
void LLReflectionMap::autoAdjustOrigin()
diff --git a/indra/newview/llreflectionmap.h b/indra/newview/llreflectionmap.h
index 7ea0fe6187..9e888f20d0 100644
--- a/indra/newview/llreflectionmap.h
+++ b/indra/newview/llreflectionmap.h
@@ -36,6 +36,15 @@ class alignas(16) LLReflectionMap : public LLRefCount
{
LL_ALIGN_NEW
public:
+
+ enum class ProbeType
+ {
+ ALL = 0,
+ RADIANCE,
+ IRRADIANCE,
+ REFLECTION
+ };
+
// allocate an environment map of the given resolution
LLReflectionMap();
@@ -43,7 +52,7 @@ public:
// update this environment map
// resolution - size of cube map to generate
- void update(U32 resolution, U32 face);
+ void update(U32 resolution, U32 face, bool force_dynamic = false, F32 near_clip = -1.f, bool useClipPlane = false, LLPlane clipPlane = LLPlane(LLVector3(0, 0, 0), LLVector3(0, 0, 1)));
// for volume partition probes, try to place this probe in the best spot
void autoAdjustOrigin();
@@ -127,5 +136,7 @@ public:
GLuint mOcclusionQuery = 0;
bool mOccluded = false;
U32 mOcclusionPendingFrames = 0;
+
+ ProbeType mType;
};
diff --git a/indra/newview/llreflectionmapmanager.cpp b/indra/newview/llreflectionmapmanager.cpp
index 69674417c1..8506886409 100644
--- a/indra/newview/llreflectionmapmanager.cpp
+++ b/indra/newview/llreflectionmapmanager.cpp
@@ -27,6 +27,9 @@
#include "llviewerprecompiledheaders.h"
#include "llreflectionmapmanager.h"
+
+#include <vector>
+
#include "llviewercamera.h"
#include "llspatialpartition.h"
#include "llviewerregion.h"
@@ -306,8 +309,8 @@ void LLReflectionMapManager::update()
}
}
- if (realtime &&
- closestDynamic == nullptr &&
+ if (realtime &&
+ closestDynamic == nullptr &&
probe->mCubeIndex != -1 &&
probe->getIsDynamic())
{
@@ -322,7 +325,7 @@ void LLReflectionMapManager::update()
// should do a full irradiance pass on "odd" frames and a radiance pass on "even" frames
closestDynamic->autoAdjustOrigin();
- // store and override the value of "isRadiancePass" -- parts of the render pipe rely on "isRadiancePass" to set
+ // store and override the value of "isRadiancePass" -- parts of the render pipe rely on "isRadiancePass" to set
// lighting values etc
bool radiance_pass = isRadiancePass();
mRadiancePass = mRealtimeRadiancePass;
@@ -573,7 +576,7 @@ void LLReflectionMapManager::doProbeUpdate()
// Do the reflection map update render passes.
// For every 12 calls of this function, one complete reflection probe radiance map and irradiance map is generated
-// First six passes render the scene with direct lighting only into a scratch space cube map at the end of the cube map array and generate
+// First six passes render the scene with direct lighting only into a scratch space cube map at the end of the cube map array and generate
// a simple mip chain (not convolution filter).
// At the end of these passes, an irradiance map is generated for this probe and placed into the irradiance cube map array at the index for this probe
// The next six passes render the scene with both radiance and irradiance into the same scratch space cube map and generate a simple mip chain.
@@ -734,6 +737,7 @@ void LLReflectionMapManager::updateProbeFace(LLReflectionMap* probe, U32 face)
mTexture->bind(channel);
gRadianceGenProgram.uniform1i(sSourceIdx, sourceIdx);
gRadianceGenProgram.uniform1f(LLShaderMgr::REFLECTION_PROBE_MAX_LOD, mMaxProbeLOD);
+ gRadianceGenProgram.uniform1f(LLShaderMgr::REFLECTION_PROBE_STRENGTH, 1.f);
U32 res = mMipChain[0].getWidth();
@@ -898,14 +902,14 @@ void LLReflectionMapManager::updateUniforms()
// see class3/deferred/reflectionProbeF.glsl
struct ReflectionProbeData
{
- // for box probes, matrix that transforms from camera space to a [-1, 1] cube representing the bounding box of
+ // for box probes, matrix that transforms from camera space to a [-1, 1] cube representing the bounding box of
// the box probe
- LLMatrix4 refBox[LL_MAX_REFLECTION_PROBE_COUNT];
+ LLMatrix4 refBox[LL_MAX_REFLECTION_PROBE_COUNT];
// for sphere probes, origin (xyz) and radius (w) of refmaps in clip space
- LLVector4 refSphere[LL_MAX_REFLECTION_PROBE_COUNT];
+ LLVector4 refSphere[LL_MAX_REFLECTION_PROBE_COUNT];
- // extra parameters
+ // extra parameters
// x - irradiance scale
// y - radiance scale
// z - fade in
@@ -917,14 +921,14 @@ void LLReflectionMapManager::updateUniforms()
// [i][1] - index into "refNeighbor" for probes that intersect this probe
// [i][2] - number of probes that intersect this probe, or -1 for no neighbors
// [i][3] - priority (probe type stored in sign bit - positive for spheres, negative for boxes)
- GLint refIndex[LL_MAX_REFLECTION_PROBE_COUNT][4];
+ GLint refIndex[LL_MAX_REFLECTION_PROBE_COUNT][4];
// list of neighbor indices
- GLint refNeighbor[4096];
+ GLint refNeighbor[4096];
GLint refBucket[256][4]; //lookup table for which index to start with for the given Z depth
// numbrer of active refmaps
- GLint refmapCount;
+ GLint refmapCount;
};
mReflectionMaps.resize(mReflectionProbeCount);
@@ -1152,7 +1156,7 @@ void LLReflectionMapManager::setUniforms()
}
if (mUBO == 0)
- {
+ {
updateUniforms();
}
glBindBufferBase(GL_UNIFORM_BUFFER, 1, mUBO);
@@ -1343,8 +1347,8 @@ void LLReflectionMapManager::initReflectionMaps()
}
}
-void LLReflectionMapManager::cleanup()
-{
+void LLReflectionMapManager::cleanup()
+{
mVertexBuffer = nullptr;
mRenderTarget.release();
@@ -1383,3 +1387,39 @@ void LLReflectionMapManager::doOcclusion()
}
}
}
+
+void LLReflectionMapManager::forceDefaultProbeAndUpdateUniforms(bool force)
+{
+ static std::vector<bool> mProbeWasOccluded;
+
+ if (force)
+ {
+ llassert(mProbeWasOccluded.empty());
+
+ for (size_t i = 0; i < mProbes.size(); ++i)
+ {
+ auto& probe = mProbes[i];
+ mProbeWasOccluded.push_back(probe->mOccluded);
+ if (probe != nullptr && probe != mDefaultProbe)
+ {
+ probe->mOccluded = true;
+ }
+ }
+
+ updateUniforms();
+ }
+ else
+ {
+ llassert(mProbes.size() == mProbeWasOccluded.size());
+
+ const size_t n = llmin(mProbes.size(), mProbeWasOccluded.size());
+ for (size_t i = 0; i < n; ++i)
+ {
+ auto& probe = mProbes[i];
+ llassert(probe->mOccluded == (probe != mDefaultProbe));
+ probe->mOccluded = mProbeWasOccluded[i];
+ }
+ mProbeWasOccluded.clear();
+ mProbeWasOccluded.shrink_to_fit();
+ }
+}
diff --git a/indra/newview/llreflectionmapmanager.h b/indra/newview/llreflectionmapmanager.h
index b77a33da89..0fee99eefc 100644
--- a/indra/newview/llreflectionmapmanager.h
+++ b/indra/newview/llreflectionmapmanager.h
@@ -43,21 +43,23 @@ class LLViewerObject;
// reflection probe mininum scale
#define LL_REFLECTION_PROBE_MINIMUM_SCALE 1.f;
+void renderReflectionProbe(LLReflectionMap* probe);
+
class alignas(16) LLReflectionMapManager
{
LL_ALIGN_NEW
public:
- enum class DetailLevel
+ enum class DetailLevel
{
STATIC_ONLY = 0,
STATIC_AND_DYNAMIC,
REALTIME = 2
};
- // allocate an environment map of the given resolution
+ // allocate an environment map of the given resolution
LLReflectionMapManager();
- // release any GL state
+ // release any GL state
void cleanup();
// maintain reflection probes
@@ -106,8 +108,14 @@ public:
// perform occlusion culling on all active reflection probes
void doOcclusion();
+ // *HACK: "cull" all reflection probes except the default one. Only call
+ // this if you don't intend to call updateUniforms directly. Call again
+ // with false when done.
+ void forceDefaultProbeAndUpdateUniforms(bool force = true);
+
private:
friend class LLPipeline;
+ friend class LLHeroProbeManager;
// initialize mCubeFree array to default values
void initCubeFree();
@@ -119,7 +127,7 @@ private:
// returns -1 if allocation failed
S32 allocateCubeIndex();
- // update the neighbors of the given probe
+ // update the neighbors of the given probe
void updateNeighbors(LLReflectionMap* probe);
// update UBO used for rendering (call only once per render pipe flush)
diff --git a/indra/newview/llselectmgr.cpp b/indra/newview/llselectmgr.cpp
index d172a87b1d..c2e3857af0 100644
--- a/indra/newview/llselectmgr.cpp
+++ b/indra/newview/llselectmgr.cpp
@@ -1959,26 +1959,30 @@ bool LLSelectMgr::selectionSetGLTFMaterial(const LLUUID& mat_id)
{
return false;
}
- if (mItem && objectp->isAttachment())
+ LLUUID asset_id = mMatId;
+ if (mItem)
{
const LLPermissions& perm = mItem->getPermissions();
- BOOL unrestricted = ((perm.getMaskBase() & PERM_ITEM_UNRESTRICTED) == PERM_ITEM_UNRESTRICTED) ? TRUE : FALSE;
- if (!unrestricted)
+ bool from_library = perm.getOwner() == ALEXANDRIA_LINDEN_ID;
+ if (objectp->isAttachment())
{
- // Attachments are in world and in inventory simultaneously,
- // at the moment server doesn't support such a situation.
- return false;
+ bool unrestricted = (perm.getMaskBase() & PERM_ITEM_UNRESTRICTED) == PERM_ITEM_UNRESTRICTED;
+
+ if (!unrestricted && !from_library)
+ {
+ // Attachments are in world and in inventory simultaneously,
+ // at the moment server doesn't support such a situation.
+ return false;
+ }
}
- }
- LLUUID asset_id = mMatId;
- if (mItem)
- {
- // If success, the material may be copied into the object's inventory
- BOOL success = LLToolDragAndDrop::handleDropMaterialProtections(objectp, mItem, LLToolDragAndDrop::SOURCE_AGENT, LLUUID::null);
- if (!success)
+
+ if (!from_library
+ // Check if item may be copied into the object's inventory
+ && !LLToolDragAndDrop::handleDropMaterialProtections(objectp, mItem, LLToolDragAndDrop::SOURCE_AGENT, LLUUID::null))
{
return false;
}
+
asset_id = mItem->getAssetUUID();
if (asset_id.isNull())
{
@@ -1994,11 +1998,13 @@ bool LLSelectMgr::selectionSetGLTFMaterial(const LLUUID& mat_id)
};
bool success = true;
- if (item &&
- (!item->getPermissions().allowOperationBy(PERM_COPY, gAgent.getID()) ||
+ if (item
+ && (!item->getPermissions().allowOperationBy(PERM_COPY, gAgent.getID()) ||
!item->getPermissions().allowOperationBy(PERM_TRANSFER, gAgent.getID()) ||
!item->getPermissions().allowOperationBy(PERM_MODIFY, gAgent.getID())
- ))
+ )
+ && item->getPermissions().getOwner() != ALEXANDRIA_LINDEN_ID
+ )
{
success = success && getSelection()->applyRestrictedPbrMaterialToTEs(item);
}
diff --git a/indra/newview/llsettingsvo.cpp b/indra/newview/llsettingsvo.cpp
index 17405ca864..caa3f296dd 100644
--- a/indra/newview/llsettingsvo.cpp
+++ b/indra/newview/llsettingsvo.cpp
@@ -739,7 +739,6 @@ void LLSettingsVOSky::applySpecial(void *ptarget, bool force)
static LLCachedControl<F32> auto_adjust_blue_horizon_scale(gSavedSettings, "RenderSkyAutoAdjustBlueHorizonScale", 1.f);
static LLCachedControl<F32> auto_adjust_blue_density_scale(gSavedSettings, "RenderSkyAutoAdjustBlueDensityScale", 1.f);
static LLCachedControl<F32> auto_adjust_sun_color_scale(gSavedSettings, "RenderSkyAutoAdjustSunColorScale", 1.f);
- static LLCachedControl<F32> auto_adjust_probe_ambiance(gSavedSettings, "RenderSkyAutoAdjustProbeAmbiance", 1.f);
static LLCachedControl<F32> sunlight_scale(gSavedSettings, "RenderSkySunlightScale", 1.5f);
static LLCachedControl<F32> ambient_scale(gSavedSettings, "RenderSkyAmbientScale", 1.5f);
@@ -772,8 +771,7 @@ void LLSettingsVOSky::applySpecial(void *ptarget, bool force)
shader->uniform3fv(LLShaderMgr::BLUE_DENSITY, blue_density.mV);
shader->uniform3fv(LLShaderMgr::BLUE_HORIZON, blue_horizon.mV);
- LLSettingsSky::sAutoAdjustProbeAmbiance = auto_adjust_probe_ambiance;
- probe_ambiance = auto_adjust_probe_ambiance; // NOTE -- must match LLSettingsSky::getReflectionProbeAmbiance value for "auto_adjust" true
+ probe_ambiance = sAutoAdjustProbeAmbiance;
}
else
{
diff --git a/indra/newview/llspatialpartition.cpp b/indra/newview/llspatialpartition.cpp
index 931880a475..40e8e526d1 100644
--- a/indra/newview/llspatialpartition.cpp
+++ b/indra/newview/llspatialpartition.cpp
@@ -47,6 +47,7 @@
#include "pipeline.h"
#include "llmeshrepository.h"
#include "llrender.h"
+#include "lldrawpool.h"
#include "lloctree.h"
#include "llphysicsshapebuilderutil.h"
#include "llvoavatar.h"
@@ -2000,7 +2001,11 @@ void renderBoundingBox(LLDrawable* drawable, BOOL set_color = TRUE)
drawBoxOutline(pos,size);
}
}
-
+// *TODO: LLDrawables which are not part of LLVOVolumes fall into a different
+// code path which uses a shader - it was tested to be faster than mapping a
+// vertex buffer in the terrain case. Consider using it for LLVOVolumes as well
+// to simplify and speed up this debug code. Alternatively, a compute shader is
+// likely faster. -Cosmic,2023-09-28
void renderNormals(LLDrawable *drawablep)
{
if (!drawablep->isVisible())
@@ -2008,11 +2013,13 @@ void renderNormals(LLDrawable *drawablep)
LLVertexBuffer::unbind();
+ LLViewerObject* obj = drawablep->getVObj();
LLVOVolume *vol = drawablep->getVOVolume();
- if (vol)
+ if (obj)
{
- LLVolume *volume = vol->getVolume();
+ LLGLEnable blend(GL_BLEND);
+ LLGLDepthTest gl_depth(GL_TRUE, GL_FALSE);
// Drawable's normals & tangents are stored in model space, i.e. before any scaling is applied.
//
@@ -2021,68 +2028,136 @@ void renderNormals(LLDrawable *drawablep)
// transform. We get that effect here by pre-applying the inverse scale (twice, because
// one forward scale will be re-applied via the MVP in the vertex shader)
- LLVector3 scale_v3 = vol->getScale();
- float scale_len = scale_v3.length();
- LLVector4a obj_scale(scale_v3.mV[VX], scale_v3.mV[VY], scale_v3.mV[VZ]);
- obj_scale.normalize3();
+ LLVector4a inv_scale;
+ float scale_len;
+ if (vol)
+ {
+ LLVector3 scale_v3 = vol->getScale();
+ LLVector4a obj_scale(scale_v3.mV[VX], scale_v3.mV[VY], scale_v3.mV[VZ]);
+ obj_scale.normalize3();
- // Normals &tangent line segments get scaled along with the object. Divide by scale length
- // to keep the as-viewed lengths (relatively) constant with the debug setting length
- float draw_length = gSavedSettings.getF32("RenderDebugNormalScale") / scale_len;
+ // Create inverse-scale vector for normals
+ inv_scale.set(1.0 / scale_v3.mV[VX], 1.0 / scale_v3.mV[VY], 1.0 / scale_v3.mV[VZ], 0.0);
+ inv_scale.mul(inv_scale); // Squared, to apply inverse scale twice
- // Create inverse-scale vector for normals
- LLVector4a inv_scale(1.0 / scale_v3.mV[VX], 1.0 / scale_v3.mV[VY], 1.0 / scale_v3.mV[VZ]);
- inv_scale.mul(inv_scale); // Squared, to apply inverse scale twice
- inv_scale.normalize3fast();
+ inv_scale.normalize3fast();
+ scale_len = scale_v3.length();
+ }
+ else
+ {
+ inv_scale.set(1.0, 1.0, 1.0, 0.0);
+ scale_len = 1.0;
+ }
gGL.pushMatrix();
- gGL.multMatrix((F32 *) vol->getRelativeXform().mMatrix);
+ if (vol)
+ {
+ gGL.multMatrix((F32 *) vol->getRelativeXform().mMatrix);
+ }
gGL.getTexUnit(0)->unbind(LLTexUnit::TT_TEXTURE);
- for (S32 i = 0; i < volume->getNumVolumeFaces(); ++i)
+ // Normals &tangent line segments get scaled along with the object. Divide by scale length
+ // to keep the as-viewed lengths (relatively) constant with the debug setting length
+ float draw_length = gSavedSettings.getF32("RenderDebugNormalScale") / scale_len;
+
+ std::vector<LLVolumeFace>* faces = nullptr;
+ std::vector<LLFace*>* drawable_faces = nullptr;
+ if (vol)
+ {
+ LLVolume* volume = vol->getVolume();
+ faces = &volume->getVolumeFaces();
+ }
+ else
{
- const LLVolumeFace &face = volume->getVolumeFace(i);
+ drawable_faces = &drawablep->getFaces();
+ }
- gGL.flush();
- gGL.diffuseColor4f(1, 1, 0, 1);
- gGL.begin(LLRender::LINES);
- for (S32 j = 0; j < face.mNumVertices; ++j)
- {
- LLVector4a n, p;
+ if (faces)
+ {
+ for (auto it = faces->begin(); it != faces->end(); ++it)
+ {
+ const LLVolumeFace& face = *it;
+
+ gGL.flush();
+ gGL.diffuseColor4f(1, 1, 0, 1);
+ gGL.begin(LLRender::LINES);
+ for (S32 j = 0; j < face.mNumVertices; ++j)
+ {
+ LLVector4a n, p;
- n.setMul(face.mNormals[j], 1.0);
- n.mul(inv_scale); // Pre-scale normal, so it's left with an inverse-transpose xform after MVP
- n.normalize3fast();
- n.mul(draw_length);
- p.setAdd(face.mPositions[j], n);
+ n.setMul(face.mNormals[j], 1.0);
+ n.mul(inv_scale); // Pre-scale normal, so it's left with an inverse-transpose xform after MVP
+ n.normalize3fast();
+ n.mul(draw_length);
+ p.setAdd(face.mPositions[j], n);
- gGL.vertex3fv(face.mPositions[j].getF32ptr());
- gGL.vertex3fv(p.getF32ptr());
- }
- gGL.end();
+ gGL.vertex3fv(face.mPositions[j].getF32ptr());
+ gGL.vertex3fv(p.getF32ptr());
+ }
+ gGL.end();
+
+ // Tangents are simple vectors and do not require reorientation via pre-scaling
+ if (face.mTangents)
+ {
+ gGL.flush();
+ gGL.diffuseColor4f(0, 1, 1, 1);
+ gGL.begin(LLRender::LINES);
+ for (S32 j = 0; j < face.mNumVertices; ++j)
+ {
+ LLVector4a t, p;
- // Tangents are simple vectors and do not require reorientation via pre-scaling
- if (face.mTangents)
+ t.setMul(face.mTangents[j], 1.0f);
+ t.normalize3fast();
+ t.mul(draw_length);
+ p.setAdd(face.mPositions[j], t);
+
+ gGL.vertex3fv(face.mPositions[j].getF32ptr());
+ gGL.vertex3fv(p.getF32ptr());
+ }
+ gGL.end();
+ }
+ }
+ }
+ else if (drawable_faces)
+ {
+ // *HACK: Prepare to restore previous shader as other debug code depends on a simpler shader being present
+ llassert(LLGLSLShader::sCurBoundShaderPtr == &gDebugProgram);
+ LLGLSLShader* prev_shader = LLGLSLShader::sCurBoundShaderPtr;
+ for (auto it = drawable_faces->begin(); it != drawable_faces->end(); ++it)
{
- gGL.flush();
- gGL.diffuseColor4f(0, 1, 1, 1);
- gGL.begin(LLRender::LINES);
- for (S32 j = 0; j < face.mNumVertices; ++j)
+ LLFace* facep = *it;
+ LLFace& face = **it;
+ LLVertexBuffer* buf = face.getVertexBuffer();
+ if (!buf) { continue; }
+ U32 mask_vn = LLVertexBuffer::TYPE_VERTEX | LLVertexBuffer::TYPE_NORMAL;
+ if ((buf->getTypeMask() & mask_vn) != mask_vn) { continue; }
+
+ LLGLSLShader* shader;
+ if ((buf->getTypeMask() & LLVertexBuffer::TYPE_TANGENT) != LLVertexBuffer::TYPE_TANGENT)
{
- LLVector4a t, p;
+ shader = &gNormalDebugProgram[NORMAL_DEBUG_SHADER_DEFAULT];
+ }
+ else
+ {
+ shader = &gNormalDebugProgram[NORMAL_DEBUG_SHADER_WITH_TANGENTS];
+ }
+ shader->bind();
- t.setMul(face.mTangents[j], 1.0f);
- t.normalize3fast();
- t.mul(draw_length);
- p.setAdd(face.mPositions[j], t);
+ shader->uniform1f(LLShaderMgr::DEBUG_NORMAL_DRAW_LENGTH, draw_length);
- gGL.vertex3fv(face.mPositions[j].getF32ptr());
- gGL.vertex3fv(p.getF32ptr());
- }
- gGL.end();
+ LLRenderPass::applyModelMatrix(&facep->getDrawable()->getRegion()->mRenderMatrix);
+
+ buf->setBuffer();
+ // *NOTE: The render type in the vertex shader is TRIANGLES, but gets converted to LINES in the geometry shader
+ // *NOTE: For terrain normal debug, this seems to also include vertices for water, which is technically not part of the terrain. Should fix that at some point.
+ buf->drawRange(LLRender::TRIANGLES, face.getGeomIndex(), face.getGeomIndex() + face.getGeomCount()-1, face.getIndicesCount(), face.getIndicesStart());
}
- }
+ if (prev_shader)
+ {
+ prev_shader->bind();
+ }
+ }
gGL.popMatrix();
}
diff --git a/indra/newview/llstartup.cpp b/indra/newview/llstartup.cpp
index d0b76848f7..8681bf6e2a 100644
--- a/indra/newview/llstartup.cpp
+++ b/indra/newview/llstartup.cpp
@@ -1511,9 +1511,6 @@ bool idle_startup()
gXferManager->registerCallbacks(gMessageSystem);
display_startup();
- LLGLTFMaterialList::registerCallbacks();
- display_startup();
-
LLStartUp::initNameCache();
display_startup();
diff --git a/indra/newview/llsurface.cpp b/indra/newview/llsurface.cpp
index 1418499f8b..804afe6266 100644
--- a/indra/newview/llsurface.cpp
+++ b/indra/newview/llsurface.cpp
@@ -643,17 +643,18 @@ void LLSurface::updatePatchVisibilities(LLAgent &agent)
}
}
-BOOL LLSurface::idleUpdate(F32 max_update_time)
+template<bool PBR>
+bool LLSurface::idleUpdate(F32 max_update_time)
{
if (!gPipeline.hasRenderType(LLPipeline::RENDER_TYPE_TERRAIN))
{
- return FALSE;
+ return false;
}
// Perform idle time update of non-critical stuff.
// In this case, texture and normal updates.
LLTimer update_timer;
- BOOL did_update = FALSE;
+ bool did_update = false;
// If the Z height data has changed, we need to rebuild our
// property line vertex arrays.
@@ -669,13 +670,13 @@ BOOL LLSurface::idleUpdate(F32 max_update_time)
{
std::set<LLSurfacePatch *>::iterator curiter = iter++;
LLSurfacePatch *patchp = *curiter;
- patchp->updateNormals();
+ patchp->updateNormals<PBR>();
patchp->updateVerticalStats();
if (max_update_time == 0.f || update_timer.getElapsedTimeF32() < max_update_time)
{
if (patchp->updateTexture())
{
- did_update = TRUE;
+ did_update = true;
patchp->clearDirty();
mDirtyPatchList.erase(curiter);
}
@@ -691,6 +692,9 @@ BOOL LLSurface::idleUpdate(F32 max_update_time)
return did_update;
}
+template bool LLSurface::idleUpdate</*PBR=*/false>(F32 max_update_time);
+template bool LLSurface::idleUpdate</*PBR=*/true>(F32 max_update_time);
+
void LLSurface::decompressDCTPatch(LLBitPack &bitpack, LLGroupHeader *gopp, BOOL b_large_patch)
{
diff --git a/indra/newview/llsurface.h b/indra/newview/llsurface.h
index 33a64ae7d5..b7b47d2a1c 100644
--- a/indra/newview/llsurface.h
+++ b/indra/newview/llsurface.h
@@ -112,7 +112,8 @@ public:
LLSurfacePatch *resolvePatchGlobal(const LLVector3d &position_global) const;
// Update methods (called during idle, normally)
- BOOL idleUpdate(F32 max_update_time);
+ template<bool PBR>
+ bool idleUpdate(F32 max_update_time);
BOOL containsPosition(const LLVector3 &position);
@@ -224,6 +225,9 @@ private:
static S32 sTextureSize; // Size of the surface texture
};
+extern template bool LLSurface::idleUpdate</*PBR=*/false>(F32 max_update_time);
+extern template bool LLSurface::idleUpdate</*PBR=*/true>(F32 max_update_time);
+
// . __.
diff --git a/indra/newview/llsurfacepatch.cpp b/indra/newview/llsurfacepatch.cpp
index 449d3d95c8..92b1273041 100644
--- a/indra/newview/llsurfacepatch.cpp
+++ b/indra/newview/llsurfacepatch.cpp
@@ -221,7 +221,9 @@ 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);
+ // *NOTE: Only PBR terrain uses the UVs right now. Texture terrain just ignores it.
+ // *NOTE: In the future, UVs and horizontal position will no longer have a 1:1 relationship for PBR terrain
+ LLVector3 tex_pos = rel_pos;
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);
@@ -241,7 +243,8 @@ void LLSurfacePatch::eval(const U32 x, const U32 y, const U32 stride, LLVector3
}
-void LLSurfacePatch::calcNormal(const U32 x, const U32 y, const U32 stride)
+template<>
+void LLSurfacePatch::calcNormal</*PBR=*/false>(const U32 x, const U32 y, const U32 stride)
{
U32 patch_width = mSurfacep->mPVArray.mPatchWidth;
U32 surface_stride = mSurfacep->getGridsPerEdge();
@@ -354,6 +357,166 @@ void LLSurfacePatch::calcNormal(const U32 x, const U32 y, const U32 stride)
*(mDataNorm + surface_stride * y + x) = normal;
}
+template<>
+void LLSurfacePatch::calcNormal</*PBR=*/true>(const U32 x, const U32 y, const U32 stride)
+{
+ llassert(mDataNorm);
+ constexpr U32 index = 0;
+
+ const U32 surface_stride = mSurfacep->getGridsPerEdge();
+ LLVector3& normal_out = *(mDataNorm + surface_stride * y + x);
+ calcNormalFlat(normal_out, x, y, index);
+}
+
+// Calculate the flat normal of a triangle whose least coordinate is specified by the given x,y values.
+// If index = 0, calculate the normal of the first triangle, otherwise calculate the normal of the second.
+void LLSurfacePatch::calcNormalFlat(LLVector3& normal_out, const U32 x, const U32 y, const U32 index)
+{
+ llassert(index == 0 || index == 1);
+
+ U32 patch_width = mSurfacep->mPVArray.mPatchWidth;
+ U32 surface_stride = mSurfacep->getGridsPerEdge();
+
+ // Vertex stride is always 1 because we want the flat surface of the current triangle face
+ constexpr U32 stride = 1;
+
+ const F32 mpg = mSurfacep->getMetersPerGrid() * stride;
+
+ S32 poffsets[2][2][2];
+ poffsets[0][0][0] = x;
+ poffsets[0][0][1] = y;
+
+ poffsets[0][1][0] = x;
+ poffsets[0][1][1] = y + stride;
+
+ poffsets[1][0][0] = x + stride;
+ poffsets[1][0][1] = y;
+
+ poffsets[1][1][0] = x + stride;
+ poffsets[1][1][1] = y + stride;
+
+ const LLSurfacePatch *ppatches[2][2];
+
+ // LLVector3 p1, p2, p3, p4;
+
+ ppatches[0][0] = this;
+ ppatches[0][1] = this;
+ ppatches[1][0] = this;
+ ppatches[1][1] = this;
+
+ U32 i, j;
+ for (i = 0; i < 2; i++)
+ {
+ for (j = 0; j < 2; j++)
+ {
+ if (poffsets[i][j][0] < 0)
+ {
+ if (!ppatches[i][j]->getNeighborPatch(WEST))
+ {
+ poffsets[i][j][0] = 0;
+ }
+ else
+ {
+ poffsets[i][j][0] += patch_width;
+ ppatches[i][j] = ppatches[i][j]->getNeighborPatch(WEST);
+ }
+ }
+ if (poffsets[i][j][1] < 0)
+ {
+ if (!ppatches[i][j]->getNeighborPatch(SOUTH))
+ {
+ poffsets[i][j][1] = 0;
+ }
+ else
+ {
+ poffsets[i][j][1] += patch_width;
+ ppatches[i][j] = ppatches[i][j]->getNeighborPatch(SOUTH);
+ }
+ }
+ if (poffsets[i][j][0] >= (S32)patch_width)
+ {
+ if (!ppatches[i][j]->getNeighborPatch(EAST))
+ {
+ poffsets[i][j][0] = patch_width - 1;
+ }
+ else
+ {
+ poffsets[i][j][0] -= patch_width;
+ ppatches[i][j] = ppatches[i][j]->getNeighborPatch(EAST);
+ }
+ }
+ if (poffsets[i][j][1] >= (S32)patch_width)
+ {
+ if (!ppatches[i][j]->getNeighborPatch(NORTH))
+ {
+ poffsets[i][j][1] = patch_width - 1;
+ }
+ else
+ {
+ poffsets[i][j][1] -= patch_width;
+ ppatches[i][j] = ppatches[i][j]->getNeighborPatch(NORTH);
+ }
+ }
+ }
+ }
+
+ LLVector3 p00(-mpg,-mpg,
+ *(ppatches[0][0]->mDataZ
+ + poffsets[0][0][0]
+ + poffsets[0][0][1]*surface_stride));
+ LLVector3 p01(-mpg,+mpg,
+ *(ppatches[0][1]->mDataZ
+ + poffsets[0][1][0]
+ + poffsets[0][1][1]*surface_stride));
+ LLVector3 p10(+mpg,-mpg,
+ *(ppatches[1][0]->mDataZ
+ + poffsets[1][0][0]
+ + poffsets[1][0][1]*surface_stride));
+ LLVector3 p11(+mpg,+mpg,
+ *(ppatches[1][1]->mDataZ
+ + poffsets[1][1][0]
+ + poffsets[1][1][1]*surface_stride));
+
+ // Triangle index / coordinate convention
+ // for a single surface patch
+ //
+ // p01 p11
+ //
+ // ^ ._____.
+ // | |\ |
+ // | | \ 1 |
+ // | | \ |
+ // | 0 \ |
+ // y |____\|
+ //
+ // p00 x ---> p10
+ //
+ // (z up / out of the screen due to right-handed coordinate system)
+
+ LLVector3 normal;
+ if (index == 0)
+ {
+ LLVector3 c1 = p10 - p00;
+ LLVector3 c2 = p01 - p00;
+
+ normal = c1;
+ normal %= c2;
+ normal.normVec();
+ }
+ else // index == 1
+ {
+ LLVector3 c1 = p11 - p01;
+ LLVector3 c2 = p11 - p10;
+
+ normal = c1;
+ normal %= c2;
+ normal.normVec();
+ }
+
+ llassert(&normal_out);
+ normal_out = normal;
+}
+
const LLVector3 &LLSurfacePatch::getNormal(const U32 x, const U32 y) const
{
U32 surface_stride = mSurfacep->getGridsPerEdge();
@@ -451,6 +614,7 @@ void LLSurfacePatch::updateVerticalStats()
}
+template<bool PBR>
void LLSurfacePatch::updateNormals()
{
if (mSurfacep->mType == 'w')
@@ -468,9 +632,9 @@ void LLSurfacePatch::updateNormals()
{
for (j = 0; j <= grids_per_patch_edge; j++)
{
- calcNormal(grids_per_patch_edge, j, 2);
- calcNormal(grids_per_patch_edge - 1, j, 2);
- calcNormal(grids_per_patch_edge - 2, j, 2);
+ calcNormal<PBR>(grids_per_patch_edge, j, 2);
+ calcNormal<PBR>(grids_per_patch_edge - 1, j, 2);
+ calcNormal<PBR>(grids_per_patch_edge - 2, j, 2);
}
dirty_patch = TRUE;
@@ -481,9 +645,9 @@ void LLSurfacePatch::updateNormals()
{
for (i = 0; i <= grids_per_patch_edge; i++)
{
- calcNormal(i, grids_per_patch_edge, 2);
- calcNormal(i, grids_per_patch_edge - 1, 2);
- calcNormal(i, grids_per_patch_edge - 2, 2);
+ calcNormal<PBR>(i, grids_per_patch_edge, 2);
+ calcNormal<PBR>(i, grids_per_patch_edge - 1, 2);
+ calcNormal<PBR>(i, grids_per_patch_edge - 2, 2);
}
dirty_patch = TRUE;
@@ -494,8 +658,8 @@ void LLSurfacePatch::updateNormals()
{
for (j = 0; j < grids_per_patch_edge; j++)
{
- calcNormal(0, j, 2);
- calcNormal(1, j, 2);
+ calcNormal<PBR>(0, j, 2);
+ calcNormal<PBR>(1, j, 2);
}
dirty_patch = TRUE;
}
@@ -505,8 +669,8 @@ void LLSurfacePatch::updateNormals()
{
for (i = 0; i < grids_per_patch_edge; i++)
{
- calcNormal(i, 0, 2);
- calcNormal(i, 1, 2);
+ calcNormal<PBR>(i, 0, 2);
+ calcNormal<PBR>(i, 1, 2);
}
dirty_patch = TRUE;
}
@@ -582,10 +746,10 @@ void LLSurfacePatch::updateNormals()
// We've got a northeast patch in the same surface.
// The z and normals will be handled by that patch.
}
- calcNormal(grids_per_patch_edge, grids_per_patch_edge, 2);
- calcNormal(grids_per_patch_edge, grids_per_patch_edge - 1, 2);
- calcNormal(grids_per_patch_edge - 1, grids_per_patch_edge, 2);
- calcNormal(grids_per_patch_edge - 1, grids_per_patch_edge - 1, 2);
+ calcNormal<PBR>(grids_per_patch_edge, grids_per_patch_edge, 2);
+ calcNormal<PBR>(grids_per_patch_edge, grids_per_patch_edge - 1, 2);
+ calcNormal<PBR>(grids_per_patch_edge - 1, grids_per_patch_edge, 2);
+ calcNormal<PBR>(grids_per_patch_edge - 1, grids_per_patch_edge - 1, 2);
dirty_patch = TRUE;
}
@@ -596,7 +760,7 @@ void LLSurfacePatch::updateNormals()
{
for (i=2; i < grids_per_patch_edge - 2; i++)
{
- calcNormal(i, j, 2);
+ calcNormal<PBR>(i, j, 2);
}
}
dirty_patch = TRUE;
@@ -613,6 +777,9 @@ void LLSurfacePatch::updateNormals()
}
}
+template void LLSurfacePatch::updateNormals</*PBR=*/false>();
+template void LLSurfacePatch::updateNormals</*PBR=*/true>();
+
void LLSurfacePatch::updateEastEdge()
{
U32 grids_per_patch_edge = mSurfacep->getGridsPerPatchEdge();
@@ -739,7 +906,7 @@ void LLSurfacePatch::updateGL()
updateCompositionStats();
F32 tex_patch_size = meters_per_grid*grids_per_patch_edge;
- if (comp->generateTexture((F32)origin_region[VX], (F32)origin_region[VY],
+ if (comp->generateMinimapTileLand((F32)origin_region[VX], (F32)origin_region[VY],
tex_patch_size, tex_patch_size))
{
mSTexUpdate = FALSE;
diff --git a/indra/newview/llsurfacepatch.h b/indra/newview/llsurfacepatch.h
index 8c8f501dce..ec3864ce44 100644
--- a/indra/newview/llsurfacepatch.h
+++ b/indra/newview/llsurfacepatch.h
@@ -77,6 +77,7 @@ public:
void updateVerticalStats();
void updateCompositionStats();
+ template<bool PBR>
void updateNormals();
void updateEastEdge();
@@ -102,9 +103,18 @@ public:
LLVector3 getPointAgent(const U32 x, const U32 y) const; // get the point at the offset.
LLVector2 getTexCoords(const U32 x, const U32 y) const;
+ // Per-vertex normals
+ // *TODO: PBR=true is a test implementation solely for proof-of-concept.
+ // Final implementation would likely be very different and may not even use
+ // this function. If we decide to keep calcNormalFlat, remove index as it
+ // is a debug parameter for testing.
+ template<bool PBR>
void calcNormal(const U32 x, const U32 y, const U32 stride);
const LLVector3 &getNormal(const U32 x, const U32 y) const;
+ // Per-triangle normals for flat edges
+ void calcNormalFlat(LLVector3& normal_out, const U32 x, const U32 y, const U32 index /* 0 or 1 */);
+
void eval(const U32 x, const U32 y, const U32 stride,
LLVector3 *vertex, LLVector3 *normal, LLVector2 *tex0, LLVector2 *tex1);
@@ -181,5 +191,8 @@ protected:
LLSurface *mSurfacep; // Pointer to "parent" surface
};
+extern template void LLSurfacePatch::updateNormals</*PBR=*/false>();
+extern template void LLSurfacePatch::updateNormals</*PBR=*/true>();
+
#endif // LL_LLSURFACEPATCH_H
diff --git a/indra/newview/lltexturectrl.cpp b/indra/newview/lltexturectrl.cpp
index 28e01c6c21..0439b0b115 100644
--- a/indra/newview/lltexturectrl.cpp
+++ b/indra/newview/lltexturectrl.cpp
@@ -72,6 +72,7 @@
#include "llradiogroup.h"
#include "llfloaterreg.h"
+#include "llgltfmaterialpreviewmgr.h"
#include "lllocalbitmaps.h"
#include "lllocalgltfmaterials.h"
#include "llerror.h"
@@ -82,9 +83,11 @@
//static
bool get_is_predefined_texture(LLUUID asset_id)
{
- if (asset_id == LLUUID(gSavedSettings.getString("DefaultObjectTexture"))
- || asset_id == LLUUID(gSavedSettings.getString("UIImgWhiteUUID"))
- || asset_id == LLUUID(gSavedSettings.getString("UIImgInvisibleUUID"))
+ if (asset_id == DEFAULT_OBJECT_TEXTURE
+ || asset_id == DEFAULT_OBJECT_SPECULAR
+ || asset_id == DEFAULT_OBJECT_NORMAL
+ || asset_id == BLANK_OBJECT_NORMAL
+ || asset_id == IMG_WHITE
|| asset_id == LLUUID(SCULPT_DEFAULT_TEXTURE))
{
return true;
@@ -151,7 +154,8 @@ LLFloaterTexturePicker::LLFloaterTexturePicker(
PermissionMask immediate_filter_perm_mask,
PermissionMask dnd_filter_perm_mask,
BOOL can_apply_immediately,
- LLUIImagePtr fallback_image)
+ LLUIImagePtr fallback_image,
+ EPickInventoryType pick_type)
: LLFloater(LLSD()),
mOwner( owner ),
mImageAssetID( image_asset_id ),
@@ -181,7 +185,7 @@ LLFloaterTexturePicker::LLFloaterTexturePicker(
mSetImageAssetIDCallback(NULL),
mOnUpdateImageStatsCallback(NULL),
mBakeTextureEnabled(FALSE),
- mInventoryPickType(LLTextureCtrl::PICK_TEXTURE)
+ mInventoryPickType(pick_type)
{
mCanApplyImmediately = can_apply_immediately;
buildFromFile("floater_texture_ctrl.xml");
@@ -225,7 +229,7 @@ void LLFloaterTexturePicker::setImageID(const LLUUID& image_id, bool set_selecti
LLInventoryItem* itemp = gInventory.getItem(inv_view->getUUID());
- if (mInventoryPickType == LLTextureCtrl::PICK_MATERIAL
+ if (mInventoryPickType == PICK_MATERIAL
&& mImageAssetID == LLGLTFMaterialList::BLANK_MATERIAL_ASSET_ID
&& itemp && itemp->getAssetUUID().isNull())
{
@@ -266,7 +270,7 @@ void LLFloaterTexturePicker::setImageID(const LLUUID& image_id, bool set_selecti
void LLFloaterTexturePicker::setImageIDFromItem(const LLInventoryItem* itemp, bool set_selection)
{
LLUUID asset_id = itemp->getAssetUUID();
- if (mInventoryPickType == LLTextureCtrl::PICK_MATERIAL && asset_id.isNull())
+ if (mInventoryPickType == PICK_MATERIAL && asset_id.isNull())
{
// If an inventory item has a null asset, consider it a valid blank material(gltf)
asset_id = LLGLTFMaterialList::BLANK_MATERIAL_ASSET_ID;
@@ -425,11 +429,11 @@ BOOL LLFloaterTexturePicker::handleDragAndDrop(
bool is_material = cargo_type == DAD_MATERIAL;
bool allow_dnd = false;
- if (mInventoryPickType == LLTextureCtrl::PICK_MATERIAL)
+ if (mInventoryPickType == PICK_MATERIAL)
{
allow_dnd = is_material;
}
- else if (mInventoryPickType == LLTextureCtrl::PICK_TEXTURE)
+ else if (mInventoryPickType == PICK_TEXTURE)
{
allow_dnd = is_texture || is_mesh;
}
@@ -602,9 +606,7 @@ BOOL LLFloaterTexturePicker::postBuild()
// don't put keyboard focus on selected item, because the selection callback
// will assume that this was user input
-
-
- if(!mImageAssetID.isNull())
+ if(!mImageAssetID.isNull() || mInventoryPickType == PICK_MATERIAL)
{
mInventoryPanel->setSelection(findItemID(mImageAssetID, FALSE), TAKE_FOCUS_NO);
}
@@ -658,17 +660,31 @@ void LLFloaterTexturePicker::draw()
if( mOwner )
{
mTexturep = NULL;
+ LLPointer<LLFetchedGLTFMaterial> old_material = mGLTFMaterial;
mGLTFMaterial = NULL;
if (mImageAssetID.notNull())
{
- if (mInventoryPickType == LLTextureCtrl::PICK_MATERIAL)
+ if (mInventoryPickType == PICK_MATERIAL)
{
mGLTFMaterial = (LLFetchedGLTFMaterial*) gGLTFMaterialList.getMaterial(mImageAssetID);
llassert(mGLTFMaterial == nullptr || dynamic_cast<LLFetchedGLTFMaterial*>(gGLTFMaterialList.getMaterial(mImageAssetID)) != nullptr);
+ if (mGLTFPreview.isNull() || mGLTFMaterial.isNull() || (old_material.notNull() && (old_material.get() != mGLTFMaterial.get())))
+ {
+ // Only update the preview if needed, since gGLTFMaterialPreviewMgr does not cache the preview.
+ if (mGLTFMaterial.isNull())
+ {
+ mGLTFPreview = nullptr;
+ }
+ else
+ {
+ mGLTFPreview = gGLTFMaterialPreviewMgr.getPreview(mGLTFMaterial);
+ }
+ }
}
else
{
LLPointer<LLViewerFetchedTexture> texture = NULL;
+ mGLTFPreview = nullptr;
if (LLAvatarAppearanceDefines::LLAvatarAppearanceDictionary::isBakedImageId(mImageAssetID))
{
@@ -678,7 +694,7 @@ void LLFloaterTexturePicker::draw()
if (obj)
{
LLViewerTexture* viewerTexture = obj->getBakedTextureForMagicId(mImageAssetID);
- texture = viewerTexture ? dynamic_cast<LLViewerFetchedTexture*>(viewerTexture) : NULL;
+ texture = viewerTexture ? dynamic_cast<LLViewerFetchedTexture*>(viewerTexture) : NULL;
}
}
@@ -719,27 +735,29 @@ void LLFloaterTexturePicker::draw()
// If the floater is focused, don't apply its alpha to the texture (STORM-677).
const F32 alpha = getTransparencyType() == TT_ACTIVE ? 1.0f : getCurrentTransparency();
- LLViewerTexture* texture = nullptr;
+ LLViewerTexture* preview = nullptr;
if (mGLTFMaterial)
{
- texture = mGLTFMaterial->getUITexture();
+ preview = mGLTFPreview.get();
}
else
{
- texture = mTexturep.get();
+ preview = mTexturep.get();
+ if (mTexturep)
+ {
+ // Pump the priority
+ mTexturep->addTextureStats( (F32)(interior.getWidth() * interior.getHeight()) );
+ }
}
- if( texture )
+ if( preview )
{
- if( texture->getComponents() == 4 )
+ if( preview->getComponents() == 4 )
{
gl_rect_2d_checkerboard( interior, alpha );
}
- gl_draw_scaled_image( interior.mLeft, interior.mBottom, interior.getWidth(), interior.getHeight(), texture, UI_VERTEX_COLOR % alpha );
-
- // Pump the priority
- texture->addTextureStats( (F32)(interior.getWidth() * interior.getHeight()) );
+ gl_draw_scaled_image( interior.mLeft, interior.mBottom, interior.getWidth(), interior.getHeight(), preview, UI_VERTEX_COLOR % alpha );
}
else if (!mFallbackImage.isNull())
{
@@ -786,27 +804,43 @@ void LLFloaterTexturePicker::draw()
const LLUUID& LLFloaterTexturePicker::findItemID(const LLUUID& asset_id, BOOL copyable_only, BOOL ignore_library)
{
- LLUUID loockup_id = asset_id;
- if (loockup_id.isNull())
+ if (asset_id.isNull())
{
- if (mInventoryPickType == LLTextureCtrl::PICK_MATERIAL)
- {
- loockup_id = LLGLTFMaterialList::BLANK_MATERIAL_ASSET_ID;
- }
- else
- {
- return LLUUID::null;
- }
+ // null asset id means, no material or texture assigned
+ return LLUUID::null;
}
+ LLUUID loockup_id = asset_id;
+ if (mInventoryPickType == PICK_MATERIAL && loockup_id == LLGLTFMaterialList::BLANK_MATERIAL_ASSET_ID)
+ {
+ // default asset id means we are looking for an inventory item with a default asset UUID (null)
+ loockup_id = LLUUID::null;
+ }
+
LLViewerInventoryCategory::cat_array_t cats;
LLViewerInventoryItem::item_array_t items;
- LLAssetIDMatches asset_id_matches(loockup_id);
- gInventory.collectDescendentsIf(LLUUID::null,
- cats,
- items,
- LLInventoryModel::INCLUDE_TRASH,
- asset_id_matches);
+
+ if (loockup_id.isNull())
+ {
+ // looking for a material with a null id, null id is shared by a lot
+ // of objects as a default value, so have to filter by type as well
+ LLAssetIDAndTypeMatches matches(loockup_id, LLAssetType::AT_MATERIAL);
+ gInventory.collectDescendentsIf(LLUUID::null,
+ cats,
+ items,
+ LLInventoryModel::INCLUDE_TRASH,
+ matches);
+ }
+ else
+ {
+ LLAssetIDMatches asset_id_matches(loockup_id);
+ gInventory.collectDescendentsIf(LLUUID::null,
+ cats,
+ items,
+ LLInventoryModel::INCLUDE_TRASH,
+ asset_id_matches);
+ }
+
if (items.size())
{
@@ -871,7 +905,7 @@ void LLFloaterTexturePicker::commitCallback(LLTextureCtrl::ETexturePickOp op)
LLInventoryItem* itemp = gInventory.getItem(inv_view->getUUID());
- if (mInventoryPickType == LLTextureCtrl::PICK_MATERIAL
+ if (mInventoryPickType == PICK_MATERIAL
&& mImageAssetID == LLGLTFMaterialList::BLANK_MATERIAL_ASSET_ID
&& itemp && itemp->getAssetUUID().isNull())
{
@@ -1064,15 +1098,15 @@ void LLFloaterTexturePicker::onBtnAdd(void* userdata)
{
LLFloaterTexturePicker* self = (LLFloaterTexturePicker*)userdata;
- if (self->mInventoryPickType == LLTextureCtrl::PICK_TEXTURE_MATERIAL)
+ if (self->mInventoryPickType == PICK_TEXTURE_MATERIAL)
{
LLFilePickerReplyThread::startPicker(boost::bind(&onPickerCallback, _1, self->getHandle()), LLFilePicker::FFLOAD_MATERIAL_TEXTURE, true);
}
- else if (self->mInventoryPickType == LLTextureCtrl::PICK_TEXTURE)
+ else if (self->mInventoryPickType == PICK_TEXTURE)
{
LLFilePickerReplyThread::startPicker(boost::bind(&onPickerCallback, _1, self->getHandle()), LLFilePicker::FFLOAD_IMAGE, true);
}
- else if (self->mInventoryPickType == LLTextureCtrl::PICK_MATERIAL)
+ else if (self->mInventoryPickType == PICK_MATERIAL)
{
LLFilePickerReplyThread::startPicker(boost::bind(&onPickerCallback, _1, self->getHandle()), LLFilePicker::FFLOAD_MATERIAL, true);
}
@@ -1351,7 +1385,7 @@ void LLFloaterTexturePicker::changeMode()
getChild<LLCheckBoxCtrl>("hide_base_mesh_region")->setVisible(FALSE);// index == 2 ? TRUE : FALSE);
bool pipette_visible = (index == PICKER_INVENTORY)
- && (mInventoryPickType != LLTextureCtrl::PICK_MATERIAL);
+ && (mInventoryPickType != PICK_MATERIAL);
mPipetteBtn->setVisible(pipette_visible);
if (index == PICKER_BAKE)
@@ -1414,16 +1448,16 @@ void LLFloaterTexturePicker::refreshLocalList()
{
mLocalScrollCtrl->clearRows();
- if (mInventoryPickType == LLTextureCtrl::PICK_TEXTURE_MATERIAL)
+ if (mInventoryPickType == PICK_TEXTURE_MATERIAL)
{
LLLocalBitmapMgr::getInstance()->feedScrollList(mLocalScrollCtrl);
LLLocalGLTFMaterialMgr::getInstance()->feedScrollList(mLocalScrollCtrl);
}
- else if (mInventoryPickType == LLTextureCtrl::PICK_TEXTURE)
+ else if (mInventoryPickType == PICK_TEXTURE)
{
LLLocalBitmapMgr::getInstance()->feedScrollList(mLocalScrollCtrl);
}
- else if (mInventoryPickType == LLTextureCtrl::PICK_MATERIAL)
+ else if (mInventoryPickType == PICK_MATERIAL)
{
LLLocalGLTFMaterialMgr::getInstance()->feedScrollList(mLocalScrollCtrl);
}
@@ -1433,18 +1467,18 @@ void LLFloaterTexturePicker::refreshInventoryFilter()
{
U32 filter_types = 0x0;
- if (mInventoryPickType == LLTextureCtrl::PICK_TEXTURE_MATERIAL)
+ if (mInventoryPickType == PICK_TEXTURE_MATERIAL)
{
filter_types |= 0x1 << LLInventoryType::IT_TEXTURE;
filter_types |= 0x1 << LLInventoryType::IT_SNAPSHOT;
filter_types |= 0x1 << LLInventoryType::IT_MATERIAL;
}
- else if (mInventoryPickType == LLTextureCtrl::PICK_TEXTURE)
+ else if (mInventoryPickType == PICK_TEXTURE)
{
filter_types |= 0x1 << LLInventoryType::IT_TEXTURE;
filter_types |= 0x1 << LLInventoryType::IT_SNAPSHOT;
}
- else if (mInventoryPickType == LLTextureCtrl::PICK_MATERIAL)
+ else if (mInventoryPickType == PICK_MATERIAL)
{
filter_types |= 0x1 << LLInventoryType::IT_MATERIAL;
}
@@ -1479,13 +1513,13 @@ void LLFloaterTexturePicker::setBakeTextureEnabled(BOOL enabled)
onModeSelect(0, this);
}
-void LLFloaterTexturePicker::setInventoryPickType(LLTextureCtrl::EPickInventoryType type)
+void LLFloaterTexturePicker::setInventoryPickType(EPickInventoryType type)
{
mInventoryPickType = type;
refreshLocalList();
refreshInventoryFilter();
- if (mInventoryPickType == LLTextureCtrl::PICK_MATERIAL)
+ if (mInventoryPickType == PICK_MATERIAL)
{
getChild<LLButton>("Pipette")->setVisible(false);
}
@@ -1501,7 +1535,7 @@ void LLFloaterTexturePicker::setInventoryPickType(LLTextureCtrl::EPickInventoryT
setTitle(pick + mLabel);
}
- else if(mInventoryPickType == LLTextureCtrl::PICK_MATERIAL)
+ else if(mInventoryPickType == PICK_MATERIAL)
{
setTitle(getString("pick_material"));
}
@@ -1509,6 +1543,12 @@ void LLFloaterTexturePicker::setInventoryPickType(LLTextureCtrl::EPickInventoryT
{
setTitle(getString("pick_texture"));
}
+
+ // refresh selection
+ if (!mImageAssetID.isNull() || mInventoryPickType == PICK_MATERIAL)
+ {
+ mInventoryPanel->setSelection(findItemID(mImageAssetID, FALSE), TAKE_FOCUS_NO);
+ }
}
void LLFloaterTexturePicker::setImmediateFilterPermMask(PermissionMask mask)
@@ -1543,16 +1583,16 @@ void LLFloaterTexturePicker::onPickerCallback(const std::vector<std::string>& fi
LLFloaterTexturePicker* self = (LLFloaterTexturePicker*)handle.get();
self->mLocalScrollCtrl->clearRows();
- if (self->mInventoryPickType == LLTextureCtrl::PICK_TEXTURE_MATERIAL)
+ if (self->mInventoryPickType == PICK_TEXTURE_MATERIAL)
{
LLLocalBitmapMgr::getInstance()->feedScrollList(self->mLocalScrollCtrl);
LLLocalGLTFMaterialMgr::getInstance()->feedScrollList(self->mLocalScrollCtrl);
}
- else if (self->mInventoryPickType == LLTextureCtrl::PICK_TEXTURE)
+ else if (self->mInventoryPickType == PICK_TEXTURE)
{
LLLocalBitmapMgr::getInstance()->feedScrollList(self->mLocalScrollCtrl);
}
- else if (self->mInventoryPickType == LLTextureCtrl::PICK_MATERIAL)
+ else if (self->mInventoryPickType == PICK_MATERIAL)
{
LLLocalGLTFMaterialMgr::getInstance()->feedScrollList(self->mLocalScrollCtrl);
}
@@ -1565,7 +1605,7 @@ void LLFloaterTexturePicker::onTextureSelect( const LLTextureEntry& te )
if (inventory_item_id.notNull())
{
LLToolPipette::getInstance()->setResult(TRUE, "");
- if (mInventoryPickType == LLTextureCtrl::PICK_MATERIAL)
+ if (mInventoryPickType == PICK_MATERIAL)
{
// tes have no data about material ids
// Plus gltf materials are layered with overrides,
@@ -1616,7 +1656,7 @@ LLTextureCtrl::LLTextureCtrl(const LLTextureCtrl::Params& p)
mShowLoadingPlaceholder( TRUE ),
mOpenTexPreview(false),
mBakeTextureEnabled(true),
- mInventoryPickType(PICK_TEXTURE),
+ mInventoryPickType(p.pick_type),
mImageAssetID(p.image_id),
mDefaultImageAssetID(p.default_image_id),
mDefaultImageName(p.default_image_name),
@@ -1625,8 +1665,7 @@ LLTextureCtrl::LLTextureCtrl(const LLTextureCtrl::Params& p)
// Default of defaults is white image for diff tex
//
- LLUUID whiteImage( gSavedSettings.getString( "UIImgWhiteUUID" ) );
- setBlankImageAssetID( whiteImage );
+ setBlankImageAssetID(IMG_WHITE);
setAllowNoTexture(p.allow_no_texture);
setCanApplyImmediately(p.can_apply_immediately);
@@ -1807,7 +1846,8 @@ void LLTextureCtrl::showPicker(BOOL take_focus)
mImmediateFilterPermMask,
mDnDFilterPermMask,
mCanApplyImmediately,
- mFallbackImage);
+ mFallbackImage,
+ mInventoryPickType);
mFloaterHandle = floaterp->getHandle();
LLFloaterTexturePicker* texture_floaterp = dynamic_cast<LLFloaterTexturePicker*>(floaterp);
@@ -1828,7 +1868,6 @@ void LLTextureCtrl::showPicker(BOOL take_focus)
texture_floaterp->setSetImageAssetIDCallback(boost::bind(&LLTextureCtrl::setImageAssetID, this, _1));
texture_floaterp->setBakeTextureEnabled(mBakeTextureEnabled);
- texture_floaterp->setInventoryPickType(mInventoryPickType);
}
LLFloater* root_floater = gFloaterView->getParentFloater(this);
@@ -1891,7 +1930,7 @@ BOOL LLTextureCtrl::handleMouseDown(S32 x, S32 y, MASK mask)
if (!mOpenTexPreview)
{
showPicker(FALSE);
- if (mInventoryPickType == LLTextureCtrl::PICK_MATERIAL)
+ if (mInventoryPickType == PICK_MATERIAL)
{
//grab materials first...
LLInventoryModelBackgroundFetch::instance().start(gInventory.findCategoryUUIDForType(LLFolderType::FT_MATERIAL));
@@ -2089,11 +2128,11 @@ BOOL LLTextureCtrl::handleDragAndDrop(S32 x, S32 y, MASK mask,
bool is_material = cargo_type == DAD_MATERIAL;
bool allow_dnd = false;
- if (mInventoryPickType == LLTextureCtrl::PICK_MATERIAL)
+ if (mInventoryPickType == PICK_MATERIAL)
{
allow_dnd = is_material;
}
- else if (mInventoryPickType == LLTextureCtrl::PICK_TEXTURE)
+ else if (mInventoryPickType == PICK_TEXTURE)
{
allow_dnd = is_texture || is_mesh;
}
@@ -2135,48 +2174,69 @@ void LLTextureCtrl::draw()
{
mBorder->setKeyboardFocusHighlight(hasFocus());
+ LLPointer<LLViewerTexture> preview = NULL;
+
if (!mValid)
{
mTexturep = NULL;
+ mGLTFMaterial = NULL;
+ mGLTFPreview = NULL;
}
else if (!mImageAssetID.isNull())
{
- LLPointer<LLViewerFetchedTexture> texture = NULL;
-
if (LLAvatarAppearanceDefines::LLAvatarAppearanceDictionary::isBakedImageId(mImageAssetID))
{
LLViewerObject* obj = LLSelectMgr::getInstance()->getSelection()->getFirstObject();
if (obj)
{
LLViewerTexture* viewerTexture = obj->getBakedTextureForMagicId(mImageAssetID);
- texture = viewerTexture ? dynamic_cast<LLViewerFetchedTexture*>(viewerTexture) : NULL;
+ mTexturep = viewerTexture ? dynamic_cast<LLViewerFetchedTexture*>(viewerTexture) : NULL;
+ mGLTFMaterial = NULL;
+ mGLTFPreview = NULL;
+
+ preview = mTexturep;
}
}
- if (texture.isNull())
+ if (preview.isNull())
{
- if (mInventoryPickType == LLTextureCtrl::PICK_MATERIAL)
+ LLPointer<LLFetchedGLTFMaterial> old_material = mGLTFMaterial;
+ mGLTFMaterial = NULL;
+ mTexturep = NULL;
+ if (mInventoryPickType == PICK_MATERIAL)
{
- LLPointer<LLFetchedGLTFMaterial> material = gGLTFMaterialList.getMaterial(mImageAssetID);
- if (material)
+ mGLTFMaterial = gGLTFMaterialList.getMaterial(mImageAssetID);
+ if (mGLTFPreview.isNull() || mGLTFMaterial.isNull() || (old_material.notNull() && (old_material.get() != mGLTFMaterial.get())))
{
- texture = material->getUITexture();
+ // Only update the preview if needed, since gGLTFMaterialPreviewMgr does not cache the preview.
+ if (mGLTFMaterial.isNull())
+ {
+ mGLTFPreview = nullptr;
+ }
+ else
+ {
+ mGLTFPreview = gGLTFMaterialPreviewMgr.getPreview(mGLTFMaterial);
+ }
}
+
+ preview = mGLTFPreview;
}
else
{
- texture = LLViewerTextureManager::getFetchedTexture(mImageAssetID, FTT_DEFAULT, TRUE, LLGLTexture::BOOST_NONE, LLViewerTexture::LOD_TEXTURE);
- texture->setBoostLevel(LLGLTexture::BOOST_PREVIEW);
- texture->forceToSaveRawImage(0);
+ mTexturep = LLViewerTextureManager::getFetchedTexture(mImageAssetID, FTT_DEFAULT, TRUE, LLGLTexture::BOOST_NONE, LLViewerTexture::LOD_TEXTURE);
+ mTexturep->setBoostLevel(LLGLTexture::BOOST_PREVIEW);
+ mTexturep->forceToSaveRawImage(0);
+
+ preview = mTexturep;
}
}
-
- mTexturep = texture;
}
else//mImageAssetID == LLUUID::null
{
mTexturep = NULL;
+ mGLTFMaterial = NULL;
+ mGLTFPreview = NULL;
}
// Border
@@ -2189,15 +2249,18 @@ void LLTextureCtrl::draw()
// If we're in a focused floater, don't apply the floater's alpha to the texture (STORM-677).
const F32 alpha = getTransparencyType() == TT_ACTIVE ? 1.0f : getCurrentTransparency();
- if( mTexturep )
+ if( preview )
{
- if( mTexturep->getComponents() == 4 )
+ if( preview->getComponents() == 4 )
{
gl_rect_2d_checkerboard( interior, alpha );
}
- gl_draw_scaled_image( interior.mLeft, interior.mBottom, interior.getWidth(), interior.getHeight(), mTexturep, UI_VERTEX_COLOR % alpha);
- mTexturep->addTextureStats( (F32)(interior.getWidth() * interior.getHeight()) );
+ gl_draw_scaled_image( interior.mLeft, interior.mBottom, interior.getWidth(), interior.getHeight(), preview, UI_VERTEX_COLOR % alpha);
+ if (mTexturep)
+ {
+ mTexturep->addTextureStats( (F32)(interior.getWidth() * interior.getHeight()) );
+ }
}
else if (!mFallbackImage.isNull())
{
@@ -2313,7 +2376,7 @@ BOOL LLTextureCtrl::doDrop(LLInventoryItem* item)
// no callback installed, so just set the image ids and carry on.
LLUUID asset_id = item->getAssetUUID();
- if (mInventoryPickType == LLTextureCtrl::PICK_MATERIAL && asset_id.isNull())
+ if (mInventoryPickType == PICK_MATERIAL && asset_id.isNull())
{
// If an inventory material has a null asset, consider it a valid blank material(gltf)
asset_id = LLGLTFMaterialList::BLANK_MATERIAL_ASSET_ID;
@@ -2344,6 +2407,16 @@ LLSD LLTextureCtrl::getValue() const
return LLSD(getImageAssetID());
}
+namespace LLInitParam
+{
+ void TypeValues<EPickInventoryType>::declareValues()
+ {
+ declare("texture_material", PICK_TEXTURE_MATERIAL);
+ declare("texture", PICK_TEXTURE);
+ declare("material", PICK_MATERIAL);
+ }
+}
+
diff --git a/indra/newview/lltexturectrl.h b/indra/newview/lltexturectrl.h
index 7a96eea60d..05ea185b1b 100644
--- a/indra/newview/lltexturectrl.h
+++ b/indra/newview/lltexturectrl.h
@@ -64,6 +64,23 @@ bool get_is_predefined_texture(LLUUID asset_id);
LLUUID get_copy_free_item_by_asset_id(LLUUID image_id, bool no_trans_perm = false);
bool get_can_copy_texture(LLUUID image_id);
+
+typedef enum e_pick_inventory_type
+{
+ PICK_TEXTURE_MATERIAL = 0,
+ PICK_TEXTURE = 1,
+ PICK_MATERIAL = 2,
+} EPickInventoryType;
+
+namespace LLInitParam
+{
+ template<>
+ struct TypeValues<EPickInventoryType> : public TypeValuesHelper<EPickInventoryType>
+ {
+ static void declareValues();
+ };
+}
+
enum LLPickerSource
{
PICKER_INVENTORY,
@@ -87,19 +104,13 @@ public:
TEXTURE_CANCEL
} ETexturePickOp;
- typedef enum e_pick_inventory_type
- {
- PICK_TEXTURE_MATERIAL = 0,
- PICK_TEXTURE = 1,
- PICK_MATERIAL = 2,
- } EPickInventoryType;
-
public:
struct Params : public LLInitParam::Block<Params, LLUICtrl::Params>
{
Optional<LLUUID> image_id;
Optional<LLUUID> default_image_id;
Optional<std::string> default_image_name;
+ Optional<EPickInventoryType> pick_type;
Optional<bool> allow_no_texture;
Optional<bool> can_apply_immediately;
Optional<bool> no_commit_on_selection; // alternative mode: commit occurs and the widget gets dirty
@@ -117,6 +128,7 @@ public:
: image_id("image"),
default_image_id("default_image_id"),
default_image_name("default_image_name"),
+ pick_type("pick_type", PICK_TEXTURE),
allow_no_texture("allow_no_texture", false),
can_apply_immediately("can_apply_immediately"),
no_commit_on_selection("no_commit_on_selection", false),
@@ -250,6 +262,8 @@ private:
commit_callback_t mOnCloseCallback;
texture_selected_callback mOnTextureSelectedCallback;
LLPointer<LLViewerFetchedTexture> mTexturep;
+ LLPointer<LLFetchedGLTFMaterial> mGLTFMaterial;
+ LLPointer<LLViewerTexture> mGLTFPreview;
LLUIColor mBorderColor;
LLUUID mImageItemID;
LLUUID mImageAssetID;
@@ -276,7 +290,7 @@ private:
S32 mLabelWidth;
bool mOpenTexPreview;
bool mBakeTextureEnabled;
- LLTextureCtrl::EPickInventoryType mInventoryPickType;
+ EPickInventoryType mInventoryPickType;
};
//////////////////////////////////////////////////////////////////////////////////////////
@@ -300,8 +314,8 @@ public:
PermissionMask immediate_filter_perm_mask,
PermissionMask dnd_filter_perm_mask,
BOOL can_apply_immediately,
- LLUIImagePtr fallback_image_name
- );
+ LLUIImagePtr fallback_image_name,
+ EPickInventoryType pick_type);
virtual ~LLFloaterTexturePicker();
@@ -369,7 +383,7 @@ public:
void setLocalTextureEnabled(BOOL enabled);
void setBakeTextureEnabled(BOOL enabled);
- void setInventoryPickType(LLTextureCtrl::EPickInventoryType type);
+ void setInventoryPickType(EPickInventoryType type);
void setImmediateFilterPermMask(PermissionMask mask);
static void onPickerCallback(const std::vector<std::string>& filenames, LLHandle<LLFloater> handle);
@@ -382,6 +396,7 @@ protected:
LLPointer<LLViewerTexture> mTexturep;
LLPointer<LLFetchedGLTFMaterial> mGLTFMaterial;
+ LLPointer<LLViewerTexture> mGLTFPreview;
LLView* mOwner;
LLUUID mImageAssetID; // Currently selected texture
@@ -428,7 +443,7 @@ private:
bool mLimitsSet;
S32 mMaxDim;
S32 mMinDim;
- LLTextureCtrl::EPickInventoryType mInventoryPickType;
+ EPickInventoryType mInventoryPickType;
texture_selected_callback mTextureSelectedCallback;
diff --git a/indra/newview/lltinygltfhelper.cpp b/indra/newview/lltinygltfhelper.cpp
index 999be07dba..5b75db37d0 100644
--- a/indra/newview/lltinygltfhelper.cpp
+++ b/indra/newview/lltinygltfhelper.cpp
@@ -178,6 +178,7 @@ LLImageRaw * LLTinyGLTFHelper::getTexture(const std::string & folder, const tiny
{
rawImage = new LLImageRaw(&image->image[0], image->width, image->height, image->component);
rawImage->verticalFlip();
+ rawImage->optimizeAwayAlpha();
}
return rawImage;
diff --git a/indra/newview/llviewercontrol.cpp b/indra/newview/llviewercontrol.cpp
index 7738cb904e..ba1add9b92 100644
--- a/indra/newview/llviewercontrol.cpp
+++ b/indra/newview/llviewercontrol.cpp
@@ -54,6 +54,7 @@
#include "llvotree.h"
#include "llvovolume.h"
#include "llworld.h"
+#include "llvlcomposition.h"
#include "pipeline.h"
#include "llviewerjoystick.h"
#include "llviewerobjectlist.h"
@@ -117,12 +118,25 @@ static bool handleRenderFarClipChanged(const LLSD& newvalue)
return false;
}
-static bool handleTerrainDetailChanged(const LLSD& newvalue)
+static bool handleTerrainScaleChanged(const LLSD& newvalue)
{
- LLDrawPoolTerrain::sDetailMode = newvalue.asInteger();
+ F64 scale = newvalue.asReal();
+ if (scale != 0.0)
+ {
+ LLDrawPoolTerrain::sDetailScale = F32(1.0 / scale);
+ }
return true;
}
+static bool handlePBRTerrainScaleChanged(const LLSD& newvalue)
+{
+ F64 scale = newvalue.asReal();
+ if (scale != 0.0)
+ {
+ LLDrawPoolTerrain::sPBRDetailScale = F32(1.0 / scale);
+ }
+ return true;
+}
static bool handleDebugAvatarJointsChanged(const LLSD& newvalue)
{
@@ -650,6 +664,16 @@ void handleFPSTuningStrategyChanged(const LLSD& newValue)
const auto newval = gSavedSettings.getU32("TuningFPSStrategy");
LLPerfStats::tunables.userFPSTuningStrategy = newval;
}
+
+void handleLocalTerrainChanged(const LLSD& newValue)
+{
+ for (U32 i = 0; i < LLTerrainMaterials::ASSET_COUNT; ++i)
+ {
+ const auto setting = gSavedSettings.getString(std::string("LocalTerrainAsset") + std::to_string(i + 1));
+ const LLUUID materialID(setting);
+ gLocalTerrainMaterials.setDetailAssetID(i, materialID);
+ }
+}
////////////////////////////////////////////////////////////////////////////
LLPointer<LLControlVariable> setting_get_control(LLControlGroup& group, const std::string& setting)
@@ -684,7 +708,11 @@ 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, "RenderTerrainPBRScale", handlePBRTerrainScaleChanged);
+ setting_setup_signal_listener(gSavedSettings, "RenderTerrainPBRDetail", handleSetShaderChanged);
+ setting_setup_signal_listener(gSavedSettings, "RenderTerrainPBRPlanarSampleCount", handleSetShaderChanged);
+ setting_setup_signal_listener(gSavedSettings, "RenderTerrainPBRTriplanarBlendFactor", handleSetShaderChanged);
setting_setup_signal_listener(gSavedSettings, "OctreeStaticObjectSizeFactor", handleRepartition);
setting_setup_signal_listener(gSavedSettings, "OctreeDistanceFactor", handleRepartition);
setting_setup_signal_listener(gSavedSettings, "OctreeMaxNodeCapacity", handleRepartition);
@@ -830,6 +858,10 @@ void settings_setup_listeners()
setting_setup_signal_listener(gSavedSettings, "AutoTuneImpostorFarAwayDistance", handleUserImpostorDistanceChanged);
setting_setup_signal_listener(gSavedSettings, "AutoTuneImpostorByDistEnabled", handleUserImpostorByDistEnabledChanged);
setting_setup_signal_listener(gSavedSettings, "TuningFPSStrategy", handleFPSTuningStrategyChanged);
+ setting_setup_signal_listener(gSavedSettings, "LocalTerrainAsset1", handleLocalTerrainChanged);
+ setting_setup_signal_listener(gSavedSettings, "LocalTerrainAsset2", handleLocalTerrainChanged);
+ setting_setup_signal_listener(gSavedSettings, "LocalTerrainAsset3", handleLocalTerrainChanged);
+ setting_setup_signal_listener(gSavedSettings, "LocalTerrainAsset4", handleLocalTerrainChanged);
setting_setup_signal_listener(gSavedPerAccountSettings, "AvatarHoverOffsetZ", handleAvatarHoverOffsetChanged);
}
diff --git a/indra/newview/llviewerdisplay.cpp b/indra/newview/llviewerdisplay.cpp
index a936012781..b07a3243c7 100644
--- a/indra/newview/llviewerdisplay.cpp
+++ b/indra/newview/llviewerdisplay.cpp
@@ -730,8 +730,8 @@ void display(BOOL rebuild, F32 zoom_factor, int subfield, BOOL for_snapshot)
LL_PROFILE_ZONE_NAMED_CATEGORY_DISPLAY("display - 2")
if (gResizeScreenTexture)
{
- gResizeScreenTexture = FALSE;
gPipeline.resizeScreenTexture();
+ gResizeScreenTexture = FALSE;
}
gGL.setColorMask(true, true);
@@ -1064,7 +1064,7 @@ void display_cube_face()
LLSpatialGroup::sNoDelete = TRUE;
S32 occlusion = LLPipeline::sUseOcclusion;
- LLPipeline::sUseOcclusion = 0; // occlusion data is from main camera point of view, don't read or write it during cube snapshots
+ LLPipeline::sUseOcclusion = 1; // occlusion data is from main camera point of view, don't read or write it during cube snapshots
//gDepthDirty = TRUE; //let "real" render pipe know it can't trust the depth buffer for occlusion data
static LLCullResult result;
diff --git a/indra/newview/llviewermenu.cpp b/indra/newview/llviewermenu.cpp
index 9db9d97ddc..da7b1131a3 100644
--- a/indra/newview/llviewermenu.cpp
+++ b/indra/newview/llviewermenu.cpp
@@ -2122,6 +2122,20 @@ class LLAdvancedPurgeShaderCache : public view_listener_t
}
};
+/////////////////////
+// REBUILD TERRAIN //
+/////////////////////
+
+
+class LLAdvancedRebuildTerrain : public view_listener_t
+{
+ bool handleEvent(const LLSD& userdata)
+ {
+ gPipeline.rebuildTerrain();
+ return true;
+ }
+};
+
////////////////////
// EVENT Recorder //
///////////////////
@@ -9492,6 +9506,10 @@ void initialize_menus()
view_listener_t::addMenu(new LLAdvancedClickRenderProfile(), "Advanced.ClickRenderProfile");
view_listener_t::addMenu(new LLAdvancedClickRenderBenchmark(), "Advanced.ClickRenderBenchmark");
view_listener_t::addMenu(new LLAdvancedPurgeShaderCache(), "Advanced.ClearShaderCache");
+ if (gSavedSettings.get<bool>("RenderTerrainPBREnabled"))
+ {
+ view_listener_t::addMenu(new LLAdvancedRebuildTerrain(), "Advanced.RebuildTerrain");
+ }
#ifdef TOGGLE_HACKED_GODLIKE_VIEWER
view_listener_t::addMenu(new LLAdvancedHandleToggleHackedGodmode(), "Advanced.HandleToggleHackedGodmode");
diff --git a/indra/newview/llviewerobject.cpp b/indra/newview/llviewerobject.cpp
index d4346ee2d9..691a2e14d3 100644
--- a/indra/newview/llviewerobject.cpp
+++ b/indra/newview/llviewerobject.cpp
@@ -313,7 +313,9 @@ LLViewerObject::LLViewerObject(const LLUUID &id, const LLPCode pcode, LLViewerRe
mLastUpdateCached(FALSE),
mCachedMuteListUpdateTime(0),
mCachedOwnerInMuteList(false),
- mRiggedAttachedWarned(false)
+ mRiggedAttachedWarned(false),
+ mIsMirror(false),
+ mMirrorFace(3)
{
if (!is_global)
{
@@ -1147,6 +1149,39 @@ U32 LLViewerObject::extractSpatialExtents(LLDataPackerBinaryBuffer *dp, LLVector
return parent_id;
}
+void detectMirror(const std::string &str, bool &mirror, U8 &mode)
+{
+
+ std::stringstream ss(str);
+ std::string word;
+ while (ss >> word)
+ {
+ if (word == "IsMirror")
+ {
+ mirror = true;
+ }
+
+ if (mirror)
+ {
+ bool num = false;
+ std::string::const_iterator it = word.begin();
+ while (it != word.end())
+ {
+ num = std::isdigit(*it);
+ ++it;
+
+ if (!num)
+ break;
+ }
+
+ if (num)
+ {
+ mode = atoi(word.c_str());
+ }
+ }
+ }
+}
+
U32 LLViewerObject::processUpdateMessage(LLMessageSystem *mesgsys,
void **user_data,
U32 block_num,
@@ -1523,11 +1558,14 @@ U32 LLViewerObject::processUpdateMessage(LLMessageSystem *mesgsys,
std::string temp_string;
mesgsys->getStringFast(_PREHASH_ObjectData, _PREHASH_Text, temp_string, block_num );
+ detectMirror(temp_string, mIsMirror, mMirrorFace);
+
LLColor4U coloru;
mesgsys->getBinaryDataFast(_PREHASH_ObjectData, _PREHASH_TextColor, coloru.mV, 4, block_num);
-
+
// alpha was flipped so that it zero encoded better
coloru.mV[3] = 255 - coloru.mV[3];
+
mText->setColor(LLColor4(coloru));
mText->setString(temp_string);
@@ -1907,6 +1945,9 @@ U32 LLViewerObject::processUpdateMessage(LLMessageSystem *mesgsys,
{
std::string temp_string;
dp->unpackString(temp_string, "Text");
+
+ detectMirror(temp_string, mIsMirror, mMirrorFace);
+
LLColor4U coloru;
dp->unpackBinaryDataFixed(coloru.mV, 4, "Color");
coloru.mV[3] = 255 - coloru.mV[3];
@@ -5041,11 +5082,6 @@ void LLViewerObject::updateTEMaterialTextures(U8 te)
LLViewerObject* obj = gObjectList.findObject(id);
if (obj)
{
- LLViewerRegion* region = obj->getRegion();
- if(region)
- {
- region->loadCacheMiscExtras(obj->getLocalID());
- }
obj->markForUpdate();
}
});
@@ -5354,7 +5390,6 @@ S32 LLViewerObject::setTEFullbright(const U8 te, const U8 fullbright)
return retval;
}
-
S32 LLViewerObject::setTEMediaFlags(const U8 te, const U8 media_flags)
{
// this might need work for media type
@@ -6293,6 +6328,11 @@ LLViewerObject::ExtraParameter* LLViewerObject::createNewParameterEntry(U16 para
new_block = new LLReflectionProbeParams();
break;
}
+ case LLNetworkData::PARAMS_MIRROR:
+ {
+ new_block = new LLMirrorParams();
+ break;
+ }
default:
{
LL_INFOS_ONCE() << "Unknown param type: " << param_type << LL_ENDL;
diff --git a/indra/newview/llviewerobject.h b/indra/newview/llviewerobject.h
index 80da7b2f73..f3c00e83dc 100644
--- a/indra/newview/llviewerobject.h
+++ b/indra/newview/llviewerobject.h
@@ -257,6 +257,8 @@ public:
virtual BOOL isRiggedMesh() const { return FALSE; }
virtual BOOL hasLightTexture() const { return FALSE; }
virtual BOOL isReflectionProbe() const { return FALSE; }
+ virtual BOOL isMirror() const { return FALSE; }
+ virtual U8 mirrorFace() const { return 0; }
// This method returns true if the object is over land owned by
// the agent, one of its groups, or it encroaches and
@@ -878,6 +880,9 @@ protected:
F32 mPhysicsCost;
F32 mLinksetPhysicsCost;
+ bool mIsMirror;
+ U8 mMirrorFace;
+
// If true, "shrink wrap" this volume in its spatial partition. See "shrinkWrap"
bool mShouldShrinkWrap = false;
diff --git a/indra/newview/llviewerregion.cpp b/indra/newview/llviewerregion.cpp
index 452dcdd8fd..ce57585d82 100755
--- a/indra/newview/llviewerregion.cpp
+++ b/indra/newview/llviewerregion.cpp
@@ -1105,6 +1105,11 @@ void LLViewerRegion::dirtyHeights()
}
}
+void LLViewerRegion::dirtyAllPatches()
+{
+ getLand().dirtyAllPatches();
+}
+
//physically delete the cache entry
void LLViewerRegion::killCacheEntry(LLVOCacheEntry* entry, bool for_rendering)
{
@@ -1605,7 +1610,19 @@ void LLViewerRegion::idleUpdate(F32 max_update_time)
mLastUpdate = LLViewerOctreeEntryData::getCurrentFrame();
- mImpl->mLandp->idleUpdate(max_update_time);
+ static bool pbr_terrain_enabled = gSavedSettings.get<bool>("RenderTerrainPBREnabled");
+ static LLCachedControl<bool> pbr_terrain_experimental_normals(gSavedSettings, "RenderTerrainPBRNormalsEnabled", FALSE);
+ bool pbr_material = mImpl->mCompositionp && (mImpl->mCompositionp->getMaterialType() == LLTerrainMaterials::Type::PBR);
+ bool pbr_land = pbr_material && pbr_terrain_enabled && pbr_terrain_experimental_normals;
+
+ if (!pbr_land)
+ {
+ mImpl->mLandp->idleUpdate</*PBR=*/false>(max_update_time);
+ }
+ else
+ {
+ mImpl->mLandp->idleUpdate</*PBR=*/true>(max_update_time);
+ }
if (mParcelOverlay)
{
@@ -1879,8 +1896,6 @@ LLViewerObject* LLViewerRegion::addNewObject(LLVOCacheEntry* entry)
addActiveCacheEntry(entry);
}
- loadCacheMiscExtras(entry->getLocalID());
-
return obj;
}
@@ -1908,7 +1923,21 @@ LLViewerObject* LLViewerRegion::updateCacheEntry(U32 local_id, LLViewerObject* o
// As above, but forcibly do the update.
void LLViewerRegion::forceUpdate()
{
- mImpl->mLandp->idleUpdate(0.f);
+ constexpr F32 max_update_time = 0.f;
+
+ static bool pbr_terrain_enabled = gSavedSettings.get<BOOL>("RenderTerrainPBREnabled");
+ static LLCachedControl<BOOL> pbr_terrain_experimental_normals(gSavedSettings, "RenderTerrainPBRNormalsEnabled", FALSE);
+ bool pbr_material = mImpl->mCompositionp && (mImpl->mCompositionp->getMaterialType() == LLTerrainMaterials::Type::PBR);
+ bool pbr_land = pbr_material && pbr_terrain_enabled && pbr_terrain_experimental_normals;
+
+ if (!pbr_land)
+ {
+ mImpl->mLandp->idleUpdate</*PBR=*/false>(max_update_time);
+ }
+ else
+ {
+ mImpl->mLandp->idleUpdate</*PBR=*/true>(max_update_time);
+ }
if (mParcelOverlay)
{
@@ -2409,7 +2438,19 @@ void LLViewerRegion::setSimulatorFeatures(const LLSD& sim_features)
mSimulatorFeatures = sim_features;
setSimulatorFeaturesReceived(true);
-
+
+ // if region has MaxTextureResolution, set max_texture_dimension settings, otherwise use default
+ if (mSimulatorFeatures.has("MaxTextureResolution"))
+ {
+ S32 max_texture_resolution = mSimulatorFeatures["MaxTextureResolution"].asInteger();
+ gSavedSettings.setS32("max_texture_dimension_X", max_texture_resolution);
+ gSavedSettings.setS32("max_texture_dimension_Y", max_texture_resolution);
+ }
+ else
+ {
+ gSavedSettings.setS32("max_texture_dimension_X", 1024);
+ gSavedSettings.setS32("max_texture_dimension_Y", 1024);
+ }
}
//this is called when the parent is not cacheable.
@@ -2965,20 +3006,20 @@ void LLViewerRegion::unpackRegionHandshake()
// Get the 4 textures for land
msg->getUUID("RegionInfo", "TerrainDetail0", tmp_id);
- changed |= (tmp_id != compp->getDetailTextureID(0));
- compp->setDetailTextureID(0, tmp_id);
+ changed |= (tmp_id != compp->getDetailAssetID(0));
+ compp->setDetailAssetID(0, tmp_id);
msg->getUUID("RegionInfo", "TerrainDetail1", tmp_id);
- changed |= (tmp_id != compp->getDetailTextureID(1));
- compp->setDetailTextureID(1, tmp_id);
+ changed |= (tmp_id != compp->getDetailAssetID(1));
+ compp->setDetailAssetID(1, tmp_id);
msg->getUUID("RegionInfo", "TerrainDetail2", tmp_id);
- changed |= (tmp_id != compp->getDetailTextureID(2));
- compp->setDetailTextureID(2, tmp_id);
+ changed |= (tmp_id != compp->getDetailAssetID(2));
+ compp->setDetailAssetID(2, tmp_id);
msg->getUUID("RegionInfo", "TerrainDetail3", tmp_id);
- changed |= (tmp_id != compp->getDetailTextureID(3));
- compp->setDetailTextureID(3, tmp_id);
+ changed |= (tmp_id != compp->getDetailAssetID(3));
+ compp->setDetailAssetID(3, tmp_id);
// Get the start altitude and range values for land textures
F32 tmp_f32;
@@ -3655,15 +3696,6 @@ std::string LLViewerRegion::getSimHostName()
return std::string("...");
}
-void LLViewerRegion::loadCacheMiscExtras(U32 local_id)
-{
- auto iter = mImpl->mGLTFOverridesLLSD.find(local_id);
- if (iter != mImpl->mGLTFOverridesLLSD.end())
- {
- LLGLTFMaterialList::loadCacheOverrides(iter->second);
- }
-}
-
void LLViewerRegion::applyCacheMiscExtras(LLViewerObject* obj)
{
LL_PROFILE_ZONE_SCOPED_CATEGORY_DISPLAY;
diff --git a/indra/newview/llviewerregion.h b/indra/newview/llviewerregion.h
index a409d837a4..1c2ff9bc97 100644
--- a/indra/newview/llviewerregion.h
+++ b/indra/newview/llviewerregion.h
@@ -163,6 +163,9 @@ public:
// Call this whenever you change the height data in the region.
// (Automatically called by LLSurfacePatch's update routine)
void dirtyHeights();
+ // Call this whenever you want to force all terrain to rebuild.
+ // (For example, if a global terrain config option has changed)
+ void dirtyAllPatches();
LLViewerParcelOverlay *getParcelOverlay() const
{ return mParcelOverlay; }
@@ -435,8 +438,6 @@ private:
bool isNonCacheableObjectCreated(U32 local_id);
public:
- void loadCacheMiscExtras(U32 local_id);
-
void applyCacheMiscExtras(LLViewerObject* obj);
struct CompareDistance
diff --git a/indra/newview/llviewershadermgr.cpp b/indra/newview/llviewershadermgr.cpp
index 3225299493..7149dc781f 100644
--- a/indra/newview/llviewershadermgr.cpp
+++ b/indra/newview/llviewershadermgr.cpp
@@ -69,6 +69,14 @@ bool LLViewerShaderMgr::sSkipReload = false;
LLVector4 gShinyOrigin;
+S32 clamp_terrain_mapping(S32 mapping)
+{
+ // 1 = "flat", 2 not implemented, 3 = triplanar mapping
+ mapping = llclamp(mapping, 1, 3);
+ if (mapping == 2) { mapping = 1; }
+ return mapping;
+}
+
//utility shaders
LLGLSLShader gOcclusionProgram;
LLGLSLShader gSkinnedOcclusionProgram;
@@ -83,6 +91,8 @@ LLGLSLShader gTwoTextureCompareProgram;
LLGLSLShader gOneTextureFilterProgram;
LLGLSLShader gDebugProgram;
LLGLSLShader gSkinnedDebugProgram;
+LLGLSLShader gNormalDebugProgram[NORMAL_DEBUG_SHADER_COUNT];
+LLGLSLShader gSkinnedNormalDebugProgram[NORMAL_DEBUG_SHADER_COUNT];
LLGLSLShader gClipProgram;
LLGLSLShader gAlphaMaskProgram;
LLGLSLShader gBenchmarkProgram;
@@ -214,6 +224,7 @@ LLGLSLShader gDeferredSkinnedPBROpaqueProgram;
LLGLSLShader gHUDPBRAlphaProgram;
LLGLSLShader gDeferredPBRAlphaProgram;
LLGLSLShader gDeferredSkinnedPBRAlphaProgram;
+LLGLSLShader gDeferredPBRTerrainProgram;
//helper for making a rigged variant of a given shader
bool make_rigged_variant(LLGLSLShader& shader, LLGLSLShader& riggedShader)
@@ -271,7 +282,7 @@ LLViewerShaderMgr::LLViewerShaderMgr() :
mShaderList.push_back(&gDeferredEmissiveProgram);
mShaderList.push_back(&gDeferredSkinnedEmissiveProgram);
mShaderList.push_back(&gDeferredAvatarEyesProgram);
- mShaderList.push_back(&gDeferredAvatarAlphaProgram);
+ mShaderList.push_back(&gDeferredAvatarAlphaProgram);
mShaderList.push_back(&gDeferredWLSkyProgram);
mShaderList.push_back(&gDeferredWLCloudProgram);
mShaderList.push_back(&gDeferredWLMoonProgram);
@@ -623,6 +634,16 @@ std::string LLViewerShaderMgr::loadBasicShaders()
attribs["REF_SAMPLE_COUNT"] = "32";
}
+ { // PBR terrain
+ const S32 mapping = clamp_terrain_mapping(gSavedSettings.getS32("RenderTerrainPBRPlanarSampleCount"));
+ attribs["TERRAIN_PLANAR_TEXTURE_SAMPLE_COUNT"] = llformat("%d", mapping);
+ const F32 triplanar_factor = gSavedSettings.getF32("RenderTerrainPBRTriplanarBlendFactor");
+ attribs["TERRAIN_TRIPLANAR_BLEND_FACTOR"] = llformat("%.2f", triplanar_factor);
+ S32 detail = gSavedSettings.getS32("RenderTerrainPBRDetail");
+ detail = llclamp(detail, TERRAIN_PBR_DETAIL_MIN, TERRAIN_PBR_DETAIL_MAX);
+ attribs["TERRAIN_PBR_DETAIL"] = llformat("%d", detail);
+ }
+
LLGLSLShader::sGlobalDefines = attribs;
// We no longer have to bind the shaders to global glhandles, they are automatically added to a map now.
@@ -660,6 +681,7 @@ std::string LLViewerShaderMgr::loadBasicShaders()
index_channels.push_back(-1); shaders.push_back( make_pair( "deferred/deferredUtil.glsl", 1) );
index_channels.push_back(-1); shaders.push_back( make_pair( "deferred/shadowUtil.glsl", 1) );
index_channels.push_back(-1); shaders.push_back( make_pair( "deferred/aoUtil.glsl", 1) );
+ index_channels.push_back(-1); shaders.push_back( make_pair( "deferred/pbrterrainUtilF.glsl", 1) );
index_channels.push_back(-1); shaders.push_back( make_pair( "deferred/reflectionProbeF.glsl", has_reflection_probes ? 3 : 2) );
index_channels.push_back(-1); shaders.push_back( make_pair( "deferred/screenSpaceReflUtil.glsl", ssr ? 3 : 1) );
index_channels.push_back(-1); shaders.push_back( make_pair( "lighting/lightNonIndexedF.glsl", mShaderLevel[SHADER_LIGHTING] ) );
@@ -951,6 +973,7 @@ BOOL LLViewerShaderMgr::loadShadersDeferred()
gDeferredSkinnedPBROpaqueProgram.unload();
gDeferredPBRAlphaProgram.unload();
gDeferredSkinnedPBRAlphaProgram.unload();
+ gDeferredPBRTerrainProgram.unload();
return TRUE;
}
@@ -1242,6 +1265,34 @@ BOOL LLViewerShaderMgr::loadShadersDeferred()
success = shader->createShader(NULL, NULL);
llassert(success);
}
+
+ if (success)
+ {
+ S32 detail = gSavedSettings.getS32("RenderTerrainPBRDetail");
+ detail = llclamp(detail, TERRAIN_PBR_DETAIL_MIN, TERRAIN_PBR_DETAIL_MAX);
+ const S32 mapping = clamp_terrain_mapping(gSavedSettings.getS32("RenderTerrainPBRPlanarSampleCount"));
+ gDeferredPBRTerrainProgram.mName = llformat("Deferred PBR Terrain Shader %d %s",
+ detail,
+ (mapping == 1 ? "flat" : "triplanar"));
+ gDeferredPBRTerrainProgram.mFeatures.encodesNormal = true;
+ gDeferredPBRTerrainProgram.mFeatures.hasSrgb = true;
+ gDeferredPBRTerrainProgram.mFeatures.isAlphaLighting = true;
+ gDeferredPBRTerrainProgram.mFeatures.disableTextureIndex = true; //hack to disable auto-setup of texture channels
+ gDeferredPBRTerrainProgram.mFeatures.calculatesAtmospherics = true;
+ gDeferredPBRTerrainProgram.mFeatures.hasAtmospherics = true;
+ gDeferredPBRTerrainProgram.mFeatures.hasGamma = true;
+ gDeferredPBRTerrainProgram.mFeatures.hasTransport = true;
+ gDeferredPBRTerrainProgram.mFeatures.isPBRTerrain = true;
+
+ gDeferredPBRTerrainProgram.mShaderFiles.clear();
+ gDeferredPBRTerrainProgram.mShaderFiles.push_back(make_pair("deferred/pbrterrainV.glsl", GL_VERTEX_SHADER));
+ gDeferredPBRTerrainProgram.mShaderFiles.push_back(make_pair("deferred/pbrterrainF.glsl", GL_FRAGMENT_SHADER));
+ gDeferredPBRTerrainProgram.mShaderLevel = mShaderLevel[SHADER_DEFERRED];
+ gDeferredPBRTerrainProgram.addPermutation("TERRAIN_PBR_DETAIL", llformat("%d", detail));
+ gDeferredPBRTerrainProgram.addPermutation("TERRAIN_PLANAR_TEXTURE_SAMPLE_COUNT", llformat("%d", mapping));
+ success = gDeferredPBRTerrainProgram.createShader(NULL, NULL);
+ llassert(success);
+ }
if (success)
{
@@ -1757,6 +1808,11 @@ BOOL LLViewerShaderMgr::loadShadersDeferred()
gDeferredSoftenProgram.addPermutation("HAS_SUN_SHADOW", "1");
}
+ if (LLPipeline::RenderMirrors)
+ {
+ gDeferredSoftenProgram.addPermutation("HERO_PROBES", "1");
+ }
+
if (gSavedSettings.getBOOL("RenderDeferredSSAO"))
{ //if using SSAO, take screen space light map into account as if shadows are enabled
gDeferredSoftenProgram.mShaderLevel = llmax(gDeferredSoftenProgram.mShaderLevel, 2);
@@ -1955,8 +2011,6 @@ BOOL LLViewerShaderMgr::loadShadersDeferred()
gDeferredTerrainProgram.mName = "Deferred Terrain Shader";
gDeferredTerrainProgram.mFeatures.encodesNormal = true;
gDeferredTerrainProgram.mFeatures.hasSrgb = true;
- gDeferredTerrainProgram.mFeatures.calculatesLighting = false;
- gDeferredTerrainProgram.mFeatures.hasLighting = false;
gDeferredTerrainProgram.mFeatures.isAlphaLighting = true;
gDeferredTerrainProgram.mFeatures.disableTextureIndex = true; //hack to disable auto-setup of texture channels
gDeferredTerrainProgram.mFeatures.calculatesAtmospherics = true;
@@ -2643,6 +2697,33 @@ BOOL LLViewerShaderMgr::loadShadersInterface()
if (success)
{
+ for (S32 variant = 0; variant < NORMAL_DEBUG_SHADER_COUNT; ++variant)
+ {
+ LLGLSLShader& shader = gNormalDebugProgram[variant];
+ LLGLSLShader& skinned_shader = gSkinnedNormalDebugProgram[variant];
+ shader.mName = "Normal Debug Shader";
+ shader.mShaderFiles.clear();
+ shader.mShaderFiles.push_back(make_pair("interface/normaldebugV.glsl", GL_VERTEX_SHADER));
+ // *NOTE: Geometry shaders have a reputation for being slow.
+ // Consider using compute shaders instead, which have a reputation
+ // for being fast. This geometry shader in particular seems to run
+ // fine on my machine, but I won't vouch for this in
+ // performance-critical areas. -Cosmic,2023-09-28
+ shader.mShaderFiles.push_back(make_pair("interface/normaldebugG.glsl", GL_GEOMETRY_SHADER));
+ shader.mShaderFiles.push_back(make_pair("interface/normaldebugF.glsl", GL_FRAGMENT_SHADER));
+ shader.mRiggedVariant = &skinned_shader;
+ shader.mShaderLevel = mShaderLevel[SHADER_INTERFACE];
+ if (variant == NORMAL_DEBUG_SHADER_WITH_TANGENTS)
+ {
+ shader.addPermutation("HAS_ATTRIBUTE_TANGENT", "1");
+ }
+ success = make_rigged_variant(shader, skinned_shader);
+ success = success && shader.createShader(NULL, NULL);
+ }
+ }
+
+ if (success)
+ {
gClipProgram.mName = "Clip Shader";
gClipProgram.mShaderFiles.clear();
gClipProgram.mShaderFiles.push_back(make_pair("interface/clipV.glsl", GL_VERTEX_SHADER));
diff --git a/indra/newview/llviewershadermgr.h b/indra/newview/llviewershadermgr.h
index 04da7e48ae..824c66ab49 100644
--- a/indra/newview/llviewershadermgr.h
+++ b/indra/newview/llviewershadermgr.h
@@ -156,6 +156,14 @@ extern LLGLSLShader gRadianceGenProgram;
extern LLGLSLShader gIrradianceGenProgram;
extern LLGLSLShader gGlowCombineFXAAProgram;
extern LLGLSLShader gDebugProgram;
+enum NormalDebugShaderVariant : S32
+{
+ NORMAL_DEBUG_SHADER_DEFAULT,
+ NORMAL_DEBUG_SHADER_WITH_TANGENTS,
+ NORMAL_DEBUG_SHADER_COUNT
+};
+extern LLGLSLShader gNormalDebugProgram[NORMAL_DEBUG_SHADER_COUNT];
+extern LLGLSLShader gSkinnedNormalDebugProgram[NORMAL_DEBUG_SHADER_COUNT];
extern LLGLSLShader gClipProgram;
extern LLGLSLShader gBenchmarkProgram;
extern LLGLSLShader gReflectionProbeDisplayProgram;
@@ -272,4 +280,20 @@ extern LLGLSLShader gPBRGlowProgram;
extern LLGLSLShader gDeferredPBROpaqueProgram;
extern LLGLSLShader gDeferredPBRAlphaProgram;
extern LLGLSLShader gHUDPBRAlphaProgram;
+
+// Encodes detail level for dropping textures, in accordance with the GLTF spec where possible
+// 0 is highest detail, -1 drops emissive, etc
+// Dropping metallic roughness is off-spec - Reserve for potato machines as needed
+// https://registry.khronos.org/glTF/specs/2.0/glTF-2.0.html#additional-textures
+enum TerrainPBRDetail : S32
+{
+ TERRAIN_PBR_DETAIL_MAX = 0,
+ TERRAIN_PBR_DETAIL_EMISSIVE = 0,
+ TERRAIN_PBR_DETAIL_OCCLUSION = -1,
+ TERRAIN_PBR_DETAIL_NORMAL = -2,
+ TERRAIN_PBR_DETAIL_METALLIC_ROUGHNESS = -3,
+ TERRAIN_PBR_DETAIL_BASE_COLOR = -4,
+ TERRAIN_PBR_DETAIL_MIN = -4,
+};
+extern LLGLSLShader gDeferredPBRTerrainProgram;
#endif
diff --git a/indra/newview/llviewertexture.cpp b/indra/newview/llviewertexture.cpp
index 56bba51692..8436159e14 100644
--- a/indra/newview/llviewertexture.cpp
+++ b/indra/newview/llviewertexture.cpp
@@ -1699,7 +1699,7 @@ void LLViewerFetchedTexture::processTextureStats()
{
if (mFullWidth > MAX_IMAGE_SIZE_DEFAULT || mFullHeight > MAX_IMAGE_SIZE_DEFAULT)
{
- mDesiredDiscardLevel = 1; // MAX_IMAGE_SIZE_DEFAULT = 1024 and max size ever is 2048
+ mDesiredDiscardLevel = 1; // MAX_IMAGE_SIZE_DEFAULT = 2048 and max size ever is 4096
}
else
{
@@ -1712,7 +1712,7 @@ void LLViewerFetchedTexture::processTextureStats()
}
else
{
- U32 desired_size = MAX_IMAGE_SIZE_DEFAULT; // MAX_IMAGE_SIZE_DEFAULT = 1024 and max size ever is 2048
+ U32 desired_size = MAX_IMAGE_SIZE_DEFAULT; // MAX_IMAGE_SIZE_DEFAULT = 2048 and max size ever is 4096
if(!mKnownDrawWidth || !mKnownDrawHeight || mFullWidth <= mKnownDrawWidth || mFullHeight <= mKnownDrawHeight)
{
if (mFullWidth > desired_size || mFullHeight > desired_size)
@@ -3089,7 +3089,7 @@ void LLViewerLODTexture::processTextureStats()
{
mDesiredDiscardLevel = 0;
if (mFullWidth > MAX_IMAGE_SIZE_DEFAULT || mFullHeight > MAX_IMAGE_SIZE_DEFAULT)
- mDesiredDiscardLevel = 1; // MAX_IMAGE_SIZE_DEFAULT = 1024 and max size ever is 2048
+ mDesiredDiscardLevel = 1; // MAX_IMAGE_SIZE_DEFAULT = 2048 and max size ever is 4096
}
else if (mBoostLevel < LLGLTexture::BOOST_HIGH && mMaxVirtualSize <= 10.f)
{
@@ -3134,7 +3134,7 @@ void LLViewerLODTexture::processTextureStats()
discard_level = floorf(discard_level);
F32 min_discard = 0.f;
- U32 desired_size = MAX_IMAGE_SIZE_DEFAULT; // MAX_IMAGE_SIZE_DEFAULT = 1024 and max size ever is 2048
+ U32 desired_size = MAX_IMAGE_SIZE_DEFAULT; // MAX_IMAGE_SIZE_DEFAULT = 2048 and max size ever is 4096
if (mBoostLevel <= LLGLTexture::BOOST_SCULPTED)
{
desired_size = DESIRED_NORMAL_TEXTURE_SIZE;
diff --git a/indra/newview/llviewertexturelist.cpp b/indra/newview/llviewertexturelist.cpp
index 9a6d40ab0a..ebf03ae988 100644
--- a/indra/newview/llviewertexturelist.cpp
+++ b/indra/newview/llviewertexturelist.cpp
@@ -121,8 +121,17 @@ void LLViewerTextureList::doPreloadImages()
LLTexUnit::sWhiteTexture = LLViewerFetchedTexture::sWhiteImagep->getTexName();
LLUIImageList* image_list = LLUIImageList::getInstance();
- // Set the default flat normal map
- LLViewerFetchedTexture::sFlatNormalImagep = LLViewerTextureManager::getFetchedTextureFromFile("flatnormal.tga", FTT_LOCAL_FILE, MIPMAP_NO, LLViewerFetchedTexture::BOOST_BUMP);
+ // Set the default flat normal map
+ // BLANK_OBJECT_NORMAL has a version on dataserver, but it has compression artifacts
+ LLViewerFetchedTexture::sFlatNormalImagep =
+ LLViewerTextureManager::getFetchedTextureFromFile("flatnormal.tga",
+ FTT_LOCAL_FILE,
+ MIPMAP_NO,
+ LLViewerFetchedTexture::BOOST_BUMP,
+ LLViewerTexture::FETCHED_TEXTURE,
+ 0,
+ 0,
+ BLANK_OBJECT_NORMAL);
// PBR: irradiance
LLViewerFetchedTexture::sDefaultIrradiancePBRp = LLViewerTextureManager::getFetchedTextureFromFile("default_irradiance.png", FTT_LOCAL_FILE, MIPMAP_YES, LLViewerFetchedTexture::BOOST_UI);
diff --git a/indra/newview/llviewerwindow.cpp b/indra/newview/llviewerwindow.cpp
index ed671fe849..0aae6f4b35 100644
--- a/indra/newview/llviewerwindow.cpp
+++ b/indra/newview/llviewerwindow.cpp
@@ -5307,7 +5307,7 @@ BOOL LLViewerWindow::simpleSnapshot(LLImageRaw* raw, S32 image_width, S32 image_
void display_cube_face();
-BOOL LLViewerWindow::cubeSnapshot(const LLVector3& origin, LLCubeMapArray* cubearray, S32 cubeIndex, S32 face, F32 near_clip, bool dynamic_render)
+BOOL LLViewerWindow::cubeSnapshot(const LLVector3& origin, LLCubeMapArray* cubearray, S32 cubeIndex, S32 face, F32 near_clip, bool dynamic_render, bool useCustomClipPlane, LLPlane clipPlane)
{
// NOTE: implementation derived from LLFloater360Capture::capture360Images() and simpleSnapshot
LL_PROFILE_ZONE_SCOPED_CATEGORY_APP;
@@ -5338,6 +5338,14 @@ BOOL LLViewerWindow::cubeSnapshot(const LLVector3& origin, LLCubeMapArray* cubea
camera->setOrigin(origin);
camera->setNear(near_clip);
+ LLPlane previousClipPlane;
+
+ if (useCustomClipPlane)
+ {
+ previousClipPlane = camera->getUserClipPlane();
+ camera->setUserClipPlane(clipPlane);
+ }
+
glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT); // stencil buffer is deprecated | GL_STENCIL_BUFFER_BIT);
U32 dynamic_render_types[] = {
@@ -5444,6 +5452,11 @@ BOOL LLViewerWindow::cubeSnapshot(const LLVector3& origin, LLCubeMapArray* cubea
gPipeline.resetDrawOrders();
mWorldViewRectRaw = window_rect;
+
+ if (useCustomClipPlane)
+ {
+ camera->setUserClipPlane(previousClipPlane);
+ }
// restore original view/camera/avatar settings settings
*camera = saved_camera;
diff --git a/indra/newview/llviewerwindow.h b/indra/newview/llviewerwindow.h
index ccef006a07..ad634503ba 100644
--- a/indra/newview/llviewerwindow.h
+++ b/indra/newview/llviewerwindow.h
@@ -374,7 +374,8 @@ public:
// index - cube index in the array to use (cube index, not face-layer)
// face - which cube face to update
// near_clip - near clip setting to use
- BOOL cubeSnapshot(const LLVector3& origin, LLCubeMapArray* cubearray, S32 index, S32 face, F32 near_clip, bool render_avatars);
+ BOOL cubeSnapshot(const LLVector3 &origin, LLCubeMapArray *cubearray, S32 index, S32 face, F32 near_clip, bool render_avatars,
+ bool customCullingPlane = false, LLPlane cullingPlane = LLPlane(LLVector3(0, 0, 0), LLVector3(0, 0, 1)));
// special implementation of simpleSnapshot for reflection maps
diff --git a/indra/newview/llvlcomposition.cpp b/indra/newview/llvlcomposition.cpp
index 001fab7755..7c16ee4f61 100644
--- a/indra/newview/llvlcomposition.cpp
+++ b/indra/newview/llvlcomposition.cpp
@@ -34,12 +34,16 @@
#include "lltextureview.h"
#include "llviewertexture.h"
#include "llviewertexturelist.h"
+#include "llfetchedgltfmaterial.h"
+#include "llgltfmateriallist.h"
#include "llviewerregion.h"
#include "noise.h"
#include "llregionhandle.h" // for from_region_handle
#include "llviewercontrol.h"
+static const U32 BASE_SIZE = 128;
+
F32 bilinear(const F32 v00, const F32 v01, const F32 v10, const F32 v11, const F32 x_frac, const F32 y_frac)
{
@@ -57,18 +61,220 @@ F32 bilinear(const F32 v00, const F32 v01, const F32 v10, const F32 v11, const F
return result;
}
+LLTerrainMaterials::LLTerrainMaterials()
+{
+ for (S32 i = 0; i < ASSET_COUNT; ++i)
+ {
+ mMaterialTexturesSet[i] = false;
+ }
+}
-LLVLComposition::LLVLComposition(LLSurface *surfacep, const U32 width, const F32 scale) :
- LLViewerLayer(width, scale),
- mParamsReady(FALSE)
+LLTerrainMaterials::~LLTerrainMaterials()
{
- mSurfacep = surfacep;
+}
+
+BOOL LLTerrainMaterials::generateMaterials()
+{
+ if (texturesReady(TRUE))
+ {
+ return TRUE;
+ }
+
+ if (materialsReady(TRUE))
+ {
+ return TRUE;
+ }
+
+ return FALSE;
+}
+
+LLUUID LLTerrainMaterials::getDetailAssetID(S32 asset)
+{
+ llassert(mDetailTextures[asset] && mDetailMaterials[asset]);
+ // *HACK: Assume both the the material and texture were fetched in the same
+ // way using the same UUID. However, we may not know at this point which
+ // one will load.
+ return mDetailTextures[asset]->getID();
+}
+
+LLPointer<LLViewerFetchedTexture> fetch_terrain_texture(const LLUUID& id)
+{
+ if (id.isNull())
+ {
+ return nullptr;
+ }
+
+ LLPointer<LLViewerFetchedTexture> tex = LLViewerTextureManager::getFetchedTexture(id);
+ tex->setNoDelete();
+ return tex;
+}
+
+void LLTerrainMaterials::setDetailAssetID(S32 asset, const LLUUID& id)
+{
+ // This is terrain texture, but we are not setting it as BOOST_TERRAIN
+ // since we will be manipulating it later as needed.
+ mDetailTextures[asset] = fetch_terrain_texture(id);
+ LLPointer<LLFetchedGLTFMaterial>& mat = mDetailMaterials[asset];
+ mat = id.isNull() ? nullptr : gGLTFMaterialList.getMaterial(id);
+ mMaterialTexturesSet[asset] = false;
+}
+LLTerrainMaterials::Type LLTerrainMaterials::getMaterialType()
+{
+ LL_PROFILE_ZONE_SCOPED;
+
+ const BOOL use_textures = texturesReady() || !materialsReady();
+ return use_textures ? Type::TEXTURE : Type::PBR;
+}
+
+BOOL LLTerrainMaterials::texturesReady(BOOL boost)
+{
+ BOOL ready = TRUE;
+ for (S32 i = 0; i < ASSET_COUNT; i++)
+ {
+ if (!textureReady(mDetailTextures[i], boost))
+ {
+ ready = FALSE;
+ }
+ }
+ return ready;
+}
+
+BOOL LLTerrainMaterials::materialsReady(BOOL boost)
+{
+#if 1
+ static bool sRenderTerrainPBREnabled = gSavedSettings.get<bool>("RenderTerrainPBREnabled");
+ static LLCachedControl<bool> sRenderTerrainPBRForce(gSavedSettings, "RenderTerrainPBRForce", false);
+ if (sRenderTerrainPBREnabled && sRenderTerrainPBRForce)
+ {
+ bool defined = true;
+ for (S32 i = 0; i < ASSET_COUNT; i++)
+ {
+ if (!mDetailMaterials[i])
+ {
+ defined = false;
+ break;
+ }
+ }
+ if (defined)
+ {
+ return TRUE;
+ }
+ }
+#endif
+
+ BOOL ready = TRUE;
+ for (S32 i = 0; i < ASSET_COUNT; i++)
+ {
+ if (!materialReady(mDetailMaterials[i], mMaterialTexturesSet[i], boost))
+ {
+ ready = FALSE;
+ }
+ }
+ return ready;
+}
+
+// Boost the texture loading priority
+// Return true when ready to use (i.e. texture is sufficiently loaded)
+// static
+BOOL LLTerrainMaterials::textureReady(LLPointer<LLViewerFetchedTexture>& tex, BOOL boost)
+{
+ llassert(tex.notNull());
+
+ if (tex->getDiscardLevel() < 0)
+ {
+ if (boost)
+ {
+ tex->setBoostLevel(LLGLTexture::BOOST_TERRAIN); // in case we are at low detail
+ tex->addTextureStats(BASE_SIZE*BASE_SIZE);
+ }
+ return FALSE;
+ }
+ if ((tex->getDiscardLevel() != 0 &&
+ (tex->getWidth() < BASE_SIZE ||
+ tex->getHeight() < BASE_SIZE)))
+ {
+ if (boost)
+ {
+ S32 width = tex->getFullWidth();
+ S32 height = tex->getFullHeight();
+ S32 min_dim = llmin(width, height);
+ S32 ddiscard = 0;
+ while (min_dim > BASE_SIZE && ddiscard < MAX_DISCARD_LEVEL)
+ {
+ ddiscard++;
+ min_dim /= 2;
+ }
+ tex->setBoostLevel(LLGLTexture::BOOST_TERRAIN); // in case we are at low detail
+ tex->setMinDiscardLevel(ddiscard);
+ tex->addTextureStats(BASE_SIZE*BASE_SIZE); // priority
+ }
+ return FALSE;
+ }
+ if (tex->getComponents() == 0)
+ {
+ return FALSE;
+ }
+ return TRUE;
+}
+
+// Boost the loading priority of every known texture in the material
+// Return true when ready to use (i.e. material and all textures within are sufficiently loaded)
+// static
+BOOL LLTerrainMaterials::materialReady(LLPointer<LLFetchedGLTFMaterial>& mat, bool& textures_set, BOOL boost)
+{
+ if (!mat || !mat->isLoaded())
+ {
+ return FALSE;
+ }
+
+ // Material is loaded, but textures may not be
+ if (!textures_set)
+ {
+ // *NOTE: These can sometimes be set to to nullptr due to
+ // updateTEMaterialTextures. For the sake of robustness, we emulate
+ // that fetching behavior by setting textures of null IDs to nullptr.
+ mat->mBaseColorTexture = fetch_terrain_texture(mat->mTextureId[LLGLTFMaterial::GLTF_TEXTURE_INFO_BASE_COLOR]);
+ mat->mNormalTexture = fetch_terrain_texture(mat->mTextureId[LLGLTFMaterial::GLTF_TEXTURE_INFO_NORMAL]);
+ mat->mMetallicRoughnessTexture = fetch_terrain_texture(mat->mTextureId[LLGLTFMaterial::GLTF_TEXTURE_INFO_METALLIC_ROUGHNESS]);
+ mat->mEmissiveTexture = fetch_terrain_texture(mat->mTextureId[LLGLTFMaterial::GLTF_TEXTURE_INFO_EMISSIVE]);
+ textures_set = true;
+
+ return FALSE;
+ }
+
+ if (mat->mTextureId[LLGLTFMaterial::GLTF_TEXTURE_INFO_BASE_COLOR].notNull() && !textureReady(mat->mBaseColorTexture, boost))
+ {
+ return FALSE;
+ }
+ if (mat->mTextureId[LLGLTFMaterial::GLTF_TEXTURE_INFO_NORMAL].notNull() && !textureReady(mat->mNormalTexture, boost))
+ {
+ return FALSE;
+ }
+ if (mat->mTextureId[LLGLTFMaterial::GLTF_TEXTURE_INFO_METALLIC_ROUGHNESS].notNull() && !textureReady(mat->mMetallicRoughnessTexture, boost))
+ {
+ return FALSE;
+ }
+ if (mat->mTextureId[LLGLTFMaterial::GLTF_TEXTURE_INFO_EMISSIVE].notNull() && !textureReady(mat->mEmissiveTexture, boost))
+ {
+ return FALSE;
+ }
+
+ return TRUE;
+}
+
+
+LLVLComposition::LLVLComposition(LLSurface *surfacep, const U32 width, const F32 scale) :
+ LLTerrainMaterials(),
+ LLViewerLayer(width, scale)
+{
// Load Terrain Textures - Original ones
- setDetailTextureID(0, TERRAIN_DIRT_DETAIL);
- setDetailTextureID(1, TERRAIN_GRASS_DETAIL);
- setDetailTextureID(2, TERRAIN_MOUNTAIN_DETAIL);
- setDetailTextureID(3, TERRAIN_ROCK_DETAIL);
+ setDetailAssetID(0, TERRAIN_DIRT_DETAIL);
+ setDetailAssetID(1, TERRAIN_GRASS_DETAIL);
+ setDetailAssetID(2, TERRAIN_MOUNTAIN_DETAIL);
+ setDetailAssetID(3, TERRAIN_ROCK_DETAIL);
+
+ mSurfacep = surfacep;
// Initialize the texture matrix to defaults.
for (S32 i = 0; i < CORNER_COUNT; ++i)
@@ -76,14 +282,12 @@ LLVLComposition::LLVLComposition(LLSurface *surfacep, const U32 width, const F32
mStartHeight[i] = gSavedSettings.getF32("TerrainColorStartHeight");
mHeightRange[i] = gSavedSettings.getF32("TerrainColorHeightRange");
}
- mTexScaleX = 16.f;
- mTexScaleY = 16.f;
- mTexturesLoaded = FALSE;
}
LLVLComposition::~LLVLComposition()
{
+ LLTerrainMaterials::~LLTerrainMaterials();
}
@@ -92,20 +296,6 @@ void LLVLComposition::setSurface(LLSurface *surfacep)
mSurfacep = surfacep;
}
-
-void LLVLComposition::setDetailTextureID(S32 corner, const LLUUID& id)
-{
- if(id.isNull())
- {
- return;
- }
- // This is terrain texture, but we are not setting it as BOOST_TERRAIN
- // since we will be manipulating it later as needed.
- mDetailTextures[corner] = LLViewerTextureManager::getFetchedTexture(id);
- mDetailTextures[corner]->setNoDelete() ;
- mRawImages[corner] = NULL;
-}
-
BOOL LLVLComposition::generateHeights(const F32 x, const F32 y,
const F32 width, const F32 height)
{
@@ -149,10 +339,6 @@ BOOL LLVLComposition::generateHeights(const F32 x, const F32 y,
const F32 noise_magnitude = 2.f; // Degree to which noise modulates composition layer (versus
// simple height)
- // Heights map into textures as 0-1 = first, 1-2 = second, etc.
- // So we need to compress heights into this range.
- const S32 NUM_TEXTURES = 4;
-
const F32 xyScaleInv = (1.f / xyScale);
const F32 zScaleInv = (1.f / zScale);
@@ -199,7 +385,7 @@ BOOL LLVLComposition::generateHeights(const F32 x, const F32 y,
twiddle += turbulence2(vec, 2)*slope_squared; // High frequency component
twiddle *= noise_magnitude;
- F32 scaled_noisy_height = (height + twiddle - start_height) * F32(NUM_TEXTURES) / height_range;
+ F32 scaled_noisy_height = (height + twiddle - start_height) * F32(ASSET_COUNT) / height_range;
scaled_noisy_height = llmax(0.f, scaled_noisy_height);
scaled_noisy_height = llmin(3.f, scaled_noisy_height);
@@ -209,49 +395,20 @@ BOOL LLVLComposition::generateHeights(const F32 x, const F32 y,
return TRUE;
}
-static const U32 BASE_SIZE = 128;
+LLTerrainMaterials gLocalTerrainMaterials;
BOOL LLVLComposition::generateComposition()
{
-
if (!mParamsReady)
{
// All the parameters haven't been set yet (we haven't gotten the message from the sim)
return FALSE;
}
- for (S32 i = 0; i < 4; i++)
- {
- if (mDetailTextures[i]->getDiscardLevel() < 0)
- {
- mDetailTextures[i]->setBoostLevel(LLGLTexture::BOOST_TERRAIN); // in case we are at low detail
- mDetailTextures[i]->addTextureStats(BASE_SIZE*BASE_SIZE);
- return FALSE;
- }
- if ((mDetailTextures[i]->getDiscardLevel() != 0 &&
- (mDetailTextures[i]->getWidth() < BASE_SIZE ||
- mDetailTextures[i]->getHeight() < BASE_SIZE)))
- {
- S32 width = mDetailTextures[i]->getFullWidth();
- S32 height = mDetailTextures[i]->getFullHeight();
- S32 min_dim = llmin(width, height);
- S32 ddiscard = 0;
- while (min_dim > BASE_SIZE && ddiscard < MAX_DISCARD_LEVEL)
- {
- ddiscard++;
- min_dim /= 2;
- }
- mDetailTextures[i]->setBoostLevel(LLGLTexture::BOOST_TERRAIN); // in case we are at low detail
- mDetailTextures[i]->setMinDiscardLevel(ddiscard);
- mDetailTextures[i]->addTextureStats(BASE_SIZE*BASE_SIZE); // priority
- return FALSE;
- }
- }
-
- return TRUE;
+ return LLTerrainMaterials::generateMaterials();
}
-BOOL LLVLComposition::generateTexture(const F32 x, const F32 y,
+BOOL LLVLComposition::generateMinimapTileLand(const F32 x, const F32 y,
const F32 width, const F32 height)
{
LL_PROFILE_ZONE_SCOPED
@@ -259,8 +416,6 @@ BOOL LLVLComposition::generateTexture(const F32 x, const F32 y,
llassert(x >= 0.f);
llassert(y >= 0.f);
- LLTimer gen_timer;
-
///////////////////////////
//
// Generate raw data arrays for surface textures
@@ -268,15 +423,61 @@ BOOL LLVLComposition::generateTexture(const F32 x, const F32 y,
//
// These have already been validated by generateComposition.
- U8* st_data[4];
- S32 st_data_size[4]; // for debugging
-
- for (S32 i = 0; i < 4; i++)
+ U8* st_data[ASSET_COUNT];
+ S32 st_data_size[ASSET_COUNT]; // for debugging
+
+ const bool use_textures = getMaterialType() != LLTerrainMaterials::Type::PBR;
+ // *TODO: Remove this as it is reduandant computation (first and foremost
+ // because getMaterialType() does something similar, but also... shouldn't
+ // the textures/materials already be loaded by now?)
+ if (use_textures)
+ {
+ if (!texturesReady()) { return FALSE; }
+ }
+ else
+ {
+ if (!materialsReady()) { return FALSE; }
+ }
+
+ for (S32 i = 0; i < ASSET_COUNT; i++)
{
if (mRawImages[i].isNull())
{
// Read back a raw image for this discard level, if it exists
- S32 min_dim = llmin(mDetailTextures[i]->getFullWidth(), mDetailTextures[i]->getFullHeight());
+ LLViewerFetchedTexture* tex;
+ LLViewerFetchedTexture* tex_emissive; // Can be null
+ bool has_base_color_factor;
+ bool has_emissive_factor;
+ LLColor3 base_color_factor;
+ LLColor3 emissive_factor;
+ if (use_textures)
+ {
+ tex = mDetailTextures[i];
+ tex_emissive = nullptr;
+ has_base_color_factor = false;
+ has_emissive_factor = false;
+ llassert(tex);
+ }
+ else
+ {
+ tex = mDetailMaterials[i]->mBaseColorTexture;
+ tex_emissive = mDetailMaterials[i]->mEmissiveTexture;
+ base_color_factor = LLColor3(mDetailMaterials[i]->mBaseColor);
+ // *HACK: Treat alpha as black
+ base_color_factor *= (mDetailMaterials[i]->mBaseColor.mV[VW]);
+ emissive_factor = mDetailMaterials[i]->mEmissiveColor;
+ has_base_color_factor = (base_color_factor.mV[VX] != 1.f ||
+ base_color_factor.mV[VY] != 1.f ||
+ base_color_factor.mV[VZ] != 1.f);
+ has_emissive_factor = (emissive_factor.mV[VX] != 1.f ||
+ emissive_factor.mV[VY] != 1.f ||
+ emissive_factor.mV[VZ] != 1.f);
+ }
+
+ if (!tex) { tex = LLViewerFetchedTexture::sWhiteImagep; }
+ // tex_emissive can be null, and then will be ignored
+
+ S32 min_dim = llmin(tex->getFullWidth(), tex->getFullHeight());
S32 ddiscard = 0;
while (min_dim > BASE_SIZE && ddiscard < MAX_DISCARD_LEVEL)
{
@@ -284,34 +485,92 @@ BOOL LLVLComposition::generateTexture(const F32 x, const F32 y,
min_dim /= 2;
}
- BOOL delete_raw = (mDetailTextures[i]->reloadRawImage(ddiscard) != NULL) ;
- if(mDetailTextures[i]->getRawImageLevel() != ddiscard)//raw iamge is not ready, will enter here again later.
+ BOOL delete_raw = (tex->reloadRawImage(ddiscard) != NULL) ;
+ if(tex->getRawImageLevel() != ddiscard)
{
- if (mDetailTextures[i]->getFetchPriority() <= 0.0f && !mDetailTextures[i]->hasSavedRawImage())
+ // Raw image is not ready, will enter here again later.
+ if (tex->getFetchPriority() <= 0.0f && !tex->hasSavedRawImage())
{
- mDetailTextures[i]->setBoostLevel(LLGLTexture::BOOST_MAP);
- mDetailTextures[i]->forceToRefetchTexture(ddiscard);
+ tex->setBoostLevel(LLGLTexture::BOOST_MAP);
+ tex->forceToRefetchTexture(ddiscard);
}
if(delete_raw)
{
- mDetailTextures[i]->destroyRawImage() ;
+ tex->destroyRawImage() ;
}
- LL_DEBUGS("Terrain") << "cached raw data for terrain detail texture is not ready yet: " << mDetailTextures[i]->getID() << " Discard: " << ddiscard << LL_ENDL;
return FALSE;
}
+ if (tex_emissive)
+ {
+ if(tex_emissive->getRawImageLevel() != ddiscard)
+ {
+ // Raw image is not ready, will enter here again later.
+ if (tex_emissive->getFetchPriority() <= 0.0f && !tex_emissive->hasSavedRawImage())
+ {
+ tex_emissive->setBoostLevel(LLGLTexture::BOOST_MAP);
+ tex_emissive->forceToRefetchTexture(ddiscard);
+ }
+
+ if(delete_raw)
+ {
+ tex_emissive->destroyRawImage() ;
+ }
+ return FALSE;
+ }
+ }
- mRawImages[i] = mDetailTextures[i]->getRawImage() ;
+ mRawImages[i] = tex->getRawImage() ;
if(delete_raw)
{
- mDetailTextures[i]->destroyRawImage() ;
+ tex->destroyRawImage() ;
}
- if (mDetailTextures[i]->getWidth(ddiscard) != BASE_SIZE ||
- mDetailTextures[i]->getHeight(ddiscard) != BASE_SIZE ||
- mDetailTextures[i]->getComponents() != 3)
+
+ // *TODO: This isn't quite right for PBR:
+ // 1) It does not convert the color images from SRGB to linear
+ // before mixing (which will always require copying the image).
+ // 2) It mixes emissive and base color before mixing terrain
+ // materials, but it should be the other way around
+ // 3) The composite function used to put emissive into base color
+ // is not an alpha blend.
+ // Long-term, we should consider a method that is more
+ // maintainable. Shaders, perhaps? Bake shaders to textures?
+ LLPointer<LLImageRaw> raw_emissive;
+ if (tex_emissive)
+ {
+ raw_emissive = tex_emissive->getRawImage();
+ if (has_emissive_factor ||
+ tex_emissive->getWidth(ddiscard) != BASE_SIZE ||
+ tex_emissive->getHeight(ddiscard) != BASE_SIZE ||
+ tex_emissive->getComponents() != 4)
+ {
+ LLPointer<LLImageRaw> newraw_emissive = new LLImageRaw(BASE_SIZE, BASE_SIZE, 4);
+ // Copy RGB, leave alpha alone (set to opaque by default)
+ newraw_emissive->copy(mRawImages[i]);
+ if (has_emissive_factor)
+ {
+ newraw_emissive->tint(emissive_factor);
+ }
+ raw_emissive = newraw_emissive; // deletes old
+ }
+ }
+ if (has_base_color_factor ||
+ raw_emissive ||
+ tex->getWidth(ddiscard) != BASE_SIZE ||
+ tex->getHeight(ddiscard) != BASE_SIZE ||
+ tex->getComponents() != 3)
{
LLPointer<LLImageRaw> newraw = new LLImageRaw(BASE_SIZE, BASE_SIZE, 3);
newraw->composite(mRawImages[i]);
+ if (has_base_color_factor)
+ {
+ newraw->tint(base_color_factor);
+ }
+ // Apply emissive texture
+ if (raw_emissive)
+ {
+ newraw->composite(raw_emissive);
+ }
mRawImages[i] = newraw; // deletes old
}
}
@@ -333,12 +592,12 @@ BOOL LLVLComposition::generateTexture(const F32 x, const F32 y,
if (x_end > mWidth)
{
- LL_WARNS("Terrain") << "x end > width" << LL_ENDL;
+ llassert(false);
x_end = mWidth;
}
if (y_end > mWidth)
{
- LL_WARNS("Terrain") << "y end > width" << LL_ENDL;
+ llassert(false);
y_end = mWidth;
}
@@ -368,7 +627,7 @@ BOOL LLVLComposition::generateTexture(const F32 x, const F32 y,
if (tex_comps != st_comps)
{
- LL_WARNS("Terrain") << "Base texture comps != input texture comps" << LL_ENDL;
+ llassert(false);
return FALSE;
}
@@ -459,7 +718,7 @@ BOOL LLVLComposition::generateTexture(const F32 x, const F32 y,
}
texturep->setSubImage(raw, tex_x_begin, tex_y_begin, tex_x_end - tex_x_begin, tex_y_end - tex_y_begin);
- for (S32 i = 0; i < 4; i++)
+ for (S32 i = 0; i < ASSET_COUNT; i++)
{
// Un-boost detatil textures (will get re-boosted if rendering in high detail)
mDetailTextures[i]->setBoostLevel(LLGLTexture::BOOST_NONE);
@@ -469,19 +728,19 @@ BOOL LLVLComposition::generateTexture(const F32 x, const F32 y,
return TRUE;
}
-LLUUID LLVLComposition::getDetailTextureID(S32 corner)
-{
- return mDetailTextures[corner]->getID();
-}
-
-LLViewerFetchedTexture* LLVLComposition::getDetailTexture(S32 corner)
+F32 LLVLComposition::getStartHeight(S32 corner)
{
- return mDetailTextures[corner];
+ return mStartHeight[corner];
}
-F32 LLVLComposition::getStartHeight(S32 corner)
+void LLVLComposition::setDetailAssetID(S32 asset, const LLUUID& id)
{
- return mStartHeight[corner];
+ if (id.isNull())
+ {
+ return;
+ }
+ LLTerrainMaterials::setDetailAssetID(asset, id);
+ mRawImages[asset] = NULL;
}
void LLVLComposition::setStartHeight(S32 corner, const F32 start_height)
diff --git a/indra/newview/llvlcomposition.h b/indra/newview/llvlcomposition.h
index 2dd04ac5a5..d59c0f95bb 100644
--- a/indra/newview/llvlcomposition.h
+++ b/indra/newview/llvlcomposition.h
@@ -28,11 +28,54 @@
#define LL_LLVLCOMPOSITION_H
#include "llviewerlayer.h"
-#include "llviewertexture.h"
+#include "llpointer.h"
+
+#include "llimage.h"
class LLSurface;
-class LLVLComposition : public LLViewerLayer
+class LLViewerFetchedTexture;
+class LLFetchedGLTFMaterial;
+
+class LLTerrainMaterials
+{
+public:
+ friend class LLDrawPoolTerrain;
+
+ LLTerrainMaterials();
+ virtual ~LLTerrainMaterials();
+
+ // Heights map into textures (or materials) as 0-1 = first, 1-2 = second, etc.
+ // So we need to compress heights into this range.
+ static const S32 ASSET_COUNT = 4;
+
+ enum class Type
+ {
+ TEXTURE,
+ PBR,
+ COUNT
+ };
+
+ BOOL generateMaterials();
+
+ LLUUID getDetailAssetID(S32 asset);
+ virtual void setDetailAssetID(S32 asset, const LLUUID& id);
+ Type getMaterialType();
+ BOOL texturesReady(BOOL boost = FALSE);
+ BOOL materialsReady(BOOL boost = FALSE);
+
+protected:
+ static BOOL textureReady(LLPointer<LLViewerFetchedTexture>& tex, BOOL boost = FALSE);
+ static BOOL materialReady(LLPointer<LLFetchedGLTFMaterial>& mat, bool& textures_set, BOOL boost = FALSE);
+ LLPointer<LLViewerFetchedTexture> mDetailTextures[ASSET_COUNT];
+ LLPointer<LLFetchedGLTFMaterial> mDetailMaterials[ASSET_COUNT];
+ bool mMaterialTexturesSet[ASSET_COUNT];
+};
+
+// Local materials to override all regions
+extern LLTerrainMaterials gLocalTerrainMaterials;
+
+class LLVLComposition : public LLTerrainMaterials, public LLViewerLayer
{
public:
LLVLComposition(LLSurface *surfacep, const U32 width, const F32 scale);
@@ -44,7 +87,11 @@ public:
BOOL generateHeights(const F32 x, const F32 y, const F32 width, const F32 height);
BOOL generateComposition();
// Generate texture from composition values.
- BOOL generateTexture(const F32 x, const F32 y, const F32 width, const F32 height);
+ BOOL generateMinimapTileLand(const F32 x, const F32 y, const F32 width, const F32 height);
+
+ // Heights map into textures (or materials) as 0-1 = first, 1-2 = second, etc.
+ // So we need to compress heights into this range.
+ static const S32 ASSET_COUNT = 4;
// Use these as indeces ito the get/setters below that use 'corner'
enum ECorner
@@ -55,12 +102,11 @@ public:
NORTHEAST = 3,
CORNER_COUNT = 4
};
- LLUUID getDetailTextureID(S32 corner);
- LLViewerFetchedTexture* getDetailTexture(S32 corner);
+
+ void setDetailAssetID(S32 asset, const LLUUID& id) override;
F32 getStartHeight(S32 corner);
F32 getHeightRange(S32 corner);
- void setDetailTextureID(S32 corner, const LLUUID& id);
void setStartHeight(S32 corner, F32 start_height);
void setHeightRange(S32 corner, F32 range);
@@ -68,19 +114,21 @@ public:
friend class LLDrawPoolTerrain;
void setParamsReady() { mParamsReady = TRUE; }
BOOL getParamsReady() const { return mParamsReady; }
+
protected:
- BOOL mParamsReady;
+ static BOOL textureReady(LLPointer<LLViewerFetchedTexture>& tex, BOOL boost = FALSE);
+ static BOOL materialReady(LLPointer<LLFetchedGLTFMaterial>& mat, bool& textures_set, BOOL boost = FALSE);
+
+ BOOL mParamsReady = FALSE;
LLSurface *mSurfacep;
- BOOL mTexturesLoaded;
- LLPointer<LLViewerFetchedTexture> mDetailTextures[CORNER_COUNT];
- LLPointer<LLImageRaw> mRawImages[CORNER_COUNT];
+ LLPointer<LLImageRaw> mRawImages[LLTerrainMaterials::ASSET_COUNT];
F32 mStartHeight[CORNER_COUNT];
F32 mHeightRange[CORNER_COUNT];
- F32 mTexScaleX;
- F32 mTexScaleY;
+ F32 mTexScaleX = 16.f;
+ F32 mTexScaleY = 16.f;
};
#endif //LL_LLVLCOMPOSITION_H
diff --git a/indra/newview/llvosurfacepatch.cpp b/indra/newview/llvosurfacepatch.cpp
index 15fabf0414..69b9476d38 100644
--- a/indra/newview/llvosurfacepatch.cpp
+++ b/indra/newview/llvosurfacepatch.cpp
@@ -39,6 +39,7 @@
#include "llviewerobjectlist.h"
#include "llviewerregion.h"
#include "llvlcomposition.h"
+#include "llvolume.h"
#include "llvovolume.h"
#include "pipeline.h"
#include "llspatialpartition.h"
@@ -213,6 +214,7 @@ BOOL LLVOSurfacePatch::updateGeometry(LLDrawable *drawable)
void LLVOSurfacePatch::updateFaceSize(S32 idx)
{
+ LL_PROFILE_ZONE_SCOPED;
if (idx != 0)
{
LL_WARNS() << "Terrain partition requested invalid face!!!" << LL_ENDL;
@@ -241,48 +243,50 @@ BOOL LLVOSurfacePatch::updateLOD()
return TRUE;
}
-void LLVOSurfacePatch::getGeometry(LLStrider<LLVector3> &verticesp,
- LLStrider<LLVector3> &normalsp,
- LLStrider<LLVector2> &texCoords0p,
- LLStrider<LLVector2> &texCoords1p,
- LLStrider<U16> &indicesp)
+void LLVOSurfacePatch::getTerrainGeometry(LLStrider<LLVector3> &verticesp,
+ LLStrider<LLVector3> &normalsp,
+ LLStrider<LLVector2> &texCoords0p,
+ LLStrider<LLVector2> &texCoords1p,
+ LLStrider<U16> &indicesp)
{
LLFace* facep = mDrawable->getFace(0);
- if (facep)
- {
- U32 index_offset = facep->getGeomIndex();
-
- updateMainGeometry(facep,
- verticesp,
- normalsp,
- texCoords0p,
- texCoords1p,
- indicesp,
- index_offset);
- updateNorthGeometry(facep,
- verticesp,
- normalsp,
- texCoords0p,
- texCoords1p,
- indicesp,
- index_offset);
- updateEastGeometry(facep,
- verticesp,
- normalsp,
- texCoords0p,
- texCoords1p,
- indicesp,
- index_offset);
- }
+ if (!facep)
+ {
+ return;
+ }
+
+ U32 index_offset = facep->getGeomIndex();
+
+ updateMainGeometry(facep,
+ verticesp,
+ normalsp,
+ texCoords0p,
+ texCoords1p,
+ indicesp,
+ index_offset);
+ updateNorthGeometry(facep,
+ verticesp,
+ normalsp,
+ texCoords0p,
+ texCoords1p,
+ indicesp,
+ index_offset);
+ updateEastGeometry(facep,
+ verticesp,
+ normalsp,
+ texCoords0p,
+ texCoords1p,
+ indicesp,
+ index_offset);
}
void LLVOSurfacePatch::updateMainGeometry(LLFace *facep,
- LLStrider<LLVector3> &verticesp,
- LLStrider<LLVector3> &normalsp,
- LLStrider<LLVector2> &texCoords0p,
- LLStrider<LLVector2> &texCoords1p,
- LLStrider<U16> &indicesp,
- U32 &index_offset)
+ LLStrider<LLVector3> &verticesp,
+ LLStrider<LLVector3> &normalsp,
+ LLStrider<LLVector2> &texCoords0p,
+ LLStrider<LLVector2> &texCoords1p,
+ LLStrider<U16> &indicesp,
+ U32 &index_offset)
{
S32 i, j, x, y;
@@ -381,12 +385,12 @@ void LLVOSurfacePatch::updateMainGeometry(LLFace *facep,
void LLVOSurfacePatch::updateNorthGeometry(LLFace *facep,
- LLStrider<LLVector3> &verticesp,
- LLStrider<LLVector3> &normalsp,
- LLStrider<LLVector2> &texCoords0p,
- LLStrider<LLVector2> &texCoords1p,
- LLStrider<U16> &indicesp,
- U32 &index_offset)
+ LLStrider<LLVector3> &verticesp,
+ LLStrider<LLVector3> &normalsp,
+ LLStrider<LLVector2> &texCoords0p,
+ LLStrider<LLVector2> &texCoords1p,
+ LLStrider<U16> &indicesp,
+ U32 &index_offset)
{
S32 i, x, y;
@@ -571,12 +575,12 @@ void LLVOSurfacePatch::updateNorthGeometry(LLFace *facep,
}
void LLVOSurfacePatch::updateEastGeometry(LLFace *facep,
- LLStrider<LLVector3> &verticesp,
- LLStrider<LLVector3> &normalsp,
- LLStrider<LLVector2> &texCoords0p,
- LLStrider<LLVector2> &texCoords1p,
- LLStrider<U16> &indicesp,
- U32 &index_offset)
+ LLStrider<LLVector3> &verticesp,
+ LLStrider<LLVector3> &normalsp,
+ LLStrider<LLVector2> &texCoords0p,
+ LLStrider<LLVector2> &texCoords1p,
+ LLStrider<U16> &indicesp,
+ U32 &index_offset)
{
S32 i, x, y;
@@ -982,6 +986,49 @@ LLTerrainPartition::LLTerrainPartition(LLViewerRegion* regionp)
mPartitionType = LLViewerRegion::PARTITION_TERRAIN;
}
+// Do not add vertices; honor strict vertex count specified by strider_vertex_count
+void gen_terrain_tangents(U16 strider_vertex_count,
+ U32 strider_index_count,
+ LLStrider<LLVector3> &verticesp,
+ LLStrider<LLVector3> &normalsp,
+ LLStrider<LLVector4a> &tangentsp,
+ LLStrider<LLVector2> &texCoords0p,
+ LLStrider<U16> &indicesp)
+{
+ LL_PROFILE_ZONE_SCOPED
+
+ LLVector4a *vertices = new LLVector4a[strider_vertex_count];
+ LLVector4a *normals = new LLVector4a[strider_vertex_count];
+ LLVector4a *tangents = new LLVector4a[strider_vertex_count];
+ std::vector<LLVector2> texcoords(strider_vertex_count);
+ std::vector<U16> indices(strider_index_count);
+
+ for (U16 v = 0; v < strider_vertex_count; ++v)
+ {
+ F32 *vert = verticesp[v].mV;
+ vertices[v] = LLVector4a(vert[0], vert[1], vert[2], 1.f);
+ F32 *n = normalsp[v].mV;
+ normals[v] = LLVector4a(n[0], n[1], n[2], 1.f);
+ tangents[v] = tangentsp[v];
+ texcoords[v] = texCoords0p[v];
+ }
+ for (U32 i = 0; i < strider_index_count; ++i)
+ {
+ indices[i] = indicesp[i];
+ }
+
+ LLCalculateTangentArray(strider_vertex_count, vertices, normals, texcoords.data(), strider_index_count / 3, indices.data(), tangents);
+
+ for (U16 v = 0; v < strider_vertex_count; ++v)
+ {
+ tangentsp[v] = tangents[v];
+ }
+
+ delete[] vertices;
+ delete[] normals;
+ delete[] tangents;
+}
+
void LLTerrainPartition::getGeometry(LLSpatialGroup* group)
{
LL_PROFILE_ZONE_SCOPED;
@@ -989,35 +1036,57 @@ void LLTerrainPartition::getGeometry(LLSpatialGroup* group)
LLVertexBuffer* buffer = group->mVertexBuffer;
//get vertex buffer striders
- LLStrider<LLVector3> vertices;
- LLStrider<LLVector3> normals;
- LLStrider<LLVector2> texcoords2;
- LLStrider<LLVector2> texcoords;
- LLStrider<U16> indices;
-
- llassert_always(buffer->getVertexStrider(vertices));
- llassert_always(buffer->getNormalStrider(normals));
- llassert_always(buffer->getTexCoord0Strider(texcoords));
- llassert_always(buffer->getTexCoord1Strider(texcoords2));
- llassert_always(buffer->getIndexStrider(indices));
-
- U32 indices_index = 0;
- U32 index_offset = 0;
-
- for (std::vector<LLFace*>::iterator i = mFaceList.begin(); i != mFaceList.end(); ++i)
- {
- LLFace* facep = *i;
-
- facep->setIndicesIndex(indices_index);
- facep->setGeomIndex(index_offset);
- facep->setVertexBuffer(buffer);
-
- LLVOSurfacePatch* patchp = (LLVOSurfacePatch*) facep->getViewerObject();
- patchp->getGeometry(vertices, normals, texcoords, texcoords2, indices);
-
- indices_index += facep->getIndicesCount();
- index_offset += facep->getGeomCount();
- }
+ LLStrider<LLVector3> vertices_start;
+ LLStrider<LLVector3> normals_start;
+ LLStrider<LLVector4a> tangents_start;
+ LLStrider<LLVector2> texcoords_start;
+ LLStrider<LLVector2> texcoords2_start;
+ LLStrider<U16> indices_start;
+
+ llassert_always(buffer->getVertexStrider(vertices_start));
+ llassert_always(buffer->getNormalStrider(normals_start));
+ llassert_always(buffer->getTangentStrider(tangents_start));
+ llassert_always(buffer->getTexCoord0Strider(texcoords_start));
+ llassert_always(buffer->getTexCoord1Strider(texcoords2_start));
+ llassert_always(buffer->getIndexStrider(indices_start));
+
+ U32 indices_index = 0;
+ U32 index_offset = 0;
+
+ {
+ LLStrider<LLVector3> vertices = vertices_start;
+ LLStrider<LLVector3> normals = normals_start;
+ LLStrider<LLVector2> texcoords = texcoords_start;
+ LLStrider<LLVector2> texcoords2 = texcoords2_start;
+ LLStrider<U16> indices = indices_start;
+
+ for (std::vector<LLFace*>::iterator i = mFaceList.begin(); i != mFaceList.end(); ++i)
+ {
+ LLFace* facep = *i;
+
+ facep->setIndicesIndex(indices_index);
+ facep->setGeomIndex(index_offset);
+ facep->setVertexBuffer(buffer);
+
+ LLVOSurfacePatch* patchp = (LLVOSurfacePatch*) facep->getViewerObject();
+ patchp->getTerrainGeometry(vertices, normals, texcoords, texcoords2, indices);
+
+ indices_index += facep->getIndicesCount();
+ index_offset += facep->getGeomCount();
+ }
+ }
+
+ const bool has_tangents = tangents_start.get() != nullptr;
+ if (has_tangents)
+ {
+ LLStrider<LLVector3> vertices = vertices_start;
+ LLStrider<LLVector3> normals = normals_start;
+ LLStrider<LLVector4a> tangents = tangents_start;
+ LLStrider<LLVector2> texcoords = texcoords_start;
+ LLStrider<U16> indices = indices_start;
+
+ gen_terrain_tangents(index_offset, indices_index, vertices, normals, tangents, texcoords, indices);
+ }
buffer->unmapBuffer();
mFaceList.clear();
diff --git a/indra/newview/llvosurfacepatch.h b/indra/newview/llvosurfacepatch.h
index aed67162d1..a3dcb945d1 100644
--- a/indra/newview/llvosurfacepatch.h
+++ b/indra/newview/llvosurfacepatch.h
@@ -63,11 +63,11 @@ public:
/*virtual*/ BOOL updateGeometry(LLDrawable *drawable);
/*virtual*/ BOOL updateLOD();
/*virtual*/ void updateFaceSize(S32 idx);
- void getGeometry(LLStrider<LLVector3> &verticesp,
- LLStrider<LLVector3> &normalsp,
- LLStrider<LLVector2> &texCoords0p,
- LLStrider<LLVector2> &texCoords1p,
- LLStrider<U16> &indicesp);
+ void getTerrainGeometry(LLStrider<LLVector3> &verticesp,
+ LLStrider<LLVector3> &normalsp,
+ LLStrider<LLVector2> &texCoords0p,
+ LLStrider<LLVector2> &texCoords1p,
+ LLStrider<U16> &indicesp);
/*virtual*/ void updateTextures();
/*virtual*/ void setPixelAreaAndAngle(LLAgent &agent); // generate accurate apparent angle and area
diff --git a/indra/newview/llvovolume.cpp b/indra/newview/llvovolume.cpp
index ec2f490742..9813039145 100644
--- a/indra/newview/llvovolume.cpp
+++ b/indra/newview/llvovolume.cpp
@@ -249,6 +249,9 @@ LLVOVolume::~LLVOVolume()
mTextureAnimp = NULL;
delete mVolumeImpl;
mVolumeImpl = NULL;
+
+ if (mIsMirror)
+ gPipeline.mHeroProbeManager.unregisterHeroDrawable(this);
gMeshRepo.unregisterMesh(this);
@@ -996,7 +999,12 @@ LLDrawable *LLVOVolume::createDrawable(LLPipeline *pipeline)
{
updateReflectionProbePtr();
}
-
+
+ if (isMirror())
+ {
+ gPipeline.mHeroProbeManager.registerHeroDrawable(this);
+ }
+
updateRadius();
bool force_update = true; // avoid non-alpha mDistance update being optimized away
mDrawable->updateDistance(*LLViewerCamera::getInstance(), force_update);
@@ -3319,6 +3327,48 @@ F32 LLVOVolume::getLightCutoff() const
}
}
+bool LLVOVolume::setIsMirror(BOOL is_mirror)
+{
+ BOOL was_mirror = isMirror();
+ if (is_mirror != was_mirror)
+ {
+ if (is_mirror)
+ {
+ setParameterEntryInUse(LLNetworkData::PARAMS_MIRROR, TRUE, true);
+ }
+ else
+ {
+ setParameterEntryInUse(LLNetworkData::PARAMS_MIRROR, FALSE, true);
+ }
+ }
+
+ updateMirrorDrawable();
+
+ return was_mirror != is_mirror;
+}
+
+void LLVOVolume::updateMirrorDrawable()
+{
+ if (isMirror())
+ {
+ gPipeline.mHeroProbeManager.registerHeroDrawable(this);
+ }
+ else
+ {
+ gPipeline.mHeroProbeManager.unregisterHeroDrawable(this);
+ }
+}
+
+BOOL LLVOVolume::isMirror() const
+{
+ return mIsMirror;
+}
+
+U8 LLVOVolume::mirrorFace() const
+{
+ return mMirrorFace;
+}
+
BOOL LLVOVolume::isReflectionProbe() const
{
return getParameterEntryInUse(LLNetworkData::PARAMS_REFLECTION_PROBE);
@@ -4369,6 +4419,11 @@ void LLVOVolume::parameterChanged(U16 param_type, LLNetworkData* data, BOOL in_u
}
updateReflectionProbePtr();
+
+ if (isMirror())
+ gPipeline.mHeroProbeManager.registerHeroDrawable(this);
+ else
+ gPipeline.mHeroProbeManager.unregisterHeroDrawable(this);
}
void LLVOVolume::updateReflectionProbePtr()
diff --git a/indra/newview/llvovolume.h b/indra/newview/llvovolume.h
index aadc1fbcf3..b03fc4b862 100644
--- a/indra/newview/llvovolume.h
+++ b/indra/newview/llvovolume.h
@@ -294,6 +294,11 @@ public:
F32 getLightRadius() const;
F32 getLightFalloff(const F32 fudge_factor = 1.f) const;
F32 getLightCutoff() const;
+
+ // Mirrors
+ bool setIsMirror(BOOL is_mirror);
+ void updateMirrorDrawable();
+ U8 mirrorFace() const override;
// Reflection Probes
bool setIsReflectionProbe(BOOL is_probe);
@@ -307,6 +312,8 @@ public:
F32 getReflectionProbeNearClip() const;
bool getReflectionProbeIsBox() const;
bool getReflectionProbeIsDynamic() const;
+
+ BOOL isMirror() const override;
// Flexible Objects
U32 getVolumeInterfaceID() const;
diff --git a/indra/newview/pipeline.cpp b/indra/newview/pipeline.cpp
index 3a1edb0d00..d63b9d317e 100644
--- a/indra/newview/pipeline.cpp
+++ b/indra/newview/pipeline.cpp
@@ -198,8 +198,11 @@ F32 LLPipeline::RenderScreenSpaceReflectionDepthRejectBias;
F32 LLPipeline::RenderScreenSpaceReflectionAdaptiveStepMultiplier;
S32 LLPipeline::RenderScreenSpaceReflectionGlossySamples;
S32 LLPipeline::RenderBufferVisualization;
+bool LLPipeline::RenderMirrors;
LLTrace::EventStatHandle<S64> LLPipeline::sStatBatchSize("renderbatchsize");
+const U32 LLPipeline::MAX_BAKE_WIDTH = 512;
+
const F32 BACKLIGHT_DAY_MAGNITUDE_OBJECT = 0.1f;
const F32 BACKLIGHT_NIGHT_MAGNITUDE_OBJECT = 0.08f;
const F32 ALPHA_BLEND_CUTOFF = 0.598f;
@@ -555,6 +558,7 @@ void LLPipeline::init()
connectRefreshCachedSettingsSafe("RenderScreenSpaceReflectionAdaptiveStepMultiplier");
connectRefreshCachedSettingsSafe("RenderScreenSpaceReflectionGlossySamples");
connectRefreshCachedSettingsSafe("RenderBufferVisualization");
+ connectRefreshCachedSettingsSafe("RenderMirrors");
gSavedSettings.getControl("RenderAutoHideSurfaceAreaLimit")->getCommitSignal()->connect(boost::bind(&LLPipeline::refreshCachedSettings));
}
@@ -638,6 +642,7 @@ void LLPipeline::cleanup()
mCubeVB = NULL;
mReflectionMapManager.cleanup();
+ mHeroProbeManager.cleanup();
}
//============================================================================
@@ -764,10 +769,19 @@ LLPipeline::eFBOStatus LLPipeline::doAllocateScreenBuffer(U32 resX, U32 resY)
bool LLPipeline::allocateScreenBuffer(U32 resX, U32 resY, U32 samples)
{
LL_PROFILE_ZONE_SCOPED_CATEGORY_DISPLAY;
- if (mRT == &mMainRT && sReflectionProbesEnabled)
+ if (mRT == &mMainRT)
{ // hacky -- allocate auxillary buffer
+
gCubeSnapshot = TRUE;
mReflectionMapManager.initReflectionMaps();
+ mHeroProbeManager.initReflectionMaps();
+
+ if (sReflectionProbesEnabled)
+ {
+ gCubeSnapshot = TRUE;
+ mReflectionMapManager.initReflectionMaps();
+ }
+
mRT = &mAuxillaryRT;
U32 res = mReflectionMapManager.mProbeResolution * 4; //multiply by 4 because probes will be 16x super sampled
allocateScreenBuffer(res, res, samples);
@@ -1043,6 +1057,7 @@ void LLPipeline::refreshCachedSettings()
RenderScreenSpaceReflectionAdaptiveStepMultiplier = gSavedSettings.getF32("RenderScreenSpaceReflectionAdaptiveStepMultiplier");
RenderScreenSpaceReflectionGlossySamples = gSavedSettings.getS32("RenderScreenSpaceReflectionGlossySamples");
RenderBufferVisualization = gSavedSettings.getS32("RenderBufferVisualization");
+ RenderMirrors = gSavedSettings.getBOOL("RenderMirrors");
sReflectionProbesEnabled = LLFeatureManager::getInstance()->isFeatureAvailable("RenderReflectionsEnabled") && gSavedSettings.getBOOL("RenderReflectionsEnabled");
RenderSpotLight = nullptr;
@@ -1072,7 +1087,6 @@ void LLPipeline::releaseGLBuffers()
releaseLUTBuffers();
mWaterDis.release();
- mBake.release();
mSceneMap.release();
@@ -1151,9 +1165,6 @@ void LLPipeline::createGLBuffers()
stop_glerror();
assertInitialized();
- // Use FBO for bake tex
- mBake.allocate(512, 512, GL_RGBA, true); // SL-12781 Build > Upload > Model; 3D Preview
-
stop_glerror();
GLuint resX = gViewerWindow->getWorldViewWidthRaw();
@@ -2394,6 +2405,26 @@ void LLPipeline::doOcclusion(LLCamera& camera)
gGL.setColorMask(true, true);
}
+
+ if (sReflectionProbesEnabled && sUseOcclusion > 1 && !LLPipeline::sShadowRender && !gCubeSnapshot)
+ {
+ gGL.setColorMask(false, false);
+ LLGLDepthTest depth(GL_TRUE, GL_FALSE);
+ LLGLDisable cull(GL_CULL_FACE);
+
+ gOcclusionCubeProgram.bind();
+
+ if (mCubeVB.isNull())
+ { //cube VB will be used for issuing occlusion queries
+ mCubeVB = ll_create_cube_vb(LLVertexBuffer::MAP_VERTEX);
+ }
+ mCubeVB->setBuffer();
+
+ mHeroProbeManager.doOcclusion();
+ gOcclusionCubeProgram.unbind();
+
+ gGL.setColorMask(true, true);
+ }
if (LLPipeline::sUseOcclusion > 1 &&
(sCull->hasOcclusionGroups() || LLVOCachePartition::sNeedsOcclusionCheck))
@@ -3771,6 +3802,7 @@ void LLPipeline::renderGeomDeferred(LLCamera& camera, bool do_occlusion)
{
//update reflection probe uniform
mReflectionMapManager.updateUniforms();
+ mHeroProbeManager.updateUniforms();
}
U32 cur_type = 0;
@@ -6536,7 +6568,7 @@ void LLPipeline::renderAlphaObjects(bool rigged)
LLGLSLShader::sCurBoundShaderPtr->uniform1i(LLShaderMgr::SUN_UP_FACTOR, sun_up);
LLGLSLShader::sCurBoundShaderPtr->uniform1f(LLShaderMgr::DEFERRED_SHADOW_TARGET_WIDTH, (float)target_width);
LLGLSLShader::sCurBoundShaderPtr->setMinimumAlpha(ALPHA_BLEND_CUTOFF);
- mSimplePool->pushRiggedGLTFBatch(*pparams, lastAvatar, lastMeshId);
+ LLRenderPass::pushRiggedGLTFBatch(*pparams, lastAvatar, lastMeshId);
}
else
{
@@ -6562,7 +6594,7 @@ void LLPipeline::renderAlphaObjects(bool rigged)
LLGLSLShader::sCurBoundShaderPtr->uniform1i(LLShaderMgr::SUN_UP_FACTOR, sun_up);
LLGLSLShader::sCurBoundShaderPtr->uniform1f(LLShaderMgr::DEFERRED_SHADOW_TARGET_WIDTH, (float)target_width);
LLGLSLShader::sCurBoundShaderPtr->setMinimumAlpha(ALPHA_BLEND_CUTOFF);
- mSimplePool->pushGLTFBatch(*pparams);
+ LLRenderPass::pushGLTFBatch(*pparams);
}
else
{
@@ -8209,6 +8241,7 @@ void LLPipeline::renderDeferredLighting()
LLPipeline::RENDER_TYPE_CONTROL_AV,
LLPipeline::RENDER_TYPE_ALPHA_MASK,
LLPipeline::RENDER_TYPE_FULLBRIGHT_ALPHA_MASK,
+ LLPipeline::RENDER_TYPE_TERRAIN,
LLPipeline::RENDER_TYPE_WATER,
END_RENDER_TYPES);
@@ -8359,7 +8392,7 @@ void LLPipeline::doWaterHaze()
else
{
//render water patches like LLDrawPoolWater does
- LLGLDepthTest depth(GL_FALSE);
+ LLGLDepthTest depth(GL_TRUE, GL_FALSE);
LLGLDisable cull(GL_CULL_FACE);
gGLLastMatrix = NULL;
@@ -8612,6 +8645,17 @@ void LLPipeline::bindReflectionProbes(LLGLSLShader& shader)
mReflectionMapManager.mIrradianceMaps->bind(channel);
bound = true;
}
+
+ if (RenderMirrors)
+ {
+ channel = shader.enableTexture(LLShaderMgr::HERO_PROBE, LLTexUnit::TT_CUBE_MAP_ARRAY);
+ if (channel > -1 && mHeroProbeManager.mTexture.notNull())
+ {
+ mHeroProbeManager.mTexture->bind(channel);
+ bound = true;
+ }
+ }
+
if (bound)
{
@@ -10826,3 +10870,12 @@ void LLPipeline::rebuildDrawInfo()
}
}
+void LLPipeline::rebuildTerrain()
+{
+ for (LLWorld::region_list_t::const_iterator iter = LLWorld::getInstance()->getRegionList().begin();
+ iter != LLWorld::getInstance()->getRegionList().end(); ++iter)
+ {
+ LLViewerRegion* region = *iter;
+ region->dirtyAllPatches();
+ }
+}
diff --git a/indra/newview/pipeline.h b/indra/newview/pipeline.h
index 88a7eab813..fb28a0e41c 100644
--- a/indra/newview/pipeline.h
+++ b/indra/newview/pipeline.h
@@ -39,6 +39,7 @@
#include "lldrawable.h"
#include "llrendertarget.h"
#include "llreflectionmapmanager.h"
+#include "llheroprobemanager.h"
#include <stack>
@@ -133,6 +134,8 @@ public:
// rebuild all LLVOVolume render batches
void rebuildDrawInfo();
+ // Rebuild all terrain
+ void rebuildTerrain();
// Clear LLFace mVertexBuffer pointers
void resetVertexBuffers(LLDrawable* drawable);
@@ -458,6 +461,7 @@ public:
void handleShadowDetailChanged();
LLReflectionMapManager mReflectionMapManager;
+ LLHeroProbeManager mHeroProbeManager;
private:
void unloadShaders();
@@ -694,6 +698,7 @@ public:
RenderTargetPack mMainRT;
// auxillary 512x512 render target pack
+ // used by reflection probes and dynamic texture bakes
RenderTargetPack mAuxillaryRT;
// currently used render target pack
@@ -754,7 +759,7 @@ public:
//water distortion texture (refraction)
LLRenderTarget mWaterDis;
- LLRenderTarget mBake;
+ static const U32 MAX_BAKE_WIDTH;
//texture for making the glow
LLRenderTarget mGlow[3];
@@ -1047,6 +1052,7 @@ public:
static F32 RenderScreenSpaceReflectionAdaptiveStepMultiplier;
static S32 RenderScreenSpaceReflectionGlossySamples;
static S32 RenderBufferVisualization;
+ static bool RenderMirrors;
};
void render_bbox(const LLVector3 &min, const LLVector3 &max);
diff --git a/indra/newview/skins/default/xui/en/floater_tools.xml b/indra/newview/skins/default/xui/en/floater_tools.xml
index 9966fe0b56..510351b471 100644
--- a/indra/newview/skins/default/xui/en/floater_tools.xml
+++ b/indra/newview/skins/default/xui/en/floater_tools.xml
@@ -2410,7 +2410,15 @@ even though the user gets a free copy.
name="object_horizontal"
top_pad="10"
width="278" />
-
+ <check_box
+ height="16"
+ label="Mirror"
+ layout="topleft"
+ left="10"
+ name="Mirror Checkbox Ctrl"
+ tool_tip="Causes object to be a mirror"
+ top_pad="8"
+ width="60" />
<check_box
height="16"
label="Light"
diff --git a/indra/newview/skins/default/xui/en/menu_viewer.xml b/indra/newview/skins/default/xui/en/menu_viewer.xml
index 660f4b62c7..9b238693e0 100644
--- a/indra/newview/skins/default/xui/en/menu_viewer.xml
+++ b/indra/newview/skins/default/xui/en/menu_viewer.xml
@@ -3297,6 +3297,13 @@ function="World.EnvPreset"
<menu_item_call.on_click
function="Advanced.ClearShaderCache" />
</menu_item_call>
+ <menu_item_call
+ enabled="true"
+ label="Rebuild Terrain"
+ name="Rebuild Terrain">
+ <menu_item_call.on_click
+ function="Advanced.RebuildTerrain" />
+ </menu_item_call>
<menu_item_separator />
<menu_item_call
enabled="true"
diff --git a/indra/newview/skins/default/xui/en/notifications.xml b/indra/newview/skins/default/xui/en/notifications.xml
index d642ea162c..df9f53686e 100644
--- a/indra/newview/skins/default/xui/en/notifications.xml
+++ b/indra/newview/skins/default/xui/en/notifications.xml
@@ -4004,7 +4004,7 @@ Are you sure you want to return objects owned by [USER_NAME]?
Couldn&apos;t set region textures:
Terrain texture [TEXTURE_NUM] has an invalid bit depth of [TEXTURE_BIT_DEPTH].
-Replace texture [TEXTURE_NUM] with a 24-bit [MAX_SIZE]x[MAX_SIZE] or smaller image then click &quot;Apply&quot; again.
+Replace texture [TEXTURE_NUM] with an RGB [MAX_SIZE]x[MAX_SIZE] or smaller image then click &quot;Apply&quot; again.
<tag>fail</tag>
</notification>
@@ -4015,7 +4015,7 @@ Replace texture [TEXTURE_NUM] with a 24-bit [MAX_SIZE]x[MAX_SIZE] or smaller ima
Couldn&apos;t set region textures:
Terrain texture [TEXTURE_NUM] is too large at [TEXTURE_SIZE_X]x[TEXTURE_SIZE_Y].
-Replace texture [TEXTURE_NUM] with a 24-bit [MAX_SIZE]x[MAX_SIZE] or smaller image then click &quot;Apply&quot; again.
+Replace texture [TEXTURE_NUM] with an RGB [MAX_SIZE]x[MAX_SIZE] or smaller image then click &quot;Apply&quot; again.
</notification>
<notification
diff --git a/indra/newview/skins/default/xui/en/panel_region_terrain.xml b/indra/newview/skins/default/xui/en/panel_region_terrain.xml
index 2aaea04a6d..88855ab739 100644
--- a/indra/newview/skins/default/xui/en/panel_region_terrain.xml
+++ b/indra/newview/skins/default/xui/en/panel_region_terrain.xml
@@ -76,29 +76,61 @@
left="8"
top="30"
width="460" />
+ <combo_box
+ layout="topleft"
+ left="10"
+ top="105"
+ follows="left|top"
+ name="terrain_material_type"
+ width="170">
+ <combo_box.item
+ label="Terrain Textures"
+ name="Textures"
+ value="Textures" />
+ <combo_box.item
+ label="Terrain PBR Materials"
+ name="PBRMaterials"
+ value="PBRMaterials" />
+ </combo_box>
<text
type="string"
length="1"
follows="left|top"
+ halign="left"
+ valign="center"
height="20"
layout="topleft"
- left="10"
name="detail_texture_text"
- top="110"
- width="300">
- Terrain Textures (requires 1024x1024, 24 bit .tga files)
+ top_delta="0"
+ left_delta="0"
+ width="170">
+ Terrain Textures
+ </text>
+ <text
+ type="string"
+ length="1"
+ halign="left"
+ valign="center"
+ follows="left|top"
+ height="20"
+ layout="topleft"
+ top_delta="0"
+ left_delta="180"
+ name="detail_texture_limits_text"
+ width="200">
+ Maximum size: 1024x1024
</text>
<texture_picker
follows="left|top"
height="100"
layout="topleft"
- left_delta="0"
+ left="10"
name="texture_detail_0"
default_image_id="0bc58228-74a0-7e83-89bc-5c23464bcec5"
- top_delta="20"
+ top_delta="30"
width="100" />
<texture_picker
- follows="left|top"
+ follows="top"
height="100"
layout="topleft"
left_pad="10"
@@ -124,6 +156,50 @@
default_image_id="53a2f406-4895-1d13-d541-d2e3b86bc19c"
top_delta="0"
width="100" />
+ <texture_picker
+ visible="false"
+ follows="left|top"
+ height="100"
+ layout="topleft"
+ left="10"
+ name="material_detail_0"
+ pick_type="material"
+ allow_no_texture="true"
+ top_delta="0"
+ width="100" />
+ <texture_picker
+ visible="false"
+ follows="left|top"
+ height="100"
+ layout="topleft"
+ left_pad="10"
+ name="material_detail_1"
+ pick_type="material"
+ allow_no_texture="true"
+ top_delta="0"
+ width="100" />
+ <texture_picker
+ visible="false"
+ follows="left|top"
+ height="100"
+ layout="topleft"
+ left_pad="10"
+ name="material_detail_2"
+ pick_type="material"
+ allow_no_texture="true"
+ top_delta="0"
+ width="100" />
+ <texture_picker
+ visible="false"
+ follows="left|top"
+ height="100"
+ layout="topleft"
+ left_pad="10"
+ name="material_detail_3"
+ pick_type="material"
+ allow_no_texture="true"
+ top_delta="0"
+ width="100" />
<text
type="string"
length="1"
diff --git a/indra/newview/skins/default/xui/en/strings.xml b/indra/newview/skins/default/xui/en/strings.xml
index 5d33853adc..e405d9ea10 100644
--- a/indra/newview/skins/default/xui/en/strings.xml
+++ b/indra/newview/skins/default/xui/en/strings.xml
@@ -53,7 +53,6 @@ Draw distance: [DRAW_DISTANCE]m
Bandwidth: [NET_BANDWITH]kbit/s
LOD factor: [LOD_FACTOR]
Render quality: [RENDER_QUALITY]
-Advanced Lighting Model: [GPU_SHADERS]
Texture memory: [TEXTURE_MEMORY]MB
Disk cache: [DISK_CACHE_INFO]
</string>