Transparency alpha render issues

Layers aren’t on the entity object. They are on model or render components.

1 Like

So I get an output of the loaded GLB-model’s meshes - so far so good.
But I am not able to set, the layers to each of (the model’s) meshinstances - for then finally the goal of refracting each meshinstance:

Refraction.prototype.postUpdate = function(dt) {

    if(this.app.root.findByName("RightHandUrHook_SwarowskiEx").script.lexg3.fr >20){

    if (this.firstRender) {

        this.firstRender = false;

       

        var self = this;

        var device = this.app.graphicsDevice;

       

        if (! this.layerRefraction) {

            console.log('Refraction: no "Refraction" layer found.');

            return;

        }

       

        // create render target

        this.resize();

       

        // for each entity marked as refract

        var loadedGLB = this.app.root.findByGuid(this.app.root.findByName("RightHandUrHook_SwarowskiEx").script.lexg3.ggu);// console.log("FF: "+loadedGLB.name);

        var entities = loadedGLB.model.meshInstances;

       

        if (entities.length === 0)

            console.log("LAYER1 Refraction: no entities found. Mark entities with `refract` tags.");

       

        for(var i = 0; i < entities.length; i++) {

            var mesh = entities[i];

            console.log("LAYER1: "+ entities.length);

            if (! mesh) {

                console.log('LAYER1 Refraction: entity "' + entities[i].name + '" have no model component.');

                continue;

            }

            entities[i].modelLayers = 1;

            var modelLayers = entities[i].modelLayers.slice(0);

            if (modelLayers.indexOf(this.layerWorld.id) === -1) {

                console.log('LAYER1 Refraction: entity "' + entities[i].name + '" is not on "World" layer.');

                continue;

            }

You don’t need to do it on the meshinstances directly, the model/render component will handle that for you when the layer id array is set on the component

Hmmm I think I am almost there:

Refraction.prototype.postUpdate = function(dt) {

    if(this.app.root.findByName("RightHandUrHook_SwarowskiEx").script.lexg3.fr >200){

    if (this.firstRender) {
        this.firstRender = false;    
        var device = this.app.graphicsDevice;
       if (! this.layerRefraction) {
            console.log('Refraction: no "Refraction" layer found.');
            return;
        }       

        // create render target
        this.resize();      

        // for each entity marked as refract
        var tmpval = this.app.root.findByName("RightHandUrHook_SwarowskiEx").script.lexg3.ggu; 
        var loadedGLB = this.app.root.findByName(tmpval);     var entities = loadedGLB.name;      

          // update materials

           var meshes = this.app.root.findByName("RightHandUrHook_SwarowskiEx").script.lexg3.meshes;

        for(var m = 0; m < meshes.length; m++) {      meshes[m].layer =1;
               meshes[m].material.chunks.refractionPS = this.chunkRefractFS.resource;
              meshes[m].depthWrite=false;
              meshes[m].material.update();

          }

        // render again
        this.layerRefraction.addMeshInstances(this.layerWorld.opaqueMeshInstances);
        this.layerRefraction.addMeshInstances(this.layerWorld.transparentMeshInstances);
     
        // set screenspace texture     
        device.scope.resolve('texture_screen').setValue(this.renderTarget.colorBuffer);
    }
    }

};

The code compiles, but no change in material / refraction

Here is the project: https://playcanvas.com/editor/scene/1314831

A post was split to a new topic: WebGL error when opening project in Editor