Skip to content
2 changes: 2 additions & 0 deletions indra/llrender/llglslshader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ using std::string;
GLuint LLGLSLShader::sCurBoundShader = 0;
LLGLSLShader* LLGLSLShader::sCurBoundShaderPtr = NULL;
S32 LLGLSLShader::sIndexedTextureChannels = 0;
S32 LLGLSLShader::sIndexedGLTFChannels = 0;
bool LLGLSLShader::sIndexedLegacyMaterials = false;
U32 LLGLSLShader::sMaxGLTFMaterials = 0;
U32 LLGLSLShader::sMaxGLTFNodes = 0;
bool LLGLSLShader::sProfileEnabled = false;
Expand Down
11 changes: 11 additions & 0 deletions indra/llrender/llglslshader.h
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,17 @@ class LLGLSLShader
static LLGLSLShader* sCurBoundShaderPtr;
static S32 sIndexedTextureChannels;

// Number of GLTF PBR materials that can be batched into one indexed draw call.
// Each material consumes four texture units (base color, normal, ORM, emissive),
// so this is roughly (available fragment texture units) / 4. See
// PASS_GLTF_PBR_INDEXED and LLVolumeGeometryManager::genDrawInfo.
static S32 sIndexedGLTFChannels;

// True once the indexed legacy (Blinn-Phong) material programs have loaded.
// Gates indexed POOL_MATERIALS batching (shares sIndexedGLTFChannels for the
// per-slot stride); independent so a material-shader failure doesn't disable PBR.
static bool sIndexedLegacyMaterials;

static U32 sMaxGLTFMaterials;
static U32 sMaxGLTFNodes;

Expand Down
11 changes: 11 additions & 0 deletions indra/newview/app_settings/settings_alchemy.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1235,6 +1235,17 @@
<key>Value</key>
<integer>1</integer>
</map>
<key>RenderGLTFPBRBatching</key>
<map>
<key>Comment</key>
<string>Batch multiple materials into a single indexed draw call across the supported GLTF PBR and legacy material passes (opaque, alpha-mask, rigged, shadow, glow). 0 = one draw call per material (legacy), 1 = indexed multi-material batching. Reduces draw calls in material-heavy scenes.</string>
<key>Persist</key>
<integer>1</integer>
<key>Type</key>
<string>Boolean</string>
<key>Value</key>
<integer>1</integer>
</map>
<key>RenderBloomThreshold</key>
<map>
<key>Comment</key>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
/**
* @file emissiveIndexedF.glsl
*
* $LicenseInfo:firstyear=2007&license=viewerlgpl$
* Second Life Viewer Source Code
* Copyright (C) 2007, 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]*/

// Indexed (multi-material) variant of emissiveF.glsl (legacy glow). Only alpha is
// written. vary_material_index selects this primitive's diffuse map (bound to unit
// s); its alpha modulates the per-vertex glow factor. If-chains (not switch) are
// used for driver portability.

out vec4 frag_color;

in vec4 vertex_color;
in vec2 vary_texcoord0;
flat in int vary_material_index;

uniform sampler2D diffuse0;
#if GLTF_INDEXED_CHANNELS > 1
uniform sampler2D diffuse1;
#endif
#if GLTF_INDEXED_CHANNELS > 2
uniform sampler2D diffuse2;
#endif
#if GLTF_INDEXED_CHANNELS > 3
uniform sampler2D diffuse3;
#endif
#if GLTF_INDEXED_CHANNELS > 4
uniform sampler2D diffuse4;
#endif
#if GLTF_INDEXED_CHANNELS > 5
uniform sampler2D diffuse5;
#endif
#if GLTF_INDEXED_CHANNELS > 6
uniform sampler2D diffuse6;
#endif
#if GLTF_INDEXED_CHANNELS > 7
uniform sampler2D diffuse7;
#endif

vec4 sample_diffuse(vec2 uv)
{
if (vary_material_index == 0) return texture(diffuse0, uv);
#if GLTF_INDEXED_CHANNELS > 1
if (vary_material_index == 1) return texture(diffuse1, uv);
#endif
#if GLTF_INDEXED_CHANNELS > 2
if (vary_material_index == 2) return texture(diffuse2, uv);
#endif
#if GLTF_INDEXED_CHANNELS > 3
if (vary_material_index == 3) return texture(diffuse3, uv);
#endif
#if GLTF_INDEXED_CHANNELS > 4
if (vary_material_index == 4) return texture(diffuse4, uv);
#endif
#if GLTF_INDEXED_CHANNELS > 5
if (vary_material_index == 5) return texture(diffuse5, uv);
#endif
#if GLTF_INDEXED_CHANNELS > 6
if (vary_material_index == 6) return texture(diffuse6, uv);
#endif
#if GLTF_INDEXED_CHANNELS > 7
if (vary_material_index == 7) return texture(diffuse7, uv);
#endif
return vec4(1, 0, 1, 1);
}

void main()
{
// NOTE: when this shader is used, only alpha is being written to
float a = sample_diffuse(vary_texcoord0.xy).a * vertex_color.a;
frag_color = max(vec4(0, 0, 0, a), vec4(0));
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/**
* @file emissiveIndexedV.glsl
*
* $LicenseInfo:firstyear=2007&license=viewerlgpl$
* Second Life Viewer Source Code
* Copyright (C) 2007, 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$
*/

// Indexed (multi-material) variant of emissiveV.glsl (legacy glow). Forwards the
// per-vertex material slot to the fragment shader so each slot's diffuse alpha can
// be sampled. The diffuse texture transform is baked into texcoord0 at buffer build
// (indexed faces exclude texture animation), so texture_matrix0 is not applied.
// HAS_SKIN adds rigged matrix-palette skinning.

#ifdef HAS_SKIN
uniform mat4 modelview_matrix;
uniform mat4 projection_matrix;
mat4 getObjectSkinnedTransform();
#else
uniform mat4 modelview_projection_matrix;
#endif

in vec3 position;
in vec4 emissive;
in vec2 texcoord0;
in int texture_index;

flat out int vary_material_index;
out vec4 vertex_color;
out vec2 vary_texcoord0;

void main()
{
#ifdef HAS_SKIN
mat4 mat = getObjectSkinnedTransform();
mat = modelview_matrix * mat;
vec3 pos = (mat*vec4(position.xyz,1.0)).xyz;
gl_Position = projection_matrix*vec4(pos,1.0);
#else
gl_Position = modelview_projection_matrix * vec4(position.xyz, 1.0);
#endif

vary_material_index = texture_index;
vary_texcoord0 = texcoord0;
vertex_color = emissive;
}
Loading
Loading