This is the result I desire, but currently I need 2 detailMaps for this. One for the barcode and one for the white background. Both of this textures are set to clamp and have transparent edges. Barcode as well as the background need to be tinted.
Here is my current shader chunk override for this:
Now to eliminate the second texture for the background I would like to know if it is possible in the shader to know wether I´m in the area of the red square or not (see image below). Which depends on the offset and tiling of the detailMap.
In the shader I could then check:
Outside Area → Diffuse albedo (do nothing/transparent)
Inside Area, but no barcode → Background with tinting
Inside Area and barcode → Barcode with tinting
That would work if I have one barcode, but if I have a second one I do need a second detailMap. Generating the texture at runtime would probably lead to a new set of problems^^
Is it possible to get the offset and tiling of the detailMap in the shader chunk? That would eliminate the need for the background texture, as I could then check if im in the barcode area or outside of it.
I guess I could just add a uniform vec4 and set the offset and tiling to it.
If you know the UVs map between 0-1, then you can skip applying the rectangle if the UV coordinate for your pixel is outside the area. If you define your clipping area as a uniform vec4 containing left, right, top, bottom, then all pixels between 0 < left, right > 1, 0 < top, 1 > bottom can be discarded.
Obviously, to handle tiling and offsets, you’d need to do something more clever, since you’d get a repeating pattern. Something like this should work: