Good day,
I am hoping to apply the same effect illustrated in the TestVertexProgramState example. Below is a screenshot of the problem:
This screenshot is derived from only drawing the shaded torus. I can fix this by calling the following piece of code:
// Remove all of the lights...
lightState.detatchAll();
// This works just the same...
lightState.setEnable(false);
However, when I do that and then reenable the outline torus the following happens:
Notice that there are only two shaded color values on the torus. I have not modified the 1x16 shader.png nor modified the celshaderARB.vp shader example included in the latest jME release.
It would seem that with the lights on I am getting the correct number of shaded colors on my torus, but the torus has some sort of artifact problem. Also, with the light on my outline becomes a sort of gradient which is not the effect I am trying to emulate.
Below is my source code which is almost identical to jmetest.renderer.state.TestVertexProgramState by Eric Woroshow.
import com.jme.app.SimpleGame;
import com.jme.image.Texture;
import com.jme.input.NodeHandler;
import com.jme.math.Vector3f;
import com.jme.renderer.ColorRGBA;
import com.jme.scene.shape.Torus;
import com.jme.scene.state.CullState;
import com.jme.scene.state.TextureState;
import com.jme.scene.state.VertexProgramState;
import com.jme.scene.state.WireframeState;
import com.jme.util.TextureManager;
public class Test extends SimpleGame {
private final float[] lightPosition = { -0.8f, 0.8f, 0.8f, 0.0f };
public static void main(String[] args) {
Test app = new Test();
// app.setDialogBehaviour(ALWAYS_SHOW_PROPS_DIALOG);
app.start();
}
protected void simpleInitGame() {
display.setTitle("Vertex Programs");
display.getRenderer().setBackgroundColor(
new ColorRGBA(0.25f, 0.25f, 0.25f, 1.0f));
cam.setLocation(new Vector3f(0, 0, 45));
cam.update();
input = new NodeHandler(rootNode, 10, 2);
lightState.detachAll();
Torus outline = createOutlineTorus();
Torus shaded = createShadedTorus();
rootNode.attachChild(outline);
rootNode.attachChild(shaded);
rootNode.updateRenderState();
}
private Torus createShadedTorus() {
VertexProgramState vp = display.getRenderer()
.createVertexProgramState();
vp.setParameter(lightPosition, 8);
vp.load(Test.class.getClassLoader().getResource(
"jmetest/data/images/celshaderARB.vp"));
vp.setEnabled(true);
TextureState ts = display.getRenderer().createTextureState();
ts.setTexture(TextureManager.loadTexture(Test.class.getClassLoader()
.getResource("jmetest/data/images/shader.png"),
Texture.MM_NEAREST, Texture.MM_NEAREST));
ts.setEnabled(true);
CullState cs = display.getRenderer().createCullState();
cs.setCullMode(CullState.CS_BACK);
cs.setEnabled(true);
Torus torus = new Torus("shadedTorus", 128, 32, 3.0f, 5.0f);
torus.setDefaultColor(ColorRGBA.orange.clone());
torus.setRenderState(vp);
torus.setRenderState(ts);
torus.setRenderState(cs);
return torus;
}
private Torus createOutlineTorus() {
CullState cs = display.getRenderer().createCullState();
cs.setCullMode(CullState.CS_FRONT);
cs.setEnabled(true);
WireframeState ws = display.getRenderer().createWireframeState();
ws.setLineWidth(6.0f);
ws.setFace(WireframeState.WS_FRONT);
ws.setEnabled(true);
Torus torus = new Torus("outlineTorus", 128, 32, 3.0f, 5.0f);
torus.setDefaultColor(ColorRGBA.black.clone());
torus.setRenderState(cs);
torus.setRenderState(ws);
return torus;
}
}
I appreciate the help!