How to use shaders

How can I use Vignette shaders: .vert and .frag ? I saw tutorial but there was only example with Material. Vignette work for screen, not objects with materials.

@Skatty said: How can I use Vignette shaders: .vert and .frag ? I saw tutorial but there was only example with Material. Vignette work for screen, not objects with materials.

This needs to use a post processing filter. It takes the outputted frame buffer image and applies the shaders to the rendered scene.

Where is this .vert/.frag from? And…
The example doesn’t have the filter with it?

1 Like

Ok but which post processing filter? I have to create my own?
And here are the codes:
vert:
[java]attribute vec4 a_color;
attribute vec3 a_position;
attribute vec2 a_texCoord0;

uniform mat4 u_projTrans;

varying vec4 v_color;
varying vec2 v_texCoord0;

void main() {
v_color = a_color;
v_texCoord0 = a_texCoord0;
gl_Position = u_projTrans * vec4(a_position, 1.);
}[/java]
and frag
[java]varying vec4 v_color;
varying vec2 v_texCoord0;

uniform vec2 u_resolution;
uniform sampler2D u_sampler2D;

const float outerRadius = 0.65f;
const float innerRadius = 0.4f;
const float intensity = 0.6f;

void main() {
vec4 color = texture2D(u_sampler2D, v_texCoord0) * v_color;

vec2 relativePosition = gl_FragCoord.xy / u_resolution - 0.5;
// relativePosition.x *= u_resolution.x / u_resolution.y;
float len = length(relativePosition);
float vignette = smoothstep(outerRadius, innerRadius, len);
color.rgb = mix(color.rgb, color.rgb * vignette, intensity);

gl_FragColor = color;

}[/java]

Where did you get these shaders from? If I know the source (which should hint at the user that wrote them), we can ask about the filter and find out where it is.

It’s pretty rare that a set of shaders would be put together by someone here without the associated code for being able to make use of them.

And, was there a material definition file for these?

1 Like

description

first you need to make a .j3md (jme 3 material definiton) file, inside it you reference your vert and frag files and your user variables. your vert and frag files usually go in the same folder with your j3md.

there a wiki that explains the etails here: https://wiki.jmonkeyengine.org/legacy/doku.php/jme3:advanced:jme3_shaders

then you load the j3md material as explained in the material tutorial, (but using your own mat def instead of the Unshaded or Lighting)

if your shader is meant to be a full screen filter, you still make a .j3md but you also need to make a YourFiler extends Filter class. You may want to look at FadeFilter (because of how small/easy it is) for an easy example of how to create your own filter

(theres tutorials on the wiki that show how to add filters to your scene)

1 Like

Thank you both for help :slight_smile: