Пример #1
0
 protected override void PostAttached(SystemRegistry registry)
 {
     _gs      = registry.GetSystem <GraphicsSystem>();
     _ad      = registry.GetSystem <AssetSystem>().Database;
     _texture = Texture.Get(_ad);
     _cameraDistanceComparer = new CameraDistanceComparer(_gs);
     _gs.ExecuteOnMainThread(() => InitializeContextObjects(_gs.Context, _gs.MaterialCache, _gs.BufferCache));
 }
Пример #2
0
        protected override void Attached(SystemRegistry registry)
        {
            _gs = registry.GetSystem <GraphicsSystem>();
            _as = registry.GetSystem <AssetSystem>();
            var ad = _as.Database;

            RecreateCubemapTexture();
            _gs.ExecuteOnMainThread(() => InitializeContextObjects(ad, _gs.Context));
        }
Пример #3
0
 protected override void Attached(SystemRegistry registry)
 {
     _gs      = registry.GetSystem <GraphicsSystem>();
     _ad      = registry.GetSystem <AssetSystem>().Database;
     _texture = Texture.Get(_ad);
     _mesh    = Mesh.Get(_ad);
     _centeredBoundingSphere = _mesh.GetBoundingSphere();
     _centeredBoundingBox    = _mesh.GetBoundingBox();
     _gs.ExecuteOnMainThread(() =>
     {
         InitializeContextObjects(_gs.Context, _gs.MaterialCache, _gs.BufferCache);
     });
 }
Пример #4
0
        private async void InitializeContextObjects(RenderContext context, MaterialCache materialCache, BufferCache bufferCache)
        {
            ResourceFactory factory = context.ResourceFactory;

            Debug.Assert(_vb == null);
            Debug.Assert(_ib == null);
            Debug.Assert(_deviceTexture == null);
            Debug.Assert(_textureBinding == null);

            _vb = bufferCache.GetVertexBuffer(_mesh);
            CreateIndexBuffer(wasTransparent: false);

            if (s_regularGlobalInputs == null)
            {
                s_regularGlobalInputs = new MaterialInputs <MaterialGlobalInputElement>(
                    new MaterialGlobalInputElement[]
                {
                    new MaterialGlobalInputElement("ProjectionMatrixBuffer", MaterialInputType.Matrix4x4, "ProjectionMatrix"),
                    new MaterialGlobalInputElement("ViewMatrixBuffer", MaterialInputType.Matrix4x4, "ViewMatrix"),
                    new MaterialGlobalInputElement("LightProjectionMatrixBuffer", MaterialInputType.Matrix4x4, "LightProjMatrix"),
                    new MaterialGlobalInputElement("LightViewMatrixBuffer", MaterialInputType.Matrix4x4, "LightViewMatrix"),
                    new MaterialGlobalInputElement("LightInfoBuffer", MaterialInputType.Custom, "LightBuffer"),
                    new MaterialGlobalInputElement("CameraInfoBuffer", MaterialInputType.Custom, "CameraInfo"),
                    new MaterialGlobalInputElement("PointLightsBuffer", MaterialInputType.Custom, "PointLights")
                });
            }

            _regularPassMaterial = materialCache.GetMaterial(
                context,
                RegularPassVertexShaderSource,
                RegularPassFragmentShaderSource,
                s_vertexInputs,
                s_regularGlobalInputs,
                s_perObjectInputs,
                s_textureInputs);

            _regularPassTransparentMaterial = materialCache.GetMaterial(
                context,
                RegularPassTransparentVertexShaderSource,
                RegularPassTransparentFragmentShaderSource,
                s_vertexInputs,
                s_regularGlobalInputs,
                s_transparentPerObjectInputs,
                s_transparentTextureInputs);

            if (_texture == null)
            {
                _texture = RawTextureDataArray <RgbaFloat> .FromSingleColor(RgbaFloat.Pink);
            }

            _deviceTexture = await _gs.ExecuteOnMainThread(() => _texture.CreateDeviceTexture(factory));

            _textureBinding = await _gs.ExecuteOnMainThread(() => factory.CreateShaderTextureBinding(_deviceTexture));

            if (s_shadowmapGlobalInputs == null)
            {
                s_shadowmapGlobalInputs = new MaterialInputs <MaterialGlobalInputElement>(
                    new MaterialGlobalInputElement[]
                {
                    new MaterialGlobalInputElement("ProjectionMatrixBuffer", MaterialInputType.Matrix4x4, "LightProjMatrix"),
                    new MaterialGlobalInputElement("ViewMatrixBuffer", MaterialInputType.Matrix4x4, "LightViewMatrix")
                });
            }

            _shadowPassMaterial = materialCache.GetMaterial(
                context,
                ShadowMapPassVertexShaderSource,
                ShadowMapPassFragmentShaderSource,
                s_vertexInputs,
                s_shadowmapGlobalInputs,
                s_shadowmapPerObjectInputs,
                MaterialTextureInputs.Empty);

            if (s_wireframeRS == null)
            {
                s_wireframeRS = factory.CreateRasterizerState(FaceCullingMode.None, TriangleFillMode.Wireframe, true, true);
            }
            if (s_noCullRS == null)
            {
                s_noCullRS = factory.CreateRasterizerState(FaceCullingMode.None, TriangleFillMode.Solid, true, true);
            }

            _initialized = true;
        }
Пример #5
0
 protected override void Attached(SystemRegistry registry)
 {
     _gs = registry.GetSystem <GraphicsSystem>();
     _as = registry.GetSystem <AssetSystem>();
     _gs.ExecuteOnMainThread(InitializeContextObjects);
 }