gogoprog

Explosion scene for a game

Recommended Posts

Used this is a great place to start... https://doc.babylonjs.com/snippets/writing2  

Adapted to extend range (supernova effect)[loops itself] and added fader fadeout -> cool things.

var blueBoom; 
anmExplodeShader = function(){

        BABYLON.Effect.ShadersStore["customVertexShader"]= "\r\n"+   
            "precision highp float;\r\n"+

            "// Attributes\r\n"+
            "attribute vec3 position;\r\n"+
            "attribute vec3 normal;\r\n"+

            "// Uniforms\r\n"+
            "uniform mat4 worldViewProjection;\r\n"+
            "uniform float time;\r\n"+

            "void main(void) {\r\n"+
            "    vec3 p = position;\r\n"+
            "    vec3 j = vec3(0., -1.0, 0.);\r\n"+
            "    p = p + normal * log2(1. + time) * 25.0;\r\n"+
            "    gl_Position = worldViewProjection * vec4(p, 1.0);\r\n"+
            "}\r\n";

        BABYLON.Effect.ShadersStore["customFragmentShader"]="\r\n"+
           "precision highp float;\r\n"+

            "uniform float time;\r\n"+
            "uniform float fader;\r\n"+

            "void main(void) {\r\n"+
            // "   gl_FragColor = vec4(1.0,0.0,1.0,1.0);\r\n"+
            // "   gl_FragColor = vec4(0.2,0.0,1.0,1.0);\r\n"+
            "   gl_FragColor = vec4(0.2,0.0,1.0,fader);\r\n"+
            "}\r\n";

        var shaderMaterial = new BABYLON.ShaderMaterial("shader", scene, {
            vertex: "custom",
            fragment: "custom",
            },
            {
                // needAlphaBlending : true,
                attributes: ["position", "normal", "uv"],
                uniforms: ["world", "worldView", "worldViewProjection", "view", "projection"],
                needAlphaBlending: true
            });

            // "    gl_FragColor = vec4(1. - log2(1. + time)/100., 1. * log2(1. + time), 0., 1. - log2(1. + time/2.)/log2(1. + 3.95));\r\n"+

        shaderMaterial.backFaceCulling = false;

        blueBoom = BABYLON.MeshBuilder.CreateSphere("blueBoom", {diameter:100}, scene);
        blueBoom.convertToFlatShadedMesh();   

        blueBoom.material = shaderMaterial;
        blueBoom.material.alphaMode = 2; 

        var time = 0.;
        var fader = 1;
        scene.registerBeforeRender(function() {
            if(time<50) {
                blueBoom.material.setFloat("fader", fader);
                blueBoom.material.setFloat("time", time);
                time +=0.1;
                //fadeout over time
                if(time > 30){
                    blueBoom.material.setFloat("fader", fader);
                    fader -=0.01;
                    // blueBoom.material.alpha -= 0.5;
                    // console.log('ALPHA: ',blueBoom.material.alpha)
                }
            } 
            else {
                blueBoom.dispose();
            }
        });

Also rotate the camera to look down into the y axis... pretty cool low poly cartoon explosion effect.

Share this post


Link to post
Share on other sites
25 minutes ago, aFalcon said:

Used this is a great place to start... https://doc.babylonjs.com/snippets/writing2  

Adapted to extend range (supernova effect)[loops itself] and added fader fadeout -> cool things.


var blueBoom; 
...

Also rotate the camera to look down into the y axis... pretty cool low poly cartoon explosion effect.

Thanks for your input but we are aiming at something more realistic

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.