Author Topic: Terrain Shader from the wiki  (Read 3383 times)

Offline Gatobot14

  • int
  • **
  • Posts: 64
    • View Profile
Terrain Shader from the wiki
« on: May 07, 2016, 05:03:20 am »
Hi egon ive been using the terrain shader from the wiki,  im passing the next values to the shader
Code: [Select]
                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 :'(

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Terrain Shader from the wiki
« Reply #1 on: May 07, 2016, 10:35:23 am »
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.

Offline Gatobot14

  • int
  • **
  • Posts: 64
    • View Profile
Re: Terrain Shader from the wiki
« Reply #2 on: May 08, 2016, 02:46:05 pm »
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

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Terrain Shader from the wiki
« Reply #3 on: May 08, 2016, 07:11:05 pm »
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.

Offline Gatobot14

  • int
  • **
  • Posts: 64
    • View Profile
Re: Terrain Shader from the wiki
« Reply #4 on: May 09, 2016, 03:08:17 pm »
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

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Terrain Shader from the wiki
« Reply #5 on: May 09, 2016, 07:55:05 pm »
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).

Offline Gatobot14

  • int
  • **
  • Posts: 64
    • View Profile
Re: Terrain Shader from the wiki
« Reply #6 on: May 11, 2016, 02:52:12 am »
But you use shaders for ligths?

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Terrain Shader from the wiki
« Reply #7 on: May 11, 2016, 07:41:07 am »
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.