// Author: Juan Carlos De Abreu (jcabreur@gmail.com)
//
// This file define a class that implement a volume stencil shadows for the
// objects. This method get the shadows after two pass, this method have an 
// artefact when the view is in the front of the light. Is neccessary that the 
// lighting will be disable before call the render method.

#ifndef SHADOW_VOLUME_SHADOWS_H__
#define SHADOW_VOLUME_SHADOWS_H__

#include "Shadows.h"
#include "../Base/Memory/SmartPointer.h"
#include "../scene/scene_nodes/light_node.h"
#include "../scene/scene_nodes/geometry_node.h"
#include "ShadowInstance.h"

BEGIN_TEG_NAMESPACE();

#define SHADOW_OPACITY 0.4f

// Definition of the structure of the volume shadows
class VolumeShadows : public Shadows {
 public:
  // VolumeShadows constructor and destructor.
  VolumeShadows();
  ~VolumeShadows();

  // Method to draw the shadows
  void render();
  void render(const SmartPointer<LightNode>& light, std::vector<SmartPointer<GeometryNode>>& models);

  void checkGeometry(SmartPointer<LightNode> l, SmartPointer<GeometryNode> g);

  // Methods to calculate the ecuation plane of each face and to determin what
  // face are adyacent to other.
  void calculatePlanes(const Group& g, std::vector<ShadowPlane>& s); 
  void SetConnectivity(const Group& g, std::vector<ShadowPlane>& s); 

  void shadows1(ShadowInstance* s);
  void shadows2(SmartPointer<IModel> m, ShadowInstance* s);
  void shadows3(SmartPointer<IModel> m, ShadowInstance* s);

  AUTO_SIZE();

 private:
  // Volume Shadows attributes.
  std::map< std::pair<SmartPointer<LightNode>, SmartPointer<GeometryNode> >, ShadowInstance> instances;
  DISALLOW_COPY_AND_ASSIGN(VolumeShadows);
};

END_TEG_NAMESPACE();

#endif  // SHADOW_VOLUME_SHADOWS_H__
