三.InstancedBufferGeometry 和阴影 [英] THREE.InstancedBufferGeometry and shadows

查看:40
本文介绍了三.InstancedBufferGeometry 和阴影的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在玩实例并且很棒.
现在我试图让每个实例都投下阴影,但没有运气.我制作了一个 Lambert 材质的克隆,添加了位置、比例等的实例处理,并且正在工作,但这只会投射一个阴影:来自位置 (0,0,0) 处的原始几何体的阴影(即使没有实例是在那个位置).
有人可以指出我在哪里可以找到使它起作用还是这是实例或材料的限制?
谢谢.

I'm playing with instances and is awesome.
Now I'm trying to make every instance cast shadows but no luck. I made a clone of Lambert material adding the instance handling for position, scale, etc and is working, but this is casting only one shadow: the one from the original geometry at position (0,0,0) (even if no instance is at that position).
Can someone point me where to look for make it work or is this a limitation of instances or material?
Thanks.

推荐答案

我用这篇文章中的信息修复了这个问题:http://blog.edankwan.com/post/three-js-advanced-tips-shadow

I fixed this with info from this post: http://blog.edankwan.com/post/three-js-advanced-tips-shadow

我复制了 THREE.ShaderLib.depthRGBA.vertexShader 并添加了我在实际绘制实例的材质中的所有属性(平移、缩放、旋转)和代码(使用 THREE.ShaderChunk).THREE.ShaderLib.depthRGBA.fragmentShader 保持不变.

I made a copy of THREE.ShaderLib.depthRGBA.vertexShader and added all attributes (translation, scale, rotation) and code that I have in the material that actually draws the instances (use THREE.ShaderChunk). THREE.ShaderLib.depthRGBA.fragmentShader stays the same.

然后我使用上一步中创建的新 VS 和 FS 创建了一个新的 THREE.ShaderMaterial:

Then I created a new THREE.ShaderMaterial with the new VS and FS created in previous step:

mesh.customDepthMaterial = new THREE.ShaderMaterial({
        vertexShader: <my DepthRGBA vertex shader here>,
        fragmentShader: THREE.ShaderLib.depthRGBA.fragmentShader,
        ....
    });

这篇关于三.InstancedBufferGeometry 和阴影的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆