- Home /
Blending between two parts of a texture atlas, using another texture atlas as an Alpha Channel
For a procedural mesh generator I'm constructing, I'm building a mesh dynamically and assigning it a series of UV sets, based on a pair of texture atlases - one for the main texture (the checkerboard) and one for the borders (the dirt). This just uses a Decal2UVs shader and 2 UV sets - uv1 being the main texture, and uv2 being the border texture
Now while this is perfectly serviceable, I would like to use a lot more border effects, but given all the permutations available for a eight sided border checker, I could only realistically fit five on a ^2 sheet (there are 45 non-blank options per border, not including anything I plan for diagonals - at 64px on a 1024 sheet, that works out to about 5, with some left over).
What I ideally want is to have the border sheet contain Alpha Channels that fade between textures on the texture atlas itself, as on the image below:
I'm not especially good at Shaderlab, understanding only enough to hammer out a basic lerp between alpha after a few hours of tinkering, and certainly not good enough to pull three UV sets out of only two on the mesh. I was reading that there is a possibility of accessing the Vertex Color objects (which I'm not using) and jury-rig those as a third and fourth UVs if I need them.
If someone can point me in the right direction for building this kind of shader that takes two sets of UVs from one texture atlas, another set of UVs from a border texture atlas, and interpolates between the first two using the third as a guide, I would be very grateful. Alternatively, if one already exists out there I'd appreciate that too (either commercial and noncommercial)
This is my current shader code. It shares the border shader with the second instance of the main texture - I need to somehow get a texcoord2 from somewhere
Shader "Custom/BlendTextureAtlasShader" {
Properties {
_Color ("$$anonymous$$ain Color", Color) = (1,1,1,1)
_SpecColor ("Spec Color", Color) = (1,1,1,1)
_Emission ("Emmisive Color", Color) = (0,0,0,0)
_Shininess ("Shininess", Range (0.01, 1)) = 0.7
_$$anonymous$$ainTex ("Base (RGB)", 2D) = "white" {}
_DecalTex ("Decal (RGBA)", 2D) = "black" {}
}
SubShader {
$$anonymous$$aterial {
Diffuse [_Color]
Ambient [_Color]
Shininess [_Shininess]
Specular [_SpecColor]
Emission [_Emission]
}
Tags { "Queue" = "Transparent" }
Pass {
BindChannels {
Bind "texcoord", texcoord// main uses 1st uv
}
Lighting On
SeparateSpecular On
Blend SrcAlpha One$$anonymous$$inusSrcAlpha
SetTexture[_$$anonymous$$ainTex]
}
Pass {
BindChannels {
Bind "texcoord", texcoord1 // main uses 1st uv
Bind "texcoord1", texcoord0 // border needs to use a 3rd UV?
}
Lighting On
SeparateSpecular On
Blend SrcAlpha One$$anonymous$$inusSrcAlpha
SetTexture[_$$anonymous$$ainTex]
SetTexture[_DecalTex] {Combine previous Lerp(texture) texture}
}
}
Fallback " VertexLit", 1
}
Your answer
Follow this Question
Related Questions
shader for light replacement blending, instead of additive blending? 0 Answers
Help with triplanar atlas shader. 2 Answers
Weird shader thing 1 Answer
Shader texture blend performance 0 Answers
Blending Reflection 0 Answers