Unexpected Terrain Lighting Results

I’m not 100% sure if this is suppesed to happen, but I want to change it, when I use the terrain lighting with a directional light, I get the following result: http://imgur.com/AK3dU I’m specifically talking about the weird ‘Ink Blotches’ or splotches where the terrian is pure black, if these are the shadows, I don’t wan’t them to be 100% black, I wan’t them to be darker, but not black. How do you fix this? Like I stated above, I’m using a directional light, do I need to use a different light source?



Note : I posted this under effects, but I didn’t get any response, so I didn’t know if they didn’t know or if nobody ever read it. So I have also posted it here.

How are you creating the terrain? Are you doing anything with the tangents after it is created?

I’m not doing anything (I don’t think) with the terrain after it’s generated. Here’s my code:



[java]

package mygame;



import com.jme3.app.SimpleApplication;

import com.jme3.material.Material;

import com.jme3.math.ColorRGBA;

import com.jme3.math.Vector3f;

import com.jme3.texture.Texture;

import com.jme3.texture.Texture.WrapMode;

import com.jme3.terrain.geomipmap.TerrainQuad;

import com.jme3.light.AmbientLight;

import com.jme3.light.DirectionalLight;



public class Main extends SimpleApplication {



public static void main(String[] args) {

Main app = new Main();

app.start();

}



public float[] map = new float[4096];



@Override

public void simpleInitApp() {

//setup our sky color

viewPort.setBackgroundColor(new ColorRGBA(0.7f, 0.8f, 1f, 1f));

//set up flycam

flyCam.setMoveSpeed(100f);

//set up the class definations

MapObj world = new MapObj();

//call the world generator

map = world.Spawn(map);

//use the world generator

create();

//init the sun

initSun();

}



Material mat_terrain;

TerrainQuad terrain;



public void create() {

//setup the terrain

terrain = new TerrainQuad(“terrain1”, 33, 65, map);

rootNode.attachChild(terrain);

//setup the aphamapping and the textures

mat_terrain = new Material(assetManager, “Common/MatDefs/Terrain/TerrainLighting.j3md”);

mat_terrain.setTexture(“AlphaMap”, assetManager.loadTexture(“Textures/alphaMap.png”));

Texture grass = assetManager.loadTexture(“Textures/grass.jpg”);

grass.setWrap(WrapMode.Repeat);

mat_terrain.setTexture(“DiffuseMap”, grass);

mat_terrain.setFloat(“DiffuseMap_0_scale”, 1f);

//setup rood node

terrain.setMaterial(mat_terrain);

terrain.setLocalScale(100f, 0.3f, 100f);

}



public void initSun() {

// We add light so we see the scene

AmbientLight al = new AmbientLight();

al.setColor(ColorRGBA.White.mult(5.0f));

rootNode.addLight(al);



DirectionalLight dl = new DirectionalLight();

dl.setColor(ColorRGBA.White);

dl.setDirection(new Vector3f(2.8f, -2.8f, -2.8f).normalizeLocal());

rootNode.addLight(dl);

}

}

[/java]



And for MapObj:



[java]package mygame;





import java.util.Random;



public class MapObj {



Random gen = new Random();



public float[] Spawn(float[] map) {

float x = 0;

int z = 0;

int y = 0;

float oz = 0;

float oy = 0;

float ox = 0;

float oox = 0;

int nn = 0;

int c = 0;

int a = 257;

for(int n = 0; n < 4096; ++n) {

if(n == 1) {

//seed gen

System.out.println(“Generating Map”);

x = gen.nextInt(64);

map[n] = x;

} else if(n <= 64 && n != 1) {

//first row gen

y = gen.nextInt(4);

z = gen.nextInt(2);

oy = y;

if(z == 1) {x = x + oy;} else {x = x - oy;}

if(x >190) { x = x - 100;}

map[n] = x;

} else if(n == a) {

//first col. gen

x = map[n - 64];

y = gen.nextInt(4);

z = gen.nextInt(2);

oy = y;

if(z == 1) {x = x + oy;} else {x = x - oy;}

if(x >190) { x = x - 100;}

map[n] = x;

} else {

//main body gen

oox = map[n - 64];

ox = map[n - 1];

y = gen.nextInt(4);

z = gen.nextInt(2);

oy = y;

if(z == 1) {x = (oox + oy) + (ox + oy) / 2;} else {x = (oox - oy) - (ox - oy) / 2;}

if(x >190) { x = x - 100;}

map[n] = x;

}

}



return map;

}

}

[/java]

I tried your code. Your terrain is just massive (the scale is huge) and is getting cut off by the view frustum, giving your those dark spots (terrain that is being culled by the frustum). Set the scale to 10 on the X and Z axis and you will see most of it without it being culled.

It fixed it a little bit in that when I move closer, it gets a bit smaller, however, there’s still good sized portions that are being culled. http://imgur.com/8QP1N

If it’s getting cut off by the view frustum can you expand the frustum view so it isn’t cut off???

@chessmaster942 said:
If it's getting cut off by the view frustum can you expand the frustum view so it isn't cut off???

Of course.
getCamera().setFrustumFar(2000);

Just tried setting the frustum to 2000 (I even tried 9,000) and I’m having the same problem still. I tried implementing shadows, but it didn’t change anything. (I didn’t try using shadows for curved surfaces, as I didn’t think that that would help)

It’s not shadows.

It could be your graphics driver is out of date.

I’ll try updating it. Thanks for continuing to help, hopefully this will fix it.

Just pulled up some specs, I have a NVIDIA 310m graphics card. Not very good for gaming, so I’m going to get a new one (this isn’t the only reason, other programs have been nagging me) In the mean time, I was wondering, sense I was using lighting for a day/night cycle, as well as other things, is there a way to change the alpha of a texture, and add / subtract textures from a material? (I wanted this so I could phase out a texture and phase in a new one)

Yep.

To fade in a texture you have to modify one of the texture channels corresponding to the texture you want to fade. You get the alpha image from the material, then modify the pixels.

There are 3 alpha maps, meaning 12 diffuse textures are supported.

First alpha map is textures 0-3, second alpha map is textures 4-7, and the last is textures 8-11.

Look at PaintTerrainToolAction.java (part of the SDK code) for manipulating the alpha maps on the fly.

After updating my video graphics card, and messing with it’s settings, I finally got it to work. Leaving me with only one more question why does this happen : http://imgur.com/YdQHZ? Here’s my code for the light:



[java]

DirectionalLight sun = new DirectionalLight();

sun.setColor(new ColorRGBA(0.6f, 0.6f, 0.6f, 1.0f));

sun.setDirection(new Vector3f(-1.13f, -1.13f, 1.13f).normalizeLocal());

rootNode.addLight(sun);

[/java]



I thought that directional light ment that it acted like the sun, and if the sun acted like this then our world would be very different. What am I missing / confused on???




<br />
I want to light up the whole map should I have a spotlight with a large radius???

That is a strange effect. It could be the shininess setting on the material, try mat_terrain.setFloat(“Shininess”, 0.001f);

If it isn’t that, well then it might be your card again doing strange things.

You do not want a spotlight, that is like a flashlight. You want an ambient light and directional light (like the sun).

It works great now. Thanks for your time.

No problem :slight_smile:

The terrain shader should provide a means for controlling shininess/specularity or just not include it at all which would be totally acceptable. Its just that you cant expect a dirt texture and a road texture to have the same shininess values or specular intensities.