Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Amanda Ghassaei
AMOEBA
Commits
4cd227cc
Commit
4cd227cc
authored
Jul 09, 2016
by
amandaghassaei
Browse files
new k and d workin in shader
parent
c38c7995
Changes
2
Hide whitespace changes
Inline
Side-by-side
js/simulation/function/EM/emSimLattice.js
View file @
4cd227cc
...
...
@@ -555,71 +555,71 @@ define(['underscore', 'backbone', 'threeModel', 'lattice', 'plist', 'emWire', 'G
iter
:
function
(
time
,
runConstants
,
shouldRender
){
//
//gpuMath.step("quaternionCalc", ["u_lastTranslation", "u_lastQuaternion", "u_fixed", "u_neighborsXMapping",
//
//
"u_neighborsYMapping", "u_compositeKs"], "u_quaternion", "u_wires", "u_wiresMeta", time);
//
gpuMath.step("velocityCalc", ["u_lastVelocity", "u_lastTranslation", "u_mass", "u_neighborsXMapping",
//
"u_neighborsYMapping", "u_compositeKs", "u_compositeDs", "u_originalPosition", "u_lastQuaternion", "u_wires",
//
"u_wiresMeta"], "u_velocity", time);
//
gpuMath.step("positionCalc", ["u_velocity", "u_lastTranslation", "u_mass"], "u_translation");
//
//
if (shouldRender) {
//
var textureSize = this.textureSize[0]*this.textureSize[1];
//
//
//get position
//
var vectorLength = 3;
//
gpuMath.setProgram("packToBytes");
//
gpuMath.setUniformForProgram("packToBytes", "u_vectorLength", vectorLength, "1f");
//
gpuMath.setSize(this.textureSize[0]*vectorLength, this.textureSize[1]);
//
gpuMath.step("packToBytes", ["u_translation"], "outputPositionBytes");
//
var pixels = new Uint8Array(textureSize * 4*vectorLength);
//
if (gpuMath.readyToRead()) {
//
gpuMath.readPixels(0, 0, this.textureSize[0] * vectorLength, this.textureSize[1], pixels);
//
var parsedPixels = new Float32Array(pixels.buffer);
//
var cells = lattice.getCells();
//
var multiplier = 1 / (plist.allUnitTypes[lattice.getUnits()].multiplier);
//
for (var i = 0; i < textureSize; i++) {
//
var rgbaIndex = 4 * i;
//
if (this.mass[rgbaIndex+1] < 0) continue;//no more cells
//
var index = [this.cellsArrayMapping[rgbaIndex], this.cellsArrayMapping[rgbaIndex + 1], this.cellsArrayMapping[rgbaIndex + 2]];
//
var parsePixelsIndex = vectorLength * i;
//
var translation = [parsedPixels[parsePixelsIndex], parsedPixels[parsePixelsIndex + 1], parsedPixels[parsePixelsIndex + 2]];
//
var position = [this.originalPosition[rgbaIndex], this.originalPosition[rgbaIndex + 1], this.originalPosition[rgbaIndex + 2]];
//
position[0] += multiplier * translation[0];
//
position[1] += multiplier * translation[1];
//
position[2] += multiplier * translation[2];
//
cells[index[0]][index[1]][index[2]].object3D.position.set(position[0], position[1], position[2]);
//
}
//
}
//
//
vectorLength = 4;
//
gpuMath.setUniformForProgram("packToBytes", "u_vectorLength", vectorLength, "1f");
//
gpuMath.setSize(this.textureSize[0]*vectorLength, this.textureSize[1]);
//
gpuMath.step("packToBytes", ["u_quaternion"], "outputQuaternionBytes");
//
pixels = new Uint8Array(textureSize * 4*vectorLength);
//
if (gpuMath.readyToRead()) {
//
gpuMath.readPixels(0, 0, this.textureSize[0] * vectorLength, this.textureSize[1], pixels);
//
parsedPixels = new Float32Array(pixels.buffer);
//
for (var i = 0; i < textureSize; i++) {
//
var rgbaIndex = 4 * i;
//
if (this.mass[rgbaIndex+1] < 0) break;//no more cells
//
var index = [this.cellsArrayMapping[rgbaIndex], this.cellsArrayMapping[rgbaIndex + 1], this.cellsArrayMapping[rgbaIndex + 2]];
//
var parsePixelsIndex = vectorLength * i;
//
//
var quaternion = this._multiplyQuaternions([parsedPixels[parsePixelsIndex], parsedPixels[parsePixelsIndex + 1], parsedPixels[parsePixelsIndex + 2], parsedPixels[parsePixelsIndex + 3]],
//
[this.originalQuaternion[rgbaIndex], this.originalQuaternion[rgbaIndex+1], this.originalQuaternion[rgbaIndex+2], this.originalQuaternion[rgbaIndex+3]]);
//
var rotation = this._eulerFromQuaternion(quaternion);
//
//
cells[index[0]][index[1]][index[2]].object3D.rotation.set(rotation[0], rotation[1], rotation[2]);
//
}
//
}
//
//
gpuMath.setSize(this.textureSize[0], this.textureSize[1]);
//
}
//
//
gpuMath.swapTextures("u_velocity", "u_lastVelocity");
//
gpuMath.swapTextures("u_translation", "u_lastTranslation");
//
//gpuMath.swapTextures("u_quaternion", "u_lastQuaternion");
//
return;
//gpuMath.step("quaternionCalc", ["u_lastTranslation", "u_lastQuaternion", "u_fixed", "u_neighborsXMapping",
// "u_neighborsYMapping", "u_compositeKs"], "u_quaternion", "u_wires", "u_wiresMeta", time);
gpuMath
.
step
(
"
velocityCalc
"
,
[
"
u_lastVelocity
"
,
"
u_lastTranslation
"
,
"
u_mass
"
,
"
u_neighborsXMapping
"
,
"
u_neighborsYMapping
"
,
"
u_compositeKs
"
,
"
u_compositeDs
"
,
"
u_originalPosition
"
,
"
u_lastQuaternion
"
,
"
u_wires
"
,
"
u_wiresMeta
"
],
"
u_velocity
"
,
time
);
gpuMath
.
step
(
"
positionCalc
"
,
[
"
u_velocity
"
,
"
u_lastTranslation
"
,
"
u_mass
"
],
"
u_translation
"
);
if
(
shouldRender
)
{
var
textureSize
=
this
.
textureSize
[
0
]
*
this
.
textureSize
[
1
];
//get position
var
vectorLength
=
3
;
gpuMath
.
setProgram
(
"
packToBytes
"
);
gpuMath
.
setUniformForProgram
(
"
packToBytes
"
,
"
u_vectorLength
"
,
vectorLength
,
"
1f
"
);
gpuMath
.
setSize
(
this
.
textureSize
[
0
]
*
vectorLength
,
this
.
textureSize
[
1
]);
gpuMath
.
step
(
"
packToBytes
"
,
[
"
u_translation
"
],
"
outputPositionBytes
"
);
var
pixels
=
new
Uint8Array
(
textureSize
*
4
*
vectorLength
);
if
(
gpuMath
.
readyToRead
())
{
gpuMath
.
readPixels
(
0
,
0
,
this
.
textureSize
[
0
]
*
vectorLength
,
this
.
textureSize
[
1
],
pixels
);
var
parsedPixels
=
new
Float32Array
(
pixels
.
buffer
);
var
cells
=
lattice
.
getCells
();
var
multiplier
=
1
/
(
plist
.
allUnitTypes
[
lattice
.
getUnits
()].
multiplier
);
for
(
var
i
=
0
;
i
<
textureSize
;
i
++
)
{
var
rgbaIndex
=
4
*
i
;
if
(
this
.
mass
[
rgbaIndex
+
1
]
<
0
)
continue
;
//no more cells
var
index
=
[
this
.
cellsArrayMapping
[
rgbaIndex
],
this
.
cellsArrayMapping
[
rgbaIndex
+
1
],
this
.
cellsArrayMapping
[
rgbaIndex
+
2
]];
var
parsePixelsIndex
=
vectorLength
*
i
;
var
translation
=
[
parsedPixels
[
parsePixelsIndex
],
parsedPixels
[
parsePixelsIndex
+
1
],
parsedPixels
[
parsePixelsIndex
+
2
]];
var
position
=
[
this
.
originalPosition
[
rgbaIndex
],
this
.
originalPosition
[
rgbaIndex
+
1
],
this
.
originalPosition
[
rgbaIndex
+
2
]];
position
[
0
]
+=
multiplier
*
translation
[
0
];
position
[
1
]
+=
multiplier
*
translation
[
1
];
position
[
2
]
+=
multiplier
*
translation
[
2
];
cells
[
index
[
0
]][
index
[
1
]][
index
[
2
]].
object3D
.
position
.
set
(
position
[
0
],
position
[
1
],
position
[
2
]);
}
}
vectorLength
=
4
;
gpuMath
.
setUniformForProgram
(
"
packToBytes
"
,
"
u_vectorLength
"
,
vectorLength
,
"
1f
"
);
gpuMath
.
setSize
(
this
.
textureSize
[
0
]
*
vectorLength
,
this
.
textureSize
[
1
]);
gpuMath
.
step
(
"
packToBytes
"
,
[
"
u_quaternion
"
],
"
outputQuaternionBytes
"
);
pixels
=
new
Uint8Array
(
textureSize
*
4
*
vectorLength
);
if
(
gpuMath
.
readyToRead
())
{
gpuMath
.
readPixels
(
0
,
0
,
this
.
textureSize
[
0
]
*
vectorLength
,
this
.
textureSize
[
1
],
pixels
);
parsedPixels
=
new
Float32Array
(
pixels
.
buffer
);
for
(
var
i
=
0
;
i
<
textureSize
;
i
++
)
{
var
rgbaIndex
=
4
*
i
;
if
(
this
.
mass
[
rgbaIndex
+
1
]
<
0
)
break
;
//no more cells
var
index
=
[
this
.
cellsArrayMapping
[
rgbaIndex
],
this
.
cellsArrayMapping
[
rgbaIndex
+
1
],
this
.
cellsArrayMapping
[
rgbaIndex
+
2
]];
var
parsePixelsIndex
=
vectorLength
*
i
;
var
quaternion
=
this
.
_multiplyQuaternions
([
parsedPixels
[
parsePixelsIndex
],
parsedPixels
[
parsePixelsIndex
+
1
],
parsedPixels
[
parsePixelsIndex
+
2
],
parsedPixels
[
parsePixelsIndex
+
3
]],
[
this
.
originalQuaternion
[
rgbaIndex
],
this
.
originalQuaternion
[
rgbaIndex
+
1
],
this
.
originalQuaternion
[
rgbaIndex
+
2
],
this
.
originalQuaternion
[
rgbaIndex
+
3
]]);
var
rotation
=
this
.
_eulerFromQuaternion
(
quaternion
);
cells
[
index
[
0
]][
index
[
1
]][
index
[
2
]].
object3D
.
rotation
.
set
(
rotation
[
0
],
rotation
[
1
],
rotation
[
2
]);
}
}
gpuMath
.
setSize
(
this
.
textureSize
[
0
],
this
.
textureSize
[
1
]);
}
gpuMath
.
swapTextures
(
"
u_velocity
"
,
"
u_lastVelocity
"
);
gpuMath
.
swapTextures
(
"
u_translation
"
,
"
u_lastTranslation
"
);
//gpuMath.swapTextures("u_quaternion", "u_lastQuaternion");
return
;
var
gravity
=
runConstants
.
gravity
;
var
groundHeight
=
runConstants
.
groundHeight
;
...
...
js/simulation/function/EM/shaders/velocityCalcShader.js
View file @
4cd227cc
...
...
@@ -217,16 +217,6 @@ void main(){
vec2
mappingIndex
=
vec2
(
xIndex
/
(
u_textureDim
.
x
*
2.0
),
scaledFragCoord
.
y
);
vec3
neighborsXMapping
=
texture2D
(
u_neighborsXMapping
,
mappingIndex
).
xyz
;
vec3
neighborsYMapping
=
texture2D
(
u_neighborsYMapping
,
mappingIndex
).
xyz
;
vec3
longitudalK
=
texture2D
(
u_compositeKs
,
mappingIndex
).
xyz
;
vec3
shearK1
=
vec3
(
10
,
10
,
10
);
vec3
shearK2
=
vec3
(
10
,
10
,
10
);
vec3
longitudalD
=
texture2D
(
u_compositeDs
,
mappingIndex
).
xyz
;
vec3
shearD1
=
vec3
(
0.03
,
0.03
,
0.03
);
vec3
shearD2
=
vec3
(
0.03
,
0.03
,
0.03
);
for
(
int
j
=
0
;
j
<
3
;
j
++
){
if
(
neighborsXMapping
[
j
]
<
0.0
)
continue
;
//no neighbor
...
...
@@ -271,6 +261,11 @@ void main(){
//else if (neighborAxis == 1) actuatedD[1] *= 1.0+actuation;
//else if (neighborAxis == 2) actuatedD[2] *= 1.0+actuation;
float
kIndex_x
=
((
fragCoord
.
x
-
0.5
)
*
12.0
+
2.0
*
(
i
*
3.0
+
float
(
j
))
+
0.5
)
/
(
u_textureDim
.
x
*
12.0
);
vec2
kIndex
=
vec2
(
kIndex_x
,
scaledFragCoord
.
y
);
vec3
translationalK
=
texture2D
(
u_compositeKs
,
kIndex
).
xyz
;
vec3
translationalD
=
texture2D
(
u_compositeDs
,
kIndex
).
xyz
;
vec4
averageQuaternion
=
averageQuaternions
(
quaternion
,
neighborQuaternion
);
vec4
averageQuaternionInverse
=
invertQuaternion
(
averageQuaternion
);
...
...
@@ -279,24 +274,7 @@ void main(){
vec3
velocityDelta
=
neighborVelocity
-
velocity
;
vec3
velocityDeltaXYZ
=
applyQuaternion
(
velocityDelta
,
averageQuaternionInverse
);
vec3
_force
=
vec3
(
0.0
,
0.0
,
0.0
);
//longitudal and shear
for
(
int
_axis
=
0
;
_axis
<
3
;
_axis
++
)
{
if
(
_axis
==
neighborAxis
)
{
_force
[
_axis
]
+=
longitudalK
[
_axis
]
*
translationalDeltaXYZ
[
_axis
]
+
longitudalD
[
_axis
]
*
velocityDeltaXYZ
[
_axis
];
}
else
{
if
(
neighborAxis
==
0
){
if
(
_axis
==
1
)
_force
[
_axis
]
+=
shearK1
[
0
]
*
translationalDeltaXYZ
[
_axis
]
+
shearD1
[
0
]
*
velocityDeltaXYZ
[
_axis
];
else
if
(
_axis
==
2
)
_force
[
_axis
]
+=
shearK1
[
1
]
*
translationalDeltaXYZ
[
_axis
]
+
shearD1
[
1
]
*
velocityDeltaXYZ
[
_axis
];
}
else
if
(
neighborAxis
==
1
){
if
(
_axis
==
0
)
_force
[
_axis
]
+=
shearK1
[
2
]
*
translationalDeltaXYZ
[
_axis
]
+
shearD1
[
2
]
*
velocityDeltaXYZ
[
_axis
];
else
if
(
_axis
==
2
)
_force
[
_axis
]
+=
shearK2
[
0
]
*
translationalDeltaXYZ
[
_axis
]
+
shearD2
[
0
]
*
velocityDeltaXYZ
[
_axis
];
}
else
if
(
neighborAxis
==
2
){
if
(
_axis
==
0
)
_force
[
_axis
]
+=
shearK2
[
1
]
*
translationalDeltaXYZ
[
_axis
]
+
shearD2
[
1
]
*
velocityDeltaXYZ
[
_axis
];
else
if
(
_axis
==
1
)
_force
[
_axis
]
+=
shearK2
[
2
]
*
translationalDeltaXYZ
[
_axis
]
+
shearD2
[
2
]
*
velocityDeltaXYZ
[
_axis
];
}
}
}
vec3
_force
=
translationalK
*
translationalDeltaXYZ
+
translationalD
*
velocityDeltaXYZ
;
//convert _force vector back into world reference frame
_force
=
applyQuaternion
(
_force
,
averageQuaternion
);
force
+=
_force
;
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment