More shaders/filters to share if there be any interest

I have a couple more things I have been working on for my game that other people may (or may not) find useful. I’ll post some screen shots with a description of that they are.



Some of these screens just show the use of the BasicSSAO + the new FogFilter I posted here working together. Also…

A texture splatter shader (extension of the Lighting shader) (textures x10 + original texture)

An update to the Lighting.frag shader which allows you to tile the output texture by setting a scale (it works like the texture splatter… just for single textures… no need for alpha mapping in this one).

In stead of using DoF, I wrote a filter that does peripheral doubling. It does not have to do depth lookups, so it works a TON faster and gives the same basic impresion as if you were using DoF

This filter also does things like, ripple effect… with no pulling/tearing at the sides of the frame.



Anyways… here be a bunch of screens… let me know if anything listed here is something you’re interested in.



















Heh… no real way of showing the ripple effect without a video… this filter also contains a really cool warping effect that looks like a spherical punch that moves.



Well… here is a vid of the warp effect anyways…

http://youtu.be/YVRS9tsK8s8



And the ripple effect:
http://youtu.be/V2Xhhe5M9wM


Screen of the peripheral double set pretty high...
6 Likes

All your creations are very welcome in the official contributions repository. I know @mifth is quick with offering a place in his repos but in fact we have no control over them and most of the code in them is probably lost for the cause of the project. So if you PM me I’d be happy to give you commit access to create a “tonegod effects plugin” with all your creations as a jar file for all jme users to use :slight_smile:

1 Like

All your contributions look really nice! :slight_smile:

I cannot really say that I have explicit interest in your code, since I am far away from needing anything similar, but I doubt that any of JMonkeys would be angry on you if you would share as much as you can. :smiley:

I’d really like a T0neg0d effect plugin indeed.

The warp and wave effect looks very good

yeh, you come up with such amazing stuff, and so fast, thanks for sharing! you must make some tutorials and share your knowledge :slight_smile:

As always you are welcome to the shaderBlow.



Just paste it here and i will add everything.

@t0neg0d , can you share with your Ripple filter? I need to create anomaly field like this:

http://devmaster.net/posts/shader-effects-refraction



Thank you!

@mifth said:
@t0neg0d , can you share with your Ripple filter? I need to create anomaly field like this:
http://devmaster.net/posts/shader-effects-refraction

Thank you!


Hey you...

Do you need this as a post filter effect? If not, the code for doing this is in the GPU Animation Factory thingy I just posted. If you need to ensure no screen edge tearing issues, you'll want to grab it from the frag shader for that... otherwise.... um.... on sec...

[java]
const float pi = 3.14159;
const vec2 center = vec2(0.5);

// Stops edge tearing/pulling
vec2 deformFGradientDistance(in vec2 vecOut, in bool invert) {
float distX = distance(vecOut.x, center.x);
float distY = distance(vecOut.y, center.y);
if (!invert) {
distX = sin(distX * pi) * center.x;
distY = sin(distY * pi) * center.y;
} else {
distX = cos(distX * pi) * center.x;
distY = cos(distY * pi) * center.y;
}
return vec2(distX,distY);
}
float deformFAngleFromCenter(in vec2 vecOut) {
return atan(center.y-vecOut.y,center.x-vecOut.x);//-(pi/2);
}

// Image distortions
#ifdef USE_FWAVE
vec2 deformFRipple(in vec2 texCoords) {
vec2 vecOut = texCoords;
vec2 dist = deformFGradientDistance(vecOut, true);
// Centered Ripple //
vec2 tc = vecOut;
vec2 p = -1.0 + 2.0 * tc;
float len = length(p);
vecOut.x = center.x*cos(len*m_DeformF_Wave_SizeX-(g_Time*m_DeformF_Wave_SpeedX)*m_DeformF_Wave_DepthX)*(m_DeformF_Wave_DepthX*0.01);
vecOut.y = center.y*cos(len*m_DeformF_Wave_SizeY-(g_Time*m_DeformF_Wave_SpeedY)*m_DeformF_Wave_DepthY)*(m_DeformF_Wave_DepthY*0.01);

vecOut *= dist;

return vecOut;
}
[/java]

Replace m_DeformF uniform references with settings that work for you.

IMPORTANT!! This returns the offsets only, so you'll want to add this to the original texCoord.

EDIT: Forgot to add the constants

@t0neg0d Thanks!!!



Can you tell me is this post filter or not? :



[java]



/// <summary>

/// Shader to refract all pixels with their alpha channel set to 0.

/// </summary>





#ifdef GL_ES

precision highp float;

#endif





/// <summary>

/// Uniform variables.

/// <summary>

uniform vec2 ImageSize;

uniform vec2 TexelSize;

uniform sampler2D Sample0;



/// <summary>

/// Size of the refraction.

/// <summary>

uniform float Amplitude;



/// <summary>

/// Frequency of the refraction.

/// <summary>

uniform float Frequency;



/// <summary>

/// Relative speed (period) of the refraction.

/// <summary>

uniform float Period;



/// <summary>

/// Random number to animate or mix up the refracted results.

/// <summary>

uniform float RandomNumber;





/// <summary>

/// Varying variables.

/// <summary>

varying vec2 vUv;





// Description : Array and textureless GLSL 3D simplex noise function.

// Author : Ian McEwan, Ashima Arts.

// Maintainer : ijm

// Lastmod : 20110822 (ijm)

// License : Copyright © 2011 Ashima Arts. All rights reserved.

// Distributed under the MIT License. See LICENSE file.

// GitHub - ashima/webgl-noise: Procedural Noise Shader Routines compatible with WebGL

vec3 mod289(vec3 x) { return x - floor(x * (1.0 / 289.0)) * 289.0; }

vec4 mod289(vec4 x) { return x - floor(x * (1.0 / 289.0)) * 289.0; }

vec4 permute(vec4 x) { return mod289(((x34.0)+1.0)x); }

vec4 taylorInvSqrt(vec4 r) { return 1.79284291400159 - 0.85373472095314 * r; }

float snoise(vec3 v)

{

const vec2 C = vec2(1.0/6.0, 1.0/3.0) ;

const vec4 D = vec4(0.0, 0.5, 1.0, 2.0);



// First corner

vec3 i = floor(v + dot(v, C.yyy) );

vec3 x0 = v - i + dot(i, C.xxx) ;



// Other corners

vec3 g = step(x0.yzx, x0.xyz);

vec3 l = 1.0 - g;

vec3 i1 = min( g.xyz, l.zxy );

vec3 i2 = max( g.xyz, l.zxy );



// x0 = x0 - 0.0 + 0.0 * C.xxx;

// x1 = x0 - i1 + 1.0 * C.xxx;

// x2 = x0 - i2 + 2.0 * C.xxx;

// x3 = x0 - 1.0 + 3.0 * C.xxx;

vec3 x1 = x0 - i1 + C.xxx;

vec3 x2 = x0 - i2 + C.yyy; // 2.0
C.x = 1/3 = C.y

vec3 x3 = x0 - D.yyy; // -1.0+3.0
C.x = -0.5 = -D.y



// Permutations

i = mod289(i);

vec4 p = permute( permute( permute(

i.z + vec4(0.0, i1.z, i2.z, 1.0 ))

  • i.y + vec4(0.0, i1.y, i2.y, 1.0 ))
  • i.x + vec4(0.0, i1.x, i2.x, 1.0 ));



    // Gradients: 7x7 points over a square, mapped onto an octahedron.

    // The ring size 1717 = 289 is close to a multiple of 49 (496 = 294)

    float n_ = 0.142857142857; // 1.0/7.0

    vec3 ns = n_ * D.wyz - D.xzx;



    vec4 j = p - 49.0 * floor(p * ns.z * ns.z); // mod(p,7*7)



    vec4 x_ = floor(j * ns.z);

    vec4 y_ = floor(j - 7.0 * x_ ); // mod(j,N)



    vec4 x = x_ *ns.x + ns.yyyy;

    vec4 y = y_ *ns.x + ns.yyyy;

    vec4 h = 1.0 - abs(x) - abs(y);



    vec4 b0 = vec4( x.xy, y.xy );

    vec4 b1 = vec4( x.zw, y.zw );



    //vec4 s0 = vec4(lessThan(b0,0.0))*2.0 - 1.0;

    //vec4 s1 = vec4(lessThan(b1,0.0))*2.0 - 1.0;

    vec4 s0 = floor(b0)2.0 + 1.0;

    vec4 s1 = floor(b1)2.0 + 1.0;

    vec4 sh = -step(h, vec4(0.0));



    vec4 a0 = b0.xzyw + s0.xzyw
    sh.xxyy ;

    vec4 a1 = b1.xzyw + s1.xzyw
    sh.zzww ;



    vec3 p0 = vec3(a0.xy,h.x);

    vec3 p1 = vec3(a0.zw,h.y);

    vec3 p2 = vec3(a1.xy,h.z);

    vec3 p3 = vec3(a1.zw,h.w);



    //Normalise gradients

    vec4 norm = taylorInvSqrt(vec4(dot(p0,p0), dot(p1,p1), dot(p2, p2), dot(p3,p3)));

    p0 *= norm.x;

    p1 *= norm.y;

    p2 *= norm.z;

    p3 = norm.w;



    // Mix final noise value

    vec4 m = max(0.6 - vec4(dot(x0,x0), dot(x1,x1), dot(x2,x2), dot(x3,x3)), 0.0);

    m = m * m;

    return 42.0 * dot( m
    m, vec4( dot(p0,x0), dot(p1,x1),

    dot(p2,x2), dot(p3,x3) ) );

    }





    /// <summary>

    /// Compute the normal using a sobel filter on the adjacent noise pixels.

    ///

    /// Normally you would output the noise to a texture first and then calculate

    /// the normals on that texture to improve performance; however everthing is

    /// kept in this shader as a single process to help illustrate what’s going on.

    /// <summary>

    /// <returns>A normal vector.</returns>

    vec3 GetNormal ()

    {

    // Get Sobel values

    vec2 uv = vUv * Frequency;

    float z = RandomNumber * Period;



    float tl = snoise(vec3(uv.x - TexelSize.x, uv.y - TexelSize.y, z));

    float t = snoise(vec3(uv.x, uv.y - TexelSize.y, z));

    float tr = snoise(vec3(uv.x + TexelSize.x, uv.y - TexelSize.y, z));

    float l = snoise(vec3(uv.x - TexelSize.x, uv.y, z));

    float r = snoise(vec3(uv.x + TexelSize.x, uv.y, z));

    float bl = snoise(vec3(uv.x - TexelSize.x, uv.y + TexelSize.y, z));

    float b = snoise(vec3(uv.x, uv.y + TexelSize.y, z));

    float br = snoise(vec3(uv.x + TexelSize.x, uv.y + TexelSize.y, z));



    // Sobel filter

    vec3 normal = vec3((-tl - l * 2.0 - bl) + (tr + r * 2.0 + br),

    (-tl - t * 2.0 - tr) + (bl + b * 2.0 + br),

    1.0 / Amplitude);



    // Return normalized vector

    return normalize(normal);

    }





    /// <summary>

    /// Fragment shader entry.

    /// <summary>

    void main ()

    {

    // Refract only tagged pixels (that is, the alpha channel has been set)

    vec2 offset;

    if ( texture2D(Sample0, vUv).w == 0.0 )

    {

    // Method 1: Use noise as the refraction angle.

    // Fast and good results for some scenarios.

    //const float pi = 3.141592;

    //float noise = snoise(vec3((vUv * Frequency), RandomNumber * Period)) * pi;

    //offset = vec2(cos(noise), sin(noise)) * Amplitude * TexelSize;



    // Method 2: Get the normal from an animating normalmap to use as the refracted vector.

    // Slower, but better results.

    vec3 normal = GetNormal();

    offset = normal.xy;

    }



    // Use the colour at the specified offset into the texture

    gl_FragColor.xyz = texture2D(Sample0, vUv + offset).xyz;

    gl_FragColor.w = 1.0;

    }



    [/java]

I’m guessing that was it’s intended purpose reading through the comments. Oh… incase you didn’t see it… I forgot to add the referenced constants to what I posted. I updated the post above.

One more side note… There are a few things I opted not to incorporate into the GPU Animation deal.


  1. Adjusting const vec2 center can have some cool effects on the texture deforms.
  2. This code here:

    [java]vec2 p = -1.0 + 2.0 * tc;

    float len = length§;[/java]

    Finds the distance from the from the center of the texture (Note this is different from the gradient distance… which creates an oval shape inside of the screen bounds and gradually increases distance either towards the center or towards the edges of the screen). Anyways… adjusting this can have some neat effects as well (specifically ‘tc’ – the reference to texcoord – portion).



    EDIT: Actually… I mispoke myself. Lemme explain the gradient thing a bit better.



    When getting the invert gradient (towards the center of the screen) it does what I said.



    When passing in false to invert… it flips each of the four quadrants of the oval(circle) and then does a gradient distance out from the center… using the border of the oval as a threshold. I hope this makes sense. It’s what I used for the peripheral blurring to limit where/how much it was being blurred.

Hello, I know this was a pretty long time ago, but if you could, the texture splattering shader would be really nice to have, because 11 textures that can be slatted is awesome.