00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #include "spheretexShader.h"
00019 #include "config_shader.h"
00020
00021 #include <lightTransition.h>
00022 #include <textureTransition.h>
00023 #include <textureTransition.h>
00024 #include <texMatrixTransition.h>
00025 #include <depthTestTransition.h>
00026 #include <texGenTransition.h>
00027 #include <textureApplyTransition.h>
00028 #include <colorBlendTransition.h>
00029 #include <get_rel_pos.h>
00030 #include <dftraverser.h>
00031 #include <graphicsStateGuardian.h>
00032 #include <colorBlendTransition.h>
00033 #include <attribTraverser.h>
00034 #include <directRenderTraverser.h>
00035
00036
00037
00038
00039 TypeHandle SpheretexShader::_type_handle;
00040
00041
00042
00043
00044
00045
00046 SpheretexShader::SpheretexShader(Texture* texture) : Shader()
00047 {
00048 set_texture(texture);
00049 _blend_mode = ColorBlendProperty::M_multiply_add;
00050 }
00051
00052
00053
00054
00055
00056
00057 void SpheretexShader::config(void)
00058 {
00059 Configurable::config();
00060
00061 nassertv(_texture != (Texture *)NULL);
00062 _texture->set_minfilter(Texture::FT_linear);
00063 _texture->set_magfilter(Texture::FT_linear);
00064 _texture->set_wrapu(Texture::WM_clamp);
00065 _texture->set_wrapv(Texture::WM_clamp);
00066 }
00067
00068
00069
00070
00071
00072
00073 void SpheretexShader::
00074 apply(Node *node, const AllAttributesWrapper &init_state,
00075 const AllTransitionsWrapper &net_trans, GraphicsStateGuardian *gsg) {
00076
00077 Shader::apply(node, init_state, net_trans, gsg);
00078
00079
00080 AllTransitionsWrapper trans(net_trans);
00081
00082
00083 TexGenTransition *tg = new TexGenTransition;
00084 tg->set_sphere_map();
00085 trans.set_transition(tg);
00086
00087
00088 nassertv(_texture != (Texture *)NULL);
00089 TextureTransition *t = new TextureTransition;
00090 t->set_on(_texture);
00091 t->set_priority(_priority);
00092 trans.set_transition(t);
00093
00094 if (_viz != (Shader::Visualize*)0L)
00095 _viz->DisplayTexture(_texture, this);
00096
00097
00098 trans.set_transition(new TexMatrixTransition(LMatrix4f::ident_mat()));
00099
00100
00101 trans.set_transition(new LightTransition(LightTransition::all_off()));
00102 gsg->enable_normals(true);
00103
00104
00105
00106 if (_multipass_on) {
00107
00108
00109 ColorBlendTransition *cb =
00110 new ColorBlendTransition(_blend_mode);
00111 trans.set_transition(cb);
00112
00113 TextureApplyTransition *ta =
00114 new TextureApplyTransition(TextureApplyProperty::M_decal);
00115 trans.set_transition(ta);
00116
00117
00118 DepthTestTransition *dta =
00119 new DepthTestTransition(DepthTestProperty::M_equal);
00120 trans.set_transition(dta);
00121 }
00122
00123
00124 DirectRenderTraverser drt(gsg, RenderRelation::get_class_type());
00125 gsg->render_subgraph(&drt, node, init_state, trans);
00126
00127 gsg->enable_normals(false);
00128 }
00129
00130
00131