sorry to bother everyone again… I have an interesting problem… My bump mapped terrain is a bit strange looking… No matter what texture and normal map i use… it looks really strange. help?
Code for bump map
public void initBumpMaps(DisplaySystem display, Texture base){
//make height based textures
ProceduralSplatTextureGenerator pt_norm = new ProceduralSplatTextureGenerator(grid_map);
pt_norm= readDoc(NORMALS,“data”,pt_norm);
pt_norm = makeSplats(NORMALS,ALPHAS,“splats”, pt_norm);
pt_norm.createTexture(1024);
Texture normal = TextureManager.loadTexture(
pt_norm.getImageIcon().getImage()
, Texture.MM_LINEAR_LINEAR,
Texture.FM_LINEAR,true);
ProceduralSplatTextureGenerator pt_height = new ProceduralSplatTextureGenerator(grid_map);
pt_height= readDoc(HEIGHTS,“data”,pt_height);
pt_height = makeSplats(HEIGHTS,ALPHAS,“splats”, pt_height);
pt_height.createTexture(1024);
Texture height = TextureManager.loadTexture(
pt_height.getImageIcon().getImage(), Texture.MM_LINEAR_LINEAR,
Texture.FM_LINEAR,true);
TextureState allTogether = display.getRenderer().createTextureState();
allTogether.setTexture(base,0);
allTogether.setTexture(normal,1);
allTogether.setTexture(height,2);
allTogether.setEnabled(true);
VertexProgramState vert = display.getRenderer()
.createVertexProgramState();
FragmentProgramState frag = display.getRenderer()
.createFragmentProgramState();
// Ensure the extensions are supported, else exit immediately
if (!vert.isSupported() || !frag.isSupported()) {
System.out.println(“GRAPHICS CARD DOES NOT SUPPORT THIS”);
}
else{
vert.load(Grid.class.getClassLoader().getResource(
“Terrains/normals/bump_parallax.vp”));
vert.setEnabled(true);
// Load fragment program
URL u = Grid.class.getClassLoader().getResource(
“Terrains/normals/bump_parallax.fp”);
System.out.println(u);
frag.load(u);
frag.setEnabled(true);
grid_gui.setRenderState(allTogether);
grid_gui.setRenderState(vert);
grid_gui.setRenderState(frag);
}
faraway said:
i corrected the wrapping problem, but i'm having trouble figuring out how to set the floatbuffer to the terrainpage.... >_<
its a simple for loop if u look at the wiki page i wrote, it should be pretty clear. i also put the things u need to be aware of on there too.
is there any specific part or line of code u dont understand?
terrainpages don't have a setTextureBuffer method?
u need to set the texture buffer of ur terrain geometry. look at the wiki page, i wrote a small section on that.
http://www.jmonkeyengine.com/wiki/doku.php?id=parallax_mapping
second u r also missing the wrap mode for the normal and height maps. i assume u dont have 1024*1024 normal and height maps.
and btw, u r using parallax mapping to be more specific. ur frame rate looks :-o
i corrected the wrapping problem, but i'm having trouble figuring out how to set the floatbuffer to the terrainpage… >_<
faraway said:
terrainpages don't have a setTextureBuffer method?
u need to get the child that is the actual geometry in the terrain page to set the texture buffer. tru debugg and c where those children r.
a simple helper method should be fine.
still getting jelly terrain… Not quite sure where the problem is… lol… It probably is obvious and i'm just missing it. It could involve something with the floatbuffers. Need i change the floatbuffer values for my terrain, because if i understand correctly the tutorial was designed for a quad.
Code:
Snippet that composes floatbuffers
ArrayList <TerrainBlock> meshes = checkChildren(grid_gui, new ArrayList(), new ArrayList());
FloatBuffer tex2 = BufferUtils.createVector2Buffer(meshes.get(0).getVertexCount());
FloatBuffer texa = BufferUtils.createVector2Buffer(meshes.get(0).getVertexCount());
for (int x = 0; x < meshes.get(0).getVertexCount(); x++)
texa.put(1.0f).put(0.0f);
for (int x = 0; x < meshes.get(0).getVertexCount(); x++)
tex2.put(0.0f).put(1.0f);
for(int i=0;i<meshes.size();i++){
System.out.println(meshes.get(i).getName());
meshes.get(i).setTextureBuffer(0, tex2, 2);
meshes.get(i).setTextureBuffer(0, texa, 1);
}
Finds the TerrainBlocks in the TerrainPage
public ArrayList<TerrainBlock> checkChildren(Spatial s, ArrayList<Spatial> temp,ArrayList<TerrainBlock> b){
FloatBuffer f;
if(s instanceof TerrainBlock) b.add((TerrainBlock) s);
else
{
temp = ((TerrainPage)s).getChildren();
for(int i=0;i<temp.size();i++){
checkChildren(temp.get(i), new ArrayList(), b);
}
}
return b;
}