Search code examples
javafxlighting

JavaFX: Illuminate object from inside


I'm making a little model solar system, and trying to learn the finer points of lighting. The sun is modeled as a sphere with a diffuse map texture I found, and I added a PointLight to its center. It illuminates the other planets very nicely, but the sun itself is dark. What's the right way to make an object appear radiant and not just reflective?


Solution

  • Of course I found an answer RIGHT after posting. The key is the setSelfIlluminationMap method in PhongMaterial:

    private static Sphere buildGlowingPlanet(double radius, Image diffuseMap, Image selfIlluminationMap) {
    
        Sphere planet = new Sphere(radius);
    
        PhongMaterial planetMaterial = new PhongMaterial();
        planetMaterial.setDiffuseMap(diffuseMap);
        planetMaterial.setSelfIlluminationMap(selfIlluminationMap);
    
        planet.setMaterial(planetMaterial);
    
        return planet;
    }
    

    It would be nice if there was a way to just make the illumination be a solid color, but you could just use a blank white image for that.