use of com.jme3.light.LightList in project jmonkeyengine by jMonkeyEngine.
the class Technique method render.
/**
* Render the technique according to its {@link TechniqueDefLogic}.
*
* @param renderManager The render manager to perform the rendering against.
* @param shader The shader that was selected in
* {@link #makeCurrent(com.jme3.renderer.RenderManager, java.util.EnumSet)}.
* @param geometry The geometry to render
* @param lights Lights which influence the geometry.
*/
void render(RenderManager renderManager, Shader shader, Geometry geometry, LightList lights, int lastTexUnit) {
TechniqueDefLogic logic = def.getLogic();
logic.render(renderManager, shader, geometry, lights, lastTexUnit);
}
use of com.jme3.light.LightList in project jmonkeyengine by jMonkeyEngine.
the class Spatial method read.
public void read(JmeImporter im) throws IOException {
InputCapsule ic = im.getCapsule(this);
name = ic.readString("name", null);
worldBound = (BoundingVolume) ic.readSavable("world_bound", null);
cullHint = ic.readEnum("cull_mode", CullHint.class, CullHint.Inherit);
batchHint = ic.readEnum("batch_hint", BatchHint.class, BatchHint.Inherit);
queueBucket = ic.readEnum("queue", RenderQueue.Bucket.class, RenderQueue.Bucket.Inherit);
shadowMode = ic.readEnum("shadow_mode", ShadowMode.class, ShadowMode.Inherit);
localTransform = (Transform) ic.readSavable("transform", Transform.IDENTITY);
localLights = (LightList) ic.readSavable("lights", null);
localLights.setOwner(this);
ArrayList<MatParamOverride> localOverridesList = ic.readSavableArrayList("overrides", null);
if (localOverridesList == null) {
localOverrides = new SafeArrayList<>(MatParamOverride.class);
} else {
localOverrides = new SafeArrayList(MatParamOverride.class, localOverridesList);
}
worldOverrides = new SafeArrayList<>(MatParamOverride.class);
//changed for backward compatibility with j3o files generated before the AnimControl/SkeletonControl split
//the AnimControl creates the SkeletonControl for old files and add it to the spatial.
//The SkeletonControl must be the last in the stack so we add the list of all other control before it.
//When backward compatibility won't be needed anymore this can be replaced by :
//controls = ic.readSavableArrayList("controlsList", null));
controls.addAll(0, ic.readSavableArrayList("controlsList", null));
userData = (HashMap<String, Savable>) ic.readStringSavableMap("user_data", null);
}
use of com.jme3.light.LightList in project jmonkeyengine by jMonkeyEngine.
the class RenderManager method renderGeometry.
/**
* Renders the given geometry.
* <p>
* First the proper world matrix is set, if
* the geometry's {@link Geometry#setIgnoreTransform(boolean) ignore transform}
* feature is enabled, the identity world matrix is used, otherwise, the
* geometry's {@link Geometry#getWorldMatrix() world transform matrix} is used.
* <p>
* Once the world matrix is applied, the proper material is chosen for rendering.
* If a {@link #setForcedMaterial(com.jme3.material.Material) forced material} is
* set on this RenderManager, then it is used for rendering the geometry,
* otherwise, the {@link Geometry#getMaterial() geometry's material} is used.
* <p>
* If a {@link #setForcedTechnique(java.lang.String) forced technique} is
* set on this RenderManager, then it is selected automatically
* on the geometry's material and is used for rendering. Otherwise, one
* of the {@link MaterialDef#getDefaultTechniques() default techniques} is
* used.
* <p>
* If a {@link #setForcedRenderState(com.jme3.material.RenderState) forced
* render state} is set on this RenderManager, then it is used
* for rendering the material, and the material's own render state is ignored.
* Otherwise, the material's render state is used as intended.
*
* @param geom The geometry to render
*
* @see Technique
* @see RenderState
* @see Material#selectTechnique(java.lang.String, com.jme3.renderer.RenderManager)
* @see Material#render(com.jme3.scene.Geometry, com.jme3.renderer.RenderManager)
*/
public void renderGeometry(Geometry geom) {
if (geom.isIgnoreTransform()) {
setWorldMatrix(Matrix4f.IDENTITY);
} else {
setWorldMatrix(geom.getWorldMatrix());
}
// Perform light filtering if we have a light filter.
LightList lightList = geom.getWorldLightList();
if (lightFilter != null) {
filteredLightList.clear();
lightFilter.filterLights(geom, filteredLightList);
lightList = filteredLightList;
}
Material material = geom.getMaterial();
//else the geom is not rendered
if (forcedTechnique != null) {
MaterialDef matDef = material.getMaterialDef();
if (matDef.getTechniqueDefs(forcedTechnique) != null) {
Technique activeTechnique = material.getActiveTechnique();
String previousTechniqueName = activeTechnique != null ? activeTechnique.getDef().getName() : TechniqueDef.DEFAULT_TECHNIQUE_NAME;
geom.getMaterial().selectTechnique(forcedTechnique, this);
//saving forcedRenderState for future calls
RenderState tmpRs = forcedRenderState;
if (geom.getMaterial().getActiveTechnique().getDef().getForcedRenderState() != null) {
//forcing forced technique renderState
forcedRenderState = geom.getMaterial().getActiveTechnique().getDef().getForcedRenderState();
}
// use geometry's material
material.render(geom, lightList, this);
material.selectTechnique(previousTechniqueName, this);
//restoring forcedRenderState
forcedRenderState = tmpRs;
//Reverted this part from revision 6197
//If forcedTechnique does not exists, and forcedMaterial is not set, the geom MUST NOT be rendered
} else if (forcedMaterial != null) {
// use forced material
forcedMaterial.render(geom, lightList, this);
}
} else if (forcedMaterial != null) {
// use forced material
forcedMaterial.render(geom, lightList, this);
} else {
material.render(geom, lightList, this);
}
}
use of com.jme3.light.LightList in project jmonkeyengine by jMonkeyEngine.
the class TestManyLightsSingle method simpleInitApp.
@Override
public void simpleInitApp() {
renderManager.setPreferredLightMode(lm);
renderManager.setSinglePassLightBatchSize(6);
flyCam.setMoveSpeed(10);
Node scene = (Node) assetManager.loadModel("Scenes/ManyLights/Main.scene");
rootNode.attachChild(scene);
Node n = (Node) rootNode.getChild(0);
final LightList lightList = n.getWorldLightList();
final Geometry g = (Geometry) n.getChild("Grid-geom-1");
g.getMaterial().setColor("Ambient", new ColorRGBA(0.2f, 0.2f, 0.2f, 1f));
/* A colored lit cube. Needs light source! */
Box boxMesh = new Box(1f, 1f, 1f);
final Geometry boxGeo = new Geometry("Colored Box", boxMesh);
Material boxMat = g.getMaterial().clone();
boxMat.clearParam("DiffuseMap");
boxMat.setBoolean("UseMaterialColors", true);
boxMat.setColor("Ambient", new ColorRGBA(0.2f, 0.2f, 0.2f, 1f));
boxMat.setColor("Diffuse", ColorRGBA.Blue);
boxGeo.setMaterial(boxMat);
final Node cubeNodes = new Node();
n.attachChild(cubeNodes);
int nb = 0;
for (Light light : lightList) {
nb++;
PointLight p = (PointLight) light;
if (nb > 60) {
n.removeLight(light);
} else {
LightNode ln = new LightNode("l", light);
n.attachChild(ln);
ln.setLocalTranslation(p.getPosition());
int rand = FastMath.nextRandomInt(0, 3);
switch(rand) {
case 0:
light.setColor(ColorRGBA.Red);
// ln.addControl(new MoveControl(5f));
break;
case 1:
light.setColor(ColorRGBA.Yellow);
// ln.addControl(new MoveControl(5f));
break;
case 2:
light.setColor(ColorRGBA.Green);
//ln.addControl(new MoveControl(-5f));
break;
case 3:
light.setColor(ColorRGBA.Orange);
//ln.addControl(new MoveControl(-5f));
break;
}
}
Geometry b = boxGeo.clone(false);
cubeNodes.attachChild(b);
b.setLocalTranslation(p.getPosition().x, 2, p.getPosition().z);
}
// cam.setLocation(new Vector3f(3.1893547f, 17.977385f, 30.8378f));
// cam.setRotation(new Quaternion(0.14317635f, 0.82302624f, -0.23777823f, 0.49557027f));
cam.setLocation(new Vector3f(-1.8901939f, 29.34097f, 73.07533f));
cam.setRotation(new Quaternion(0.0021000702f, 0.971012f, -0.23886925f, 0.008527749f));
BasicProfilerState profiler = new BasicProfilerState(true);
profiler.setGraphScale(1000f);
// getStateManager().attach(profiler);
// guiNode.setCullHint(CullHint.Always);
flyCam.setDragToRotate(true);
flyCam.setMoveSpeed(50);
final MaterialDebugAppState debug = new MaterialDebugAppState();
stateManager.attach(debug);
inputManager.addListener(new ActionListener() {
public void onAction(String name, boolean isPressed, float tpf) {
if (name.equals("toggle") && isPressed) {
if (lm == TechniqueDef.LightMode.SinglePass) {
lm = TechniqueDef.LightMode.MultiPass;
helloText.setText("(Multi pass)");
} else {
lm = TechniqueDef.LightMode.SinglePass;
helloText.setText("(Single pass) nb lights per batch : " + renderManager.getSinglePassLightBatchSize());
}
renderManager.setPreferredLightMode(lm);
reloadScene(g, boxGeo, cubeNodes);
}
if (name.equals("lightsUp") && isPressed) {
renderManager.setSinglePassLightBatchSize(renderManager.getSinglePassLightBatchSize() + 1);
helloText.setText("(Single pass) nb lights per batch : " + renderManager.getSinglePassLightBatchSize());
}
if (name.equals("lightsDown") && isPressed) {
renderManager.setSinglePassLightBatchSize(renderManager.getSinglePassLightBatchSize() - 1);
helloText.setText("(Single pass) nb lights per batch : " + renderManager.getSinglePassLightBatchSize());
}
if (name.equals("toggleOnOff") && isPressed) {
for (final Light light : lightList) {
if (light instanceof AmbientLight) {
continue;
}
light.setEnabled(!light.isEnabled());
}
}
}
}, "toggle", "lightsUp", "lightsDown", "toggleOnOff");
inputManager.addMapping("toggle", new KeyTrigger(KeyInput.KEY_SPACE));
inputManager.addMapping("lightsUp", new KeyTrigger(KeyInput.KEY_UP));
inputManager.addMapping("lightsDown", new KeyTrigger(KeyInput.KEY_DOWN));
inputManager.addMapping("toggleOnOff", new KeyTrigger(KeyInput.KEY_L));
SpotLight spot = new SpotLight();
spot.setDirection(new Vector3f(-1f, -1f, -1f).normalizeLocal());
spot.setColor(ColorRGBA.Blue.mult(5));
spot.setSpotOuterAngle(FastMath.DEG_TO_RAD * 20);
spot.setSpotInnerAngle(FastMath.DEG_TO_RAD * 5);
spot.setPosition(new Vector3f(10, 10, 20));
rootNode.addLight(spot);
DirectionalLight dl = new DirectionalLight();
dl.setDirection(new Vector3f(-1, -1, 1));
rootNode.addLight(dl);
AmbientLight al = new AmbientLight();
al.setColor(new ColorRGBA(0.2f, 0.2f, 0.2f, 1f));
rootNode.addLight(al);
/**
* Write text on the screen (HUD)
*/
guiNode.detachAllChildren();
guiFont = assetManager.loadFont("Interface/Fonts/Default.fnt");
helloText = new BitmapText(guiFont, false);
helloText.setSize(guiFont.getCharSet().getRenderedSize());
helloText.setText("(Single pass) nb lights per batch : " + renderManager.getSinglePassLightBatchSize());
helloText.setLocalTranslation(300, helloText.getLineHeight(), 0);
guiNode.attachChild(helloText);
}
Aggregations