aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--assets/shaders/Basic.frag.glsl4
-rw-r--r--assets/shaders/Basic.vert.glsl3
-rw-r--r--assets/shaders/Taper.vert.glsl21
-rw-r--r--js/helper-classes/RDGE/GLMaterial.js4
-rw-r--r--js/helper-classes/RDGE/GLRectangle.js64
-rw-r--r--js/helper-classes/RDGE/GLWorld.js6
-rw-r--r--js/helper-classes/RDGE/Materials/FlatMaterial.js11
7 files changed, 71 insertions, 42 deletions
diff --git a/assets/shaders/Basic.frag.glsl b/assets/shaders/Basic.frag.glsl
index a2c21afa..c1f9a5c8 100644
--- a/assets/shaders/Basic.frag.glsl
+++ b/assets/shaders/Basic.frag.glsl
@@ -11,7 +11,9 @@ precision highp float;
11 11
12 12
13uniform vec4 color; 13uniform vec4 color;
14varying vec4 v_color;
14 15
15void main() { 16void main() {
16 gl_FragColor = color; 17 gl_FragColor = v_color;
18 //gl_FragColor = color;
17} 19}
diff --git a/assets/shaders/Basic.vert.glsl b/assets/shaders/Basic.vert.glsl
index 028786d1..40b97ad7 100644
--- a/assets/shaders/Basic.vert.glsl
+++ b/assets/shaders/Basic.vert.glsl
@@ -12,7 +12,9 @@ precision highp float;
12 12
13// attributes 13// attributes
14attribute vec3 a_pos; 14attribute vec3 a_pos;
15attribute vec2 texcoord;
15 16
17varying vec4 v_color;
16 18
17 19
18// matrix uniforms 20// matrix uniforms
@@ -22,5 +24,6 @@ uniform mat4 u_worldMatrix;
22 24
23void main(void) 25void main(void)
24{ 26{
27 v_color = vec4(texcoord.x, texcoord.y, 0, 1);
25 gl_Position = u_projMatrix * u_mvMatrix * vec4(a_pos,1.0) ; 28 gl_Position = u_projMatrix * u_mvMatrix * vec4(a_pos,1.0) ;
26} \ No newline at end of file 29} \ No newline at end of file
diff --git a/assets/shaders/Taper.vert.glsl b/assets/shaders/Taper.vert.glsl
index 46f04fb3..82151f13 100644
--- a/assets/shaders/Taper.vert.glsl
+++ b/assets/shaders/Taper.vert.glsl
@@ -20,6 +20,7 @@ uniform float u_limit1;
20uniform float u_limit2; 20uniform float u_limit2;
21uniform float u_limit3; 21uniform float u_limit3;
22uniform float u_taperAmount; 22uniform float u_taperAmount;
23uniform float u_center;
23 24
24uniform vec4 color; 25uniform vec4 color;
25 26
@@ -31,31 +32,35 @@ uniform mat4 u_worldMatrix;
31 32
32varying vec4 v_color; 33varying vec4 v_color;
33 34
35float TaperAmount( float param )
36{
37 float y0 = 1.0, y1 = 1.0, y2 = 0.0, y3 = 0.0;
38 float yA0 = y0 + param*(y1 - y0), yA1 = y1 + param*(y2 - y1), yA2 = y2 + param*(y3 - y2);
39 float yB0 = yA0 + param*(yA1 - yA0), yB1 = yA1 + param*(yA2 - yA1);
40 float yC0 = yB0 + param*(yB1 - yB0);
41
42 return yC0;
43}
34 44
35void main(void) 45void main(void)
36{ 46{
37 vec3 pos = vert; 47 vec3 pos = vert;
38 vec2 uv = texcoord; 48 vec2 uv = texcoord;
39 49
40 v_color = vec4(0, 1, 0, 1); 50 v_color = vec4(texcoord.x, texcoord.y, 0, 1);
41 if (uv.x > u_limit1) 51 if (uv.x > u_limit1)
42 { 52 {
43 if (uv.x < u_limit2) 53 if (uv.x < u_limit2)
44 { 54 {
45 float t = (uv.x - u_limit1)/(u_limit2 - u_limit1); 55 float t = (uv.x - u_limit1)/(u_limit2 - u_limit1);
46 pos.y = pos.y - t*u_taperAmount; 56 pos.y = pos.y - pos.y*TaperAmount(t)*u_taperAmount;
47 v_color = vec4( 1, 1, 0, 1 );
48 } 57 }
49 else if (uv.x < u_limit3) 58 else if (uv.x < u_limit3)
50 { 59 {
51 float t = 1.0 - (uv.x - u_limit2)/(u_limit3 - u_limit2); 60 float t = 1.0 - (uv.x - u_limit2)/(u_limit3 - u_limit2);
52 pos.y = pos.y - t*u_taperAmount; 61 pos.y = pos.y - pos.y*TaperAmount(t)*u_taperAmount;
53 v_color = vec4( 0, 1, 1, 1 );
54 } 62 }
55 else
56 v_color = vec4(0,0,1,1);
57 } 63 }
58 64
59
60 gl_Position = u_projMatrix * u_mvMatrix * vec4(pos,1.0) ; 65 gl_Position = u_projMatrix * u_mvMatrix * vec4(pos,1.0) ;
61} \ No newline at end of file 66} \ No newline at end of file
diff --git a/js/helper-classes/RDGE/GLMaterial.js b/js/helper-classes/RDGE/GLMaterial.js
index 07a98ab5..a74a74e4 100644
--- a/js/helper-classes/RDGE/GLMaterial.js
+++ b/js/helper-classes/RDGE/GLMaterial.js
@@ -34,7 +34,7 @@ function GLMaterial( world )
34 // vertex deformation variables 34 // vertex deformation variables
35 this._hasVertexDeformation = false; 35 this._hasVertexDeformation = false;
36 this._vertexDeformationRange = [0, 0, 1, 1]; // (xMin, yMin, xMax, yMax) 36 this._vertexDeformationRange = [0, 0, 1, 1]; // (xMin, yMin, xMax, yMax)
37 this._vertexDeformationTolerance = 0.05; 37 this._vertexDeformationTolerance = 0.1;
38 38
39 // RDGE variables 39 // RDGE variables
40 this._shader; 40 this._shader;
@@ -74,7 +74,7 @@ function GLMaterial( world )
74 // the vertex shader can apply deformations requiring refinement in 74 // the vertex shader can apply deformations requiring refinement in
75 // certain areas. 75 // certain areas.
76 this.hasVertexDeformation = function() { return this._hasVertexDeformation; } 76 this.hasVertexDeformation = function() { return this._hasVertexDeformation; }
77 this.getVertexDeformationRange = function() { return this._vertexDeformationRange.slice(); } 77 this.getVertexDeformationRange = function() { return this._vertexDeformationRange.slice(); }
78 this.getVertexDeformationTolerance = function() { return this._vertexDeformationTolerance; } 78 this.getVertexDeformationTolerance = function() { return this._vertexDeformationTolerance; }
79 79
80 80
diff --git a/js/helper-classes/RDGE/GLRectangle.js b/js/helper-classes/RDGE/GLRectangle.js
index e72b4488..7fe03022 100644
--- a/js/helper-classes/RDGE/GLRectangle.js
+++ b/js/helper-classes/RDGE/GLRectangle.js
@@ -1121,6 +1121,7 @@ RectangleStroke.create = function( rectCtr, width, height, strokeWidth, tlRad,
1121 1121
1122 // create the RDGE primitive 1122 // create the RDGE primitive
1123 var prim = ShapePrimitive.create(this.vertices, this.normals, this.uvs, this.indices, g_Engine.getContext().renderer.TRIANGLES, nVertices); 1123 var prim = ShapePrimitive.create(this.vertices, this.normals, this.uvs, this.indices, g_Engine.getContext().renderer.TRIANGLES, nVertices);
1124 //var prim = ShapePrimitive.create(this.vertices, this.normals, this.uvs, this.indices, g_Engine.getContext().renderer.LINES, nVertices);
1124 return prim; 1125 return prim;
1125} 1126}
1126 1127
@@ -1214,6 +1215,7 @@ RectangleGeometry.create = function( ctr, width, height, material )
1214 1215
1215 // create the RDGE primitive 1216 // create the RDGE primitive
1216 var prim = ShapePrimitive.create(this.vertices, this.normals, this.uvs, this.indices, g_Engine.getContext().renderer.TRIANGLES, nVertices); 1217 var prim = ShapePrimitive.create(this.vertices, this.normals, this.uvs, this.indices, g_Engine.getContext().renderer.TRIANGLES, nVertices);
1218 //var prim = ShapePrimitive.create(this.vertices, this.normals, this.uvs, this.indices, g_Engine.getContext().renderer.LINES, nVertices);
1217 return prim; 1219 return prim;
1218} 1220}
1219 1221
@@ -1301,7 +1303,7 @@ ShapePrimitive.refineMesh = function( verts, norms, uvs, indices, nVertices, pa
1301 i2 = indices[index+2]; 1303 i2 = indices[index+2];
1302 1304
1303 // get the uv values 1305 // get the uv values
1304 var vrtIndex = 3*iTriangle; 1306 //var vrtIndex = 3*iTriangle;
1305 var iuv0 = 2 * i0, 1307 var iuv0 = 2 * i0,
1306 iuv1 = 2 * i1, 1308 iuv1 = 2 * i1,
1307 iuv2 = 2 * i2; 1309 iuv2 = 2 * i2;
@@ -1335,7 +1337,7 @@ ShapePrimitive.refineMesh = function( verts, norms, uvs, indices, nVertices, pa
1335 iTriangle++; 1337 iTriangle++;
1336 index += 3; 1338 index += 3;
1337 } 1339 }
1338 else // split the triangle 1340 else // split the triangle into 4 parts
1339 { 1341 {
1340 //calculate the position of the new vertex 1342 //calculate the position of the new vertex
1341 var iPt0 = 3 * i0, 1343 var iPt0 = 3 * i0,
@@ -1344,34 +1346,42 @@ ShapePrimitive.refineMesh = function( verts, norms, uvs, indices, nVertices, pa
1344 var x0 = verts[iPt0], y0 = verts[iPt0+1], z0 = verts[iPt0+2], 1346 var x0 = verts[iPt0], y0 = verts[iPt0+1], z0 = verts[iPt0+2],
1345 x1 = verts[iPt1], y1 = verts[iPt1+1], z1 = verts[iPt1+2], 1347 x1 = verts[iPt1], y1 = verts[iPt1+1], z1 = verts[iPt1+2],
1346 x2 = verts[iPt2], y2 = verts[iPt2+1], z2 = verts[iPt2+2]; 1348 x2 = verts[iPt2], y2 = verts[iPt2+1], z2 = verts[iPt2+2];
1347 var xMid = (x0 + x1 + x2)/3.0, 1349
1348 yMid = (y0 + y1 + y2)/3.0, 1350 // calculate the midpoints of the edges
1349 zMid = (z0 + z1 + z2)/3.0; 1351 var xA = (x0 + x1)/2.0, yA = (y0 + y1)/2.0, zA = (z0 + z1)/2.0,
1350 1352 xB = (x1 + x2)/2.0, yB = (y1 + y2)/2.0, zB = (z1 + z2)/2.0,
1351 // calculate the uv value of the new coordinate 1353 xC = (x2 + x0)/2.0, yC = (y2 + y0)/2.0, zC = (z2 + z0)/2.0;
1352 var uMid = (u0 + u1 + u2)/3.0, 1354
1353 vMid = (v0 + v1 + v2)/3.0; 1355 // calculate the uv values of the new coordinates
1354 1356 var uA = (u0 + u1)/2.0, vA = (v0 + v1)/2.0,
1355 // calculate the normal for the new coordinate 1357 uB = (u1 + u2)/2.0, vB = (v1 + v2)/2.0,
1358 uC = (u2 + u0)/2.0, vC = (v2 + v0)/2.0;
1359
1360 // calculate the normals for the new points
1356 var nx0 = norms[iPt0], ny0 = norms[iPt0+1], nz0 = norms[iPt0+2], 1361 var nx0 = norms[iPt0], ny0 = norms[iPt0+1], nz0 = norms[iPt0+2],
1357 nx1 = norms[iPt1], ny1 = norms[iPt1+1], nz1 = norms[iPt1+2], 1362 nx1 = norms[iPt1], ny1 = norms[iPt1+1], nz1 = norms[iPt1+2],
1358 nx2 = norms[iPt2], ny2 = norms[iPt2+1], nz2 = norms[iPt2+2]; 1363 nx2 = norms[iPt2], ny2 = norms[iPt2+1], nz2 = norms[iPt2+2];
1359 var nxMid = (nx0 + nx1 + nx2), 1364 var nxA = (nx0 + nx1), nyA = (ny0 + ny1), nzA = (nz0 + nz1); var nrmA = VecUtils.vecNormalize(3, [nxA, nyA, nzA], 1.0 ),
1360 nyMid = (ny0 + ny1 + ny2), 1365 nxB = (nx1 + nx2), nyB = (ny1 + ny2), nzB = (nz1 + nz2); var nrmB = VecUtils.vecNormalize(3, [nxB, nyB, nzB], 1.0 ),
1361 nzMid = (nz0 + nz1 + nz2); 1366 nxC = (nx2 + nx0), nyC = (ny2 + ny0), nzC = (nz2 + nz0); var nrmC = VecUtils.vecNormalize(3, [nxC, nyC, nzC], 1.0 );
1362 var nrm = VecUtils.vecNormalize(3, [nxMid, nyMid, nzMid], 1.0 ); 1367
1363 1368 // push everything
1364 // push the new vertex 1369 verts.push(xA); verts.push(yA); verts.push(zA);
1365 verts.push(nrm[0]); verts.push(nrm[1]); verts.push(nrm[2]); 1370 verts.push(xB); verts.push(yB); verts.push(zB);
1366 uvs.push(uMid), uvs.push(vMid); 1371 verts.push(xC); verts.push(yC); verts.push(zC);
1367 norms.push(nrm[0]); norms.push(nrm[1]); norms.push(nrm[2]); 1372 uvs.push(uA), uvs.push(vA);