Terrain Shader from the wiki

Started by Gatobot14, May 07, 2016, 05:03:20 AM

Previous topic - Next topic

Gatobot14

Hi egon ive been using the terrain shader from the wiki,  im passing the next values to the shader

                shader.setStaticUniform("map0", 0);
shader.setStaticUniform("map1", 1);
shader.setStaticUniform("map2", 2);
shader.setStaticUniform("map3", 3);
shader.setStaticUniform("splatTransform", new Matrix());


if the terrain its only flat, everything seem to work ok, but if i import a modified terrain(mountains and lakes etc) the texture coordinates are all mess up.....

i hope you can explain me how to use this shader and what more info you could need.


thanks in advance :'(

EgonOlsen

The texture coordinates come from the model, not from the shader. If you model has no proper texture coordinates, then the shader can't do anything against that.

Gatobot14

Yes my model has texture coordinates, the example has a method called setTexture where assigns a textureinfo object to the model and define the texture coordinate, strange is if a load my model like it comes from the exporter(vertical) and then calculate the texture , it show everything wrong, all texture are mess up, but if i rotate the model(horizontal) all the textures are corrected and everything work fine :o

EgonOlsen

Nothing strange to it then. IIRC, the setTexture method just maps a texture onto the terrain based on the vertices' coordinates. Depending in the orientation of the model in object space, the results differ. Keep in mind that this is just the quick and dirty way which the example uses to create some texture coordinates. It's not required to do it that way nor is it needed for  the texture splatting. All you need are proper coordinates. It doesn't matter where these come from.

Gatobot14

Ahhhh  :P and another question , just wondering, how do you make to have many ligths in your game, i notice every torch in tthe dungeons have its own ligth, even the crystals and they look awesome

EgonOlsen

The dungeons are constructed out of tiles, i.e. there's not one large dungeon object but a lot of 3d tiles that form the dungeon. Each tile is an Object3D and as such, it can have up to 8 lights each, which makes it pretty easy to render a dungeon with 80 light sources...simply because not all light sources light all tiles. I'm doing some basic culling on them in addition to set light to invisible that can't be seen anyway, but that's doesn't change the basic idea.
Apart from that, it's basic vertex lighting for torches and crytals and some offset mapping on top of that for the player's light source (the player lits up everything around him as if he would be carrying a light).

Gatobot14

But you use shaders for ligths?

EgonOlsen

Yes, of course. It's all OpenGL ES 2.0, so you have to use shaders. But all they do in the dungeons in rather simple vertex lighting...maybe with some tweak IIRC, but that's about it.