Error with physically based rendering and custom ScnGeometry

I found a nice example of how to create a procedurally generated terrain using custom ScnGeometry


https://medium.com/@rogerboesch/scenekit-tutorial-from-zero-to-hero-part-i-c3f56063b54c


As soon as I add a normal map and/or displacement map to the terrain class, I start getting these errors:



Compiler error while building render pipeline state for node <C3DNode:0x103b10a40 "(null)"
  geometry: <C3DGeometry:0x282b3c410 "(null)"
  mesh: <C3DMesh 0x28293c000 "(null)"
  element0: <C3DMeshElement 0x28293c0e0 type:triangles primCount:204160 channels:1 indexBytes:4 offset:0 acmr:2.000000 inst:1 dataSize:2449920 shared:0x0>
  source position (channel:0) : <C3DMeshSource 0x283b3e8b0(position) data:(0x280576580) mut:0 count:409600 type:float3 divisor:0 mtl:0 offset:0 stride:12>
  source normal (channel:0) : <C3DMeshSource 0x283b3e920(normal) data:(0x280576740) mut:0 count:409600 type:float3 divisor:0 mtl:0 offset:0 stride:12>
  source texcoord (channel:0) : <C3DMeshSource 0x283b3e990(texcoord) data:(0x280576780) mut:0 count:408320 type:float2 divisor:0 mtl:0 offset:0 stride:8>

mat0: <C3DMaterial 0x283b3ea00 : "(null)"common profile <C3DCommonProfileEffect 0x28273c370 : lightingModel:SCNLightingModelPhysicallyBased perPixelLit:1 isOpaque:1 transparencyMode:0[Diffuse] texture:1 xform:0[Normal] texture:1 xform:0[Roughness] texture:1 xform:0[Displacement] texture:1 xform:0>>>>:
Error Domain=AGXMetalA12 Code=3 "Vertex attribute 2 is not defined in the vertex descriptor." UserInfo={NSLocalizedDescription=Vertex attribute 2 is not defined in the vertex descriptor.}


[SceneKit] Error: error in C3DMeshCreateTangentsIfNeeded

[SceneKit] Error: Cannot generate valid tangents without valid texture coordinates



material.lightingModel = .physicallyBased
material.diffuse.contents = UIImage(named: "art.scnassets/coral_mud_01_diff_1k.jpg")
material.normal.contents = UIImage(named: "art.scnassets/coral_mud_01_Nor_1k.jpg")
material.displacement.contents = UIImage(named: "art.scnassets/coral_mud_01_bump_1k.jpg")
material.roughness.contents = UIImage(named: "art.scnassets/coral_mud_01_rough_1k.jpg")


The texture coordinates seem to work, since the terrain renders with a texture as long as I don't use a normal or displaement map. I'm not sure how to fix this error since internet searches for these erroes have yielded few or no results. I hoping someone here recognizes these errors and could point me towards a solution.


Does anyone know of any working examples of custom geometries that also use phsically based rendering?

Replies

hello,i have the same problem.do you hava solved it? i am so ....pzzled.

i know how to fix it ,so happy