I'm not at all versed in OpenGL, but I really love the concept of blur and focus, and would love to be able to use it in my game.
As I understand it, for a standard box blur (or should I be trying for gaussian instead?) I need to make the value the average of all the neighboring values, weighted for distance, so I'd need a nested for loop to get the square of neighboring pixels?
I'm just a little unsure on how to access those values.
Help with a blur filter and GLSL?
Re: Help with a blur filter and GLSL?
Here's a typical GLSL gaussian blur shader:
This shader is applied once with a uShift of (x,0) (x is the blur distance) and once with (0,x).
A box blur looks the same, but the values in gaussFilter are differenr (and gaussRadius usually is smaller).
Code: Select all
#version 120
uniform sampler2D uTexture;
uniform vec2 uShift;
const int gaussRadius = 11;
const float gaussFilter[gaussRadius] = float[gaussRadius](
0.0402,0.0623,0.0877,0.1120,0.1297,0.1362,0.1297,0.1120,0.0877,0.0623,0.0402
);
void main() {
vec2 texCoord = gl_TexCoord[0].xy - float(int(gaussRadius/2)) * uShift;
vec3 color = vec3(0.0, 0.0, 0.0);
for (int i=0; i<gaussRadius; ++i) {
color += gaussFilter[i] * texture2D(uTexture, texCoord).xyz;
texCoord += uShift;
}
gl_FragColor = vec4(color,1.0);
}
A box blur looks the same, but the values in gaussFilter are differenr (and gaussRadius usually is smaller).
- dizzykiwi3
- Citizen
- Posts: 58
- Joined: Tue Jan 14, 2014 2:03 am
Re: Help with a blur filter and GLSL?
So in terms of adding it to love I would use love.graphics.newShader and bracket that code like this?
I seem to be getting an error from doing that
Code: Select all
gshader = love.graphics.newShader [[
uniform sampler2D uTexture;
uniform vec2 uShift;
const int gaussRadius = 11;
const float gaussFilter[gaussRadius] = float[gaussRadius](
0.0402,0.0623,0.0877,0.1120,0.1297,0.1362,0.1297,0.1120,0.0877,0.0623,0.0402
);
void main() {
vec2 texCoord = gl_TexCoord[0].xy - float(int(gaussRadius/2)) * uShift;
vec3 color = vec3(0.0, 0.0, 0.0);
for (int i=0; i<gaussRadius; ++i) {
color += gaussFilter[i] * texture2D(uTexture, texCoord).xyz;
texCoord += uShift;
}
gl_FragColor = vec4(color,1.0);
}
]]
Re: Help with a blur filter and GLSL?
you need to change it a little to match löve's shader syntax: https://love2d.org/wiki/love.graphics.n ... r_Languagedizzykiwi3 wrote:So in terms of adding it to love I would use love.graphics.newShader and bracket that code like this?I seem to be getting an error from doing thatCode: Select all
gshader = love.graphics.newShader [[ uniform sampler2D uTexture; uniform vec2 uShift; const int gaussRadius = 11; const float gaussFilter[gaussRadius] = float[gaussRadius]( 0.0402,0.0623,0.0877,0.1120,0.1297,0.1362,0.1297,0.1120,0.0877,0.0623,0.0402 ); void main() { vec2 texCoord = gl_TexCoord[0].xy - float(int(gaussRadius/2)) * uShift; vec3 color = vec3(0.0, 0.0, 0.0); for (int i=0; i<gaussRadius; ++i) { color += gaussFilter[i] * texture2D(uTexture, texCoord).xyz; texCoord += uShift; } gl_FragColor = vec4(color,1.0); } ]]
- dizzykiwi3
- Citizen
- Posts: 58
- Joined: Tue Jan 14, 2014 2:03 am
Re: Help with a blur filter and GLSL?
I have little to no idea how I would go about doing that, nor what I would pass into the shader for the externs.
Who is online
Users browsing this forum: Ahrefs [Bot], Bing [Bot] and 2 guests