00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016 #ifndef SHADERGENERATOR_H
00017 #define SHADERGENERATOR_H
00018
00019 #include "pandabase.h"
00020 #include "graphicsStateGuardianBase.h"
00021 #include "graphicsOutputBase.h"
00022 #include "nodePath.h"
00023 #include "shaderAttrib.h"
00024 #include "renderState.h"
00025 #include "renderAttrib.h"
00026
00027 class AmbientLight;
00028 class DirectionalLight;
00029 class PointLight;
00030 class Spotlight;
00031 class LightAttrib;
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067 class EXPCL_PANDA_PGRAPHNODES ShaderGenerator : public TypedObject {
00068 PUBLISHED:
00069 ShaderGenerator(PT(GraphicsStateGuardianBase) gsg, PT(GraphicsOutputBase) host);
00070 virtual ~ShaderGenerator();
00071 virtual CPT(RenderAttrib) synthesize_shader(const RenderState *rs);
00072
00073 protected:
00074 CPT(RenderAttrib) create_shader_attrib(const string &txt);
00075 PT(Texture) update_shadow_buffer(NodePath light_np);
00076 static const string combine_mode_as_string(CPT(TextureStage) stage,
00077 TextureStage::CombineMode c_mode, bool alpha, short texindex);
00078 static const string combine_source_as_string(CPT(TextureStage) stage,
00079 short num, bool alpha, bool single_value, short texindex);
00080 static const string texture_type_as_string(Texture::TextureType ttype);
00081
00082
00083
00084 int _vcregs_used;
00085 int _fcregs_used;
00086 int _vtregs_used;
00087 int _ftregs_used;
00088 void reset_register_allocator();
00089 INLINE char *alloc_vreg();
00090 INLINE char *alloc_freg();
00091
00092
00093
00094 CPT(RenderState) _state;
00095 Material *_material;
00096 int _num_textures;
00097
00098 pvector <AmbientLight *> _alights;
00099 pvector <DirectionalLight *> _dlights;
00100 pvector <PointLight *> _plights;
00101 pvector <Spotlight *> _slights;
00102 pvector <NodePath> _alights_np;
00103 pvector <NodePath> _dlights_np;
00104 pvector <NodePath> _plights_np;
00105 pvector <NodePath> _slights_np;
00106
00107 bool _vertex_colors;
00108 bool _flat_colors;
00109
00110 bool _lighting;
00111 bool _shadows;
00112 bool _fog;
00113
00114 bool _have_ambient;
00115 bool _have_diffuse;
00116 bool _have_emission;
00117 bool _have_specular;
00118
00119 bool _separate_ambient_diffuse;
00120
00121 int _map_index_normal;
00122 int _map_index_height;
00123 int _map_index_glow;
00124 int _map_index_gloss;
00125 bool _map_height_in_alpha;
00126
00127 bool _out_primary_glow;
00128 bool _out_aux_normal;
00129 bool _out_aux_glow;
00130 bool _out_aux_any;
00131
00132 bool _have_alpha_test;
00133 bool _have_alpha_blend;
00134 bool _calc_primary_alpha;
00135 bool _subsume_alpha_test;
00136 bool _disable_alpha_write;
00137
00138 int _num_clip_planes;
00139 bool _use_shadow_filter;
00140
00141 bool _need_material_props;
00142 bool _need_world_position;
00143 bool _need_world_normal;
00144 bool _need_eye_position;
00145 bool _need_eye_normal;
00146 bool _auto_normal_on;
00147 bool _auto_glow_on;
00148 bool _auto_gloss_on;
00149 bool _auto_ramp_on;
00150 bool _auto_shadow_on;
00151
00152 void analyze_renderstate(const RenderState *rs);
00153 void clear_analysis();
00154
00155 PT(GraphicsStateGuardianBase) _gsg;
00156 PT(GraphicsOutputBase) _host;
00157 pmap<WCPT(RenderState), CPT(ShaderAttrib)> _generated_shaders;
00158
00159 public:
00160 static TypeHandle get_class_type() {
00161 return _type_handle;
00162 }
00163 static void init_type() {
00164 TypedObject::init_type();
00165 register_type(_type_handle, "ShaderGenerator",
00166 TypedObject::get_class_type());
00167 }
00168 virtual TypeHandle get_type() const {
00169 return get_class_type();
00170 }
00171 virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
00172
00173 private:
00174 static TypeHandle _type_handle;
00175 };
00176
00177 #include "shaderGenerator.I"
00178
00179 #endif // SHADERGENERATOR_H
00180