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
39 * A class wich add shadows in a postprocess stage.
41 class SGShadowVolume {
44 SGShadowVolume( ssgBranch *root );
50 occluderTypeTileObject
53 void init(SGPropertyNode *sim_rendering_options);
54 void startOfFrame(void);
55 void addOccluder(ssgBranch *occluder, OccluderType occluder_type, ssgBranch *tile=0);
56 void deleteOccluder(ssgBranch *occluder);
57 void deleteOccluderFromTile(ssgBranch *tile);
58 void setupShadows(double lon, double lat,
59 double gst, double SunRightAscension, double SunDeclination, double sunAngle );
60 void endOfFrame(void);
61 static int ACpostTravCB( ssgEntity *entity, int traversal_mask );
69 sgVec4 planeEquations;
70 int neighbourIndices[3];
71 bool isSilhouetteEdge[3];
75 ssgBranch *geometry_leaf;
76 ssgBranch *scenery_object;
77 ssgBranch *lib_object;
78 ssgBranch *first_select;
80 sgMat4 last_transform;
88 GLushort *silhouetteEdgeIndices;
89 int lastSilhouetteIndicesCount;
92 ShadowCaster( int _num_tri, ssgBranch * _geometry_leaf );
94 void addLeaf( int & tri_idx, int & ind_idx, ssgLeaf *_geometry_leaf );
95 void SetConnectivity();
96 void CalculateSilhouetteEdges(sgVec3 lightPosition);
97 void DrawInfiniteShadowVolume(sgVec3 lightPosition, bool drawCaps);
98 void computeShadows(sgMat4 rotation, sgMat4 rotation_translation, OccluderType occluder_type);
99 void getNetTransform ( ssgBranch * branch, sgMat4 xform );
100 bool isSelected ( ssgBranch * branch, float dist);
102 bool sameVertex(int edge1, int edge2);
104 typedef vector<ShadowCaster *> ShadowCaster_list;
106 class SceneryObject {
108 SceneryObject(ssgBranch *_scenery_object, OccluderType _occluder_type);
110 void computeShadows(void);
111 void traverseTree(ssgBranch *branch);
112 void find_trans(void);
113 ssgBranch *scenery_object;
114 ssgBranch *lib_object;
115 ssgBranch *pending_object;
117 ShadowCaster_list parts;
118 OccluderType occluder_type;
120 typedef map<ssgBranch *, SceneryObject *> SceneryObject_map;
124 void update_light_view(void);
125 void computeShadows(void);
126 void cull ( ssgBranch *b, sgFrustum *f, sgMat4 m, int test_needed );
128 bool shadows_enabled;
129 bool shadowsAC_enabled, shadowsAI_enabled, shadowsTO_enabled, shadowsDebug_enabled;
130 bool shadowsAC_transp_enabled;
132 bool canDoAlpha, canDoStencil;
133 SGPropertyNode *sim_rendering;
137 int lastTraverseTreeFrame;
140 SceneryObject_map sceneryObjects;
142 bool shadows_rendered;
145 #endif // _SHADOWVOLUME_HXX