summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorXiaohong Bao <bao@lindenlab.com>2013-01-24 17:10:37 -0700
committerXiaohong Bao <bao@lindenlab.com>2013-01-24 17:10:37 -0700
commit173806c4b1d18fe0188c1d189e7044fa977268ae (patch)
tree6f72266dba83351d63b0c33081dcc13af13a71c2
parent940e7c8fcd9c6f7b6eb98a5ad77d15de23f15b72 (diff)
for SH-3665: more post processing of the frame difference image
-rw-r--r--indra/newview/app_settings/shaders/class1/interface/twotexturecompareF.glsl17
-rw-r--r--indra/newview/llscenemonitor.cpp76
-rw-r--r--indra/newview/llscenemonitor.h8
-rw-r--r--indra/newview/llviewershadermgr.cpp1
4 files changed, 102 insertions, 0 deletions
diff --git a/indra/newview/app_settings/shaders/class1/interface/twotexturecompareF.glsl b/indra/newview/app_settings/shaders/class1/interface/twotexturecompareF.glsl
index 050114b37e..6eeb2596b2 100644
--- a/indra/newview/app_settings/shaders/class1/interface/twotexturecompareF.glsl
+++ b/indra/newview/app_settings/shaders/class1/interface/twotexturecompareF.glsl
@@ -31,6 +31,10 @@ out vec4 frag_color;
uniform sampler2D tex0;
uniform sampler2D tex1;
+uniform sampler2D dither_tex;
+uniform float dither_scale;
+uniform float dither_scale_s;
+uniform float dither_scale_t;
VARYING vec2 vary_texcoord0;
VARYING vec2 vary_texcoord1;
@@ -38,4 +42,17 @@ VARYING vec2 vary_texcoord1;
void main()
{
frag_color = abs(texture2D(tex0, vary_texcoord0.xy) - texture2D(tex1, vary_texcoord0.xy));
+
+ vec2 dither_coord;
+ dither_coord[0] = vary_texcoord0[0] * dither_scale_s;
+ dither_coord[1] = vary_texcoord0[1] * dither_scale_t;
+ vec4 dither_vec = texture(dither_tex, dither_coord.xy);
+
+ for(int i = 0; i < 3; i++)
+ {
+ if(frag_color[i] < dither_vec[i] * dither_scale)
+ {
+ frag_color[i] = 0.f;
+ }
+ }
}
diff --git a/indra/newview/llscenemonitor.cpp b/indra/newview/llscenemonitor.cpp
index 2f1c4e065a..9de6b52d12 100644
--- a/indra/newview/llscenemonitor.cpp
+++ b/indra/newview/llscenemonitor.cpp
@@ -86,6 +86,7 @@ void LLSceneMonitor::destroyClass()
delete mRecording;
mRecording = NULL;
+ mDitheringTexture = NULL;
}
void LLSceneMonitor::reset()
@@ -108,6 +109,67 @@ void LLSceneMonitor::reset()
}
}
+void LLSceneMonitor::generateDitheringTexture(S32 width, S32 height)
+{
+#if 1
+ //4 * 4 matrix
+ mDitherMatrixWidth = 4;
+ S32 dither_matrix[4][4] =
+ {
+ {1, 9, 3, 11},
+ {13, 5, 15, 7},
+ {4, 12, 2, 10},
+ {16, 8, 14, 6}
+ };
+
+ mDitherScale = 255.f / 17;
+#else
+ //8 * 8 matrix
+ mDitherMatrixWidth = 16;
+ S32 dither_matrix[16][16] =
+ {
+ {1, 49, 13, 61, 4, 52, 16, 64, 1, 49, 13, 61, 4, 52, 16, 64},
+ {33, 17, 45, 29, 36, 20, 48, 32, 33, 17, 45, 29, 36, 20, 48, 32},
+ {9, 57, 5, 53, 12, 60, 8, 56, 9, 57, 5, 53, 12, 60, 8, 56},
+ {41, 25, 37, 21, 44, 28, 40, 24, 41, 25, 37, 21, 44, 28, 40, 24},
+ {3, 51, 15, 63, 2, 50, 14, 62, 3, 51, 15, 63, 2, 50, 14, 62},
+ {35, 19, 47, 31, 34, 18, 46, 30, 35, 19, 47, 31, 34, 18, 46, 30},
+ {11, 59, 7, 55, 10, 58, 6, 54, 11, 59, 7, 55, 10, 58, 6, 54},
+ {43, 27, 39, 23, 42, 26, 38, 22, 43, 27, 39, 23, 42, 26, 38, 22},
+ {1, 49, 13, 61, 4, 52, 16, 64, 1, 49, 13, 61, 4, 52, 16, 64},
+ {33, 17, 45, 29, 36, 20, 48, 32, 33, 17, 45, 29, 36, 20, 48, 32},
+ {9, 57, 5, 53, 12, 60, 8, 56, 9, 57, 5, 53, 12, 60, 8, 56},
+ {41, 25, 37, 21, 44, 28, 40, 24, 41, 25, 37, 21, 44, 28, 40, 24},
+ {3, 51, 15, 63, 2, 50, 14, 62, 3, 51, 15, 63, 2, 50, 14, 62},
+ {35, 19, 47, 31, 34, 18, 46, 30, 35, 19, 47, 31, 34, 18, 46, 30},
+ {11, 59, 7, 55, 10, 58, 6, 54, 11, 59, 7, 55, 10, 58, 6, 54},
+ {43, 27, 39, 23, 42, 26, 38, 22, 43, 27, 39, 23, 42, 26, 38, 22}
+ };
+
+ mDitherScale = 255.f / 65;
+#endif
+
+ LLPointer<LLImageRaw> image_raw = new LLImageRaw(mDitherMatrixWidth, mDitherMatrixWidth, 3);
+ U8* data = image_raw->getData();
+ for (S32 i = 0; i < mDitherMatrixWidth; i++)
+ {
+ for (S32 j = 0; j < mDitherMatrixWidth; j++)
+ {
+ U8 val = dither_matrix[i][j];
+ *data++ = val;
+ *data++ = val;
+ *data++ = val;
+ }
+ }
+
+ mDitheringTexture = LLViewerTextureManager::getLocalTexture(image_raw.get(), FALSE) ;
+ mDitheringTexture->setAddressMode(LLTexUnit::TAM_WRAP);
+ mDitheringTexture->setFilteringOption(LLTexUnit::TFO_POINT);
+
+ mDitherScaleS = (F32)width / mDitherMatrixWidth;
+ mDitherScaleT = (F32)height / mDitherMatrixWidth;
+}
+
void LLSceneMonitor::setDebugViewerVisible(BOOL visible)
{
mDebugViewerVisible = visible;
@@ -287,10 +349,13 @@ void LLSceneMonitor::compare()
{
mDiff = new LLRenderTarget();
mDiff->allocate(width, height, GL_RGBA, false, false, LLTexUnit::TT_TEXTURE, true);
+
+ generateDitheringTexture(width, height);
}
else if(mDiff->getWidth() != width || mDiff->getHeight() != height)
{
mDiff->resize(width, height, GL_RGBA);
+ generateDitheringTexture(width, height);
}
mDiff->bindTarget();
@@ -298,6 +363,10 @@ void LLSceneMonitor::compare()
gTwoTextureCompareProgram.bind();
+ gTwoTextureCompareProgram.uniform1f("dither_scale", mDitherScale);
+ gTwoTextureCompareProgram.uniform1f("dither_scale_s", mDitherScaleS);
+ gTwoTextureCompareProgram.uniform1f("dither_scale_t", mDitherScaleT);
+
gGL.getTexUnit(0)->activate();
gGL.getTexUnit(0)->enable(LLTexUnit::TT_TEXTURE);
gGL.getTexUnit(0)->bind(mFrames[0]);
@@ -308,6 +377,11 @@ void LLSceneMonitor::compare()
gGL.getTexUnit(1)->bind(mFrames[1]);
gGL.getTexUnit(1)->activate();
+ gGL.getTexUnit(2)->activate();
+ gGL.getTexUnit(2)->enable(LLTexUnit::TT_TEXTURE);
+ gGL.getTexUnit(2)->bind(mDitheringTexture);
+ gGL.getTexUnit(2)->activate();
+
gl_rect_2d_simple_tex(width, height);
mDiff->flush();
@@ -318,6 +392,8 @@ void LLSceneMonitor::compare()
gGL.getTexUnit(0)->unbind(LLTexUnit::TT_TEXTURE);
gGL.getTexUnit(1)->disable();
gGL.getTexUnit(1)->unbind(LLTexUnit::TT_TEXTURE);
+ gGL.getTexUnit(2)->disable();
+ gGL.getTexUnit(2)->unbind(LLTexUnit::TT_TEXTURE);
mHasNewDiff = TRUE;
diff --git a/indra/newview/llscenemonitor.h b/indra/newview/llscenemonitor.h
index 93e6c20bb9..709650e206 100644
--- a/indra/newview/llscenemonitor.h
+++ b/indra/newview/llscenemonitor.h
@@ -35,6 +35,7 @@
class LLCharacter;
class LLRenderTarget;
+class LLViewerTexture;
class LLSceneMonitor : public LLSingleton<LLSceneMonitor>
{
@@ -69,6 +70,7 @@ private:
void unfreezeScene();
void reset();
bool preCapture();
+ void generateDitheringTexture(S32 width, S32 height);
private:
BOOL mEnabled;
@@ -88,6 +90,12 @@ private:
F32 mSamplingTime; //time interval to capture frames, in seconds
F32 mDiffPixelRatio; //ratio of pixels used for comparison against the original mDiff size along one dimension
+ LLPointer<LLViewerTexture> mDitheringTexture;
+ S32 mDitherMatrixWidth;
+ F32 mDitherScale;
+ F32 mDitherScaleS;
+ F32 mDitherScaleT;
+
std::vector<LLAnimPauseRequest> mAvatarPauseHandles;
LLTrace::ExtendableRecording* mRecording;
diff --git a/indra/newview/llviewershadermgr.cpp b/indra/newview/llviewershadermgr.cpp
index 1aa36eafee..dd86ef4f34 100644
--- a/indra/newview/llviewershadermgr.cpp
+++ b/indra/newview/llviewershadermgr.cpp
@@ -2723,6 +2723,7 @@ BOOL LLViewerShaderMgr::loadShadersInterface()
gTwoTextureCompareProgram.bind();
gTwoTextureCompareProgram.uniform1i("tex0", 0);
gTwoTextureCompareProgram.uniform1i("tex1", 1);
+ gTwoTextureCompareProgram.uniform1i("dither_tex", 2);
}
}