#677 Move PBR mirror radiance mixing to reflectionProbeF so transparent PBR surfaces can be mirrors

master
RunitaiLinden 2024-02-02 15:43:56 -06:00
parent 6846600e3e
commit 5abc68ad43
6 changed files with 33 additions and 18 deletions

View File

@ -44,6 +44,7 @@ using std::make_pair;
using std::string;
LLShaderMgr * LLShaderMgr::sInstance = NULL;
bool LLShaderMgr::sMirrorsEnabled = false;
LLShaderMgr::LLShaderMgr()
{
@ -604,6 +605,11 @@ GLuint LLShaderMgr::loadShaderFile(const std::string& filename, S32 & shader_lev
extra_code_text[extra_code_count++] = strdup("#define FXAA_GLSL_130 1\n");
}
if (sMirrorsEnabled)
{
extra_code_text[extra_code_count++] = strdup("#define HERO_PROBES 1\n");
}
// Use alpha float to store bit flags
// See: C++: addDeferredAttachment(), shader: frag_data[2]
extra_code_text[extra_code_count++] = strdup("#define GBUFFER_FLAG_SKIP_ATMOS 0.0 \n"); // atmo kill

View File

@ -365,6 +365,7 @@ public:
bool mShaderCacheInitialized = false;
bool mShaderCacheEnabled = false;
std::string mShaderCacheDir;
static bool sMirrorsEnabled;
protected:

View File

@ -682,6 +682,12 @@ vec3 sampleProbeAmbient(vec3 pos, vec3 dir, vec3 amblit)
return col[1]+col[0];
}
#if defined(HERO_PROBES)
uniform vec4 clipPlane;
uniform samplerCubeArray heroProbes;
#endif
void doProbeSample(inout vec3 ambenv, inout vec3 glossenv,
vec2 tc, vec3 pos, vec3 norm, float glossiness, bool transparent, vec3 amblit)
{
@ -713,6 +719,18 @@ void doProbeSample(inout vec3 ambenv, inout vec3 glossenv,
glossenv = mix(glossenv, ssr.rgb, ssr.a);
}
#endif
#if defined(HERO_PROBES)
float clipDist = dot(pos.xyz, clipPlane.xyz) + clipPlane.w;
if (clipDist > 0.0 && clipDist < 0.1 && glossiness > 0.8)
{
vec3 refnormpersp = reflect(pos.xyz, norm.xyz);
if (dot(refnormpersp.xyz, clipPlane.xyz) > 0.0)
{
glossenv = textureLod(heroProbes, vec4(env_mat * refnormpersp, 0), (1.0-glossiness)*10).xyz;
}
}
#endif
}
void sampleReflectionProbes(inout vec3 ambenv, inout vec3 glossenv,

View File

@ -189,19 +189,6 @@ void main()
float gloss = 1.0 - perceptualRoughness;
sampleReflectionProbes(irradiance, radiance, tc, pos.xyz, norm.xyz, gloss, false, amblit_linear);
#ifdef HERO_PROBES
float clipDist = dot(pos.xyz, clipPlane.xyz) + clipPlane.w;
if (clipDist > 0.0 && clipDist < 0.1 && perceptualRoughness < 0.2)
{
vec3 refnormpersp = reflect(pos.xyz, norm.xyz);
if (dot(refnormpersp.xyz, clipPlane.xyz) > 0.0)
{
radiance = textureLod(heroProbes, vec4(env_mat * refnormpersp, 0), perceptualRoughness*11).xyz;
}
}
#endif
adjustIrradiance(irradiance, ambocc);

View File

@ -764,6 +764,12 @@ BOOL LLViewerCamera::cameraUnderWater() const
{
LLViewerRegion* regionp = LLWorld::instance().getRegionFromPosAgent(getOrigin());
if (gPipeline.mHeroProbeManager.isMirrorPass())
{
// TODO: figure out how to handle this case
return FALSE;
}
if (!regionp)
{
regionp = gAgent.getRegion();

View File

@ -359,6 +359,8 @@ void LLViewerShaderMgr::setShaders()
return;
}
LLShaderMgr::sMirrorsEnabled = LLPipeline::RenderMirrors;
if (!gGLManager.mHasRequirements)
{
// Viewer will show 'hardware requirements' warning later
@ -1813,11 +1815,6 @@ 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);