aboutsummaryrefslogtreecommitdiff
path: root/js/lib/rdge/materials/keleidoscope-material.js
diff options
context:
space:
mode:
Diffstat (limited to 'js/lib/rdge/materials/keleidoscope-material.js')
-rw-r--r--js/lib/rdge/materials/keleidoscope-material.js173
1 files changed, 92 insertions, 81 deletions
<
diff --git a/js/lib/rdge/materials/keleidoscope-material.js b/js/lib/rdge/materials/keleidoscope-material.js
index 648bf401..a935dbda 100644
--- a/js/lib/rdge/materials/keleidoscope-material.js
+++ b/js/lib/rdge/materials/keleidoscope-material.js
@@ -1,24 +1,25 @@
1/* <copyright> 1/* <copyright>
2Copyright (c) 2012, Motorola Mobility, Inc 2Copyright (c) 2012, Motorola Mobility LLC.
3All Rights Reserved. 3All Rights Reserved.
4BSD License.
5 4
6Redistribution and use in source and binary forms, with or without 5Redistribution and use in source and binary forms, with or without
7modification, are permitted provided that the following conditions are met: 6modification, are permitted provided that the following conditions are met:
8 7
9 - Redistributions of source code must retain the above copyright notice, 8* Redistributions of source code must retain the above copyright notice,
10 this list of conditions and the following disclaimer. 9 this list of conditions and the following disclaimer.
11 - Redistributions in binary form must reproduce the above copyright 10
12 notice, this list of conditions and the following disclaimer in the 11* Redistributions in binary form must reproduce the above copyright notice,
13 documentation and/or other materials provided with the distribution. 12 this list of conditions and the following disclaimer in the documentation
14 - Neither the name of Motorola Mobility nor the names of its contributors 13 and/or other materials provided with the distribution.
15 may be used to endorse or promote products derived from this software 14
16 without specific prior written permission. 15* Neither the name of Motorola Mobility LLC nor the names of its
16 contributors may be used to endorse or promote products derived from this
17 software without specific prior written permission.
17 18
18THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 19THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 22ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
22LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 23LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 24CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
@@ -35,13 +36,13 @@ var KeleidoscopeMaterial = function KeleidoscopeMaterial() {
35 /////////////////////////////////////////////////////////////////////// 36 ///////////////////////////////////////////////////////////////////////
36 // Instance variables 37 // Instance variables
37 /////////////////////////////////////////////////////////////////////// 38 ///////////////////////////////////////////////////////////////////////
38 this._name = "Keleidoscope"; 39 this._name = "Keleidoscope";
39 this._shaderName = "keleidoscope"; 40 this._shaderName = "keleidoscope";
40 41
41 this._defaultTexMap = 'assets/images/rocky-normal.jpg'; 42 this._defaultTexMap = 'assets/images/rocky-normal.jpg';
42 43
43 this._time = 0.0; 44 this._time = 0.0;
44 this._dTime = 0.01; 45 this._dTime = 0.01;
45 46
46 // array textures indexed by shader uniform name 47 // array textures indexed by shader uniform name
47 this._glTextures = []; 48 this._glTextures = [];
@@ -49,21 +50,21 @@ var KeleidoscopeMaterial = function KeleidoscopeMaterial() {
49 /////////////////////////////////////////////////////////////////////// 50 ///////////////////////////////////////////////////////////////////////
50 // Properties 51 // Properties
51 /////////////////////////////////////////////////////////////////////// 52 ///////////////////////////////////////////////////////////////////////
52 // all defined in parent PulseMaterial.js 53 // all defined in parent PulseMaterial.js
53 // load the local default value 54 // load the local default value
54 var u_tex0_index = 0, u_speed_index = 1; 55 var u_tex0_index = 0, u_speed_index = 1;
55 this._propNames = ["u_tex0", "u_speed" ]; 56 this._propNames = ["u_tex0", "u_speed" ];
56 this._propLabels = ["Texture map", "Speed" ]; 57 this._propLabels = ["Texture map", "Speed" ];
57 this._propTypes = ["file", "float" ]; 58 this._propTypes = ["file", "float" ];
58 this._propValues = []; 59 this._propValues = [];
59 this._propValues[this._propNames[u_tex0_index]] = this._defaultTexMap.slice(0); 60 this._propValues[this._propNames[u_tex0_index]] = this._defaultTexMap.slice(0);
60 this._propValues[this._propNames[u_speed_index]] = 1.0; 61 this._propValues[this._propNames[u_speed_index]] = 1.0;
61 62
62 /////////////////////////////////////////////////////////////////////// 63 ///////////////////////////////////////////////////////////////////////
63 // Material Property Accessors 64 // Material Property Accessors
64 /////////////////////////////////////////////////////////////////////// 65 ///////////////////////////////////////////////////////////////////////
65 this.isAnimated = function() { return true; }; 66 this.isAnimated = function() { return true; };
66 this.getShaderDef = function() { return keleidoscopeMaterialDef; } 67 this.getShaderDef = function() { return keleidoscopeMaterialDef; }
67 68
68 /////////////////////////////////////////////////////////////////////// 69 ///////////////////////////////////////////////////////////////////////
69 70
@@ -71,75 +72,85 @@ var KeleidoscopeMaterial = function KeleidoscopeMaterial() {
71 /////////////////////////////////////////////////////////////////////// 72 ///////////////////////////////////////////////////////////////////////
72 // Methods 73 // Methods
73 /////////////////////////////////////////////////////////////////////// 74 ///////////////////////////////////////////////////////////////////////
74 // duplcate method requirde 75 // duplcate method requirde
75 76
76 this.init = function( world ) { 77 this.init = function( world ) {
77 // save the world 78 // save the world
78 if (world) this.setWorld( world ); 79 if (world) this.setWorld( world );
79 80
80 // set up the shader 81 // set up the shader
81 this._shader = new RDGE.jshader(); 82 this._shader = new RDGE.jshader();
82 this._shader.def = keleidoscopeMaterialDef; 83 this._shader.def = keleidoscopeMaterialDef;
83 this._shader.init(); 84 this._shader.init();
84 85
85 // set up the material node 86 // set up the material node
86 this._materialNode = RDGE.createMaterialNode("keleidoscopeMaterial" + "_" + world.generateUniqueNodeID()); 87 this._materialNode = RDGE.createMaterialNode("keleidoscopeMaterial" + "_" + world.generateUniqueNodeID());
87 this._materialNode.setShader(this._shader); 88 this._materialNode.setShader(this._shader);
88 89
89 this._time = 0; 90 this._time = 0;
90 if (this._shader && this._shader['default']) { 91 if (this._shader && this._shader['default']) {
91 this._shader['default'].u_time.set( [this._time] ); 92 this._shader['default'].u_time.set( [this._time] );
92 } 93 }
93 94
94 // set the shader values in the shader 95 // set the shader values in the shader
95 this.setShaderValues(); 96 this.setShaderValues();
96 this.setResolution( [world.getViewportWidth(),world.getViewportHeight()] ); 97 this.setResolution( [world.getViewportWidth(),world.getViewportHeight()] );
97 this.update( 0 ); 98 this.update( 0 );
98 }; 99 };
100
101 this.resetToDefault = function()
102 {
103 this._propValues[this._propNames[u_tex0_index]] = this._defaultTexMap.slice(0);
104 this._propValues[this._propNames[u_speed_index]] = 1.0;
105
106 var nProps = this._propNames.length;
107 for (var i=0; i<nProps; i++)
108 this.setProperty( this._propNames[i], this._propValues[this._propNames[i]] );
109};
99}; 110};
100 111
101/////////////////////////////////////////////////////////////////////////////////////// 112///////////////////////////////////////////////////////////////////////////////////////
102// RDGE shader 113// RDGE shader
103 114
104// shader spec (can also be loaded from a .JSON file, or constructed at runtime) 115// shader spec (can also be loaded from a .JSON file, or constructed at runtime)
105var keleidoscopeMaterialDef = 116var keleidoscopeMaterialDef =
106{'shaders': 117{'shaders':
107 { 118 {
108 'defaultVShader':"assets/shaders/Basic.vert.glsl", 119 'defaultVShader':"assets/shaders/Basic.vert.glsl",
109 'defaultFShader':"assets/shaders/Keleidoscope.frag.glsl" 120 'defaultFShader':"assets/shaders/Keleidoscope.frag.glsl"
110 }, 121 },
111 'techniques': 122 'techniques':
112 { 123 {
113 'default': 124 'default':
114 [ 125 [
115 { 126 {
116 'vshader' : 'defaultVShader', 127 'vshader' : 'defaultVShader',
117 'fshader' : 'defaultFShader', 128 'fshader' : 'defaultFShader',
118 // attributes 129 // attributes
119 'attributes' : 130 'attributes' :
120 { 131 {
121 'vert' : { 'type' : 'vec3' }, 132 'vert' : { 'type' : 'vec3' },
122 'normal' : { 'type' : 'vec3' }, 133 'normal' : { 'type' : 'vec3' },
123 'texcoord' : { 'type' : 'vec2' } 134 'texcoord' : { 'type' : 'vec2' }
124 }, 135 },
125 // parameters 136 // parameters
126 'params' : 137 'params' :
127 { 138 {
128 'u_tex0': { 'type' : 'tex2d' }, 139 'u_tex0': { 'type' : 'tex2d' },
129 'u_speed' : { 'type' : 'float' }, 140 'u_speed' : { 'type' : 'float' },
130 'u_time' : { 'type' : 'float' }, 141 'u_time' : { 'type' : 'float' },
131 'u_resolution' : { 'type' : 'vec2' }, 142 'u_resolution' : { 'type' : 'vec2' },
132 }, 143 },
133 144
134 // render states 145