3 // Written by Harald JOHNSEN, started June 2005.
5 // Copyright (C) 2005 Harald JOHNSEN - hjohnsen@evc.net
7 // This program is free software; you can redistribute it and/or
8 // modify it under the terms of the GNU General Public License as
9 // published by the Free Software Foundation; either version 2 of the
10 // License, or (at your option) any later version.
12 // This program is distributed in the hope that it will be useful, but
13 // WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 // General Public License for more details.
17 // You should have received a copy of the GNU General Public License
18 // along with this program; if not, write to the Free Software
19 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
23 #ifndef _SHADOWVOLUME_HXX
24 #define _SHADOWVOLUME_HXX
26 #include <simgear/compiler.h>
27 #include <simgear/props/props.hxx>
40 * A class wich add shadows in a postprocess stage.
42 class SGShadowVolume {
45 SGShadowVolume( ssgBranch *root );
51 occluderTypeTileObject
54 void init(SGPropertyNode *sim_rendering_options);
55 void startOfFrame(void);
56 void addOccluder(ssgBranch *occluder, OccluderType occluder_type, ssgBranch *tile=0);
57 void deleteOccluder(ssgBranch *occluder);
58 void deleteOccluderFromTile(ssgBranch *tile);
59 void setupShadows(double lon, double lat,
60 double gst, double SunRightAscension, double SunDeclination, double sunAngle );
61 void endOfFrame(void);
62 static int ACpostTravCB( ssgEntity *entity, int traversal_mask );
70 sgVec4 planeEquations;
71 int neighbourIndices[3];
72 bool isSilhouetteEdge[3];
76 ssgSharedPtr<ssgBranch> geometry_leaf;
77 ssgSharedPtr<ssgBranch> scenery_object;
78 ssgSharedPtr<ssgBranch> lib_object;
79 ssgSharedPtr<ssgBranch> first_select;
81 sgMat4 last_transform;
89 GLushort *silhouetteEdgeIndices;
90 int lastSilhouetteIndicesCount;
93 ShadowCaster( int _num_tri, ssgBranch * _geometry_leaf );
95 void addLeaf( int & tri_idx, int & ind_idx, ssgLeaf *_geometry_leaf );
96 void SetConnectivity();
97 void CalculateSilhouetteEdges(sgVec3 lightPosition);
98 void DrawInfiniteShadowVolume(sgVec3 lightPosition, bool drawCaps);
99 void computeShadows(sgMat4 rotation, sgMat4 rotation_translation, OccluderType occluder_type);
100 void getNetTransform ( ssgBranch * branch, sgMat4 xform );
101 bool isSelected ( ssgBranch * branch, float dist);
103 bool sameVertex(int edge1, int edge2);
105 typedef vector<ShadowCaster *> ShadowCaster_list;
107 class SceneryObject {
109 SceneryObject(ssgBranch *_scenery_object, OccluderType _occluder_type);
111 void computeShadows(void);
112 void traverseTree(ssgBranch *branch);
113 void find_trans(void);
114 ssgSharedPtr<ssgBranch> scenery_object;
115 ssgSharedPtr<ssgBranch> lib_object;
116 ssgSharedPtr<ssgBranch> pending_object;
117 ssgSharedPtr<ssgBranch> tile;
118 ShadowCaster_list parts;
119 OccluderType occluder_type;
121 typedef map<ssgSharedPtr<ssgBranch>, SceneryObject *> SceneryObject_map;
125 void update_light_view(void);
126 void computeShadows(void);
127 void cull ( ssgBranch *b, sgFrustum *f, sgMat4 m, int test_needed );
129 bool shadows_enabled;
130 bool shadowsAC_enabled, shadowsAI_enabled, shadowsTO_enabled, shadowsDebug_enabled;
131 bool shadowsAC_transp_enabled;
133 bool canDoAlpha, canDoStencil;
134 SGPropertyNode_ptr sim_rendering;
138 int lastTraverseTreeFrame;
141 SceneryObject_map sceneryObjects;
142 ssgSharedPtr<ssgBranch> ssg_root;
143 bool shadows_rendered;
146 #endif // _SHADOWVOLUME_HXX