t0neg0d
February 25, 2012, 5:35pm
1
EDIT: I replaced this with the GPUAnimationFactory shader (far more useful, as it does texture animations as well), which can be found here:
http://hub.jmonkeyengine.org/groups/user-code-projects/forum/topic/gpu-animation-factory/
Here is the final mesh deformation shader coupled with JME’s lighting fragment shader.
Deformations:
Ripple, Wave, Swell, Pulse, Warble
Settings:
Speed, Size, Depth, Direction, Polar Mirror, Rotation, Offset1 & 2
New features:
You can now compound deforms against a single axis… for instance: ripple, wave & warble all against the Y axis
You can set the rotation of the wave deform
You can set the origin of the ripple deform
Notes:
When using deformations against a Y-axis plane (for example), mixing some x-axis, z-axis deformation can have undesired effects in the normals recalculation. I could have set a param for defining use with planes and the axis the plane is on, but some of the “undesired” effects can be quite cool, so I left it well enough alone.
Using polar mirroring on a flat plane will produce “undesired” effect with normals recalculation. Reason being, it is impossible to mirror an effect on a flat surface. Go figure…
Using mirroring on spheres with a high depth setting will create flipped face at the horizon line. This is not an error… it is simply the results of deforming vertices that close to the horizon line. This produces cool effects when back-face culling is turned off.
FIXED - Using offsets to place the ripple origin does not work properly with normals recalculation atm. - FIXED
New sample vid:
http://youtu.be/DIEGiqOhO9Q
Anyways, here is a sample video of some of the effects.
http://youtu.be/H7MVoptc2Kk
Updated the j3md & vert files below. Feel free to use it as is as the usage will not be changed, only added to.
15 Likes
t0neg0d
February 25, 2012, 5:37pm
3
Here is the j3md:
[java]
MaterialDef Displace {
MaterialParameters {
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
// Lighting
Boolean VertexLighting
Boolean LowQuality
Boolean HighQuality
Boolean UseAlpha
Float AlphaDiscardThreshold
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
}
Technique {
LightMode MultiPass
VertexShader GLSL100: Shaders/Displace.vert
FragmentShader GLSL100: Common/MatDefs/Light/Lighting.frag
WorldParameters {
WorldViewProjectionMatrix
NormalMatrix
WorldViewMatrix
ViewMatrix
CameraPosition
WorldMatrix
Time
}
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
//Lighting
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 : SphereMap
}
}
Technique PreShadow {
VertexShader GLSL100 : Common/MatDefs/Shadow/PreShadow.vert
FragmentShader GLSL100 : Common/MatDefs/Shadow/PreShadow.frag
WorldParameters {
WorldViewProjectionMatrix
WorldViewMatrix
}
Defines {
DIFFUSEMAP_ALPHA : DiffuseMap
}
RenderState {
FaceCull Off
DepthTest On
DepthWrite On
PolyOffset 5 0
ColorWrite Off
}
}
Technique PreNormalPass {
VertexShader GLSL100 : Common/MatDefs/SSAO/normal.vert
FragmentShader GLSL100 : Common/MatDefs/SSAO/normal.frag
WorldParameters {
WorldViewProjectionMatrix
WorldViewMatrix
NormalMatrix
}
Defines {
DIFFUSEMAP_ALPHA : DiffuseMap
}
RenderState {
}
}
Technique GBuf {
VertexShader GLSL100: Common/MatDefs/Light/GBuf.vert
FragmentShader GLSL100: Common/MatDefs/Light/GBuf.frag
WorldParameters {
WorldViewProjectionMatrix
NormalMatrix
WorldViewMatrix
WorldMatrix
}
Defines {
VERTEX_COLOR : UseVertexColor
MATERIAL_COLORS : UseMaterialColors
V_TANGENT : VTangent
MINNAERT : Minnaert
WARDISO : WardIso
DIFFUSEMAP : DiffuseMap
NORMALMAP : NormalMap
SPECULARMAP : SpecularMap
PARALLAXMAP : ParallaxMap
}
}
Technique FixedFunc {
LightMode FixedPipeline
}
Technique Glow {
VertexShader GLSL100: Common/MatDefs/Misc/SimpleTextured.vert
FragmentShader GLSL100: Common/MatDefs/Light/Glow.frag
WorldParameters {
WorldViewProjectionMatrix
}
Defines {
HAS_GLOWMAP : GlowMap
HAS_GLOWCOLOR : GlowColor
}
}
}
[/java]
1 Like
t0neg0d
February 25, 2012, 5:38pm
4
Here is the .vert
[java]
#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 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;
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;
//varying vec2 texCoord;
#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
#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.znew_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_TimespeedX)cos(m_RotationX (pi/180.0)));
float wave1X = ( m_DepthX ( sin( (m_SizeXdist1X)+time1X ) ) );
float wave2X = ( m_DepthX ( sin( (m_SizeXdist2X)+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.xnew_pos.x));
float dist2Y = sqrt((new_pos.z new_pos.z)+(new_pos.znew_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_TimespeedY)cos(m_RotationY (pi/180.0)));
float wave1Y = ( m_DepthY ( sin( (m_SizeYdist1Y)+time1Y ) ) );
float wave2Y = ( m_DepthY ( sin( (m_SizeYdist2Y)+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.xnew_pos.x));
float dist2Z = sqrt((new_pos.y new_pos.y)+(new_pos.ynew_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_TimespeedZ)cos(m_RotationZ (pi/180.0)));
float wave1Z = ( m_DepthZ ( sin( (m_SizeZdist1Z)+time1Z ) ) );
float wave2Z = ( m_DepthZ ( sin( (m_SizeZdist2Z)+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.ynew_pos.y));
float dist2X = sqrt((new_pos.z new_pos.z)+(new_pos.znew_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_TimespeedX)cos(m_RotationX (pi/180.0)));
float wave1X = ( m_DepthX sin(m_DepthX+time1X)( sin( (m_SizeX dist1X) ) ) );
float wave2X = ( m_DepthXsin(m_DepthX+time2X) ( sin( (m_SizeXdist2X) ) ) );
#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.xnew_pos.x));
float dist2Y = sqrt((new_pos.z new_pos.z)+(new_pos.znew_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_TimespeedY)cos(m_RotationY (pi/180.0)));
float wave1Y = ( m_DepthY sin(m_DepthY+time1Y)( sin( (m_SizeY dist1Y) ) ) );
float wave2Y = ( m_DepthYsin(m_DepthY+time2Y) ( sin( (m_SizeYdist2Y) ) ) );
#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.xnew_pos.x));
float dist2Z = sqrt((new_pos.y new_pos.y)+(new_pos.ynew_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_TimespeedZ)cos(m_RotationZ (pi/180.0)));
float wave1Z = ( m_DepthZ sin(m_DepthZ+time1Z)( sin( (m_SizeZ dist1Z) ) ) );
float wave2Z = ( m_DepthZsin(m_DepthZ+time2Z) ( sin( (m_SizeZdist2Z) ) ) );
#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)+(offset2Xoffset2X));
// float distX = sqrt((new_pos.y new_pos.y)+(new_pos.znew_pos.z));
#ifdef USE_MIRRORX
if (new_pos.x > 0.0) {
new_pos.x += (m_DepthX sin((m_SizeXdistX)+(g_Time speedX)));
} else {
new_pos.x -= (m_DepthXsin((m_SizeX distX)+(g_TimespeedX)));
}
#else
new_pos.x += (m_DepthX sin((m_SizeXdistX)+(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((offset1Yoffset1Y)+(offset2Y offset2Y));
#ifdef USE_MIRRORY
if (new_pos.y < 0.0) {
new_pos.y += (m_DepthYsin((m_SizeY distY)+(g_TimespeedY)));
} else {
new_pos.y -= (m_DepthY sin((m_SizeYdistY)+(g_Time speedY)));
}
#else
new_pos.y += (m_DepthYsin((m_SizeY distY)+(g_TimespeedY)));
#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)+(offset2Zoffset2Z));
// float distZ = sqrt((new_pos.x new_pos.x)+(new_pos.ynew_pos.y));
#ifdef USE_MIRRORZ
if (new_pos.z < 0.0) {
new_pos.z += (m_DepthZ sin((m_SizeZdistZ)+(g_Time speedZ)));
} else {
new_pos.z -= (m_DepthZsin((m_SizeZ distZ)+(g_TimespeedZ)));
}
#else
new_pos.z += (m_DepthZ sin((m_SizeZdistZ)+(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_TimespeedX));
if (m_DirX == 1) swellX = -swellX;
float distX = sqrt((new_pos.y new_pos.y)+(new_pos.znew_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.xnew_pos.x)+(new_pos.z new_pos.z));
if (new_pos.y < 0.0) {
new_pos.y += m_DepthYabs(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.ynew_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.ynew_pos.y)+(new_pos.z new_pos.z));
if (new_pos.x < 0.0) {
new_pos.x += m_DepthXabs(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.znew_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.xnew_pos.x)+(new_pos.y new_pos.y));
if (new_pos.z < 0.0) {
new_pos.z += m_DepthZabs(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.znew_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_TimespeedX)sin(m_RotationX (pi/180.0)));
time2X = ((g_Time speedX)cos(m_RotationX (pi/180.0)));
jac_coef1X = (m_DepthXcos((m_SizeX dist1X)+time1X)/(dist1X+0.00001));
jac_coef2X = (m_DepthXcos((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_coef1Xnew_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.ynew_pos.y)+(new_pos.y new_pos.y));
dist2X = sqrt((new_pos.znew_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_TimespeedX)sin(m_RotationX (pi/180.0)));
time2X = -((g_Time speedX)cos(m_RotationX (pi/180.0)));
jac_coef1X = ( m_DepthXcos(m_DepthX+time1X) ( cos( (m_SizeXdist1X) ) ) )/(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_coef1Xnew_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((offset1Xoffset1X)+(offset2X offset2X));
jac_coefX = m_DepthXcos((m_SizeX distX)+(g_TimespeedX))/(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.ynew_pos.y)+(new_pos.z new_pos.z));
jac_coefX = m_DepthXabs(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.znew_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.xnew_pos.x));
dist2Y = sqrt((new_pos.z new_pos.z)+(new_pos.znew_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_TimespeedY)cos(m_RotationY (pi/180.0)));
jac_coef1Y = (m_DepthY cos((m_SizeYdist1Y)+time1Y)/(dist1Y+0.00001));
jac_coef2Y = (m_DepthY cos((m_SizeYdist2Y)+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_coef2Ynew_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.xnew_pos.x));
dist2Y = sqrt((new_pos.z new_pos.z)+(new_pos.znew_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_TimespeedY)cos(m_RotationY (pi/180.0)));
jac_coef1Y = ( m_DepthY cos(m_DepthY+time1Y)( cos( (m_SizeY dist1Y) ) ) )/(dist1Y+0.00001);
jac_coef2Y = ( m_DepthYcos(m_DepthY+time2Y) ( cos( (m_SizeYdist2Y) ) ) )/(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_coef2Ynew_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)+(offset2Yoffset2Y));
// distY = sqrt((new_pos.x new_pos.x)+(new_pos.znew_pos.z));
jac_coefY = m_DepthY cos((m_SizeYdistY)+(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_TimespeedY));
if (m_DirY == 1) swellY = -swellY;
distY = sqrt((new_pos.x new_pos.x)+(new_pos.znew_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.xnew_pos.x)+(new_pos.z new_pos.z));
jac_coefY = (m_DepthYabs(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.ynew_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_TimespeedZ)sin(m_RotationZ (pi/180.0)));
time2Z = ((g_Time speedZ)cos(m_RotationZ (pi/180.0)));
jac_coef1Z = (m_DepthZcos((m_SizeZ dist1Z)+time1Z)/(dist1Z+0.00001));
jac_coef2Z = (m_DepthZcos((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_coef1Znew_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.xnew_pos.x)+(new_pos.x new_pos.x));
dist2Z = sqrt((new_pos.ynew_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_TimespeedZ)sin(m_RotationZ (pi/180.0)));
time2Z = -((g_Time speedZ)cos(m_RotationZ (pi/180.0)));
jac_coef1Z = ( m_DepthZcos(m_DepthZ+time1Z) ( cos( (m_SizeZdist1Z) ) ) )/(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_coef1Znew_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((offset1Zoffset1Z)+(offset2Z offset2Z));
// distZ = sqrt((new_pos.xnew_pos.x)+(new_pos.y new_pos.y));
jac_coefZ = m_DepthZsin((m_SizeZ distZ)+(g_TimespeedZ))/(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.xnew_pos.x)+(new_pos.y new_pos.y));
jac_coefZ = m_DepthZabs(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.ynew_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 = Jbinormal;
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);
// vec4 pos = vec4(inPosition, 1.0);
// gl_Position = g_WorldViewProjectionMatrix * pos;
// texCoord = inTexCoord;
#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
//vNormal = normalize(g_NormalMatrix displacedNormal);
}
[/java]
1 Like
enum
February 25, 2012, 6:22pm
5
Thank you very much. This will definitely be useful
mifth
February 25, 2012, 9:11pm
6
@t0neg0d , you are cool!!! Really nice!
Can you provide a simple examples? I’ll add you shader to the shader library.
t0neg0d
February 25, 2012, 10:07pm
7
@mifth I sure can. I’ll also finally post the GPU version of the other shader for moving textures as well. I think I’m going to revisit this current one and break it into separate shaders for each deformation so I can extend them easier.
The ripple effect… it should be able to clamp the origin to any side or corner (well virtual corner on 3d meshes)…
You should be able to do the same for the wave effect, or have it originate from the center (heh… and I spent so much time trying to figure out how to NOT have it centered). Also, you should be able to adjust X, Z frequencies separately to (or randomize them) to create a more natural effect.
Speaking of that, you should be able to set a global tolerance for randomization and enable/disable it to produce slight variances on every effect.
The pulse and swell effects are not taking size into account atm either. You should be able to divide the effect across the mesh to double, triple, etc, etc the swell or pulse.
And once they are all extended to a more usable form for animations, I’ll recompile them back into a single shader for animating.
The reason I am going to do this (and this is only a for-instance)… using the ripple effect to animate the top portion of a jellyfish requires a center clamp… however, the tentacles… or a snake for that matter… would require a side clamp. Hair blowing in the wind would require a corner clamp.
Once all of this is completed (which shouldn’t take very long… a week maybe), producing realistic mesh animations just using the shader should be completely possible.
mifth
February 25, 2012, 10:36pm
8
ok, man! I’ll be waiting. )
nehon
February 26, 2012, 9:38am
9
This is really a great work.
Kudos @t0neg0d
t0neg0d
February 27, 2012, 12:39am
10
@mifth Sorry for the delay, however, it will be worth while! I’m adding a new deform (warble). But, more importantly, I’m adding the ability to compound multiple deforms against a single axis. Oh… and the ability to set the rotation on wave and the anchor point on ripple.
Multiple transforms against a single axis works like this:
mat.setBoolean(“DeformX_Wave”, true);
mat.setBoolean(“DeformX_Ripple”, true);
mat.setBoolean(“DeformX_Warble”, true);
This would have the effect of (not actually producing separate meshs… just how the transforms are compounded)
mesh + wave = deformedmesh1
deformedmesh1 + ripple = deformedmesh2
deformedmesh2 + warble = finaldeform
If you modify the order, you get varying results. This makes for some absolutely AWESOME water chop deformation. And if you use different compounds for different axis’ on a 3d model… it is just trippy what you can do with it.
Oh… I also noticed a few bugs in what I posted here (not recalcing the normals for anything other than ripple and wave… etc).
Anyways… won’t be long now.
mifth
February 27, 2012, 1:25pm
12
No problem man! you are making good stuff. This defenetely will be used by JME Community.
t0neg0d
February 27, 2012, 5:09pm
13
Updated topic with new features & vid.
Updated j3md & vert.
One last issue to resolve with one of the new features and then I’ll upload a sample project.
2 Likes
t0neg0d
February 28, 2012, 4:21am
14
@mifth Ok… this one is ready to go as well. Being able to commit the source myself probably isn’t a bad idea, as it will save you time… plus, I was thinking about extending JME’s lighting.frag with texture deforms as well, so I probably will have more useful stuff soonish. I think it would be cool to be able to apply both mesh and texture deforms to create more realistic liquid effects.
I can create versions that extend the lighting shaders you have in the repository. Those are seriously cool.
Anyways, let me know.
madjack
February 28, 2012, 7:04am
15
Really nice work there @t0neg0d I like!
Got a Q for you though.
I was thinking of doing something similar for my game but with a twist…
Here’s the thing:
What I’d like to have is a deformed sphere based on certain points surrounding an origin point. But, and here’s the twist, once that’s set, I want it to remain static; unmoving, until there’s a change. When (if) that happens then a new deformed sphere should be used.
I intend to use this as a frontier delimiter for each race at their home world at location of X/Y/Z. By using that race’s home world as an origin and feeding it the farthest points to it, I should be able to deform a sphere enough so it includes each system inside it.
It’s really late here and I haven’t checked the code, only the videos, but how hard do you think it would be to modify the above .vert/.frag to accommodate for this kind of thing?
Thanks.
t0neg0d
February 28, 2012, 8:42am
16
@madjack If you do the following when creating the material:
[java]
mat.setBoolean(“DeformX_Ripple”, true);
mat.setFloat(“SpeedX”, 0f);
[/java]
It produces a static (unanimated) deform.
I hope this answered your question correctly. It’s late here to
Ooops… I think I missed the whole second part of your question. I’ll give this some thought in the AM and see about answering the second part as well.
madjack
February 28, 2012, 4:57pm
17
Thanks for the reply.
I’ll check that up later this week. I have to make a new video first.
mifth
March 9, 2012, 8:25am
18
@t0neg0d , can you provide a simple example scene? I’ll add it to the shader library.
@t0neg0d Does CryEngine or Unigine Engine uses these type of shader for Sea surface?
@mifth Sorry about the major delay here. I’m in the midst of a move that was COMPLETELY unexpected. Owner of the house got foreclosed on… and of course, we were the last to find out I’ll try and get this out tonight, once Internet access is up in the new house.
@iamcreasy I’m pretty sure that a mesh deformation is used, yes.