Shadows for DirectionalLights

Okay here’s the deal, i have a world sized 16,215,777x16,215,777, a huge world, generated by chunks, the problem tho is that because the world is so big, the shadows disappear somewhere, i tried this:

 var d = 100;
 directionalLight.shadow.camera.left = - d;
 directionalLight.shadow.camera.right = d;
 directionalLight.shadow.camera.top = d;
 directionalLight.shadow.camera.bottom = - d;

    
 directionalLight.shadow.camera.near = 1;
 directionalLight.shadow.camera.far = 10000;

and it seems to expand the range but not quite to my world size, so i tried this:

	static helper: THREE.CameraHelper;
	static updateLightPosition(v: THREE.Vector3){
		const { directionalLight } = this.lights!;
		const pos = v.clone().addScalar(10);
		directionalLight.position.set(
			pos.x,
			pos.y,
			pos.z
		);
		directionalLight.target.position.set(
			pos.x,
			pos.y,
			pos.z
		);
		this.helper.position.set(
			pos.x,
			pos.y,
			pos.z
		);
		console.log(directionalLight.userData.control.position);
	}

here’s the deal, the directionallight seems to just rotate but not move, and it’s not working as expected at all.

and i found other posts, but people are mostly working with smaller scale scenes… what do i do then?

Are your directional lights moving in real time?
In my case (terrain with static directional lights and trees/objects) I solved this by creating an offscreen scene working like a “photobooth” with similar light settings of the main scene.

before displaying the main scene, I move each instance of any tree/objects with their individual rotation in the “photobooth”, catch their projected shadows on canvas texture, then merge them with the terrain’s material at the correct UV/position. It’s super cheap and still allow realtime shadow (like moving characters) on top of it.

Depending the cases, you may use the lightmap layer of your terrain material.
this way you keep the shadows as separate image source.

This method is only good for very very large terrain with basic objects like trees, when even the most optimized light setup would kill the framerate, It doesn’t solve convoluted structures, I may provide some basic code if needed, it’s still quite tricky to pull off

To answer this specific part: you need to update light’s target matrix if you change it’s position.
directionalLight.target.updateMatrixWorld();
it’s not mentioned anywhere in the docs tho :laughing:

OMFG… dude i ignored it until u said that… how dumb can i be… anyways thanks, btw… anyway you know of to also make the light offset around so that i could make it rotate around the player based on the time?