Is it possible to send an image to a metal shader (from scenekit) without any color/gamma correction?
I have a data texture where each channel corresponds to specific values that I want to be able to test against. It's a world map with the green channel mapping to a country index. The country will be rendered red if it's 'active', grey otherwise.
Here's an example of the code I'm using:
sphereNode = SCNNode(geometry: sphereGeometry)
scene.rootNode.addChildNode(sphereNode)
let program = SCNProgram()
program.vertexFunctionName = "sliceVertex"
program.fragmentFunctionName = "sliceFragment"
sphereNode.geometry?.firstMaterial?.program = program
let imageProperty = SCNMaterialProperty(contents: UIImage(named: "art.scnassets/Textures/earth-data-map-2k.png")!)
mageProperty.mipFilter = SCNFilterMode.none
sphereNode.geometry?.firstMaterial?.setValue(imageProperty, forKey: "dataTexture")
The fragment shader:
fragment float4 sliceFragment(
Vertex in [[stage_in]],
texture2d<float, access::sample> dataTexture [[texture(0)]]
){
constexpr sampler quadSampler(coord::normalized, filter::linear, address::repeat);
float4 color = dataTexture.sample(quadSampler, in.texCoords);
int index = int(color.g * 255.0);
float active = index == 81 ? 1.0 : 0.0;
float3 col = mix(float3(color.g,color.g,color.g), float3(1.0,0.0,0.0), active);
return float4(col.r, col.g, col.b, 1);
}
The problem is that the UIImage that I'm using for the texture seems to be converted into linear space but I want to use the image data unchanged in the shader.