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
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
Have played with all params of my bloom effect, no chance.
Thanks!