一次渲染阴影 [英] Render the shadows once for all

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

问题描述

鉴于阴影投射的成本,我想知道是否存在一种功能或一种可能的/实验性的方式来针对动态定位的静态对象(仅在webgl中)在three.js(甚至在webgl中)一次渲染一次阴影贴图。市)。因此,该结果可以在下一帧中用于静态对象,而不会产生任何费用。阴影渲染仅在某些东西移动时才会完成。

Given the cost of shadow casting, i was wondering if there is a feature or a possible/experimental way to render a shadowmap only once in three.js (even in webgl), for static objects positionned dynamically (ex: a procedural city). So the result can be used in next frames for static objects, at no cost. The shadow rendering would be done only when something moves.

推荐答案

EDIT

mrdoobs批准:

mrdoobs approved :

renderer.shadowMap.autoUpdate = false;
renderer.shadowMap.needsUpdate = true; // when scene changes






原始答案:


Original answer :

我找到了自己的方式:我复制了 verticesNeedUpdate 的工作方式。我在WebGLRenderer中添加了 shadowMapNeedsUpdate = true 参数。在ShadowMapPlugin的渲染功能中,我检查此参数是否为true并将其设置为false:

I found my way : i copied the way verticesNeedUpdate works. I added a shadowMapNeedsUpdate = true parameter to the WebGLRenderer. In the render function of the ShadowMapPlugin i check if this paramater is true and set it to false after :

if( _renderer.shadowMapEnabled===false || _renderer.shadowMapNeedsUpdate===false ) return;

_renderer.shadowMapNeedsUpdate = false

这样,阴影贴图在第一次渲染时渲染一次,如果场景需要实时渲染阴影贴图必须在渲染循环中进行精确调整。否则释放计算能力

This way the shadowmap is rendered once at the first rendering, and if the scene requires the realtime shadowmap it has to be precised in the render loop. Otherwise computational power is freed

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

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