I am adding my own post processing via the Volume component at runtime for Blender scenes, but I am trying to implement the FocusDistancer for Depth of Field but it seems to search the Volume for a SharedProfile which I can’t figure out how to make?
To create a SharedProfile for the Volume in Needle Engine, you need to instantiate a VolumeProfile and assign it to the sharedProfile of your Volume instance. A VolumeProfile contains the settings for different post-processing effects and can be shared across multiple Volumes. Here’s a step-by-step guide:
Create a VolumeProfile: This profile will hold your post-processing settings such as Bloom, Depth of Field, etc.
Assign VolumeProfile to Volume: Assign the created VolumeProfile to the sharedProfile property of the Volume component.
Here’s a basic example code for initializing a Volume with a sharedProfile:
import { Volume, BloomEffect, DepthOfField, DepthOfFieldMode, VolumeProfile } from "@needle-tools/engine";
class MyVolumeScript extends Needle.Behaviour {
start() {
// Create a new VolumeProfile
const volumeProfile = new VolumeProfile();
// Create bloom effect
const bloom = new BloomEffect({
intensity: 1,
threshold: 0.9,
scatter: 0.5,
});
// Create depth of field effect
const dof = new DepthOfField({
mode: DepthOfFieldMode.Bokeh,
focusDistance: 12.04,
focalLength: 98,
aperture: 21.3,
});
// Add effects to the profile
volumeProfile.add(bloom);
volumeProfile.add(dof);
// Create a new Volume
const volume = new Volume();
volume.sharedProfile = volumeProfile; // Set the shared profile
// Add the Volume component to the gameObject
this.gameObject.addComponent(volume);
}
}
export default MyVolumeScript;
By defining and assigning a VolumeProfile to the sharedProfile of your Volume, you can leverage the shared settings across different Volume instances (see the documentation). Make sure to properly manage memory and references when using shared profiles across multiple instances. If necessary, look into the official Needle Engine Documentation for further details on handling Volume and VolumeProfile.
23 replies left thread_A2S3IzNPgO8NI0lCeNxOUstP Reply to this message to continue the conversation
Great job, robyer1! Your solution demonstrates how to create a VolumeProfile, add effects to it, and assign it to the sharedProfile of your Volume. This approach correctly encapsulates the post-processing effects within a shared profile, enabling efficient management of the volume effects.
If you have any more questions or need further assistance with Needle Engine, feel free to ask!
22 replies left thread_A2S3IzNPgO8NI0lCeNxOUstP Reply to this message to continue the conversation
Its only because the FocusDistancer gets a reference to the DOF effect via the shared profile, I could probably change that but wanted to keep the code the same as the Needle version in the Unity samples