#Perfomance issue loading multiple tiles
1 messages ยท Page 1 of 1 (latest)
many materials cause issues with unity is what i heard
might just be rumors tho
so more materials is better?
because that is exactly what im doing yet the setPass calls amount is quite high
Different mesh with same material would batched and cause less draw call
isnt that better?
Yes
mm any idea how can i easily create mutliple quads as seperate meshes for the texture atlas?
its just mainly tiles represented as quad meshes
i did create a script that would instantiate quads and change their uvs to fit their texture
So you are doing texture atlas, maybe look for MaterialPropertyBlock
but in frame debugger it shows me that it loads each of them separately
not as batch
What does frame debugger say for reason
this is mainly what i did
one sec ill hcek again
You have GPU instancing enabled for your material
true
Which requires to be same mesh
oh i see
so its like a 3rd option of batching?
as its not dynamic nor static batching
Yeah it's kind of .. batching for meshes
Again I think MaterialPropertyBlock is best fit for your requirement
i mean i used it for animated materials, but im not sure how i would use it in this case
in animated materials i mainly used the propertyblocks to change the texture without changing the material
wouldnt changing the uv of the mesh do the same?
yes but changing uv create different mesh
which is what we want, no?
for mesh batching
If you use MaterialPropertyBlock you can keep your mesh, gpu instancing, and use same material
Using single mesh, single material, setting offset/tiling with MaterialPropertyBlock
alright then, ill try it out, thank you so much ๐
if you have any tips on improving performance, i would love to hear
I think SpriteRenderer would do things for you
true, but it cannot display normal maps
the game is mostly 3d
It could if you extend their shader
Though you may need same work for normal map if it is also atlased
interesting, but then its depth would not work in the 3d enviroment
as much as i played with sprites in 3d enviroments, it always displayed the sprites in a weird order
yes sorting
i can fix it wish simple command script
but then the last issue is how will it react to other light sources?
Lighting is also up to shader
wouldnt i just end up making regular standard shader?
Yeah maybe, lol
mainly what seriously killed my performance is the second cam
i use it for water reflection
With stencil buffer?
so now im searching every way to boost performance while maintaining with water reflection
stencil? mm no i dont think so
its just upside down camera and render texture
Hmm I see can't you just bake them and make fake reflection lol
There may be lot of room for optimization
thats another issue, the levels are randomly generated
so i cannot bake anything
therefore occlusion also does not work
so i made my own sort of occlusion
yeah reflection probe requires baking no? never used it
There is realtime one
from what i heard its much heavier
but i dont mind trying
im using legacy built-in pipeline
I see , isn't it still PBR?
i guess so, yeah
You can manually refresh Realtime probe when you want, then it's basically baking
if its less time than Camera.render, that would be great
Hopefully. You can try.. ๐
that i will, regardless, thank you very much ๐
as i expected, realtime reflection probes require for the scene to be static ๐ well it was worth trying
https://docs.unity3d.com/Manual/class-ReflectionProbe.html
You have option
Actually it's Custom with Dynamic Objects
๐ค
Nvm, they may be not work dynamically
apparently its also not a solution...
If you are using [PerRendererData] it should work, which shader and properties are you using?
unity's standard shader
i need to make custom shader?
alright i have the custom shader, where do i insert [PerRendererData] for material offset?
On the texture ๐ค you are using texture atlas right?
like this?
because it doesnt work ๐
Oh you should put PerRendererData for other properties you are using
Why on OnValidate, though?
to check it in editor
i commented the other ones out while i was testing the offest
ok wow it asks me to completely modify the shader and i have little to no knowledge in shader scripts.. how do i turn standard shader into instantiable standard shader?
the example you've sent only explains how to change colors with MPB, but nothing is written on every other aspect of the shader, no mainTex or metallic or normal map
I mean PerRendererData and MaterialPropertyBlock should already helping your performance
Also standard shader supports GPU instancing by default ๐ค
You should add the part starting with UNITY_INSTANCING_BUFFER_START
https://docs.unity3d.com/Manual/gpu-instancing-shader.html
in frame debuffer it keeps showing this and it loads each tile on a seperate call
I see. You need the part starting UNITY_INSTANCING_BUFFER_START with it
where exactly to i write it?๐
If you see the API doc I sent you it's this part
UNITY_INSTANCING_BUFFER_START(Props)
UNITY_DEFINE_INSTANCED_PROP(float4, _Color)
UNITY_INSTANCING_BUFFER_END(Props)
Umm you can see it from doc it's like same level as vert and frag
alright, but this part is related specifically to _color change, where as i change material offset and tilling. not color
I know, so it should be UNITY_DEFINE_INSTANCED_PROP(float4, _MainTex_ST)
And other stuffs
oh.. so its that simple?
alright ill try it but the next question, on which pass do i add it to?
the standard shader seems to have multiple
And when the access those variable, you need to replace it with UNITY_ACCESS_INSTANCED_PROP
how do i know where it accesses that material?
i can show you the shader if it helps
in the shader script there is no place where it mentions _MainTex_ST
Maybe defining surface shader like the sample yourself could be easier... ๐ค
it poses the same challange, i have no clue how to add normal and occlusion maps ๐
i mainly only need the offset and tiling
That is not that hard with surface shader. All you do is sampling texture and setting to SurfaceOutputStandard member
for you it might seem simple, for me i have no clue where to even begin, i have no experience with shader scripts at all
Let me see if I can write one for you
i would really appriciate it, thank you so much ๐
You can test it out
oh my god you are amazing!
i wont lie i was scaptical that it would work after trying everything i could find to batch tiles in the game, but it does work
again, thank you so so much, i truly appreciate it ๐
now only to understand how to let it also scale normal maps and occlusion ๐
Yeah that part, you can see the shader I calculated main_uv separately
Easy way is replacing uv_OcclusionMap and uv_BumpMap with main_uv
That is assuming all your textures(diffuse/normal/occul) are sharing same coords
yep they are the exact same texture but turned into normal and occlusion
Then simply replacing them with main_uv should work, you can remove uv_BumpMap and uv_OcclusionMap in Input as they won't be used
so replace everything after UNITY_INSTANCING_BUFFER_START(Props)?
uv_OcclusionMap and uv_BumpMap are only used in surf function
yup this does the trick, thanks again ๐
Yay
it seems i wont be able to escape from learning to code shaders ๐
Eventually you will have to deal with shader ๐
The real question is : did it help with your game's performance?
yess, it batches them together, loads them all in two calls which is incredible
not sure why but its two calls, first it loads everything close enough, and then the rest, ill have to check whats the reason behind that
Sounds good enough ๐
im shocked to find out there is little to no explenation or guides on batchable materials as the one you did, trust me i searched everywhere
maybe i wrote it wrong as i was searching, not sure if there is a correct naming for this
Maybe ppl are just using URP/HDRP with shader graph and SRP batcher
It's called GPU instancing
oh another question, how do i change normal map strength? everything else does allow me to change except for the normal strength
Oh I forgot to implement that didn't I lol
i do wander if there is any benefit in using built in pipeline or im just wasting my time
in terms of performance
bumpmap *= UNITY_ACCESS_INSTANCED_PROP(Props, _BumpScale); something like this?
oh wait theres another part
wait let me try it
o.Normal = UnpackNormalWithScale(tex2D(_BumpMap, IN.uv_BumpMap), UNITY_ACCESS_INSTANCED_PROP(Props, _BumpScale));
I think this is correct way to do it
like this?
half normals = tex2D(_BumpMap, IN.main_uv).g; normals *= UNITY_ACCESS_INSTANCED_PROP(Props, _BumpScale);
Scaling normal needs some calculation, UnpackNormalWithScale would handle it
i see, well it was worth a try ๐
does it matter after what line i enter it?
oh nvm, its suppose to replace the existing one
Yes
The syntax is similar to C language
yes now its perfect! thank you once again ๐
Yay ๐
oh wait.. now its on different calls ๐ , maybe its because of the normal scale
Actually did you replace it to main_uv lol I write the code based on mine
yup
wait im trying to see if its something that i did
huh ok yeah its something that i did
apparently when you add additional light source, it cancels the batched call for the affected tiles
Ah lighting yes, it breaks some batch
well, it shouldn't cause too much trouble i assume when the whole tile map is batched in one call
Dynamic lighting is always expensive but yeah you should be fine if light source are not everywhere
You might want to look into deferred rendering for this
If you use many dynamic lights
yeah i did check about it and forward suits better for my design ๐