If I set this on my planet (like on demo above with ShaderMaterial), the asteroidsystem is shown in front of my planet.
code of planet material:
const terrain = new BABYLON.DynamicTexture('random', 128, this.scene, false, BABYLON.Texture.NEAREST_SAMPLINGMODE);
const clouds = new BABYLON.DynamicTexture('random', 128, this.scene, false, BABYLON.Texture.NEAREST_SAMPLINGMODE);
let updateRandomSurface = function (random) {
let context = random.getContext();
let imgData = context.getImageData(0, 0, 512, 512);
for (let i = 0; i < 512 * 512 * 4; i++) {
imgData.data[i] = Math.random() * 256 | 0
}
context.putImageData(imgData, 0, 0);
random.update()
};
let noiseTexture;
let cloudTexture;
this.body = BABYLON.MeshBuilder.CreateSphere('planet', { segments: 64, diameter: 2*this.radius}, this.scene);
this.body.parent = this.root;
this.body.material = new BABYLON.ShaderMaterial('shader', this.scene, { // ShaderMaterial
vertex: './assets/textures/planets/planet',
fragment: './assets/textures/planets/planet'
}, {
attributes: ['position', 'normal', 'uv'],
uniforms: ['world', 'worldView', 'worldViewProjection', 'view', 'projection'],
needAlphaBlending: true
});
this.body.material.setVector3('cameraPosition', this.scene.activeCamera.position);
this.body.material.setVector3('lightPosition', this.mesher.light.position);
const generateBiome = () => {
this.options = this.worlder.planetOptions[this.data['planet_type_id']];
for(const [optionKey,optionData] of Object.entries(this.worlder.planetOptions[1])) {// Default values
if(!this.options[optionKey]) {
this.options[optionKey] = optionData;
}
}
this.options.seed *= this.data['planet_random'];
if(this.options.cloudSeed) this.options.cloudSeed *= this.data['planet_random'];
this.options.groundAlbedo *= this.data['planet_random'];
if (noiseTexture) {
noiseTexture.dispose();
cloudTexture.dispose()
}
updateRandomSurface(terrain);
updateRandomSurface(clouds);
noiseTexture = new BABYLON.ProceduralTexture('noise', this.options.mapSize, './assets/textures/noises/noise', game.scene, null, true, true);
noiseTexture.setColor3('upperColor', this.options.upperColor);
noiseTexture.setColor3('lowerColor', this.options.lowerColor);
noiseTexture.setFloat('mapSize', this.options.mapSize);
noiseTexture.setFloat('maxResolution', this.options.maxResolution);
noiseTexture.setFloat('seed', this.options.seed);
noiseTexture.setVector2('lowerClamp', this.options.lowerClamp);
noiseTexture.setTexture('randomSampler', terrain);
noiseTexture.setVector2('range', this.options.range);
noiseTexture.setVector3('options', new BABYLON.Vector3(this.options.directNoise ? 1 : 0, this.options.lowerClip.x, this.options.lowerClip.y));
this.body.material.setTexture('textureSampler', noiseTexture);
cloudTexture = new BABYLON.ProceduralTexture('cloud', this.options.mapSize, './assets/textures/noises/noise', game.scene, null, true, true);
cloudTexture.setTexture('randomSampler', clouds);
cloudTexture.setFloat('mapSize', this.options.mapSize);
cloudTexture.setFloat('maxResolution', 256);
cloudTexture.setFloat('seed', this.options.cloudSeed);
cloudTexture.setVector3('options', new BABYLON.Vector3(1, 0, 1));
this.body.material.setTexture('cloudSampler', cloudTexture);
this.body.material.setColor3('haloColor', this.options.haloColor);
};
generateBiome();