Motion Blur Effect with JME3

Question is quite simple : Is that possible to do motion blur with JME3 ? I found motion blur renderer pass on a JMEX library but i’m not sure it will work .



Thanks in advance

There is no built in Filter for MotionBlur for now, but of course it’s doable to implement a filter and shaders for it.

Anyone has an implementation of motion blur on his jme3 project and want to share ?

I can’t believe no one has a motion blur shader on his project … come on guys :wink:

We do have a lot of filters already. Motion blur is a bit more complex since it requires a motion vector buffer, the implementation for jME2 overrides the model’s material and is really fairly simple.

i see … so i should forget Motion Blur for now ?



Is there any way to do that again ? http://www.youtube.com/watch?v=t1FEZgGVwFk&feature=related i think i was avalaible in JME 1

Well since jme3 is shader based, maniulating the materials is not the best approach i guess.



There are actually two different options for you.

A) Wait untill someone makes a motion blur effect, to the rest of your game meanwhile

B) Read into motion blur technics, how jme3 works and write a motion blur filter yourself.



While B might be frustrating at first it is probably quite worth it in the long term since you learn much about shaders that way. However it will not be easy I guess, so A might be a better option depending on your knowledge.

I’ll do my best and i’ll try the B option thanks a lot :wink:

Yeah there are a lot of resources online.

You should read about shaders and look at how the filter system works in jME3.

I do not recommend using the code from jME1/2 since it manipulates the objects. For jME3 we need a filter that uses a motion vector buffer if possible.

By the way , does the JME team planing to build its own motion shaders ?

We are basically planning to rule the entire world…so i guess motion blur should find its place in JME3 on the path to glory



But…if YOU were contributing such a shader, you would definitely earn your place in monkeys paradise…

1 Like

I would love to ! and i want to rule the world with you guys :stuck_out_tongue:

I found a motion blur wrote in GLSL somewhere on the web if someone can do something with here’s the code :



[java]



// this creates the motion-vectors. Render the whole scene with this shader

#include “system.h”

varying vec2 texcoord0 :TEX0;

varying vec4 curpos :TEX1;

varying vec4 prevpos:TEX2;

#if IS_VERTEXuniform mat4 matcur;

uniform mat4 matprev;

void main(){

texcoord0=gl_MultiTexCoord0.xy;

curpos = matcur * gl_Vertex; prevpos = matprev * gl_Vertex;

gl_Position=curpos;

}

#endif#if IS_FRAGMENT

void main(){

vec2 position = curpos.xy/curpos.w;

vec2 position2 = prevpos.xy/prevpos.w;

#define BLUR_VECTOR_SCALE 60.0

vec2 delta = (position-position2) * (SCREEN_SIZE/BLUR_VECTOR_SCALE) +0.5;

float DOF_blur = abs(curpos.z/curpos.w - 0.8);

gl_FragColor = vec4(delta,DOF_blur,0);}#endif











// this is the final, post-processing step to do motion-blur

#include “system.h”

#define FAST_PRECISION//varying vec2 texcoord0;

#define texcoord0 gl_TexCoord[0].xy

#if IS_VERTEXvoid main()

{

texcoord0=gl_MultiTexCoord0.xy;

gl_Position=gl_Vertex;

}

#endif

#if IS_FRAGMENT

uniform samplerRect tex0;

uniform samplerRect tex1;

uniform samplerRect tex2;

const vec2 poisson[16]={

vec2(0.007937789, 0.73124397), vec2(-0.10177308, -0.6509396), vec2(-0.9906806, -0.63400936), vec2(-0.5583586, -0.3614012), vec2(0.7163085, 0.22836149), vec2(-0.65210974, 0.37117887), vec2(-0.12714535, 0.112056136), vec2(0.48898065, -0.66669613), vec2(-0.9744036, 0.9155904), vec2(0.9274436, -0.9896486), vec2(0.9782181, 0.90990245), vec2(0.96427417, -0.25506377), vec2(-0.5021933, -0.9712455), vec2(0.3091557, -0.17652994), vec2(0.4665941, 0.96454906), vec2(-0.461774, 0.9360856)};

void main(){

const float numSamples=8;

#define BLUR_VECTOR_SCALE 60.0

vec2 vector = (textureRect(tex0,texcoord0).xy-0.5) * BLUR_VECTOR_SCALE/numSamples;

vec4 color=0;

/* //


[ Depth of Field ]
[
#if 0
float radius = textureRect(tex1,texcoord0).z * 30;
for(int i=0;i<16;i++){
color+= textureRect(tex1,texcoord0+ radius*poisson);
}
color/=16;
gl_FragColor = color+ vector.xyxy*0.00001;
#else float radius = (textureRect(tex1,texcoord0).z+0.01) * 3;
#define SIZ 1
#define SIZ2 (SIZ*2+1) #define SIZ3 (SIZ2*SIZ2)
for(int y=-SIZ;y<=SIZ;y++){
for(int x=-SIZ;x<=SIZ;x++){
vec2 v = vec2(x,y);
float len=length(v)+1;
color+=textureRect(tex1,texcoord0+ radius*v)/len;
}
}
//color/=SIZ3;
color/=20;
gl_FragColor = color+ vector.xyxy*0.00001;
#endif //

/ */
#define METHOD 1
#if METHOD==1
for(float i=0;i<numSamples/2;i++){
color+= textureRect(tex1,texcoord0+vector*i);
color+= textureRect(tex2,texcoord0+vector*i);
}
for(float i=numSamples/2;i<numSamples;i++){
color+= textureRect(tex1,texcoord0+vector*i)*0.5;
color+= textureRect(tex2,texcoord0+vector*i)*0.5;
}
for(float i=0;i<numSamples/2;i++){
color+= textureRect(tex1,texcoord0-vector*i);
color+= textureRect(tex2,texcoord0-vector*i);
}
for(float i=numSamples/2;i<numSamples;i++){
color+= textureRect(tex1,texcoord0-vector*i)*0.5;
color+= textureRect(tex2,texcoord0-vector*i)*0.5;
}
gl_FragColor = color/(numSamples*3);
#endif
#if METHOD==2
for(float i=0;i<numSamples/2;i++){
color+= textureRect(tex1,texcoord0+vector*i);
}
for(float i=numSamples/2;i<numSamples;i++){
color+= textureRect(tex1,texcoord0+vector*i)*0.5;
}
for(float i=0;i<numSamples/2;i++){
color+= textureRect(tex1,texcoord0-vector*i);
}
for(float i=numSamples/2;i<numSamples;i++){
color+= textureRect(tex1,texcoord0-vector*i)*0.5;
}
gl_FragColor = color/(numSamples * 1.5);
#endif#if METHOD=:3
for(float i=0;i<numSamples;i++){
color+= textureRect(tex1,texcoord0+vector*i);
}
gl_FragColor = color/numSamples;
#endif
#if METHOD==4
for(float i=0;i<numSamples;i++){
vec4 color1 = textureRect(tex1,texcoord0-vector*i);
vec4 color2 = textureRect(tex2,texcoord0-vector*i)*0.01;
float alpha = i/(numSamples);
color += mix(color1,color2,alpha);
}
for(float i=1;i<numSamples;i++){
vec4 color1 = textureRect(tex1,texcoord0+vector*i);
vec4 color2 = textureRect(tex2,texcoord0+vector*i)*0.01;
float alpha = i/(numSamples);
color += mix(color1,color2,alpha);
}
gl_FragColor = color/(numSamples);
#endif
}
#endif
[/java]

I'm still learning shaders so i won't be able to help :(

In case someone decides to use this it would be really helpful if you could include your source and preferably the name of the original author, so proper credits can be given.

sure ! I found it here http://www.gamedev.net/topic/529351-glsl-motion-blur/