• Advertisement
  • Popular Tags

  • Popular Now

  • Advertisement
  • Similar Content

    • By BillyGD

      Play Flick Football 3D @ https://gamejolt.com/games/flickfootball3d/326078
      Check out our Facebook page @ https://www.facebook.com/FlickFootball3D/
      Flick Football 3D is a turn based football game inspired by the table top classic 'Subbuteo'.
      The game is currently in very early Alpha development. There is still a lot to be done before the first proper release but I have decided to release this playable version to get as much feedback as possible.
      The only game mode currently available in this release is the 'Practice Mode' which gives you control of both teams. Either play against yourself to get used to how the game works or play against friends and family on the same computer!
      Planned Future Features Include:
      -Take control of your own custom team in the single player campaign.
      -Play in online leagues and tournaments against other players in the multiplayer mode.
      -Fully customisable stadiums to make you stand out from the rest of the players.
      -Improve your players stats and skills by playing matches and setting up training sessions.
      Flick Football 3D is available for Windows, Mac and Browser.
      Thank you for viewing my game, all feedback is greatly appreciated. I can be contacted at; BillyGDev@outlook.com
      'Flick Football 3D' is also the development name for the game and I haven't yet decided what the full release will be called, so if you have any ideas please drop me a message!
    • By drcrack
      It is a combination of fundamental RPG elements and challenging, session-based MOBA elements. Having features such as creating your unique build, customizing your outfit and preparing synergic team compositions with friends, players can brave dangerous adventures or merciless arena fights against deadly creatures and skilled players alike.

      This time with no grinding and no pay to win features.

      We're still looking for:
      1) 3D Character Artist
      2) 3D Environment Artist
      3) Animator
      4) Sound Designer
      5) VFX Artist

      Discord https://discord.gg/zXpY29V or drcrack#4575
    • By Francisco Tufr
      Hi everyone! I'm currently working on a series of books about 2D Shader Development.

      The idea is to synthesize a bunch of techniques that are specifically useful for 2D, even if they work on 3D as well.

      I released the first book last week. It's 4.99 on Amazon or free on the series website, https://www.2dshaders.com

      This is an independent initiative, I don't work for any publisher whatsoever. The contents of the books are the result of a 4-year span where I started teaching this in Argentina and USA, always making the workshop better. Now I'm expanding it to make more sense in book form.

      I'd love to hear your opinions on the idea and if you get the book let me know what you think.

      By the way, the examples are in Unity, but the concepts from the book should be easily transferable to any graphics api/engine.

      Hope you like it!
    • By RoKabium Games
      While looking out for that pesky Terrator, our little alien is doing a bit of relaxed mining down on the new gas planet "Lelantos" this weekend.... 
      #gamedev #indiedev #madewithunity #screenshotsaturday
    • By vividgamer
      I have a native iOS game (objective c, XCode build) which I am considering to port to other platforms.
      Core gameplay is based on solely on geographical maps, and custom drawing over maps. It also has Core Data. This part is complete in development.
      What is not done yet is: monetization, gamification (leaderboards, challenges) and multiplayer functionality.
      As I think more about it, I am tempted to think if this is the right time to move to a cross platform tool such as Unity. But before dedicating time to port my 5 years side-project effort in Objective C, I really want to know if its worth it.
      - Does Unity support such plugins / assets that will fulfill all my above requirements?
      - Unity Personal seems to have only 20 concurrent users - is it too costly scaling if I decide for extending to web and android platforms?
      - What is the general workflow involved in publishing to iOS, Android, PC, and web platforms while using Unity? I mean to ask about various points of signing stuff, paying fees and getting certified.
      - How long will it really take to port my entire Objective C project into Unity? I am somewhat familiar with C# but I am finding it hard fidgeting with Unity IDE as lot of things are focused around FPS and 3D while my game is still 2d - not much action involved. I seem bit overwhelmed by the list of features I see there. All in all, I do not want to lose my momentum while still making sure its portable to everywhere.
      - Any assets I could use (for free to try basis in debug) that are relevant for my game?
      - Last but not the least, are there any costs that I need to be paying upfront to Unity, for using it (apart from their monthly subscription model)? I don't understand their costing for multiplayer in conjunction with their subscription fees - if someone could kindly elaborate.
      Thanks in advance for your time reading a newbie
  • Advertisement
  • Advertisement
Sign in to follow this  

Render submesh with material of mesh by script.

Recommended Posts


I want to create a fairly large "tilemap" with 3D assets. I started testing and have very promising results with generating the terrain mesh by code.

private Mesh createChunck(int width, int height)
        Vector3[] verts = new Vector3[width * height * 6];
        Vector2[] uvs = new Vector2[width * height * 6];
        int[] triangles = new int[width * height * 6];

        for (int y = 0; y < height; y++)
            for (int x = 0; x < width; x++)
                //Debug.Log("x: " + x + ", y: " + y);

                verts[(y * width + x) * 6 + 0] = new Vector3(x, 0, y);
                verts[(y * width + x) * 6 + 1] = new Vector3(x + 1, 0, y);
                verts[(y * width + x) * 6 + 2] = new Vector3(x + 1, .5f, y + 1);

                verts[(y * width + x) * 6 + 3] = new Vector3(x, 0, y);
                verts[(y * width + x) * 6 + 4] = new Vector3(x + 1, .5f, y + 1);
                verts[(y * width + x) * 6 + 5] = new Vector3(x, 0, y + 1);

                uvs[(y * width + x) * 6 + 0] = new Vector2(0, 0);
                uvs[(y * width + x) * 6 + 1] = new Vector2(1, 0);
                uvs[(y * width + x) * 6 + 2] = new Vector2(1, 1);

                uvs[(y * width + x) * 6 + 3] = new Vector2(0, 0);
                uvs[(y * width + x) * 6 + 4] = new Vector2(1, 1);
                uvs[(y * width + x) * 6 + 5] = new Vector2(0, 1);

                for (int t = 0; t < 6; t++)
                    triangles[(y * width + x) * 6 + t] = (y * width + x) * 6 + 5 - t;

        Mesh m = new Mesh();
        m.vertices = verts;
        m.uv = uvs;
        m.triangles = triangles;

        return m;


I can easily render 10 x 10 "chuncks" of 100 x 100 tiles in a scene which is should be enough. However I need the tri's to be able to change material individually, by code. Obviously without (re)generating the mesh again since that does take some time. With the following code I can change and add submeshes to the mesh.

        test.subMeshCount = 2;

        int[] tri1 = new int[] { 5, 4, 3 };
        int[] tri2 = new int[] { 2, 1, 0 };

        test.SetTriangles(tri1, 0);
        test.SetTriangles(tri2, 1);

And it seems like simply adding a Material array to Graphics.DrawMesh(...) but unfortunately it only takes a single material and all the triangles that are out of the submesh group 0 are not being drawn.

I could probably create a GameObject with a renderer component and thrown in the mesh and create my material array there but I don't really need/want a GameObject. I'm just looking for a clean way to render this mesh my script with different materials for it's submeshes by script.

In case you are interested in the stats of rendering 1.000.000 tiles using 100 large meshes here is a screengrab. Looks promising, but I got to be able to change texture/material on individual tiles dynamically. With this setup I might look into a perspective cam and allow for a slightly sharper angle on the camera.

Share this post

Link to post
Share on other sites

Ok, some options:

1) Changing the mesh data:

A texture-atlas ( a single aggregate texture that contains each tile-texture side-by-side ), and each sub-texture can be referenced through enumeration. Using a triangle list, change the tex-coords of a given quad to the appropriate area in a texture-atlas.

2) using a shader:
You have a texture-atlas. You have a second texture, which contains the map-tile-info in each pixel, such as texture-atlas-index. Pixel (0,0) refers to tile(0,0), and contains a texture-atlas index in say channel R. The shader then grabs the texture-atlas index (channel R) and applies that part of the texture-atlas to the quad. 

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this  

  • Advertisement