Thread: Image blur
View Single Post
Old 12-07-2006, 04:16 PM
jrodman jrodman is offline
Join Date: Jun 2003
Posts: 21
Originally Posted by jrodman View Post
Finally, when I increase the "blurScale" to 3 or more, it starts to look pixelated. I presume this is because there's no diagonal blurring. I think I can modify the script myself to blur over a box or circle. I will attempt to do so now.
Having looked a little closer, I now realize that the separate vertical and horizontal passes do generate diagonal blurring. I now think that the pixelation is generated by the fact that there is a fixed number of samples taken to generate the blurring. And this means that when the scale gets too big, it starts skipping pixels.

I tried increasing the number of samples, but the current code adds one line of c++ for each sample. There appears to be a limit to the amount of c++ code that can be passed to the render node's apply function.

Next I tried rewriting the c++ to include a for loop so there wouldn't have to be a separate line for each sample. This code, however, seems to be crashing. I have no way to debug it since it's getting run inside Vizard where I can't attach a debugger or print debug statements.

Here's my code:

		blur_source = """
		uniform sampler2D srcImage;
		uniform float blurScale;
		void main(void)
			vec4 color = vec4(0,0,0,0);
			float numSamples = blurScale * 4.0;
			for(float index = -numSamples; index <= numSamples; index += 1.0)
				float offset = index / %size%;
				float temp = index / numSamples;
				`float weight = 0.05 + ((1.0 - temp * temp) / 4.0);
				color += ( texture2D( srcImage, gl_TexCoord[0].xy + vec2( %modifier% ) ) * weight );
			color.a = 1.0;
			gl_FragColor = color / 1.7;

		#Create horizontal blur shader
		temp_source = blur_source.replace('%size%', str(float(size[0])) )
		blur_code = temp_source.replace('%modifier%', 'offset * blurScale, 0.0' )
		horzBlurShader = viz.addShader(frag=blur_code)

		#Create vertical blur shader
		temp_source = blur_source.replace('%size%', str(float(size[1])) )
		blur_code = temp_source.replace('%modifier%', '0.0, offset * blurScale' )
		vertBlurShader = viz.addShader(frag=blur_code)
I think I left the rest of your script the same. When I run this, I get a notification that a program crashed, but winviz is left running, taking up all of the CPU. I'm guessing this means that winviz spawns a process to run the c++, that process crashes, and winviz is left waiting for it.

Any ideas what would cause this? Is it worth pursuing if we're going to get a video card that will run your other script?
Reply With Quote