金属中的SCN着色器修改器-将统一传递给着色器 [英] SCN shader modifier in metal - pass uniform to shader

查看:102
本文介绍了金属中的SCN着色器修改器-将统一传递给着色器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图将着色器修改器与Metal结合使用.我想不出要申报制服...到目前为止,我的片段修饰符是:

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;

这将输出紫色纹理,没有日志.如果我只有_output.color.rgb = (u_color_transformation * _output.color).rgb,一切正常.我认为我正在遵循 doc ,但也许没有!

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!

制服设置为:

material.shaderModifiers =
        [ SCNShaderModifierEntryPoint.fragment: theShaderAbove ]

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

所有这些在openGL上都可以正常工作

All this was working fine with openGL

更新:

显然,SceneKit着色器修改器使用glsl代码,并注意将其转换为金属.所以我将着色器更改为:

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;

现在输出为白色(建议至少已编译),这表明u_color_transformation没有传递给着色器,而是解析为着色器中的空矩阵,这将产生黑色,一旦反转,黑色即为白色

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.

推荐答案

SceneKit假定您正在使用glsl,因为着色器主体中包含vec3(1.0).如果将其更改为float3(1.0),它将使用metal且无需使用统一关键字即可工作.

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.

这篇关于金属中的SCN着色器修改器-将统一传递给着色器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆