|
@@ -1,7 +1,10 @@
|
|
package jme3test.scene.instancing;
|
|
package jme3test.scene.instancing;
|
|
|
|
|
|
|
|
+import java.util.Locale;
|
|
|
|
+
|
|
import com.jme3.app.SimpleApplication;
|
|
import com.jme3.app.SimpleApplication;
|
|
-import com.jme3.light.PointLight;
|
|
|
|
|
|
+import com.jme3.font.BitmapText;
|
|
|
|
+import com.jme3.light.DirectionalLight;
|
|
import com.jme3.material.Material;
|
|
import com.jme3.material.Material;
|
|
import com.jme3.math.ColorRGBA;
|
|
import com.jme3.math.ColorRGBA;
|
|
import com.jme3.math.Vector3f;
|
|
import com.jme3.math.Vector3f;
|
|
@@ -9,53 +12,81 @@ import com.jme3.scene.Geometry;
|
|
import com.jme3.scene.instancing.InstancedNode;
|
|
import com.jme3.scene.instancing.InstancedNode;
|
|
import com.jme3.scene.shape.Box;
|
|
import com.jme3.scene.shape.Box;
|
|
|
|
|
|
|
|
+/**
|
|
|
|
+ * This test specifically validates the corrected PBR rendering when combined
|
|
|
|
+ * with instancing, as addressed in issue #2435.
|
|
|
|
+ *
|
|
|
|
+ * It creates an InstancedNode
|
|
|
|
+ * with a PBR-materialized Box to ensure the fix in PBRLighting.vert correctly
|
|
|
|
+ * handles world position calculations for instanced geometry.
|
|
|
|
+ */
|
|
public class TestInstanceNodeWithPbr extends SimpleApplication {
|
|
public class TestInstanceNodeWithPbr extends SimpleApplication {
|
|
- // Try to test with different offset
|
|
|
|
- private static float offset = 12;
|
|
|
|
|
|
|
|
public static void main(String[] args) {
|
|
public static void main(String[] args) {
|
|
TestInstanceNodeWithPbr app = new TestInstanceNodeWithPbr();
|
|
TestInstanceNodeWithPbr app = new TestInstanceNodeWithPbr();
|
|
app.start();
|
|
app.start();
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ private BitmapText bmp;
|
|
private Geometry box;
|
|
private Geometry box;
|
|
- private PointLight pointLight;
|
|
|
|
-
|
|
|
|
|
|
+ private float pos = -5;
|
|
|
|
+ private float vel = 5;
|
|
|
|
+
|
|
@Override
|
|
@Override
|
|
public void simpleInitApp() {
|
|
public void simpleInitApp() {
|
|
- InstancedNode instancedNode = new InstancedNode("testInstancedNode");
|
|
|
|
|
|
+ configureCamera();
|
|
|
|
+ bmp = createLabelText(10, 20, "<placeholder>");
|
|
|
|
+
|
|
|
|
+ InstancedNode instancedNode = new InstancedNode("InstancedNode");
|
|
rootNode.attachChild(instancedNode);
|
|
rootNode.attachChild(instancedNode);
|
|
|
|
|
|
- box = new Geometry("PBRLightingBox", new Box(0.5f, 0.5f, 0.5f));
|
|
|
|
- Material pbrLightingMaterial = new Material(assetManager, "Common/MatDefs/Light/PBRLighting.j3md");
|
|
|
|
- pbrLightingMaterial.setBoolean("UseInstancing", true);
|
|
|
|
- pbrLightingMaterial.setColor("BaseColor", ColorRGBA.Red);
|
|
|
|
- box.setMaterial(pbrLightingMaterial);
|
|
|
|
|
|
+ Box mesh = new Box(0.5f, 0.5f, 0.5f);
|
|
|
|
+ box = new Geometry("Box", mesh);
|
|
|
|
+ Material pbrMaterial = createPbrMaterial(ColorRGBA.Red);
|
|
|
|
+ box.setMaterial(pbrMaterial);
|
|
|
|
|
|
instancedNode.attachChild(box);
|
|
instancedNode.attachChild(box);
|
|
instancedNode.instance();
|
|
instancedNode.instance();
|
|
|
|
|
|
- pointLight = new PointLight();
|
|
|
|
- pointLight.setColor(ColorRGBA.White);
|
|
|
|
- pointLight.setRadius(10f);
|
|
|
|
- rootNode.addLight(pointLight);
|
|
|
|
-
|
|
|
|
- box.setLocalTranslation(new Vector3f(offset, 0, 0));
|
|
|
|
- pointLight.setPosition(new Vector3f(offset - 3f, 0, 0));
|
|
|
|
|
|
+ DirectionalLight light = new DirectionalLight();
|
|
|
|
+ light.setDirection(new Vector3f(-1, -2, -3).normalizeLocal());
|
|
|
|
+ rootNode.addLight(light);
|
|
|
|
+ }
|
|
|
|
|
|
- cam.setLocation(new Vector3f(offset - 5f, 0, 0));
|
|
|
|
- cam.lookAtDirection(Vector3f.UNIT_X, Vector3f.UNIT_Y);
|
|
|
|
|
|
+ private Material createPbrMaterial(ColorRGBA color) {
|
|
|
|
+ Material mat = new Material(assetManager, "Common/MatDefs/Light/PBRLighting.j3md");
|
|
|
|
+ mat.setColor("BaseColor", color);
|
|
|
|
+ mat.setFloat("Roughness", 0.8f);
|
|
|
|
+ mat.setFloat("Metallic", 0.1f);
|
|
|
|
+ mat.setBoolean("UseInstancing", true);
|
|
|
|
+ return mat;
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ private void configureCamera() {
|
|
|
|
+ flyCam.setMoveSpeed(15f);
|
|
|
|
+ flyCam.setDragToRotate(true);
|
|
|
|
|
|
|
|
+ cam.setLocation(Vector3f.UNIT_XYZ.mult(12));
|
|
|
|
+ cam.lookAt(Vector3f.ZERO, Vector3f.UNIT_Y);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private BitmapText createLabelText(int x, int y, String text) {
|
|
|
|
+ BitmapText bmp = new BitmapText(guiFont);
|
|
|
|
+ bmp.setText(text);
|
|
|
|
+ bmp.setLocalTranslation(x, settings.getHeight() - y, 0);
|
|
|
|
+ bmp.setColor(ColorRGBA.Red);
|
|
|
|
+ guiNode.attachChild(bmp);
|
|
|
|
+ return bmp;
|
|
|
|
+ }
|
|
|
|
+
|
|
@Override
|
|
@Override
|
|
public void simpleUpdate(float tpf) {
|
|
public void simpleUpdate(float tpf) {
|
|
- offset += tpf;
|
|
|
|
-
|
|
|
|
- System.err.println(offset);
|
|
|
|
- box.setLocalTranslation(new Vector3f(offset, 0, 0));
|
|
|
|
- pointLight.setPosition(new Vector3f(offset - 3f, 0, 0));
|
|
|
|
-
|
|
|
|
- cam.setLocation(new Vector3f(offset - 5f, 0, 0));
|
|
|
|
- cam.lookAtDirection(Vector3f.UNIT_X, Vector3f.UNIT_Y);
|
|
|
|
|
|
+ pos += tpf * vel;
|
|
|
|
+ if (pos < -10f || pos > 10f) {
|
|
|
|
+ vel *= -1;
|
|
|
|
+ }
|
|
|
|
+ box.setLocalTranslation(pos, 0f, 0f);
|
|
|
|
+ bmp.setText(String.format(Locale.ENGLISH, "BoxPosition: (%.2f, %.1f, %.1f)", pos, 0f, 0f));
|
|
}
|
|
}
|
|
-}
|
|
|
|
|
|
+
|
|
|
|
+}
|