aboutsummaryrefslogtreecommitdiff
path: root/js/lib/rdge/materials/pulse-material.js
diff options
context:
space:
mode:
authorValerio Virgillito2012-07-09 14:35:44 -0700
committerValerio Virgillito2012-07-09 14:35:44 -0700
commit84b3327bd92faafab7954b5eb64c7abe24a3fe13 (patch)
tree3f56cbed2f08c5a81ea79eaf0bcb9bd031d8a627 /js/lib/rdge/materials/pulse-material.js
parentc0a42c56f768a873ba637f5b86d5f6a84d4a3312 (diff)
parent40c6eb2c06b34f65a74d59ef9687251952858bab (diff)
downloadninja-84b3327bd92faafab7954b5eb64c7abe24a3fe13.tar.gz
Merge branch 'normalize' of https://github.com/kriskowal/ninja-internal
Conflicts: js/components/gradientpicker.reel/gradientpicker.js js/components/tools-properties/text-properties.reel/text-properties.js js/document/views/base.js js/document/views/design.js js/helper-classes/3D/StageLine.js js/helper-classes/3D/draw-utils.js js/lib/drawing/world.js js/lib/geom/circle.js js/lib/geom/line.js js/lib/geom/rectangle.js js/lib/geom/shape-primitive.js js/lib/rdge/materials/bump-metal-material.js js/lib/rdge/materials/flag-material.js js/lib/rdge/materials/fly-material.js js/lib/rdge/materials/julia-material.js js/lib/rdge/materials/keleidoscope-material.js js/lib/rdge/materials/mandel-material.js js/lib/rdge/materials/material.js js/lib/rdge/materials/plasma-material.js js/lib/rdge/materials/pulse-material.js js/lib/rdge/materials/radial-gradient-material.js js/lib/rdge/materials/taper-material.js js/lib/rdge/materials/twist-vert-material.js js/lib/rdge/materials/water-material.js js/panels/Materials/materials-library-panel.reel/materials-library-panel.html js/panels/Materials/materials-library-panel.reel/materials-library-panel.js js/panels/Materials/materials-popup.reel/materials-popup.html js/panels/Materials/materials-popup.reel/materials-popup.js js/tools/LineTool.js Signed-off-by: Valerio Virgillito <valerio@motorola.com>
Diffstat (limited to 'js/lib/rdge/materials/pulse-material.js')
-rw-r--r--js/lib/rdge/materials/pulse-material.js312
1 files changed, 156 insertions, 156 deletions
diff --git a/js/lib/rdge/materials/pulse-material.js b/js/lib/rdge/materials/pulse-material.js
index a5d17fcb..c065b4a1 100644
--- a/js/lib/rdge/materials/pulse-material.js
+++ b/js/lib/rdge/materials/pulse-material.js
@@ -37,85 +37,85 @@ 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.resetToDefault = function() 120 this.resetToDefault = function()
121 { 121 {
@@ -129,96 +129,96 @@ var PulseMaterial = function PulseMaterial()
129 this.setProperty( this._propNames[i], this._propValues[this._propNames[i]] ); 129 this.setProperty( this._propNames[i], this._propValues[this._propNames[i]] );
130 }; 130 };
131 131
132 this.update = function( time ) 132 this.update = function( time )
133 { 133 {
134 var material = this._materialNode; 134 var material = this._materialNode;
135 if (material) 135 if (material)
136 { 136 {
137 var technique = material.shaderProgram['default']; 137 var technique = material.shaderProgram['default'];
138 var renderer = RDGE.globals.engine.getContext().renderer; 138 var renderer = RDGE.globals.engine.getContext().renderer;
139 if (renderer && technique) 139 if (renderer && technique)
140 { 140 {
141 var glTex = this._glTextures["u_tex0"]; 141 var glTex = this._glTextures["u_tex0"];
142 if (glTex) 142 if (glTex)
143 { 143 {
144 //this.updateTexture(); 144 //this.updateTexture();
145 if (glTex.isAnimated()) 145 if (glTex.isAnimated())
146 glTex.render(); 146 glTex.render();
147 tex = glTex.getTexture(); 147 tex = glTex.getTexture();
148 if (tex) 148 if (tex)
149 technique.u_tex0.set( tex ); 149 technique.u_tex0.set( tex );
150 } 150 }
151 151
152 if (this._shader && this._shader['default']) { 152 if (this._shader && this._shader['default']) {
153 this._shader['default'].u_time.set( [this._time] ); 153 this._shader['default'].u_time.set( [this._time] );
154 } 154 }
155 this._time += this._dTime; 155 this._time += this._dTime;
156 } 156 }
157 } 157 }
158 }; 158 };
159 159
160 this.setResolution = function( res ) { 160 this.setResolution = function( res ) {
161 var material = this._materialNode; 161 var material = this._materialNode;
162 if (material) { 162 if (material) {
163 var technique = material.shaderProgram['default']; 163 var technique = material.shaderProgram['default'];
164 var renderer = RDGE.globals.engine.getContext().renderer; 164 var renderer = RDGE.globals.engine.getContext().renderer;
165 if (renderer && technique) { 165 if (renderer && technique) {
166 technique.u_resolution.set( res ); 166 technique.u_resolution.set( res );
167 } 167 }
168 } 168 }
169 };