我尝试从scenekit扩展PBR材料时遇到奇怪的行为。我想做的就是读取纹理,使用第一个uv通道映射它(与正常通道相同)。我提到_surface.diffuseTexcoord
后,_surface.diffuse
似乎变成了白色。它似乎不是常量(_output.rgb = vec3(1.)
),而是通过照明管道传递颜色白色。
let myShader = "#pragma arguments\n" +
"sampler uMaskTex;\n" +
"uniform sampler2D uMaskTex;\n" +
"#pragma body\n" +
//"vec2 myDuv = _surface.diffuseTexcoord;\n" //paints the object white
OR
//"vec3 mask = texture2D( uMaskTex, _surface.diffuseTexcoord ).xyz;\n" //paints the object white
OR
"vec3 mask = texture2D( uMaskTex, vec2(1.) ).xyz;\n" //does not paint the object white
我完全不明白为什么这些频道与"环境","漫反射","镜面反射"当它们存在于_geometry.texcoords[MY_CHANNEL]
的顶点着色器中时。
我尝试通过_geometry.texcoords[0]
转移varying vec2 v_my_abstract_uv_channel_not_diffuse_necesserily
以失败告终。
在做了一些巫术魔术之后,我设法让这个东西以我想要的方式工作,但仍然不知道是什么导致了这种行为。
注意,我在材质的漫反射槽中没有纹理,它被设置为恒定颜色。认为某些事情可能会充满垃圾,但奇怪的是,_surface.diffuseTexcoord
确实包含值并且它们是正确的。它只是提到它会导致一切变白。
然而,我正在使用通过gui分配的普通纹理。
我已经猜到有一个相应的_surface.normalTexcoord
,即使它的未记录,这似乎也有效。即使它包含相同的值,也不会导致材料变白。
"#pragma arguments\n" +
"sampler uMaskTex;\n" +
"uniform sampler2D uMaskTex;\n" +
//"varying vec2 vTexCoord0;\n" + //varyings don't work :( ,
"#pragma body\n" +
"vec3 mask = texture2D(uMaskTex,_surface.diffuseTexcoord).xyz;\n" + //does not work, even though i don't do anything with this variable, it affects _surface.diffuse
"_output.color.rgb = vec3(_surface.diffuseTexcoord,1.);\n" + //actually contains values, not garbage as i thought
"_output.color.rgb = _surface.diffuse.rgb;\n"; //does not work, this outputs white, even though a different color is set
"_output.color.rgb = mask;\n"; //i do however get the texture to map correctly, i do see the texture with _surface.diffuseTexcoord lookup... ?!
另一方面:
"#pragma body\n" +
"vec3 mask = texture2D(uMaskTex,_surface.normalTexcoord).xyz;\n" + //works!
//works! even though there is no mention of this in the documentation.
//Gives exactly the same values as _surface.diffuseTexcoord
"_output.color.rgb = vec3( _surface.normalTexcoord , 1.);\n" +
"_output.color.rgb = _surface.diffuse.rgb;\n"; //works! no gremlins, doesn't turn to white, shows the color from gui!