Here is everything

```
//uniform vec3 g_CameraPosition;
//float base(float dist, float max) {
//if(dist > max) {
//return 1;
//}
//return (dist / max);
//}
void main() {
//float dist = base(distance(g_CameraPosition, inPosition), 500);
//outColor = vec4(dist, dist, dist, 1);
outColor = vec4(0.0,0.0,1.0,1.0);
}
```

```
ShaderNodeDefinitions{
ShaderNodeDefinition DistanceFrag {
Type: Fragment
Shader GLSL100: Shaders/data/dist.frag
Documentation{
I like cheese.
}
Input {
float inMax
vec3 inPosition;
}
Output {
vec4 outColor
}
}
}
```

```
MaterialDef Simple {
MaterialParameters {
Float Max
}
Technique {
WorldParameters {
WorldViewProjectionMatrix
}
VertexShaderNodes {
ShaderNode CommonVert {
Definition : CommonVert : Common/MatDefs/ShaderNodes/Common/CommonVert.j3sn
InputMappings {
worldViewProjectionMatrix = WorldParam.WorldViewProjectionMatrix
modelPosition = Global.position.xyz
}
OutputMappings {
Global.position = projPosition
}
}
}
FragmentShaderNodes {
ShaderNode DistanceFrag {
Definition : DistanceFrag : Shaders/data/distancefrag.j3sn
InputMappings {
inPosition = Global.position.xyz
inMax = MatParam.Max
}
OutputMappings {
Global.color = outColor
}
}
}
}
}
```

```
package test.shader;
import com.jme3.app.SimpleApplication;
import com.jme3.material.Material;
import com.jme3.scene.Geometry;
import com.jme3.scene.shape.Box;
/**
*
* @author MisterCavespider
*/
public class ShaderDistanceSimple extends SimpleApplication {
@Override
public void simpleInitApp() {
flyCam.setMoveSpeed(65);
Geometry box = new Geometry("box", new Box(1, 1, 1));
Material mat = new Material(assetManager, "Materials/distance.j3md");
mat.setFloat("Max", 30);
box.setMaterial(mat);
rootNode.attachChild(box);
float dist = cam.getLocation().distance(box.getLocalTranslation());
System.out.println(dist);
}
}
```

It’s either a typo, or I did something wrong somewhere.

I don’t know.

ADD:

and this is how it looks like when it’s interpreted/compiled:

```
1 #version 150 core
2 #define FRAGMENT_SHADER 1
3
4 uniform float m_Max;
5
6
7 //uniform vec3 g_CameraPosition;
8
9 //float base(float dist, float max) {
10 //if(dist > max) {
11 //return 1;
12 //}
13 //return (dist / max);
14 //}
15
16 out vec4 Global_position;
17 out vec4 Global_color;
18
19 void main(){
20 Global_position = vec4(1.0);
21 Global_color = vec4(1.0);
22
23 //TheFrag : Begin
24 vec3 TheFrag_inPosition = Global_position.xyz;
25 vec4 TheFrag_outColor;
26
27 //float dist = base(distance(g_CameraPosition, TheFrag_inPosition), 500);
28 //TheFrag_outColor = vec4(dist, dist, dist, 1);
29 TheFrag_outColor = vec4(0.0, 1.0, 0.5, 1.0):::::;
30 Global_color = TheFrag_outColor;
31 //TheFrag : End
32 }
```