[Solved] TerrainLighting (is there a doc page for it?) [yes, there is]

Hello peeps.



I’m trying to get terrain lighting working in my ‘game’



My code for setting up the mat_terrain is stock from the documentation page for HelloTerrain except that i changed

Code:
terrain_mat = new Material(assetManager, "Common/MatDefs/Terrain/Terrain.j3md");

into TerrainLighting.j3md.

When i do this, whatever plat texture is defined next causes an exception ("Tex1", grass in the default case)


Obviously i'm doing something wrong, but seeing as i cannot find documentation for this, can someone nudge me in the right direction ?

yeah, the normal example works just fine, except that i get this lovely little exception when i try to use TerrainLighting.j3md

If i touch the .setTexture and change it from “Alpha” to “m_AlphaMap” as i see in some attempts in the forum, stuff just breaks(throws exception) the next texture over.



I don’t know where to even look for the answer.

Code:
SEVERE: Uncaught exception thrown in Thread[LWJGL Renderer Thread,5,main] java.lang.IllegalArgumentException: Material parameter is not defined: Alpha at com.jme3.material.Material.checkSetParam(Material.java:374) at com.jme3.material.Material.setTextureParam(Material.java:476) at com.jme3.material.Material.setTexture(Material.java:524) at jme3test.helloworld.HelloTerrain.simpleInitApp(HelloTerrain.java:35) at com.jme3.app.SimpleApplication.initialize(SimpleApplication.java:230) at com.jme3.system.lwjgl.LwjglAbstractDisplay.initInThread(LwjglAbstractDisplay.java:129) at com.jme3.system.lwjgl.LwjglAbstractDisplay.run(LwjglAbstractDisplay.java:205) at java.lang.Thread.run(Thread.java:680)

[edit]
Thanks for that link; where/how did you find it ?

[edit2]
Argh, now my terrain is invisible :S (i'm not falling though, and raycasting confirms that the terrain is still there)

https://wiki.jmonkeyengine.org/legacy/doku.php/jme3:advanced:terrain



edit: here



Google Code Archive - Long-term storage for Google Code Project Hosting.

you use “AlphaMap” (for the first) so try without “m_”



for more:

AlphaMap_1

AlphaMap_2

AlphaMap_3



AlphaMap_n

don’t know how many possible



The link was in the advanced terrain doc :slight_smile:

linked as terrain (terramonkey) not as (advanced)



Guess i thought that was about the terrain editing tools (which i don’t use, my heightmap is generated procedurally)



Also i fixed the invisibility problem, i didn’t have a light in there yet (i guess being able to see the ‘sky’ fooled me)

I’ll try again in the morning with a moving light, its 05:09 now :smiley:



Anyway, thanks :slight_smile:

how you wanted see terrain in darkness? :roll:



seriously that link was in https://wiki.jmonkeyengine.org/legacy/doku.php/jme3:advanced:terrain :slight_smile: look there are:



Sample Code

*

TerrainTest.java

*

TerrainTestAdvanced.java

*

TerrainTestCollision.java

*

TerrainTestModifyHeight.java

*

TerrainTestReadWrite.java







and im happy you solved problem :slight_smile:



edit: Naah its 5:12 :slight_smile:

1 Like
@oxplay2 said:
...
AlphaMap_1
AlphaMap_2
AlphaMap_3
.....
AlphaMap_n
don't know how many possible

Just the 3 alpha maps right now, meaning a max of 12 diffuse textures. I plan to increase this in the future using texture arrays or 3d textures, I have to play around a bit first though and see how they work.

@oxplay yeah, i wanted it to be pitch-black first, so i could be sure everything was working, and see the exact result my lightsource was having but the sky fooled me into thinking the terrain had gone invisible. (because the sky is colored and not influenced by lighting)



as for the link: like i said, i must have glossed over that thinking it was about the terrain editor, as the link on the page says TerraMonkey, my sleep deprived brain thought it was about using the terrain editor.



Anyway, i’m going to bed now :stuck_out_tongue:

Stayed up much longer than i planned.

Ok, now that i’ve had some sleep met me distinguish my question.



What i wanted to ask is whether or not there was a tutorial for this, not just an example.

(i got the example to work, i just only have half a clue about what i’m doing)

@Sploreg said:
Just the 3 alpha maps right now, meaning a max of 12 diffuse textures. I plan to increase this in the future using texture arrays or 3d textures, I have to play around a bit first though and see how they work.


Actually I'm already mid finished with this based on the TerrainLightning, and can contribute as soon as everything works correctly.



@ xeno
Usually there are tutorials in the wiki.
However for the lighening:
you need x diffuse maps and x normal maps(normal maps are optional, but look quite awesome)
now set the diffuse maps (take a look at the j3md file for exact names, note hat you never do the m_ from jme (it is more for the shaders, that the names between attributes from the mesh and materialparameters cannot overlap).

Alphamap defines where wich of the diffuse maps is. for a tst I suggest using 3 diffuse maps and one alpha atthe beginning. RGB of a pixel in the alphamap then decides what texture to use for the corresponding geometry part. Now the last thing, add for example a Pointlight to the scene.
Then it should work.
1 Like

hehe, i’ll have to do a little study as to what half of that means (as you migth have notices, i’m a bit of a n00b in this , i normally do buisiness logic CMS/webapps in php )

@EmpirePhoenix said:
Actually I'm already mid finished with this based on the TerrainLightning, and can contribute as soon as everything works correctly.

If you want to contribute it I would love to incorporate it into core :)

@oxplay2



this is why i wanted it to start out pitch dark :smiley: what little light you have will really stand out :slight_smile:

yes it look nice, but i think it is too dark :stuck_out_tongue: add a little AmbientLight :slight_smile:

that’s because of the angle at which i make the light hit the terrain :slight_smile:

(it comes from the same angle as the sun is in the sky picture)

Code:
light.setDirection((new Vector3f(-0.4f, -0.9f, -0.5f)).normalize());

But the extreme dark is what i wanted :) it sure does prove lighting works. I had the orbiting red ball from some of the example code in before, but i noticed no difference on the terrain. Now; i'll see differences :)

@xenofobiq yes, cerainly now you know it work



now you should really add some ambient light(just a little), DepthOfFieldFilter to blur distant terrain, and Light Scattering. Thats all will give full effect :slight_smile:

Eventually, first i have work some magic on my landscape algorithm, as you can see it leaves terrain a bit blocky

hey man, if you want to do blocky terrain use voxel terrain. (but i hope you don’t do second minecraft - becouse i see thousands of it :D)

no that’s exactly what i don’t want, hence why i need to do more magic on it