aboutsummaryrefslogtreecommitdiff
path: root/js/lib/rdge/materials/fly-material.js
diff options
context:
space:
mode:
Diffstat (limited to 'js/lib/rdge/materials/fly-material.js')
-rw-r--r--js/lib/rdge/materials/fly-material.js142
1 files changed, 71 insertions, 71 deletions
diff --git a/js/lib/rdge/materials/fly-material.js b/js/lib/rdge/materials/fly-material.js
index eabc32ea..873f82ce 100644
--- a/js/lib/rdge/materials/fly-material.js
+++ b/js/lib/rdge/materials/fly-material.js
@@ -35,13 +35,13 @@ var FlyMaterial = function FlyMaterial() {
35 /////////////////////////////////////////////////////////////////////// 35 ///////////////////////////////////////////////////////////////////////
36 // Instance variables 36 // Instance variables
37 /////////////////////////////////////////////////////////////////////// 37 ///////////////////////////////////////////////////////////////////////
38 this._name = "Fly"; 38 this._name = "Fly";
39 this._shaderName = "fly"; 39 this._shaderName = "fly";
40 40
41 this._defaultTexMap = 'assets/images/rocky-normal.jpg'; 41 this._defaultTexMap = 'assets/images/rocky-normal.jpg';
42 42
43 this._time = 0.0; 43 this._time = 0.0;
44 this._dTime = 0.01; 44 this._dTime = 0.01;
45 45
46 // array textures indexed by shader uniform name 46 // array textures indexed by shader uniform name
47 this._glTextures = []; 47 this._glTextures = [];
@@ -49,50 +49,50 @@ var FlyMaterial = function FlyMaterial() {
49 /////////////////////////////////////////////////////////////////////// 49 ///////////////////////////////////////////////////////////////////////
50 // Properties 50 // Properties
51 /////////////////////////////////////////////////////////////////////// 51 ///////////////////////////////////////////////////////////////////////
52 // all defined in parent PulseMaterial.js 52 // all defined in parent PulseMaterial.js
53 // load the local default value 53 // load the local default value
54 var u_tex0_index = 0, u_speed_index = 1; 54 var u_tex0_index = 0, u_speed_index = 1;
55 this._propNames = ["u_tex0", "u_speed" ]; 55 this._propNames = ["u_tex0", "u_speed" ];
56 this._propLabels = ["Texture map", "Speed" ]; 56 this._propLabels = ["Texture map", "Speed" ];
57 this._propTypes = ["file", "float" ]; 57 this._propTypes = ["file", "float" ];
58 this._propValues = []; 58 this._propValues = [];
59 this._propValues[this._propNames[u_tex0_index]] = this._defaultTexMap.slice(0); 59 this._propValues[this._propNames[u_tex0_index]] = this._defaultTexMap.slice(0);
60 this._propValues[this._propNames[u_speed_index]] = 1.0; 60 this._propValues[this._propNames[u_speed_index]] = 1.0;
61 61
62 /////////////////////////////////////////////////////////////////////// 62 ///////////////////////////////////////////////////////////////////////
63 // Material Property Accessors 63 // Material Property Accessors
64 /////////////////////////////////////////////////////////////////////// 64 ///////////////////////////////////////////////////////////////////////
65 this.isAnimated = function() { return true; }; 65 this.isAnimated = function() { return true; };
66 this.getShaderDef = function() { return flyMaterialDef; }; 66 this.getShaderDef = function() { return flyMaterialDef; };
67 67
68 /////////////////////////////////////////////////////////////////////// 68 ///////////////////////////////////////////////////////////////////////
69 // Methods 69 // Methods
70 /////////////////////////////////////////////////////////////////////// 70 ///////////////////////////////////////////////////////////////////////
71 // duplcate method requirde 71 // duplcate method requirde
72 72
73 this.init = function( world ) { 73 this.init = function( world ) {
74 // save the world 74 // save the world
75 if (world) this.setWorld( world ); 75 if (world) this.setWorld( world );
76 76
77 // set up the shader 77 // set up the shader
78 this._shader = new RDGE.jshader(); 78 this._shader = new RDGE.jshader();
79 this._shader.def = flyMaterialDef; 79 this._shader.def = flyMaterialDef;
80 this._shader.init(); 80 this._shader.init();
81 81
82 // set up the material node 82 // set up the material node
83 this._materialNode = RDGE.createMaterialNode("flyMaterial" + "_" + world.generateUniqueNodeID()); 83 this._materialNode = RDGE.createMaterialNode("flyMaterial" + "_" + world.generateUniqueNodeID());
84 this._materialNode.setShader(this._shader); 84 this._materialNode.setShader(this._shader);
85 85
86 this._time = 0; 86 this._time = 0;
87 if (this._shader && this._shader['default']) { 87 if (this._shader && this._shader['default']) {
88 this._shader['default'].u_time.set( [this._time] ); 88 this._shader['default'].u_time.set( [this._time] );
89 } 89 }
90 90
91 // set the shader values in the shader 91 // set the shader values in the shader
92 this.setShaderValues(); 92 this.setShaderValues();
93 this.setResolution( [world.getViewportWidth(),world.getViewportHeight()] ); 93 this.setResolution( [world.getViewportWidth(),world.getViewportHeight()] );
94 this.update( 0 ); 94 this.update( 0 );
95 }; 95 };
96 96
97 this.resetToDefault = function() 97 this.resetToDefault = function()
98 { 98 {
@@ -102,52 +102,52 @@ var FlyMaterial = function FlyMaterial() {
102 var nProps = this._propNames.length; 102 var nProps = this._propNames.length;
103 for (var i=0; i<nProps; i++) 103 for (var i=0; i<nProps; i++)
104 this.setProperty( this._propNames[i], this._propValues[this._propNames[i]] ); 104 this.setProperty( this._propNames[i], this._propValues[this._propNames[i]] );
105 }; 105};
106}; 106};
107 107
108/////////////////////////////////////////////////////////////////////////////////////// 108///////////////////////////////////////////////////////////////////////////////////////
109// RDGE shader 109// RDGE shader
110 110
111// shader spec (can also be loaded from a .JSON file, or constructed at runtime) 111// shader spec (can also be loaded from a .JSON file, or constructed at runtime)
112var flyMaterialDef = 112var flyMaterialDef =
113{ 113{
114 'shaders': 114 'shaders':
115 { 115 {
116 'defaultVShader':"assets/shaders/Basic.vert.glsl", 116 'defaultVShader':"assets/shaders/Basic.vert.glsl",
117 'defaultFShader':"assets/shaders/Fly.frag.glsl" 117 'defaultFShader':"assets/shaders/Fly.frag.glsl"
118 }, 118 },
119 'techniques': 119 'techniques':
120 { 120 {
121 'default': 121 'default':
122 [ 122 [
123 { 123 {
124 'vshader' : 'defaultVShader', 124 'vshader' : 'defaultVShader',
125 'fshader' : 'defaultFShader', 125 'fshader' : 'defaultFShader',
126 // attributes 126 // attributes
127 'attributes' : 127 'attributes' :
128 { 128 {
129 'vert' : { 'type' : 'vec3' }, 129 'vert' : { 'type' : 'vec3' },
130 'normal' : { 'type' : 'vec3' }, 130 'normal' : { 'type' : 'vec3' },
131 'texcoord' : { 'type' : 'vec2' } 131 'texcoord' : { 'type' : 'vec2' }
132 }, 132 },
133 // parameters 133 // parameters
134 'params' : 134 'params' :
135 { 135 {
136 'u_tex0': { 'type' : 'tex2d' }, 136 'u_tex0': { 'type' : 'tex2d' },
137 'u_time' : { 'type' : 'float' }, 137 'u_time' : { 'type' : 'float' },
138 'u_speed' : { 'type' : 'float' }, 138 'u_speed' : { 'type' : 'float' },
139 'u_resolution' : { 'type' : 'vec2' }, 139 'u_resolution' : { 'type' : 'vec2' },
140 }, 140 },
141 141
142 // render states 142 // render states
143 'states' : 143 'states' :
144 { 144 {
145 'depthEnable' : true, 145 'depthEnable' : true,
146 'offset':[1.0, 0.1] 146 'offset':[1.0, 0.1]
147 } 147 }
148 } 148 }
149 ] 149 ]
150 } 150 }
151}; 151};
152 152
153FlyMaterial.prototype = new PulseMaterial(); 153FlyMaterial.prototype = new PulseMaterial();