Hi Jordi, thanks for the tip. I’ve attempted to draw the sphere into a FBO, and I’ve got the edges to blur. However, It seems I’m missing a step somewhere. As you can see when I rotate the camera, the sphere is drawn onto a flat plane instead of being a sphere, and I’m only getting part of it.
Here’s some code:
planet.h
#ifndef _PLANET
#define _PLANET
#include "ofMain.h"
class planet {
public:
ofSpherePrimitive sphere;
ofShader Xpass;
ofImage img;
ofFbo blurPass01;
planet();
void update();
void draw();
private:
};
#endif
planet.cpp
#include "planet.h"
planet::planet()
{
Xpass.load("shaders/Xpass");
sphere.set(200,20);
img.loadImage("leaves.jpg");
sphere.mapTexCoordsFromTexture(img.getTextureReference());
blurPass01.allocate(1024, 768);
blurPass01.begin();
ofClear(0, 0, 0, 0);
blurPass01.end();
}
void planet::update()
{
}
void planet::draw()
{
blurPass01.begin();
img.getTextureReference().bind();
sphere.draw();
img.getTextureReference().unbind();
blurPass01.end();
Xpass.begin();
Xpass.setUniformTexture("img", blurPass01.getTextureReference(0), 0);
blurPass01.draw(0, 0);
Xpass.end();
}
Xpass.vert
// vertex shader
#version 150
uniform mat4 modelViewProjectionMatrix;
in vec4 position;
in vec2 texcoord;
out vec2 texCoordVar;
void main()
{
texCoordVar = texcoord;
gl_Position = modelViewProjectionMatrix * position;
}
Xpass.frag
// fragment shader
#version 150
in vec2 texCoordVar;
out vec4 outputColor;
uniform sampler2DRect img;
void main()
{
vec4 color;
float blurAmnt = 5.0;
color += 1.0 * texture(img, texCoordVar + vec2(blurAmnt * -4.0, 0.0));
color += 2.0 * texture(img, texCoordVar + vec2(blurAmnt * -3.0, 0.0));
color += 3.0 * texture(img, texCoordVar + vec2(blurAmnt * -2.0, 0.0));
color += 4.0 * texture(img, texCoordVar + vec2(blurAmnt * -1.0, 0.0));
color += 5.0 * texture(img, texCoordVar + vec2(blurAmnt, 0));
color += 4.0 * texture(img, texCoordVar + vec2(blurAmnt * 1.0, 0.0));
color += 3.0 * texture(img, texCoordVar + vec2(blurAmnt * 2.0, 0.0));
color += 2.0 * texture(img, texCoordVar + vec2(blurAmnt * 3.0, 0.0));
color += 1.0 * texture(img, texCoordVar + vec2(blurAmnt * 4.0, 0.0));
color /= 25.0;
outputColor = color;
}