Post not yet marked as solved
Hi, In SceneKit I pass custom parameters to a metal shader using a SCNAnimation, for example:
let revealAnimation = CABasicAnimation(keyPath: "revealage")
revealAnimation.duration = duration
revealAnimation.toValue = toValue
let scnRevealAnimation = SCNAnimation(caAnimation: revealAnimation)
material.addAnimation(scnRevealAnimation, forKey: "Reveal")
How would I do similar to a metal shader in RealityKit?
I saw in the Octopus example:
//int(params.uniforms().custom_parameter()[0])
But it's commented out and there is no example how to set the custom variable and animate it? (unless I missed it)
Great session BTW
Thanks
Post not yet marked as solved
Hello,
in this project https://developer.apple.com/documentation/arkit/content_anchors/tracking_and_visualizing_faces there is some sample code that describes how to map the camera feed to an object with SceneKit and a shader modifier.
I would like know if there is an easy way to achieve the same thing with a CustomMaterial and RealityKit 2.
Specifically I'm interested in what would be the best way to pass in the background of the RealityKit environment as a texture to the custom shader.
In SceneKit this was really easy as one could just do the following:
material.diffuse.contents = sceneView.scene.background.contents
As the texture input for custom material requires a TextureResource I would probably need a way to create a CGImage from the background or camera feed on the fly.
What I've tried so far is accessing the captured image from the camera feed and creating a CGImage from the pixel buffer like so:
guard
let frame = arView.session.currentFrame,
let cameraFeedTexture = CGImage.create(pixelBuffer: frame.capturedImage),
let textureResource = try? TextureResource.generate(from: cameraFeedTexture, withName: "cameraFeedTexture", options: .init(semantic: .color))
else {
return
}
// assign texture
customMaterial.custom.texture = .init(textureResource)
extension CGImage {
public static func create(pixelBuffer: CVPixelBuffer) -> CGImage? {
var cgImage: CGImage?
VTCreateCGImageFromCVPixelBuffer(pixelBuffer, options: nil, imageOut: &cgImage)
return cgImage
}
}
This seems wasteful though and is also quite slow.
Is there any other way to accomplish this efficiently or would I need to go the post processing route?
In the sample code the displayTransform for the view is also being passed as a SCNMatrix4. CustomMaterial custom.value only accepts a SIMD4 though. Is there another way to pass in the matrix?
Another idea I've had was to create a CustomMaterial from an OcclusionMaterial which already seems to contain information about the camera feed but so far had no luck with it.
Thanks for the support!
Post not yet marked as solved
Can i use PhotogrammetrySession on the centos7
Post not yet marked as solved
I would like to pass in a cube map to a custom material shader in RealityKit 2 so I can achieve effects like custom reflections and iridescence.
I am aware of material.custom.texture and material.custom.value as talked about here:
https://developer.apple.com/forums/thread/682632
But those only allow for a 2D texture and a simd_float4 (a vector of 4 float values).
And I am aware of how to pass in animatable custom parameters as talked about here:
https://developer.apple.com/forums/thread/682632
But I would like to be able to sample a cube map instead of a 2D texture. Any help is much appreciated.
Post not yet marked as solved
hi
In my M1 iPad Pro gets to 25 fps after 20 seconds and same for my iPhone pro 12
seems to happen when scenereeconstruction is on
is this going to be improved?
or should I just stick with SceneKit?
Post not yet marked as solved
Dear all,
In "Explore advanced rendering with RealityKit 2," Courtland presents how one can efficiently leverage dynamic meshes in RealityKit and update them at runtime.
My question is quite practical: Say, I have
a model of fixed topology and
a set of animations (coordinates of each vertex per frame, finite duration)
that I can only generate at runtime.
How do I drive the mesh updates at 60FPS?
Can I define a reusable Animation Resource for every animation once at startup and then schedule their playback like simple transform animations?
Any helpful reply pointing me in the right direction is appreciated. Thank you.
~ Alexander