Panda3D
|
00001 // Filename: shaderGenerator.h 00002 // Created by: jyelon (15Dec07) 00003 // Updated by: weifengh, PandaSE(15Apr10) 00004 // 00005 //////////////////////////////////////////////////////////////////// 00006 // 00007 // PANDA 3D SOFTWARE 00008 // Copyright (c) Carnegie Mellon University. All rights reserved. 00009 // 00010 // All use of this software is subject to the terms of the revised BSD 00011 // license. You should have received a copy of this license along 00012 // with this source code in a file named "LICENSE." 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 // Class : ShaderGenerator 00035 // Description : The ShaderGenerator is a device that effectively 00036 // replaces the classic fixed function pipeline with 00037 // a 'next-gen' fixed function pipeline. The next-gen 00038 // fixed function pipeline supports features like 00039 // normal mapping, gloss mapping, cartoon lighting, 00040 // and so forth. It works by automatically generating 00041 // a shader from a given RenderState. 00042 // 00043 // Currently, there is one ShaderGenerator object per 00044 // GraphicsStateGuardian. It is our intent that in 00045 // time, people will write classes that derive from 00046 // ShaderGenerator but which yield slightly different 00047 // results. 00048 // 00049 // The ShaderGenerator owes its existence to the 00050 // 'Bamboo Team' at Carnegie Mellon's Entertainment 00051 // Technology Center. This is a group of students 00052 // who, as a semester project, decided that next-gen 00053 // graphics should be accessible to everyone, even if 00054 // they don't know shader programming. The group 00055 // consisted of: 00056 // 00057 // Aaron Lo, Programmer 00058 // Heegun Lee, Programmer 00059 // Erin Fernandez, Artist/Tester 00060 // Joe Grubb, Artist/Tester 00061 // Ivan Ortega, Technical Artist/Tester 00062 // 00063 // Thanks to them! 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 // Shader register allocation: 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 // RenderState analysis information. Created by analyze_renderstate: 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