Panda3D
|
The ShaderGenerator is a device that effectively replaces the classic fixed function pipeline with a 'next-gen' fixed function pipeline. More...
#include "shaderGenerator.h"
Public Member Functions | |
ShaderGenerator (PT(GraphicsStateGuardianBase) gsg, PT(GraphicsOutputBase) host) | |
Create a ShaderGenerator. | |
virtual | ~ShaderGenerator () |
Destroy a ShaderGenerator. | |
TypedObject * | as_typed_object () |
Returns the object, upcast (if necessary) to a TypedObject pointer. | |
const TypedObject * | as_typed_object () const |
Returns the object, upcast (if necessary) to a TypedObject pointer. | |
virtual | CPT (RenderAttrib) synthesize_shader(const RenderState *rs) |
virtual TypeHandle | force_init_type () |
int | get_best_parent_from_Set (const std::set< int > &) const |
virtual TypeHandle | get_type () const |
int | get_type_index () const |
Returns the internal index number associated with this object's TypeHandle, a unique number for each different type. | |
bool | is_exact_type (TypeHandle handle) const |
Returns true if the current object is the indicated type exactly. | |
bool | is_of_type (TypeHandle handle) const |
Returns true if the current object is or derives from the indicated type. | |
void | operator delete (void *ptr) |
void | operator delete (void *ptr, void *) |
void | operator delete[] (void *, void *) |
void | operator delete[] (void *ptr) |
void * | operator new (size_t size, void *ptr) |
void * | operator new (size_t size) |
void * | operator new[] (size_t size, void *ptr) |
void * | operator new[] (size_t size) |
Static Public Member Functions | |
static TypeHandle | get_class_type () |
static void | init_type () |
This function is declared non-inline to work around a compiler bug in g++ 2.96. | |
Protected Member Functions | |
char * | alloc_freg () |
Allocate a freg. | |
char * | alloc_vreg () |
Allocate a vreg. | |
void | analyze_renderstate (const RenderState *rs) |
Analyzes the RenderState prior to shader generation. | |
void | clear_analysis () |
Called after analyze_renderstate to discard all the results of the analysis. | |
CPT (RenderAttrib) create_shader_attrib(const string &txt) | |
CPT (RenderState) _state | |
PT (Texture) update_shadow_buffer(NodePath light_np) | |
PT (GraphicsOutputBase) _host | |
PT (GraphicsStateGuardianBase) _gsg | |
void | reset_register_allocator () |
Clears the register allocator. | |
Static Protected Member Functions | |
static const string | combine_mode_as_string (CPT(TextureStage) stage, TextureStage::CombineMode c_mode, bool alpha, short texindex) |
This 'synthesizes' a combine mode into a string. | |
static const string | combine_source_as_string (CPT(TextureStage) stage, short num, bool alpha, bool single_value, short texindex) |
This 'synthesizes' a combine source into a string. | |
static const string | texture_type_as_string (Texture::TextureType ttype) |
Returns 1D, 2D, 3D or CUBE, depending on the given texture type. | |
Protected Attributes | |
pvector< AmbientLight * > | _alights |
pvector< NodePath > | _alights_np |
bool | _calc_primary_alpha |
bool | _disable_alpha_write |
pvector< DirectionalLight * > | _dlights |
pvector< NodePath > | _dlights_np |
int | _fcregs_used |
bool | _flat_colors |
int | _ftregs_used |
pmap< WCPT(RenderState), CPT(ShaderAttrib)> | _generated_shaders |
bool | _have_alpha_blend |
bool | _have_alpha_test |
bool | _have_ambient |
bool | _have_diffuse |
bool | _have_emission |
bool | _have_specular |
bool | _lighting |
bool | _map_height_in_alpha |
int | _map_index_gloss |
int | _map_index_glow |
int | _map_index_height |
int | _map_index_normal |
Material * | _material |
bool | _need_eye_normal |
bool | _need_eye_position |
bool | _need_material_props |
bool | _need_world_normal |
bool | _need_world_position |
int | _num_clip_planes |
int | _num_textures |
bool | _out_aux_any |
bool | _out_aux_glow |
bool | _out_aux_normal |
bool | _out_primary_glow |
pvector< PointLight * > | _plights |
pvector< NodePath > | _plights_np |
bool | _separate_ambient_diffuse |
bool | _shadows |
pvector< Spotlight * > | _slights |
pvector< NodePath > | _slights_np |
bool | _subsume_alpha_test |
bool | _use_shadow_filter |
int | _vcregs_used |
bool | _vertex_colors |
int | _vtregs_used |
The ShaderGenerator is a device that effectively replaces the classic fixed function pipeline with a 'next-gen' fixed function pipeline.
The next-gen fixed function pipeline supports features like normal mapping, gloss mapping, cartoon lighting, and so forth. It works by automatically generating a shader from a given RenderState.
Currently, there is one ShaderGenerator object per GraphicsStateGuardian. It is our intent that in time, people will write classes that derive from ShaderGenerator but which yield slightly different results.
The ShaderGenerator owes its existence to the 'Bamboo Team' at Carnegie Mellon's Entertainment Technology Center. This is a group of students who, as a semester project, decided that next-gen graphics should be accessible to everyone, even if they don't know shader programming. The group consisted of:
Aaron Lo, Programmer Heegun Lee, Programmer Erin Fernandez, Artist/Tester Joe Grubb, Artist/Tester Ivan Ortega, Technical Artist/Tester
Thanks to them!
Definition at line 66 of file shaderGenerator.h.
ShaderGenerator::ShaderGenerator | ( | PT(GraphicsStateGuardianBase) | gsg, |
PT(GraphicsOutputBase) | host | ||
) |
Create a ShaderGenerator.
This has no state, except possibly to cache certain results. The parameter that must be passed is the GSG to which the shader generator belongs.
Definition at line 50 of file shaderGenerator.cxx.
ShaderGenerator::~ShaderGenerator | ( | ) | [virtual] |
Destroy a ShaderGenerator.
Definition at line 60 of file shaderGenerator.cxx.
char * ShaderGenerator::alloc_freg | ( | ) | [inline, protected] |
Allocate a freg.
Definition at line 130 of file shaderGenerator.cxx.
char * ShaderGenerator::alloc_vreg | ( | ) | [inline, protected] |
Allocate a vreg.
Definition at line 84 of file shaderGenerator.cxx.
void ShaderGenerator::analyze_renderstate | ( | const RenderState * | rs | ) | [protected] |
Analyzes the RenderState prior to shader generation.
The results of the analysis are stored in instance variables of the Shader Generator.
Definition at line 178 of file shaderGenerator.cxx.
References clear_analysis(), Material::get_ambient(), RenderState::get_attrib_def(), ColorAttrib::get_color_type(), Material::get_default(), Material::get_diffuse(), Material::get_emission(), MaterialAttrib::get_material(), LightRampAttrib::get_mode(), TexGenAttrib::get_mode(), TextureStage::get_mode(), TransparencyAttrib::get_mode(), ColorBlendAttrib::get_mode(), AlphaTestAttrib::get_mode(), LightAttrib::get_num_on_lights(), ClipPlaneAttrib::get_num_on_planes(), TextureAttrib::get_num_on_stages(), LightAttrib::get_on_light(), TextureAttrib::get_on_stage(), AuxBitplaneAttrib::get_outputs(), Material::get_specular(), Material::has_ambient(), Material::has_diffuse(), Material::has_emission(), Material::has_specular(), TexGenAttrib::has_stage(), NodePath::is_empty(), FogAttrib::is_off(), MaterialAttrib::is_off(), and NodePath::node().
TypedObject * TypedObject::as_typed_object | ( | ) | [inline, inherited] |
Returns the object, upcast (if necessary) to a TypedObject pointer.
Definition at line 99 of file typedObject.I.
const TypedObject * TypedObject::as_typed_object | ( | ) | const [inline, inherited] |
Returns the object, upcast (if necessary) to a TypedObject pointer.
Definition at line 110 of file typedObject.I.
void ShaderGenerator::clear_analysis | ( | ) | [protected] |
Called after analyze_renderstate to discard all the results of the analysis.
This is generally done after shader generation is complete.
Definition at line 445 of file shaderGenerator.cxx.
Referenced by analyze_renderstate().
const string ShaderGenerator::combine_mode_as_string | ( | CPT(TextureStage) | stage, |
TextureStage::CombineMode | c_mode, | ||
bool | alpha, | ||
short | texindex | ||
) | [static, protected] |
This 'synthesizes' a combine mode into a string.
Definition at line 1342 of file shaderGenerator.cxx.
References combine_source_as_string().
const string ShaderGenerator::combine_source_as_string | ( | CPT(TextureStage) | stage, |
short | num, | ||
bool | alpha, | ||
bool | single_value, | ||
short | texindex | ||
) | [static, protected] |
This 'synthesizes' a combine source into a string.
Definition at line 1392 of file shaderGenerator.cxx.
References TextureStage::get_color(), TextureStage::get_combine_alpha_operand0(), TextureStage::get_combine_alpha_operand1(), TextureStage::get_combine_alpha_operand2(), TextureStage::get_combine_alpha_source0(), TextureStage::get_combine_alpha_source1(), TextureStage::get_combine_alpha_source2(), TextureStage::get_combine_rgb_operand0(), TextureStage::get_combine_rgb_operand1(), TextureStage::get_combine_rgb_operand2(), TextureStage::get_combine_rgb_source0(), TextureStage::get_combine_rgb_source1(), and TextureStage::get_combine_rgb_source2().
Referenced by combine_mode_as_string().
int TypedObject::get_type_index | ( | ) | const [inline, inherited] |
Returns the internal index number associated with this object's TypeHandle, a unique number for each different type.
This is equivalent to get_type().get_index().
Definition at line 52 of file typedObject.I.
References TypeHandle::get_index().
static void ShaderGenerator::init_type | ( | ) | [inline, static] |
This function is declared non-inline to work around a compiler bug in g++ 2.96.
Making it inline seems to cause problems in the optimizer.
Reimplemented from TypedObject.
Definition at line 156 of file shaderGenerator.h.
References TypedObject::init_type().
bool TypedObject::is_exact_type | ( | TypeHandle | handle | ) | const [inline, inherited] |
Returns true if the current object is the indicated type exactly.
Definition at line 74 of file typedObject.I.
References TypeHandle::get_name().
Referenced by GraphicsStateGuardian::async_reload_texture(), PortalNode::combine_with(), PandaNode::combine_with(), GeomNode::combine_with(), CollisionNode::combine_with(), Character::combine_with(), PGItem::cull_callback(), FactoryParams::get_param_of_type(), CollisionHandlerPusher::handle_entries(), SceneGraphReducer::r_flatten(), ConnectionWriter::send(), FltToEggLevelState::set_transform(), and VirtualFileSystem::unmount().
bool TypedObject::is_of_type | ( | TypeHandle | handle | ) | const [inline, inherited] |
Returns true if the current object is or derives from the indicated type.
Definition at line 63 of file typedObject.I.
References TypeHandle::is_derived_from().
Referenced by EggSliderData::add_back_pointer(), EggJointData::add_back_pointer(), CIntervalManager::add_c_interval(), XFileNode::add_child(), CollisionTraverser::add_collider(), CollisionHandlerPhysical::add_collider(), EggXfmSAnim::add_data(), CharacterJointBundle::add_node(), NonlinearImager::add_screen(), EggGroupNode::apply_first_attribute(), EggGroupNode::apply_last_attribute(), DeferredNodeProperty::apply_to_node(), RecorderController::begin_playback(), NodePath::clear_clip_plane(), EggGroupNode::clear_connected_shading(), NodePath::clear_light(), EggBase::convert_paths(), NodePath::decode_from_bam_stream(), VrpnClient::disconnect_device(), PhysicsManager::do_physics(), GraphicsStateGuardian::fetch_specified_part(), EggRenderState::fill_state(), AnimBundleNode::find_anim_bundle(), EggGroupNode::find_coordsys_entry(), XFile::find_data_object(), Character::find_joint(), EggGroupNode::find_materials(), Character::find_slider(), XFile::find_template(), EggGroupNode::find_textures(), EggMaterialCollection::find_used_materials(), EggTextureCollection::find_used_textures(), EggGroupNode::force_filenames(), EggJointData::force_initial_rest_frame(), WindowFramework::get_aspect_2d(), EggPoolUniquifier::get_category(), EggGroupUniquifier::get_category(), EggGroupNode::get_connected_shading(), PandaFramework::get_mouse(), FactoryParams::get_param_of_type(), EggGroupNode::has_absolute_pathnames(), NodePath::has_clip_plane(), NodePath::has_clip_plane_off(), NodePath::has_light(), PandaFramework::hide_collision_solids(), x11GraphicsWindow::open_window(), eglGraphicsWindow::open_window(), EggNode::parse_egg(), CharacterMaker::part_to_node(), EggGroupNode::post_apply_flat_attribute(), EggBinner::prepare_node(), PortalClipper::prepare_portal(), NodePath::project_texture(), EggMatrixTablePointer::quantize_channels(), ParametricCurveCollection::r_add_curves(), SceneGraphReducer::r_collect_vertex_data(), EggGroupNode::r_load_externals(), EggGroupNode::rebuild_vertex_pools(), EggGroupNode::recompute_polygon_normals(), EggGroupNode::remove_invalid_primitives(), EggGroupNode::remove_unused_vertices(), EggLoader::reparent_decals(), EggMaterialCollection::replace_materials(), EggTextureCollection::replace_textures(), EggGroupNode::resolve_filenames(), EggGroupNode::reverse_vertex_ordering(), NodePath::set_clip_plane(), NodePath::set_clip_plane_off(), NodePath::set_light(), ProjectionScreen::set_projector(), NonlinearImager::set_source_camera(), EggXfmSAnim::set_value(), NonlinearImager::set_viewer_camera(), PandaFramework::show_collision_solids(), BamCache::store(), XFileToEggConverter::strip_nodes(), EggGroupNode::strip_normals(), DataGraphTraverser::traverse(), DataGraphTraverser::traverse_below(), EggGroupNode::triangulate_polygons(), EggGroupNode::unify_attributes(), EggNameUniquifier::uniquify(), NodeCullCallbackData::upcall(), PhysicsCollisionHandler::validate_target(), EggXfmSAnim::write(), EggGroup::write(), EggToDXFLayer::write_3d_face(), and EggToDXFLayer::write_entities().
void ShaderGenerator::reset_register_allocator | ( | ) | [protected] |
Clears the register allocator.
Initially, the pool of available registers is empty. You have to add some if you want there to be any.
Definition at line 71 of file shaderGenerator.cxx.
const string ShaderGenerator::texture_type_as_string | ( | Texture::TextureType | ttype | ) | [static, protected] |
Returns 1D, 2D, 3D or CUBE, depending on the given texture type.
Definition at line 1476 of file shaderGenerator.cxx.