SCN shader modifier in metal - pass uniform to shader

眉间皱痕 提交于 2019-12-07 15:48:41

问题


I'm trying to use shaders modifiers with Metal. I cannot figure out to declare uniforms... 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 outputs a purple texture, with no log.. If I just have _output.color.rgb = (u_color_transformation * _output.color).rgb, things are ok. I think I'm following the doc but maybe not!

The uniform is set with:

material.shaderModifiers =
        [ SCNShaderModifierEntryPoint.fragment: theShaderAbove ]

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

All this was working fine with openGL

Update:

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

// color changes
#pragma arguments
uniform mat4 u_color_transformation;

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

The output is now white (suggesting that at least it compiled), suggesting that u_color_transformation is not passed to the shader, and is resolved to a null matrix in the shader, which gives black which, once inverted, is white.


回答1:


SceneKit assumed you were using glsl because you had vec3(1.0) in your shader body. If you changed that to float3(1.0), it would have used metal and worked without the uniform keyword.



来源:https://stackoverflow.com/questions/39522370/scn-shader-modifier-in-metal-pass-uniform-to-shader

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!