From 438c49971832a6756c6097068902a6518a90271f Mon Sep 17 00:00:00 2001 From: Shyotl Date: Wed, 19 Sep 2012 15:06:34 -0500 Subject: [PATCH] And the shader.. --- .../shaders/class1/effects/MotionBlurF.glsl | 55 +++++++++++++++++++ indra/newview/llviewershadermgr.cpp | 21 +++++++ 2 files changed, 76 insertions(+) create mode 100644 indra/newview/app_settings/shaders/class1/effects/MotionBlurF.glsl diff --git a/indra/newview/app_settings/shaders/class1/effects/MotionBlurF.glsl b/indra/newview/app_settings/shaders/class1/effects/MotionBlurF.glsl new file mode 100644 index 000000000..89aaa8f10 --- /dev/null +++ b/indra/newview/app_settings/shaders/class1/effects/MotionBlurF.glsl @@ -0,0 +1,55 @@ +/** + * @file colorFilterF.glsl + * + * Copyright (c) 2007-$CurrentYear$, Linden Research, Inc. + * $License$ + */ + +#extension GL_ARB_texture_rectangle : enable + +#ifdef DEFINE_GL_FRAGCOLOR +out vec4 frag_color; +#else +#define frag_color gl_FragColor +#endif + +uniform sampler2DRect tex0; +uniform sampler2DRect tex1; +uniform mat4 inv_proj; +uniform mat4 prev_proj; +uniform vec2 screen_res; +uniform int blur_strength; + +VARYING vec2 vary_texcoord0; + +#define SAMPLE_COUNT 10 + +vec4 getPosition(vec2 pos_screen, out vec4 ndc) +{ + float depth = texture2DRect(tex1, pos_screen.xy).r; + vec2 sc = pos_screen.xy*2.0; + sc /= screen_res; + sc -= vec2(1.0,1.0); + 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; +} + +void main(void) +{ + vec4 ndc; + vec4 pos = getPosition(vary_texcoord0,ndc); + vec4 prev_pos = prev_proj * pos; + prev_pos/=prev_pos.w; + prev_pos.w = 1.0; + vec2 vel = ((ndc.xy-prev_pos.xy) * .5) * screen_res * .001 * blur_strength; + vec3 color = texture2DRect(tex0, vary_texcoord0.st).rgb; + vec2 texcoord = vary_texcoord0 + vel; + for(int i = 1; i < SAMPLE_COUNT; ++i, texcoord += vel) + { + color += texture2DRect(tex0, texcoord.st).rgb; + } + frag_color = vec4(color / SAMPLE_COUNT, 1.0); +} diff --git a/indra/newview/llviewershadermgr.cpp b/indra/newview/llviewershadermgr.cpp index 356cc6cac..25014b640 100644 --- a/indra/newview/llviewershadermgr.cpp +++ b/indra/newview/llviewershadermgr.cpp @@ -171,6 +171,7 @@ LLGLSLShader gPostColorFilterProgram(LLViewerShaderMgr::SHADER_EFFECT); //Not LLGLSLShader gPostNightVisionProgram(LLViewerShaderMgr::SHADER_EFFECT); //Not in mShaderList LLGLSLShader gPostGaussianBlurProgram(LLViewerShaderMgr::SHADER_EFFECT); //Not in mShaderList LLGLSLShader gPostPosterizeProgram(LLViewerShaderMgr::SHADER_EFFECT); //Not in mShaderList +LLGLSLShader gPostMotionBlurProgram(LLViewerShaderMgr::SHADER_EFFECT); //Not in mShaderList // Deferred rendering shaders LLGLSLShader gDeferredImpostorProgram(LLViewerShaderMgr::SHADER_DEFERRED); @@ -977,6 +978,26 @@ BOOL LLViewerShaderMgr::loadShadersEffects() gPostPosterizeProgram.uniform1i("tex0", 0); } } + + { + vector shaderUniforms; + shaderUniforms.reserve(3); + shaderUniforms.push_back("inv_proj"); + shaderUniforms.push_back("prev_proj"); + shaderUniforms.push_back("screen_res"); + + gPostMotionBlurProgram.mName = "Motion Blur Shader (Post)"; + gPostMotionBlurProgram.mShaderFiles.clear(); + gPostMotionBlurProgram.mShaderFiles.push_back(make_pair("effects/MotionBlurF.glsl", GL_FRAGMENT_SHADER_ARB)); + gPostMotionBlurProgram.mShaderFiles.push_back(make_pair("interface/onetexturenocolorV.glsl", GL_VERTEX_SHADER_ARB)); + gPostMotionBlurProgram.mShaderLevel = mVertexShaderLevel[SHADER_EFFECT]; + if(gPostMotionBlurProgram.createShader(NULL, &shaderUniforms)) + { + gPostMotionBlurProgram.bind(); + gPostMotionBlurProgram.uniform1i("tex0", 0); + gPostMotionBlurProgram.uniform1i("tex1", 1); + } + } #endif return success;