com.jme3.light.SpotLight Java Examples

The following examples show how to use com.jme3.light.SpotLight. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: LightPropertyBuilder.java    From jmonkeybuilder with Apache License 2.0 6 votes vote down vote up
@Override
@FxThread
protected void buildForImpl(@NotNull final Object object, @Nullable final Object parent, @NotNull final VBox container,
                            @NotNull final ModelChangeConsumer changeConsumer) {

    if (object instanceof DirectionalLight) {
        buildForDirectionLight((DirectionalLight) object, container, changeConsumer);
    } else if (object instanceof SpotLight) {
        buildForSpotLight((SpotLight) object, container, changeConsumer);
    } else if (object instanceof PointLight) {
        buildForPointLight((PointLight) object, container, changeConsumer);
    }

    if (object instanceof Light) {
        buildForLight((Light) object, container, changeConsumer);
    }
}
 
Example #2
Source File: LightControl.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 6 votes vote down vote up
private void spatialTolight(Light light) {
    if (light instanceof PointLight) {
        ((PointLight) light).setPosition(spatial.getWorldTranslation());
    }
    TempVars vars = TempVars.get();

    if (light instanceof DirectionalLight) {
        ((DirectionalLight) light).setDirection(vars.vect1.set(spatial.getWorldTranslation()).multLocal(-1.0f));
    }

    if (light instanceof SpotLight) {
        ((SpotLight) light).setPosition(spatial.getWorldTranslation());            
        ((SpotLight) light).setDirection(spatial.getWorldRotation().multLocal(vars.vect1.set(Vector3f.UNIT_Y).multLocal(-1)));
    }
    vars.release();

}
 
Example #3
Source File: TestSpotLightTerrain.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 6 votes vote down vote up
@Override
public void simpleInitApp() {  
    makeTerrain();
    flyCam.setMoveSpeed(50);

    sl = new SpotLight();
    sl.setSpotRange(100);
    sl.setSpotOuterAngle(20 * FastMath.DEG_TO_RAD);
    sl.setSpotInnerAngle(15 * FastMath.DEG_TO_RAD);
    sl.setDirection(new Vector3f(-0.39820394f, -0.73094344f, 0.55421597f));
    sl.setPosition(new Vector3f(-64.61567f, -87.615425f, -202.41328f));
    rootNode.addLight(sl);

    AmbientLight ambLight = new AmbientLight();
    ambLight.setColor(new ColorRGBA(0.8f, 0.8f, 0.8f, 0.2f));
    rootNode.addLight(ambLight);

    cam.setLocation(new Vector3f(-41.219646f, -84.8363f, -171.67267f));
    cam.setRotation(new Quaternion(-0.04562731f, 0.89917684f, -0.09668826f, -0.4243236f));
    sl.setDirection(cam.getDirection());
    sl.setPosition(cam.getLocation());

}
 
Example #4
Source File: LightControl.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
private void spatialToLight(Light light) {

        final Vector3f worldTranslation = spatial.getWorldTranslation();

        if (light instanceof PointLight) {
            ((PointLight) light).setPosition(worldTranslation);
            return;
        }

        final TempVars vars = TempVars.get();
        final Vector3f vec = vars.vect1;

        if (light instanceof DirectionalLight) {
            ((DirectionalLight) light).setDirection(vec.set(worldTranslation).multLocal(-1.0f));
        }

        if (light instanceof SpotLight) {
            final SpotLight spotLight = (SpotLight) light;
            spotLight.setPosition(worldTranslation);
            spotLight.setDirection(spatial.getWorldRotation().multLocal(vec.set(Vector3f.UNIT_Y).multLocal(-1)));
        }

        vars.release();
    }
 
Example #5
Source File: TestSpotLightTerrain.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Override
public void simpleInitApp() {  
    makeTerrain();
    flyCam.setMoveSpeed(50);

    sl = new SpotLight();
    sl.setSpotRange(100);
    sl.setSpotOuterAngle(20 * FastMath.DEG_TO_RAD);
    sl.setSpotInnerAngle(15 * FastMath.DEG_TO_RAD);
    sl.setDirection(new Vector3f(-0.39820394f, -0.73094344f, 0.55421597f));
    sl.setPosition(new Vector3f(-64.61567f, -87.615425f, -202.41328f));
    rootNode.addLight(sl);

    AmbientLight ambLight = new AmbientLight();
    ambLight.setColor(ColorRGBA.Black);
    rootNode.addLight(ambLight);

    cam.setLocation(new Vector3f(-41.219646f, 0.8363f, -171.67267f));
    cam.setRotation(new Quaternion(-0.04562731f, 0.89917684f, -0.09668826f, -0.4243236f));
    sl.setDirection(cam.getDirection());
    sl.setPosition(cam.getLocation());

}
 
Example #6
Source File: JmeSpotLight.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 6 votes vote down vote up
@Override
protected Sheet createSheet() {
    //TODO: multithreading..
    Sheet sheet = super.createSheet();
    Sheet.Set set = Sheet.createPropertiesSet();
    set.setDisplayName("SpotLight");
    set.setName(SpotLight.class.getName());
    SpotLight obj = spotLight;
    if (obj == null) {
        return sheet;
    }

    createFields(SpotLight.class, set, obj);

    sheet.put(set);
    return sheet;

}
 
Example #7
Source File: TestJaime.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public void setupLights() {
    AmbientLight al = new AmbientLight();
    al.setColor(new ColorRGBA(0.1f, 0.1f, 0.1f, 1));
    rootNode.addLight(al);
    
    SpotLight sl = new SpotLight();
    sl.setColor(ColorRGBA.White.mult(1.0f));
    sl.setPosition(new Vector3f(1.2074411f, 10.6868908f, 4.1489987f));
    sl.setDirection(sl.getPosition().mult(-1)); 
    sl.setSpotOuterAngle(0.1f);
    sl.setSpotInnerAngle(0.004f);      
    rootNode.addLight(sl);
    
    //pointlight to fake indirect light coming from the ground
    PointLight pl = new PointLight();
    pl.setColor(ColorRGBA.White.mult(1.5f));
    pl.setPosition(new Vector3f(0, 0, 1));
    pl.setRadius(2);
    rootNode.addLight(pl);
    
    SpotLightShadowRenderer shadows = new SpotLightShadowRenderer(assetManager, 1024);
    shadows.setLight(sl);
    shadows.setShadowIntensity(0.3f);
    shadows.setEdgeFilteringMode(EdgeFilteringMode.PCF8);
    viewPort.addProcessor(shadows);

    
    FilterPostProcessor fpp = new FilterPostProcessor(assetManager);
    SSAOFilter filter = new SSAOFilter(0.10997847f,0.440001f,0.39999998f,-0.008000026f);;
    fpp.addFilter(filter);
    fpp.addFilter(new FXAAFilter());
    fpp.addFilter(new FXAAFilter());     
    
    viewPort.addProcessor(fpp);
}
 
Example #8
Source File: SceneLoader.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private void parseLightSpotLightRange(Attributes attribs) throws SAXException {
    checkTopNode("light");

    float outer = SAXUtil.parseFloat(attribs.getValue("outer"));
    float inner = SAXUtil.parseFloat(attribs.getValue("inner"));

    if (!(light instanceof SpotLight)) {
        throw new SAXException("dotScene parse error: spotLightRange "
                + "can only appear under 'spot' light elements");
    }

    SpotLight sl = (SpotLight) light;
    sl.setSpotInnerAngle(inner * 0.5f);
    sl.setSpotOuterAngle(outer * 0.5f);
}
 
Example #9
Source File: SceneLoader.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private void parseLightAttenuation(Attributes attribs) throws SAXException {
    // NOTE: Derives range based on "linear" if it is used solely
    // for the attenuation. Otherwise derives it from "range"
    checkTopNode("light");

    if (light instanceof PointLight || light instanceof SpotLight) {
        float range = parseFloat(attribs.getValue("range"));
        float constant = parseFloat(attribs.getValue("constant"));
        float linear = parseFloat(attribs.getValue("linear"));

        String quadraticStr = attribs.getValue("quadratic");
        if (quadraticStr == null) {
            quadraticStr = attribs.getValue("quadric");
        }

        float quadratic = parseFloat(quadraticStr);

        if (constant == 1 && quadratic == 0 && linear > 0) {
            range = 1f / linear;
        }

        if (light instanceof PointLight) {
            ((PointLight) light).setRadius(range);
        } else {
            ((SpotLight) light).setSpotRange(range);
        }
    }
}
 
Example #10
Source File: SceneLoader.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private void parseLightNormal(Attributes attribs) throws SAXException {
    checkTopNode("light");

    // SpotLight will be supporting a direction-normal, too.
    if (light instanceof DirectionalLight) {
        ((DirectionalLight) light).setDirection(parseVector3(attribs));
    } else if (light instanceof SpotLight) {
        ((SpotLight) light).setDirection(parseVector3(attribs));
    }
}
 
Example #11
Source File: TestSpotLight.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public void setupLighting(){
      AmbientLight al=new AmbientLight();
      al.setColor(ColorRGBA.White.mult(0.8f));
      rootNode.addLight(al);
        
      spot=new SpotLight();
      
      spot.setSpotRange(1000);
      spot.setSpotInnerAngle(5*FastMath.DEG_TO_RAD);
      spot.setSpotOuterAngle(10*FastMath.DEG_TO_RAD);
      spot.setPosition(new Vector3f(77.70334f, 34.013165f, 27.1017f));
      spot.setDirection(lightTarget.subtract(spot.getPosition()));     
      spot.setColor(ColorRGBA.White.mult(2));
      rootNode.addLight(spot);
      
      
//        PointLight pl=new PointLight();
//      pl.setPosition(new Vector3f(77.70334f, 34.013165f, 27.1017f));
//      pl.setRadius(1000);     
//      pl.setColor(ColorRGBA.White.mult(2));
//      rootNode.addLight(pl);
       lightMdl = new Geometry("Light", new Sphere(10, 10, 0.1f));
      lightMdl.setMaterial(assetManager.loadMaterial("Common/Materials/RedColor.j3m"));
      lightMdl.setLocalTranslation(new Vector3f(77.70334f, 34.013165f, 27.1017f));
      lightMdl.setLocalScale(5);
      rootNode.attachChild(lightMdl);
        
//        DirectionalLight dl = new DirectionalLight();
//        dl.setDirection(lightTarget.subtract(new Vector3f(77.70334f, 34.013165f, 27.1017f)));
//        dl.setColor(ColorRGBA.White.mult(2));
//        rootNode.addLight(dl);
      
      
    }
 
Example #12
Source File: SceneComposerToolController.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
/**
 * Adds a marker for the light to the scene if it does not exist yet
 */
public void addLightMarker(Light light) {
    if (!(light instanceof PointLight) && !(light instanceof SpotLight))
        return; // only handle point and spot lights
    
    Spatial s = nonSpatialMarkersNode.getChild(light.getName());
    if (s != null) {
        // update location maybe? Remove old and replace with new?
        return;
    }
    
    LightMarker lm = new LightMarker(light);
    nonSpatialMarkersNode.attachChild(lm);
}
 
Example #13
Source File: SpotLightShadowRenderer.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public void read(JmeImporter im) throws IOException {
    super.read(im);
    InputCapsule ic = im.getCapsule(this);
    zFarOverride = ic.readInt("zFarOverride", 0);
    light = (SpotLight) ic.readSavable("light", null);
    fadeInfo = (Vector2f) ic.readSavable("fadeInfo", null);
    fadeLength = ic.readFloat("fadeLength", 0f);
    init((int) shadowMapSize);

}
 
Example #14
Source File: SceneComposerToolController.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Override
public void setLocalTranslation(Vector3f location) {
    super.setLocalTranslation(location);
    if (light instanceof PointLight)
        ((PointLight)light).setPosition(location);
    else if (light instanceof SpotLight)
        ((SpotLight)light).setPosition(location);
}
 
Example #15
Source File: SceneComposerToolController.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Override
public void setLocalTranslation(float x, float y, float z) {
    super.setLocalTranslation(x, y, z);
    if (light instanceof PointLight)
        ((PointLight)light).setPosition(new Vector3f(x,y,z));
    else if (light instanceof SpotLight)
        ((SpotLight)light).setPosition(new Vector3f(x,y,z));
}
 
Example #16
Source File: StaticPassLightingLogic.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public Shader makeCurrent(AssetManager assetManager, RenderManager renderManager,
        EnumSet<Caps> rendererCaps, LightList lights, DefineList defines) {

    // TODO: if it ever changes that render isn't called
    // right away with the same geometry after makeCurrent, it would be
    // a problem.
    // Do a radix sort.
    tempDirLights.clear();
    tempPointLights.clear();
    tempSpotLights.clear();
    for (Light light : lights) {
        switch (light.getType()) {
            case Directional:
                tempDirLights.add((DirectionalLight) light);
                break;
            case Point:
                tempPointLights.add((PointLight) light);
                break;
            case Spot:
                tempSpotLights.add((SpotLight) light);
                break;
        }
    }

    defines.set(numDirLightsDefineId, tempDirLights.size());
    defines.set(numPointLightsDefineId, tempPointLights.size());
    defines.set(numSpotLightsDefineId, tempSpotLights.size());

    return techniqueDef.getShader(assetManager, rendererCaps, defines);
}
 
Example #17
Source File: SpotLightTreeNode.java    From jmonkeybuilder with Apache License 2.0 5 votes vote down vote up
@Override
@FromAnyThread
public @NotNull String getName() {
    final SpotLight element = getElement();
    final String name = element.getName();
    return StringUtils.isEmpty(name) ? Messages.MODEL_FILE_EDITOR_NODE_SPOT_LIGHT : name;
}
 
Example #18
Source File: SceneLoader.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private void parseLightSpotLightRange(Attributes attribs) throws SAXException {
    checkTopNode("light");

    float outer = SAXUtil.parseFloat(attribs.getValue("outer"));
    float inner = SAXUtil.parseFloat(attribs.getValue("inner"));

    if (!(light instanceof SpotLight)) {
        throw new SAXException("dotScene parse error: spotLightRange "
                + "can only appear under 'spot' light elements");
    }

    SpotLight sl = (SpotLight) light;
    sl.setSpotInnerAngle(inner * 0.5f);
    sl.setSpotOuterAngle(outer * 0.5f);
}
 
Example #19
Source File: SceneLoader.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private void parseLightAttenuation(Attributes attribs) throws SAXException {
    // NOTE: Derives range based on "linear" if it is used solely
    // for the attenuation. Otherwise derives it from "range"
    checkTopNode("light");

    if (light instanceof PointLight || light instanceof SpotLight) {
        float range = parseFloat(attribs.getValue("range"));
        float constant = parseFloat(attribs.getValue("constant"));
        float linear = parseFloat(attribs.getValue("linear"));

        String quadraticStr = attribs.getValue("quadratic");
        if (quadraticStr == null) {
            quadraticStr = attribs.getValue("quadric");
        }

        float quadratic = parseFloat(quadraticStr);

        if (constant == 1 && quadratic == 0 && linear > 0) {
            range = 1f / linear;
        }

        if (light instanceof PointLight) {
            ((PointLight) light).setRadius(range);
        } else {
            ((SpotLight) light).setSpotRange(range);
        }
    }
}
 
Example #20
Source File: SceneLoader.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private void parseLightNormal(Attributes attribs) throws SAXException {
    checkTopNode("light");

    // SpotLight will be supporting a direction-normal, too.
    if (light instanceof DirectionalLight) {
        ((DirectionalLight) light).setDirection(parseVector3(attribs));
    } else if (light instanceof SpotLight) {
        ((SpotLight) light).setDirection(parseVector3(attribs));
    }
}
 
Example #21
Source File: SceneComposerToolController.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Override
protected void controlUpdate(float f) {
    super.controlUpdate(f);
    LightMarker marker = (LightMarker) getSpatial();
    if (marker != null) {
        if (marker.getLight() instanceof PointLight) {
            marker.setLocalTranslation(((PointLight)marker.getLight()).getPosition());
        } else if (marker.getLight() instanceof SpotLight) {
            marker.setLocalTranslation(((SpotLight)marker.getLight()).getPosition());
        }
    }
}
 
Example #22
Source File: CreateSpotLightAction.java    From jmonkeybuilder with Apache License 2.0 5 votes vote down vote up
@Override
@FxThread
protected @NotNull Light createLight() {
    final SpotLight spotLight = new SpotLight();
    spotLight.setName(Messages.MODEL_NODE_TREE_ACTION_SPOT_LIGHT);
    return spotLight;
}
 
Example #23
Source File: TestSpotLight.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public void setupLighting(){
      AmbientLight al=new AmbientLight();
      al.setColor(ColorRGBA.White.mult(0.02f));
      rootNode.addLight(al);
        
      spot=new SpotLight();
      
      spot.setSpotRange(1000);
      spot.setSpotInnerAngle(5*FastMath.DEG_TO_RAD);
      spot.setSpotOuterAngle(10*FastMath.DEG_TO_RAD);
      spot.setPosition(new Vector3f(77.70334f, 34.013165f, 27.1017f));
      spot.setDirection(lightTarget.subtract(spot.getPosition()));     
      spot.setColor(ColorRGBA.White.mult(2));
      rootNode.addLight(spot);
      
      
//        PointLight pl=new PointLight();
//      pl.setPosition(new Vector3f(77.70334f, 34.013165f, 27.1017f));
//      pl.setRadius(1000);     
//      pl.setColor(ColorRGBA.White.mult(2));
//      rootNode.addLight(pl);
       lightMdl = new Geometry("Light", new Sphere(10, 10, 0.1f));
      lightMdl.setMaterial(assetManager.loadMaterial("Common/Materials/RedColor.j3m"));
      lightMdl.setLocalTranslation(new Vector3f(77.70334f, 34.013165f, 27.1017f));
      lightMdl.setLocalScale(5);
      rootNode.attachChild(lightMdl);
        
//        DirectionalLight dl = new DirectionalLight();
//        dl.setDirection(lightTarget.subtract(new Vector3f(77.70334f, 34.013165f, 27.1017f)));
//        dl.setColor(ColorRGBA.White.mult(2));
//        rootNode.addLight(dl);
      
      
    }
 
Example #24
Source File: NewLightPopup.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public void actionPerformed(ActionEvent e) {
    SceneApplication.getApplication().enqueue(new Callable<Void>() {

        public Void call() throws Exception {
            SpotLight light = new SpotLight();
            light.setColor(ColorRGBA.White);
             node.addLight(light);
            addLightUndo(node, light);
            setModified();
            return null;
        }
    });
}
 
Example #25
Source File: Material.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 4 votes vote down vote up
/**
 * Uploads the lights in the light list as two uniform arrays.<br/><br/>
 *      * <p>
 * <code>uniform vec4 g_LightColor[numLights];</code><br/>
 * // g_LightColor.rgb is the diffuse/specular color of the light.<br/>
 * // g_Lightcolor.a is the type of light, 0 = Directional, 1 = Point, <br/>
 * // 2 = Spot. <br/>
 * <br/>
 * <code>uniform vec4 g_LightPosition[numLights];</code><br/>
 * // g_LightPosition.xyz is the position of the light (for point lights)<br/>
 * // or the direction of the light (for directional lights).<br/>
 * // g_LightPosition.w is the inverse radius (1/r) of the light (for attenuation) <br/>
 * </p>
 */
protected void updateLightListUniforms(Shader shader, Geometry g, int numLights) {
    if (numLights == 0) { // this shader does not do lighting, ignore.
        return;
    }

    LightList lightList = g.getWorldLightList();
    Uniform lightColor = shader.getLightColorUniform();
    Uniform lightPos = shader.getLightPositionUniform();
    Uniform lightDir = shader.getLightDirectionUniform();
    lightColor.setVector4Length(numLights);
    lightPos.setVector4Length(numLights);
    lightDir.setVector4Length(numLights);

    Uniform ambientColor = shader.getAmbientColorUniform();
    ambientColor.setValue(VarType.Vector4, getAmbientColor(lightList));

    int lightIndex = 0;

    for (int i = 0; i < numLights; i++) {
        if (lightList.size() <= i) {
            lightColor.setVector4InArray(0f, 0f, 0f, 0f, lightIndex);
            lightPos.setVector4InArray(0f, 0f, 0f, 0f, lightIndex);
        } else {
            Light l = lightList.get(i);
            ColorRGBA color = l.getColor();
            lightColor.setVector4InArray(color.getRed(),
                    color.getGreen(),
                    color.getBlue(),
                    l.getType().getId(),
                    i);

            switch (l.getType()) {
                case Directional:
                    DirectionalLight dl = (DirectionalLight) l;
                    Vector3f dir = dl.getDirection();
                    lightPos.setVector4InArray(dir.getX(), dir.getY(), dir.getZ(), -1, lightIndex);
                    break;
                case Point:
                    PointLight pl = (PointLight) l;
                    Vector3f pos = pl.getPosition();
                    float invRadius = pl.getInvRadius();
                    lightPos.setVector4InArray(pos.getX(), pos.getY(), pos.getZ(), invRadius, lightIndex);
                    break;
                case Spot:
                    SpotLight sl = (SpotLight) l;
                    Vector3f pos2 = sl.getPosition();
                    Vector3f dir2 = sl.getDirection();
                    float invRange = sl.getInvSpotRange();
                    float spotAngleCos = sl.getPackedAngleCos();

                    lightPos.setVector4InArray(pos2.getX(), pos2.getY(), pos2.getZ(), invRange, lightIndex);
                    lightDir.setVector4InArray(dir2.getX(), dir2.getY(), dir2.getZ(), spotAngleCos, lightIndex);
                    break;
                case Ambient:
                    // skip this light. Does not increase lightIndex
                    continue;
                default:
                    throw new UnsupportedOperationException("Unknown type of light: " + l.getType());
            }
        }

        lightIndex++;
    }

    while (lightIndex < numLights) {
        lightColor.setVector4InArray(0f, 0f, 0f, 0f, lightIndex);
        lightPos.setVector4InArray(0f, 0f, 0f, 0f, lightIndex);

        lightIndex++;
    }
}
 
Example #26
Source File: JmeSpotLight.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public Class getExplorerObjectClass() {
    return SpotLight.class;
}
 
Example #27
Source File: JmeSpotLight.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public JmeSpotLight(Spatial spatial, SpotLight spotLight) {
    super(spatial, spotLight);
    this.spotLight = spotLight;
    lookupContents.add(spotLight);
    setName("SpotLight");
}
 
Example #28
Source File: LightPropertyBuilder.java    From jmonkeybuilder with Apache License 2.0 4 votes vote down vote up
@FxThread
private void buildForSpotLight(@NotNull final SpotLight light, @NotNull final VBox container,
                               @NotNull final ModelChangeConsumer changeConsumer) {

    final Vector3f direction = light.getDirection().clone();
    final Vector3f position = light.getPosition().clone();

    final float innerAngle = light.getSpotInnerAngle();
    final float outerAngle = light.getSpotOuterAngle();
    final float range = light.getSpotRange();

    final DirectionLightPropertyControl<SpotLight> directionControl =
            new DirectionLightPropertyControl<>(direction, Messages.MODEL_PROPERTY_DIRECTION, changeConsumer);
    directionControl.setApplyHandler(SpotLight::setDirection);
    directionControl.setSyncHandler(SpotLight::getDirection);
    directionControl.setEditObject(light);

    final Vector3fPropertyControl<ModelChangeConsumer, SpotLight> positionControl =
            new Vector3fPropertyControl<>(position, Messages.MODEL_PROPERTY_LOCATION, changeConsumer);
    positionControl.setApplyHandler(SpotLight::setPosition);
    positionControl.setSyncHandler(SpotLight::getPosition);
    positionControl.setEditObject(light);

    final FloatPropertyControl<ModelChangeConsumer, SpotLight> rangeControl =
            new FloatPropertyControl<>(range, Messages.MODEL_PROPERTY_RADIUS, changeConsumer);
    rangeControl.setApplyHandler(SpotLight::setSpotRange);
    rangeControl.setSyncHandler(SpotLight::getSpotRange);
    rangeControl.setMinMax(0, Integer.MAX_VALUE);
    rangeControl.setEditObject(light);

    final FloatPropertyControl<ModelChangeConsumer, SpotLight> innerAngleControl =
            new FloatPropertyControl<>(innerAngle, Messages.MODEL_PROPERTY_INNER_ANGLE, changeConsumer);
    innerAngleControl.setApplyHandler(SpotLight::setSpotInnerAngle);
    innerAngleControl.setSyncHandler(SpotLight::getSpotInnerAngle);
    innerAngleControl.setMinMax(0F, FastMath.HALF_PI);
    innerAngleControl.setScrollPower(1F);
    innerAngleControl.setEditObject(light);

    final FloatPropertyControl<ModelChangeConsumer, SpotLight> outerAngleControl =
            new FloatPropertyControl<>(outerAngle, Messages.MODEL_PROPERTY_OUTER_ANGLE, changeConsumer);
    outerAngleControl.setApplyHandler(SpotLight::setSpotOuterAngle);
    outerAngleControl.setSyncHandler(SpotLight::getSpotOuterAngle);
    outerAngleControl.setMinMax(0F, FastMath.HALF_PI);
    outerAngleControl.setScrollPower(1F);
    outerAngleControl.setEditObject(light);

    FXUtils.addToPane(directionControl, container);
    FXUtils.addToPane(positionControl, container);
    buildSplitLine(container);
    FXUtils.addToPane(rangeControl, container);
    FXUtils.addToPane(innerAngleControl, container);
    FXUtils.addToPane(outerAngleControl, container);
}
 
Example #29
Source File: TestShadowBug.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
public void simpleInitApp() {
  flyCam.setMoveSpeed(100f);
  rootNode.attachChild(makeFloor());

  Node characters = new Node("Characters");
  characters.setShadowMode(ShadowMode.Cast);
  rootNode.attachChild(characters);

  Spatial golem = assetManager.loadModel("Models/Oto/Oto.mesh.xml");
  golem.scale(0.5f);
  golem.setLocalTranslation(200.0f, -6f, 200f);
  golem.setShadowMode(ShadowMode.CastAndReceive);
  characters.attachChild(golem);

  DirectionalLight sun = new DirectionalLight();
  sun.setDirection(new Vector3f(-1f, -1f, 1f));
  sun.setColor(ColorRGBA.White.mult(1.3f));
  rootNode.addLight(sun);
  characters.addLight(sun);

  SpotLight spot = new SpotLight();
  spot.setSpotRange(13f);                           // distance
  spot.setSpotInnerAngle(15f * FastMath.DEG_TO_RAD); // inner light cone (central beam)
  spot.setSpotOuterAngle(20f * FastMath.DEG_TO_RAD); // outer light cone (edge of the light)
  spot.setColor(ColorRGBA.White.mult(1.3f));         // light color
  spot.setPosition(new Vector3f(192.0f, -1f, 192f));
  spot.setDirection(new Vector3f(1, -0.5f, 1));
  rootNode.addLight(spot);

  PointLight lamp_light = new PointLight();
  lamp_light.setColor(ColorRGBA.Yellow);
  lamp_light.setRadius(20f);
  lamp_light.setPosition(new Vector3f(210.0f, 0f, 210f));
  rootNode.addLight(lamp_light);

  SpotLightShadowRenderer slsr = new SpotLightShadowRenderer(assetManager, 512);
  slsr.setLight(spot);
  slsr.setEdgeFilteringMode(EdgeFilteringMode.Nearest);
  slsr.setShadowIntensity(0.6f);
  viewPort.addProcessor(slsr);

  PointLightShadowRenderer plsr = new PointLightShadowRenderer(assetManager, 512);
  plsr.setLight(lamp_light);
  plsr.setShadowIntensity(0.6f);
  plsr.setEdgeFilteringMode(EdgeFilteringMode.Nearest);
  viewPort.addProcessor(plsr);

  viewPort.getCamera().setLocation(new Vector3f(192.0f, 10f, 192f));
  float[] angles = new float[]{3.14f/2, 3.14f/2, 0};
  viewPort.getCamera().setRotation(new Quaternion(angles));
}
 
Example #30
Source File: TestSpotLightShadows.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
public void setupLighting() {
        AmbientLight al = new AmbientLight();
        al.setColor(ColorRGBA.White.mult(0.02f));
        rootNode.addLight(al);

        rootNode.setShadowMode(ShadowMode.CastAndReceive);

        spot = new SpotLight();

        spot.setSpotRange(1000);
        spot.setSpotInnerAngle(5f * FastMath.DEG_TO_RAD);
        spot.setSpotOuterAngle(10 * FastMath.DEG_TO_RAD);
        spot.setPosition(new Vector3f(70.70334f, 34.013165f, 27.1017f));
        spot.setDirection(lightTarget.subtract(spot.getPosition()).normalizeLocal());
        spot.setColor(ColorRGBA.White.mult(2));
        rootNode.addLight(spot);


//        PointLight pl=new PointLight();
//      pl.setPosition(new Vector3f(77.70334f, 34.013165f, 27.1017f));
//      pl.setRadius(1000);     
//      pl.setColor(ColorRGBA.White.mult(2));
//      rootNode.addLight(pl);
        lightMdl = new Geometry("Light", new Sphere(10, 10, 0.1f));
        lightMdl.setMaterial(assetManager.loadMaterial("Common/Materials/RedColor.j3m"));
        lightMdl.setLocalTranslation(new Vector3f(77.70334f, 34.013165f, 27.1017f));
        lightMdl.setLocalScale(5);
        rootNode.attachChild(lightMdl);

//        DirectionalLight dl = new DirectionalLight();
//        dl.setDirection(lightTarget.subtract(new Vector3f(77.70334f, 34.013165f, 27.1017f)));
//        dl.setColor(ColorRGBA.White.mult(0.7f));
//        rootNode.addLight(dl);


        final SpotLightShadowRenderer slsr = new SpotLightShadowRenderer(assetManager, 512);
        slsr.setLight(spot);       
        slsr.setShadowIntensity(0.5f);
        slsr.setShadowZExtend(100);
        slsr.setShadowZFadeLength(5);
        slsr.setEdgeFilteringMode(EdgeFilteringMode.PCFPOISSON);   
        viewPort.addProcessor(slsr);

        SpotLightShadowFilter slsf = new SpotLightShadowFilter(assetManager, 512);
        slsf.setLight(spot);    
        slsf.setShadowIntensity(0.5f);
        slsf.setShadowZExtend(100);
        slsf.setShadowZFadeLength(5);
        slsf.setEdgeFilteringMode(EdgeFilteringMode.PCFPOISSON);  
        slsf.setEnabled(false);
        
        FilterPostProcessor fpp = new FilterPostProcessor(assetManager);
        fpp.addFilter(slsf);
        viewPort.addProcessor(fpp);
        
        ShadowTestUIManager uiMan = new ShadowTestUIManager(assetManager, slsr, slsf, guiNode, inputManager, viewPort);

        inputManager.addListener(new ActionListener() {
            @Override
            public void onAction(String name, boolean isPressed, float tpf) {
                if (name.equals("stop") && isPressed) {
                    stop = !stop;
                 //   slsr.displayFrustum();
                    System.out.println("pos : " + spot.getPosition());
                    System.out.println("dir : " + spot.getDirection());
                }
            }
        }, "stop");

        inputManager.addMapping("stop", new KeyTrigger(KeyInput.KEY_1));
        flyCam.setDragToRotate(true);
    }