Unity 3d exporter missing terrain

Yo @nasimiasl can you please show me the shader code for the texture atlas above… I believe it’s the same texture packing unity PackTextureAtlas function produces

And the rects defining where each texture is in the atlas are already normalized from 0 to 1

Just need to see your solution for fracting to get texture from atlas using the defined rectangle for each texture… please :smiling_face:

the main problem is happen when “texture2D” blur your texture in far places
then the sides image content be effect the main atlas part in blur ed image

and solution : " i need test it after this week "

  1. use “Texture2DLODExt”
    that work fine but the new problem happen in far place

  2. Texture2DLODExt not blur any part and if we calculate the distance and set to LOD parameter
    still we back to Texture2D problem

https://www.babylonjs-playground.com/#FBNKRF#14

  1. so i think we can make 5 level of lmage and define in texture atlas and reference that in 5 level of defeirent distance

4.we draw texture without any lod and we manage it by shader code
i dont know about result yet

level coordinates
1: x-------------------------------,y-----------------------------------, x1----------------------------------- ,y1
2: x1-----------------------------,y-----------------------------------, x1+(x1-x)/2-------------------- ,y1+(y1-y)/2
3: x1-----------------------------,y+(y1-y)/2---------------------, x1+(x1-x)/4 ------------------- ,y+(y1-y)/2+(y1-y)/4
4 x1+(x1-x)/4---------------,y+(y1-y)/2---------------------, x1+(x1-x)/4+(x1-x)/8 ---- ,y+(y1-y)/2+(x1-x)/8
5:x1+(x1-x)/4---------------,y+(y1-y)/2+(y1-y)/8------,x1+(x1-x)/4+(x1-x)/16---- ,y+(y1-y)/2+(y1-y)/8++(y1-y)/16

you can continue n time

Wow bro @nasimiasl … Now thats some shader code (I dont understand it all :))

But hey man, i think we might be talking about Texture Atlas usage for two very different things.

I am talking about using a texture atlas to PACK the terrain layer textures into a texture atlas and maintain each texture’s rectangle (0 to 1) in the atlas so i can pack all the terrain layer textures (up to 12) into one single texture and NOT have to main a separate texture slot properties on the material for each supported texture:

material.terrainTexture1
material.terrainTexture2
material.terrainTexture3
...
material.terrainTexture12   

but instead do something like:

material.terrainTextureAtlas
material.terrainNormalAtlas
material.terrainSplatmapAtlas

and then using the maintained rects as shader vec4 for each:

  • SPLATMAP TEXTURE (mix map)
  • TERRAIN TEXTURE
  • NORMAL TEXTURE

to either fract or texture2DLOD to read the required texture from its atlas and then MIX all those layer textures using its splatmap channel.

I think you are talking about using a Texture Atlas to make SMALLER copies of the SAME image… But not for mixing or splatmaps … but for the proper blur effect for looking at the terrain from FAR AWAY. I assume keeping a separate copy of each LOD level (i think you keep up to 5) and calculating the distance and actually SAMPLE into texture map for the SMALLER LOD image … because each level is lower in resolution, when you LOOK OUT on the terrain as you look further away each LEVEL is just a BIT BLURRIER.

NOTE: I thought the GPU and Mip Mapping was supposed to do this automatically :frowning:

Anyways… If you are saying i need to make a texture atlas for each texture layer image so i can physically maintain MIP LEVEL versions of that texture… Well that kinda defeats the whole PACKING UP TO 12 TEXTURES into an atlas.

i am going to need to do something like this:

material.terrainTextureAtlas1
material.terrainTextureAtlas2
material.terrainTextureAtlas3
...
material.terrainTextureAtlas12   

No that way… Supporting up to 12 Splats/Layers… I would need:
1 terrain splatmap atlas holding up to 4 splatmaps
12 terrain diffuse textures
12 terrain normal textures

Only devices that can support up to 32 MAX_TEXTURES allowed can run terrain :frowning:

I would love to actually talk about what it is means to make a terrain shader vs a everyday diffuse shader used for a cube for example… i assume its a bit different because of how you could be looking at the terrain… either up close or pieces of the
terrain that are far away from your camera view… So let actually hook up…

FYI… I built an entire SHADER MATERIAL SYSTEM in Unity based of what you keep trying to show me with that ShaderBuilder thing. I wrote something in Unity that works the same way but you use it like a normal unity shader asset :slight_smile:

I make a demo video for you…

I would really love for you to PLEASE TRY … just this one time and use my Toolkit and EDIT or FIX UP my shader… I made it as EASY AS POSSIBLE to Create, attach and use a custom shader right in the Unity environment. I will make a video showing you the whole shader system… And using my new PARTIAL SHADER MATERIALS … You can build out the shader chunks EASIER than you can in the sample playground you listed above…

Anyways… i cant really understand that ShaderBuilder… So i made a shader system (Based off what your where doing with that ShaderBuilder) … So Please try and use it… At least this one time to help me with the terrain splatmap shaders :slight_smile:

Ill send a copy of my toolkit for you play with these shaders

Sorry For All The Bolds

:slight_smile:

yes i know but we most fix the texture atlas tile for one texture then we can attach any textures in one or n picture

we can make the final atlas texture in canvas automaticly and make the shader for that
we need can do it by 3 texture

for using 4096x we can have 16 1024x image or 64 512x image

but in this way you have 682 px for 1024( for attach all 5 size )
but in this way you have 342 px for 512( for attach all 5 size )

** 341 px texture

the final result can support 64 PBR material using by 6 channel of sampler and 1 for help us to mix it
for mix 64 texture we need 64 different color
we have 8 color but we cant use the black for this
so we have 7 color so if we use 10 different steps like 25 - 50 - 75 … 255
then we can support 70 ~ 64 level mixing texture

so summery :slight_smile:

64 PBR material + shadow with 342x342 resolution can be available in 8 textures

16 PBR material + shadow with 682x682 resolution can be available in 8 textures

why i keep limit the 8 textures
always you most notice mobile device and always you most keep some uniform free for other animation parts

So what can I do to help…if I send you my new toolkit will you try and use the Shader Material System I setup ???

Just this once :blush:

tasks

  1. make shader use with 8 texture
  2. make atlas function+ make pbr with atlas Index map for shader
    2_1 . we can use fixed or variable parameter for map
  3. make canvas render for build textures (in new format )
  4. Build a new terrianMaterial

i try work on it today

What you mean by use 8 textures. Are you talking about setting up a material that has the 8 textures you are talking about… Like terrainTexture1 thru 8 or something like that ???

What mean use Canvas to build Textures… I can just create a texture atlas in unity using the terrain layer textures… I can also create texture atlas for terrain layer normals and i can pack the up to 4 splatmap/mixmap textures into a texture atlas as well… then i was gonna assign the textures to the PBR material in GLTF using material.extras.metadata.commoncontants.splatmapTexture … Kinda the same way i handle passing lightmapTextures to materials

I wanna start on my side by generating Texture Atlas for the single texture using Unity’s PackTextureAtlas Function.

From what i can tell… you are just taking the ORIGINAL texture (lets say 1024 px for example) and scaling down 4 times to 512, 256, 128, 64 and packing those 5 images into a texture atlas… Or am i wrong about that…???

Just please tell me how many and what size each pseudo mip level to create for each size… And i will make the toolkit start by at least packing the first single base texture splat to test the BLUR shader code using LOD distance

Once i create that first texture atlas … i will send a copy of new toolkit with video showing how to use… All you would have to do is fill in the shader chunk sections :slight_smile:

that is why i asking a sample of Unity export

share your sample unity export

we split that to 1 uniq texture ( + nrm + … )
the we recreate that

we most make the small size for fix edge issue
then we need support more textures

we can use 1024px
for passed a webgl limitation we need change the input ( automaticly )

for show what happen :

we need fix first real LOD bug :

https://www.babylonjs-playground.com/#FBNKRF#21 not complete fully…


** noticf the 3 parts

after we fix that we most get any texture from unity exporter texture
use with canvas and split that to separated textures

then we most make them in new 5 level pic

then we most make atlas texture and reference them to correct place

I will give you whole toolkit (Not ready for public yet)… You can use that if you like.

I made changes to the toolkit to pack textures right from editor…

Here is a Unity Terrain Texture Export (With 5 levels) so hopefuly you can workout the read from a texture atlas taking into account the distance for bluring… If so these Texture Atlas generated from Unity should work perfect.

Note: I am using Unity PackTextures API to pack the final textures. BUT Unity use 0, 0 from bottom left:

That is the unity exported terrain texture for a single splat/layer… looks good to me :slight_smile:

Please try and use that… Note i will get the rect info for where each texture is in the atlas tomorrow… Im sleepy now :slight_smile:

Yo @nasimiasl … Check this out… This is the Unity Terrain with 12 Texture Layers:

It has 12 Textures at 1024 each… Using your texture packing routines with all the extra LOD levels of the image… ITS FITS PERFECT in a 4096 Texture Atlas… So as long as we get the atlas code going in the shader… 12 Terrain Texture Layers Fit Perfect at 1024k for the master image:

Fully Packed Texture Atlas

That is looking really good… Remember bottom left is 0,0 :slight_smile:

3 Likes

Here’s an example showcasing something similar:(Not done by me)

Uses the following atlas:

1 Like

that s happen when i don’t search a lot :slight_smile: and just try
anyway i guess we have some benefit in rewrite that

and the way i collect pics have bigger space

actually we can use unity texture
i can find texture place :slight_smile:

we need read this array

AR =
[1 , 4 , 12 , 5 , 5 ,
2 , 8 , 1 , 4 , 4 ,
3 , 10 , 5 , 6 , 2
4 , 6 , 8 , 7 , 6
5 , 5 , 6 , 12 , 12
6 , 2 , 3 , 9 , 8
7 , 1 , 11, 2, 10
8 , 8 , 3, 11 , 3
9 , 12 , 7 , 10 , 10 ,
10 , 11, 9 , 1, 1,
11 , 7 , 4 , 8 , 11 ,
12 , 3 , 2 , 3 , 7 ];

PX = [ 0 , 0 , 0 , 0 , 1 , 2 , 3 ,3 , 2 , 1, 1 , 1 ] ;
PY = [ 0 , 1 , 2 , 3 , 3 , 3 , 3 , 2 , 2, 2, 1, 0 ] ;

I = currentIndex
T = textureIndex
L = levelIndex

X = [0 , 2048 , 2048+1024, 2048 + 1024 + 512 , 2048 + 1024 + 512 + 256 ];

i = [ T * 5 + L ] ;

position : [ X[L] + px [ i ] * (1024 / L ) , py[ i ] * (1024 / L ) , 1024 / L , 1024 / L ] ;

How can we take a look at that shader code ???

By using the editor: PlayCanvas 3D HTML5 Game Engine
I did a quick copy/paste without much luck, as it still gives artifacts, and without fully understanding the shader, I have no idea where it might go wrong:
EDIT: A slightly cleaned up version, for readability: https://www.babylonjs-playground.com/#LIVRIY#42

Shit… I already had that PlayCanvas project FORKED in my PlayCanvas Account: PlayCanvas 3D HTML5 Game Engine

I looked at these shaders before, he has several different approaches to handle splatmap shaders for terrain… I think the tile16lodatlas or tile16lodbiasatlas is the ones dont have ARTIFACTS but both of these use texture2DLodExt (which i believe is only available in WebGL 2).

If WebGL 2 has to be our MIN WebGL version for Terrain Exports from Unity… I guess im kool with that… HOPEFULLY WEBGL 2 will be EVERYWHERE SOON :slight_smile:

Yo @nasimiasl … What do you think about these Shaders ???

Can we use any of that code… Especially the getMipLevel function ???

What do you think about the artifacts issue WITHOUT using texture2DLODExt… Should we just target WebGL 2 for terrains and just call it a day ???

i don’t have any solution without WITHOUT using texture2DLODExt
** we can accept some edge issue in webgl 1

and i can write a faster shader for terrain ( convert exact unity export to terrain parts )
but as i say i have so busy week

I am kinda glad to see people using the PBRCustomMaterial…

Even though I created the PBRCustomMaterial class (to sync up custom shader support with custom standard materials). I dont actually USE IT.

The only reason i even created that class was to give @Deltakosh a reason to put all those custom #define tags in the main pbr.vertex.fx and pbr.fragment.fx.

I actually create a series of Universal Materials i use from Unity Exporter thats covers the gambit of shader usage. Including a new Partial Shader Material System for both Albedo and Diffues type shaders… Thats why i needed those define tags to be in the default pbr shader programs :slight_smile:

Update:

These are the heart and soul of my shader system:

Yo @nasimiasl … So you say you can make use of the style of texture atlas packing Unity creates.

So you can use this Unity Style Texture Atlas Here: https://www.babylontoolkit.com/files/TestTerrainAtlas.jpg

Note: Bottom Left Is 0,0