I just finished a Texture atlas shader node and was wondering if @nehon wanted to include it in 3.2
I have no idea how to use git but I will drop the code here for you.
TextureAtlas.j3sn
ShaderNodeDefinitions{
ShaderNodeDefinition TextureAtlas {
Type: Fragment
Shader GLSL100: MatDefs/TextureAtlas100.frag
Documentation{
Outputs the Color by slicing the texture into tiles and using one tile based on tilePosition.
Tile side is defined by tilesWidth and tilesHeight
@input texture2D atlas The Atlas image
@input vec2 tilePosition A 2D vector describing the tile position to use
@input float tileWidth The number of tiles wide
@input float tileHeight The number of tiles heigh
@input vec2 atlasOffset The atlas offset in pixles
@input vec2 inTextCord The texture Cordinates
@output vec4 outColor The output color
}
Input {
sampler2D atlas
vec2 tilePosition
float tileWidth
float tileHeight
vec2 inTextCord
vec2 atlasOffset
}
Output {
vec4 outColor
}
}
}
TextureAtlas100.frag
void main(){
//@input texture2D atlas The Atlas image
//@input vec2 tilePosition A 2D vector describing the tile position to use
//@input float tileWidth The width of the tile in pixles
//@input float tileHeight The height of the tile in pixles
//@input vec2 inTextCord The texture Cordinates
//@input vec2 atlasOffset The atlas offset in pixles
//@output vec4 outColor The output color
//insert glsl code here
float scaleX = 1.0 / tileWidth;
float scaleY = 1.0 / tileHeight;
vec2 realTexCord = inTextCord;
realTexCord.x = realTexCord.x + (atlasOffset.x * scaleX);
realTexCord.y = realTexCord.y + (atlasOffset.y * scaleY);
outColor = texture2D(atlas, vec2((realTexCord.x * scaleX) + tilePosition.x * scaleX , (realTexCord.y * scaleY) + tilePosition.y * scaleY));
}