So I created a shader for setting up curtain like effects on a plane drape but some instanced meshes.
I am already using defines: [’#define INSTANCES’] when setting up the material and
#include in the shader and #include in the main of the vertex shader.
What’s interesting is the meshes render at the correct postion. It it the instanced meshes that are out of postion. They render fine and wave like they are supposed to. They are just out of place for some reason.
export const drape_vertex = `
precision highp float;
attribute vec3 position;
attribute vec2 uv;
attribute vec2 uv2;
#include<instancesDeclaration>
// Uniforms
uniform mat4 worldViewProjection;
uniform mat4 worldView;
uniform bool vertexFogEnabled;
uniform float time;
uniform float frequency;
uniform float amplitude;
uniform float rate;
varying vec2 vUV0;
varying float fogFactor;
void main(void) {
#include<instancesVertex>
vec3 v = position;
v.z += uv.x * sin(time*rate+uv.x*frequency) * amplitude;
if(vertexFogEnabled){
float start = 47.0;
float end = 50.0;
float vDistance = length(worldView * vec4(v,1.0));
fogFactor = clamp((vDistance - start) / (end - start), 0.0, 1.0);
}
gl_Position = worldViewProjection * vec4(v, 1.0);
vUV0 = uv;
}
`;
Material Setup Code
this._drapeMaterial = new ShaderMaterial('drape_material', this._scene, drapeShader, {
attributes: ['position', 'uv', 'uv2'],
uniforms: ['worldview', 'time', 'frequency', 'worldViewProjection', 'amplitude', 'rate'],
needAlphaBlending: true,
needAlphaTesting: false,
defines: ['#define INSTANCES'],
});
const albedo = new Texture('assets/textures/drapes.jpg', this._scene);
this._drapeMaterial.setTexture('albedo', albedo);
//this._drapeMaterial.setInt('vertexFogEnabled', 0);
this._drapeMaterial.setFloat('frequency', -3);
this._drapeMaterial.setFloat('amplitude', 0.7);
this._drapeMaterial.setFloat('rate', 0.9);
this._drapeMaterial.backFaceCulling = true;
this._drapeMaterial.forceDepthWrite = true;
Am I doing something wrong or missing something? I am on babylon v 4.1.0