I’m using a directional light, with direction (0,-1,0) (pointing straight down) on my terrain, which is loaded from an ogre model. I keep getting these strange black areas on the opposite sides of hills from the camera. Since the light is from directly above, how can these exist and how can I get rid of them?
I attempted, but I got the following error:
SEVERE: Uncaught exception thrown in Thread[LWJGL Renderer Thread,5,main]
java.lang.IllegalArgumentException: Material parameter is not defined: m_Specular
This is my code:
[java] Material mat = new Material(assetManager, “Common/MatDefs/Misc/SimpleTextured.j3md”);
assetManager.registerLocator("/", FileLocator.class.getName());
//For some reason, you can’t have “…/” here so I did it above.
TextureKey key = new TextureKey("/home/user/Projects/terrain/image.jpg");
Texture tex = assetManager.loadTexture(key);
tex.setMinFilter(Texture.MinFilter.Trilinear);
mat.setTexture(“m_ColorMap”, tex);
mat.setColor(“m_Specular”, ColorRGBA.White);[/java]
In the examples, they use “Common/MatDefs/Light/Lighting.j3md” as the material. I don’t know how to add am image texture to this. When I replaced my material with the following code, the artifacts are still there, even though I can’t add an overlay image:
[java] Material mat = new Material(assetManager, “Common/MatDefs/Light/Lighting.j3md”);
mat.setFloat(“m_Shininess”, 32f);
mat.setBoolean(“m_UseMaterialColors”, true);
mat.setColor(“m_Ambient”, ColorRGBA.Black);
mat.setColor(“m_Diffuse”, ColorRGBA.White);
mat.setColor(“m_Specular”, ColorRGBA.White);[/java]
Did you set shininess on the materials? NVIDIA cards have a bug that causes issues when shininess is 0
You can set shininess by using [java]material.setFloat("m_Shininess", value);[/java]
I just tried that with no luck. The black is still there, but when I apply shininess the entire model turns completely white. Setting the material colors just turns the entire thing whatever color I set it to and I loose the original material of the model. I hadn’t been setting a material to the model at all in Jmonkey, it was just in the materials file of the model.
I’m using an ATI card, so I don’t think the Nvidia problem would apply.
I also tried to just add directional lighting to get rid of the shadows, but instead of getting rid of the black parts, it just made them the color of the directional light. I also attempted to change the background color of the viewport to see if that was the cause, but the shadows are still black.
Try building a gray scale image off the color image and applying it to the specular texture. I’ve noticed this artifact as well.
Look at the material definition you are using. SimpleTextured.j3md does not take a m_Specular argument.
Lighting.j3md does take multiple Texture argument, although i don’t know the purpose of all of them, i think you want the diffuse map for your texture (m_DiffuseMap). Use m_SpecularMap for the grayscale map suggested by lwsquad.
Maybe I’m just not doing this right.
Below is what I tried. Each block of code represents a separate test. In each test, I tried each method in that block of code by itself, then in all combinations with the other commands. Still the artifact persists. The result is the same with all of these, the ground (which is my model) turns white. The only one that did something different was Test 3. the model was just a lighter color than normal, but the artifact did not change.
Am I going about this all wrong?
[java]Material mat = new Material(assetManager, “Common/MatDefs/Light/Lighting.j3md”);
assetManager.registerLocator("/", FileLocator.class.getName());
TextureKey key = new TextureKey("/home/user/Projects/dependencies/JanTerrain/Jan2/vBnW.jpg");
//key.setGenerateMips(true); //no clue what this does.
Texture tex = assetManager.loadTexture(key);
tex.setMinFilter(Texture.MinFilter.Trilinear);
mat.getTextureParam(“m_DiffuseMap”);
/* The below comments were one test */
// mat.setFloat(“m_Shininess”, 0.25f);
//mat.setBoolean(“m_UseMaterialColors”, true);
// mat.setColor(“m_Ambient”, ColorRGBA.White);
// mat.setColor(“m_Diffuse”, ColorRGBA.White);
// mat.setColor(“m_Specular”, ColorRGBA.White);
/*The below code block was test 2 */
mat.setTexture(“m_Ambient”, tex);
mat.setTexture(“m_Diffuse”, tex);
mat.setTexture(“m_Specular”, tex);
/*The below code was test 3 */
mat.setTexture(“m_Diffuse”,assetManager.loadTexture("/home/user/Projects/dependencies/JanTerrain/Jan2/vBnW.jpg"));
[/java]
ok, from what ive read on this thread, you should try this:
[java]
Material mat = new Material(assetManager, “Common/MatDefs/Light/Lighting.j3md”);
assetManager.registerLocator("/", FileLocator.class.getName());
TextureKey key = new TextureKey("/home/user/Projects/dependencies/JanTerrain/Jan2/vBnW.jpg");
TextureKey grayKey = new TextureKey("/home/user/Projects/dependencies/JanTerrain/Jan2/vBnW-grayscale.jpg");
//key.setGenerateMips(true); //no clue what this does.
Texture tex = assetManager.loadTexture(key);
Texture grayTex = assetManager.loadTexture(grayKey);
tex.setMinFilter(Texture.MinFilter.Trilinear);
mat.setFloat(“m_Shininess”, 128f);
mat.setTexture(“m_DiffuseMap”, tex);
mat.setTexture(“m_SpecularMap”, grayTex);
[/java]
I didn’t test
Here is the result from that code. It looks similar to my other tries. The material layer gets washed out, but the black unlit artifacts are unchanged,
The reason everything looks washed out is that I had the intensity of the directional light in my original screenshot, and so I kept it the same for this test (multiplied by 2.5 to brighten the material layer.)
If I reduce the intensity of the directionLight back to 1, then the screenshot looks exactly like my first one.
Is ther maybee a normal flipped in the model, so that that polygon is facing down instead of up? Kinda looks like that.
Isn’t the issue on the sky box and not on the ground mesh?
How did you set up your sky?
I used example code for this I think. Here is exactly what I have:
[java] public void setupSkyBox() {
Texture envMap;
if (renderer.getCaps().contains(Caps.FloatTexture)) {
envMap = assetManager.loadTexture("Textures/Sky/Bright/BrightSky.dds");//FullskiesBlueClear03.dds"); //BrightSky.dds
} else {
envMap = assetManager.loadTexture("Textures/Sky/Night/Night.png");
}
rootNode.attachChild(SkyFactory.createSky(assetManager, envMap, new Vector3f(-1, -1, -1), true));
}[/java]
mhh ok,
get rid of the true in the skybox, you use a cubemap, so you don’t have to use it as a sphere map (so use false).
I don’t know if it’s the issue though, but it can’t hurt
Setting that to false actually gets rid of my skybox all together, the whole sky is black unless it is set to true.
I think your model is not constructed as it should be, the normals seems to point the wrong direction. Could you try to see the scene from the other direction or set the cull hint to never for the model, so you can check this out?
You are awesome! that did the trick! Thanks!
You seem knowledgeable about models, what could I do to possibly fix the normals in the model? The method I’m using to export my model is: Google Earth -->Google Sketchup → Ogre Mesh exporter
I’ve been having weird problems with this as when I try to apply the image texture to the model, the image if flipped vertically. To get the image to line up correctly with the model, I have to manually flip the image in a paint program. Is there a better way of flipping the image?
I think it has nothing to do with the image. The general generation of normals is based on the order of vertices in the vertex array, as far as i know, so the model seems to be modeled wrong. Many modeling softwares don’t care about the normals(cause of ignoring culling) but the rendering software and graphic cards do.
The only way i would suggest is to change the order of the vertices of the model part (seems to be a special part).
I experienced, that the normals are generated to the top direction if the vertices are against clockwise. So i don’t really know how your model can be fixed in you’re special case. All i can say, it is not made for professional usage.
Try to fix your model or the affected part with change the order of vertices or use none culling(but this would be the dirty way). The model must be constructed the right way, and i also have no good and easy solution for that.
Ähhm, one thing i could suggest. Check the ogre xml for the error in normal vectors, if they are there. If the most normals point to +Y and a few to -y, change them to point to +y. But thats only a guess.