Jump to content

Texture Atlas Tiling At the Shader


MackeyK24
 Share

Recommended Posts

On 4/18/2017 at 0:48 AM, MackeyK24 said:

splatColor = getTileFromAtlasMap(albedoSampler, atlasRect1, atlasInfo1.xy, vTerrainUV) * baseColor1.r; if (atlasInfos > 1.0 && atlasRects > 1.0) { splatColor += getTileFromAtlasMap(albedoSampler, atlasRect2, atlasInfo2.xy, vTerrainUV) * baseColor1.g; } if (atlasInfos > 2.0 && atlasRects > 2.0) { splatColor += getTileFromAtlasMap(albedoSampler, atlasRect3, atlasInfo3.xy, vTerrainUV) * baseColor1.b; } // Second splat colors if (atlasInfos > 3.0 && atlasRects > 3.0) { splatColor += getTileFromAtlasMap(albedoSampler, atlasRect4, atlasInfo4.xy, vTerrainUV) * baseColor2.r; } if (atlasInfos > 4.0 && atlasRects > 4.0) { splatColor += getTileFromAtlasMap(albedoSampler, atlasRect5, atlasInfo5.xy, vTerrainUV) * baseColor2.g; } if (atlasInfos > 5.0 && atlasRects > 5.0) { splatColor += getTileFromAtlasMap(albedoSampler, atlasRect6, atlasInfo6.xy, vTerrainUV) * baseColor2.b; } // Third splat colors if (atlasInfos > 6.0 && atlasRects > 6.0) { splatColor += getTileFromAtlasMap(albedoSampler, atlasRect7, atlasInfo7.xy, vTerrainUV) * baseColor3.r; } if (atlasInfos > 7.0 && atlasRects > 7.0) { splatColor += getTileFromAtlasMap(albedoSampler, atlasRect8, atlasInfo8.xy, vTerrainUV) * baseColor3.g; } if (atlasInfos > 8.0 && atlasRects > 8.0) { splatColor += getTileFromAtlasMap(albedoSampler, atlasRect9, atlasInfo9.xy, vTerrainUV) * baseColor3.b; } // Final splat colors if (atlasInfos > 9.0 && atlasRects > 9.0) { splatColor += getTileFromAtlasMap(albedoSampler, atlasRect10, atlasInfo10.xy, vTerrainUV) * baseColor4.r; } if (atlasInfos > 10.0 && atlasRects > 10.0) { splatColor += getTileFromAtlasMap(albedoSampler, atlasRect11, atlasInfo11.xy, vTerrainUV) * baseColor4.g; } if (atlasInfos > 11.0 && atlasRects > 11.0) { splatColor += getTileFromAtlasMap(albedoSampler, atlasRect12, atlasInfo12.xy, vTerrainUV) * baseColor4.b; }

i think this part make it to different color

you append color  in any step that maybe change your base color

Link to comment
Share on other sites

8 minutes ago, NasimiAsl said:

i think this part make it to different color

you append color  in any step that maybe change your base color

even when i use only one color... Still the same

I will export you out a .babylon scene file with the terrain and the texture atlas images... plus the 0.1 normalized Rect info for where the texture is within the atlas... You should then be able to importMeshes for the terrain and use the rect info manually in your PG code :)

 

Link to comment
Share on other sites

18 hours ago, NasimiAsl said:

make it with your textures too

I can get to load in play ground...

Here is my scene file with just Candylan Terrain mesh:

Terrains.babylon

 

UPDATE

The url to atlas image: http://mackey.cloud/files/terrains_atlas.png

 

The atlas rect for splat 1:

X: 0.0

Y: 0.5

Z: 0.5 (height)

W: 0.25 (width)

Tile X: 20

Tile Y: 20

 

 

Link to comment
Share on other sites

15 minutes ago, NasimiAsl said:

what is atlasInfos???

You must be looking at My UniversialShaderMaterial class ... Thats a combo class i use for all shaders:

Check it out if need be...

babylon.sceneshaders.ts

AtlasInfos have the BabylonTexture.uScale and vScale  (Tile.x and Tile.y)

Just like the Babylon texture.ts sets level and texture coordinates in a uniform...

For example: this._effect.setFloat2("vAlbedoInfos", this.albedoTexture.coordinatesIndex, this.albedoTexture.level);

But in case of terrains: 

Vector4 atlasInfo = new Vector4(Tools.GetTerrainScale(info.TileSize.x), Tools.GetTerrainScale(info.TileSize.y), info.TileOffset.x, info.TileOffset.y);
babylonTerrainMaterial.vectors4.Add("atlasInfo" + (ii + 1).ToString(), atlasInfo.ToFloat());
 
Each atlas texture get a atlas info that has the Tile Size And Offset... So gain.. basically Tile.x and Tile.y

The Atlas Rects contains the texture atlas 'Packing Results" ... a Rect[] each... rect is the X,Y, height and width of the texture within the atlas... Already Normalized 

Vector4 atlasRect = new Vector4(albedoRect.x, albedoRect.y, albedoRect.height, albedoRect.width);

babylonTerrainMaterial.vectors4.Add("atlasRect" + (ii + 1).ToString(), atlasRect.ToFloat());
 
Link to comment
Share on other sites

Hey @NasimiAsl Just so you know... there is still a bit of blur issue as well... Know you are working on the artifact issue but i just wanted you you to be aware of that incase you need to address while your in there:

 

Here is original shot using 9 copy and crop in unity editor:

 

58f80976da747_ScreenShot2017-04-19at3_03_03PM.thumb.png.0b84ddf0d02c2b3195b07117f9435ddd.png

 

And this on in babylon using the 5.0 edgeUvFactor... looks a little blurry compared to unity's render of the same 9 copy crop image:

 

58f809c7480c2_ScreenShot2017-04-19at3_02_44PM.thumb.png.b47c1c59f67d4b3719f60e3c2885fb1e.png

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...