Changeset View
Standalone View
effects/blur/blurshader.cpp
Show First 20 Lines • Show All 67 Lines • ▼ Show 20 Line(s) | 66 | { | |||
---|---|---|---|---|---|
68 | m_shaderDownsample = nullptr; | 68 | m_shaderDownsample = nullptr; | ||
69 | 69 | | |||
70 | delete m_shaderUpsample; | 70 | delete m_shaderUpsample; | ||
71 | m_shaderUpsample = nullptr; | 71 | m_shaderUpsample = nullptr; | ||
72 | 72 | | |||
73 | delete m_shaderCopysample; | 73 | delete m_shaderCopysample; | ||
74 | m_shaderCopysample = nullptr; | 74 | m_shaderCopysample = nullptr; | ||
75 | 75 | | |||
76 | delete m_shaderNoisesample; | ||||
77 | m_shaderNoisesample = nullptr; | ||||
78 | | ||||
76 | setIsValid(false); | 79 | setIsValid(false); | ||
77 | } | 80 | } | ||
78 | 81 | | |||
79 | void GLSLBlurShader::setModelViewProjectionMatrix(const QMatrix4x4 &matrix) | 82 | void GLSLBlurShader::setModelViewProjectionMatrix(const QMatrix4x4 &matrix) | ||
80 | { | 83 | { | ||
81 | if (!isValid()) | 84 | if (!isValid()) | ||
82 | return; | 85 | return; | ||
83 | 86 | | |||
Show All 16 Lines | 87 | switch (m_activeSampleType) { | |||
100 | 103 | | |||
101 | case DownSampleType: | 104 | case DownSampleType: | ||
102 | if (matrix == m_matrixDownsample) | 105 | if (matrix == m_matrixDownsample) | ||
103 | return; | 106 | return; | ||
104 | 107 | | |||
105 | m_matrixDownsample = matrix; | 108 | m_matrixDownsample = matrix; | ||
106 | m_shaderDownsample->setUniform(m_mvpMatrixLocationDownsample, matrix); | 109 | m_shaderDownsample->setUniform(m_mvpMatrixLocationDownsample, matrix); | ||
107 | break; | 110 | break; | ||
111 | | ||||
112 | case NoiseSampleType: | ||||
113 | if (matrix == m_matrixNoisesample) | ||||
114 | return; | ||||
115 | | ||||
116 | m_matrixNoisesample = matrix; | ||||
117 | m_shaderNoisesample->setUniform(m_mvpMatrixLocationNoisesample, matrix); | ||||
118 | break; | ||||
108 | } | 119 | } | ||
109 | } | 120 | } | ||
110 | 121 | | |||
111 | void GLSLBlurShader::setOffset(float offset) | 122 | void GLSLBlurShader::setOffset(float offset) | ||
112 | { | 123 | { | ||
113 | if (!isValid()) | 124 | if (!isValid()) | ||
114 | return; | 125 | return; | ||
115 | 126 | | |||
116 | switch (m_activeSampleType) { | 127 | switch (m_activeSampleType) { | ||
117 | case UpSampleType: | 128 | case UpSampleType: | ||
118 | if (offset == m_offsetUpsample) | 129 | if (offset == m_offsetUpsample) | ||
119 | return; | 130 | return; | ||
120 | 131 | | |||
121 | m_offsetUpsample = offset; | 132 | m_offsetUpsample = offset; | ||
122 | m_shaderUpsample->setUniform(m_offsetLocationUpsample, offset); | 133 | m_shaderUpsample->setUniform(m_offsetLocationUpsample, offset); | ||
123 | break; | 134 | break; | ||
124 | 135 | | |||
125 | case DownSampleType: | 136 | case DownSampleType: | ||
126 | if (offset == m_offsetDownsample) | 137 | if (offset == m_offsetDownsample) | ||
127 | return; | 138 | return; | ||
128 | 139 | | |||
129 | m_offsetDownsample = offset; | 140 | m_offsetDownsample = offset; | ||
130 | m_shaderDownsample->setUniform(m_offsetLocationDownsample, offset); | 141 | m_shaderDownsample->setUniform(m_offsetLocationDownsample, offset); | ||
131 | break; | 142 | break; | ||
143 | | ||||
144 | case NoiseSampleType: | ||||
145 | if (offset == m_offsetNoisesample) | ||||
146 | return; | ||||
147 | | ||||
148 | m_offsetNoisesample = offset; | ||||
149 | m_shaderNoisesample->setUniform(m_offsetLocationNoisesample, offset); | ||||
150 | break; | ||||
132 | } | 151 | } | ||
133 | } | 152 | } | ||
134 | 153 | | |||
135 | void GLSLBlurShader::setTargetSize(QSize renderTextureSize) | 154 | void GLSLBlurShader::setTargetTextureSize(QSize renderTextureSize) | ||
136 | { | 155 | { | ||
137 | if (!isValid()) | 156 | if (!isValid()) | ||
138 | return; | 157 | return; | ||
139 | 158 | | |||
140 | QVector2D texSize = QVector2D(renderTextureSize.width(), renderTextureSize.height()); | 159 | QVector2D texSize = QVector2D(renderTextureSize.width(), renderTextureSize.height()); | ||
141 | 160 | | |||
142 | switch (m_activeSampleType) { | 161 | switch (m_activeSampleType) { | ||
143 | case CopySampleType: | 162 | case CopySampleType: | ||
144 | if (renderTextureSize == m_renderTextureSizeCopysample) | | |||
145 | return; | | |||
146 | | ||||
147 | m_renderTextureSizeCopysample = renderTextureSize; | | |||
148 | m_shaderCopysample->setUniform(m_renderTextureSizeLocationCopysample, texSize); | 163 | m_shaderCopysample->setUniform(m_renderTextureSizeLocationCopysample, texSize); | ||
149 | break; | 164 | break; | ||
150 | 165 | | |||
151 | case UpSampleType: | 166 | case UpSampleType: | ||
152 | if (renderTextureSize == m_renderTextureSizeUpsample) | | |||
153 | return; | | |||
154 | | ||||
155 | m_renderTextureSizeUpsample = renderTextureSize; | | |||
156 | m_shaderUpsample->setUniform(m_renderTextureSizeLocationUpsample, texSize); | 167 | m_shaderUpsample->setUniform(m_renderTextureSizeLocationUpsample, texSize); | ||
157 | m_shaderUpsample->setUniform(m_halfpixelLocationUpsample, QVector2D(0.5 / texSize.x(), 0.5 / texSize.y())); | 168 | m_shaderUpsample->setUniform(m_halfpixelLocationUpsample, QVector2D(0.5 / texSize.x(), 0.5 / texSize.y())); | ||
158 | break; | 169 | break; | ||
159 | 170 | | |||
160 | case DownSampleType: | 171 | case DownSampleType: | ||
161 | if (renderTextureSize == m_renderTextureSizeDownsample) | | |||
162 | return; | | |||
163 | | ||||
164 | m_renderTextureSizeDownsample = renderTextureSize; | | |||
165 | m_shaderDownsample->setUniform(m_renderTextureSizeLocationDownsample, texSize); | 172 | m_shaderDownsample->setUniform(m_renderTextureSizeLocationDownsample, texSize); | ||
166 | m_shaderDownsample->setUniform(m_halfpixelLocationDownsample, QVector2D(0.5 / texSize.x(), 0.5 / texSize.y())); | 173 | m_shaderDownsample->setUniform(m_halfpixelLocationDownsample, QVector2D(0.5 / texSize.x(), 0.5 / texSize.y())); | ||
167 | break; | 174 | break; | ||
175 | | ||||
176 | case NoiseSampleType: | ||||
177 | m_shaderNoisesample->setUniform(m_renderTextureSizeLocationNoisesample, texSize); | ||||
178 | m_shaderNoisesample->setUniform(m_halfpixelLocationNoisesample, QVector2D(0.5 / texSize.x(), 0.5 / texSize.y())); | ||||
179 | break; | ||||
168 | } | 180 | } | ||
169 | } | 181 | } | ||
170 | 182 | | |||
183 | void GLSLBlurShader::setNoiseTextureSize(QSize noiseTextureSize) | ||||
184 | { | ||||
185 | QVector2D noiseTexSize = QVector2D(noiseTextureSize.width(), noiseTextureSize.height()); | ||||
186 | | ||||
187 | if (noiseTexSize != m_noiseTextureSizeNoisesample) { | ||||
188 | m_noiseTextureSizeNoisesample = noiseTexSize; | ||||
189 | m_shaderNoisesample->setUniform(m_noiseTextureSizeLocationNoisesample, noiseTexSize); | ||||
190 | } | ||||
191 | } | ||||
192 | | ||||
193 | void GLSLBlurShader::setTexturePosition(QPoint texPos) | ||||
194 | { | ||||
195 | m_shaderNoisesample->setUniform(m_texStartPosLocationNoisesample, QVector2D(-texPos.x(), texPos.y())); | ||||
196 | } | ||||
197 | | ||||
171 | void GLSLBlurShader::setBlurRect(QRect blurRect, QSize screenSize) | 198 | void GLSLBlurShader::setBlurRect(QRect blurRect, QSize screenSize) | ||
172 | { | 199 | { | ||
173 | if (!isValid() || blurRect == m_blurRectCopysample) | 200 | if (!isValid() || blurRect == m_blurRectCopysample) | ||
174 | return; | 201 | return; | ||
175 | 202 | | |||
176 | m_blurRectCopysample = blurRect; | 203 | m_blurRectCopysample = blurRect; | ||
177 | 204 | | |||
178 | QVector4D rect = QVector4D( | 205 | QVector4D rect = QVector4D( | ||
179 | blurRect.bottomLeft().x() / float(screenSize.width()), | 206 | blurRect.bottomLeft().x() / float(screenSize.width()), | ||
180 | 1.0 - blurRect.bottomLeft().y() / float(screenSize.height()), | 207 | 1.0 - blurRect.bottomLeft().y() / float(screenSize.height()), | ||
181 | blurRect.topRight().x() / float(screenSize.width()), | 208 | blurRect.topRight().x() / float(screenSize.width()), | ||
182 | 1.0 - blurRect.topRight().y() / float(screenSize.height()) | 209 | 1.0 - blurRect.topRight().y() / float(screenSize.height()) | ||
183 | ); | 210 | ); | ||
184 | 211 | | |||
185 | m_shaderCopysample->setUniform(m_blurRectLocationCopysample, rect); | 212 | m_shaderCopysample->setUniform(m_blurRectLocationCopysample, rect); | ||
186 | } | 213 | } | ||
187 | 214 | | |||
188 | void GLSLBlurShader::bind(SampleType sampleType) | 215 | void GLSLBlurShader::bind(SampleType sampleType) | ||
fredrik: This only needs to be done once after the shader has been linked. | |||||
189 | { | 216 | { | ||
190 | if (!isValid()) | 217 | if (!isValid()) | ||
191 | return; | 218 | return; | ||
192 | 219 | | |||
193 | switch (sampleType) { | 220 | switch (sampleType) { | ||
194 | case CopySampleType: | 221 | case CopySampleType: | ||
195 | ShaderManager::instance()->pushShader(m_shaderCopysample); | 222 | ShaderManager::instance()->pushShader(m_shaderCopysample); | ||
196 | break; | 223 | break; | ||
197 | 224 | | |||
198 | case UpSampleType: | 225 | case UpSampleType: | ||
199 | ShaderManager::instance()->pushShader(m_shaderUpsample); | 226 | ShaderManager::instance()->pushShader(m_shaderUpsample); | ||
200 | break; | 227 | break; | ||
201 | 228 | | |||
202 | case DownSampleType: | 229 | case DownSampleType: | ||
203 | ShaderManager::instance()->pushShader(m_shaderDownsample); | 230 | ShaderManager::instance()->pushShader(m_shaderDownsample); | ||
204 | break; | 231 | break; | ||
232 | | ||||
233 | case NoiseSampleType: | ||||
234 | ShaderManager::instance()->pushShader(m_shaderNoisesample); | ||||
235 | break; | ||||
205 | } | 236 | } | ||
206 | 237 | | |||
207 | m_activeSampleType = sampleType; | 238 | m_activeSampleType = sampleType; | ||
208 | } | 239 | } | ||
209 | 240 | | |||
210 | void GLSLBlurShader::unbind() | 241 | void GLSLBlurShader::unbind() | ||
211 | { | 242 | { | ||
212 | ShaderManager::instance()->popShader(); | 243 | ShaderManager::instance()->popShader(); | ||
213 | } | 244 | } | ||
214 | 245 | | |||
215 | void GLSLBlurShader::init() | 246 | void GLSLBlurShader::init() | ||
216 | { | 247 | { | ||
217 | const bool gles = GLPlatform::instance()->isGLES(); | 248 | const bool gles = GLPlatform::instance()->isGLES(); | ||
218 | const bool glsl_140 = !gles && GLPlatform::instance()->glslVersion() >= kVersionNumber(1, 40); | 249 | const bool glsl_140 = !gles && GLPlatform::instance()->glslVersion() >= kVersionNumber(1, 40); | ||
219 | const bool core = glsl_140 || (gles && GLPlatform::instance()->glslVersion() >= kVersionNumber(3, 0)); | 250 | const bool core = glsl_140 || (gles && GLPlatform::instance()->glslVersion() >= kVersionNumber(3, 0)); | ||
220 | 251 | | |||
221 | QByteArray vertexSource; | 252 | QByteArray vertexSource; | ||
222 | QByteArray fragmentDownSource; | 253 | QByteArray fragmentDownSource; | ||
223 | QByteArray fragmentUpSource; | 254 | QByteArray fragmentUpSource; | ||
224 | QByteArray fragmentCopySource; | 255 | QByteArray fragmentCopySource; | ||
256 | QByteArray fragmentNoiseSource; | ||||
225 | 257 | | |||
226 | const QByteArray attribute = core ? "in" : "attribute"; | 258 | const QByteArray attribute = core ? "in" : "attribute"; | ||
227 | const QByteArray texture2D = core ? "texture" : "texture2D"; | 259 | const QByteArray texture2D = core ? "texture" : "texture2D"; | ||
228 | const QByteArray fragColor = core ? "fragColor" : "gl_FragColor"; | 260 | const QByteArray fragColor = core ? "fragColor" : "gl_FragColor"; | ||
229 | 261 | | |||
230 | QString glHeaderString; | 262 | QString glHeaderString; | ||
231 | 263 | | |||
232 | if (gles) { | 264 | if (gles) { | ||
▲ Show 20 Lines • Show All 93 Lines • ▼ Show 20 Line(s) | |||||
326 | streamFragCopy << "void main(void)\n"; | 358 | streamFragCopy << "void main(void)\n"; | ||
327 | streamFragCopy << "{\n"; | 359 | streamFragCopy << "{\n"; | ||
328 | streamFragCopy << " vec2 uv = vec2(gl_FragCoord.xy / renderTextureSize);\n"; | 360 | streamFragCopy << " vec2 uv = vec2(gl_FragCoord.xy / renderTextureSize);\n"; | ||
329 | streamFragCopy << " " << fragColor << " = " << texture2D << "(texUnit, clamp(uv, blurRect.xy, blurRect.zw));\n"; | 361 | streamFragCopy << " " << fragColor << " = " << texture2D << "(texUnit, clamp(uv, blurRect.xy, blurRect.zw));\n"; | ||
330 | streamFragCopy << "}\n"; | 362 | streamFragCopy << "}\n"; | ||
331 | 363 | | |||
332 | streamFragCopy.flush(); | 364 | streamFragCopy.flush(); | ||
333 | 365 | | |||
366 | // Fragment shader - Noise texture | ||||
367 | // =================================================================== | ||||
368 | QTextStream streamFragNoise(&fragmentNoiseSource); | ||||
369 | | ||||
370 | streamFragNoise << glHeaderString << glUniformString; | ||||
371 | | ||||
372 | streamFragNoise << "uniform sampler2D noiseTexUnit;\n"; | ||||
373 | streamFragNoise << "uniform vec2 noiseTextureSize;\n"; | ||||
374 | streamFragNoise << "uniform vec2 texStartPos;\n"; | ||||
375 | | ||||
376 | // Upsampling + Noise | ||||
377 | streamFragNoise << "void main(void)\n"; | ||||
378 | streamFragNoise << "{\n"; | ||||
379 | streamFragNoise << " vec2 uv = vec2(gl_FragCoord.xy / renderTextureSize);\n"; | ||||
380 | streamFragNoise << " vec2 uvNoise = vec2((texStartPos.xy + gl_FragCoord.xy) / noiseTextureSize);\n"; | ||||
381 | streamFragNoise << " \n"; | ||||
382 | streamFragNoise << " vec4 sum = " << texture2D << "(texUnit, uv + vec2(-halfpixel.x * 2.0, 0.0) * offset);\n"; | ||||
Always adding the noise value will make the pattern invisible when blurring a white area. Could this shader also do the final upscaling, so the two operations are combined? fredrik: Always adding the noise value will make the pattern invisible when blurring a white area. | |||||
Fixed invisible problem. Combining upscaling and noise would add too much complication. anemeth: Fixed invisible problem.
Combining upscaling and noise would add too much complication.
It's… | |||||
Subtracting reverses the problem though, making the effect invisible over black backgrounds. I would subtract 0.5 from the noise value before adding it instead, so the range becomes [-0.5..+0.5] instead of [0...1].
Doing both in one pass is usually faster though, because you only rasterize half as many pixels. Isn't combining the passes a matter of copying the code from the main function in the upscaling shader, and adding the noise value after dividing the sum by 12? The blur effect would just need to switch from the upscale shader to the noise shader before doing the final pass. fredrik: > Fixed invisible problem.
Subtracting reverses the problem though, making the effect… | |||||
383 | streamFragNoise << " sum += " << texture2D << "(texUnit, uv + vec2(-halfpixel.x, halfpixel.y) * offset) * 2.0;\n"; | ||||
384 | streamFragNoise << " sum += " << texture2D << "(texUnit, uv + vec2(0.0, halfpixel.y * 2.0) * offset);\n"; | ||||
385 | streamFragNoise << " sum += " << texture2D << "(texUnit, uv + vec2(halfpixel.x, halfpixel.y) * offset) * 2.0;\n"; | ||||
386 | streamFragNoise << " sum += " << texture2D << "(texUnit, uv + vec2(halfpixel.x * 2.0, 0.0) * offset);\n"; | ||||
387 | streamFragNoise << " sum += " << texture2D << "(texUnit, uv + vec2(halfpixel.x, -halfpixel.y) * offset) * 2.0;\n"; | ||||
388 | streamFragNoise << " sum += " << texture2D << "(texUnit, uv + vec2(0.0, -halfpixel.y * 2.0) * offset);\n"; | ||||
389 | streamFragNoise << " sum += " << texture2D << "(texUnit, uv + vec2(-halfpixel.x, -halfpixel.y) * offset) * 2.0;\n"; | ||||
390 | streamFragNoise << " \n"; | ||||
391 | streamFragNoise << " " << fragColor << " = sum / 12.0 - (vec4(0.5, 0.5, 0.5, 0) - vec4(" << texture2D << "(noiseTexUnit, uvNoise).rrr, 0));\n"; | ||||
fredrik: This still subtracts the noise value. See the first part of my comment above. | |||||
Yes, it substrats (darkens) the noise, but this time I added an abs() function to it. Before | After ---------------- 100 95 (substracted normally) 10 5 (substracted normally) 8 3 (substracted normally) 5 0 (substracted normally) 4 1 (4 - 5 = -1 ---> abs(-1) = 1) 2 3 (3 - 5 = -3 ---> abs(-3) = 3) 0 5 (0 - 5 = -5 ---> abs(-5) = 5) anemeth: Yes, it substrats (darkens) the noise, but this time I added an abs() function to it.
If the… | |||||
Right, I missed the abs(). The downside though is that the stronger the noise, the more the brightness of the image is reduced. If you are concerned about the cost of an additional subtraction, you can avoid that by changing the texture format to GL_R8_SNORM. That's a GL 3.1 feature though, so it would need a fallback path. fredrik: Right, I missed the abs(). The downside though is that the stronger the noise, the more the… | |||||
392 | streamFragNoise << "}\n"; | ||||
393 | | ||||
394 | streamFragNoise.flush(); | ||||
395 | | ||||
334 | 396 | | |||
335 | m_shaderDownsample = ShaderManager::instance()->loadShaderFromCode(vertexSource, fragmentDownSource); | 397 | m_shaderDownsample = ShaderManager::instance()->loadShaderFromCode(vertexSource, fragmentDownSource); | ||
336 | m_shaderUpsample = ShaderManager::instance()->loadShaderFromCode(vertexSource, fragmentUpSource); | 398 | m_shaderUpsample = ShaderManager::instance()->loadShaderFromCode(vertexSource, fragmentUpSource); | ||
337 | m_shaderCopysample = ShaderManager::instance()->loadShaderFromCode(vertexSource, fragmentCopySource); | 399 | m_shaderCopysample = ShaderManager::instance()->loadShaderFromCode(vertexSource, fragmentCopySource); | ||
400 | m_shaderNoisesample = ShaderManager::instance()->loadShaderFromCode(vertexSource, fragmentNoiseSource); | ||||
338 | 401 | | |||
339 | bool areShadersValid = m_shaderDownsample->isValid() && m_shaderUpsample->isValid() && m_shaderCopysample->isValid(); | 402 | bool areShadersValid = m_shaderDownsample->isValid() && | ||
403 | m_shaderUpsample->isValid() && | ||||
404 | m_shaderCopysample->isValid() && | ||||
405 | m_shaderNoisesample->isValid(); | ||||
340 | setIsValid(areShadersValid); | 406 | setIsValid(areShadersValid); | ||
341 | 407 | | |||
342 | if (areShadersValid) { | 408 | if (areShadersValid) { | ||
343 | m_mvpMatrixLocationDownsample = m_shaderDownsample->uniformLocation("modelViewProjectionMatrix"); | 409 | m_mvpMatrixLocationDownsample = m_shaderDownsample->uniformLocation("modelViewProjectionMatrix"); | ||
344 | m_offsetLocationDownsample = m_shaderDownsample->uniformLocation("offset"); | 410 | m_offsetLocationDownsample = m_shaderDownsample->uniformLocation("offset"); | ||
345 | m_renderTextureSizeLocationDownsample = m_shaderDownsample->uniformLocation("renderTextureSize"); | 411 | m_renderTextureSizeLocationDownsample = m_shaderDownsample->uniformLocation("renderTextureSize"); | ||
346 | m_halfpixelLocationDownsample = m_shaderDownsample->uniformLocation("halfpixel"); | 412 | m_halfpixelLocationDownsample = m_shaderDownsample->uniformLocation("halfpixel"); | ||
347 | 413 | | |||
348 | m_mvpMatrixLocationUpsample = m_shaderUpsample->uniformLocation("modelViewProjectionMatrix"); | 414 | m_mvpMatrixLocationUpsample = m_shaderUpsample->uniformLocation("modelViewProjectionMatrix"); | ||
349 | m_offsetLocationUpsample = m_shaderUpsample->uniformLocation("offset"); | 415 | m_offsetLocationUpsample = m_shaderUpsample->uniformLocation("offset"); | ||
350 | m_renderTextureSizeLocationUpsample = m_shaderUpsample->uniformLocation("renderTextureSize"); | 416 | m_renderTextureSizeLocationUpsample = m_shaderUpsample->uniformLocation("renderTextureSize"); | ||
351 | m_halfpixelLocationUpsample = m_shaderUpsample->uniformLocation("halfpixel"); | 417 | m_halfpixelLocationUpsample = m_shaderUpsample->uniformLocation("halfpixel"); | ||
352 | 418 | | |||
353 | m_mvpMatrixLocationCopysample = m_shaderCopysample->uniformLocation("modelViewProjectionMatrix"); | 419 | m_mvpMatrixLocationCopysample = m_shaderCopysample->uniformLocation("modelViewProjectionMatrix"); | ||
354 | m_renderTextureSizeLocationCopysample = m_shaderCopysample->uniformLocation("renderTextureSize"); | 420 | m_renderTextureSizeLocationCopysample = m_shaderCopysample->uniformLocation("renderTextureSize"); | ||
355 | m_blurRectLocationCopysample = m_shaderCopysample->uniformLocation("blurRect"); | 421 | m_blurRectLocationCopysample = m_shaderCopysample->uniformLocation("blurRect"); | ||
356 | 422 | | |||
423 | m_mvpMatrixLocationNoisesample = m_shaderNoisesample->uniformLocation("modelViewProjectionMatrix"); | ||||
424 | m_offsetLocationNoisesample = m_shaderNoisesample->uniformLocation("offset"); | ||||
425 | m_renderTextureSizeLocationNoisesample = m_shaderNoisesample->uniformLocation("renderTextureSize"); | ||||
426 | m_noiseTextureSizeLocationNoisesample = m_shaderNoisesample->uniformLocation("noiseTextureSize"); | ||||
427 | m_texStartPosLocationNoisesample = m_shaderNoisesample->uniformLocation("texStartPos"); | ||||
428 | m_halfpixelLocationNoisesample = m_shaderNoisesample->uniformLocation("halfpixel"); | ||||
429 | | ||||
357 | QMatrix4x4 modelViewProjection; | 430 | QMatrix4x4 modelViewProjection; | ||
358 | const QSize screenSize = effects->virtualScreenSize(); | 431 | const QSize screenSize = effects->virtualScreenSize(); | ||
359 | modelViewProjection.ortho(0, screenSize.width(), screenSize.height(), 0, 0, 65535); | 432 | modelViewProjection.ortho(0, screenSize.width(), screenSize.height(), 0, 0, 65535); | ||
360 | 433 | | |||
361 | //Add default values to the uniforms of the shaders | 434 | //Add default values to the uniforms of the shaders | ||
362 | ShaderManager::instance()->pushShader(m_shaderDownsample); | 435 | ShaderManager::instance()->pushShader(m_shaderDownsample); | ||
363 | m_shaderDownsample->setUniform(m_mvpMatrixLocationDownsample, modelViewProjection); | 436 | m_shaderDownsample->setUniform(m_mvpMatrixLocationDownsample, modelViewProjection); | ||
364 | m_shaderDownsample->setUniform(m_offsetLocationDownsample, float(1.0)); | 437 | m_shaderDownsample->setUniform(m_offsetLocationDownsample, float(1.0)); | ||
Show All 9 Lines | |||||
374 | ShaderManager::instance()->popShader(); | 447 | ShaderManager::instance()->popShader(); | ||
375 | 448 | | |||
376 | ShaderManager::instance()->pushShader(m_shaderCopysample); | 449 | ShaderManager::instance()->pushShader(m_shaderCopysample); | ||
377 | m_shaderCopysample->setUniform(m_mvpMatrixLocationCopysample, modelViewProjection); | 450 | m_shaderCopysample->setUniform(m_mvpMatrixLocationCopysample, modelViewProjection); | ||
378 | m_shaderCopysample->setUniform(m_renderTextureSizeLocationCopysample, QVector2D(1.0, 1.0)); | 451 | m_shaderCopysample->setUniform(m_renderTextureSizeLocationCopysample, QVector2D(1.0, 1.0)); | ||
379 | m_shaderCopysample->setUniform(m_blurRectLocationCopysample, QVector4D(1.0, 1.0, 1.0, 1.0)); | 452 | m_shaderCopysample->setUniform(m_blurRectLocationCopysample, QVector4D(1.0, 1.0, 1.0, 1.0)); | ||
380 | ShaderManager::instance()->popShader(); | 453 | ShaderManager::instance()->popShader(); | ||
381 | 454 | | |||
455 | ShaderManager::instance()->pushShader(m_shaderNoisesample); | ||||
456 | m_shaderNoisesample->setUniform(m_mvpMatrixLocationNoisesample, modelViewProjection); | ||||
457 | m_shaderNoisesample->setUniform(m_offsetLocationNoisesample, float(1.0)); | ||||
458 | m_shaderNoisesample->setUniform(m_renderTextureSizeLocationNoisesample, QVector2D(1.0, 1.0)); | ||||
459 | m_shaderNoisesample->setUniform(m_noiseTextureSizeLocationNoisesample, QVector2D(1.0, 1.0)); | ||||
460 | m_shaderNoisesample->setUniform(m_texStartPosLocationNoisesample, QVector2D(1.0, 1.0)); | ||||
461 | m_shaderNoisesample->setUniform(m_halfpixelLocationNoisesample, QVector2D(1.0, 1.0)); | ||||
462 | | ||||
463 | glUniform1i(m_shaderNoisesample->uniformLocation("texUnit"), 0); | ||||
464 | glUniform1i(m_shaderNoisesample->uniformLocation("noiseTexUnit"), 1); | ||||
465 | | ||||
466 | ShaderManager::instance()->popShader(); | ||||
467 | | ||||
382 | m_activeSampleType = -1; | 468 | m_activeSampleType = -1; | ||
469 | | ||||
470 | m_offsetDownsample = 0.0; | ||||
471 | m_matrixDownsample = QMatrix4x4(); | ||||
472 | | ||||
473 | m_offsetUpsample = 0.0; | ||||
474 | m_matrixUpsample = QMatrix4x4(); | ||||
475 | | ||||
476 | m_matrixCopysample = QMatrix4x4(); | ||||
477 | m_blurRectCopysample = QRect(); | ||||
478 | | ||||
479 | m_offsetNoisesample = 0.0; | ||||
480 | m_noiseTextureSizeNoisesample = QVector2D(); | ||||
481 | m_matrixNoisesample = QMatrix4x4(); | ||||
383 | } | 482 | } | ||
384 | } | 483 | } |
This only needs to be done once after the shader has been linked.