aboutsummaryrefslogtreecommitdiff
path: root/js/lib/rdge/materials/twist-vert-material.js
diff options
context:
space:
mode:
Diffstat (limited to 'js/lib/rdge/materials/twist-vert-material.js')
-rw-r--r--js/lib/rdge/materials/twist-vert-material.js290
1 files changed, 145 insertions, 145 deletions
diff --git a/js/lib/rdge/materials/twist-vert-material.js b/js/lib/rdge/materials/twist-vert-material.js
index 6b71593f..6ab2662e 100644
--- a/js/lib/rdge/materials/twist-vert-material.js
+++ b/js/lib/rdge/materials/twist-vert-material.js
@@ -37,159 +37,159 @@ var Texture = require("js/lib/rdge/texture").Texture;
37/////////////////////////////////////////////////////////////////////// 37///////////////////////////////////////////////////////////////////////
38var TwistVertMaterial = function TwistVertMaterial() 38var TwistVertMaterial = function TwistVertMaterial()
39{ 39{
40 // initialize the inherited members 40 // initialize the inherited members
41 this.inheritedFrom = Material; 41 this.inheritedFrom = Material;
42 this.inheritedFrom(); 42 this.inheritedFrom();
43 43
44 /////////////////////////////////////////////////////////////////////// 44 ///////////////////////////////////////////////////////////////////////
45 // Instance variables 45 // Instance variables
46 /////////////////////////////////////////////////////////////////////// 46 ///////////////////////////////////////////////////////////////////////
47 this._name = "Twist Vertex"; 47 this._name = "Twist Vertex";
48 this._shaderName = "twistVert"; 48 this._shaderName = "twistVert";
49 49
50 this._tex0 = 'assets/images/rocky-normal.jpg'; 50 this._tex0 = 'assets/images/rocky-normal.jpg';
51 this._tex1 = 'assets/images/metal.png'; 51 this._tex1 = 'assets/images/metal.png';
52 52
53 this._angle = 0.0; 53 this._angle = 0.0;
54 this._deltaTime = 0.01; 54 this._deltaTime = 0.01;
55 this._speed = 1.0; 55 this._speed = 1.0;
56 56
57 /////////////////////////////////////////////////////////////////////// 57 ///////////////////////////////////////////////////////////////////////
58 // Property Accessors 58 // Property Accessors
59 /////////////////////////////////////////////////////////////////////// 59 ///////////////////////////////////////////////////////////////////////
60 this.getShaderName = function () { return this._shaderName; }; 60 this.getShaderName = function () { return this._shaderName; };
61 this.isAnimated = function () { return true; }; 61 this.isAnimated = function () { return true; };
62 this.getShaderDef = function() { return twistVertShaderDef; }; 62 this.getShaderDef = function() { return twistVertShaderDef; };
63 this.getTechniqueName = function() { return 'twistMe' }; 63 this.getTechniqueName = function() { return 'twistMe' };
64 64
65 this.hasVertexDeformation = function () { return this._hasVertexDeformation; }; 65 this.hasVertexDeformation = function () { return this._hasVertexDeformation; };
66 this._hasVertexDeformation = true; 66 this._hasVertexDeformation = true;
67 this._vertexDeformationTolerance = 0.02; // should be a property 67 this._vertexDeformationTolerance = 0.02; // should be a property
68 68
69 /////////////////////////////////////////////////////////////////////// 69 ///////////////////////////////////////////////////////////////////////
70 // Material Property Accessors 70 // Material Property Accessors
71 /////////////////////////////////////////////////////////////////////// 71 ///////////////////////////////////////////////////////////////////////
72 this._propNames = [ "u_limit1", "u_limit2", "u_twistAmount", "speed", "u_tex0", "u_tex1"]; 72 this._propNames = [ "u_limit1", "u_limit2", "u_twistAmount", "speed", "u_tex0", "u_tex1"];
73 this._propLabels = [ "Start Parameter", "End Paramater", "Twist Amount", "Speed", "Front facing texture map", "Back facing texture map"]; 73 this._propLabels = [ "Start Parameter", "End Paramater", "Twist Amount", "Speed", "Front facing texture map", "Back facing texture map"];
74 this._propTypes = [ "float", "float", "angle", "float", "file", "file"]; 74 this._propTypes = [ "float", "float", "angle", "float", "file", "file"];
75 this._propValues = []; 75 this._propValues = [];
76 76
77 // initialize the property values 77 // initialize the property values
78 this._propValues[this._propNames[0]] = 0.0; 78 this._propValues[this._propNames[0]] = 0.0;
79 this._propValues[this._propNames[1]] = 1.0; 79 this._propValues[this._propNames[1]] = 1.0;
80 this._propValues[this._propNames[2]] = 2.0 * Math.PI; 80 this._propValues[this._propNames[2]] = 2.0 * Math.PI;
81 this._propValues[this._propNames[3]] = this._speed; 81 this._propValues[this._propNames[3]] = this._speed;
82 this._propValues[this._propNames[4]] = this._tex0.slice(); 82 this._propValues[this._propNames[4]] = this._tex0.slice();
83 this._propValues[this._propNames[5]] = this._tex1.slice(); 83 this._propValues[this._propNames[5]] = this._tex1.slice();
84 /////////////////////////////////////////////////////////////////////// 84 ///////////////////////////////////////////////////////////////////////
85 85
86 /////////////////////////////////////////////////////////////////////// 86 ///////////////////////////////////////////////////////////////////////
87 // Methods 87 // Methods
88 /////////////////////////////////////////////////////////////////////// 88 ///////////////////////////////////////////////////////////////////////
89 89
90 this.init = function (world) 90 this.init = function (world)
91 { 91 {
92 this.setWorld(world); 92 this.setWorld(world);
93 93
94 // set up the shader 94 // set up the shader
95 this._shader = new RDGE.jshader(); 95 this._shader = new RDGE.jshader();
96 this._shader.def = twistVertShaderDef; 96 this._shader.def = twistVertShaderDef;
97 this._shader.init(); 97 this._shader.init();
98 98
99 // set up the material node 99 // set up the material node
100 this._materialNode = RDGE.createMaterialNode("twistVertMaterial" + "_" + world.generateUniqueNodeID()); 100 this._materialNode = RDGE.createMaterialNode("twistVertMaterial" + "_" + world.generateUniqueNodeID());
101 this._materialNode.setShader(this._shader); 101 this._materialNode.setShader(this._shader);
102 102
103 103
104 // initialize the twist vert properties 104 // initialize the twist vert properties
105 this.setShaderValues(); 105 this.setShaderValues();
106 }; 106 };
107 107
108 this.update = function (time) 108 this.update = function (time)
109 { 109 {
110 if (this._shader && this._shader.twistMe) 110 if (this._shader && this._shader.twistMe)
111 { 111 {
112 var technique = this._shader.twistMe; 112 var technique = this._shader.twistMe;
113 113
114 var angle = this._angle; 114 var angle = this._angle;
115 angle += this._deltaTime * this._propValues["speed"]; 115 angle += this._deltaTime * this._propValues["speed"];
116 if (angle > this._propValues["u_twistAmount"]) 116 if (angle > this._propValues["u_twistAmount"])
117 { 117 {
118 angle = this._propValues["u_twistAmount"]; 118 angle = this._propValues["u_twistAmount"];
119 this._deltaTime = -this._deltaTime; 119 this._deltaTime = -this._deltaTime;
120 } 120 }
121 else if (angle < 0.0) 121 else if (angle < 0.0)
122 { 122 {
123 angle = 0; 123 angle = 0;
124 this._deltaTime = -this._deltaTime; 124 this._deltaTime = -this._deltaTime;
125 } 125 }
126 this._angle = angle; 126 this._angle = angle;
127 this._shader.twistMe["u_twistAmount"].set([angle]); 127 this._shader.twistMe["u_twistAmount"].set([angle]);
128 128
129 var tex; 129 var tex;
130 var glTex = this._glTextures["u_tex0"]; 130 var glTex = this._glTextures["u_tex0"];
131 if (glTex) 131 if (glTex)
132 { 132 {
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 glTex = this._glTextures["u_tex1"]; 140 glTex = this._glTextures["u_tex1"];
141 if (glTex) 141 if (glTex)
142 { 142 {
143 //if (glTex.isAnimated()) 143 //if (glTex.isAnimated())
144 glTex.render(); 144 glTex.render();
145 tex = glTex.getTexture(); 145 tex = glTex.getTexture();
146 if (tex) 146 if (tex)
147 technique.u_tex1.set( tex ); 147 technique.u_tex1.set( tex );
148 } 148 }
149 149
150 } 150 }
151 } 151 }
152}; 152};
153 153
154// shader spec (can also be loaded from a .JSON file, or constructed at runtime) 154// shader spec (can also be loaded from a .JSON file, or constructed at runtime)
155twistVertShaderDef = 155twistVertShaderDef =
156{ 156{
157 'shaders': { // shader files 157 'shaders': { // shader files
158 'defaultVShader': "assets/shaders/TwistVert.vert.glsl", 158 'defaultVShader': "assets/shaders/TwistVert.vert.glsl",
159 'defaultFShader': "assets/shaders/TwistVert.frag.glsl" 159 'defaultFShader': "assets/shaders/TwistVert.frag.glsl"
160 }, 160 },
161 'techniques': { // rendering control 161 'techniques': { // rendering control
162 'twistMe': [ // simple color pass 162 'twistMe': [ // simple color pass
163 { 163 {
164 'vshader': 'defaultVShader', 164 'vshader': 'defaultVShader',
165 'fshader': 'defaultFShader', 165 'fshader': 'defaultFShader',
166 166
167 // attributes 167 // attributes