Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- float tilesX = max(AtlasGridSize.x, 1.0);
- float tilesY = max(AtlasGridSize.y, 1.0);
- float TileCount = AtlasGridSize.x * AtlasGridSize.y;
- float Index = round((TileCount - 1) * Noise);
- // Clamp index
- float safeIndex = max(Index, 0.0);
- float tileX = fmod(safeIndex, tilesX);
- float tileY = floor(safeIndex / tilesX);
- float2 tileID = float2(tileX, tileY);
- // Build 64x64 grid
- float2 grid = max(NoiseGridSize, float2(1.0, 1.0));
- float2 baseUV = UV * grid;
- float2 cellID = floor(baseUV);
- float2 cellUV = frac(baseUV);// Declare rot outside so it's accessible at the end
- int rot = 0;// Apply rotation only if enabled
- if (UseTextureRotation > 0.5)
- {
- float2 p = cellID;
- p = frac(p * 0.3183099 + float2(0.71, 0.113));
- p *= 17.0;
- float rand = frac(p.x * p.y * (p.x + p.y));
- rot = (int)(rand * 4.0);
- if (rot == 1)
- {
- cellUV = float2(cellUV.y, 1.0 - cellUV.x);
- }
- else if (rot == 2)
- {
- cellUV = 1.0 - cellUV;
- }
- else if (rot == 3)
- {
- cellUV = float2(1.0 - cellUV.y, cellUV.x);
- }
- }
- // Slight padding to avoid bleeding
- //cellUV = cellUV * 0.98 + 0.01;// Atlas UV
- float2 atlasUV;
- atlasUV.x = (tileX + cellUV.x) / tilesX;
- atlasUV.y = (tileY + cellUV.y) / tilesY;// RG = atlas UV, B = rotation index for normal map correction
- return float3(atlasUV, float(rot));
Advertisement
Add Comment
Please, Sign In to add comment