Guest User

Untitled

a guest
Apr 17th, 2026
202
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.33 KB | None | 0 0
  1. float tilesX = max(AtlasGridSize.x, 1.0);
  2. float tilesY = max(AtlasGridSize.y, 1.0);
  3. float TileCount = AtlasGridSize.x * AtlasGridSize.y;
  4. float Index = round((TileCount - 1) * Noise);
  5. // Clamp index
  6. float safeIndex = max(Index, 0.0);
  7. float tileX = fmod(safeIndex, tilesX);
  8. float tileY = floor(safeIndex / tilesX);
  9. float2 tileID = float2(tileX, tileY);
  10. // Build 64x64 grid
  11. float2 grid = max(NoiseGridSize, float2(1.0, 1.0));
  12. float2 baseUV = UV * grid;
  13. float2 cellID = floor(baseUV);
  14. float2 cellUV = frac(baseUV);// Declare rot outside so it's accessible at the end
  15. int rot = 0;// Apply rotation only if enabled
  16. if (UseTextureRotation > 0.5)
  17. {
  18.     float2 p = cellID;
  19.     p = frac(p * 0.3183099 + float2(0.71, 0.113));
  20.     p *= 17.0;
  21.     float rand = frac(p.x * p.y * (p.x + p.y));
  22.     rot = (int)(rand * 4.0);
  23.     if (rot == 1)
  24.     {
  25.         cellUV = float2(cellUV.y, 1.0 - cellUV.x);
  26.     }
  27.     else if (rot == 2)
  28.     {
  29.         cellUV = 1.0 - cellUV;
  30.     }
  31.     else if (rot == 3)
  32.     {
  33.         cellUV = float2(1.0 - cellUV.y, cellUV.x);
  34.     }
  35. }
  36.  
  37. // Slight padding to avoid bleeding
  38. //cellUV = cellUV * 0.98 + 0.01;// Atlas UV
  39.  
  40. float2 atlasUV;
  41. atlasUV.x = (tileX + cellUV.x) / tilesX;
  42. atlasUV.y = (tileY + cellUV.y) / tilesY;// RG = atlas UV, B = rotation index for normal map correction
  43. return float3(atlasUV, float(rot));
Advertisement
Add Comment
Please, Sign In to add comment