GPU Animation Factory (UPDATE: Added texture rotate, auto-rotate clockwise/counter-clockwise)

I’ve been meaning to finish this up for quite a while. It’s basic purpose is to combine vertex deformations with texture deformations and lighting. In it’s current form (which aside from any bugs someone reports, is final) it does the following…



UPDATE: You can now rotate textures either to a set angle, or spin them clockwise or counter clockwise at a set speed. This update effected the Mat Def and the Vertex Shader. Updated usage with how to make shit spin.



MINOR UPDATE: Centered rotation

MINOR UPDATE PART 2: Swapped rotation/movement order to ensure rotation is centered on object, otherwise the rotation speeds up the further 0,0 gets away from the visible area.



Texture deformations:



Ripple/Wave

Warp

Breath

Mixer



Vertex Deformations:



Ripple

Wave

Warble

Swell

Pulse



Here be a vid of it doing it’s thing (random setting… no real reason I selected these):

http://youtu.be/1NaaM-pZ8KQ



Other notes:

You can stack multiple texture deformations.
The deforms are applied to all lighting textures.
Texture movement only applies to the texture, not the deformation. i.e. ripple radiates from the center whether or not the texture is moving.
Texture deforms can be either animated or static
You can stack multiple vertex deforms again each axis.
The normals are recalculated to ensure proper lighting.

Things you may be interested in for your own work: (in the frag shader)

deformFGradientDistance(texCoord, invert)
deformFAngleFromCenter(texCoord)

These two took a bit to figure out, but can be used in some very useful ways... especially for stopping tearing/pulling of scene edges when used as a full scene filter deformation.

Speaking of which, I'll be splitting out the texture deforms as a filter soon.

Usage:
[java]
mat_1D = new Material(assetManager, "MatDefs/GPUAnimationFactory.j3md");

// Standard uniforms for lighting
mat_1D.setBoolean("SteepParallax", true);
mat_1D.setTexture("DiffuseMap", tex_BW);
mat_1D.setTexture("NormalMap", tex_BWN);

// Applying movement to the texture
mat_1D.setBoolean("Texture_Move",true);
mat_1D.setFloat("MoveF_Speed", 3f);
mat_1D.setFloat("MoveF_Rotation", 23);

// Turn on & Animate texture deformation
mat_1D.setBoolean("Texture_Deform",true);
mat_1D.setBoolean("Texture_Animate",true);

// Applying texture ripple
mat_1D.setBoolean("DeformF_Wave", true);
mat_1D.setFloat("DeformF_Wave_SizeX",12f);
mat_1D.setFloat("DeformF_Wave_SizeY",12f);
mat_1D.setFloat("DeformF_Wave_DepthX",12f);
mat_1D.setFloat("DeformF_Wave_DepthY",12f);
mat_1D.setFloat("DeformF_Wave_SpeedX",1f);
mat_1D.setFloat("DeformF_Wave_SpeedY",1f);

// Applying texture warp
mat_1D.setBoolean("DeformF_Warp", true);
mat_1D.setFloat("DeformF_Warp_SizeX",12f);
mat_1D.setFloat("DeformF_Warp_SizeY",12f);
mat_1D.setFloat("DeformF_Warp_DepthX",12f);
mat_1D.setFloat("DeformF_Warp_DepthY",12f);
mat_1D.setFloat("DeformF_Warp_SpeedX",1f);
mat_1D.setFloat("DeformF_Warp_SpeedY",1f);

// Applying texture warp
mat_1D.setBoolean("DeformF_Mixer", true);
mat_1D.setFloat("DeformF_Mixer_SizeX",12f);
mat_1D.setFloat("DeformF_Mixer_SizeY",12f);
mat_1D.setFloat("DeformF_Mixer_DepthX",12f);
mat_1D.setFloat("DeformF_Mixer_DepthY",12f);
mat_1D.setFloat("DeformF_Mixer_SpeedX",1f);
mat_1D.setFloat("DeformF_Mixer_SpeedY",1f);

// Applying texture breath
mat_1D.setBoolean("DeformF_Breath", true);

// Applying vertex deforms (X axis)
mat_1D.setBoolean("DeformX_Wave", true);
mat_1D.setBoolean("DeformX_Ripple", true);
mat_1D.setBoolean("DeformX_Warble", true);
mat_1D.setBoolean("DeformX_Pulse", true);
mat_1D.setBoolean("DeformX_Swell", true);

// Global X axis settings
mat_1D.setInt("DirX", 180);
mat_1D.setFloat("SpeedX", 10f);
mat_1D.setFloat("SizeX", 20f);
mat_1D.setFloat("DepthX", .02f);

// Mirror deforms along X axis
mat_1D.setBoolean("MirrorX", true);

// To apply these along other axis replace X with either Y or Z in the examples for X axis

// To rotate textures:
// Auto-rotation:
mat_1D.setBoolean("RotF_Rotate", true); // turn rotation on
mat_1D.setBoolean("RotF_AutoRotate", true); // turn auto-rotation on
mat_1D.setBoolean("RotF_Clockwise", false); // true is default setting
mat_1D.setFloat("RotF_Speed", 0.35f); // sets the rotation speed

// Picking a static rotation:
mat_1D.setBoolean("RotF_Rotate", true); // turn rotation on
mat_1D.setBoolean("RotF_AutoRotate", false); // turn auto-rotation off
mat_1D.setFloat("RotF_Angle", 35f); // pick an angle
[/java]

The codededed:

(Material def file)
GPUAnimationFactory.j3md
[java]MaterialDef MovingTexture {

MaterialParameters {
Texture2D Texture
Float MoveF_Rotation : 0.0
Float MoveF_Speed
Boolean Texture_Move
Boolean Texture_Deform
Boolean Texture_Animate

Boolean RotF_Rotate
Boolean RotF_AutoRotate
Boolean RotF_Clockwise : true
Float RotF_Speed
Float RotF_Angle

Boolean DeformF_Wave
Float DeformF_Wave_SizeX
Float DeformF_Wave_SizeY
Float DeformF_Wave_DepthX
Float DeformF_Wave_DepthY
Float DeformF_Wave_SpeedX
Float DeformF_Wave_SpeedY

Boolean DeformF_Breath

Boolean DeformF_Warp
Float DeformF_Warp_SizeX
Float DeformF_Warp_SizeY
Float DeformF_Warp_DepthX
Float DeformF_Warp_DepthY
Float DeformF_Warp_SpeedX
Float DeformF_Warp_SpeedY

Boolean DeformF_Mixer
Float DeformF_Mixer_SizeX
Float DeformF_Mixer_SizeY
Float DeformF_Mixer_DepthX
Float DeformF_Mixer_DepthY
Float DeformF_Mixer_SpeedX
Float DeformF_Mixer_SpeedY

Boolean DeformF_Fisheye

Float SpeedX : 5.0
Float SpeedY : 5.0
Float SpeedZ : 5.0
Float SizeX : 1.0
Float SizeY : 1.0
Float SizeZ : 1.0
Float DepthX : 0.3
Float DepthY : 0.3
Float DepthZ : 0.3
Int DirX : 1
Int DirY : 1
Int DirZ : 1
Float RotationX : 45.0
Float RotationY : 45.0
Float RotationZ : 45.0
Float Offset1X : 0.0
Float Offset2X : 0.0
Float Offset1Y : 0.0
Float Offset2Y : 0.0
Float Offset1Z : 0.0
Float Offset2Z : 0.0
Boolean MirrorX
Boolean MirrorY
Boolean MirrorZ
Boolean DeformX_Wave
Boolean DeformY_Wave
Boolean DeformZ_Wave
Boolean DeformX_Ripple
Boolean DeformY_Ripple
Boolean DeformZ_Ripple
Boolean DeformX_Swell
Boolean DeformY_Swell
Boolean DeformZ_Swell
Boolean DeformX_Pulse
Boolean DeformY_Pulse
Boolean DeformZ_Pulse
Boolean DeformX_Warble
Boolean DeformY_Warble
Boolean DeformZ_Warble
Boolean DeformX_Water
Boolean DeformY_Water
Boolean DeformZ_Water
Boolean XPlane
Boolean YPlane
Boolean ZPlane

// Fog Params
Int FogMode : 1
Color FogColor
Float FogDensity : 0.2
Float FogStartDistance : 15.0
Float FogEndDistance : 250.0
Boolean ExcludeSky

Boolean VertexLighting
Boolean LowQuality
Boolean HighQuality
Boolean UseAlpha
Boolean LATC
Boolean UseMaterialColors
Boolean VTangent
Boolean Minnaert
Boolean WardIso
Boolean UseVertexColor
Color Ambient (MaterialAmbient)
Color Diffuse (MaterialDiffuse)
Color Specular (MaterialSpecular)
Float Shininess (MaterialShininess) : 1
Texture2D DiffuseMap
Texture2D NormalMap
Texture2D SpecularMap
Texture2D ParallaxMap
Boolean PackedNormalParallax
Float ParallaxHeight : 0.05
Boolean SteepParallax
Texture2D AlphaMap
Texture2D ColorRamp
Texture2D GlowMap
Texture2D LightMap
Boolean SeparateTexCoord
Color GlowColor
Vector3 FresnelParams
TextureCubeMap EnvMap
Boolean EnvMapAsSphereMap
Int FilterMode
Boolean HardwareShadows
Texture2D ShadowMap0
Texture2D ShadowMap1
Texture2D ShadowMap2
Texture2D ShadowMap3
Float ShadowIntensity
Vector4 Splits
Matrix4 LightViewProjectionMatrix0
Matrix4 LightViewProjectionMatrix1
Matrix4 LightViewProjectionMatrix2
Matrix4 LightViewProjectionMatrix3
Float PCFEdge
Float Scale : 1.0
}

Technique {
LightMode MultiPass

VertexShader GLSL100: Shaders/GPUAnimationFactory.vert
FragmentShader GLSL100: Shaders/GPUAnimationFactory.frag

WorldParameters {
WorldViewProjectionMatrix
Time
NormalMatrix
WorldViewMatrix
ViewMatrix
CameraPosition
WorldMatrix
}

Defines {
DEFORMX_WAVE : DeformX_Wave
DEFORMY_WAVE : DeformY_Wave
DEFORMZ_WAVE : DeformZ_Wave
DEFORMX_RIPPLE : DeformX_Ripple
DEFORMY_RIPPLE : DeformY_Ripple
DEFORMZ_RIPPLE : DeformZ_Ripple
DEFORMX_SWELL : DeformX_Swell
DEFORMY_SWELL : DeformY_Swell
DEFORMZ_SWELL : DeformZ_Swell
DEFORMX_PULSE : DeformX_Pulse
DEFORMY_PULSE : DeformY_Pulse
DEFORMZ_PULSE : DeformZ_Pulse
DEFORMX_WARBLE : DeformX_Warble
DEFORMY_WARBLE : DeformY_Warble
DEFORMZ_WARBLE : DeformZ_Warble
DEFORMX_WATER : DeformX_Water
DEFORMY_WATER : DeformY_Water
DEFORMZ_WATER : DeformZ_Water
USE_MIRRORX : MirrorX
USE_MIRRORY : MirrorY
USE_MIRRORZ : MirrorZ
IS_XPLANE : XPlane
IS_YPLANE : YPlane
IS_ZPLANE : ZPlane

LATC : LATC
VERTEX_COLOR : UseVertexColor
VERTEX_LIGHTING : VertexLighting
ATTENUATION : Attenuation
MATERIAL_COLORS : UseMaterialColors
V_TANGENT : VTangent
MINNAERT : Minnaert
WARDISO : WardIso
LOW_QUALITY : LowQuality
HQ_ATTENUATION : HighQuality

DIFFUSEMAP : DiffuseMap
NORMALMAP : NormalMap
SPECULARMAP : SpecularMap
PARALLAXMAP : ParallaxMap
NORMALMAP_PARALLAX : PackedNormalParallax
STEEP_PARALLAX : SteepParallax
ALPHAMAP : AlphaMap
COLORRAMP : ColorRamp
LIGHTMAP : LightMap
SEPARATE_TEXCOORD : SeparateTexCoord

USE_REFLECTION : EnvMap
SPHERE_MAP : EnvMapAsSphereMap

HAS_COLORMAP : ColorMap
HAS_COLOR : Color
HAS_ALPHA : Alpha
IS_MOVING : Texture_Move
USE_DEFORM : Texture_Deform
USE_ANIMATION : Texture_Animate
USE_FWAVE : DeformF_Wave
USE_FFISHEYE : DeformF_Fisheye
USE_FMIXER : DeformF_Mixer
USE_FBREATH : DeformF_Breath
USE_FWARP : DeformF_Warp
}
}
}[/java]

(Shaders)
GPUAnimationFactory.vert
[java]uniform mat4 g_WorldViewProjectionMatrix;
uniform mat4 g_WorldViewMatrix;
uniform mat3 g_NormalMatrix;
attribute vec3 inPosition;
attribute vec2 inTexCoord;
attribute vec3 inNormal;
varying vec2 texCoord;
uniform float g_Time;
const float pi = 3.14159;
varying vec2 animTexCoord1;
varying vec2 animTexCoord2;

#ifdef IS_MOVING
uniform float m_MoveF_Speed;
uniform float m_MoveF_Rotation;
#endif

uniform bool m_RotF_Rotate;
uniform bool m_RotF_AutoRotate;
uniform bool m_RotF_Clockwise;
uniform float m_RotF_Speed;
uniform float m_RotF_Angle;

#define ATTENUATION

#if defined(DEFORMX_WAVE) || defined(DEFORMY_WAVE) || defined(DEFORMZ_WAVE)
#define HAS_DEFORMWAVE
#endif
#if defined(DEFORMX_RIPPLE) || defined(DEFORMY_RIPPLE) || defined(DEFORMZ_RIPPLE)
#define HAS_DEFORMRIPPLE
#endif
#if defined(DEFORMX_SWELL) || defined(DEFORMY_SWELL) || defined(DEFORMZ_SWELL)
#define HAS_DEFORMSWELL
#endif
#if defined(DEFORMX_PULSE) || defined(DEFORMY_PULSE) || defined(DEFORMZ_PULSE)
#define HAS_DEFORMPULSE
#endif
#if defined(DEFORMX_WARBLE) || defined(DEFORMY_WARBLE) || defined(DEFORMZ_WARBLE)
#define HAS_DEFORMWARBLE
#endif
#if defined(DEFORMX_WATER) || defined(DEFORMY_WATER) || defined(DEFORMZ_WATER)
#define HAS_DEFORMWATER
#endif

uniform vec4 m_FogColor;
uniform float m_FogDensity;
uniform float m_FogDistance;
varying float fog_z;

uniform float m_SpeedX;
uniform float m_SizeX;
uniform float m_DepthX;
uniform int m_DirX;
uniform bool m_MirrorX;
uniform float m_RotationX;
uniform float m_Offset1X;
uniform float m_Offset2X;

uniform float m_SpeedY;
uniform float m_SizeY;
uniform float m_DepthY;
uniform int m_DirY;
uniform bool m_MirrorY;
uniform float m_RotationY;
uniform float m_Offset1Y;
uniform float m_Offset2Y;

uniform float m_SpeedZ;
uniform float m_SizeZ;
uniform float m_DepthZ;
uniform int m_DirZ;
uniform bool m_MirrorZ;
uniform float m_RotationZ;
uniform float m_Offset1Z;
uniform float m_Offset2Z;

//varying vec3 vNormal;
varying vec4 vVertex;
varying vec3 vPosition;

uniform mat4 g_ViewMatrix;

uniform vec4 m_Ambient;
uniform vec4 m_Diffuse;
uniform vec4 m_Specular;
uniform float m_Shininess;

uniform vec4 g_LightColor;
uniform vec4 g_LightPosition;
uniform vec4 g_AmbientLightColor;

#ifdef SEPARATE_TEXCOORD
varying vec2 texCoord2;
attribute vec2 inTexCoord2;
#endif

varying vec3 AmbientSum;
varying vec4 DiffuseSum;
varying vec3 SpecularSum;

varying vec3 lightVec;
//varying vec4 spotVec;

#ifdef VERTEX_COLOR
attribute vec4 inColor;
#endif

varying vec3 vNormal;

#ifndef VERTEX_LIGHTING
attribute vec4 inTangent;

#ifndef NORMALMAP
// varying vec3 vNormal;
#endif
//varying vec3 vPosition;
varying vec3 vViewDir;
varying vec4 vLightDir;
#else
varying vec2 vertexLightValues;
uniform vec4 g_LightDirection;
#endif

#ifdef USE_REFLECTION
uniform vec3 g_CameraPosition;
uniform mat4 g_WorldMatrix;

uniform vec3 m_FresnelParams;
varying vec4 refVec;


/**
* Input:
* attribute inPosition
* attribute inNormal
* uniform g_WorldMatrix
* uniform g_CameraPosition
*
* Output:
* varying refVec
*/
void computeRef(){
vec3 worldPos = (g_WorldMatrix * vec4(inPosition,1.0)).xyz;

vec3 I = normalize( g_CameraPosition - worldPos ).xyz;
vec3 N = normalize( (g_WorldMatrix * vec4(inNormal, 0.0)).xyz );

refVec.xyz = reflect(I, N);
refVec.w = m_FresnelParams.x + m_FresnelParams.y * pow(1.0 + dot(I, N), m_FresnelParams.z);
}
#endif

// JME3 lights in world space
void lightComputeDir(in vec3 worldPos, in vec4 color, in vec4 position, out vec4 lightDir){
float posLight = step(0.5, color.w);
vec3 tempVec = position.xyz * sign(posLight - 0.5) - (worldPos * posLight);
lightVec = tempVec;
#ifdef ATTENUATION
float dist = length(tempVec);
lightDir.w = clamp(1.0 - position.w * dist * posLight, 0.0, 1.0);
lightDir.xyz = tempVec / vec3(dist);
#else
lightDir = vec4(normalize(tempVec), 1.0);
#endif
}

#ifdef VERTEX_LIGHTING
float lightComputeDiffuse(in vec3 norm, in vec3 lightdir){
return max(0.0, dot(norm, lightdir));
}

float lightComputeSpecular(in vec3 norm, in vec3 viewdir, in vec3 lightdir, in float shiny){
if (shiny <= 1.0){
return 0.0;
}
#ifndef LOW_QUALITY
vec3 H = (viewdir + lightdir) * vec3(0.5);
return pow(max(dot(H, norm), 0.0), shiny);
#else
return 0.0;
#endif
}

vec2 computeLighting(in vec3 wvPos, in vec3 wvNorm, in vec3 wvViewDir, in vec4 wvLightPos){
vec4 lightDir;
lightComputeDir(wvPos, g_LightColor, wvLightPos, lightDir);
float spotFallOff = 1.0;
if(g_LightDirection.w != 0.0){
vec3 L=normalize(lightVec.xyz);
vec3 spotdir = normalize(g_LightDirection.xyz);
float curAngleCos = dot(-L, spotdir);
float innerAngleCos = floor(g_LightDirection.w) * 0.001;
float outerAngleCos = fract(g_LightDirection.w);
float innerMinusOuter = innerAngleCos - outerAngleCos;
spotFallOff = clamp((curAngleCos - outerAngleCos) / innerMinusOuter, 0.0, 1.0);
}
float diffuseFactor = lightComputeDiffuse(wvNorm, lightDir.xyz);
float specularFactor = lightComputeSpecular(wvNorm, wvViewDir, lightDir.xyz, m_Shininess);
//specularFactor *= step(0.01, diffuseFactor);
return vec2(diffuseFactor, specularFactor) * vec2(lightDir.w)*spotFallOff;
}
#endif

#ifdef HAS_DEFORMWAVE
vec3 displaceWave(in vec3 pos) {
vec3 new_pos = vec3(pos);

#ifdef DEFORMX_WAVE
float speedX = m_SpeedX;
if (m_DirX == 0) speedX = -speedX;
float dist1X = sqrt((new_pos.y*new_pos.y)+(new_pos.y*new_pos.y));
float dist2X = sqrt((new_pos.z*new_pos.z)+(new_pos.z*new_pos.z));
if (new_pos.y > 0.0) dist1X = -dist1X;
if (new_pos.z > 0.0) dist2X = -dist2X;
float time1X = ((g_Time*speedX)*sin(m_RotationX*(pi/180.0)));
float time2X = ((g_Time*speedX)*cos(m_RotationX*(pi/180.0)));
float wave1X = ( m_DepthX*( sin( (m_SizeX*dist1X)+time1X ) ) );
float wave2X = ( m_DepthX*( sin( (m_SizeX*dist2X)+time2X ) ) );
#ifdef USE_MIRRORX
if (new_pos.x > 0.0) {
new_pos.x += wave1X;
new_pos.x += wave2X;
} else {
new_pos.x -= wave1X;
new_pos.x -= wave2X;
}
#else
new_pos.x += wave1X;
new_pos.x += wave2X;
#endif
#endif
#ifdef DEFORMY_WAVE
float speedY = m_SpeedY;
if (m_DirY == 0) speedY = -speedY;
float dist1Y = sqrt((new_pos.x*new_pos.x)+(new_pos.x*new_pos.x));
float dist2Y = sqrt((new_pos.z*new_pos.z)+(new_pos.z*new_pos.z));
if (new_pos.x > 0.0) dist1Y = -dist1Y;
if (new_pos.z > 0.0) dist2Y = -dist2Y;
float time1Y = ((g_Time*speedY)*sin(m_RotationY*(pi/180.0)));
float time2Y = ((g_Time*speedY)*cos(m_RotationY*(pi/180.0)));
float wave1Y = ( m_DepthY*( sin( (m_SizeY*dist1Y)+time1Y ) ) );
float wave2Y = ( m_DepthY*( sin( (m_SizeY*dist2Y)+time2Y ) ) );
#ifdef USE_MIRRORY
if (new_pos.y > 0.0) {
new_pos.y += wave1Y;
new_pos.y += wave2Y;
} else {
new_pos.y -= wave1Y;
new_pos.y -= wave2Y;
}
#else
new_pos.y += wave1Y;
new_pos.y += wave2Y;
#endif
#endif
#ifdef DEFORMZ_WAVE
float speedZ = m_SpeedZ;
if (m_DirZ == 0) speedZ = -speedZ;
float dist1Z = sqrt((new_pos.x*new_pos.x)+(new_pos.x*new_pos.x));
float dist2Z = sqrt((new_pos.y*new_pos.y)+(new_pos.y*new_pos.y));
if (new_pos.x > 0.0) dist1Z = -dist1Z;
if (new_pos.y > 0.0) dist2Z = -dist2Z;
float time1Z = ((g_Time*speedZ)*sin(m_RotationZ*(pi/180.0)));
float time2Z = ((g_Time*speedZ)*cos(m_RotationZ*(pi/180.0)));
float wave1Z = ( m_DepthZ*( sin( (m_SizeZ*dist1Z)+time1Z ) ) );
float wave2Z = ( m_DepthZ*( sin( (m_SizeZ*dist2Z)+time2Z ) ) );
#ifdef USE_MIRRORZ
if (new_pos.z > 0.0) {
new_pos.z += wave1Z;
new_pos.z += wave2Z;
} else {
new_pos.z -= wave1Z;
new_pos.z -= wave2Z;
}
#else
new_pos.z += wave1Z;
new_pos.z += wave2Z;
#endif
#endif
return new_pos;
}
#endif
#ifdef HAS_DEFORMWARBLE
vec3 displaceWarble(in vec3 pos) {
vec3 new_pos = vec3(pos);

#ifdef DEFORMX_WARBLE
float speedX = m_SpeedX;
if (m_DirX == 0) speedX = -speedX;
float dist1X = sqrt((new_pos.y*new_pos.y)+(new_pos.y*new_pos.y));
float dist2X = sqrt((new_pos.z*new_pos.z)+(new_pos.z*new_pos.z));
if (new_pos.y > 0.0) dist1X = -dist1X;
if (new_pos.z > 0.0) dist2X = -dist2X;
float time1X = ((g_Time*speedX)*sin(m_RotationX*(pi/180.0)));
float time2X = ((g_Time*speedX)*cos(m_RotationX*(pi/180.0)));
float wave1X = ( m_DepthX*sin(m_DepthX+time1X)*( sin( (m_SizeX*dist1X) ) ) );
float wave2X = ( m_DepthX*sin(m_DepthX+time2X)*( sin( (m_SizeX*dist2X) ) ) );
#ifdef USE_MIRRORX
if (new_pos.x > 0.0) {
new_pos.x += wave1X;
new_pos.x += wave2X;
} else {
new_pos.x -= wave1X;
new_pos.x -= wave2X;
}
#else
new_pos.x += wave1X;
new_pos.x += wave2X;
#endif
#endif
#ifdef DEFORMY_WARBLE
float speedY = m_SpeedY;
if (m_DirY == 0) speedY = -speedY;
float dist1Y = sqrt((new_pos.x*new_pos.x)+(new_pos.x*new_pos.x));
float dist2Y = sqrt((new_pos.z*new_pos.z)+(new_pos.z*new_pos.z));
if (new_pos.x > 0.0) dist1Y = -dist1Y;
if (new_pos.z > 0.0) dist2Y = -dist2Y;
float time1Y = ((g_Time*speedY)*sin(m_RotationY*(pi/180.0)));
float time2Y = ((g_Time*speedY)*cos(m_RotationY*(pi/180.0)));
float wave1Y = ( m_DepthY*sin(m_DepthY+time1Y)*( sin( (m_SizeY*dist1Y) ) ) );
float wave2Y = ( m_DepthY*sin(m_DepthY+time2Y)*( sin( (m_SizeY*dist2Y) ) ) );
#ifdef USE_MIRRORY
if (new_pos.y > 0.0) {
new_pos.y += wave1Y;
new_pos.y += wave2Y;
} else {
new_pos.y -= wave1Y;
new_pos.y -= wave2Y;
}
#else
new_pos.y += wave1Y;
new_pos.y += wave2Y;
#endif
#endif
#ifdef DEFORMZ_WARBLE
float speedZ = m_SpeedZ;
if (m_DirZ == 0) speedZ = -speedZ;
float dist1Z = sqrt((new_pos.x*new_pos.x)+(new_pos.x*new_pos.x));
float dist2Z = sqrt((new_pos.y*new_pos.y)+(new_pos.y*new_pos.y));
if (new_pos.x > 0.0) dist1Z = -dist1Z;
if (new_pos.y > 0.0) dist2Z = -dist2Z;
float time1Z = ((g_Time*speedZ)*sin(m_RotationZ*(pi/180.0)));
float time2Z = ((g_Time*speedZ)*cos(m_RotationZ*(pi/180.0)));
float wave1Z = ( m_DepthZ*sin(m_DepthZ+time1Z)*( sin( (m_SizeZ*dist1Z) ) ) );
float wave2Z = ( m_DepthZ*sin(m_DepthZ+time2Z)*( sin( (m_SizeZ*dist2Z) ) ) );
#ifdef USE_MIRRORZ
if (new_pos.z > 0.0) {
new_pos.z += wave1Z;
new_pos.z += wave2Z;
} else {
new_pos.z -= wave1Z;
new_pos.z -= wave2Z;
}
#else
new_pos.z += wave1Z;
new_pos.z += wave2Z;
#endif
#endif
return new_pos;
}
#endif
#ifdef HAS_DEFORMRIPPLE
vec3 displaceRipple(in vec3 pos) {
vec3 new_pos = vec3(pos);

#ifdef DEFORMX_RIPPLE
float speedX = m_SpeedX;
if (m_DirX == 0) speedX = -speedX;
float offset1X = m_Offset1X+new_pos.y;
float offset2X = m_Offset2X+new_pos.z;
float distX = sqrt((offset1X*offset1X)+(offset2X*offset2X));
// float distX = sqrt((new_pos.y*new_pos.y)+(new_pos.z*new_pos.z));
#ifdef USE_MIRRORX
if (new_pos.x > 0.0) {
new_pos.x += (m_DepthX*sin((m_SizeX*distX)+(g_Time*speedX)));
} else {
new_pos.x -= (m_DepthX*sin((m_SizeX*distX)+(g_Time*speedX)));
}
#else
new_pos.x += (m_DepthX*sin((m_SizeX*distX)+(g_Time*speedX)));
#endif
#endif
#ifdef DEFORMY_RIPPLE
float speedY = m_SpeedY;
if (m_DirY == 0) speedY = -speedY;
float offset1Y = m_Offset1Y+new_pos.x;
float offset2Y = m_Offset2Y+new_pos.z;
float distY = sqrt((offset1Y*offset1Y)+(offset2Y*offset2Y));
#ifdef USE_MIRRORY
if (new_pos.y < 0.0) {
new_pos.y += (m_DepthY*sin((m_SizeY*distY)+(g_Time*speedY)));
} else {
new_pos.y -= (m_DepthY*sin((m_SizeY*distY)+(g_Time*speedY)));
}
#else
new_pos.y += (m_DepthY*sin((m_SizeY*distY)+(g_Time*speedY)));
#endif
#endif
#ifdef DEFORMZ_RIPPLE
float speedZ = m_SpeedZ;
if (m_DirZ == 0) speedZ = -speedZ;
float offset1Z = m_Offset1Z+new_pos.x;
float offset2Z = m_Offset2Z+new_pos.y;
float distZ = sqrt((offset1Z*offset1Z)+(offset2Z*offset2Z));
// float distZ = sqrt((new_pos.x*new_pos.x)+(new_pos.y*new_pos.y));
#ifdef USE_MIRRORZ
if (new_pos.z < 0.0) {
new_pos.z += (m_DepthZ*sin((m_SizeZ*distZ)+(g_Time*speedZ)));
} else {
new_pos.z -= (m_DepthZ*sin((m_SizeZ*distZ)+(g_Time*speedZ)));
}
#else
new_pos.z += (m_DepthZ*sin((m_SizeZ*distZ)+(g_Time*speedZ)));
#endif
#endif
return new_pos;
}
#endif
#ifdef HAS_DEFORMSWELL
vec3 displaceSwell(in vec3 pos) {
vec3 new_pos = vec3(pos);

#ifdef DEFORMX_SWELL
float speedX = m_SpeedX;
if (m_DirX == 0) speedX = -speedX;
float swellX = abs(cos(g_Time*speedX));
if (m_DirX == 1) swellX = -swellX;
float distX = sqrt((new_pos.y*new_pos.y)+(new_pos.z*new_pos.z));
if (new_pos.x < 0.0) {
new_pos.x += m_DepthX*abs(new_pos.x)*swellX;
} else {
new_pos.x -= m_DepthX*abs(new_pos.x)*swellX;
}
#endif
#ifdef DEFORMY_SWELL
float speedY = m_SpeedY;
if (m_DirY == 0) speedY = -speedY;
float swellY = abs(cos(g_Time*speedY));
if (m_DirY == 1) swellY = -swellY;
float distY = sqrt((new_pos.x*new_pos.x)+(new_pos.z*new_pos.z));
if (new_pos.y < 0.0) {
new_pos.y += m_DepthY*abs(new_pos.y)*swellY;
} else {
new_pos.y -= m_DepthY*abs(new_pos.y)*swellY;
}
#endif
#ifdef DEFORMZ_SWELL
float speedZ = m_SpeedZ;
if (m_DirZ == 0) speedZ = -speedZ;
float swellZ = abs(cos(g_Time*speedZ));
if (m_DirZ == 1) swellZ = -swellZ;
float distZ = sqrt((new_pos.x*new_pos.x)+(new_pos.y*new_pos.y));
if (new_pos.z < 0.0) {
new_pos.z += m_DepthZ*abs(new_pos.z)*swellZ;
} else {
new_pos.z -= m_DepthZ*abs(new_pos.z)*swellZ;
}
#endif
return new_pos;
}
#endif
#ifdef HAS_DEFORMPULSE
vec3 displacePulse(in vec3 pos) {
vec3 new_pos = vec3(pos);

#ifdef DEFORMX_PULSE
float speedX = m_SpeedX;
if (m_DirX == 0) speedX = -speedX;
float pulseX = cos(g_Time*speedX);
if (m_DirX == 1) pulseX = -pulseX;
float distX = sqrt((new_pos.y*new_pos.y)+(new_pos.z*new_pos.z));
if (new_pos.x < 0.0) {
new_pos.x += m_DepthX*abs(new_pos.x)*pulseX;
} else {
new_pos.x -= m_DepthX*abs(new_pos.x)*pulseX;
}
#endif
#ifdef DEFORMY_PULSE
float speedY = m_SpeedY;
if (m_DirY == 0) speedY = -speedY;
float pulseY = cos(g_Time*speedY);
if (m_DirY == 1) pulseY = -pulseY;
float distY = sqrt((new_pos.x*new_pos.x)+(new_pos.z*new_pos.z));
if (new_pos.y < 0.0) {
new_pos.y += m_DepthY*abs(new_pos.y)*pulseY;
} else {
new_pos.y -= m_DepthY*abs(new_pos.y)*pulseY;
}
#endif
#ifdef DEFORMZ_PULSE
float speedZ = m_SpeedZ;
if (m_DirZ == 0) speedZ = -speedZ;
float pulseZ = cos(g_Time*speedZ);
if (m_DirZ == 1) pulseZ = -pulseZ;
float distZ = sqrt((new_pos.x*new_pos.x)+(new_pos.y*new_pos.y));
if (new_pos.z < 0.0) {
new_pos.z += m_DepthZ*abs(new_pos.z)*pulseZ;
} else {
new_pos.z -= m_DepthZ*abs(new_pos.z)*pulseZ;
}
#endif
return new_pos;
}
#endif
#if defined(HAS_DEFORMWAVE) || defined(HAS_DEFORMRIPPLE) || defined(HAS_DEFORMPULSE) || defined(HAS_DEFORMSWELL) || defined(HAS_DEFORMWARBLE)
vec3 displaceNormals(in vec3 pos, in vec3 norm) {
float speedX, distX, dist1X, dist2X, timeX, time1X, time2X, jac_coefX, jac_coef1X, jac_coef2X, swellX, pulseX, offset1X, offset2X;
float speedY, distY, dist1Y, dist2Y, timeY, time1Y, time2Y, jac_coefY, jac_coef1Y, jac_coef2Y, swellY, pulseY, offset1Y, offset2Y;
float speedZ, distZ, dist1Z, dist2Z, timeZ, time1Z, time2Z, jac_coefZ, jac_coef1Z, jac_coef2Z, swellZ, pulseZ, offset1Z, offset2Z;

vec3 new_pos = vec3(pos);
mat3 J = mat3(1.0,0.0,0.0,0.0,1.0,0.0,0.0,0.0,1.0);
vec3 c1 = vec3(0.0, 0.0, 1.0);
vec3 c2 = vec3(0.0, 1.0, 0.0);

vec3 tangent;
vec3 binormal;

#if defined(DEFORMX_WAVE)
speedX = m_SpeedX;
if (m_DirX == 0) speedX = -speedX;
dist1X = sqrt((new_pos.y*new_pos.y)+(new_pos.y*new_pos.y));
dist2X = sqrt((new_pos.z*new_pos.z)+(new_pos.z*new_pos.z));
if (new_pos.y > 0.0) dist1X = -dist1X;
if (new_pos.z > 0.0) dist2X = -dist2X;
time1X = ((g_Time*speedX)*sin(m_RotationX*(pi/180.0)));
time2X = ((g_Time*speedX)*cos(m_RotationX*(pi/180.0)));
jac_coef1X = (m_DepthX*cos((m_SizeX*dist1X)+time1X)/(dist1X+0.00001));
jac_coef2X = (m_DepthX*cos((m_SizeX*dist2X)+time2X)/(dist2X+0.00001));
#if defined(USE_MIRRORX)
if (new_pos.x < 0.0) {
jac_coef1X = -jac_coef1X;
jac_coef2X = -jac_coef2X;
}
#endif
J[1][0] += (jac_coef1X*new_pos.y);
J[2][0] += (jac_coef2X*new_pos.z);
#endif
#if defined(DEFORMX_WARBLE)
speedX = m_SpeedX;
if (m_DirX == 0) speedX = -speedX;
dist1X = sqrt((new_pos.y*new_pos.y)+(new_pos.y*new_pos.y));
dist2X = sqrt((new_pos.z*new_pos.z)+(new_pos.z*new_pos.z));
if (new_pos.y > 0.0) dist1X = -dist1X;
if (new_pos.z > 0.0) dist2X = -dist2X;
time1X = -((g_Time*speedX)*sin(m_RotationX*(pi/180.0)));
time2X = -((g_Time*speedX)*cos(m_RotationX*(pi/180.0)));
jac_coef1X = ( m_DepthX*cos(m_DepthX+time1X)*( cos( (m_SizeX*dist1X) ) ) )/(dist1X+0.00001);
jac_coef2X = ( m_DepthX*cos(m_DepthX+time2X)*( cos( (m_SizeX*dist2X) ) ) )/(dist2X+0.00001);
#ifdef USE_MIRRORX
if (new_pos.x < 0.0) {
jac_coef1X = -jac_coef1X;
jac_coef2X = -jac_coef2X;
}
#endif
J[1][0] += (jac_coef1X*new_pos.y)/2.0;
J[2][0] += (jac_coef2X*new_pos.z)/2.0;
#endif
#if defined(DEFORMX_RIPPLE)
speedX = m_SpeedX;
if (m_DirX == 0) speedX = -speedX;
offset1X = m_Offset1X+new_pos.y;
offset2X = m_Offset2X+new_pos.z;
distX = sqrt((offset1X*offset1X)+(offset2X*offset2X));
jac_coefX = m_DepthX*cos((m_SizeX*distX)+(g_Time*speedX))/(distX+0.00001);
#ifdef USE_MIRRORX
if (new_pos.x > 0.0) jac_coefX = -jac_coefX;
#endif
J[1][0] += jac_coefX * (m_Offset1X+new_pos.y);
J[2][0] += jac_coefX * (m_Offset2X+new_pos.z);
#endif
#if defined(DEFORMX_SWELL)
speedX = m_SpeedX;
if (m_DirX == 0) speedX = -speedX;
swellX = -abs(sin(g_Time*speedX));
if (m_DirX == 1) swellX = -swellX;
distX = sqrt((new_pos.y*new_pos.y)+(new_pos.z*new_pos.z));
jac_coefX = m_DepthX*abs(new_pos.x)*swellX;
if (new_pos.x > 0.0) {
jac_coefX = -jac_coefX;
}
J[1][0] += jac_coefX * new_pos.y;
J[2][0] += jac_coefX * new_pos.z;
#endif
#if defined(DEFORMX_PULSE)
speedX = m_SpeedX;
if (m_DirX == 0) speedX = -speedX;
pulseX = -cos(g_Time*speedX);
if (m_DirX == 1) pulseX = -pulseX;
distX = sqrt((new_pos.y*new_pos.y)+(new_pos.z*new_pos.z));
jac_coefX = (m_DepthX*abs(new_pos.x)*pulseX)/(distX+0.00001);
if (new_pos.x > 0.0) {
jac_coefX = -jac_coefX;
}
J[1][0] += jac_coefX * new_pos.y;
J[2][0] += jac_coefX * new_pos.z;
#endif

#if defined(DEFORMY_WAVE)
speedY = m_SpeedY;
if (m_DirY == 0) speedY = -speedY;
dist1Y = sqrt((new_pos.x*new_pos.x)+(new_pos.x*new_pos.x));
dist2Y = sqrt((new_pos.z*new_pos.z)+(new_pos.z*new_pos.z));
if (new_pos.x > 0.0) dist1Y = -dist1Y;
if (new_pos.z > 0.0) dist2Y = -dist2Y;
time1Y = ((g_Time*speedY)*sin(m_RotationY*(pi/180.0)));
time2Y = ((g_Time*speedY)*cos(m_RotationY*(pi/180.0)));
jac_coef1Y = (m_DepthY*cos((m_SizeY*dist1Y)+time1Y)/(dist1Y+0.00001));
jac_coef2Y = (m_DepthY*cos((m_SizeY*dist2Y)+time2Y)/(dist2Y+0.00001));
#if defined(USE_MIRRORY)
if (new_pos.y < 0.0) {
jac_coef1Y = -jac_coef1Y;
jac_coef2Y = -jac_coef2Y;
}
#endif
J[0][1] += (jac_coef1Y*new_pos.x);
J[2][1] += (jac_coef2Y*new_pos.z);
#endif
#if defined(DEFORMY_WARBLE)
speedY = m_SpeedY;
if (m_DirY == 0) speedY = -speedY;
dist1Y = sqrt((new_pos.x*new_pos.x)+(new_pos.x*new_pos.x));
dist2Y = sqrt((new_pos.z*new_pos.z)+(new_pos.z*new_pos.z));
if (new_pos.x > 0.0) dist1Y = -dist1Y;
if (new_pos.z > 0.0) dist2Y = -dist2Y;
time1Y = -((g_Time*speedY)*sin(m_RotationY*(pi/180.0)));
time2Y = -((g_Time*speedY)*cos(m_RotationY*(pi/180.0)));
jac_coef1Y = ( m_DepthY*cos(m_DepthY+time1Y)*( cos( (m_SizeY*dist1Y) ) ) )/(dist1Y+0.00001);
jac_coef2Y = ( m_DepthY*cos(m_DepthY+time2Y)*( cos( (m_SizeY*dist2Y) ) ) )/(dist2Y+0.00001);
#ifdef USE_MIRRORY
if (new_pos.y < 0.0) {
jac_coef1Y = -jac_coef1Y;
jac_coef2Y = -jac_coef2Y;
}
#endif
J[0][1] += (jac_coef1Y*new_pos.x)/2.0;
J[2][1] += (jac_coef2Y*new_pos.z)/2.0;
#endif
#if defined(DEFORMY_RIPPLE)
speedY = m_SpeedY;
if (m_DirY == 0) speedY = -speedY;
offset1Y = m_Offset1Y+new_pos.x;
offset2Y = m_Offset2Y+new_pos.z;
distY = sqrt((offset1Y*offset1Y)+(offset2Y*offset2Y));
// distY = sqrt((new_pos.x*new_pos.x)+(new_pos.z*new_pos.z));
jac_coefY = m_DepthY*cos((m_SizeY*distY)+(g_Time*speedY))/(distY+0.00001);
#ifdef USE_MIRRORY
if (new_pos.y > 0.0) jac_coefY = -jac_coefY;
#endif
J[0][1] += jac_coefY * (m_Offset1Y+new_pos.x);
J[2][1] += jac_coefY * (m_Offset2Y+new_pos.z);
#endif
#if defined(DEFORMY_SWELL)
speedY = m_SpeedY;
if (m_DirY == 0) speedY = -speedY;
swellY = -abs(cos(g_Time*speedY));
if (m_DirY == 1) swellY = -swellY;
distY = sqrt((new_pos.x*new_pos.x)+(new_pos.z*new_pos.z));
jac_coefY = m_DepthY*abs(new_pos.y)*swellY;
if (new_pos.y > 0.0) {
jac_coefY = -jac_coefY;
}
J[0][1] += jac_coefY * new_pos.x;
J[2][1] += jac_coefY * new_pos.z;
#endif
#if defined(DEFORMY_PULSE)
speedY = m_SpeedY;
if (m_DirY == 0) speedY = -speedY;
pulseY = -cos(g_Time*speedY);
if (m_DirY == 1) pulseY = -pulseY;
distY = sqrt((new_pos.x*new_pos.x)+(new_pos.z*new_pos.z));
jac_coefY = (m_DepthY*abs(new_pos.y)*pulseY)/(distY+0.00001);
if (new_pos.y > 0.0) {
jac_coefY = -jac_coefY;
}
J[0][1] += jac_coefY * new_pos.x;
J[2][1] += jac_coefY * new_pos.z;
#endif

#if defined(DEFORMZ_WAVE)
speedZ = m_SpeedZ;
if (m_DirZ == 0) speedZ = -speedZ;
dist1Z = sqrt((new_pos.x*new_pos.x)+(new_pos.x*new_pos.x));
dist2Z = sqrt((new_pos.y*new_pos.y)+(new_pos.y*new_pos.y));
if (new_pos.x > 0.0) dist1Z = -dist1Z;
if (new_pos.y > 0.0) dist2Z = -dist2Z;
time1Z = ((g_Time*speedZ)*sin(m_RotationZ*(pi/180.0)));
time2Z = ((g_Time*speedZ)*cos(m_RotationZ*(pi/180.0)));
jac_coef1Z = (m_DepthZ*cos((m_SizeZ*dist1Z)+time1Z)/(dist1Z+0.00001));
jac_coef2Z = (m_DepthZ*cos((m_SizeZ*dist2Z)+time2Z)/(dist2Z+0.00001));
#if defined(USE_MIRRORZ)
if (new_pos.z < 0.0) {
jac_coef1Z = -jac_coef1Z;
jac_coef2Z = -jac_coef2Z;
}
#endif
J[0][2] += (jac_coef1Z*new_pos.x);
J[1][2] += (jac_coef2Z*new_pos.y);
#endif
#if defined(DEFORMZ_WARBLE)
speedZ = m_SpeedZ;
if (m_DirZ == 0) speedZ = -speedZ;
dist1Z = sqrt((new_pos.x*new_pos.x)+(new_pos.x*new_pos.x));
dist2Z = sqrt((new_pos.y*new_pos.y)+(new_pos.y*new_pos.y));
if (new_pos.x > 0.0) dist1Z = -dist1Z;
if (new_pos.y > 0.0) dist2Z = -dist2Z;
time1Z = -((g_Time*speedZ)*sin(m_RotationZ*(pi/180.0)));
time2Z = -((g_Time*speedZ)*cos(m_RotationZ*(pi/180.0)));
jac_coef1Z = ( m_DepthZ*cos(m_DepthZ+time1Z)*( cos( (m_SizeZ*dist1Z) ) ) )/(dist1Z+0.00001);
jac_coef2Z = ( m_DepthZ*cos(m_DepthZ+time2Z)*( cos( (m_SizeZ*dist2Z) ) ) )/(dist2Z+0.00001);
#ifdef USE_MIRRORZ
if (new_pos.z < 0.0) {
jac_coef1Z = -jac_coef1Z;
jac_coef2Z = -jac_coef2Z;
}
#endif
J[0][2] += (jac_coef1Z*new_pos.x)/2.0;
J[1][2] += (jac_coef2Z*new_pos.y)/2.0;
#endif
#if defined(DEFORMZ_RIPPLE)
speedZ = m_SpeedZ;
if (m_DirZ == 0) speedZ = -speedZ;
offset1Z = m_Offset1Z+new_pos.x;
offset2Z = m_Offset2Z+new_pos.y;
distZ = sqrt((offset1Z*offset1Z)+(offset2Z*offset2Z));
// distZ = sqrt((new_pos.x*new_pos.x)+(new_pos.y*new_pos.y));
jac_coefZ = m_DepthZ*sin((m_SizeZ*distZ)+(g_Time*speedZ))/(distZ+0.00001);
#ifdef USE_MIRRORZ
if (new_pos.z > 0.0) jac_coefZ = -jac_coefZ;
#endif
J[0][2] += jac_coefZ * (m_Offset1Z+new_pos.x);
J[1][2] += jac_coefZ * (m_Offset2Z+new_pos.y);
#endif
#if defined(DEFORMZ_SWELL)
speedZ = m_SpeedZ;
if (m_DirZ == 0) speedZ = -speedZ;
swellZ = -abs(sin(g_Time*speedZ));
if (m_DirZ == 1) swellZ = -swellZ;
distZ = sqrt((new_pos.x*new_pos.x)+(new_pos.y*new_pos.y));
jac_coefZ = m_DepthZ*abs(new_pos.z)*swellYZ;
if (new_pos.z > 0.0) {
jac_coefZ = -jac_coefZ;
}
J[0][2] += jac_coefZ * new_pos.x;
J[1][2] += jac_coefZ * new_pos.y;
#endif
#if defined(DEFORMZ_PULSE)
speedZ = m_SpeedZ;
if (m_DirZ == 0) speedZ = -speedZ;
pulseZ = -cos(g_Time*speedZ);
if (m_DirZ == 1) pulseZ = -pulseZ;
distZ = sqrt((new_pos.x*new_pos.x)+(new_pos.y*new_pos.y));
jac_coefZ = (m_DepthZ*abs(new_pos.z)*pulseZ)/(distZ+0.00001);
if (new_pos.z > 0.0) {
jac_coefZ = -jac_coefZ;
}
J[0][2] += jac_coefZ * new_pos.x;
J[1][2] += jac_coefZ * new_pos.y;
#endif

c1 = cross(norm, c1);
c2 = cross(norm, c2);

if(length(c1)>length(c2)) tangent = c1;
else tangent = c2;
tangent = normalize(tangent);

binormal = cross(norm, tangent);
binormal = normalize(binormal);

vec3 u1 = J*tangent;
vec3 v1 = J*binormal;

vec3 n1 = cross(v1, u1);
return normalize(-n1);
}
#endif

void main(){
vec3 displacedVertex = vec3(inPosition);
vec3 displacedNormal = vec3(inNormal);

#ifdef HAS_DEFORMWAVE
displacedVertex = displaceWave(displacedVertex);
#endif
#ifdef HAS_DEFORMWARBLE
displacedVertex = displaceWarble(displacedVertex);
#endif
#ifdef HAS_DEFORMRIPPLE
displacedVertex = displaceRipple(displacedVertex);
#endif
#ifdef HAS_DEFORMSWELL
displacedVertex = displaceSwell(displacedVertex);
#endif
#ifdef HAS_DEFORMPULSE
displacedVertex = displacePulse(displacedVertex);
#endif

#if defined(HAS_DEFORMWAVE) || defined(HAS_DEFORMRIPPLE) || defined(HAS_DEFORMPULSE) || defined(HAS_DEFORMSWELL) || defined(HAS_DEFORMWARBLE)
displacedNormal = displaceNormals(displacedVertex,displacedNormal);
#endif

gl_Position = g_WorldViewProjectionMatrix * vec4(displacedVertex,1.0);

vPosition = gl_Position.xyz;
vVertex = g_WorldViewMatrix * vec4(displacedVertex,1.0);
texCoord = inTexCoord;

vNormal = normalize(g_NormalMatrix*displacedNormal);
#ifdef SEPARATE_TEXCOORD
texCoord2 = inTexCoord2;
#endif

vec3 wvPosition = (g_WorldViewMatrix * vVertex).xyz;
vec3 wvNormal = vNormal; //normalize(g_NormalMatrix * inNormal);
vec3 viewDir = normalize(-wvPosition);

//vec4 lightColor = g_LightColor[gl_InstanceID];
//vec4 lightPos = g_LightPosition[gl_InstanceID];
//vec4 wvLightPos = (g_ViewMatrix * vec4(lightPos.xyz, lightColor.w));
//wvLightPos.w = lightPos.w;

vec4 wvLightPos = (g_ViewMatrix * vec4(g_LightPosition.xyz,clamp(g_LightColor.w,0.0,1.0)));
wvLightPos.w = g_LightPosition.w;
vec4 lightColor = g_LightColor;

#if defined(NORMALMAP) && !defined(VERTEX_LIGHTING)
vec3 wvTangent = normalize(g_NormalMatrix * inTangent.xyz);
vec3 wvBinormal = cross(wvNormal, wvTangent);

mat3 tbnMat = mat3(wvTangent, wvBinormal * -inTangent.w,wvNormal);

//vPosition = wvPosition * tbnMat;
//vViewDir = viewDir * tbnMat;
vViewDir = -wvPosition * tbnMat;
lightComputeDir(wvPosition, lightColor, wvLightPos, vLightDir);
vLightDir.xyz = (vLightDir.xyz * tbnMat).xyz;
#elif !defined(VERTEX_LIGHTING)
vNormal = wvNormal;

//vPosition = wvPosition;
vViewDir = viewDir;

lightComputeDir(wvPosition, lightColor, wvLightPos, vLightDir);

#ifdef V_TANGENT
vNormal = normalize(g_NormalMatrix * inTangent.xyz);
vNormal = -cross(cross(vLightDir.xyz, vNormal), vNormal);
#endif
#endif

//computing spot direction in view space and unpacking spotlight cos
// spotVec = (g_ViewMatrix * vec4(g_LightDirection.xyz, 0.0) );
// spotVec.w = floor(g_LightDirection.w) * 0.001;
// lightVec.w = fract(g_LightDirection.w);

lightColor.w = 1.0;
#ifdef MATERIAL_COLORS
AmbientSum = (m_Ambient * g_AmbientLightColor).rgb;
DiffuseSum = m_Diffuse * lightColor;
SpecularSum = (m_Specular * lightColor).rgb;
#else
AmbientSum = vec3(0.2, 0.2, 0.2) * g_AmbientLightColor.rgb; // Default: ambient color is dark gray
DiffuseSum = lightColor;
SpecularSum = vec3(0.0);
#endif

#ifdef VERTEX_COLOR
AmbientSum *= inColor.rgb;
DiffuseSum *= inColor;
#endif

#ifdef VERTEX_LIGHTING
vertexLightValues = computeLighting(wvPosition, wvNormal, viewDir, wvLightPos);
#endif

#ifdef USE_REFLECTION
computeRef();
#endif

animTexCoord1 = inTexCoord;
animTexCoord2 = inTexCoord;
if (m_RotF_Rotate) {
mat2 rotationMatrix;
vec2 p = -1.0 + 2.0 * animTexCoord2;
if (m_RotF_AutoRotate) {
if (m_RotF_Clockwise) {
rotationMatrix = mat2(
sin( g_Time * m_RotF_Speed ), -cos( g_Time * m_RotF_Speed ),
cos( g_Time * m_RotF_Speed ), sin( g_Time * m_RotF_Speed )
);
} else {
rotationMatrix = mat2(
cos( g_Time * m_RotF_Speed ), -sin( g_Time * m_RotF_Speed ),
sin( g_Time * m_RotF_Speed ), cos( g_Time * m_RotF_Speed )
);
}
} else {
rotationMatrix = mat2(
cos( m_RotF_Angle ), -sin( m_RotF_Angle ),
sin( m_RotF_Angle ), cos( m_RotF_Angle )
);
}
animTexCoord1 = p/2.0*rotationMatrix-0.5;
animTexCoord2 = p/2.0*rotationMatrix-0.5;
}
#ifdef IS_MOVING
float i;
float time = (g_Time*(m_MoveF_Speed*0.1));
animTexCoord1.x += (time*sin((m_MoveF_Rotation*(pi/180))));
animTexCoord1.y += (time*cos((m_MoveF_Rotation*(pi/180))));
#endif

// fog_z = gl_Position.z;
}[/java]

GPUAnimationFactory.frag
[java]#import "Common/ShaderLib/Parallax.glsllib"
#import "Common/ShaderLib/Optics.glsllib"

#define ATTENUATION
//#define HQ_ATTENUATION
varying float fog_z;
uniform int m_FogMode;
uniform bool m_ExcludeSky;
uniform vec4 m_FogColor;
uniform float m_FogStartDistance;
uniform float m_FogEndDistance;
uniform float m_FogDensity;

varying vec2 texCoord;
#ifdef SEPARATE_TEXCOORD
varying vec2 texCoord2;
#endif

varying vec3 AmbientSum;
varying vec4 DiffuseSum;
varying vec3 SpecularSum;

uniform float m_Scale;

uniform sampler2D m_Texture;
uniform float g_Time;

const float pi = 3.14159;
const vec2 center = vec2(0.5);
const float threshold = 0.0;

varying vec2 animTexCoord1;
varying vec2 animTexCoord2;

#ifndef VERTEX_LIGHTING
uniform vec4 g_LightDirection;
//varying vec3 vPosition;
varying vec3 vViewDir;
varying vec4 vLightDir;
varying vec3 lightVec;
#else
varying vec2 vertexLightValues;
#endif

#ifdef DIFFUSEMAP
uniform sampler2D m_DiffuseMap;
#endif

#ifdef SPECULARMAP
uniform sampler2D m_SpecularMap;
#endif

#ifdef PARALLAXMAP
uniform sampler2D m_ParallaxMap;
#endif
#if (defined(PARALLAXMAP) || (defined(NORMALMAP_PARALLAX) && defined(NORMALMAP))) && !defined(VERTEX_LIGHTING)
uniform float m_ParallaxHeight;
#endif

#ifdef LIGHTMAP
uniform sampler2D m_LightMap;
#endif

#ifdef NORMALMAP
uniform sampler2D m_NormalMap;
#else
varying vec3 vNormal;
#endif

#ifdef ALPHAMAP
uniform sampler2D m_AlphaMap;
#endif

#ifdef COLORRAMP
uniform sampler2D m_ColorRamp;
#endif

uniform float m_AlphaDiscardThreshold;

#ifndef VERTEX_LIGHTING
uniform float m_Shininess;

#ifdef HQ_ATTENUATION
uniform vec4 g_LightPosition;
#endif

#ifdef USE_REFLECTION
uniform float m_ReflectionPower;
uniform float m_ReflectionIntensity;
varying vec4 refVec;

uniform ENVMAP m_EnvMap;
#endif

#ifdef IS_MOVING
// uniform float m_MoveF_Speed;
#endif

float tangDot(in vec3 v1, in vec3 v2){
float d = dot(v1,v2);
#ifdef V_TANGENT
d = 1.0 - d*d;
return step(0.0, d) * sqrt(d);
#else
return d;
#endif
}

float lightComputeDiffuse(in vec3 norm, in vec3 lightdir, in vec3 viewdir){
#ifdef MINNAERT
float NdotL = max(0.0, dot(norm, lightdir));
float NdotV = max(0.0, dot(norm, viewdir));
return NdotL * pow(max(NdotL * NdotV, 0.1), -1.0) * 0.5;
#else
return max(0.0, dot(norm, lightdir));
#endif
}

float lightComputeSpecular(in vec3 norm, in vec3 viewdir, in vec3 lightdir, in float shiny){
// NOTE: check for shiny <= 1 removed since shininess is now
// 1.0 by default (uses matdefs default vals)
#ifdef LOW_QUALITY
// Blinn-Phong
// Note: preferably, H should be computed in the vertex shader
vec3 H = (viewdir + lightdir) * vec3(0.5);
return pow(max(tangDot(H, norm), 0.0), shiny);
#elif defined(WARDISO)
// Isotropic Ward
vec3 halfVec = normalize(viewdir + lightdir);
float NdotH = max(0.001, tangDot(norm, halfVec));
float NdotV = max(0.001, tangDot(norm, viewdir));
float NdotL = max(0.001, tangDot(norm, lightdir));
float a = tan(acos(NdotH));
float p = max(shiny/128.0, 0.001);
return NdotL * (1.0 / (4.0*3.14159265*p*p)) * (exp(-(a*a)/(p*p)) / (sqrt(NdotV * NdotL)));
#else
// Standard Phong
vec3 R = reflect(-lightdir, norm);
return pow(max(tangDot(R, viewdir), 0.0), shiny);
#endif
}

vec2 computeLighting(in vec3 wvNorm, in vec3 wvViewDir, in vec3 wvLightDir){
float diffuseFactor = lightComputeDiffuse(wvNorm, wvLightDir, wvViewDir);
float specularFactor = lightComputeSpecular(wvNorm, wvViewDir, wvLightDir, m_Shininess);

#ifdef HQ_ATTENUATION
float att = clamp(1.0 - g_LightPosition.w * length(lightVec), 0.0, 1.0);
#else
float att = vLightDir.w;
#endif

if (m_Shininess <= 1.0) {
specularFactor = 0.0; // should be one instruction on most cards ..
}

specularFactor *= diffuseFactor;

return vec2(diffuseFactor, specularFactor) * vec2(att);
}
#endif

#ifdef USE_DEFORM
#ifdef USE_FWAVE
uniform float m_DeformF_Wave_SizeX;
uniform float m_DeformF_Wave_SizeY;
uniform float m_DeformF_Wave_DepthX;
uniform float m_DeformF_Wave_DepthY;
uniform float m_DeformF_Wave_SpeedX;
uniform float m_DeformF_Wave_SpeedY;
#endif
#ifdef USE_FWARP
uniform float m_DeformF_Warp_SizeX;
uniform float m_DeformF_Warp_SizeY;
uniform float m_DeformF_Warp_DepthX;
uniform float m_DeformF_Warp_DepthY;
uniform float m_DeformF_Warp_SpeedX;
uniform float m_DeformF_Warp_SpeedY;
#endif
#ifdef USE_FMIXER
uniform float m_DeformF_Mixer_SizeX;
uniform float m_DeformF_Mixer_SizeY;
uniform float m_DeformF_Mixer_DepthX;
uniform float m_DeformF_Mixer_DepthY;
uniform float m_DeformF_Mixer_SpeedX;
uniform float m_DeformF_Mixer_SpeedY;
#endif
#endif

// 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 = -distX;
// distY = -distY;
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;
}
#endif
#ifdef USE_FBREATH
vec2 deformFBreath(in vec2 texCoords, in vec2 texSize, in float len) {
vec2 dist = deformFGradientDistance(texCoords,true);
vec2 vecOut = vec2(0.0);
vecOut = texSize/len*dot(texSize/len,texSize)*(sin(g_Time))*4.0*dist;
return vecOut;
}
#endif
#ifdef USE_FWARP
vec2 deformFWarp(in vec2 texCoords) {
vec2 vecOut = texCoords;

vec2 dist = deformFGradientDistance(vecOut, true);

vecOut.x = sin(dist.x*dist.y);
vecOut.x *= sin(g_Time*m_DeformF_Warp_SpeedX);
vecOut.x *= (m_DeformF_Warp_SizeX);
vecOut.x *= (m_DeformF_Warp_DepthX);
vecOut.x *= center.x;

vecOut.y = sin(dist.x*dist.y);
vecOut.y *= sin(g_Time*m_DeformF_Warp_SpeedY);
vecOut.y *= (m_DeformF_Warp_SizeY);
vecOut.y *= (m_DeformF_Warp_DepthY);
vecOut.y *= center.y;

return vecOut;
}
#endif
#ifdef USE_FMIXER
vec2 deformFMixer(in vec2 texCoords, in vec2 texSize, in float len) {
float i;
vec2 vecOut = texCoords;
vec2 center = (texSize/len);
vec2 outter = -center;
#ifdef USE_ANIMATION
vecOut.x = (outter.x+m_DeformF_Mixer_DepthX+(mod(g_Time,i)*m_DeformF_Mixer_SpeedX))*m_DeformF_Mixer_SizeX;
vecOut.y = (outter.y+m_DeformF_Mixer_DepthY+(mod(g_Time,i)*m_DeformF_Mixer_SpeedY))*m_DeformF_Mixer_SizeY;
#else
vecOut.x = (outter.x+m_DeformF_Mixer_DepthX+(m_DeformF_Mixer_SpeedX))*m_DeformF_Mixer_SizeX;
vecOut.y = (outter.y+m_DeformF_Mixer_DepthY+(m_DeformF_Mixer_SpeedY))*m_DeformF_Mixer_SizeY;
#endif
return vecOut;
}
#endif
#ifdef USE_FFISHEYE
vec2 deformFFisheye(in vec2 texCoords, in vec2 texSize, in float len) {
// vec2 dist = deformFGradientDistance(texCoords,false);
vec2 vecOut = vec2(0.0);
// vecOut = dist;
return vecOut;
}
#endif

void main(){
vec4 color = vec4(1.0);

vec2 p = -0.1 + 0.2 * animTexCoord2;
float len = length(p);
#ifdef USE_DEFORM
#ifdef USE_FWAVE
animTexCoord1 += deformFRipple(animTexCoord2);
#endif
#ifdef USE_FBREATH
animTexCoord1 += deformFBreath(animTexCoord2, p, len);
#endif
#ifdef USE_FWARP
animTexCoord1 += deformFWarp(animTexCoord2);
#endif
#ifdef USE_FMIXER
animTexCoord1 += deformFMixer(animTexCoord2, p, len);
#endif
#ifdef USE_FFISHEYE
animTexCoord1 += deformFFisheye(animTexCoord2, p, len);
#endif
// color *= texture2D(m_Texture, animTexCoord1);
#else
// color *= texture2D(m_Texture, animTexCoord1);
#endif

vec2 newTexCoord;

#if (defined(PARALLAXMAP) || (defined(NORMALMAP_PARALLAX) && defined(NORMALMAP))) && !defined(VERTEX_LIGHTING)

#ifdef STEEP_PARALLAX
#ifdef NORMALMAP_PARALLAX
//parallax map is stored in the alpha channel of the normal map
newTexCoord = steepParallaxOffset(m_NormalMap, vViewDir, animTexCoord1, m_ParallaxHeight);
#else
//parallax map is a texture
newTexCoord = steepParallaxOffset(m_ParallaxMap, vViewDir, animTexCoord1, m_ParallaxHeight);
#endif
#else
#ifdef NORMALMAP_PARALLAX
//parallax map is stored in the alpha channel of the normal map
newTexCoord = classicParallaxOffset(m_NormalMap, vViewDir, animTexCoord1, m_ParallaxHeight);
#else
//parallax map is a texture
newTexCoord = classicParallaxOffset(m_ParallaxMap, vViewDir, animTexCoord1, m_ParallaxHeight);
#endif
#endif
#else
newTexCoord = animTexCoord1;
#endif

#ifdef DIFFUSEMAP
vec4 diffuseColor = texture2D(m_DiffuseMap, newTexCoord*m_Scale);
#else
vec4 diffuseColor = vec4(1.0);
#endif

float alpha = DiffuseSum.a * diffuseColor.a;
#ifdef ALPHAMAP
alpha = alpha * texture2D(m_AlphaMap, newTexCoord*m_Scale).r;
#endif
if(alpha < m_AlphaDiscardThreshold){
discard;
}

#ifndef VERTEX_LIGHTING
float spotFallOff = 1.0;

#if __VERSION__ >= 110
// allow use of control flow
if(g_LightDirection.w != 0.0){
#endif

vec3 L = normalize(lightVec.xyz);
vec3 spotdir = normalize(g_LightDirection.xyz);
float curAngleCos = dot(-L, spotdir);
float innerAngleCos = floor(g_LightDirection.w) * 0.001;
float outerAngleCos = fract(g_LightDirection.w);
float innerMinusOuter = innerAngleCos - outerAngleCos;
spotFallOff = (curAngleCos - outerAngleCos) / innerMinusOuter;

#if __VERSION__ >= 110
if(spotFallOff <= 0.0){
gl_FragColor.rgb = AmbientSum * diffuseColor.rgb;
gl_FragColor.a = alpha;
return;
}else{
spotFallOff = clamp(spotFallOff, 0.0, 1.0);
}
}
#else
spotFallOff = clamp(spotFallOff, step(g_LightDirection.w, 0.001), 1.0);
#endif
#endif

// ***********************
// Read from textures
// ***********************
#if defined(NORMALMAP) && !defined(VERTEX_LIGHTING)
vec4 normalHeight = texture2D(m_NormalMap, newTexCoord*m_Scale);
vec3 normal = (normalHeight.xyz * vec3(2.0) - vec3(1.0));
#ifdef LATC
normal.z = sqrt(1.0 - (normal.x * normal.x) - (normal.y * normal.y));
#endif
//normal.y = -normal.y;
#elif !defined(VERTEX_LIGHTING)
vec3 normal = vNormal;
#if !defined(LOW_QUALITY) && !defined(V_TANGENT)
normal = normalize(normal);
#endif
#endif

#ifdef SPECULARMAP
vec4 specularColor = texture2D(m_SpecularMap, newTexCoord*m_Scale);
#else
vec4 specularColor = vec4(1.0);
#endif

#ifdef LIGHTMAP
vec3 lightMapColor;
#ifdef SEPARATE_TEXCOORD
lightMapColor = texture2D(m_LightMap, texCoord2*m_Scale).rgb;
#else
lightMapColor = texture2D(m_LightMap, texCoord*m_Scale).rgb;
#endif
specularColor.rgb *= lightMapColor;
diffuseColor.rgb *= lightMapColor;
#endif

#ifdef VERTEX_LIGHTING
vec2 light = vertexLightValues.xy;
#ifdef COLORRAMP
light.x = texture2D(m_ColorRamp, vec2(light.x, 0.0)).r;
light.y = texture2D(m_ColorRamp, vec2(light.y, 0.0)).r;
#endif

color.rgb = AmbientSum * diffuseColor.rgb +
DiffuseSum.rgb * diffuseColor.rgb * vec3(light.x) +
SpecularSum * specularColor.rgb * vec3(light.y);
#else
vec4 lightDir = vLightDir;
lightDir.xyz = normalize(lightDir.xyz);
vec3 viewDir = normalize(vViewDir);

vec2 light = computeLighting(normal, viewDir, lightDir.xyz) * spotFallOff;
#ifdef COLORRAMP
diffuseColor.rgb *= texture2D(m_ColorRamp, vec2(light.x, 0.0)).rgb;
specularColor.rgb *= texture2D(m_ColorRamp, vec2(light.y, 0.0)).rgb;
#endif

// Workaround, since it is not possible to modify varying variables
vec4 SpecularSum2 = vec4(SpecularSum, 1.0);
#ifdef USE_REFLECTION
vec4 refColor = Optics_GetEnvColor(m_EnvMap, refVec.xyz);

// Interpolate light specularity toward reflection color
// Multiply result by specular map
specularColor = mix(SpecularSum2 * light.y, refColor, refVec.w) * specularColor;

SpecularSum2 = vec4(1.0);
light.y = 1.0;
#endif

color.rgb = AmbientSum * diffuseColor.rgb +
DiffuseSum.rgb * diffuseColor.rgb * vec3(light.x) +
SpecularSum2.rgb * specularColor.rgb * vec3(light.y);
#endif

gl_FragColor = color;
/*
vec4 fogColor = m_FogColor;
float depth = fog_z / m_FogDistance;
float LOG2 = 1.442695;

float fogFactor = exp2( -m_FogDensity * m_FogDensity * depth * depth * LOG2 );
fogFactor = clamp(fogFactor, 0.0, 1.0);
fogColor *= 0.2;
fogColor.a = 1.0-fogFactor;
// gl_FragColor.rgb = mix(fogColor,gl_FragColor,fogFactor).rgb;
*/
// gl_FragColor = mixFog(m_FogMode, m_FogColor, m_FogStartDistance, m_FogEndDistance, m_FogDensity, m_ExcludeSky, gl_FragColor, fog_z, texCoord);
gl_FragColor.a = alpha;
}[/java]
7 Likes

Eh… forgot you can change the position the effect starts from on the vertex deformations by using:



[java]

mat_1D.setFloat("Offset1X", .02f);

mat_1D.setFloat("Offset2X", .02f);



// Change the X to Y or Z for other axis

[/java]

1 Like

That’s very nice thanks.

Decided to add videos showing why I made this to begin with…



Here is an example of it used to handle vegetation movement:

http://youtu.be/wWe4ePmsgkY



More to come... I think
7 Likes

hehe good idea, i never thought to use deformation to gain such effect :slight_smile:

oh wow!!! thanks for this. That’s really something quite spectacular, i’m gonna have to study these :slight_smile:

And another showing it as an alternate method of rendering water effects:

http://youtu.be/6s8DfQLwGjk

4 Likes

Now… for the down side of using this right now. Because the normals are recalculated on the GPU, the vertex deformation doesn’t always play nice with other effects: like self-shadowing for instance… actually, shadows that are cast are not updated either. if and when we get access to transform feedback, I’ll update this to fix this issue.

This one is actually one of the first reasons I started working on this. It’s come in handy for lots of different NPC’s in the game I’m working on



http://youtu.be/pYpSOLx9oCQ

4 Likes

Yep… just adding crap as ideas for usage. Lava flow was another one I was really interested in using it for. I think it ended up better than I imagined. Only think I would change potentially, is splitting the verts below the ground and cinch them so the lava would seem to bend around the land. But, this was just a simple test I thought I would share.



EDIT: I particularly like the way the lava seems to speed up and slow down throughout the text as it moves.



http://youtu.be/l7F4ZyPjiFQ

3 Likes

OMG!!! IT’S COOOL!!!

What parameters you set for lava?

@mifth said:
OMG!!! IT'S COOOL!!!
What parameters you set for lava?


It was this:

[java] Material mat_1D = new Material(assetManager, "MatDefs/GPUAnimationFactory.j3md");
mat_1D.setTexture("DiffuseMap", tex);
mat_1D.setBoolean("UseAlpha", true);
mat_1D.setBoolean("UseMaterialColors", true);
mat_1D.setColor("Ambient", ColorRGBA.DarkGray); //new ColorRGBA(.1f, .3f, .3f, .4f));
mat_1D.setColor("Diffuse", ColorRGBA.Gray); //new ColorRGBA(.2f, .4f, .4f, 2.6f));
mat_1D.setColor("Specular", ColorRGBA.Black); //new ColorRGBA(.1f, .3f, .3f, 1.5f));
mat_1D.setFloat("Shininess", 1f);
mat_1D.setBoolean("Texture_Move",true);
mat_1D.setFloat("MoveF_Speed", 0.15f);
mat_1D.setFloat("MoveF_Rotation", 23);
mat_1D.setFloat("Scale", 3.3f);
mat_1D.setBoolean("Texture_Deform",true);
mat_1D.setBoolean("Texture_Animate",true);
mat_1D.setBoolean("DeformF_Wave", true);
mat_1D.setFloat("DeformF_Wave_SizeX",12f);
mat_1D.setFloat("DeformF_Wave_SizeY",12f);
mat_1D.setFloat("DeformF_Wave_DepthX",4f);
mat_1D.setFloat("DeformF_Wave_DepthY",4f);
mat_1D.setFloat("DeformF_Wave_SpeedX",0.25f);
mat_1D.setFloat("DeformF_Wave_SpeedY",0.25f);
mat_1D.setBoolean("DeformY_Ripple", true);
mat_1D.setInt("DirY", 180);
mat_1D.setFloat("SpeedY", 3.5f);
mat_1D.setFloat("SizeY", 40f);
mat_1D.setFloat("DepthY", .0032f);[/java]
1 Like

You are my shader WIZARD! :slight_smile:



That’s pretty serious setup!

@mifth said:
You are my shader WIZARD! :)

That's pretty serious setup!


That's a really nice compliment... but @nehon is the real wizard when it comes to shaders.
@t0neg0d said:
That's a really nice compliment... but @nehon is the real wizard when it comes to shaders.

Thanks, but you overestimate my skills a lot :p

Does nice looking waterfall effects:



http://youtu.be/-GJmeV-VzHY

3 Likes

Like the topic says… updates are in the OP, usage is in the OP.

Samples of the texture auto-rotate:



http://youtu.be/fp-yide4pkE

You the shader masterer! :smiley:

1 Like

@t0neg0d your shader is added to shaderBlow! Thanks a lot!