Esempio n. 1
0
    public GameObject CreateBillboard(string path, string name, bool usingHDRP)
    {
        GameObject camObject = Instantiate(Resources.Load("Mtree/MtreeBillboardCamera") as GameObject); // create billboard and render it
        Camera     cam       = camObject.GetComponent <Camera>();
        Billboard  bill      = new Billboard(cam, gameObject, 512, 512);

        bill.SetupCamera();
        string texturePath = path + name + "_billboard.png";

        bill.Render(texturePath);
        DestroyImmediate(camObject);

        Mesh billboardMesh = bill.CreateMesh(); // create billboard mesh

        AssetDatabase.CreateAsset(billboardMesh, path + name + "_LOD4.mesh");

        GameObject billboard  = new GameObject(name + "_LOD4"); // create billboard object and assign mesh
        MeshFilter meshFilter = billboard.AddComponent <MeshFilter>();

        meshFilter.mesh = billboardMesh;
        MeshRenderer meshRenderer = billboard.AddComponent <MeshRenderer>();

        Texture  billboardTexture = (Texture2D)AssetDatabase.LoadAssetAtPath(texturePath, typeof(Texture2D)); // create material
        Material mat = bill.CreateMaterial(billboardTexture, usingHDRP);

        meshRenderer.sharedMaterial = mat;
        AssetDatabase.CreateAsset(mat, path + name + "billboard.mat");
        return(billboard);
    }
Esempio n. 2
0
 /// <summary>
 /// Render the points
 /// </summary>
 private void DrawPoints()
 {
     if (fPoints.Count > 0 && fBillboard != null)
     {
         GraphicsDevice.BlendState        = fBlendState;
         GraphicsDevice.DepthStencilState = DepthStencilState.None;
         Matrix vp = fCamera.Camera.ViewMatrix * fCamera.Camera.ProjectionMatrix;
         fShader.Parameters["world"].SetValue(fCamera.Camera.WorldMatrix);
         fShader.Parameters["vp"].SetValue(vp);
         fShader.Parameters["particleTexture"].SetValue(fTexture);
         for (int ps = 0; ps < fShader.CurrentTechnique.Passes.Count; ps++)
         {
             fShader.CurrentTechnique.Passes[ps].Apply();
             fBillboard.Render();
         }
     }
 }
Esempio n. 3
0
        /// <summary>
        /// Render the points
        /// </summary>
        private void DrawPoints(GameTime gameTime)
        {
            if (fPoints.Count > 0 && fBillboard1 != null)
            {
                Matrix world      = fCamera.Camera.WorldMatrix;
                Matrix view       = fCamera.Camera.ViewMatrix;
                Matrix projection = fCamera.Camera.ProjectionMatrix;
                if (!fHalted)
                {
                    fWorldAngle += Convert.ToSingle(gameTime.ElapsedGameTime.TotalSeconds * 0.5f);
                }
                world = Matrix.CreateRotationY(fWorldAngle);

                fBasicEffect.World      = world;
                fBasicEffect.View       = view;
                fBasicEffect.Projection = projection;
                fBasicEffect.CurrentTechnique.Passes[0].Apply();

                Texture2D[] textures;
                if (fTextureMode == TextureMode.Faces)
                {
                    textures = new Texture2D[] { fTexture1a, fTexture2a, fTexture3a }
                }
                ;
                else
                {
                    textures = new Texture2D[] { fTexture1b, fTexture2b, fTexture3b }
                };

                if (fDrawMode == BillboardMode.PointList)
                {
                    GraphicsDevice.DepthStencilState = DepthStencilState.Default;
                    GraphicsDevice.RasterizerState   = RasterizerState.CullNone;
                    GraphicsDevice.BlendState        = BlendState.Opaque;
                    Matrix vp = view * projection;
                    fShader.Parameters["world"].SetValue(world);
                    fShader.Parameters["vp"].SetValue(vp);
                    fShader.Parameters["particleTexture"].SetValue(textures[0]);
                    fShader.CurrentTechnique.Passes[0].Apply();
                    fBillboard1.Render();
                    fShader.Parameters["particleTexture"].SetValue(textures[1]);
                    fShader.CurrentTechnique.Passes[0].Apply();
                    fBillboard2.Render();
                    fShader.Parameters["particleTexture"].SetValue(textures[2]);
                    fShader.CurrentTechnique.Passes[0].Apply();
                    fBillboard3.Render();
                }
                else
                {
                    // Step 1
                    GraphicsDevice.BlendState        = BlendState.NonPremultiplied;
                    GraphicsDevice.DepthStencilState = DepthStencilState.Default;
                    GraphicsDevice.RasterizerState   = RasterizerState.CullNone;

                    fAlpha1.View       = view;
                    fAlpha1.Projection = projection;
                    fAlpha1.World      = world;
                    fAlpha1.Texture    = null;
                    fAlpha1.CurrentTechnique.Passes[0].Apply();

                    fAlpha1.Texture = textures[0];
                    fAlpha1.CurrentTechnique.Passes[0].Apply();
                    fBillboard1.Render();

                    fAlpha1.Texture = textures[1];
                    fAlpha1.CurrentTechnique.Passes[0].Apply();
                    fBillboard2.Render();

                    fAlpha1.Texture = textures[2];
                    fAlpha1.CurrentTechnique.Passes[0].Apply();
                    fBillboard3.Render();

                    // A second rending process can be neccessary for other textures

                    // Step 2
                    //GraphicsDevice.BlendState = BlendState.NonPremultiplied;
                    //GraphicsDevice.DepthStencilState = DepthStencilState.None;
                    //GraphicsDevice.RasterizerState = RasterizerState.CullNone;

                    //fAlpha2.View = view;
                    //fAlpha2.Projection = projection;
                    //fAlpha2.World = world;
                    //fAlpha2.Texture = null;
                    //fAlpha2.CurrentTechnique.Passes[0].Apply();

                    //fAlpha2.Texture = textures[0];
                    //fAlpha2.CurrentTechnique.Passes[0].Apply();
                    //fBillboard1.Render();

                    //fAlpha2.Texture = textures[1];
                    //fAlpha2.CurrentTechnique.Passes[0].Apply();
                    //fBillboard2.Render();

                    //fAlpha2.Texture = textures[2];
                    //fAlpha2.CurrentTechnique.Passes[0].Apply();
                    //fBillboard3.Render();

                    //GraphicsDevice.DepthStencilState = DepthStencilState.Default;
                }
            }
        }