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/structure/ssgSharedPtr.hxx>
28 #include <simgear/props/props.hxx>
44 * A class wich add shadows in a postprocess stage.
46 class SGShadowVolume {
49 SGShadowVolume( ssgBranch *root );
55 occluderTypeTileObject
58 void init(SGPropertyNode *sim_rendering_options);
59 void startOfFrame(void);
60 void addOccluder(ssgBranch *occluder, OccluderType occluder_type, ssgBranch *tile=0);
61 void deleteOccluder(ssgBranch *occluder);
62 void deleteOccluderFromTile(ssgBranch *tile);
63 void setupShadows(double lon, double lat,
64 double gst, double SunRightAscension, double SunDeclination, double sunAngle );
65 void endOfFrame(void);
66 static int ACpostTravCB( ssgEntity *entity, int traversal_mask );
74 sgVec4 planeEquations;
75 int neighbourIndices[3];
76 bool isSilhouetteEdge[3];
80 ssgSharedPtr<ssgBranch> geometry_leaf;
81 ssgSharedPtr<ssgBranch> scenery_object;
82 ssgSharedPtr<ssgBranch> lib_object;
83 ssgSharedPtr<ssgBranch> first_select;
85 sgMat4 last_transform;
93 GLushort *silhouetteEdgeIndices;
94 int lastSilhouetteIndicesCount;
97 ShadowCaster( int _num_tri, ssgBranch * _geometry_leaf );
99 void addLeaf( int & tri_idx, int & ind_idx, ssgLeaf *_geometry_leaf );
100 void SetConnectivity();
101 void CalculateSilhouetteEdges(sgVec3 lightPosition);
102 void DrawInfiniteShadowVolume(sgVec3 lightPosition, bool drawCaps);
103 void computeShadows(sgMat4 rotation, sgMat4 rotation_translation, OccluderType occluder_type);
104 void getNetTransform ( ssgBranch * branch, sgMat4 xform );
105 bool isSelected ( ssgBranch * branch, float dist);
107 bool sameVertex(int edge1, int edge2);
109 typedef vector<ShadowCaster *> ShadowCaster_list;
111 class SceneryObject {
113 SceneryObject(ssgBranch *_scenery_object, OccluderType _occluder_type);
115 void computeShadows(void);
116 void traverseTree(ssgBranch *branch);
117 void find_trans(void);
118 ssgSharedPtr<ssgBranch> scenery_object;
119 ssgSharedPtr<ssgBranch> lib_object;
120 ssgSharedPtr<ssgBranch> pending_object;
121 ssgSharedPtr<ssgBranch> tile;
122 ShadowCaster_list parts;
123 OccluderType occluder_type;
125 typedef map<ssgSharedPtr<ssgBranch>, SceneryObject *> SceneryObject_map;
129 void update_light_view(void);
130 void computeShadows(void);
131 void cull ( ssgBranch *b, sgFrustum *f, sgMat4 m, int test_needed );
133 bool shadows_enabled;
134 bool shadowsAC_enabled, shadowsAI_enabled, shadowsTO_enabled, shadowsDebug_enabled;
135 bool shadowsAC_transp_enabled;
137 bool canDoAlpha, canDoStencil;
138 SGPropertyNode_ptr sim_rendering;
142 int lastTraverseTreeFrame;
145 SceneryObject_map sceneryObjects;
146 ssgSharedPtr<ssgBranch> ssg_root;
147 bool shadows_rendered;
150 #endif // _SHADOWVOLUME_HXX