SCNShadable 没有动画

SCNShadable not animating

更新:

我有一个基本的 SceneKit 渲染一个盒子。

我正在尝试使用我在网上找到的简单片段着色器在侧面获得一种波浪效果。

着色器设置遵循指南,但没有效果。

        let box = SCNBox(width: 250, height: 250, length: 250, chamferRadius: 0)

        let greenMaterial = SCNMaterial()
        greenMaterial.diffuse.contents = UIImage(named: "water_seamless_day")
        greenMaterial.locksAmbientWithDiffuse = true

        let redMaterial = SCNMaterial()
        redMaterial.diffuse.contents = UIImage(named: "water_seamless_day")
        redMaterial.locksAmbientWithDiffuse = true

        let blueMaterial  = SCNMaterial()
        blueMaterial.diffuse.contents = UIImage(named: "water_seamless_day")
        blueMaterial.locksAmbientWithDiffuse = true

        let yellowMaterial = SCNMaterial()
        yellowMaterial.diffuse.contents = UIImage(named: "water_seamless_day")
        yellowMaterial.locksAmbientWithDiffuse = true

        let purpleMaterial = SCNMaterial()
        purpleMaterial.diffuse.contents = UIImage(named: "water_seamless_day")
        purpleMaterial.locksAmbientWithDiffuse = true

        let whiteMaterial = SCNMaterial()
        whiteMaterial.diffuse.contents = UIImage(named: "water_seamless_day")
        whiteMaterial.locksAmbientWithDiffuse   = true

        box.materials =  [greenMaterial,
                          redMaterial,
                          blueMaterial,
                          yellowMaterial,
                          purpleMaterial,
                          whiteMaterial]

        box.firstMaterial?.normal.contents = UIImage(named: "waterNormal.png")

        let shaders = [SCNShaderModifierEntryPoint.fragment : "// Elapsed time in seconds            float waterSpeed = u_time * -0.1;// Texture coordinates that will be used to sample the normal map vec2 uvs = _surface.normalTexcoord; uvs.x *= 2;// Sample the normal map vec3 tn = texture2D(u_normalTexture, vec2(uvs.x, uvs.y + waterSpeed)).xyz; // The texture stores values in the [0, 1] range// Express the coordinates of the normal vector in the [-1, +1] range tn = tn * 2 - 1; // Sample the normal map again, using the `waterSpeed` offset this time // in order to produce the animation effect vec3 tn2 = texture2D(u_normalTexture, vec2(uvs.x + 0.35 , uvs.y + 0.35 + (waterSpeed * 1.3))).xyz; tn2 = tn2 * 2 - 1;  // Combine the two normals (static and animated) to produce a richer (more complex and less uniform) effect  vec3 rn = (tn + tn2) * 0.5;// Normals in the normal map are expressed in tangent space // Convert them to object space and override the surface normal to simulate wavelets mat3 ts = mat3(_surface.tangent, _surface.bitangent, _surface.geometryNormal); _surface.normal = normalize(ts * rn);"  , SCNShaderModifierEntryPoint.surface : "float waterSpeed = u_time * -0.1;vec2 uvs = _surface.normalTexcoord;uvs.x *= 2;vec3 tn = texture2D(u_normalTexture, vec2(uvs.x, uvs.y + waterSpeed)).xyz;tn = tn * 2 - 1;vec3 tn2 = texture2D(u_normalTexture, vec2(uvs.x + 0.35 , uvs.y + 0.35 + (waterSpeed * 1.3))).xyz;tn2 = tn2 * 2 - 1;vec3 rn = (tn + tn2) * 0.5;mat3 ts = mat3(_surface.tangent, _surface.bitangent, _surface.geometryNormal);_surface.normal = normalize(ts * rn);"]

        box.firstMaterial?.shaderModifiers = shaders

        let boxNode = SCNNode(geometry: box)

        self.scene?.rootNode.addChildNode(boxNode)

        self.sceneKitView?.rendersContinuously = true

使用新的着色器代码进行编辑。

此着色器代码绝对不是 SceneKit 着色器修改器。您发布的 link 中有一个片段显示了正确的结构。