00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #include "projtexShader.h"
00019 #include "config_shader.h"
00020
00021 #include <lightTransition.h>
00022 #include <textureTransition.h>
00023 #include <get_rel_pos.h>
00024 #include <dftraverser.h>
00025 #include <colorBlendTransition.h>
00026 #include <depthTestTransition.h>
00027 #include <graphicsStateGuardian.h>
00028 #include <texGenTransition.h>
00029 #include <texMatrixTransition.h>
00030 #include <perspectiveProjection.h>
00031 #include <attribTraverser.h>
00032 #include <textureApplyTransition.h>
00033 #include <directRenderTraverser.h>
00034
00035
00036
00037
00038 TypeHandle ProjtexShader::_type_handle;
00039
00040
00041
00042
00043
00044
00045 ProjtexShader::ProjtexShader(Texture* texture,
00046 ColorBlendProperty::Mode mode)
00047 : FrustumShader(), _blend(mode)
00048 {
00049 set_texture(texture);
00050 }
00051
00052
00053
00054
00055
00056
00057 void ProjtexShader::config(void)
00058 {
00059 Configurable::config();
00060
00061 nassertv(_texture != (Texture *)NULL);
00062 }
00063
00064
00065
00066
00067
00068
00069 void ProjtexShader::
00070 apply(Node *node, const AllAttributesWrapper &init_state,
00071 const AllTransitionsWrapper &net_trans, GraphicsStateGuardian *gsg) {
00072
00073 Shader::apply(node, init_state, net_trans, gsg);
00074
00075
00076 if (get_num_frusta() == 0) {
00077 shader_cat.error()
00078 << "ProjtexShader::apply() - frusta list is empty" << endl;
00079 return;
00080 } else if (get_num_frusta() > 1) {
00081 shader_cat.warning()
00082 << "ProjtexShader::apply() - frusta list has more than one "
00083 << "- ignoring all but first one for now..." << endl;
00084 }
00085
00086
00087 AllTransitionsWrapper trans(net_trans);
00088
00089
00090
00091
00092
00093 LMatrix4f model_mat;
00094 const Projection* projection = _frusta[0]->get_projection();
00095 get_rel_mat(node, _frusta[0], model_mat);
00096
00097
00098 TexGenTransition *tg = new TexGenTransition;
00099 tg->set_texture_projector();
00100 trans.set_transition(tg);
00101
00102 nassertv(_texture != (Texture *)NULL);
00103 TextureTransition *t = new TextureTransition;
00104 t->set_on(_texture);
00105 t->set_priority(_priority);
00106 trans.set_transition(t);
00107
00108 if (_viz != (Shader::Visualize*)0L)
00109 _viz->DisplayTexture(_texture, this);
00110
00111
00112
00113
00114
00115 LMatrix4f tex_mat, proj_mat;
00116 const PerspectiveProjection *pp = DCAST(PerspectiveProjection, projection);
00117 proj_mat = pp->get_projection_mat();
00118 tex_mat = model_mat * proj_mat *
00119 LMatrix4f::scale_mat(LVector3f(0.5,0.5,1)) *
00120 LMatrix4f::translate_mat(LVector3f(0.5,0.5,0));
00121
00122 TexMatrixTransition *tm = new TexMatrixTransition;
00123 tm->set_matrix(tex_mat);
00124 trans.set_transition(tm);
00125
00126
00127 trans.set_transition(new LightTransition(LightTransition::all_off()));
00128
00129
00130 if (_multipass_on) {
00131
00132
00133
00134
00135
00136 ColorBlendTransition *cb = new ColorBlendTransition(_blend);
00137 trans.set_transition(cb);
00138
00139 TextureApplyTransition *ta =
00140 new TextureApplyTransition(TextureApplyProperty::M_decal);
00141 trans.set_transition(ta);
00142
00143
00144 DepthTestTransition *dta =
00145 new DepthTestTransition(DepthTestProperty::M_equal);
00146 trans.set_transition(dta);
00147 }
00148
00149 DirectRenderTraverser drt(gsg, RenderRelation::get_class_type());
00150 gsg->render_subgraph(&drt, node, init_state, trans);
00151 }
00152
00153
00154