restore vision spheres for PBR pipeline

master
Beq 2023-12-01 13:28:21 +00:00
parent f8d2aced99
commit bd734aba83
7 changed files with 129 additions and 130 deletions

View File

@ -14,15 +14,12 @@
*
*/
#extension GL_ARB_texture_rectangle : enable
/*[EXTRA_CODE_HERE]*/
out vec4 frag_color;
in vec2 vary_fragcoord;
uniform sampler2DRect diffuseRect;
uniform sampler2DRect depthMap;
uniform mat4 inv_proj;
uniform sampler2D diffuseRect;
uniform vec2 screen_res;
uniform int rlvEffectMode; // ESphereMode
@ -41,35 +38,26 @@ uniform vec2 rlvEffectParam5; // Blur direction (not used for blend)
#define SPHERE_PARAMS rlvEffectParam4
#define BLUR_DIRECTION rlvEffectParam5.xy
vec4 getPosition_d(vec2 pos_screen, float depth)
{
vec2 sc = pos_screen.xy * 2.0;
sc /= screen_res;
sc -= vec2(1.0, 1.0);
vec4 ndc = vec4(sc.x, sc.y, 2.0 * depth - 1.0, 1.0);
vec4 pos = inv_proj * ndc;
pos /= pos.w;
pos.w = 1.0;
return pos;
}
vec4 getPositionWithDepth(vec2 pos_screen, float depth);
float getDepth(vec2 pos_screen);
vec3 blur13(sampler2DRect source, vec2 tc, vec2 direction)
vec3 blur13(sampler2D source, vec2 tc, vec2 direction)
{
vec4 color = vec4(0.0);
vec2 off1 = vec2(1.411764705882353) * direction;
vec2 off2 = vec2(3.2941176470588234) * direction;
vec2 off3 = vec2(5.176470588235294) * direction;
color += texture2DRect(source, tc) * 0.1964825501511404;
color += texture(source, tc) * 0.1964825501511404;
color += texture2DRect(source, tc + off1) * 0.2969069646728344;
color += texture2DRect(source, tc - off1) * 0.2969069646728344;
color += texture(source, tc + off1 / screen_res) * 0.2969069646728344;
color += texture(source, tc - off1 / screen_res) * 0.2969069646728344;
color += texture2DRect(source, tc + off2) * 0.09447039785044732;
color += texture2DRect(source, tc - off2) * 0.09447039785044732;
color += texture(source, tc + off2 / screen_res) * 0.09447039785044732;
color += texture(source, tc - off2 / screen_res) * 0.09447039785044732;
color += texture2DRect(source, tc + off3) * 0.010381362401148057;
color += texture2DRect(source, tc - off3) * 0.010381362401148057;
color += texture(source, tc + off3 / screen_res) * 0.010381362401148057;
color += texture(source, tc - off3 / screen_res) * 0.010381362401148057;
return color.xyz;
}
@ -77,7 +65,7 @@ vec3 blur13(sampler2DRect source, vec2 tc, vec2 direction)
const float pi = 3.14159265;
// http://callumhay.blogspot.com/2010/09/gaussian-blur-shader-glsl.html
vec3 blurVariable(sampler2DRect source, vec2 tc, float kernelSize, vec2 direction, float strength) {
vec3 blurVariable(sampler2D source, vec2 tc, float kernelSize, vec2 direction, float strength) {
float numBlurPixelsPerSide = float(kernelSize / 2);
// Incremental Gaussian Coefficent Calculation (See GPU Gems 3 pp. 877 - 889)
@ -90,14 +78,14 @@ vec3 blurVariable(sampler2DRect source, vec2 tc, float kernelSize, vec2 directio
float coefficientSum = 0.0;
// Take the central sample first...
avgValue += texture2DRect(source, tc) * incrementalGaussian.x;
avgValue += texture(source, tc) * incrementalGaussian.x;
coefficientSum += incrementalGaussian.x;
incrementalGaussian.xy *= incrementalGaussian.yz;
// Go through the remaining 8 vertical samples (4 on each side of the center)
for (float i = 1.0; i <= numBlurPixelsPerSide; i++) {
avgValue += texture2DRect(source, tc - i * direction) * incrementalGaussian.x;
avgValue += texture2DRect(source, tc + i * direction) * incrementalGaussian.x;
avgValue += texture(source, tc - i * direction / screen_res) * incrementalGaussian.x;
avgValue += texture(source, tc + i * direction / screen_res) * incrementalGaussian.x;
coefficientSum += 2.0 * incrementalGaussian.x;
incrementalGaussian.xy *= incrementalGaussian.yz;
}
@ -105,15 +93,15 @@ vec3 blurVariable(sampler2DRect source, vec2 tc, float kernelSize, vec2 directio
return (avgValue / coefficientSum).rgb;
}
vec3 chromaticAberration(sampler2DRect source, vec2 tc, vec2 redDrift, vec2 blueDrift, float strength)
vec3 chromaticAberration(sampler2D source, vec2 tc, vec2 redDrift, vec2 blueDrift, float strength)
{
vec3 sourceColor = texture2DRect(source, tc).rgb;
vec3 sourceColor = texture(source, tc).rgb;
// Sample the color components
vec3 driftColor;
driftColor.r = texture2DRect(source, tc + redDrift).r;
driftColor.r = texture(source, tc + redDrift / screen_res).r;
driftColor.g = sourceColor.g;
driftColor.b = texture2DRect(source, tc + blueDrift).b;
driftColor.b = texture(source, tc + blueDrift / screen_res).b;
// Adjust the strength of the effect
return mix(sourceColor, driftColor, strength);
@ -121,9 +109,8 @@ vec3 chromaticAberration(sampler2DRect source, vec2 tc, vec2 redDrift, vec2 blue
void main()
{
vec2 fragTC = vary_fragcoord.st;
float fragDepth = texture2DRect(depthMap, fragTC).x;
vec3 fragPosLocal = getPosition_d(fragTC, fragDepth).xyz;
vec2 fragTC = vary_fragcoord.xy;
vec3 fragPosLocal = getPositionWithDepth(fragTC, getDepth(fragTC)).xyz;
float distance = length(fragPosLocal.xyz - SPHERE_ORIGIN);
// Linear non-branching interpolation of the strength of the sphere effect (replaces if/elseif/else for x < min, min <= x <= max and x > max)
@ -131,22 +118,19 @@ void main()
effectStrength = mix(effectStrength, mix(0, SPHERE_VALUEMIN, SPHERE_DISTEXTEND.x), distance < SPHERE_DISTMIN);
effectStrength = mix(effectStrength, mix(0, SPHERE_VALUEMAX, SPHERE_DISTEXTEND.y), distance > SPHERE_DISTMAX);
vec3 fragColor;
vec3 fragColor ;
switch (rlvEffectMode)
{
case 0: // Blend
fragColor = texture2DRect(diffuseRect, fragTC).rgb;
fragColor = texture(diffuseRect, fragTC).rgb;
fragColor = mix(fragColor, SPHERE_PARAMS.rgb, effectStrength);
break;
case 1: // Blur (fixed)
fragColor = blur13(diffuseRect, fragTC, effectStrength * BLUR_DIRECTION);
fragColor = blur13(diffuseRect, fragTC, BLUR_DIRECTION * vec2(effectStrength));
break;
case 2: // Blur (variable)
fragColor = texture2DRect(diffuseRect, fragTC).rgb;
if (effectStrength > 0)
{
fragColor = mix(fragColor, blurVariable(diffuseRect, fragTC, SPHERE_PARAMS.x, BLUR_DIRECTION, effectStrength), effectStrength);
}
fragColor = texture(diffuseRect, fragTC).rgb;
fragColor = mix(fragColor, blurVariable(diffuseRect, fragTC, SPHERE_PARAMS.x, BLUR_DIRECTION, effectStrength), int(effectStrength > 0));
break;
case 3: // ChromaticAberration
fragColor = chromaticAberration(diffuseRect, fragTC, SPHERE_PARAMS.xy, SPHERE_PARAMS.zw, effectStrength);
@ -154,9 +138,10 @@ void main()
case 4: // Pixelate
{
effectStrength = sign(effectStrength);
float pixelWidth = max(1, round(SPHERE_PARAMS.x * effectStrength)); float pixelHeight = max(1, round(SPHERE_PARAMS.y * effectStrength));
float pixelWidth = max(1, round(SPHERE_PARAMS.x * effectStrength)) / screen_res.x;
float pixelHeight = max(1, round(SPHERE_PARAMS.y * effectStrength)) / screen_res.y;
fragTC = vec2(pixelWidth * floor(fragTC.x / pixelWidth), pixelHeight * floor(fragTC.y / pixelHeight));
fragColor = texture2DRect(diffuseRect, fragTC).rgb;
fragColor = texture(diffuseRect, fragTC).rgb;
}
break;
}

View File

@ -19,7 +19,6 @@ in vec3 position;
uniform vec2 screen_res;
out vec2 vary_fragcoord;
out vec3 vary_position;
void main()
{
@ -29,5 +28,4 @@ void main()
vary_fragcoord = (pos.xy*0.5+0.5)*screen_res;
vary_position = (vec4(1, 0, 0, 1.0)).xyz;
}

View File

@ -213,6 +213,9 @@ LLGLSLShader gDeferredSkinnedFullbrightAlphaMaskAlphaProgram;
LLGLSLShader gNormalMapGenProgram;
LLGLSLShader gDeferredGenBrdfLutProgram;
LLGLSLShader gDeferredBufferVisualProgram;
// [RLVa:KB] - @setsphere
LLGLSLShader gRlvSphereProgram;
// [/RLVa:KB]
// Deferred materials shaders
LLGLSLShader gDeferredMaterialProgram[LLMaterial::SHADER_COUNT*2];
@ -1010,6 +1013,9 @@ BOOL LLViewerShaderMgr::loadShadersDeferred()
gDeferredPBRAlphaWaterProgram.unload();
gDeferredSkinnedPBRAlphaWaterProgram.unload();
// [RLVa:KB] - @setsphere
gRlvSphereProgram.unload();
// [/RLVa:KB]
return TRUE;
}
@ -2626,7 +2632,21 @@ BOOL LLViewerShaderMgr::loadShadersDeferred()
gDeferredBufferVisualProgram.mShaderLevel = mShaderLevel[SHADER_DEFERRED];
success = gDeferredBufferVisualProgram.createShader(NULL, NULL);
}
// [RLVa:KB] - @setsphere
if(success)
{
gRlvSphereProgram.mName = "RLVa Sphere Post Processing Shader";
gRlvSphereProgram.mFeatures.isDeferred = true;
gRlvSphereProgram.mShaderFiles.clear();
gRlvSphereProgram.mShaderFiles.push_back(make_pair("deferred/rlvV.glsl", GL_VERTEX_SHADER));
if (gGLManager.mGLVersion >= 4.5f)
gRlvSphereProgram.mShaderFiles.push_back(make_pair("deferred/rlvF.glsl", GL_FRAGMENT_SHADER));
else
gRlvSphereProgram.mShaderFiles.push_back(make_pair("deferred/rlvFLegacy.glsl", GL_FRAGMENT_SHADER));
gRlvSphereProgram.mShaderLevel = mShaderLevel[SHADER_DEFERRED];
success = gRlvSphereProgram.createShader(NULL, NULL);
}
// [/RLV:KB]
return success;
}

View File

@ -269,6 +269,9 @@ extern LLGLSLShader gHUDFullbrightShinyProgram;
extern LLGLSLShader gNormalMapGenProgram;
extern LLGLSLShader gDeferredGenBrdfLutProgram;
extern LLGLSLShader gDeferredBufferVisualProgram;
// [RLVa:KB] - @setsphere
extern LLGLSLShader gRlvSphereProgram;
// [/RLVa:KB]
// Deferred materials shaders
extern LLGLSLShader gDeferredMaterialProgram[LLMaterial::SHADER_COUNT*2];

View File

@ -905,8 +905,11 @@ bool LLPipeline::allocateScreenBuffer(U32 resX, U32 resY, U32 samples)
{
mRT->fxaaBuffer.release();
}
if (shadow_detail > 0 || ssao || RenderDepthOfField || samples > 0)
// <FS:Beq> restore setSphere
// if (shadow_detail > 0 || ssao || RenderDepthOfField || samples > 0))
if (shadow_detail > 0 || ssao || RenderDepthOfField || samples > 0 || RlvActions::hasPostProcess())
// </FS:Beq>
{ //only need mRT->deferredLight for shadows OR ssao OR dof OR fxaa
if (!mRT->deferredLight.allocate(resX, resY, GL_RGBA16F)) return false;
}
@ -7539,10 +7542,21 @@ void LLPipeline::renderFinalize()
applyFXAA(&mPostMap, &mRT->screen);
// <FS:Beq> Restore shader post proc for Vignette
// LLRenderTarget* finalBuffer = &mRT->screen;
renderVignette(&mRT->screen, &mPostMap); // <FS:Beq/> Restore shader post proc.
copyRenderTarget(&mPostMap, &mRT->screen);
LLRenderTarget* activeBuffer = &mRT->screen;
LLRenderTarget* targetBuffer = &mPostMap;
// [RLVa:KB] - @setsphere
if (RlvActions::hasBehaviour(RLV_BHVR_SETSPHERE))
{
LLShaderEffectParams params(activeBuffer, targetBuffer, false);
LLVfxManager::instance().runEffect(EVisualEffect::RlvSphere, &params);
// flip the buffers round
activeBuffer = params.m_pDstBuffer;
targetBuffer = params.m_pSrcBuffer;
}
// [/RLVa:KB]
renderVignette(activeBuffer, targetBuffer);
LLRenderTarget* finalBuffer = targetBuffer;
// </FS:Beq>
LLRenderTarget* finalBuffer = &mRT->screen;
if (RenderBufferVisualization > -1)
{
finalBuffer = &mPostMap;

View File

@ -298,10 +298,8 @@ ERlvCmdRet RlvSphereEffect::onValueMaxChanged(const LLUUID& idRlvObj, const boos
void RlvSphereEffect::setShaderUniforms(LLGLSLShader* pShader)
{
pShader->uniformMatrix4fv(LLShaderMgr::INVERSE_PROJECTION_MATRIX, 1, FALSE, get_current_projection().inverse().m);
pShader->uniform2f(LLShaderMgr::DEFERRED_SCREEN_RES, gPipeline.mRT->screen.getWidth(), gPipeline.mRT->screen.getHeight());
pShader->uniform1i(LLShaderMgr::RLV_EFFECT_MODE, llclamp((int)m_eMode, 0, (int)ESphereMode::Count));
// Pass the sphere origin to the shader
LLVector4 posSphereOrigin;
switch (m_eOrigin)
@ -353,41 +351,20 @@ void RlvSphereEffect::renderPass(LLGLSLShader* pShader, const LLShaderEffectPara
if (nDiffuseChannel > -1)
{
pParams->m_pSrcBuffer->bindTexture(0, nDiffuseChannel);
gGL.getTexUnit(nDiffuseChannel)->setTextureFilteringOption(LLTexUnit::TFO_POINT);
gGL.getTexUnit(nDiffuseChannel)->setTextureFilteringOption(LLTexUnit::TFO_BILINEAR);
}
// KITTYFIXME
//S32 nDepthChannel = pShader->enableTexture(LLShaderMgr::DEFERRED_DEPTH, gPipeline.mRT->deferredDepth.getUsage());
//if (nDepthChannel > -1)
//{
// gGL.getTexUnit(nDepthChannel)->bind(&gPipeline.mRT->deferredDepth, TRUE);
//}
S32 nDepthChannel = pShader->enableTexture(LLShaderMgr::DEFERRED_DEPTH, gPipeline.mRT->deferredScreen.getUsage());
if (nDepthChannel > -1)
{
gGL.getTexUnit(nDepthChannel)->bind(&gPipeline.mRT->deferredScreen, TRUE);
}
gGL.matrixMode(LLRender::MM_PROJECTION);
gGL.pushMatrix();
gGL.loadIdentity();
gGL.matrixMode(LLRender::MM_MODELVIEW);
gGL.pushMatrix();
gGL.loadMatrix(gGLModelView);
LLVector2 tc1(0, 0);
LLVector2 tc2((F32)gPipeline.mRT->screen.getWidth() * 2, (F32)gPipeline.mRT->screen.getHeight() * 2);
gGL.begin(LLRender::TRIANGLE_STRIP);
gGL.texCoord2f(tc1.mV[0], tc1.mV[1]);
gGL.vertex2f(-1, -1);
gGL.texCoord2f(tc1.mV[0], tc2.mV[1]);
gGL.vertex2f(-1, 3);
gGL.texCoord2f(tc2.mV[0], tc1.mV[1]);
gGL.vertex2f(3, -1);
gGL.end();
gGL.matrixMode(LLRender::MM_PROJECTION);
gGL.popMatrix();
gGL.matrixMode(LLRender::MM_MODELVIEW);
gGL.popMatrix();
gPipeline.mScreenTriangleVB->setBuffer();
gPipeline.mScreenTriangleVB->drawArrays(LLRender::TRIANGLES, 0, 3);
pShader->disableTexture(LLShaderMgr::DEFERRED_DIFFUSE, pParams->m_pSrcBuffer->getUsage());
//pShader->disableTexture(LLShaderMgr::DEFERRED_DEPTH, gPipeline.mRT->deferredDepth.getUsage()); // KITTYFIXME
pShader->disableTexture(LLShaderMgr::DEFERRED_DEPTH, gPipeline.mRT->deferredScreen.getUsage());
if (pParams->m_pDstBuffer)
{
@ -400,32 +377,34 @@ LLTrace::BlockTimerStatHandle FTM_RLV_EFFECT_SPHERE("Post-process (RLVa sphere)"
void RlvSphereEffect::run(const LLVisualEffectParams* pParams)
{
LL_RECORD_BLOCK_TIME(FTM_RLV_EFFECT_SPHERE);
LLGLDepthTest depth(GL_FALSE, GL_FALSE);
if (gRlvSphereProgram.isComplete())
{
LLGLDepthTest depth(GL_FALSE, GL_FALSE);
// KITTYFIXME
//gRlvSphereProgram.bind();
//setShaderUniforms(&gRlvSphereProgram);
gRlvSphereProgram.bind();
setShaderUniforms(&gRlvSphereProgram);
//const LLShaderEffectParams* pShaderParams = static_cast<const LLShaderEffectParams*>(pParams);
//switch (m_eMode)
//{
// case ESphereMode::Blend:
// case ESphereMode::ChromaticAberration:
// case ESphereMode::Pixelate:
// renderPass(&gRlvSphereProgram, pShaderParams);
// break;
// case ESphereMode::Blur:
// case ESphereMode::BlurVariable:
// gRlvSphereProgram.uniform2f(LLShaderMgr::RLV_EFFECT_PARAM5, 1.f, 0.f);
// renderPass(&gRlvSphereProgram, pShaderParams);
// gRlvSphereProgram.uniform2f(LLShaderMgr::RLV_EFFECT_PARAM5, 0.f, 1.f);
// renderPass(&gRlvSphereProgram, pShaderParams);
// break;
// default:
// llassert(true);
//}
const LLShaderEffectParams* pShaderParams = static_cast<const LLShaderEffectParams*>(pParams);
switch (m_eMode)
{
case ESphereMode::Blend:
case ESphereMode::ChromaticAberration:
case ESphereMode::Pixelate:
renderPass(&gRlvSphereProgram, pShaderParams);
break;
case ESphereMode::Blur:
case ESphereMode::BlurVariable:
gRlvSphereProgram.uniform2f(LLShaderMgr::RLV_EFFECT_PARAM5, 1.f, 0.f);
renderPass(&gRlvSphereProgram, pShaderParams);
gRlvSphereProgram.uniform2f(LLShaderMgr::RLV_EFFECT_PARAM5, 0.f, 1.f);
renderPass(&gRlvSphereProgram, pShaderParams);
break;
default:
llassert(true);
}
//gRlvSphereProgram.unbind();
gRlvSphereProgram.unbind();
}
}
// ====================================================================================

View File

@ -2155,15 +2155,14 @@ ERlvCmdRet RlvBehaviourHandler<RLV_BHVR_SETSPHERE>::onCommand(const RlvCommand&
return RLV_RET_FAILED_LOCK;
ERlvCmdRet eRet = RlvBehaviourGenericHandler<RLV_OPTION_NONE_OR_MODIFIER>::onCommand(rlvCmd, fRefCount);
// KITTYFIXME
//if ( (RLV_RET_SUCCESS == eRet) && (!rlvCmd.isModifier()) )
//{
// if (gRlvHandler.hasBehaviour(rlvCmd.getObjectID(), rlvCmd.getBehaviourType()))
// {
// LLVfxManager::instance().addEffect(new RlvSphereEffect(rlvCmd.getObjectID()));
// Rlv::forceAtmosphericShadersIfAvailable();
if ( (RLV_RET_SUCCESS == eRet) && (!rlvCmd.isModifier()) )
{
if (gRlvHandler.hasBehaviour(rlvCmd.getObjectID(), rlvCmd.getBehaviourType()))
{
LLVfxManager::instance().addEffect(new RlvSphereEffect(rlvCmd.getObjectID()));
// Rlv::forceAtmosphericShadersIfAvailable();
// <FS:Beq> Note to Kitty, this can all go I think.
// // If we're not using deferred but are using Windlight shaders we need to force use of FBO and depthmap texture
// if ( (!LLPipeline::sRenderDeferred) && (LLPipeline::WindLightUseAtmosShaders) && (!LLPipeline::sUseDepthTexture) )
// {
@ -2175,19 +2174,20 @@ ERlvCmdRet RlvBehaviourHandler<RLV_BHVR_SETSPHERE>::onCommand(const RlvCommand&
// gPipeline.resetVertexBuffers();
// LLViewerShaderMgr::instance()->setShaders();
// }
// else if (!gPipeline.mRT->deferredLight.isComplete())
// {
// // In case of deferred with no shadows, no ambient occlusion, no depth of field, and no antialiasing
// gPipeline.releaseGLBuffers();
// gPipeline.createGLBuffers();
// RLV_ASSERT(gPipeline.mRT->deferredLight.isComplete());
// }
// }
// else
// {
// LLVfxManager::instance().removeEffect<RlvSphereEffect>(gRlvHandler.getCurrentObject());
// }
//}
// else
if (!gPipeline.mRT->deferredLight.isComplete())
{
// In case of deferred with no shadows, no ambient occlusion, no depth of field, and no antialiasing
gPipeline.releaseGLBuffers();
gPipeline.createGLBuffers();
RLV_ASSERT(gPipeline.mRT->deferredLight.isComplete());
}
}
else
{
LLVfxManager::instance().removeEffect<RlvSphereEffect>(gRlvHandler.getCurrentObject());
}
}
return eRet;
}
@ -2506,7 +2506,7 @@ void RlvBehaviourToggleHandler<RLV_BHVR_SETENV>::onCommandToggle(ERlvBehaviour e
if (fHasBhvr)
{
Rlv::forceAtmosphericShadersIfAvailable();
// Rlv::forceAtmosphericShadersIfAvailable(); // <FS:Beq/> this is no longer a thing
// Usurp the 'edit' environment for RLVa locking so TPV tools like quick prefs and phototools are automatically locked out as well
// (these needed per-feature awareness of RLV in the previous implementation which often wasn't implemented)