Panda3D
|
00001 // Filename: shaderGenerator.h 00002 // Created by: jyelon (15Dec07) 00003 // 00004 //////////////////////////////////////////////////////////////////// 00005 // 00006 // PANDA 3D SOFTWARE 00007 // Copyright (c) Carnegie Mellon University. All rights reserved. 00008 // 00009 // All use of this software is subject to the terms of the revised BSD 00010 // license. You should have received a copy of this license along 00011 // with this source code in a file named "LICENSE." 00012 // 00013 //////////////////////////////////////////////////////////////////// 00014 00015 #ifndef SHADERGENERATOR_H 00016 #define SHADERGENERATOR_H 00017 00018 #include "pandabase.h" 00019 #include "graphicsStateGuardianBase.h" 00020 #include "graphicsOutputBase.h" 00021 #include "nodePath.h" 00022 #include "shaderAttrib.h" 00023 #include "renderState.h" 00024 #include "renderAttrib.h" 00025 00026 class AmbientLight; 00027 class DirectionalLight; 00028 class PointLight; 00029 class Spotlight; 00030 class LightAttrib; 00031 00032 //////////////////////////////////////////////////////////////////// 00033 // Class : ShaderGenerator 00034 // Description : The ShaderGenerator is a device that effectively 00035 // replaces the classic fixed function pipeline with 00036 // a 'next-gen' fixed function pipeline. The next-gen 00037 // fixed function pipeline supports features like 00038 // normal mapping, gloss mapping, cartoon lighting, 00039 // and so forth. It works by automatically generating 00040 // a shader from a given RenderState. 00041 // 00042 // Currently, there is one ShaderGenerator object per 00043 // GraphicsStateGuardian. It is our intent that in 00044 // time, people will write classes that derive from 00045 // ShaderGenerator but which yield slightly different 00046 // results. 00047 // 00048 // The ShaderGenerator owes its existence to the 00049 // 'Bamboo Team' at Carnegie Mellon's Entertainment 00050 // Technology Center. This is a group of students 00051 // who, as a semester project, decided that next-gen 00052 // graphics should be accessible to everyone, even if 00053 // they don't know shader programming. The group 00054 // consisted of: 00055 // 00056 // Aaron Lo, Programmer 00057 // Heegun Lee, Programmer 00058 // Erin Fernandez, Artist/Tester 00059 // Joe Grubb, Artist/Tester 00060 // Ivan Ortega, Technical Artist/Tester 00061 // 00062 // Thanks to them! 00063 // 00064 //////////////////////////////////////////////////////////////////// 00065 00066 class EXPCL_PANDA_PGRAPHNODES ShaderGenerator : public TypedObject { 00067 PUBLISHED: 00068 ShaderGenerator(PT(GraphicsStateGuardianBase) gsg, PT(GraphicsOutputBase) host); 00069 virtual ~ShaderGenerator(); 00070 virtual CPT(RenderAttrib) synthesize_shader(const RenderState *rs); 00071 00072 protected: 00073 CPT(RenderAttrib) create_shader_attrib(const string &txt); 00074 PT(Texture) update_shadow_buffer(NodePath light_np); 00075 static const string combine_mode_as_string(CPT(TextureStage) stage, 00076 TextureStage::CombineMode c_mode, bool alpha, short texindex); 00077 static const string combine_source_as_string(CPT(TextureStage) stage, 00078 short num, bool alpha, bool single_value, short texindex); 00079 static const string texture_type_as_string(Texture::TextureType ttype); 00080 00081 // Shader register allocation: 00082 00083 int _vcregs_used; 00084 int _fcregs_used; 00085 int _vtregs_used; 00086 int _ftregs_used; 00087 void reset_register_allocator(); 00088 INLINE char *alloc_vreg(); 00089 INLINE char *alloc_freg(); 00090 00091 // RenderState analysis information. Created by analyze_renderstate: 00092 00093 CPT(RenderState) _state; 00094 Material *_material; 00095 int _num_textures; 00096 00097 pvector <AmbientLight *> _alights; 00098 pvector <DirectionalLight *> _dlights; 00099 pvector <PointLight *> _plights; 00100 pvector <Spotlight *> _slights; 00101 pvector <NodePath> _alights_np; 00102 pvector <NodePath> _dlights_np; 00103 pvector <NodePath> _plights_np; 00104 pvector <NodePath> _slights_np; 00105 00106 bool _vertex_colors; 00107 bool _flat_colors; 00108 00109 bool _lighting; 00110 bool _shadows; 00111 00112 bool _have_ambient; 00113 bool _have_diffuse; 00114 bool _have_emission; 00115 bool _have_specular; 00116 00117 bool _separate_ambient_diffuse; 00118 00119 int _map_index_normal; 00120 int _map_index_height; 00121 int _map_index_glow; 00122 int _map_index_gloss; 00123 bool _map_height_in_alpha; 00124 00125 bool _out_primary_glow; 00126 bool _out_aux_normal; 00127 bool _out_aux_glow; 00128 bool _out_aux_any; 00129 00130 bool _have_alpha_test; 00131 bool _have_alpha_blend; 00132 bool _calc_primary_alpha; 00133 bool _subsume_alpha_test; 00134 bool _disable_alpha_write; 00135 00136 int _num_clip_planes; 00137 bool _use_shadow_filter; 00138 00139 bool _need_material_props; 00140 bool _need_world_position; 00141 bool _need_world_normal; 00142 bool _need_eye_position; 00143 bool _need_eye_normal; 00144 00145 void analyze_renderstate(const RenderState *rs); 00146 void clear_analysis(); 00147 00148 PT(GraphicsStateGuardianBase) _gsg; 00149 PT(GraphicsOutputBase) _host; 00150 pmap<WCPT(RenderState), CPT(ShaderAttrib)> _generated_shaders; 00151 00152 public: 00153 static TypeHandle get_class_type() { 00154 return _type_handle; 00155 } 00156 static void init_type() { 00157 TypedObject::init_type(); 00158 register_type(_type_handle, "ShaderGenerator", 00159 TypedObject::get_class_type()); 00160 } 00161 virtual TypeHandle get_type() const { 00162 return get_class_type(); 00163 } 00164 virtual TypeHandle force_init_type() {init_type(); return get_class_type();} 00165 00166 private: 00167 static TypeHandle _type_handle; 00168 }; 00169 00170 #include "shaderGenerator.I" 00171 00172 #endif // SHADERGENERATOR_H 00173