SCN shader modifier in a metal passage for a shader

I am trying to use shader modifiers with Metal. I can't figure out to declare a form ... So far, my fragment modifier is:

// color changes
#pragma arguments
float4x4 u_color_transformation;

#pragma body
_output.color.rgb = vec3(1.0) - (u_color_transformation * _output.color).rgb;

This displays a purple texture without a log. If I only _output.color.rgb = (u_color_transformation * _output.color).rgb, everything is in order. I think I follow the doc , but maybe not!

Unit is set using:

material.shaderModifiers =
        [ SCNShaderModifierEntryPoint.fragment: theShaderAbove ]

material.setValue(NSValue(mat4: GLKMatrix4Identity), forKey: "u_color_transformation")

It all worked great with openGL

Update:

Apparently, SceneKit shader modifiers use glsl code and take care of converting it to metal. So I changed the shader as follows:

// color changes
#pragma arguments
uniform mat4 u_color_transformation;

#pragma body
_output.color.rgb = vec3(1.0) - (u_color_transformation * _output.color).rgb;

(, ), , u_color_transformation , , .

+3
1

SceneKit , glsl, vec3 (1.0) . float3 (1.0), .

+2

Source: https://habr.com/ru/post/1654885/


All Articles