x_ite icon indicating copy to clipboard operation
x_ite copied to clipboard

EnvironmentLight has no effect (noob question number 3)

Open Wagyx opened this issue 1 year ago • 3 comments

Hello there, I have tried adding an environment light with a color to a default scene with a white cube and the cube remains white.

init();
function init(){
  const xBrowser = X3D.getBrowser();
  const scene = xBrowser.currentScene;

  const envLight = scene.createNode("EnvironmentLight");
  envLight.color = new X3D.SFColor(0,1,1);
  envLight.intensity = 1;
  envLight.ambientIntensity = 1;
  envLight.global = true;
  scene.rootNodes.push(envLight);

  const shape = scene.createNode("Shape");
  const geom = scene.createNode("Box");
  shape.geometry = geom;

  const appearance = scene.createNode("Appearance");
  const material = scene.createNode("Material");
  material.diffuseColor = X3D.Color3.White;
  appearance.material = material;
  shape.appearance = appearance;
  scene.rootNodes.push(shape);
}

I would appreciate your help a lot, what am I doing wrong (again ...) ? Also what is the default light in the scene ? Is it a DirectionalLight or a PointLight on the camera ? How can we change it ?

Wagyx avatar May 03 '24 18:05 Wagyx

EnvironmentLight is still experimental and will only work if you use PhysicalMaterial node, you then should set the diffuseTexture and specularTexture field. Here are some image that will work https://github.com/KhronosGroup/glTF-Sample-Environments/tree/b710a9fe6bcdfb8965530ede36e8279c298261de. A blurred image will be good for diffuse.

Otherwise DirectionalLight, SpotLight, or PointLight are your friends.

The default light is a DirectionalLight, which is tied to the Camera, it can be toggled on/off with a NavigationInfo node, with the headlight field. https://create3000.github.io/x_ite/components/navigation/navigationinfo/#sfbool-in-out-headlight-true

create3000 avatar May 03 '24 20:05 create3000

Okay, I think I'll make a new DirectionalLight with ambient intensity only since I don't have a need for a texture now.

Wagyx avatar May 04 '24 06:05 Wagyx

If you turn on DirectionalLight.ambientIntensity you should also adjust Material.ambientIntensity. ;)

create3000 avatar May 04 '24 07:05 create3000