ShaderMaterial not rendering objects

I am using a custom shader which works fine at the beginning of the game but the rendering just stops out of the blue. I know it is not an instanced mesh problem because even instanced meshes render fine at the beginning. It loads a few more assets that use this shadermaterial in the bg and then it stops working. The meshes and instanced meshes render just fine but stops rendering after a while.

public get trackMaterialBatched1(): ShaderMaterial {
if (this._trackMaterialBatched1 != undefined) return this._trackMaterialBatched1;

this._trackMaterialBatched1 = new ShaderMaterial('track_material_batched', this._scene, trackShader, {
  attributes: ['position', 'normal', 'uv', 'color', 'world0', 'world1', 'world2', 'world3'],
  uniforms: ['viewProjection', 'albedo'],
  needAlphaBlending: true,
  defines: ['#define INSTANCES'],
});
const albedo = new Texture('assets/textures/Atlas_Opaque_B.jpg', this._scene);
this._trackMaterialBatched1.setTexture('albedo', albedo);
this._trackMaterialBatched1.backFaceCulling = true;
this._trackMaterialBatched1.forceDepthWrite = true;
return this._trackMaterialBatched1;
  }

These are the shaders I am using

export const track_batched_fragment = 
precision highp float;

varying vec2 vUV0;
varying vec4 vColor;
uniform sampler2D albedo;
void main(void) {
    float intensity = 2.0;
    vec4 color = texture2D(albedo,vUV0);
    color.rgb *= vColor.rgb * intensity;
    gl_FragColor = color;
}
`;
export const track_batched_vertex = `
precision highp float;

attribute vec3 position;
attribute vec3 normal;
attribute vec2 uv;
attribute vec4 color;
#include<instancesDeclaration>

uniform mat4 viewProjection;

varying vec2 vUV0;
varying vec4 vColor;

void main() {
#include<instancesVertex>
gl_Position = viewProjection * finalWorld * vec4(position,1.0);
vUV0 = uv;
vColor = color;
}
`;

Unfortunately without a repro in the playground it is nearly impossible to help
Make the Best Use of the Forum | Babylon.js Documentation

The shaders render fine in playground. They take the vertex color from the the actual meshes in game. Could this be a problem with the models?

https://playground.babylonjs.com/#WS42QV

That seems likely yes.Can you share one model and use it in the PG?

I am afraid not as those are our work files which are likely under NDA. One problem here is how come they render fine at the beginning. Is there a limit on the number of objects (mesh or instancedmesh) that can share the same shaderMaterial?

nope. there is no :frowning:

I am stumped then. The same shadermaterial works fine at the beginning. And I can see it is till referring to the same material throughout. Very weird issue

I would love to help but I need to see it :wink:

Ohkk I had a final few questions before moving on from this topic. I noticed that I am only using viewProjection in my unforms and added worldViewProjection to it. Noticed some weird glitches on the screen when you move the camera around.

https://playground.babylonjs.com/#WS42QV#2

Bump. @Deltakosh

Ohh we finally figured out what the problem was. We were using an old version of babylon and the models we created using instantiateModelsToScene were not getting instanced properly. Since it was a recent fix, had to use the new 5.0.0-alpha.16 version and it worked with a few tweaks in the paramaters. Hope this helps someone in the future

3 Likes