aboutsummaryrefslogtreecommitdiff
path: root/js/lib/rdge/materials/water-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/water-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/water-material.js')
-rw-r--r--js/lib/rdge/materials/water-material.js274
1 files changed, 137 insertions, 137 deletions
diff --git a/js/lib/rdge/materials/water-material.js b/js/lib/rdge/materials/water-material.js
index 0b8c8235..c7b401f0 100644
--- a/js/lib/rdge/materials/water-material.js
+++ b/js/lib/rdge/materials/water-material.js
@@ -37,71 +37,71 @@ var Texture = require("js/lib/rdge/texture").Texture;
37/////////////////////////////////////////////////////////////////////// 37///////////////////////////////////////////////////////////////////////
38var WaterMaterial = function WaterMaterial() 38var WaterMaterial = function WaterMaterial()
39{ 39{
40 /////////////////////////////////////////////////////////////////////// 40 ///////////////////////////////////////////////////////////////////////
41 // Instance variables 41 // Instance variables
42 /////////////////////////////////////////////////////////////////////// 42 ///////////////////////////////////////////////////////////////////////
43 this._name = "Water"; 43 this._name = "Water";
44 this._shaderName = "water"; 44 this._shaderName = "water";
45 45
46 this._defaultTexMap = 'assets/images/rocky-normal.jpg'; 46 this._defaultTexMap = 'assets/images/rocky-normal.jpg';
47 47
48 this._time = 0.0; 48 this._time = 0.0;
49 this._dTime = 0.01; 49 this._dTime = 0.01;
50 50
51 // array textures indexed by shader uniform name 51 // array textures indexed by shader uniform name
52 this._glTextures = []; 52 this._glTextures = [];
53 53
54 this.isAnimated = function() { return true; }; 54 this.isAnimated = function() { return true; };
55 this.getShaderDef = function() { return waterMaterialDef; }; 55 this.getShaderDef = function() { return waterMaterialDef; };
56 56
57 /////////////////////////////////////////////////////////////////////// 57 ///////////////////////////////////////////////////////////////////////
58 // Properties 58 // Properties
59 /////////////////////////////////////////////////////////////////////// 59 ///////////////////////////////////////////////////////////////////////
60 // all defined in parent PulseMaterial.js 60 // all defined in parent PulseMaterial.js
61 // load the local default value 61 // load the local default value
62 this._propNames = ["u_tex0", "u_emboss", "u_delta", "u_intensity", "u_speed"]; 62 this._propNames = ["u_tex0", "u_emboss", "u_delta", "u_intensity", "u_speed"];
63 this._propLabels = ["Texture map", "Emboss", "Delta", "Intensity", "Speed"]; 63 this._propLabels = ["Texture map", "Emboss", "Delta", "Intensity", "Speed"];
64 this._propTypes = ["file", "float", "float", "float", "float"]; 64 this._propTypes = ["file", "float", "float", "float", "float"];
65 65
66 var u_tex_index = 0, 66 var u_tex_index = 0,
67 u_emboss_index = 1, 67 u_emboss_index = 1,
68 u_delta_index = 2, 68 u_delta_index = 2,
69 u_intensity_index = 3, 69 u_intensity_index = 3,
70 u_speed_index = 4; 70 u_speed_index = 4;
71 71
72 this._propValues = []; 72 this._propValues = [];
73 this._propValues[ this._propNames[u_tex_index ] ] = this._defaultTexMap.slice(0); 73 this._propValues[ this._propNames[u_tex_index ] ] = this._defaultTexMap.slice(0);
74 this._propValues[ this._propNames[u_emboss_index ] ] = 0.3; 74 this._propValues[ this._propNames[u_emboss_index ] ] = 0.3;
75 this._propValues[ this._propNames[u_delta_index ] ] = 20.0; 75 this._propValues[ this._propNames[u_delta_index ] ] = 20.0;
76 this._propValues[ this._propNames[u_intensity_index ] ] = 3.0; 76 this._propValues[ this._propNames[u_intensity_index ] ] = 3.0;
77 this._propValues[ this._propNames[u_speed_index ] ] = 0.2; 77 this._propValues[ this._propNames[u_speed_index ] ] = 0.2;
78 78
79 /////////////////////////////////////////////////////////////////////// 79 ///////////////////////////////////////////////////////////////////////
80 // Methods 80 // Methods
81 /////////////////////////////////////////////////////////////////////// 81 ///////////////////////////////////////////////////////////////////////
82 82
83 this.init = function (world) { 83 this.init = function (world) {
84 // save the world 84 // save the world
85 if (world) this.setWorld(world); 85 if (world) this.setWorld(world);
86 86
87 // set up the shader 87 // set up the shader
88 this._shader = new RDGE.jshader(); 88 this._shader = new RDGE.jshader();
89 this._shader.def = waterMaterialDef; 89 this._shader.def = waterMaterialDef;
90 this._shader.init(); 90 this._shader.init();
91 91
92 // set up the material node 92 // set up the material node
93 this._materialNode = RDGE.createMaterialNode("waterMaterial" + "_" + world.generateUniqueNodeID()); 93 this._materialNode = RDGE.createMaterialNode("waterMaterial" + "_" + world.generateUniqueNodeID());
94 this._materialNode.setShader(this._shader); 94 this._materialNode.setShader(this._shader);
95 95
96 this._time = 0; 96 this._time = 0;
97 if (this._shader && this._shader['default']) 97 if (this._shader && this._shader['default'])
98 this._shader['default'].u_time.set([this._time]); 98 this._shader['default'].u_time.set([this._time]);
99 99
100 // set the shader values in the shader 100 // set the shader values in the shader
101 this.setShaderValues(); 101 this.setShaderValues();
102 this.setResolution([world.getViewportWidth(), world.getViewportHeight()]); 102 this.setResolution([world.getViewportWidth(), world.getViewportHeight()]);
103 this.update(0); 103 this.update(0);
104 }; 104 };
105 105
106 this.resetToDefault = function() 106 this.resetToDefault = function()
107 { 107 {
@@ -114,7 +114,7 @@ var WaterMaterial = function WaterMaterial()
114 var nProps = this._propNames.length; 114 var nProps = this._propNames.length;
115 for (var i=0; i<nProps; i++) 115 for (var i=0; i<nProps; i++)
116 this.setProperty( this._propNames[i], this._propValues[this._propNames[i]] ); 116 this.setProperty( this._propNames[i], this._propValues[this._propNames[i]] );
117 }; 117};
118}; 118};
119 119
120/////////////////////////////////////////////////////////////////////////////////////// 120///////////////////////////////////////////////////////////////////////////////////////
@@ -123,96 +123,96 @@ var WaterMaterial = function WaterMaterial()
123// shader spec (can also be loaded from a .JSON file, or constructed at runtime) 123// shader spec (can also be loaded from a .JSON file, or constructed at runtime)
124var waterMaterialDef = 124var waterMaterialDef =
125{ 'shaders': 125{ 'shaders':
126 { 126 {
127 'defaultVShader': "assets/shaders/Basic.vert.glsl", 127 'defaultVShader': "assets/shaders/Basic.vert.glsl",
128 'defaultFShader': "assets/shaders/Water2.frag.glsl" 128 'defaultFShader': "assets/shaders/Water2.frag.glsl"
129 }, 129 },
130 'techniques': 130 'techniques':
131 { 131 {
132 'default': 132 'default':
133 [ 133 [
134 { 134 {
135 'vshader': 'defaultVShader', 135 'vshader': 'defaultVShader',
136 'fshader': 'defaultFShader', 136 'fshader': 'defaultFShader',
137 // attributes 137 // attributes
138 'attributes': 138 'attributes':
139 { 139 {
140 'vert': { 'type': 'vec3' }, 140 'vert': { 'type': 'vec3' },
141 'normal': { 'type': 'vec3' }, 141 'normal': { 'type': 'vec3' },
142 'texcoord': { 'type': 'vec2' } 142 'texcoord': { 'type': 'vec2' }
143 }, 143 },
144 // parameters 144 // parameters
145 'params': 145 'params':
146 { 146 {
147 'u_tex0': { 'type': 'tex2d' }, 147 'u_tex0': { 'type': 'tex2d' },
148 'u_time': { 'type': 'float' }, 148 'u_time': { 'type': 'float' },
149 'u_emboss': { 'type': 'float' }, 149 'u_emboss': { 'type': 'float' },
150 'u_delta': { 'type': 'float' }, 150 'u_delta': { 'type': 'float' },
151 'u_speed': { 'type': 'float' }, 151 'u_speed': { 'type': 'float' },
152 'u_intensity': { 'type': 'float' }, 152 'u_intensity': { 'type': 'float' },
153 'u_resolution': { 'type': 'vec2' } 153 'u_resolution': { 'type': 'vec2' }
154 }, 154 },
155 155
156 // render states 156 // render states
157 'states': 157 'states':
158 { 158 {
159 'depthEnable': true, 159 'depthEnable': true,
160 'offset': [1.0, 0.1] 160 'offset': [1.0, 0.1]
161 } 161 }
162 } 162 }
163 ] 163 ]
164 } 164 }
165}; 165};
166 166
167var ParisMaterial = function ParisMaterial() 167var ParisMaterial = function ParisMaterial()
168{ 168{
169 // initialize the inherited members 169 // initialize the inherited members
170 this.inheritedFrom = WaterMaterial;