diff options
Diffstat (limited to 'js/lib/rdge/materials/fly-material.js')
-rw-r--r-- | js/lib/rdge/materials/fly-material.js | 150 |
1 files changed, 80 insertions, 70 deletions
diff --git a/js/lib/rdge/materials/fly-material.js b/js/lib/rdge/materials/fly-material.js index b4bf0972..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,95 +49,105 @@ 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 | |||
97 | this.resetToDefault = function() | ||
98 | { | ||
99 | this._propValues[this._propNames[u_tex0_index]] = this._defaultTexMap.slice(0); | ||
100 | this._propValues[this._propNames[u_speed_index]] = 1.0; | ||
101 | |||
102 | var nProps = this._propNames.length; | ||
103 | for (var i=0; i<nProps; i++) | ||
104 | this.setProperty( this._propNames[i], this._propValues[this._propNames[i]] ); | ||
105 | }; | ||
96 | }; | 106 | }; |
97 | 107 | ||
98 | /////////////////////////////////////////////////////////////////////////////////////// | 108 | /////////////////////////////////////////////////////////////////////////////////////// |
99 | // RDGE shader | 109 | // RDGE shader |
100 | 110 | ||
101 | // 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) |
102 | var flyMaterialDef = | 112 | var flyMaterialDef = |
103 | { | 113 | { |
104 | 'shaders': | 114 | 'shaders': |
105 | { | 115 | { |
106 | 'defaultVShader':"assets/shaders/Basic.vert.glsl", | 116 | 'defaultVShader':"assets/shaders/Basic.vert.glsl", |
107 | 'defaultFShader':"assets/shaders/Fly.frag.glsl" | 117 | 'defaultFShader':"assets/shaders/Fly.frag.glsl" |
108 | }, | 118 | }, |
109 | 'techniques': | 119 | 'techniques': |
110 | { | 120 | { |
111 | 'default': | 121 | 'default': |
112 | [ | 122 | [ |
113 | { | 123 | { |
114 | 'vshader' : 'defaultVShader', | 124 | 'vshader' : 'defaultVShader', |
115 | 'fshader' : 'defaultFShader', | 125 | 'fshader' : 'defaultFShader', |
116 | // attributes | 126 | // attributes |
117 | 'attributes' : | 127 | 'attributes' : |
118 | { | 128 | { |
119 | 'vert' : { 'type' : 'vec3' }, | 129 | 'vert' : { 'type' : 'vec3' }, |
120 | 'normal' : { 'type' : 'vec3' }, | 130 | 'normal' : { 'type' : 'vec3' }, |
121 | 'texcoord' : { 'type' : 'vec2' } | 131 | 'texcoord' : { 'type' : 'vec2' } |
122 | }, | 132 | }, |
123 | // parameters | 133 | // parameters |
124 | 'params' : | 134 | 'params' : |
125 | { | 135 | { |
126 | 'u_tex0': { 'type' : 'tex2d' }, | 136 | 'u_tex0': { 'type' : 'tex2d' }, |
127 | 'u_time' : { 'type' : 'float' }, | 137 | 'u_time' : { 'type' : 'float' }, |
128 | 'u_speed' : { 'type' : 'float' }, | 138 | 'u_speed' : { 'type' : 'float' }, |
129 | 'u_resolution' : { 'type' : 'vec2' }, | 139 | 'u_resolution' : { 'type' : 'vec2' }, |
130 | }, | 140 | }, |
131 | 141 | ||
132 | // render states | 142 | // render states |
133 | 'states' : | 143 | 'states' : |
134 | { | 144 | { |
135 | 'depthEnable' : true, | 145 | 'depthEnable' : true, |
136 | 'offset':[1.0, 0.1] | 146 | 'offset':[1.0, 0.1] |
137 | } | 147 | } |
138 | } | 148 | } |
139 | ] | 149 | ] |
140 | } | 150 | } |
141 | }; | 151 | }; |
142 | 152 | ||
143 | FlyMaterial.prototype = new PulseMaterial(); | 153 | FlyMaterial.prototype = new PulseMaterial(); |