I have been experimenting with setting my camera as the parent to the volumetric light scattering mesh but I cannot seem to get it to stay in the same place when my camera rotates. If I do the same actions with a box it does. Is there something I’m doing wrong here / misunderstanding?
Edit - forgot the PG code:
// You have to create a function called createScene. This function must return a BABYLON.Scene object
// You can reference the following variables: scene, canvas
// You must at least define a camera
var createScene = function() {
var scene = new BABYLON.Scene(engine);
var camera = new BABYLON.UniversalCamera("Camera", new BABYLON.Vector3(0, -10, 0), scene);
camera.attachControl(canvas, true);
// Create the "God Rays" effect (volumetric light scattering)
var godrays = new BABYLON.VolumetricLightScatteringPostProcess('godrays', 1.0, camera, null, 100, BABYLON.Texture.BILINEAR_SAMPLINGMODE, engine, false);
godrays.mesh.position = new BABYLON.Vector3(-3, 0, 3);
// why does this not seem to rotate with the camera???
godrays.mesh.setParent(camera);
godrays.mesh.setAbsolutePosition(camera.position);
godrays.mesh.position = new BABYLON.Vector3(0,0,3);
// just for reference
var box = BABYLON.MeshBuilder.CreateBox("box", {});
// rotates with camera
var box2 = BABYLON.MeshBuilder.CreateBox("box2", {});
box2.setAbsolutePosition(camera);
box2.setParent(camera);
box2.position = new BABYLON.Vector3(0,0,3);
return scene;
};
@Galen
Thanks for reporting! Checking ASAP
The default mesh for volumetric lights post process is a plane with a billboard mode (ALL x y and z). Have you tested with the cube being the light emitter instead of the plane?
I haven’t tested with a cube as the emitter, however I have applied this to other meshes without an issue. If I get time today, I’ll create a playground scene using a cube as the emitter.
I don’t know if this is what you’re asking, but here is a simple playground scene with a cube as the emitter. I can attach to a moving camera if that’s what you are asking.
I think I know what you’re asking, and will try and build this in the afternoon. I’ll try and replace the billboard with a cube, although I don’t believe this is what the initial question was. @Num_T was using a standard VLS billboard and wanted to parent this to the camera. But it would be interesting to use a different mesh as the emitter.
Billboarding is computed according to the camera. I think that having a billboarded mesh child of the camera creates a cycle and generates wrong values.
This is a little more interesting. The cube is the emitter and parented to the camera. However, it appears there is no way to avoid billboard mode even if it is not set. I can’t seem to create a true volumetric light.