1. A concise explanation of the problem you're experiencing.
The document says I can use vertexShaderSource option in MaterialAppearance, but I can't make it work.
2. A minimal code example. If you've found a bug, this helps us reproduce and repair it.
js code:
computeAppearance = new Cesium.MaterialAppearance({
material: windField,
vertexShaderSource: Util.getShaderCode('glsl/fullscreen.vert'),
fragmentShaderSource: Util.getShaderCode('glsl/update.frag')
});
fullscreenQuad = new Cesium.GeometryInstance({
// according to the source code of Cesium.PlaneGeometry
// o----o (0.5,0.5)
// | |
// | |
// (-0.5,-0.5) o----o
geometry: new Cesium.PlaneGeometry()
});
computePrimitive = new Cesium.Primitive({
geometryInstances: fullscreenQuad,
appearance: computeAppearance
});
vertex shader code:
attribute vec3 position;
attribute vec2 st;
attribute float batchId;
varying vec2 textureCoordinate;
void main() {
textureCoordinate = st;
gl_Position = vec4(position.xy, 0.0, 1.0);
}
fragment shader code:
uniform sampler2D U;// (lon, lat*lev)
uniform sampler2D V;// (lon, lat*lev)
uniform vec3 windFieldDimensions;// (lon, lat, lev)
uniform vec3 windFieldSteps;// step of each dimension
uniform sampler2D particles;
varying vec2 textureCoordinate;
void main() {
vec4 texel = texture2D(particles, textureCoordinate); // texture coordinate must be normalized
vec3 position = texel.rgb;// (lon, lat, lev)
vec3 windFieldIndex = position;
windFieldIndex.x = windFieldIndex.x/windFieldSteps.x;
windFieldIndex.y = windFieldIndex.y/windFieldSteps.y;
windFieldIndex.z = windFieldIndex.z/windFieldSteps.z;
vec2 textureIndex = vec2(windFieldIndex.x, windFieldIndex.y * windFieldDimensions.y + windFieldIndex.z);
// quick and dirty estimation for unit conversion: longitude latitude degrees -> meters
float u = texture2D(U, textureIndex).r / (111111.0 * cos(position.x));
float v = texture2D(V, textureIndex).r / 111111.0;
float w = 0.0;
vec3 windVector = vec3(u, v, w);
vec3 nextPosition = position + windVector;
gl_FragColor = vec4(nextPosition, 1.0);
}
3. Context. Why do you need to do this? We might know a better way to accomplish your goal.
I need to perform particle computation in GPU. You can see the full problem context in my previous threads:
https://groups.google.com/forum/#!topic/cesium-dev/gjjd9TNeY2A
https://groups.google.com/forum/#!topic/cesium-dev/vR7H4KJURJ8
4. The Cesium version you're using, your operating system and browser.
Cesium 1.53