SL-17274: Stub for PBR DrawPool and shader

master
Ptolemy 2022-05-02 10:05:13 -07:00
parent 82311e4b44
commit 54919fa749
12 changed files with 321 additions and 0 deletions

View File

@ -187,6 +187,7 @@ set(viewer_SOURCE_FILES
lldrawpoolbump.cpp
lldrawpoolground.cpp
lldrawpoolmaterials.cpp
lldrawpoolpbropaque.cpp
lldrawpoolsimple.cpp
lldrawpoolsky.cpp
lldrawpoolterrain.cpp
@ -823,6 +824,7 @@ set(viewer_HEADER_FILES
lldrawpoolavatar.h
lldrawpoolbump.h
lldrawpoolmaterials.h
lldrawpoolpbropaque.h
lldrawpoolground.h
lldrawpoolsimple.h
lldrawpoolsky.h

View File

@ -0,0 +1,52 @@
/**
* @file pbropaqueF.glsl
*
* $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$
*/
/*[EXTRA_CODE_HERE]*/
#ifdef DEFINE_GL_FRAGCOLOR
out vec4 frag_data[3];
#else
#define frag_data gl_FragData
#endif
VARYING vec3 vary_normal;
VARYING vec4 vertex_color;
VARYING vec2 vary_texcoord0;
vec2 encode_normal(vec3 n);
vec3 linear_to_srgb(vec3 c);
void main()
{
vec3 col = vertex_color.rgb * diffuseLookup(vary_texcoord0.xy).rgb;
vec3 spec;
spec.rgb = vec3(vertex_color.a);
col.rgb = vec3( 1, 0, 1 ); // DEBUG
frag_data[0] = vec4(col, 0.0);
frag_data[1] = vec4(spec, vertex_color.a); // spec
vec3 nvn = normalize(vary_normal);
frag_data[2] = vec4(encode_normal(nvn.xyz), vertex_color.a, 0.0);
}

View File

@ -0,0 +1,52 @@
/**
* @file pbropaqueV.glsl
*
* $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$
*/
uniform mat3 normal_matrix;
uniform mat4 texture_matrix0;
uniform mat4 modelview_projection_matrix;
ATTRIBUTE vec3 position;
ATTRIBUTE vec4 diffuse_color;
ATTRIBUTE vec3 normal;
ATTRIBUTE vec2 texcoord0;
VARYING vec3 vary_normal;
VARYING vec4 vertex_color;
VARYING vec2 vary_texcoord0;
void passTextureIndex();
void main()
{
//transform vertex
gl_Position = modelview_projection_matrix * vec4(position.xyz, 1.0);
vary_texcoord0 = (texture_matrix0 * vec4(texcoord0,0,1)).xy;
passTextureIndex();
vary_normal = normalize(normal_matrix * normal);
vertex_color = diffuse_color;
}

View File

@ -37,6 +37,7 @@
#include "lldrawpoolbump.h"
#include "lldrawpoolmaterials.h"
#include "lldrawpoolground.h"
#include "lldrawpoolpbropaque.h"
#include "lldrawpoolsimple.h"
#include "lldrawpoolsky.h"
#include "lldrawpooltree.h"
@ -117,6 +118,9 @@ LLDrawPool *LLDrawPool::createPool(const U32 type, LLViewerTexture *tex0)
case POOL_WL_SKY:
poolp = new LLDrawPoolWLSky();
break;
case POOL_PBR_OPAQUE:
poolp = new LLDrawPoolPBROpaque();
break;
default:
LL_ERRS() << "Unknown draw pool type!" << LL_ENDL;
return NULL;

View File

@ -67,6 +67,7 @@ public:
POOL_WATER,
POOL_GLOW,
POOL_ALPHA,
POOL_PBR_OPAQUE,
NUM_POOL_TYPES,
// * invisiprims work by rendering to the depth buffer but not the color buffer, occluding anything rendered after them
// - and the LLDrawPool types enum controls what order things are rendered in

View File

@ -0,0 +1,92 @@
/**
* @file lldrawpoolpbropaque.cpp
* @brief LLDrawPoolPBROpaque 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 "lldrawpool.h"
#include "lldrawpoolpbropaque.h"
#include "llviewershadermgr.h"
#include "pipeline.h"
LLDrawPoolPBROpaque::LLDrawPoolPBROpaque() :
LLRenderPass(POOL_PBR_OPAQUE)
{
}
void LLDrawPoolPBROpaque::prerender()
{
mShaderLevel = LLViewerShaderMgr::instance()->getShaderLevel(LLViewerShaderMgr::SHADER_OBJECT);
}
// Forward
void LLDrawPoolPBROpaque::beginRenderPass(S32 pass)
{
}
void LLDrawPoolPBROpaque::endRenderPass( S32 pass )
{
}
void LLDrawPoolPBROpaque::render(S32 pass)
{
}
// Deferred
void LLDrawPoolPBROpaque::beginDeferredPass(S32 pass)
{
gDeferredPBROpaqueProgram.bind();
}
void LLDrawPoolPBROpaque::endDeferredPass(S32 pass)
{
gDeferredPBROpaqueProgram.unbind();
LLRenderPass::endRenderPass(pass);
}
void LLDrawPoolPBROpaque::renderDeferred(S32 pass)
{
if (!gPipeline.hasRenderType(LLPipeline::RENDER_TYPE_MATERIALS))
{
return;
}
gGL.flush();
LLGLDisable blend(GL_BLEND);
LLGLDisable alpha_test(GL_ALPHA_TEST);
// TODO: handle HUDs?
//if (LLPipeline::sRenderingHUDs)
// mShader->uniform1i(LLShaderMgr::NO_ATMO, 1);
//else
// mShader->uniform1i(LLShaderMgr::NO_ATMO, 0);
// TODO: handle under water?
// if (LLPipeline::sUnderWaterRender)
// PASS_SIMPLE or PASS_MATERIAL
pushBatches(LLRenderPass::PASS_SIMPLE, getVertexDataMask() | LLVertexBuffer::MAP_TEXTURE_INDEX, TRUE, TRUE);
}

View File

@ -0,0 +1,59 @@
/**
* @file lldrawpoolpbropaque.h
* @brief LLDrawPoolPBrOpaque class definition
*
* $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$
*/
#ifndef LL_LLDRAWPOOLPBROPAQUE_H
#define LL_LLDRAWPOOLPBROPAQUE_H
#include "lldrawpool.h"
class LLDrawPoolPBROpaque : public LLRenderPass
{
public:
enum
{
VERTEX_DATA_MASK = LLVertexBuffer::MAP_VERTEX
| LLVertexBuffer::MAP_NORMAL
| LLVertexBuffer::MAP_TEXCOORD0
};
virtual U32 getVertexDataMask() { return VERTEX_DATA_MASK; }
LLDrawPoolPBROpaque();
/*virtual*/ S32 getNumDeferredPasses() { return 1; }
/*virtual*/ void beginDeferredPass(S32 pass);
/*virtual*/ void endDeferredPass(S32 pass);
/*virtual*/ void renderDeferred(S32 pass);
// Non ALM isn't supported
/*virtual*/ void beginRenderPass(S32 pass);
/*virtual*/ void endRenderPass(S32 pass);
/*virtual*/ S32 getNumPasses() { return 0; }
/*virtual*/ void render(S32 pass = 0);
/*virtual*/ void prerender();
};
#endif // LL_LLDRAWPOOLPBROPAQUE_H

View File

@ -258,6 +258,7 @@ LLGLSLShader gNormalMapGenProgram;
// Deferred materials shaders
LLGLSLShader gDeferredMaterialProgram[LLMaterial::SHADER_COUNT*2];
LLGLSLShader gDeferredMaterialWaterProgram[LLMaterial::SHADER_COUNT*2];
LLGLSLShader gDeferredPBROpaqueProgram;
//helper for making a rigged variant of a given shader
bool make_rigged_variant(LLGLSLShader& shader, LLGLSLShader& riggedShader)
@ -1300,6 +1301,9 @@ BOOL LLViewerShaderMgr::loadShadersDeferred()
gDeferredMaterialProgram[i].unload();
gDeferredMaterialWaterProgram[i].unload();
}
gDeferredPBROpaqueProgram.unload();
return TRUE;
}
@ -1584,6 +1588,22 @@ BOOL LLViewerShaderMgr::loadShadersDeferred()
success = gDeferredMaterialWaterProgram[i].createShader(NULL, NULL);//&mWLUniforms);
llassert(success);
}
if (success)
{
gDeferredPBROpaqueProgram.mName = "Deferred PBR Opaque Shader";
gDeferredPBROpaqueProgram.mFeatures.encodesNormal = true;
gDeferredPBROpaqueProgram.mFeatures.hasSrgb = true;
gDeferredPBROpaqueProgram.mShaderFiles.clear();
gDeferredPBROpaqueProgram.mShaderFiles.push_back(make_pair("deferred/pbropaqueV.glsl", GL_VERTEX_SHADER_ARB));
gDeferredPBROpaqueProgram.mShaderFiles.push_back(make_pair("deferred/pbropaqueF.glsl", GL_FRAGMENT_SHADER_ARB));
gDeferredPBROpaqueProgram.mFeatures.mIndexedTextureChannels = LLGLSLShader::sIndexedTextureChannels;
gDeferredPBROpaqueProgram.mShaderLevel = mShaderLevel[SHADER_DEFERRED];
//gDeferredPBROpaqueProgram.addPermutation("HAS_NORMAL_MAP", "1");
success = gDeferredPBROpaqueProgram.createShader(NULL, NULL);
llassert(success);
}
}
gDeferredMaterialProgram[1].mFeatures.hasLighting = true;

View File

@ -313,4 +313,6 @@ extern LLGLSLShader gNormalMapGenProgram;
// Deferred materials shaders
extern LLGLSLShader gDeferredMaterialProgram[LLMaterial::SHADER_COUNT*2];
extern LLGLSLShader gDeferredMaterialWaterProgram[LLMaterial::SHADER_COUNT*2];
extern LLGLSLShader gDeferredPBROpaqueProgram;
#endif

View File

@ -5674,6 +5674,14 @@ void LLVolumeGeometryManager::rebuildGeom(LLSpatialGroup* group)
continue;
}
#if LL_RELEASE_WITH_DEBUG_INFO
const LLUUID pbr_id( "49c88210-7238-2a6b-70ac-92d4f35963cf" );
const LLUUID obj_id( vobj->getID() );
bool is_pbr = (obj_id == pbr_id);
#else
bool is_pbr = false;
#endif
//ALWAYS null out vertex buffer on rebuild -- if the face lands in a render
// batch, it will recover its vertex buffer reference from the spatial group
facep->setVertexBuffer(NULL);
@ -5739,6 +5747,12 @@ void LLVolumeGeometryManager::rebuildGeom(LLSpatialGroup* group)
BOOL force_simple = (facep->getPixelArea() < FORCE_SIMPLE_RENDER_AREA);
U32 type = gPipeline.getPoolTypeFromTE(te, tex);
if (is_pbr)
{
type = LLDrawPool::POOL_PBR_OPAQUE;
}
else
if (type != LLDrawPool::POOL_ALPHA && force_simple)
{
type = LLDrawPool::POOL_SIMPLE;

View File

@ -462,6 +462,7 @@ void LLPipeline::init()
getPool(LLDrawPool::POOL_BUMP);
getPool(LLDrawPool::POOL_MATERIALS);
getPool(LLDrawPool::POOL_GLOW);
getPool(LLDrawPool::POOL_PBR_OPAQUE);
resetFrameStats();
@ -1597,6 +1598,10 @@ LLDrawPool *LLPipeline::findPool(const U32 type, LLViewerTexture *tex0)
poolp = mWLSkyPool;
break;
case LLDrawPool::POOL_PBR_OPAQUE:
poolp = mPBROpaquePool;
break;
default:
llassert(0);
LL_ERRS() << "Invalid Pool Type in LLPipeline::findPool() type=" << type << LL_ENDL;
@ -5698,6 +5703,18 @@ void LLPipeline::addToQuickLookup( LLDrawPool* new_poolp )
}
break;
case LLDrawPool::POOL_PBR_OPAQUE:
if( mPBROpaquePool )
{
llassert(0);
LL_WARNS() << "LLPipeline::addPool(): Ignoring duplicate PBR Opaque Pool" << LL_ENDL;
}
else
{
mPBROpaquePool = new_poolp;
}
break;
default:
llassert(0);
LL_WARNS() << "Invalid Pool Type in LLPipeline::addPool()" << LL_ENDL;
@ -5814,6 +5831,11 @@ void LLPipeline::removeFromQuickLookup( LLDrawPool* poolp )
mGroundPool = NULL;
break;
case LLDrawPool::POOL_PBR_OPAQUE:
llassert( poolp == mPBROpaquePool );
mPBROpaquePool = NULL;
break;
default:
llassert(0);
LL_WARNS() << "Invalid Pool Type in LLPipeline::removeFromQuickLookup() type=" << poolp->getType() << LL_ENDL;

View File

@ -864,6 +864,7 @@ protected:
LLDrawPool* mBumpPool;
LLDrawPool* mMaterialsPool;
LLDrawPool* mWLSkyPool;
LLDrawPool* mPBROpaquePool;
// Note: no need to keep an quick-lookup to avatar pools, since there's only one per avatar
public: