How to set up Parallax mapping

Started by Yerst, July 15, 2013, 05:42:03 PM

Previous topic - Next topic

Yerst

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?

EgonOlsen

The parallax mapping stuff should be part of the examples that come with jPCT-AE...

Wolf17

    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.

Yerst

Ok, this is the code i'm using now:
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:

EgonOlsen

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.

Yerst

Ok, here are my textures:
Normalmap:

Heightmap:

Blank texture:

Thomas.


Yerst

opps  :-[
I tried this texture now:

but there is no change at all...