コード例 #1
0
 public ValueTask set_outputRenderTarget(RenderTargetTexture value)
 {
     __outputRenderTarget = null;
     return(EventHorizonBlazorInterop.Set(
                this.___guid,
                "outputRenderTarget",
                value
                ));
 }
コード例 #2
0
 public async ValueTask setDepthStencilTexture(string channel, RenderTargetTexture texture)
 {
     await EventHorizonBlazorInterop.Func <CachedEntity>(
         new object[]
     {
         new string[] { this.___guid, "setDepthStencilTexture" }, channel, texture
     }
         );
 }
コード例 #3
0
        /// <summary>
        /// </summary>
        /// <returns>
        /// </returns>
        public override BaseTexture clone()
        {
            var textureSize = this.getSize();
            var newTexture  = new RenderTargetTexture(this.name, textureSize, this.getScene(), this._generateMipMaps);

            newTexture.hasAlpha        = this.hasAlpha;
            newTexture.level           = this.level;
            newTexture.coordinatesMode = this.coordinatesMode;
            newTexture.renderList      = this.renderList.slice(0);
            return(newTexture);
        }
コード例 #4
0
 public async ValueTask <RenderTargetTexture> get_outputRenderTarget()
 {
     if (__outputRenderTarget == null)
     {
         __outputRenderTarget = await EventHorizonBlazorInterop.GetClass <RenderTargetTexture>(
             this.___guid,
             "outputRenderTarget",
             (entity) =>
         {
             return(new RenderTargetTexture()
             {
                 ___guid = entity.___guid
             });
         }
             );
     }
     return(__outputRenderTarget);
 }
コード例 #5
0
        /// <summary>
        /// </summary>
        /// <param name="mapSize">
        /// </param>
        /// <param name="light">
        /// </param>
        public ShadowGenerator(Size mapSize, DirectionalLight light)
        {
            this._light                     = light;
            this._scene                     = light.getScene();
            light._shadowGenerator          = this;
            this._shadowMap                 = new RenderTargetTexture(light.name + "_shadowMap", mapSize, this._scene, false);
            this._shadowMap.wrapU           = Texture.CLAMP_ADDRESSMODE;
            this._shadowMap.wrapV           = Texture.CLAMP_ADDRESSMODE;
            this._shadowMap.renderParticles = false;
            Action <SubMesh> renderSubMesh = (SubMesh subMesh) =>
            {
                var mesh   = subMesh.getRenderingMesh();
                var scene  = this._scene;
                var engine = scene.getEngine();
                engine.setState(subMesh.getMaterial().backFaceCulling);
                var batch = mesh._getInstancesRenderList(subMesh._id);
                if (batch.mustReturn)
                {
                    return;
                }

                var hardwareInstancedRendering = (engine.getCaps().instancedArrays != null) && (batch.visibleInstances != null);
                if (this.isReady(subMesh, hardwareInstancedRendering))
                {
                    engine.enableEffect(this._effect);
                    mesh._bind(subMesh, this._effect, false);
                    var material = subMesh.getMaterial();
                    this._effect.setMatrix("viewProjection", this.getTransformMatrix());
                    if (material != null && material.needAlphaTesting())
                    {
                        var alphaTexture = material.getAlphaTestTexture();
                        this._effect.setTexture("diffuseSampler", alphaTexture);
                        this._effect.setMatrix("diffuseMatrix", alphaTexture.getTextureMatrix());
                    }

                    var useBones = mesh.skeleton != null && mesh.isVerticesDataPresent(VertexBufferKind.MatricesIndicesKind) &&
                                   mesh.isVerticesDataPresent(VertexBufferKind.MatricesWeightsKind);
                    if (useBones)
                    {
                        this._effect.setMatrices("mBones", mesh.skeleton.getTransformMatrices());
                    }

                    if (hardwareInstancedRendering)
                    {
                        mesh._renderWithInstances(subMesh, false, batch, this._effect, engine);
                    }
                    else
                    {
                        if (batch.renderSelf[subMesh._id])
                        {
                            this._effect.setMatrix("world", mesh.getWorldMatrix());
                            mesh._draw(subMesh, true);
                        }

                        if (batch.visibleInstances[subMesh._id] != null)
                        {
                            for (var instanceIndex = 0; instanceIndex < batch.visibleInstances[subMesh._id].Length; instanceIndex++)
                            {
                                var instance = batch.visibleInstances[subMesh._id][instanceIndex];
                                this._effect.setMatrix("world", instance.getWorldMatrix());
                                mesh._draw(subMesh, true);
                            }
                        }
                    }
                }
                else
                {
                    this._shadowMap.resetRefreshCounter();
                }
            };

            this._shadowMap.customRenderFunction =
                (SmartArray <SubMesh> opaqueSubMeshes,
                 SmartArray <SubMesh> alphaTestSubMeshes,
                 SmartArray <SubMesh> transparentSubMeshes,
                 System.Action beforeTransform) =>
            {
                for (var index = 0; index < opaqueSubMeshes.Length; index++)
                {
                    renderSubMesh(opaqueSubMeshes[index]);
                }

                for (var index = 0; index < alphaTestSubMeshes.Length; index++)
                {
                    renderSubMesh(alphaTestSubMeshes[index]);
                }

                if (this._transparencyShadow)
                {
                    for (var index = 0; index < transparentSubMeshes.Length; index++)
                    {
                        renderSubMesh(transparentSubMeshes[index]);
                    }
                }
            };
        }
コード例 #6
0
        private void Scene19()
        {
            this.scene = new BABYLON.Scene(engine);
            var camera   = new BABYLON.ArcRotateCamera("Camera", 0, 0, 10, BABYLON.Vector3.Zero(), scene);
            var material = new BABYLON.StandardMaterial("kosh", scene);

            material.diffuseColor = BABYLON.Color3.Purple();
            var light = new BABYLON.PointLight("Omni0", new BABYLON.Vector3(-17.6, 18.8, -49.9), scene);

            camera.setPosition(new BABYLON.Vector3(-15, 10, -20));
            camera.minZ = 1.0;
            camera.maxZ = 120.0;

            // Skybox
            var skybox         = BABYLON.Mesh.CreateBox("skyBox", 100.0, scene);
            var skyboxMaterial = new BABYLON.StandardMaterial("skyBox", scene);

            skyboxMaterial.backFaceCulling   = false;
            skyboxMaterial.reflectionTexture = new BABYLON.CubeTexture("skybox", scene);
            skyboxMaterial.reflectionTexture.coordinatesMode = BABYLON.Texture.SKYBOX_MODE;
            skyboxMaterial.diffuseColor  = new BABYLON.Color3(0, 0, 0);
            skyboxMaterial.specularColor = new BABYLON.Color3(0, 0, 0);
            skybox.material = skyboxMaterial;

            // depth material
            BABYLON.Effect.ShadersStore["depthVertexShader"] =
                "#ifdef GL_ES\n" +
                "precision highp float;\n" +
                "#endif\n" +
                "attribute vec3 position;\n" +
                "uniform mat4 worldViewProjection;\n" +
                "void main(void) {\n" +
                "gl_Position = worldViewProjection * vec4(position, 1.0);\n" +
                "}";
            BABYLON.Effect.ShadersStore["depthPixelShader"] =
                "#ifdef GL_ES\n" +
                "precision highp float;\n" +
                "#endif\n" +

                "void main(void) {\n" +
                "float depth =  1.0 - (2.0 / (100.0 + 1.0 - gl_FragCoord.z * (100.0 - 1.0)));\n" +
                "gl_FragColor = vec4(depth, depth, depth, 1.0);\n" +
                "}\n" +
                "";

            var depthMaterial = new BABYLON.ShaderMaterial(
                "depth",
                scene,
                "depth",
                new ShaderMaterialOptions()
            {
                attributes = new Array <string>("position"),
                uniforms   = new Array <string>("worldViewProjection")
            });

            depthMaterial.backFaceCulling = false;

            // Plane
            var plane = BABYLON.Mesh.CreatePlane("map", 10, scene);

            plane.billboardMode = BABYLON.AbstractMesh.BILLBOARDMODE_ALL;
            plane.scaling.y     = 1.0 / engine.getAspectRatio(scene.activeCamera);

            // Render target
            var renderTarget = new BABYLON.RenderTargetTexture(
                "depth",
                new BABYLON.Size()
            {
                width = 1024, height = 1024
            },
                scene);

            renderTarget.renderList.Add(skybox);
            scene.customRenderTargets.Add(renderTarget);

            renderTarget.onBeforeRender = () =>
            {
                for (var index = 0; index < renderTarget.renderList.Length; index++)
                {
                    renderTarget.renderList[index]._savedMaterial = renderTarget.renderList[index].material;
                    renderTarget.renderList[index].material       = depthMaterial;
                }
            };

            renderTarget.onAfterRender = () =>
            {
                // Restoring previoux material
                for (var index = 0; index < renderTarget.renderList.Length; index++)
                {
                    renderTarget.renderList[index].material = renderTarget.renderList[index]._savedMaterial;
                }
            };

            // Spheres
            var spheresCount = 20;
            var alpha        = 0.0;

            for (var index = 0; index < spheresCount; index++)
            {
                var sphere = BABYLON.Mesh.CreateSphere("Sphere" + index, 32, 3, scene);
                sphere.position.x = 10 * Math.Cos(alpha);
                sphere.position.z = 10 * Math.Sin(alpha);
                sphere.material   = material;

                alpha += (2 * Math.PI) / spheresCount;

                renderTarget.renderList.Add(sphere);
            }

            // Plane material
            var mat = new BABYLON.StandardMaterial("plan mat", scene);

            mat.diffuseColor    = BABYLON.Color3.Black();
            mat.specularColor   = BABYLON.Color3.Black();
            mat.emissiveTexture = renderTarget;

            plane.material = mat;

            // Animations
            var isReady = false;

            scene.registerBeforeRender(() =>
            {
                camera.alpha += 0.01 * scene.getAnimationRatio();

                if (!isReady && scene.isReady())
                {
                    isReady = true;
                }
            });

            this.scene.activeCamera.attachControl(this.canvas);
        }