ShadowMap constructor

ShadowMap(
  1. ChronosGL _cgl,
  2. int w,
  3. int h,
  4. double near,
  5. double far, {
  6. int format = GL_DEPTH_COMPONENT24,
})

Implementation

ShadowMap(this._cgl, int w, int h, double near, double far,
    {int format = GL_DEPTH_COMPONENT24}) {
  _mapSize = VM.Vector2(w + 0.0, h + 0.0);
  // We do not really need a proper frame buffer texture as we are only
  // concerned about updated the depth buffer.
  // TODO: is there a way to disable the framebuffer writes altogether?
  Texture dummy = TypedTexture(
      _cgl, "frame::color", w, h, GL_RGBA8, TexturePropertiesFramebuffer);
  _depthTexture = TypedTexture(
      _cgl, "frame::depth", w, h, format, TexturePropertiesShadowMap);
  _shadowBuffer = Framebuffer(_cgl, dummy, _depthTexture);
  _phaseCompute = RenderPhase("compute-shadow", _cgl, _shadowBuffer)
    ..viewPortW = w
    ..viewPortH = h;

  _uniforms
    ..SetUniform(uTexture, GetMapTexture())
    // for visualization only:
    ..SetUniform(uCutOff, 0.0)
    ..SetUniform(uCameraNear, near)
    ..SetUniform(uCameraFar, far);

  _programCompute = Scene(
      "shadowCompute",
      RenderProgram("shadowCompute", _cgl, shadowVertexShaderDepth,
          shadowFragmentShaderDepth),
      [_uniforms]);
  _phaseCompute.add(_programCompute);

  // We do not clear the color buffer for visualization, so Visualize
  // should be called as the last thing touching the framebuffer.
  _phaseVisualize = RenderPhase("visualize-shadow", _cgl)
    ..clearColorBuffer = false;

  _programVisualize = Scene(
      "shadowVisualize",
      RenderProgram(
          "shadowVisualize",
          _cgl,
          visualizeShadowmapVertexShaderLinearDepth16,
          visualizeShadowmapFragmentShaderLinearDepth16),
      [_uniforms]);

  _programVisualize.add(UnitNode(_programVisualize.program));
  _phaseVisualize.add(_programVisualize);
}