use of com.jme3.light.DirectionalLight in project jmonkeyengine by jMonkeyEngine.
the class WaterFilter method initFilter.
@Override
protected void initFilter(AssetManager manager, RenderManager renderManager, ViewPort vp, int w, int h) {
if (reflectionScene == null) {
reflectionScene = vp.getScenes().get(0);
DirectionalLight l = findLight((Node) reflectionScene);
if (l != null) {
lightDirection = l.getDirection();
}
}
this.renderManager = renderManager;
this.viewPort = vp;
reflectionPass = new Pass();
reflectionPass.init(renderManager.getRenderer(), reflectionMapSize, reflectionMapSize, Format.RGBA8, Format.Depth);
reflectionCam = new Camera(reflectionMapSize, reflectionMapSize);
reflectionView = new ViewPort("reflectionView", reflectionCam);
reflectionView.setClearFlags(true, true, true);
reflectionView.attachScene(reflectionScene);
reflectionView.setOutputFrameBuffer(reflectionPass.getRenderFrameBuffer());
plane = new Plane(Vector3f.UNIT_Y, new Vector3f(0, waterHeight, 0).dot(Vector3f.UNIT_Y));
reflectionProcessor = new ReflectionProcessor(reflectionCam, reflectionPass.getRenderFrameBuffer(), plane);
reflectionProcessor.setReflectionClipPlane(plane);
reflectionView.addProcessor(reflectionProcessor);
normalTexture = (Texture2D) manager.loadTexture("Common/MatDefs/Water/Textures/water_normalmap.dds");
if (foamTexture == null) {
foamTexture = (Texture2D) manager.loadTexture("Common/MatDefs/Water/Textures/foam.jpg");
}
if (causticsTexture == null) {
causticsTexture = (Texture2D) manager.loadTexture("Common/MatDefs/Water/Textures/caustics.jpg");
}
heightTexture = (Texture2D) manager.loadTexture("Common/MatDefs/Water/Textures/heightmap.jpg");
normalTexture.setWrap(WrapMode.Repeat);
foamTexture.setWrap(WrapMode.Repeat);
causticsTexture.setWrap(WrapMode.Repeat);
heightTexture.setWrap(WrapMode.Repeat);
material = new Material(manager, "Common/MatDefs/Water/Water.j3md");
material.setTexture("HeightMap", heightTexture);
material.setTexture("CausticsMap", causticsTexture);
material.setTexture("FoamMap", foamTexture);
material.setTexture("NormalMap", normalTexture);
material.setTexture("ReflectionMap", reflectionPass.getRenderedTexture());
material.setFloat("WaterTransparency", waterTransparency);
material.setFloat("NormalScale", normalScale);
material.setFloat("R0", refractionConstant);
material.setFloat("MaxAmplitude", maxAmplitude);
material.setVector3("LightDir", lightDirection);
material.setColor("LightColor", lightColor);
material.setFloat("ShoreHardness", shoreHardness);
material.setFloat("RefractionStrength", refractionStrength);
material.setFloat("WaveScale", waveScale);
material.setVector3("FoamExistence", foamExistence);
material.setFloat("SunScale", sunScale);
material.setVector3("ColorExtinction", colorExtinction);
material.setFloat("Shininess", shininess);
material.setColor("WaterColor", waterColor);
material.setColor("DeepWaterColor", deepWaterColor);
material.setVector2("WindDirection", windDirection);
material.setFloat("FoamHardness", foamHardness);
material.setBoolean("UseRipples", useRipples);
material.setBoolean("UseHQShoreline", useHQShoreline);
material.setBoolean("UseSpecular", useSpecular);
material.setBoolean("UseFoam", useFoam);
material.setBoolean("UseCaustics", useCaustics);
material.setBoolean("UseRefraction", useRefraction);
material.setFloat("ReflectionDisplace", reflectionDisplace);
material.setFloat("FoamIntensity", foamIntensity);
material.setFloat("UnderWaterFogDistance", underWaterFogDistance);
material.setFloat("CausticsIntensity", causticsIntensity);
if (center != null) {
material.setVector3("Center", center);
material.setFloat("Radius", radius * radius);
material.setBoolean("SquareArea", shapeType == AreaShape.Square);
}
material.setFloat("WaterHeight", waterHeight);
}
use of com.jme3.light.DirectionalLight in project jmonkeyengine by jMonkeyEngine.
the class TestCameraMotionPath method createScene.
private void createScene() {
Material mat = new Material(assetManager, "Common/MatDefs/Light/Lighting.j3md");
mat.setFloat("Shininess", 1f);
mat.setBoolean("UseMaterialColors", true);
mat.setColor("Ambient", ColorRGBA.Black);
mat.setColor("Diffuse", ColorRGBA.DarkGray);
mat.setColor("Specular", ColorRGBA.White.mult(0.6f));
Material matSoil = new Material(assetManager, "Common/MatDefs/Light/Lighting.j3md");
matSoil.setBoolean("UseMaterialColors", true);
matSoil.setColor("Ambient", ColorRGBA.Gray);
matSoil.setColor("Diffuse", ColorRGBA.Gray);
matSoil.setColor("Specular", ColorRGBA.Black);
teapot = assetManager.loadModel("Models/Teapot/Teapot.obj");
teapot.setLocalScale(3);
teapot.setMaterial(mat);
rootNode.attachChild(teapot);
Geometry soil = new Geometry("soil", new Box(50, 1, 50));
soil.setLocalTranslation(0, -1, 0);
soil.setMaterial(matSoil);
rootNode.attachChild(soil);
DirectionalLight light = new DirectionalLight();
light.setDirection(new Vector3f(0, -1, 0).normalizeLocal());
light.setColor(ColorRGBA.White.mult(1.5f));
rootNode.addLight(light);
}
use of com.jme3.light.DirectionalLight in project jmonkeyengine by jMonkeyEngine.
the class TestCinematic method createScene.
private void createScene() {
model = (Spatial) assetManager.loadModel("Models/Oto/Oto.mesh.xml");
model.center();
model.setShadowMode(ShadowMode.CastAndReceive);
rootNode.attachChild(model);
Material mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
mat.setColor("Color", ColorRGBA.Cyan);
teapot = assetManager.loadModel("Models/Teapot/Teapot.obj");
teapot.setLocalTranslation(10, 0, 10);
teapot.setMaterial(mat);
teapot.setShadowMode(ShadowMode.CastAndReceive);
rootNode.attachChild(teapot);
Material matSoil = new Material(assetManager, "Common/MatDefs/Light/Lighting.j3md");
matSoil.setBoolean("UseMaterialColors", true);
matSoil.setColor("Ambient", ColorRGBA.Gray);
matSoil.setColor("Diffuse", ColorRGBA.Green);
matSoil.setColor("Specular", ColorRGBA.Black);
Geometry soil = new Geometry("soil", new Box(50, 1, 50));
soil.setLocalTranslation(0, -6, 0);
soil.setMaterial(matSoil);
soil.setShadowMode(ShadowMode.Receive);
rootNode.attachChild(soil);
DirectionalLight light = new DirectionalLight();
light.setDirection(new Vector3f(0, -1, -1).normalizeLocal());
light.setColor(ColorRGBA.White.mult(1.5f));
rootNode.addLight(light);
fpp = new FilterPostProcessor(assetManager);
fade = new FadeFilter();
fpp.addFilter(fade);
if (renderer.getCaps().contains(Caps.GLSL100)) {
PssmShadowRenderer pssm = new PssmShadowRenderer(assetManager, 512, 1);
pssm.setDirection(new Vector3f(0, -1, -1).normalizeLocal());
pssm.setShadowIntensity(0.4f);
viewPort.addProcessor(pssm);
viewPort.addProcessor(fpp);
}
}
use of com.jme3.light.DirectionalLight in project jmonkeyengine by jMonkeyEngine.
the class LightHelper method toLight.
public Light toLight(Structure structure, BlenderContext blenderContext) throws BlenderFileException {
Light result = (Light) blenderContext.getLoadedFeature(structure.getOldMemoryAddress(), LoadedDataType.FEATURE);
if (result != null) {
return result;
}
Light light = null;
int type = ((Number) structure.getFieldValue("type")).intValue();
switch(type) {
case // Lamp
0:
light = new PointLight();
float distance = ((Number) structure.getFieldValue("dist")).floatValue();
((PointLight) light).setRadius(distance);
break;
case // Sun
1:
LOGGER.log(Level.WARNING, "'Sun' lamp is not supported in jMonkeyEngine. Using PointLight with radius = Float.MAX_VALUE.");
light = new PointLight();
((PointLight) light).setRadius(Float.MAX_VALUE);
break;
case // Spot
2:
light = new SpotLight();
// range
((SpotLight) light).setSpotRange(((Number) structure.getFieldValue("dist")).floatValue());
// outer angle
float outerAngle = ((Number) structure.getFieldValue("spotsize")).floatValue() * FastMath.DEG_TO_RAD * 0.5f;
((SpotLight) light).setSpotOuterAngle(outerAngle);
// inner angle
float spotblend = ((Number) structure.getFieldValue("spotblend")).floatValue();
spotblend = FastMath.clamp(spotblend, 0, 1);
float innerAngle = outerAngle * (1 - spotblend);
((SpotLight) light).setSpotInnerAngle(innerAngle);
break;
case // Hemi
3:
LOGGER.log(Level.WARNING, "'Hemi' lamp is not supported in jMonkeyEngine. Using DirectionalLight instead.");
case // Area
4:
light = new DirectionalLight();
break;
default:
throw new BlenderFileException("Unknown light source type: " + type);
}
float r = ((Number) structure.getFieldValue("r")).floatValue();
float g = ((Number) structure.getFieldValue("g")).floatValue();
float b = ((Number) structure.getFieldValue("b")).floatValue();
light.setColor(new ColorRGBA(r, g, b, 1.0f));
light.setName(structure.getName());
return light;
}
use of com.jme3.light.DirectionalLight in project jmonkeyengine by jMonkeyEngine.
the class LightControl method lightToSpatial.
private void lightToSpatial(Light light) {
TempVars vars = TempVars.get();
if (light instanceof PointLight) {
PointLight pLight = (PointLight) light;
Vector3f vecDiff = vars.vect1.set(pLight.getPosition()).subtractLocal(spatial.getWorldTranslation());
spatial.setLocalTranslation(vecDiff.addLocal(spatial.getLocalTranslation()));
}
if (light instanceof DirectionalLight) {
DirectionalLight dLight = (DirectionalLight) light;
vars.vect1.set(dLight.getDirection()).multLocal(-1.0f);
Vector3f vecDiff = vars.vect1.subtractLocal(spatial.getWorldTranslation());
spatial.setLocalTranslation(vecDiff.addLocal(spatial.getLocalTranslation()));
}
vars.release();
//TODO add code for Spot light here when it's done
}
Aggregations