Shadows only work with Orthographic camera?

This article says that shadows only work with the Orthographic camera, not Perspective, is that true?

Link removed by moderation as it leads to a malicious site

I followed the article’s code with my scene that is based on a Perspective camera and It’s true, I don’t see any shadows. But I’m hoping there’s still a way to get shadows because to redo my scene with an Orthographic camera would take a lot of work I don’t have time for.

Here’s my current code:

    console.warn(`${errPrefix}Initializing Galaxy Pay.`);

     assignThreeJsCamera(new THREE.PerspectiveCamera(75, window.innerWidth / window.innerHeight, 1, 1000));
    // Set the camera position.
    g_ThreeJsCamera.position.y = 10;

    // -------------------- BEGIN: SOLAR SYSTEM LIGHTS ------------

    // >>>>> BELOW
    const lightBelowSS = new THREE.HemisphereLight(0xeeeeff, 0x777788, 1, ); // 0.75);
    lightBelowSS.position.set(SOLAR_SYSTEM_X_POS, SOLAR_SYSTEM_Y_POS - 3, SOLAR_SYSTEM_Z_POS);

    lightBelowSS.lookAt(g_TheEarth.position);

    g_ThreeJsScene.add(lightBelowSS);

    // >>>>> ABOVE
    // const lightAboveSS = new THREE.DirectionalLight(0xeeeeff, 0x777788, 1, ); // 0.75);
    const lightAboveSS = new THREE.DirectionalLight(0xeeeeff);
    lightAboveSS.position.set(SOLAR_SYSTEM_X_POS, SOLAR_SYSTEM_Y_POS + 3, SOLAR_SYSTEM_Z_POS);

    // Cast shadow.
    lightAboveSS.castShadow = true;
    // Shadow intensity.
    lightAboveSS.shadowDarkness = 0.5;
    // Debugging tool.
    lightAboveSS.shadowCameraVisible = true;

    // Look at the arth.
    lightAboveSS.lookAt(g_TheEarth.position);

    g_ThreeJsScene.add(lightAboveSS);

    // -------------------- END  : SOLAR SYSTEM LIGHTS ------------

Screenshot, no shadows.

Im also having issue shadows work only till certain distance.

  1. Please do not click the link in the first post - it seems to have been hijacked and leads to a phishing site.

  2. @steelx could you post the question as a separate topic? Shadows have certain limitations (FOV, size, and distance), which I’d be happy to explain - but in a separate topic (or you can just use StrandedKitty/three-csm and forget about shadows setup entirely.). This one was reported as spam due to the link in the original post.

3 Likes

Thanks for catching that. It appeared fine when I made the post (didn’t get any warnings from Chrome). I guess someone domain-swapped it.