render method

void render(
  1. List<Light> lights,
  2. Object3D scene,
  3. Camera camera
)

Implementation

void render(List<Light> lights, Object3D scene, Camera camera) {
  if (scope.enabled == false) return;
  if (scope.autoUpdate == false && scope.needsUpdate == false) return;

  if (lights.isEmpty) return;

  var currentRenderTarget = _renderer.getRenderTarget();
  var activeCubeFace = _renderer.getActiveCubeFace();
  var activeMipmapLevel = _renderer.getActiveMipmapLevel();

  var _state = _renderer.state;

  // Set GL state for depth map.
  _state.setBlending(NoBlending);
  _state.buffers["color"].setClear(1.0, 1.0, 1.0, 1.0, false);
  _state.buffers["depth"].setTest(true);
  _state.setScissorTest(false);

  // render depth map

  for (var i = 0, il = lights.length; i < il; i++) {
    var light = lights[i];
    var shadow = light.shadow;

    if (shadow == null) {
      // print( 'THREE.WebGLShadowMap: ${light} has no shadow.' );
      continue;
    }

    if (shadow.autoUpdate == false && shadow.needsUpdate == false) continue;

    _shadowMapSize.copy(shadow.mapSize);

    var shadowFrameExtents = shadow.getFrameExtents();
    _shadowMapSize.multiply(shadowFrameExtents);
    _viewportSize.copy(shadow.mapSize);

    if (_shadowMapSize.x > _maxTextureSize ||
        _shadowMapSize.y > _maxTextureSize) {
      if (_shadowMapSize.x > _maxTextureSize) {
        _viewportSize.x =
            Math.floor(_maxTextureSize / shadowFrameExtents.x).toDouble();
        _shadowMapSize.x = _viewportSize.x * shadowFrameExtents.x;
        shadow.mapSize.x = _viewportSize.x;
      }

      if (_shadowMapSize.y > _maxTextureSize) {
        _viewportSize.y =
            Math.floor(_maxTextureSize / shadowFrameExtents.y).toDouble();
        _shadowMapSize.y = _viewportSize.y * shadowFrameExtents.y;
        shadow.mapSize.y = _viewportSize.y;
      }
    }

    if (shadow.map == null &&
        shadow is! PointLightShadow &&
        type == VSMShadowMap) {

      shadow.map = WebGLRenderTarget(
          _shadowMapSize.x.toInt(), _shadowMapSize.y.toInt());
      shadow.map!.texture.name = light.name + '.shadowMap';

      shadow.mapPass = WebGLRenderTarget(
          _shadowMapSize.x.toInt(), _shadowMapSize.y.toInt());

      shadow.camera!.updateProjectionMatrix();
    }

    if (shadow.map == null) {
      var pars = WebGLRenderTargetOptions({
        "minFilter": NearestFilter,
        "magFilter": NearestFilter,
        "format": RGBAFormat
      });

      shadow.map = WebGLRenderTarget(
          _shadowMapSize.x.toInt(), _shadowMapSize.y.toInt(), pars);
      shadow.map!.texture.name = light.name + '.shadowMap';

      shadow.camera!.updateProjectionMatrix();
    }

    _renderer.setRenderTarget(shadow.map);
    _renderer.clear();

    var viewportCount = shadow.getViewportCount();

    for (var vp = 0; vp < viewportCount; vp++) {
      var viewport = shadow.getViewport(vp);

      _viewport.set(
          _viewportSize.x * viewport.x,
          _viewportSize.y * viewport.y,
          _viewportSize.x * viewport.z,
          _viewportSize.y * viewport.w);

      _state.viewport(_viewport);

      shadow.updateMatrices(light, viewportIndex: vp);

      _frustum = shadow.getFrustum();

      renderObject(scene, camera, shadow.camera!, light, type);
    }

    // do blur pass for VSM

    if (shadow is! PointLightShadow && type == VSMShadowMap) {
      VSMPass(shadow, camera);
    }

    shadow.needsUpdate = false;
  }

  scope.needsUpdate = false;

  _renderer.setRenderTarget(
      currentRenderTarget, activeCubeFace, activeMipmapLevel);
}