Closed cclaan closed 3 months ago
Hmm, "RealityFoundation.ShaderGraphMaterial.LoadError.invalidTypeFound" usually indicates a bug in this library. Please update as often as possible.
Tracking down the error can be tricky but watch for any yellow warnings in the log just before the invalidTypeError. Please let me know if you catch any.
I've tested a lot with in-memory textures and there might be a bug for local URLs. I will work on a texture example to find out.
Thanks for the report!
I added a texture example to the readme and the tests. I'm still verifying that local resources work but maybe you can compare your code:
Thanks. I tried running your example above, and I get the invalid type error from just running the first 3 lines:
let texture = SGValue.texture2DParameter(name: "ColorTexture")
let color = texture.sample(texcoord: SGValue.uv0)
var mat = try await ShaderGraphMaterial(surface: SGPBRSurface(baseColor: color), geometryModifier: nil)
RealityFoundation.ShaderGraphMaterial.LoadError.invalidTypeFound
I don't see any warnings that seem related.
Thanks for the great library. I encountered the same fatal error, invalidTypeFound, when using texture.sample(texcoord: SGValue.uv0). When using .color3f([1, 0, 0]) instead for example, ShaderGraphMaterial() doesn't throw the fatal error.
@cclaan @ynagatomo I'm pleased to let you know I have located the problem. The texture sampling function was returning a color4f where as the surface baseColor is supposed to be a color3f.
This led me down a long rabbit hole of fixing all the types throughout the library. That led me to working on a v2. I just finished that work and hope you'll upgrade to it. https://github.com/praeclarum/ShaderGraphCoder/releases/tag/2.0.0
There are a couple breaking changes, texture2D
is now just .texture
and .sample
is now .sampleColor3f
or .sampleColor4f
or .sampleVector4f
. Also you can just pass textures to the SGValue texture functions.
I also added a ton more type checking so the Swift types are more sound but also the graph is vigorously checked and will throw errors if there are type mismatches. Hopefully invalidTypeFound
will be a thing of the past.
Thank you! I put a new issue #5 about textures.
Thanks for this great library. I was wondering if it's possible to use a local jpg/png image as input to the baseColor / roughness / metallic of SGPBRSurface ( and if so, if you had a snippet laying around ) I made an attempt using .texture2DParameter, but I can't seem to get it working. I assume I should set the material parameter using something like "mat.setParameter(name: "customTexture", value: .textureResource(baseResource))" but I keep getting odd runtime errors. ( RealityFoundation.ShaderGraphMaterial.LoadError.invalidTypeFound ) Thanks