Hello. I’m just start plaing with jme. I’m not experienced whith developing 3d applications and with shaders especially.
I’ve created simple scene and try use CartoonEdgeFilter and got some artefacts. Looks like shader program dont take into account the distance between planes, only normals differense.
Is it possible to fix this artefacts?
Sorry for my english and mb terminolgy issues
Mhh strange CartoonEdgeFilter does not use only normals, it uses depth too.
Could you provide a test case?
O, thanks for a fast answer and for giving me a way to find solution
I’ve tried to make scene simpler. Then i try to play whith setDepthThreshold and DepthSensitivity, and i find solutuion. The edges drawing is based on camera position (didn’t know/understand this). Now i’m going to find perfect dependency between sensetivity/threshol/campostion to take an effect i want.
Anywhere - there is test case. Uncomment lines 36, 37 to take effect.
[java]
package mygame;
import com.jme3.app.SimpleApplication;
import com.jme3.light.DirectionalLight;
import com.jme3.material.Material;
import com.jme3.math.ColorRGBA;
import com.jme3.math.FastMath;
import com.jme3.math.Matrix3f;
import com.jme3.math.Quaternion;
import com.jme3.math.Transform;
import com.jme3.math.Vector3f;
import com.jme3.post.FilterPostProcessor;
import com.jme3.post.filters.CartoonEdgeFilter;
import com.jme3.renderer.Caps;
import com.jme3.renderer.RenderManager;
import com.jme3.scene.Geometry;
import com.jme3.scene.Node;
import com.jme3.scene.Spatial;
import com.jme3.scene.Spatial.CullHint;
import com.jme3.scene.shape.Box;
import com.jme3.texture.Texture;
/**
- test
-
@author normenhansen
*/
public class Main extends SimpleApplication {
private FilterPostProcessor fpp;
public static void main(String[] args) {
Main app = new Main();
app.start();
}
public void setupFilters(){
if (renderer.getCaps().contains(Caps.GLSL100)){
fpp=new FilterPostProcessor(assetManager);
//fpp.setNumSamples(4);
CartoonEdgeFilter toon=new CartoonEdgeFilter();
//toon.setDepthThreshold(0);
//toon.setDepthSensitivity(150);
fpp.addFilter(toon);
viewPort.addProcessor(fpp);
}
}
public void makeToonish(Spatial spatial){
if (spatial instanceof Node){
Node n = (Node) spatial;
for (Spatial child : n.getChildren())
makeToonish(child);
}else if (spatial instanceof Geometry){
Geometry g = (Geometry) spatial;
Material m = g.getMaterial();
if (m.getMaterialDef().getName().equals("Phong Lighting")){
Texture t = assetManager.loadTexture("Textures/ColorRamp/toon.png");
// t.setMinFilter(Texture.MinFilter.NearestNoMipMaps);
// t.setMagFilter(Texture.MagFilter.Nearest);
m.setTexture("ColorRamp", t);
m.setBoolean("UseMaterialColors", true);
m.setColor("Specular", ColorRGBA.Black);
m.setColor("Diffuse", ColorRGBA.White);
m.setBoolean("VertexLighting", true);
}
}
}
public void setupLighting(){
DirectionalLight dl = new DirectionalLight();
dl.setDirection(new Vector3f(-1, -1, 1).normalizeLocal());
dl.setColor(new ColorRGBA(2,2,2,1));
rootNode.addLight(dl);
}
public void setupModel(){
Material m = new Material(assetManager, "Common/MatDefs/Light/Lighting.j3md");
//m.setBoolean("m_UseMaterialColors", true);
m.setColor("m_Ambient", ColorRGBA.Gray);
//m.setColor("m_Diffuse", ColorRGBA.Gray);
//m.setColor("m_Specular", ColorRGBA.White);
//m.setFloat("m_Shininess", 12f);
Box floor = new Box(10, 10, 1);
Geometry floor_geom = new Geometry("Floor", floor);
floor_geom.setLocalTranslation(0, 0, 1);
floor_geom.setMaterial(m);
rootNode.attachChild(floor_geom);
makeToonish(floor_geom);
Box box = new Box(1, 1, 1);
Geometry box_geom = new Geometry("Box", box);
box_geom.setLocalTranslation(0,0,-1);
box_geom.setMaterial(m);
rootNode.attachChild(box_geom);
makeToonish(box_geom);
}
@Override
public void simpleInitApp() {
viewPort.setBackgroundColor(ColorRGBA.Gray);
cam.setLocation(new Vector3f(-5, -5, -10));
cam.lookAt(Vector3f.ZERO, new Vector3f(5, 5, 0));
cam.update();
cam.setFrustumFar(300);
flyCam.setMoveSpeed(30);
rootNode.setCullHint(CullHint.Never);
setupLighting();
setupModel();
setupFilters();
}
}
[/java]