aboutsummaryrefslogtreecommitdiff
path: root/js/lib/rdge/materials/pulse-material.js
diff options
context:
space:
mode:
Diffstat (limited to 'js/lib/rdge/materials/pulse-material.js')
-rw-r--r--js/lib/rdge/materials/pulse-material.js308
1 files changed, 154 insertions, 154 deletions
diff --git a/js/lib/rdge/materials/pulse-material.js b/js/lib/rdge/materials/pulse-material.js
index 4d5a158d..4356c911 100644
--- a/js/lib/rdge/materials/pulse-material.js
+++ b/js/lib/rdge/materials/pulse-material.js
@@ -37,124 +37,124 @@ var Texture = require("js/lib/rdge/texture").Texture;
37/////////////////////////////////////////////////////////////////////// 37///////////////////////////////////////////////////////////////////////
38var PulseMaterial = function PulseMaterial() 38var PulseMaterial = function PulseMaterial()
39{ 39{
40 var MaterialLibrary = require("js/models/materials-model").MaterialsModel; 40 var MaterialLibrary = require("js/models/materials-model").MaterialsModel;
41 41
42 // initialize the inherited members 42 // initialize the inherited members
43 this.inheritedFrom = Material; 43 this.inheritedFrom = Material;
44 this.inheritedFrom(); 44 this.inheritedFrom();
45 45
46 /////////////////////////////////////////////////////////////////////// 46 ///////////////////////////////////////////////////////////////////////
47 // Instance variables 47 // Instance variables
48 /////////////////////////////////////////////////////////////////////// 48 ///////////////////////////////////////////////////////////////////////
49 this._name = "Pulse"; 49 this._name = "Pulse";
50 this._shaderName = "pulse"; 50 this._shaderName = "pulse";
51 51
52 this._texMap = 'assets/images/cubelight.png'; 52 this._texMap = 'assets/images/cubelight.png';
53 53
54 this._time = 0.0; 54 this._time = 0.0;
55 this._dTime = 0.01; 55 this._dTime = 0.01;
56 56
57 this._glTextures = []; 57 this._glTextures = [];
58 58
59 /////////////////////////////////////////////////////////////////////// 59 ///////////////////////////////////////////////////////////////////////
60 // Property Accessors 60 // Property Accessors
61 /////////////////////////////////////////////////////////////////////// 61 ///////////////////////////////////////////////////////////////////////
62 this.isAnimated = function() { return true; }; 62 this.isAnimated = function() { return true; };
63 this.getShaderDef = function() { return pulseMaterialDef; } 63 this.getShaderDef = function() { return pulseMaterialDef; }
64 64
65 /////////////////////////////////////////////////////////////////////// 65 ///////////////////////////////////////////////////////////////////////
66 // Material Property Accessors 66 // Material Property Accessors
67 /////////////////////////////////////////////////////////////////////// 67 ///////////////////////////////////////////////////////////////////////
68 68
69 var u_tex0_index = 0, 69 var u_tex0_index = 0,
70 u_xScale_index = 1, 70 u_xScale_index = 1,
71 u_yScale_index = 2, 71 u_yScale_index = 2,
72 u_speed_index = 3; 72 u_speed_index = 3;
73 73
74 this._propNames = ["u_tex0", "u_xscale", "u_yscale", "u_speed" ]; 74 this._propNames = ["u_tex0", "u_xscale", "u_yscale", "u_speed" ];
75 this._propLabels = ["Texture map", "X Range", "Y Range", "Speed" ]; 75 this._propLabels = ["Texture map", "X Range", "Y Range", "Speed" ];
76 this._propTypes = ["file", "float", "float", "float"]; 76 this._propTypes = ["file", "float", "float", "float"];
77 this._propValues = []; 77 this._propValues = [];
78 78
79 this._propValues[ this._propNames[ u_tex0_index] ] = this._texMap.slice(0); 79 this._propValues[ this._propNames[ u_tex0_index] ] = this._texMap.slice(0);
80 this._propValues[ this._propNames[u_xScale_index] ] = 0.5; 80 this._propValues[ this._propNames[u_xScale_index] ] = 0.5;
81 this._propValues[ this._propNames[u_yScale_index] ] = 0.4; 81 this._propValues[ this._propNames[u_yScale_index] ] = 0.4;
82 this._propValues[ this._propNames[ u_speed_index] ] = 1.0; 82 this._propValues[ this._propNames[ u_speed_index] ] = 1.0;
83 /////////////////////////////////////////////////////////////////////// 83 ///////////////////////////////////////////////////////////////////////
84 84
85 85
86 /////////////////////////////////////////////////////////////////////// 86 ///////////////////////////////////////////////////////////////////////
87 // Methods 87 // Methods
88 /////////////////////////////////////////////////////////////////////// 88 ///////////////////////////////////////////////////////////////////////
89 // duplicate method required 89 // duplicate method required
90 90
91 this.init = function( world ) 91 this.init = function( world )
92 { 92 {
93 // save the world 93 // save the world
94 if (world) this.setWorld( world ); 94 if (world) this.setWorld( world );
95 95
96 // this variable declared above is inherited set to a smaller delta. 96 // this variable declared above is inherited set to a smaller delta.
97 // the pulse material runs a little faster 97 // the pulse material runs a little faster
98 this._dTime = 0.01; 98 this._dTime = 0.01;
99 99
100 // set up the shader 100 // set up the shader
101 this._shader = new RDGE.jshader(); 101 this._shader = new RDGE.jshader();
102 this._shader.def = pulseMaterialDef; 102 this._shader.def = pulseMaterialDef;
103 this._shader.init(); 103 this._shader.init();
104 104
105 // set up the material node 105 // set up the material node
106 this._materialNode = RDGE.createMaterialNode("pulseMaterial" + "_" + world.generateUniqueNodeID()); 106 this._materialNode = RDGE.createMaterialNode("pulseMaterial" + "_" + world.generateUniqueNodeID());
107 this._materialNode.setShader(this._shader); 107 this._materialNode.setShader(this._shader);
108 108
109 this._time = 0; 109 this._time = 0;
110 if (this._shader && this._shader['default']) { 110 if (this._shader && this._shader['default']) {
111 this._shader['default'].u_time.set( [this._time] ); 111 this._shader['default'].u_time.set( [this._time] );
112 } 112 }
113 113
114 // set the shader values in the shader 114 // set the shader values in the shader
115 this.setShaderValues(); 115 this.setShaderValues();
116 this.setResolution( [world.getViewportWidth(),world.getViewportHeight()] ); 116 this.setResolution( [world.getViewportWidth(),world.getViewportHeight()] );
117 this.update( 0 ); 117 this.update( 0 );
118 }; 118 };
119 119
120 this.update = function( time ) 120 this.update = function( time )
121 { 121 {
122 var material = this._materialNode; 122 var material = this._materialNode;
123 if (material) 123 if (material)
124 { 124 {
125 var technique = material.shaderProgram['default']; 125 var technique = material.shaderProgram['default'];
126 var renderer = RDGE.globals.engine.getContext().renderer; 126 var renderer = RDGE.globals.engine.getContext().renderer;
127 if (renderer && technique) 127 if (renderer && technique)
128 { 128 {
129 var glTex = this._glTextures["u_tex0"]; 129 var glTex = this._glTextures["u_tex0"];
130 if (glTex) 130 if (glTex)
131 { 131 {
132 //this.updateTexture(); 132 //this.updateTexture();
133 if (glTex.isAnimated()) 133 if (glTex.isAnimated())
134 glTex.render(); 134 glTex.render();
135 tex = glTex.getTexture(); 135 tex = glTex.getTexture();
136 if (tex) 136 if (tex)
137 technique.u_tex0.set( tex ); 137 technique.u_tex0.set( tex );
138 } 138 }
139 139
140 if (this._shader && this._shader['default']) { 140 if (this._shader && this._shader['default']) {
141 this._shader['default'].u_time.set( [this._time] ); 141 this._shader['default'].u_time.set( [this._time] );
142 } 142 }
143 this._time += this._dTime; 143 this._time += this._dTime;
144 } 144 }
145 } 145 }
146 }; 146 };
147 147
148 this.setResolution = function( res ) { 148 this.setResolution = function( res ) {
149 var material = this._materialNode; 149 var material = this._materialNode;
150 if (material) { 150 if (material) {
151 var technique = material.shaderProgram['default']; 151 var technique = material.shaderProgram['default'];
152 var renderer = RDGE.globals.engine.getContext().renderer; 152 var renderer = RDGE.globals.engine.getContext().renderer;
153 if (renderer && technique) { 153 if (renderer && technique) {
154 technique.u_resolution.set( res ); 154 technique.u_resolution.set( res );
155 } 155 }
156 } 156 }
157 }; 157 };
158 158
159}; 159};
160 160
@@ -164,49 +164,49 @@ var PulseMaterial = function PulseMaterial()
164// shader spec (can also be loaded from a .JSON file, or constructed at runtime) 164// shader spec (can also be loaded from a .JSON file, or constructed at runtime)
165var pulseMaterialDef = 165var pulseMaterialDef =
166{'shaders': 166{'shaders':
167 { 167 {
168 'defaultVShader':"assets/shaders/Basic.vert.glsl", 168 'defaultVShader':"assets/shaders/Basic.vert.glsl",
169 'defaultFShader':"assets/shaders/Pulse.frag.glsl" 169 'defaultFShader':"assets/shaders/Pulse.frag.glsl"
170 }, 170 },
171 'techniques': 171 'techniques':
172 {