Animal Crossing World Rolling Filter

Hello I have been banging my head agents this for a while and figured it is time to reach out for some help. I am using the new “jMonkeyEngine SDK 3.1 Alpha-1” when running my application for desktop it works as expected but when running it on my Android “Samsung Galaxy S4” it seems that the fragment is working but the vertex is not.

Questions:

  • Why won't this work on android?
  • Am I doing something wrong?

J3MD

MaterialDef CurvedWorld {
	MaterialParameters {
		Float Curvature
		Color Color
	}
	Technique {
		WorldParameters {
			WorldViewProjectionMatrix
			WorldViewMatrix
		}
		VertexShaderNodes {
			ShaderNode CurvedWorldVert {
				Definition : CurvedWorldVert : MatDefs/CurvedWorldVert.j3sn
				InputMappings {
					worldViewProjectionMatrix = WorldParam.WorldViewProjectionMatrix
					modelViewMatrix = WorldParam.WorldViewMatrix
					modelPosition = Global.position
					curvature = MatParam.Curvature
				}
				OutputMappings {
					Global.position = projPosition
				}
			}
		}
		FragmentShaderNodes {
			ShaderNode ColorMult {
				Definition : ColorMult : Common/MatDefs/ShaderNodes/Basic/ColorMult.j3sn
				InputMappings {
					color1 = MatParam.Color
					color2 = Global.color
				}
				OutputMappings {
					Global.color = outColor
				}
			}
		}
	}
}

J3SN

ShaderNodesDefinitions {
	ShaderNodeDefinition CurvedWorldVert {
		Type: Vertex
		Shader GLSL100: MatDefs/curvedWorld.vert
		Documentation {
		}
		Input{
			vec4 modelPosition
			mat4 worldViewProjectionMatrix
			mat4 modelViewMatrix
			float curvature
			vec2 texCoord1
			vec2 texCoord2
			vec4 vertColor
		}
		Output{
			vec4 projPosition
			vec2 texCoord1
			vec2 texCoord2
			vec4 vertColor
		}
	}
}

VERT

void main() {
	vec4 viewSpacePos = modelViewMatrix * modelPosition;
	vec4 vModelPosition = vec4(modelPosition);
	vModelPosition.y -= (viewSpacePos.z * viewSpacePos.z) * curvature;
	projPosition = worldViewProjectionMatrix * vec4(vModelPosition.xyz, 1.0);
}

And if anyone is feeling nice how do i find “vert.z - cam.z” not distance from camera?
This would allow my rolling effect to only happen in one direction.

This shader gives you the Animal Crossing World rolling effect but in both directions X and Z the world will look better if you have more vertices along X and Z. radious is the radious of your world I would use something like 256 or 128 for small planets but you could use 1736482 for the radius of the moon :stuck_out_tongue:

I have my vertex shader working in both android and windows not using shader nodes. I will dig into the new way for creating shaders at a later time. so have fun using this shader if you want to still need to put it into a Filter but that wont take very long. Does any one think this should be contributed to JME3 I just coppied the Unshaded J3MD and replaced its vert with my own.

J3MD

MaterialDef CurvedWorld2 {
	
	MaterialParameters {
		Texture2D ColorMap
		Texture2D LightMap
		Color Color (Color)
		Boolean VertexColor (UseVertexColor)
		Boolean SeparateTexCoord
		
		// Texture of the glowing parts of the material
		Texture2D GlowMap
		// The glow color of the object
		Color GlowColor
		
		// For instancing
		Boolean UseInstancing
		
		// For hardware skinning
		Int NumberOfBones
		Matrix4Array BoneMatrices
		
		// Alpha threshold for fragment discarding
		Float AlphaDiscardThreshold (AlphaTestFallOff)
		
		//Shadows
		Int FilterMode
		Boolean HardwareShadows
		
		Texture2D ShadowMap0
		Texture2D ShadowMap1
		Texture2D ShadowMap2
		Texture2D ShadowMap3
		//pointLights
		Texture2D ShadowMap4
		Texture2D ShadowMap5
		
		Float ShadowIntensity
		Vector4 Splits
		Vector2 FadeInfo
		
		Matrix4 LightViewProjectionMatrix0
		Matrix4 LightViewProjectionMatrix1
		Matrix4 LightViewProjectionMatrix2
		Matrix4 LightViewProjectionMatrix3
		//pointLight
		Matrix4 LightViewProjectionMatrix4
		Matrix4 LightViewProjectionMatrix5
		Vector3 LightPos
		Vector3 LightDir
		
		Float PCFEdge
		
		Float ShadowMapSize
		
		Float Radius
	}
	
	Technique {
		VertexShader GLSL150:   MatDefs/CurvedWorld2.vert
		FragmentShader GLSL150: Common/MatDefs/Misc/Unshaded.frag
		
		WorldParameters {
			WorldViewProjectionMatrix
			ViewProjectionMatrix
			WorldViewMatrix
			WorldMatrix
			ViewMatrix
		}
		
		Defines {
			INSTANCING : UseInstancing
			SEPARATE_TEXCOORD : SeparateTexCoord
			HAS_COLORMAP : ColorMap
			HAS_LIGHTMAP : LightMap
			HAS_VERTEXCOLOR : VertexColor
			HAS_COLOR : Color
			NUM_BONES : NumberOfBones
			DISCARD_ALPHA : AlphaDiscardThreshold
			RADIUS : Radius
		}
	}
	
	Technique {
		VertexShader GLSL100:   MatDefs/CurvedWorld2.vert
		FragmentShader GLSL100: Common/MatDefs/Misc/Unshaded.frag
		
		WorldParameters {
			WorldViewProjectionMatrix
			ViewProjectionMatrix
			WorldViewMatrix
			WorldMatrix
			ViewMatrix
		}
		
		Defines {
			INSTANCING : UseInstancing
			SEPARATE_TEXCOORD : SeparateTexCoord
			HAS_COLORMAP : ColorMap
			HAS_LIGHTMAP : LightMap
			HAS_VERTEXCOLOR : VertexColor
			HAS_COLOR : Color
			NUM_BONES : NumberOfBones
			DISCARD_ALPHA : AlphaDiscardThreshold
			RADIUS : Radius
		}
	}
	
	Technique PreNormalPass {
		VertexShader GLSL100 :   Common/MatDefs/SSAO/normal.vert
		FragmentShader GLSL100 : Common/MatDefs/SSAO/normal.frag
		
		WorldParameters {
			WorldViewProjectionMatrix
			WorldViewMatrix
			NormalMatrix
			ViewProjectionMatrix
			ViewMatrix
		}
		
		Defines {
			NUM_BONES : NumberOfBones
			INSTANCING : UseInstancing
		}
	}
	
	Technique PreShadow {
		VertexShader GLSL100 :   Common/MatDefs/Shadow/PreShadow.vert
		FragmentShader GLSL100 : Common/MatDefs/Shadow/PreShadow.frag
		
		WorldParameters {
			WorldViewProjectionMatrix
			WorldViewMatrix
			ViewProjectionMatrix
			ViewMatrix
		}
		
		Defines {
			COLOR_MAP : ColorMap
			DISCARD_ALPHA : AlphaDiscardThreshold
			NUM_BONES : NumberOfBones
			INSTANCING : UseInstancing
		}
		
		ForcedRenderState {
			FaceCull Off
			DepthTest On
			DepthWrite On
			PolyOffset 5 3
			ColorWrite Off
		}
	}
	
	Technique PostShadow15 {
		VertexShader GLSL150:   Common/MatDefs/Shadow/PostShadow15.vert
		FragmentShader GLSL150: Common/MatDefs/Shadow/PostShadow15.frag
		
		WorldParameters {
			WorldViewProjectionMatrix
			WorldMatrix
			ViewProjectionMatrix
			ViewMatrix
		}
		
		Defines {
			HARDWARE_SHADOWS : HardwareShadows
			FILTER_MODE : FilterMode
			PCFEDGE : PCFEdge
			DISCARD_ALPHA : AlphaDiscardThreshold           
			COLOR_MAP : ColorMap
			SHADOWMAP_SIZE : ShadowMapSize
			FADE : FadeInfo
			PSSM : Splits
			POINTLIGHT : LightViewProjectionMatrix5
			NUM_BONES : NumberOfBones
			INSTANCING : UseInstancing
		}
		
		ForcedRenderState {
			Blend Modulate
			DepthWrite Off                 
			PolyOffset -0.1 0
		}
	}
	
	Technique PostShadow {
		VertexShader GLSL100:   Common/MatDefs/Shadow/PostShadow.vert
		FragmentShader GLSL100: Common/MatDefs/Shadow/PostShadow.frag
		
		WorldParameters {
			WorldViewProjectionMatrix
			WorldMatrix
			ViewProjectionMatrix
			ViewMatrix
		}
		
		Defines {
			HARDWARE_SHADOWS : HardwareShadows
			FILTER_MODE : FilterMode
			PCFEDGE : PCFEdge
			DISCARD_ALPHA : AlphaDiscardThreshold           
			COLOR_MAP : ColorMap
			SHADOWMAP_SIZE : ShadowMapSize
			FADE : FadeInfo
			PSSM : Splits
			POINTLIGHT : LightViewProjectionMatrix5
			NUM_BONES : NumberOfBones
			INSTANCING : UseInstancing
		}
		
		ForcedRenderState {
			Blend Modulate
			DepthWrite Off   
			PolyOffset -0.1 0  
		}
	}
	
	Technique Glow {
		VertexShader GLSL100:   MatDefs/CurvedWorld2.vert
		FragmentShader GLSL100: Common/MatDefs/Light/Glow.frag
		
		WorldParameters {
			WorldViewProjectionMatrix
			ViewProjectionMatrix
			ViewMatrix
		}
		
		Defines {
			NEED_TEXCOORD1
			HAS_GLOWMAP : GlowMap
			HAS_GLOWCOLOR : GlowColor
			NUM_BONES : NumberOfBones
			INSTANCING : UseInstancing
			RADIUS : Radius
		}
	}
}

VERT

#import "Common/ShaderLib/Skinning.glsllib"
#import "Common/ShaderLib/Instancing.glsllib"
/*
#define hfloat highp float
#define hvec2  highp vec2
#define hvec3  highp vec3
#define hvec4  highp vec4
#define lfloat lowp float
#define lvec2 lowp vec2
#define lvec3 lowp vec3
#define lvec4 lowp vec4
*/
attribute vec3 inPosition;

#if defined(HAS_COLORMAP) || (defined(HAS_LIGHTMAP) && !defined(SEPARATE_TEXCOORD))
    #define NEED_TEXCOORD1
#endif

attribute vec2 inTexCoord;
attribute vec2 inTexCoord2;
attribute vec4 inColor;

varying vec2 texCoord1;
varying vec2 texCoord2;

varying vec4 vertColor;

bool isNan(float val)
{
	return(val <= 0.0 || 0.0 <= val) ? false : true;
}

void main() {
	#ifdef NEED_TEXCOORD1
		texCoord1 = inTexCoord;
	#endif
	
	#ifdef SEPARATE_TEXCOORD
		texCoord2 = inTexCoord2;
	#endif
	
	#ifdef HAS_VERTEXCOLOR
		vertColor = inColor;
	#endif
	
	vec4 modelSpacePos = vec4(inPosition, 1.0);
	
	#ifdef NUM_BONES
		Skinning_Compute(modelSpacePos);
	#endif
	
	#ifdef RADIUS
		vec4 worldSpacePos = TransformWorldView(modelSpacePos);
		float dist = length(worldSpacePos.xz);
		if(isNan(dist)) {
			dist = -RADIUS;
		}
		modelSpacePos.y += sqrt((RADIUS * RADIUS) - (dist * dist)) - RADIUS;
	#endif
	
	gl_Position = TransformWorldViewProjection(modelSpacePos);
}

one quick question can you check if a function is defined?

#if !defined(isnan)
bool isnan(float val) {
    return !(val <= 0.0 || 0.0 <= val);
}
#endif
1 Like