zadvorsky / three.bas

THREE.JS Buffer Animation System

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

DepthAnimationMaterial: Problem casting shadows taking alpha into account

martenzander opened this issue · comments

Hi @zadvorsky,

I have a little problem using the DepthAnimationMaterial. I have a scene with a bunch of instanced grass tufts using the InstancedPrefabBufferGeometry. I want them tufts to cast shadows taking their map's alpha into account. See the image below for an example based on MeshStandardMaterial and MeshDepthMaterial:

Example

In order to achieve this, I have to pass the following parameters to the MeshDepthMaterial in THREE.JS

{ depthPacking: THREE.RGBADepthPacking, map: MY_TEXTURE, alphaTest: 0.5, }.

adding these properties to my DepthAnimationMaterial has no effect besides that shadows disappear. I have the feeling I am missing something fundamental, so I would be very thankful if you could point me in the right direction :)

Thanks in advance and keep up the work!

thanks, I'd really appreciate it

Hello again.

I figured out what's happening, but I'll need more time to implement a proper fix. In the meantime, you'll need to do this:

In your animation material, add a alpha test define, and make sure the depthPacking is under uniformValues.

const material = new StandardAnimationMaterial({
  defines: {
    'ALPHATEST': 0.5
  },
  uniformValues: {
    alphaMap: alphaMapTexture,
    depthPacking: THREE.RGBADepthPacking
  }
})

Then when creating the depth material, set the needsUpdate flag for your alpha map.

mesh.customDepthMaterial = BAS.Utils.createDepthAnimationMaterial(material);
mesh.customDepthMaterial.uniforms.alphaMap.value.needsUpdate = true;

And everything should work, hopefully.

Unfortunately no, still no shadows appearing

Here's a reduced test case with a BAS animation material + alpha map + custom depth material. Can you work from there and see what isn't working for you?

thanks for the effort, I will test this as soon as I am back to work.

hmm still not working. Also added side: THREE.DoubleSide now. As soon as I add 'ALPHATEST': 0.5; to my defines, shadows disappear completely.

Do you have any code you can share?

Unfortunatley no, it would take some time to isolate the code from the rest of my project. Since your demos are working well, I guess the reason for the issue is stuck somewhere else in my code.

As long as I can't confirm the existence of the issue we can consider this as resolved.