Пример #1
0
        public override void OnEnable()
        {
            base.OnEnable();
            if (!Material || !Material.IsPostFx)
            {
                return;
            }
            Material.WaitForLoaded();
            _materialInstance = Material.CreateVirtualInstance();

            _inputParameters = GetPublicParameters(_materialInstance);
        }
        public override void OnEnable()
        {
            base.OnEnable();

            if (!Material || !Material.IsSurface)
            {
                return;
            }
            Material.WaitForLoaded();
            _materialInstance = Material.CreateVirtualInstance();

            _inputParameters = GetPublicParameters(_materialInstance);

            var size = Size;

            _orthographicCamera = CreateOrthographicCamera();
            _model = Content.CreateVirtualAsset <Model>();
            _model.SetupLODs(1);
            _model.SetupMaterialSlots(1);
            _model.MinScreenSize = 0;
            // TODO: Optimize, use instanced rendering and whatnot
            GenerateGridMesh(_model.LODs[0].Meshes[0], size);
            _cachedSize           = size;
            _modelActor           = FlaxEngine.Object.New <StaticModel>();
            _modelActor.Model     = _model;
            _modelActor.DrawModes = DrawPass.Depth | DrawPass.GBuffer; // TODO: Optionally enable transparency?
            _modelActor.Entries[0].ReceiveDecals = false;
            _modelActor.Entries[0].ShadowsMode   = ShadowsCastingMode.None;
            _modelActor.Entries[0].Material      = _materialInstance;
            _modelActor.LocalPosition            = new Vector3(size * -0.5f, DistanceFromOrigin);

            Output = CreateOutputTexture(Size);

            RenderTask = FlaxEngine.Object.New <SceneRenderTask>();
            RenderTask.AllowGlobalCustomPostFx = false;
            RenderTask.Order        = Order;
            RenderTask.Camera       = _orthographicCamera;
            RenderTask.ActorsSource = ActorsSources.CustomActors;
            RenderTask.Output       = Output;
            RenderTask.Begin       += OnRenderTaskBegin;
            RenderTask.End         += OnRenderTaskEnd;
            RenderTask.CustomActors.Add(_modelActor);
            RenderTask.View.MaxShadowsQuality = Quality.Low;
            RenderTask.View.Mode  = ViewMode.Emissive;
            RenderTask.View.Flags = ViewFlags.None;
        }
Пример #3
0
        private void OnEnable()
        {
            // Create backbuffer
            if (_output == null)
            {
                _output = RenderTarget.New();
            }
            _output.Init(PixelFormat.R8G8B8A8_UNorm, (int)_resolution.X, (int)_resolution.Y);

            // Create rendering task
            if (_task == null)
            {
                _task = RenderTask.Create <SceneRenderTask>();
            }
            _task.Order   = -100;
            _task.Camera  = Cam;
            _task.Output  = _output;
            _task.Enabled = false;

            if (Material && _material == null)
            {
                // Use dynamic material instance
                if (Material.WaitForLoaded())
                {
                    throw new Exception("Failed to load material.");
                }
                _material = Material.CreateVirtualInstance();

                // Set render task output to draw on model
                _material.GetParam("Image").Value = _output;

                // Bind material to parent model
                if (Actor is StaticModel staticModel && staticModel.Model)
                {
                    staticModel.Model.WaitForLoaded();
                    staticModel.Entries[0].Material = _material;
                }
            }

            _task.Enabled = true;
        }