I’ve been looking for it but I haven’t found anything on the forum nor in the code. The only thing that comes close is the OldFilm filter of the shader blow project and I only wanted to have the vignetting effect.
Thus I took pieces from here and there to achieve a simple vignette effect. The original is from ShaderLesson3 · mattdesl/lwjgl-basics Wiki · GitHub
So if anyone is looking for something similar in the future they don’t need to put it together by themselves. If you think it’s worth it then I’d be more than happy if you add it to the core effects collection as well.
VignetteFilter.java
[java]
import com.jme3.asset.AssetManager;
import com.jme3.material.Material;
import com.jme3.math.Vector2f;
import com.jme3.post.Filter;
import com.jme3.renderer.RenderManager;
import com.jme3.renderer.ViewPort;
/**
- Originally from https://github.com/mattdesl/lwjgl-basics/wiki/ShaderLesson3
-
@author Remo Arpagaus
*/
public class VignetteFilter extends Filter {
private Material material;
private float radius = 0.75f;
private float softness = 0.5f;
private float strength = 0.5f;
public VignetteFilter() {
super(VignetteFilter.class.getSimpleName());
}
@Override
protected void initFilter(AssetManager assetManager, RenderManager arg1, ViewPort arg2, int w, int h) {
material = new Material(assetManager, “MatDefs/Post/Vignette.j3md”);
material.setVector2(“Resolution”, new Vector2f(w, h));
material.setFloat(“Radius”, radius);
material.setFloat(“Softness”, softness);
material.setFloat(“Strength”, strength);
}
@Override
protected Material getMaterial() {
return material;
}
public float getRadius() {
return radius;
}
/**
- The radius of the vignette. Where a value of 0.5 will lead to a circle fitting the screen.
-
@param radius
*/
public void setRadius(float radius) {
checkFloatArgument(radius, 0, 1, “radius”);
this.radius = radius;
}
public float getSoftness() {
return softness;
}
/**
- The softness of the vignette’s edge. A value between 0 and 1.
-
@param softness
*/
public void setSoftness(float softness) {
checkFloatArgument(softness, 0, 1, “softness”);
this.softness = softness;
}
public float getStrength() {
return strength;
}
/**
- The strength vignette. A value between 0 and 1. Where a value of 0 will result in no visible effect.
-
@param strength
*/
public void setStrength(float strength) {
checkFloatArgument(strength, 0, 1, “strength”);
this.strength = strength;
}
private static void checkFloatArgument(float value, float min, float max, String name) {
if (value < min || value > max) {
throw new IllegalArgumentException(name + " was " + value + " but should be between " + min + " and " + max);
}
}
}
[/java]
Vignette.j3md
[java]
MaterialDef Vignette {
MaterialParameters {
Int NumSamples
Int NumSamplesDepth
Texture2D Texture
Vector2 Resolution;
Float Radius;
Float Softness;
Float Strength;
}
Technique {
VertexShader GLSL100: Common/MatDefs/Post/Post.vert
FragmentShader GLSL100: MatDefs/Post/Vignette.frag
WorldParameters {
}
}
}
[/java]
Vignette.frag
[java]
uniform sampler2D m_Texture;
varying vec2 texCoord;
uniform vec2 m_Resolution;
uniform float m_Radius ;
uniform float m_Softness;
uniform float m_Strength;
void main() {
vec4 texColor = texture2D(m_Texture, texCoord);
vec2 position = (gl_FragCoord.xy / m_Resolution.xy) - vec2(0.5);
float len = length(position);
float vignette = smoothstep(m_Radius, m_Radius-m_Softness, len);
texColor.rgb = mix(texColor.rgb, texColor.rgb * vignette, m_Strength);
gl_FragColor = texColor;
}
[/java]