Hello,
First of I would like to show some code:
[java]
Quad q = new Quad(2, 2);
Geometry g = new Geometry(“Quad”, q);
Material mat = new Material(assetManager,
“Common/MatDefs/Light/Lighting.j3md”);
g.setMaterial(mat);
Texture tex = assetManager
.loadTexture(“Textures/Billboards/select_ring.png”);
mat.setTexture(“m_DiffuseMap”, tex);
mat.getAdditionalRenderState().setBlendMode(BlendMode.Alpha);
Node bb = new Node(“billboard”);
bb.addControl(new BillboardControl());
bb.attachChild(g);
rootNode.attachChild(bb);
DirectionalLight light= new DirectionalLight();
sun.setDirection(new Vector3f(-0.1f, -0.7f, -1.0f));
rootNode.addLight(light);
[/java]
The problem is that when I turn around directional light, I won’t see my billboard.
Or when I rotate around the billboard it dissapears.
Do you guys know what’s the problem here (I’m a beginner but the word normals sound related)?
To display both sides of the quad, use mat.getAdditionalRenderState().setFaceCullMode(FaceCullMode.FrontAndBack); (or something like that) For the directional light thing, we added AmbientLight in svn, if you are using alpha-3 you have to put a directional light on the opposite side as well as the directional light … well… is coming from one direction only
That hid it completely:
[java]
mat.getAdditionalRenderState().setFaceCullMode(FaceCullMode.FrontAndBack);
[/java]
Tried also:
[java]
mat.getAdditionalRenderState().setFaceCullMode(FaceCullMode.Off);//the same problem that in the beginnning
[/java]
Used ambient light only, then it is okay, as soon as I add a Directional light problem begins again.
[java]
public void simpleInitApp() {
flyCam.setMoveSpeed(10);
Quad q = new Quad(2, 2);
Geometry g = new Geometry("Quad", q);
Material mat = new Material(assetManager,
"Common/MatDefs/Light/Lighting.j3md");
g.setMaterial(mat);
Texture tex = assetManager
.loadTexture("Textures/Billboards/select_ring.png");
mat.setTexture("m_DiffuseMap", tex);
mat.getAdditionalRenderState().setBlendMode(BlendMode.Alpha);
mat.getAdditionalRenderState().setFaceCullMode(FaceCullMode.Off);
Node bb = new Node("billboard");
bb.addControl(new BillboardControl());
bb.attachChild(g);
AmbientLight amb = new AmbientLight();
rootNode.attachChild(bb);
DirectionalLight sun = new DirectionalLight();
sun.setDirection(new Vector3f(-0.1f, -0.7f, -1.0f));
rootNode.addLight(sun);
DirectionalLight sun2 = new DirectionalLight();
sun2.setDirection(new Vector3f(0.1f, 0.7f, 1.0f));
rootNode.addLight(sun2);
rootNode.addLight(amb);
}
[/java]
I tested it again, and actually it only dissapears at 1 point and then appears again.
Front all okay:
Side, all not okay:
It’s like some object is infront of it
And which is even more weird is what happens when I comment out blendmode and cullmode lines.
Now I move to the “side” - it is like 1 side is with alpha the other side is without alpha:
This is how it happens:
Here is the test case:
[java]
package test;
import com.jme3.app.SimpleApplication;
import com.jme3.light.AmbientLight;
import com.jme3.light.DirectionalLight;
import com.jme3.material.Material;
import com.jme3.math.Vector3f;
import com.jme3.scene.Geometry;
import com.jme3.scene.Node;
import com.jme3.scene.control.BillboardControl;
import com.jme3.scene.shape.Quad;
import com.jme3.texture.Texture;
public class TestBill extends SimpleApplication {
@Override
public void simpleInitApp() {
flyCam.setMoveSpeed(10);
Quad q = new Quad(2, 2);
Geometry g = new Geometry(“Quad”, q);
Material mat = new Material(assetManager,
“Common/MatDefs/Light/Lighting.j3md”);
g.setMaterial(mat);
Texture tex = assetManager
.loadTexture(“Textures/Billboards/select_ring.png”);
mat.setTexture(“m_DiffuseMap”, tex);
// mat.getAdditionalRenderState().setBlendMode(BlendMode.Alpha);
// mat.getAdditionalRenderState().setFaceCullMode(FaceCullMode.FrontAndBack);
Node bb = new Node(“billboard”);
bb.addControl(new BillboardControl());
bb.attachChild(g);
AmbientLight amb = new AmbientLight();
rootNode.attachChild(bb);
DirectionalLight sun = new DirectionalLight();
sun.setDirection(new Vector3f(-0.1f, -0.7f, -1.0f));
rootNode.addLight(sun);
DirectionalLight sun2 = new DirectionalLight();
sun2.setDirection(new Vector3f(0.1f, 0.7f, 1.0f));
rootNode.addLight(sun2);
rootNode.addLight(amb);
}
public static void main(String[] args) {
TestBill app = new TestBill();
app.start();
}
}
[/java]
Forgot to set m_Shininess? You have to set it on all lighting materials (REGARDLESS if you use specularity or not), otherwise NVIDIA cards won’t display it correctly.
Okay I switched to another material type which corrected that problem but now I can’t get the transparency right:
[java]
Quad q = new Quad(quadSize, quadSize);
Geometry g = new Geometry(“Quad”, q);
Material mat = new Material(assetManager,
“Common/MatDefs/Misc/SimpleTextured.j3md”);
g.setMaterial(mat);
Texture tex = assetManager
.loadTexture(“Textures/Billboards/select_ring.png”);
mat.setTexture(“ColorMap”, tex);
mat.getAdditionalRenderState().setBlendMode(BlendMode.Alpha);
[/java]
This doesn’t display transparency and I don’t know why not…
Try disabling zbuffer writes.
material.getAdditionalRenderState().setDepthWrite(false);
and see if it helps.
Alternatively, play with AlphaDiscardThreshold (set it to something like 0.5f for example).
Setting depth write false worked fine, can you explain me why?
[java]
material.getAdditionalRenderState().setDepthWrite(false);
[/java]
That worked for transparency. But now I have the problem that the object that should be behind the billboard appears in front of it.
So I guess I need a better solution