Author Topic: How to set up Parallax mapping  (Read 3124 times)

Offline Yerst

  • byte
  • *
  • Posts: 38
    • View Profile
How to set up Parallax mapping
« on: July 15, 2013, 05:42:03 pm »
Hey!
I found the demo of Parallax mapping on youtube and also this topic in the forum: http://www.jpct.net/forum2/index.php/topic,2153.msg15839.htm
I do already have all the needed textures, but i don't know how to set up the shaders.
I found the wiki Page about shaders and tried setting it up with the GLSLShader class, but i don't know what setStaticUniform does or how i can use setRenderHook(shader) on android.
Is there a tutorial or a sample code out there?

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: How to set up Parallax mapping
« Reply #1 on: July 15, 2013, 06:21:34 pm »
The parallax mapping stuff should be part of the examples that come with jPCT-AE...

Offline Wolf17

  • int
  • **
  • Posts: 77
    • View Profile
Re: How to set up Parallax mapping
« Reply #2 on: July 15, 2013, 06:26:42 pm »
    There is a helloshader example project in the jpct ae download file . I think It is the same example( stone face) you saw in the youtube vid.

Offline Yerst

  • byte
  • *
  • Posts: 38
    • View Profile
Re: How to set up Parallax mapping
« Reply #3 on: July 15, 2013, 08:54:26 pm »
Ok, this is the code i'm using now:
Code: [Select]
InputStream vertexS = manager.open("vertex.glsl");
InputStream fragmentS = manager.open("fragment.glsl");
String vertex = Loader.loadTextFile(vertexS);
String fragment = Loader.loadTextFile(fragmentS);
GLSLShader shader = new GLSLShader(vertex,fragment);
shader.setUniform("heightScale", 1);
Texture height = new Texture(this.context.getResources().openRawResource(R.raw.earth_heightmap));
Texture normals = new Texture(this.context.getResources().openRawResource(R.raw.earth_normalmap));
Texture earth = new Texture(this.context.getResources().openRawResource(R.raw.earth));

TexelGrabber grabber = new TexelGrabber();
height.setEffect(grabber);
height.applyEffect();
int[] heighties = grabber.getAlpha();
AlphaMerger setter = new AlphaMerger(heighties);
normals.setEffect(setter);
normals.applyEffect();
tm.addTexture("earth_normalmap",normals);
tm.addTexture("earth",earth);
TextureInfo ti = new TextureInfo(TextureManager.getInstance().getTextureID("earth"));
ti.add(TextureManager.getInstance().getTextureID("earth_normalmap"),TextureInfo.MODE_BLEND);
planet.setTexture(ti);
planet.setShader(shader);
shader.setStaticUniform("invRadius", 0.0005f);

planet.build();
world.addObject(planet);
Now i have two other problems:
1.)My whole texture seems more dark. What could be the fault? The Normalmap?
2.)I can't see any Parallax mapping effect at all  :(
Here is a ingame screenshot:

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: How to set up Parallax mapping
« Reply #4 on: July 15, 2013, 10:57:38 pm »
You might have to tweak the shader values. As it is, it's not meant to be used for objects that are far away from the viewer. In addition, try to enable specular lighting on the planet in case you haven't and you might want to post the textures you are using to make sure that they fit the purpose.

Offline Yerst

  • byte
  • *
  • Posts: 38
    • View Profile
Re: How to set up Parallax mapping
« Reply #5 on: July 15, 2013, 11:16:00 pm »
Ok, here are my textures:
Normalmap:

Heightmap:

Blank texture:

Offline Thomas.

  • double
  • *****
  • Posts: 833
    • View Profile
Re: How to set up Parallax mapping
« Reply #6 on: July 15, 2013, 11:21:48 pm »
"Height map" is specular map ;)

Offline Yerst

  • byte
  • *
  • Posts: 38
    • View Profile
Re: How to set up Parallax mapping
« Reply #7 on: July 15, 2013, 11:37:26 pm »
opps  :-[
I tried this texture now:

but there is no change at all...