SH-2666 Tweak depth of field optimizations based on resident feedback.

meow-7.2.2
Dave Parks 2011-11-10 16:12:50 -06:00
parent 76bd8cee11
commit df546bfba9
8 changed files with 42 additions and 5 deletions

View File

@ -1046,6 +1046,7 @@ void LLShaderMgr::initAttribsAndUniforms()
mReservedUniforms.push_back("tan_pixel_angle");
mReservedUniforms.push_back("magnification");
mReservedUniforms.push_back("max_cof");
mReservedUniforms.push_back("res_scale");
mReservedUniforms.push_back("depthMap");
mReservedUniforms.push_back("shadowMap0");

View File

@ -141,6 +141,7 @@ public:
DOF_TAN_PIXEL_ANGLE,
DOF_MAGNIFICATION,
DOF_MAX_COF,
DOF_RES_SCALE,
DEFERRED_DEPTH,
DEFERRED_SHADOW0,

View File

@ -8017,7 +8017,19 @@
<key>Value</key>
<integer>0</integer>
</map>
<key>CameraDoFResScale</key>
<map>
<key>Comment</key>
<string>Amount to scale down depth of field resolution. Valid range is 0.25 (quarter res) to 1.0 (full res)</string>
<key>Persist</key>
<integer>1</integer>
<key>Type</key>
<string>F32</string>
<key>Value</key>
<real>0.7</real>
</map>
<key>RenderSpotLightsInNondeferred</key>
<map>
<key>Comment</key>

View File

@ -83,5 +83,5 @@ void main()
vec4 bloom = texture2D(bloomMap, vary_fragcoord.xy/screen_res);
gl_FragColor.rgb = diff.rgb + bloom.rgb;
gl_FragColor.a = sc/10.f;
gl_FragColor.a = sc/max_cof;
}

View File

@ -36,6 +36,7 @@ uniform mat4 inv_proj;
uniform vec2 screen_res;
uniform float max_cof;
uniform float res_scale;
VARYING vec2 vary_fragcoord;
@ -43,10 +44,24 @@ void main()
{
vec2 tc = vary_fragcoord.xy;
vec4 dof = texture2DRect(diffuseRect, vary_fragcoord.xy*0.5);
vec4 dof = texture2DRect(diffuseRect, vary_fragcoord.xy*res_scale);
vec4 diff = texture2DRect(lightMap, vary_fragcoord.xy);
float a = min(diff.a * max_cof*0.333, 1.0);
float a = min(diff.a * max_cof*res_scale*res_scale, 1.0);
if (a > 0.25 && a < 0.75)
{ //help out the transition a bit
float sc = a/res_scale;
vec4 col;
col = texture2DRect(lightMap, vary_fragcoord.xy+vec2(sc,sc));
col += texture2DRect(lightMap, vary_fragcoord.xy+vec2(-sc,sc));
col += texture2DRect(lightMap, vary_fragcoord.xy+vec2(sc,-sc));
col += texture2DRect(lightMap, vary_fragcoord.xy+vec2(-sc,-sc));
diff = mix(diff, col*0.25, a);
}
gl_FragColor = mix(diff, dof, a);
}

View File

@ -34,6 +34,7 @@ uniform sampler2DRect diffuseRect;
uniform mat4 inv_proj;
uniform vec2 screen_res;
uniform float max_cof;
uniform float res_scale;
VARYING vec2 vary_fragcoord;

View File

@ -186,6 +186,7 @@ F32 LLPipeline::RenderShadowErrorCutoff;
F32 LLPipeline::RenderShadowFOVCutoff;
BOOL LLPipeline::CameraOffset;
F32 LLPipeline::CameraMaxCoF;
F32 LLPipeline::CameraDoFResScale;
const F32 BACKLIGHT_DAY_MAGNITUDE_AVATAR = 0.2f;
const F32 BACKLIGHT_NIGHT_MAGNITUDE_AVATAR = 0.1f;
@ -929,6 +930,7 @@ void LLPipeline::refreshCachedSettings()
RenderShadowFOVCutoff = gSavedSettings.getF32("RenderShadowFOVCutoff");
CameraOffset = gSavedSettings.getBOOL("CameraOffset");
CameraMaxCoF = gSavedSettings.getF32("CameraMaxCoF");
CameraDoFResScale = gSavedSettings.getF32("CameraDoFResScale");
}
void LLPipeline::releaseGLBuffers()
@ -6549,6 +6551,7 @@ void LLPipeline::renderBloom(BOOL for_snapshot, F32 zoom_factor, int subfield)
shader->uniform1f(LLShaderMgr::DOF_TAN_PIXEL_ANGLE, tanf(1.f/LLDrawable::sCurPixelAngle));
shader->uniform1f(LLShaderMgr::DOF_MAGNIFICATION, magnification);
shader->uniform1f(LLShaderMgr::DOF_MAX_COF, CameraMaxCoF);
shader->uniform1f(LLShaderMgr::DOF_RES_SCALE, CameraDoFResScale);
gGL.begin(LLRender::TRIANGLE_STRIP);
gGL.texCoord2f(tc1.mV[0], tc1.mV[1]);
@ -6568,7 +6571,7 @@ void LLPipeline::renderBloom(BOOL for_snapshot, F32 zoom_factor, int subfield)
{ //perform DoF sampling at half-res (preserve alpha channel)
mScreen.bindTarget();
glViewport(0,0,mScreen.getWidth()/2, mScreen.getHeight()/2);
glViewport(0,0,mScreen.getWidth()*CameraDoFResScale, mScreen.getHeight()*CameraDoFResScale);
gGL.setColorMask(true, false);
shader = &gDeferredPostProgram;
@ -6580,6 +6583,7 @@ void LLPipeline::renderBloom(BOOL for_snapshot, F32 zoom_factor, int subfield)
}
shader->uniform1f(LLShaderMgr::DOF_MAX_COF, CameraMaxCoF);
shader->uniform1f(LLShaderMgr::DOF_RES_SCALE, CameraDoFResScale);
gGL.begin(LLRender::TRIANGLE_STRIP);
gGL.texCoord2f(tc1.mV[0], tc1.mV[1]);
@ -6611,9 +6615,11 @@ void LLPipeline::renderBloom(BOOL for_snapshot, F32 zoom_factor, int subfield)
if (channel > -1)
{
mScreen.bindTexture(0, channel);
gGL.getTexUnit(channel)->setTextureFilteringOption(LLTexUnit::TFO_BILINEAR);
}
shader->uniform1f(LLShaderMgr::DOF_MAX_COF, CameraMaxCoF);
shader->uniform1f(LLShaderMgr::DOF_RES_SCALE, CameraDoFResScale);
gGL.begin(LLRender::TRIANGLE_STRIP);
gGL.texCoord2f(tc1.mV[0], tc1.mV[1]);

View File

@ -846,6 +846,7 @@ public:
static F32 RenderShadowFOVCutoff;
static BOOL CameraOffset;
static F32 CameraMaxCoF;
static F32 CameraDoFResScale;
};
void render_bbox(const LLVector3 &min, const LLVector3 &max);