Yea sure.
So. this is how I am setting vertex coordinate according to the coordinates coming from server.
vertices = [
Vertex(position: SIMD3(Float(topLeft.x), Float(topLeft.y), 0), color: SIMD4(1, 0, 0, 1), texture: SIMD2(0, 1)),
Vertex(position: SIMD3(Float(bottomLeft.x), Float(bottomLeft.y), 0), color: SIMD4(0, 1 , 0, 1), texture: SIMD2(0, 0)),
Vertex(position: SIMD3(Float(bottomRight.x), Float(bottomRight.y), 0), color: SIMD4(0, 0, 1, 1), texture: SIMD2(1, 0)),
Vertex(position: SIMD3(Float(topRight.x), Float(topRight.y), 0), color: SIMD4(1, 0, 1, 1), texture: SIMD2(1, 1))
]
Now this how I am setting texture,
commandEncoder.setFragmentTexture(texture, index: 0)
commandEncoder.setFragmentTexture(maskTexture, index: 1)
Now for the first texture, I want the image to be setup according. to coordinates.
And for second mask texture, it should be full screen texture.
But somehow mask texture is also. taking the same vertex. data (as shown. in above image).
My vertex function.
vertex VertexOut vertex_shader(const VertexIn vertexIn [[ stage_in ]]) {
VertexOut vertexOut;
vertexOut.position = vertexIn.position;
vertexOut.color = vertexIn.color;
vertexOut.textureCoordinates = vertexIn.textureCoordinates;
vertexOut.points = vertexIn.points;
return vertexOut;
}
My fragment function,
fragment float4 textured_mask_fragment(VertexOut vertexIn [[stage_in]],
texture2d<float> srcTexture [[texture(0)]],
texture2d<float> maskTexture [[texture(1)]],
sampler sampler2d [[sampler(0)]],
constant int &maskComponent [[ buffer(0) ]]) {
float4 srcColor = srcTexture.sample(sampler2d, vertexIn.textureCoordinates);
float4 maskColor = maskTexture.sample(sampler2d, vertexIn.textureCoordinates);
if (is_null_texture(maskTexture)) {
return srcColor;
}
float4 maskedColor;
if (maskComponent == 3) { // means no mask channel
maskedColor = srcColor;
} else {
maskedColor = srcColor * maskColor[maskComponent];
}
return maskedColor;
}.
It's just like for every quad I am adding, I have to multiply the colors with the full screen texture. But the the mask. texture is not coming to. full screen, it is taking same as the vertex data I added for quad.