Creating a "glowing" sphere

Hi all,
sorry for my stupid question but i’m looking now for hours to get this to work:

I want to create a simple yellow sphere, which should be used as a light source (a sun). It should look like a sun, so it needs to glow and emit light.
My goal is to create some planets which will be lighting by this sun.
I have done this, but it don’t work:

  1. Create a sphere
  2. Create a yellow material (Lighting.j3md)
  3. Create a geometry from the sphere with this material
  4. Create a PointLight and set its location to the middle of the sun geometry (The pointlight radius is bigger than the sphere)
  5. Add geometry + light to the rootNode

So my sun is invisible although i have added the point light. I think i have figured it out why i can’t see my sun: The point light is shining from the center and only shines in the outer direction, so the sun is only lighted from inner. So how can i create such a effect which i want to? Please don’t link me to some ready-to-use libs, because i want to learn how to do this in code myself.

Thank you so much!

1 Like

In this case, you don’t want your sun to be lit. You just want it to be light. So use the unshaded material instead.

1 Like

…or a glow map, might also look nice.
The content of this post is meant to be read as a straight information or question without an implicit dismissive stance or interest in having the other party feel offended unless there’s emotes that hint otherwise or there’s an increased use of exclamation marks and all-capital words.

1 Like

@normen
can you tell me more about this “glow map” and how it works?

@pspeed
my code looks like this:

[java]
// Planet sun
Sphere sunSp = new Sphere(64, 64, 5f);
Geometry sunGeo = new Geometry(“sun”, sunSp);
Material sunMat = new Material(assetManager, “Common/MatDefs/Misc/Unshaded.j3md”);
sunMat.setColor(“Color”, ColorRGBA.Yellow);
sunGeo.setMaterial(sunMat);

    // Point Light
    PointLight pointLight = new PointLight();
    pointLight.setColor(ColorRGBA.Yellow);
    pointLight.setPosition(sunGeo.getLocalTranslation().zero());
    pointLight.setRadius(100f);
    
    // Earth
    Sphere earthSp = new Sphere(64, 64, 2f);
    Geometry earthGeo = new Geometry("earth", earthSp);
    Material earthMat= new Material(assetManager, "Common/MatDefs/Light/Lighting.j3md");
    earthMat.setBoolean("UseMaterialColors", true);
    earthMat.setColor("Ambient", ColorRGBA.Blue);  // Color of the material
    earthMat.setColor("Diffuse", ColorRGBA.Blue);  // Reflected light color
    earthGeo.setMaterial(earthMat);
    earthGeo.setLocalTranslation(10f, 0, 0);
    
    rootNode.attachChild(sunGeo);       
    rootNode.attachChild(earthGeo);
    rootNode.addLight(pointLight);

[/java]

Only see the sun, but not my earth :confused:

1 Like

LOL really stupid.
If i use White instead of Yellow for my point light, it works. I think i know why: My earth material only reflects blue light, so yellow dont work.
But my next step is to let my sun “glow” and not only be a yellow sphere. How can this work? My idea is to create a little bigger sphere which will be transparent and set it to the sun, but i think that this will be too much overhead only for a simple glow. I saw the jmeplanet video, and i want to get a smooth glow like in the video. Any idea?

1 Like

You simply set the Glow color of your sun material and add a bloom filter to your scene. That’s all.
Check the tutorial, all is in there !

2 Likes

It also doesn’t hurt to have a lens flare billboard quad to punch it up even more.

1 Like

Hey ho, thanks to the tutorials i have done a glowing sphere which uses a PointLight as light source.

@pspeed
can you tell me something more about this lens flare effect and how to use it?
i can’t find a documentation for this. thx

1 Like

A billboard is a quad that always faces the camera. I think that Pspeed just suggests using some kind of picture (or even better a shader that would provide a dynamic texture) to figure a flare effect.

I’ve never seen this in the tutorials. A small search in the forum gave this : http://hub.jmonkeyengine.org/forum/topic/lens-flare-code-small-update-screens/
A “small” gem from one of our Shader gurus…

1 Like

A propos Billboards … does anyone already have a working solution? Could not find anything at the forum, and as Billboards have to get their position from scene and their localRotation from the render that is rendereing them (so they have to align different in 2 cameras viewing them), i’m not quite shure how they would be implemented…

1 Like

[java]spatial.addControl (new BillBoardControl ()); // something like this[/java]

1 Like
@wezrule said: [java]spatial.addControl (new BillBoardControl ()); // something like this[/java]

Well, i always thought this the old implementation, because a lot of rotation is involved that kills a billboards advantage: high speed. The current implementation rotates to the looking camera, but on a real billboard implementation, the render would just calculate the billboards center point and draw the 2D-Shape at calculated and scaled z-position… thats why i allways thought it has to get implemented different than other spatials. The controller seemed like a workaraound for that. But K, it a good starting point. I’ll check if just rewriting the vertexbuffers is faster.

1 Like

Yeah, just look at the billboard control already provided in jME.

1 Like
@normen said: ..or a glow map, might also look nice. The content of this post is meant to be read as a straight information or question without an implicit dismissive stance or interest in having the other party feel offended unless there's emotes that hint otherwise or there's an increased use of exclamation marks and all-capital words.

Sorry for the stupid question, but doesn’t a glow map only effect the texture? The reason I ask is… I’m very interested in how to produce the effect he/she is looking for as well. And along those lines… is it possible to apply a Bloom effect to a single object? If so, this might help the OPer get the effect they are looking for

@pspeed Cool idea with the billboarded flare =)

1 Like

\o/ my turn to RTFM \o/…
That’s almost the only doc i wrote so i won’t miss the occasion :smiley:
https://wiki.jmonkeyengine.org/legacy/doku.php/jme3:advanced:bloom_and_glow

go to “bloom with a glow map”
The thing is it’s applied to all objects having a glow map or glow color. Dunno if that’s your use case

2 Likes
@nehon said: \o/ my turn to RTFM \o/.. That's almost the only doc i wrote so i won't miss the occasion :D https://wiki.jmonkeyengine.org/legacy/doku.php/jme3:advanced:bloom_and_glow

go to “bloom with a glow map”
The thing is it’s applied to all objects having a glow map or glow color. Dunno if that’s your use case

I have been RTFM’d!

Thanks for the quick reply. Honestly, I have no specific use case yet, as this is one of those “in the back of my mind” projects… thus the not having RTFM yet =)

This is cool to hear though… I did not realize how this works and it definitely opens up possibilities!

1 Like

It has some limitations though. And one enhancement i’d like to make is to reduce the blur scale with the distance of the object to cam.
But I guess it’s good enough for some situations.

2 Likes

Hi,
i have tryed now a lot of code and i can’t get it to work how i want to.
I want a effekt like this:

But my sun looks so:

Really minimal bloom and blur effect :frowning:

Here is my code, hope anyone can help me out:

PlanetGenerator.java
[java]

/*

  • To change this template, choose Tools | Templates
  • and open the template in the editor.
    */
    package de.miroworks.wabioto;

import com.jme3.app.SimpleApplication;
import com.jme3.asset.AssetManager;
import com.jme3.light.PointLight;
import com.jme3.material.Material;
import com.jme3.material.RenderState;
import com.jme3.math.ColorRGBA;
import com.jme3.math.Vector3f;
import com.jme3.post.FilterPostProcessor;
import com.jme3.post.filters.BloomFilter;
import com.jme3.renderer.queue.RenderQueue;
import com.jme3.scene.Geometry;
import com.jme3.scene.Node;
import com.jme3.scene.control.LightControl;
import com.jme3.scene.shape.Sphere;

/**
*

  • @author miro
    */
    public class PlanetGenerator {
    private AssetManager assetManager;
    private SimpleApplication simpleApplication;

    public PlanetGenerator(SimpleApplication simpleApplication, float blurScale){
    this.simpleApplication = simpleApplication;
    this.assetManager = simpleApplication.getAssetManager();
    createBloomFilter(blurScale);
    }

    public Node createPlanetWithAtmosphere(Vector3f position, float planetRadius, float atmoRadius, ColorRGBA planetColor, ColorRGBA atmoColor){
    Node planetNode = new Node(“PlanetNode”);
    planetNode.setLocalTranslation(position);

     Geometry planet = createPlanet(position, planetRadius, planetColor);
     Geometry atmosphere = createAtmosphere(position, atmoRadius, atmoColor);
     
     planetNode.attachChild(planet);
     planetNode.attachChild(atmosphere);
     
     return planetNode;
    

    }

    private Geometry createPlanet(Vector3f position, float radius, ColorRGBA color){
    // Planet
    Sphere sp = new Sphere(64, 64, radius);
    Geometry geo = new Geometry(“Planet”, sp);
    Material mat = new Material(assetManager, “Common/MatDefs/Light/Lighting.j3md”);
    mat.setBoolean(“UseMaterialColors”, true);
    mat.setColor(“Ambient”, color);
    mat.setColor(“Diffuse”, color);
    mat.setColor(“Specular”, color);
    geo.setMaterial(mat);
    geo.setLocalTranslation(position);
    return geo;
    }

    private Geometry createAtmosphere(Vector3f position, float radius, ColorRGBA color){
    Sphere atmo = new Sphere(64, 64, radius);
    Geometry atmoGeo = new Geometry(“Atmosphere”, atmo);
    Material atmoMat = new Material(assetManager, “Common/MatDefs/Light/Lighting.j3md”);
    atmoMat.setBoolean(“UseMaterialColors”, true);
    atmoMat.setColor(“Diffuse”, color); // Make sure to use alpha channel!
    atmoMat.setBoolean(“UseAlpha”,true);
    atmoMat.getAdditionalRenderState().setBlendMode(RenderState.BlendMode.Alpha);
    atmoGeo.setMaterial(atmoMat);
    atmoGeo.setQueueBucket(RenderQueue.Bucket.Transparent);
    atmoGeo.setLocalTranslation(position);
    return atmoGeo;
    }

    private void createBloomFilter(float blurScale){
    // Bloom
    FilterPostProcessor fpp=new FilterPostProcessor(assetManager);
    BloomFilter bloom=new BloomFilter();
    bloom.setBlurScale(blurScale);
    bloom.setBloomIntensity(2f);
    bloom.setExposurePower(500f);
    bloom.setExposureCutOff(1f);
    //bloom.setDownSamplingFactor(100.0f);
    fpp.addFilter(bloom);
    simpleApplication.getViewPort().addProcessor(fpp);
    }

    public Node createSun(Vector3f position, float radius, ColorRGBA sunColor, ColorRGBA lightColor, float lightRadius){
    Node sunNode = new Node(“Sunnode”);
    sunNode.setLocalTranslation(position);

     // Sun
     Sphere sun = new Sphere(64, 64, radius);
     Geometry sunGeo = new Geometry("Sun", sun);
     Material sunMat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
     sunMat.setColor("Color", sunColor);
     sunGeo.setMaterial(sunMat);      
     
     // PointLight
     PointLight sunLight = new PointLight();
     sunLight.setColor(lightColor);
     sunLight.setRadius(lightRadius);
     //sunLight.setPosition(position);
     
     // Add light control, to let the light follow the sun
     LightControl sunLightControl = new LightControl(sunLight);
     sunGeo.addControl(sunLightControl);
     
     sunNode.attachChild(sunGeo);
     sunNode.addLight(sunLight);
     
     return sunNode;                
    

    }
    }
    [/java]

Main.java
[java]
package de.miroworks.wabioto;

import com.jme3.app.SimpleApplication;
import com.jme3.math.ColorRGBA;
import com.jme3.math.Vector3f;
import com.jme3.renderer.RenderManager;
import com.jme3.scene.Node;

public class Main extends SimpleApplication {

Node sunNode;

public static void main(String[] args) {
    Main app = new Main();
    app.start();
}

@Override
public void simpleInitApp() {
    flyCam.setMoveSpeed(30f);
    
    // Create a planet and sun
    PlanetGenerator pg = new PlanetGenerator(this, 1f);
    sunNode = pg.createSun(Vector3f.ZERO, 10f, ColorRGBA.Yellow, ColorRGBA.White, 100f);
    Node planetNode = pg.createPlanetWithAtmosphere(new Vector3f(20f,0,0), 5f, 6f, ColorRGBA.Blue, new ColorRGBA(0,0,1,0.5f));
    sunNode.attachChild(planetNode);
    
    rootNode.attachChild(sunNode);
    //rootNode.attachChild(planetNode);
}

@Override
public void simpleUpdate(float tpf) {
    sunNode.rotate(0, tpf * 0.5f, 0);
}

@Override
public void simpleRender(RenderManager rm) {
    //TODO: add render code
}

}
[/java]

I don’t use any texture for now cause of testing, but i really want a great sun-effect for my game :frowning:
Have played with all params of my bloom effect, no chance.
Thanks!

1 Like

Without a texture or a special shader you will get nowhere near that. I suggest you learn more about materials in 3d games or just live with the fact that you can only create plain yellow suns for now so you get on with some actual code.
The content of this post is meant to be read as a straight information or question without an implicit dismissive stance or interest in having the other party feel offended unless there’s emotes that hint otherwise or there’s an increased use of exclamation marks and all-capital words.

1 Like

@normen
does this mean that if i use a material on my sun sphere the bloom effect will be greater? If so, i will try it :wink:

1 Like