<p dir="auto">I know you can alter the darkness of the shadow cast based on the light itself:<br>
light.shadowDarkness = 0.5;</p>
<p dir="auto">but say i have objects with materials of various opacities:<br>
var material = new THREE.MeshPhongMaterial( { color : 0x000000, opacity:0.1} );<br>
material.transparent = true;</p>
<p dir="auto">all of the shadows are the same darkness. Is there any way for to make the shadows adjust the darkness based on the shadow-casting objects opacity? (more translucent objects cast a lighter shadow)</p>
<h5 dir="auto">Description of the problem</h5>
<p dir="auto">Just as the issue title indicated, I create an InstancedMesh with more than one instances at different positions, but it's just the Box3 result of the Geometry attached to it. After reading the code, I have made a fix.</p>
<div class="highlight highlight-source-js notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="var _box = new THREE.Box3();
var _vector = new THREE.Vector3();
THREE.Box3.prototype.expandByObject = function (object) {

    // Computes the world-axis-aligned bounding box of an object (including its children),
    // accounting for both the object's, and children's, world transforms

    object.updateWorldMatrix(false, false);

    var geometry = object.geometry;

    if (geometry !== undefined) {

        if (geometry.boundingBox === null) {

            geometry.computeBoundingBox();

        }

        if (object.isInstancedMesh) {
            var matrixWorld = object.matrixWorld,
                matrix4Array = object.instanceMatrix.array,
                arrayLength = matrix4Array.length;
            for (var posOffset = 12; posOffset &lt; arrayLength; posOffset += 16) {
                _vector.set(matrix4Array[posOffset], matrix4Array[1 + posOffset], matrix4Array[2 + posOffset]);
                _box.expandByPoint(_vector);
            }
        } else {
            _box.copy(geometry.boundingBox);
        }
        _box.applyMatrix4(object.matrixWorld);

        this.expandByPoint(_box.min);
        this.expandByPoint(_box.max);

    }

    var children = object.children;

    for (var i = 0, l = children.length; i &lt; l; i++) {

        this.expandByObject(children[i]);

    }

    return this;
}"><pre class="notranslate"><span class="pl-k">var</span> <span class="pl-s1">_box</span> <span class="pl-c1">=</span> <span class="pl-k">new</span> <span class="pl-c1">THREE</span><span class="pl-kos">.</span><span class="pl-c1">Box3</span><span class="pl-kos">(</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
<span class="pl-k">var</span> <span class="pl-s1">_vector</span> <span class="pl-c1">=</span> <span class="pl-k">new</span> <span class="pl-c1">THREE</span><span class="pl-kos">.</span><span class="pl-c1">Vector3</span><span class="pl-kos">(</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
<span class="pl-c1">THREE</span><span class="pl-kos">.</span><span class="pl-c1">Box3</span><span class="pl-kos">.</span><span class="pl-c1">prototype</span><span class="pl-kos">.</span><span class="pl-en">expandByObject</span> <span class="pl-c1">=</span> <span class="pl-k">function</span> <span class="pl-kos">(</span><span class="pl-s1">object</span><span class="pl-kos">)</span> <span class="pl-kos">{</span>

    <span class="pl-c">// Computes the world-axis-aligned bounding box of an object (including its children),</span>
    <span class="pl-c">// accounting for both the object's, and children's, world transforms</span>

    <span class="pl-s1">object</span><span class="pl-kos">.</span><span class="pl-en">updateWorldMatrix</span><span class="pl-kos">(</span><span class="pl-c1">false</span><span class="pl-kos">,</span> <span class="pl-c1">false</span><span class="pl-kos">)</span><span class="pl-kos">;</span>

    <span class="pl-k">var</span> <span class="pl-s1">geometry</span> <span class="pl-c1">=</span> <span class="pl-s1">object</span><span class="pl-kos">.</span><span class="pl-c1">geometry</span><span class="pl-kos">;</span>

    <span class="pl-k">if</span> <span class="pl-kos">(</span><span class="pl-s1">geometry</span> <span class="pl-c1">!==</span> <span class="pl-c1">undefined</span><span class="pl-kos">)</span> <span class="pl-kos">{</span>

        <span class="pl-k">if</span> <span class="pl-kos">(</span><span class="pl-s1">geometry</span><span class="pl-kos">.</span><span class="pl-c1">boundingBox</span> <span class="pl-c1">===</span> <span class="pl-c1">null</span><span class="pl-kos">)</span> <span class="pl-kos">{</span>

            <span class="pl-s1">geometry</span><span class="pl-kos">.</span><span class="pl-en">computeBoundingBox</span><span class="pl-kos">(</span><span class="pl-kos">)</span><span class="pl-kos">;</span>

        <span class="pl-kos">}</span>

        <span class="pl-k">if</span> <span class="pl-kos">(</span><span class="pl-s1">object</span><span class="pl-kos">.</span><span class="pl-c1">isInstancedMesh</span><span class="pl-kos">)</span> <span class="pl-kos">{</span>
            <span class="pl-k">var</span> <span class="pl-s1">matrixWorld</span> <span class="pl-c1">=</span> <span class="pl-s1">object</span><span class="pl-kos">.</span><span class="pl-c1">matrixWorld</span><span class="pl-kos">,</span>
                <span class="pl-s1">matrix4Array</span> <span class="pl-c1">=</span> <span class="pl-s1">object</span><span class="pl-kos">.</span><span class="pl-c1">instanceMatrix</span><span class="pl-kos">.</span><span class="pl-c1">array</span><span class="pl-kos">,</span>
                <span class="pl-s1">arrayLength</span> <span class="pl-c1">=</span> <span class="pl-s1">matrix4Array</span><span class="pl-kos">.</span><span class="pl-c1">length</span><span class="pl-kos">;</span>
            <span class="pl-k">for</span> <span class="pl-kos">(</span><span class="pl-k">var</span> <span class="pl-s1">posOffset</span> <span class="pl-c1">=</span> <span class="pl-c1">12</span><span class="pl-kos">;</span> <span class="pl-s1">posOffset</span> <span class="pl-c1">&lt;</span> <span class="pl-s1">arrayLength</span><span class="pl-kos">;</span> <span class="pl-s1">posOffset</span> <span class="pl-c1">+=</span> <span class="pl-c1">16</span><span class="pl-kos">)</span> <span class="pl-kos">{</span>
                <span class="pl-s1">_vector</span><span class="pl-kos">.</span><span class="pl-en">set</span><span class="pl-kos">(</span><span class="pl-s1">matrix4Array</span><span class="pl-kos">[</span><span class="pl-s1">posOffset</span><span class="pl-kos">]</span><span class="pl-kos">,</span> <span class="pl-s1">matrix4Array</span><span class="pl-kos">[</span><span class="pl-c1">1</span> <span class="pl-c1">+</span> <span class="pl-s1">posOffset</span><span class="pl-kos">]</span><span class="pl-kos">,</span> <span class="pl-s1">matrix4Array</span><span class="pl-kos">[</span><span class="pl-c1">2</span> <span class="pl-c1">+</span> <span class="pl-s1">posOffset</span><span class="pl-kos">]</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
                <span class="pl-s1">_box</span><span class="pl-kos">.</span><span class="pl-en">expandByPoint</span><span class="pl-kos">(</span><span class="pl-s1">_vector</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
            <span class="pl-kos">}</span>
        <span class="pl-kos">}</span> <span class="pl-k">else</span> <span class="pl-kos">{</span>
            <span class="pl-s1">_box</span><span class="pl-kos">.</span><span class="pl-en">copy</span><span class="pl-kos">(</span><span class="pl-s1">geometry</span><span class="pl-kos">.</span><span class="pl-c1">boundingBox</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
        <span class="pl-kos">}</span>
        <span class="pl-s1">_box</span><span class="pl-kos">.</span><span class="pl-en">applyMatrix4</span><span class="pl-kos">(</span><span class="pl-s1">object</span><span class="pl-kos">.</span><span class="pl-c1">matrixWorld</span><span class="pl-kos">)</span><span class="pl-kos">;</span>

        <span class="pl-smi">this</span><span class="pl-kos">.</span><span class="pl-en">expandByPoint</span><span class="pl-kos">(</span><span class="pl-s1">_box</span><span class="pl-kos">.</span><span class="pl-c1">min</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
        <span class="pl-smi">this</span><span class="pl-kos">.</span><span class="pl-en">expandByPoint</span><span class="pl-kos">(</span><span class="pl-s1">_box</span><span class="pl-kos">.</span><span class="pl-c1">max</span><span class="pl-kos">)</span><span class="pl-kos">;</span>

    <span class="pl-kos">}</span>

    <span class="pl-k">var</span> <span class="pl-s1">children</span> <span class="pl-c1">=</span> <span class="pl-s1">object</span><span class="pl-kos">.</span><span class="pl-c1">children</span><span class="pl-kos">;</span>

    <span class="pl-k">for</span> <span class="pl-kos">(</span><span class="pl-k">var</span> <span class="pl-s1">i</span> <span class="pl-c1">=</span> <span class="pl-c1">0</span><span class="pl-kos">,</span> <span class="pl-s1">l</span> <span class="pl-c1">=</span> <span class="pl-s1">children</span><span class="pl-kos">.</span><span class="pl-c1">length</span><span class="pl-kos">;</span> <span class="pl-s1">i</span> <span class="pl-c1">&lt;</span> <span class="pl-s1">l</span><span class="pl-kos">;</span> <span class="pl-s1">i</span><span class="pl-c1">++</span><span class="pl-kos">)</span> <span class="pl-kos">{</span>

        <span class="pl-smi">this</span><span class="pl-kos">.</span><span class="pl-en">expandByObject</span><span class="pl-kos">(</span><span class="pl-s1">children</span><span class="pl-kos">[</span><span class="pl-s1">i</span><span class="pl-kos">]</span><span class="pl-kos">)</span><span class="pl-kos">;</span>

    <span class="pl-kos">}</span>

    <span class="pl-k">return</span> <span class="pl-smi">this</span><span class="pl-kos">;</span>
<span class="pl-kos">}</span></pre></div>
<p dir="auto">See also:</p>
<ul dir="auto">
<li><a href="https://github.com/mrdoob/three.js/blob/master/src/math/Box3.js">Box3.expandByObject</a></li>
<li><a href="https://https://threejs.org/docs/index.html#api/en/math/Box3.setFromObject" rel="nofollow">Box3.setFromObject</a></li>
<li><a href="https://threejs.org/docs/index.html#api/en/objects/InstancedMesh.instanceMatrix" rel="nofollow">InstancedMesh.instanceMatrix</a></li>
<li><a href="https://github.com/mrdoob/three.js/blob/master/src/core/BufferAttribute.js">BufferAttribute.getX</a></li>
<li><a href="https://github.com/mrdoob/three.js/blob/master/src/math/Matrix4.js">Matrix4.setPosition</a></li>
</ul>
<p dir="auto">Please also include a live example if possible. You can start from these templates:</p>
<ul dir="auto">
<li><a href="https://jsfiddle.net/fang3s/Lb814th5/39/" rel="nofollow">jsfiddle</a> (dev branch 39)</li>
<li><a href="https://jsbin.com/honeji/edit?html,css,js,output" rel="nofollow">jsbin</a> (latest release branch)</li>
<li><a href="https://codepen.io/kekkou/pen/GRJZrYw?editors=1010" rel="nofollow">codepen</a>(latest release branch)</li>
</ul>
<h5 dir="auto">Three.js version</h5>
<ul class="contains-task-list">
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox" checked=""> Dev</li>
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox" checked=""> r113</li>
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox"> ...</li>
</ul>
<h5 dir="auto">Browser</h5>
<ul class="contains-task-list">
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox" checked=""> All of them</li>
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox"> Chrome</li>
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox"> Firefox</li>
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox"> Internet Explorer</li>
</ul>
<h5 dir="auto">OS</h5>
<ul class="contains-task-list">
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox" checked=""> All of them</li>
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox"> Windows</li>
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox"> macOS</li>
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox"> Linux</li>
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox"> Android</li>
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox"> iOS</li>
</ul>
<h5 dir="auto">Hardware Requirements (graphics card, VR Device, ...)</h5>