I don’t know if I should put this question here. I’m pretty new for Unity now.
For the beginning, I think the tile from Don’t starve using 2 type of texture to build its tile.
the first one is used for the shape of that tile like this below(I searched it from internet) but not like a pure mask, it contains a little lines for additional decorating the edge part.
And the second type of texture is used to fill the inside part and make it looks like a hand draw style.
They somehow blend those textures while keeping those dark lines from first one, keep and showing the hand draw texture from second one. Like this one below.
For now, Here is what I did:
I just imported 2 textures and divided them into a 3X3 pieces inside unity with the sprite editor. One for the shape, one for the inside texture.
I wrote a simple shader which will show the provided texture if the color of that part is white. If not white, mix both texture by doing this"a.color.rgb * b.color.rgb".
So far everything looks fine.
Here come the problem, the inside texture need to be independent from the shape. If you expand those tiles, there will be the same edge shape with different inside texture. However, they shape texture and the inside texture both get the same UV from the sprite I assigned(Which is the divided shape texture as above).
Is there anyway I can set the inside texture individually? Or is there any other idea to implement this function?
What you can do instead, is have the details texture (not the shape) be mapped over it using world position. This way if your texture properly tiles, it will always be continuous, and you can use a single shader and only swap out materials if you need different shapes.
Thank you for your reply. I will look into mapping it with world position thing. However, for each layer of the ground there will be multiple tiles, and each tile should have its own shape(which decided by its sprite/texture). How could I blend those shape textures and the detailed texture only with one shader?
I think you mean material in this case, not shader?
That would be rather tricky to be honest, and not really worth the trouble?
If you’re worried about draw calls, profile your project first and see how many calls exactly are spent on your terrain.
Yes, material. I blend the 2 textures in every tile, by add the corresponding material to each one. So each tile caused a draw call. I don’t think it’s acceptable. For now I am think about merge the shape texture together and use the merged shape texture to blend with the detailed texture. If this works, It may solve my problem.
Hmmm normally you should only get a draw call per material in the case of your tilemap, not per tile. Say you use 9 different shapes to fill a large floor of any number of tiles, assuming you use all materials you would get 9 calls.
Also, you could further reduce draw calls using this solution here: GPU Instancing with textures - Questions & Answers - Unity Discussions
In the shader I wrote, it does a blending operating. Might be the reason, it blend those two texture in every tile. Just guessing. I am new as a programmer, definitely I need to read through the Shader Book very soon.
Yes, but the blending shouldn’t cause any additional draw calls unless you do the blending in a separate shader pass.
A draw call is caused whenever the CPU needs to send new information to the GPU. These can be textures, models, or material variables. If you have multiple objects with the exact same models and materials, they’ll be drawn in the same call.
Then, each shader creates more draw calls for each pass they have. 1 pass = 1 call.
Are you sure you’re getting a call per tile?
I tried to use Texture2D.SetPixel() to merge all tile by get every pixel and put it into the final one. Not possible, it’s too costy too. Try to find another way now.
Use mesh to render those tile, and each mesh can hold multiple set of UV. I can change UV via script and put almost all texture into one sheet and reduce the drawcall.
BTW, thank for your mention yesterday, I found out why the draw call increased. I referred material in my script, even I didn’t use it. Unity will create a copy of that material once I refer it. Just because of one line of code like " Material xx = render.material;" One more draw call will be added to your pool.