About Store Forum Documentation Contact
Donations:
309$/mo



Post Reply 
Different settings for Rivers and Lakes
Author Message
Ozmodian Offline
Member

Post: #1
Different settings for Rivers and Lakes
Hi There,

I have been working on creating rivers and lakes in code and run into a problem. Lakes work great but whenever i flag something as a River with the .lake bool, the water texture looks really bad. I am sure there is a setting in either the MeshBase or the Water Mesh or Water Mtrl that i am just not setting but i have looked everywhere and cant find it.

If you could just let me know what i am not setting, that would help. Here is a video showing the problem.



08-15-2013 08:16 AM
Find all posts by this user Quote this message in a reply
Esenthel Online
Administrator

Post: #2
RE: Different settings for Rivers and Lakes
Hi!
I haven't seen the video, but:
For Rivers (unlike Lakes) you need to manually set the texture coordinates for the vertexes.
Something like x=0 for left side, x=1 for right side, and continuously increase Y along the river direction, should do the trick.
08-20-2013 03:31 AM
Find all posts by this user Quote this message in a reply
Ozmodian Offline
Member

Post: #3
RE: Different settings for Rivers and Lakes
Hi Esenthel,

I knew it would be something like that. Unfortunately, i have no idea what that means. I checked Meshbase and the water classes but don't see anything that mentions setting texture coordinates. Any extra hint would be much appreciated.
08-20-2013 04:24 AM
Find all posts by this user Quote this message in a reply
Esenthel Online
Administrator

Post: #4
RE: Different settings for Rivers and Lakes
Hi!

There is a tutorial in 2.0 for manually setting up MeshBase parameters.

Something like that:
mesh_base.include(VTX_TEX0);
REPA(mesh_base.vtx)mesh_base.vtx.tex0(i).set(..);
08-21-2013 02:48 AM
Find all posts by this user Quote this message in a reply
Ozmodian Offline
Member

Post: #5
RE: Different settings for Rivers and Lakes
Ahh, i see what you are saying now, the Tutorial helped me put the pieces together.

I would love to see the code you use to assign the texture coords when a user is creating a river in the editor. Same kind of goes for how you determine the best mix of Triangles and Quads for Rivers and Lakes. Even pseudo code would help.

Either way, thanks for the help, i understand it much better now.
08-24-2013 02:43 AM
Find all posts by this user Quote this message in a reply
Ozmodian Offline
Member

Post: #6
RE: Different settings for Rivers and Lakes
Hi Esenthel,

So i got this to work for rivers (thanks for the tip about the text coords). I would love to give the user the ability to add additional points to a river or lake but i can't figure out a way to do that without implementing a full on Delaunay Triangulation algorithm. Since you do it in the editor so easily, i have to assume it is something the engine already has in it. Is that process exposed in any way in the engine? If not, i understand, but just thought i would ask. I feel like building they from scratch would be overkill.

Thanks as always for your help.
08-29-2013 04:13 AM
Find all posts by this user Quote this message in a reply
Esenthel Online
Administrator

Post: #7
RE: Different settings for Rivers and Lakes
Hello!

I use this code in the Editor:
Code:
class RiverBase
{
   class Vtx
   {
      flt radius=2;
      Vec pos=0;

      void set(flt radius, C Vec &pos) {T.radius=radius; T.pos=pos;}
   }

   bool        removed=false;
   byte        smooth=0;
   flt         depth=3;
   Vec2        tex_scale=1;
   UID         material=UIDZero;
   Memc<Vtx  > vtxs;
   Memc<VecI2> edges;
  ..
}

class River : RiverBase
{
   WaterMesh water_mesh;

   void setMesh(C Str &game_elm_path)
   {
      // set mesh 2D
      MeshBase mesh; mesh.create(vtxs.elms(), edges.elms(), 0, 0, VTX_SIZE);
      REPA(vtxs)
      {
         mesh.vtx.pos (i)=vtxs[i].pos.xzy();
         mesh.vtx.size(i)=vtxs[i].radius;
      }
      REPA(edges)mesh.edge.ind(i)=edges[i];

      // convert mesh 2D to 3D
      REP(Min(8, smooth))mesh.subdivideEdge();
      mesh.inflateEdges(true, false);
      mesh.quadToTri   (0.9993     ); // convert quads to tris because not flat rivers can have quads built of 2 non-coplanar tris
      mesh.texScale    (tex_scale  );
      REPA(mesh.vtx)Swap(mesh.vtx.pos(i).y, mesh.vtx.pos(i).z);

      // create water
      water_mesh.create(mesh, false, depth, WaterMtrlPtr(material.valid() ? game_elm_path+EncodeFileName(material) : S));
   }
08-29-2013 09:05 AM
Find all posts by this user Quote this message in a reply
Post Reply