コード例 #1
0
        public override void PrepareEffectPermutations(RenderDrawContext context)
        {
            base.PrepareEffectPermutations(context);

            var rootEffectRenderFeature = ((RootEffectRenderFeature)RootRenderFeature);
            var renderEffects           = RootRenderFeature.RenderData.GetData(((RootEffectRenderFeature)RootRenderFeature).RenderEffectKey);
            int effectSlotCount         = ((RootEffectRenderFeature)RootRenderFeature).EffectPermutationSlotCount;

            Dispatcher.ForEach(RootRenderFeature.ObjectNodeReferences, objectNodeReference =>
            {
                var objectNode       = RootRenderFeature.GetObjectNode(objectNodeReference);
                var renderMesh       = (RenderMesh)objectNode.RenderObject;
                var staticObjectNode = renderMesh.StaticObjectNode;

                renderMesh.ActiveMeshDraw = renderMesh.Mesh.Draw;

                foreach (var stage in RenderSystem.RenderStages)
                {
                    if (stage == null)
                    {
                        continue;
                    }
                    var effectSlot             = rootEffectRenderFeature.GetEffectPermutationSlot(stage);
                    var staticEffectObjectNode = staticObjectNode * effectSlotCount + effectSlot.Index;
                    var renderEffect           = renderEffects[staticEffectObjectNode];

                    if (renderEffect != null)
                    {
                        renderEffect.EffectValidator.ValidateParameter(StrideEffectBaseKeys.ComputeVelocityShader, new ShaderClassSource("MeshVelocity"));
                    }
                }
            });
        }
コード例 #2
0
        /// <inheritdoc/>
        public override void Extract()
        {
            if (!Context.VisibilityGroup.Tags.TryGetValue(ModelToInstancingMap, out var modelToInstancingMap))
            {
                return;
            }

            var renderObjectInstancingData = RootRenderFeature.RenderData.GetData(renderObjectInstancingDataInfoKey);

            bufferUploaded.Clear();

            foreach (var objectNodeReference in RootRenderFeature.ObjectNodeReferences)
            {
                var objectNode = RootRenderFeature.GetObjectNode(objectNodeReference);
                var renderMesh = objectNode.RenderObject as RenderMesh;
                if (renderMesh == null)
                {
                    continue;
                }

                var renderModel = renderMesh.RenderModel;
                if (renderModel == null)
                {
                    continue;
                }

                if (!modelToInstancingMap.TryGetValue(renderModel, out var renderInstancing))
                {
                    renderMesh.InstanceCount = 0;
                    continue;
                }

                ref var instancingData = ref renderObjectInstancingData[renderMesh.StaticObjectNode];

                // Instancing data
                if (renderInstancing.InstanceCount > 0)
                {
                    instancingData.InstanceCount              = renderInstancing.InstanceCount;
                    instancingData.ModelTransformUsage        = renderInstancing.ModelTransformUsage;
                    instancingData.BuffersManagedByUser       = renderInstancing.BuffersManagedByUser;
                    instancingData.WorldMatrices              = renderInstancing.WorldMatrices;
                    instancingData.WorldInverseMatrices       = renderInstancing.WorldInverseMatrices;
                    instancingData.InstanceWorldBuffer        = renderInstancing.InstanceWorldBuffer;
                    instancingData.InstanceWorldInverseBuffer = renderInstancing.InstanceWorldInverseBuffer;

                    bufferUploaded[renderInstancing.InstanceWorldBuffer] = renderInstancing.BuffersManagedByUser;
                }
                else
                {
                    instancingData.InstanceCount = 0;
                }

                // Update instance count on mesh
                renderMesh.InstanceCount = instancingData.InstanceCount;
            }
コード例 #3
0
        /// <inheritdoc/>
        public override void Extract()
        {
            var renderModelObjectInfo = RootRenderFeature.RenderData.GetData(RenderModelObjectInfoKey);

            //for (int index = 0; index < RootRenderFeature.ObjectNodeReferences.Count; index++)
            Dispatcher.For(0, RootRenderFeature.ObjectNodeReferences.Count, index =>
            {
                var objectNodeReference = RootRenderFeature.ObjectNodeReferences[index];
                var objectNode          = RootRenderFeature.GetObjectNode(objectNodeReference);
                var renderMesh          = objectNode.RenderObject as RenderMesh;

                // TODO: Extract world
                renderModelObjectInfo[objectNodeReference].World = renderMesh != null ? renderMesh.World : Matrix.Identity;
            });
        }
コード例 #4
0
ファイル: SkinningRenderFeature.cs プロジェクト: vvvv/stride
        /// <param name="context"></param>
        /// <inheritdoc/>
        public override void PrepareEffectPermutations(RenderDrawContext context)
        {
            var skinningInfos = RootRenderFeature.RenderData.GetData(skinningInfoKey);

            var renderEffects   = RootRenderFeature.RenderData.GetData(renderEffectKey);
            int effectSlotCount = ((RootEffectRenderFeature)RootRenderFeature).EffectPermutationSlotCount;

            //foreach (var objectNodeReference in RootRenderFeature.ObjectNodeReferences)
            Dispatcher.ForEach(((RootEffectRenderFeature)RootRenderFeature).ObjectNodeReferences, objectNodeReference =>
            {
                var objectNode       = RootRenderFeature.GetObjectNode(objectNodeReference);
                var renderMesh       = (RenderMesh)objectNode.RenderObject;
                var staticObjectNode = renderMesh.StaticObjectNode;

                ref var skinningInfo = ref skinningInfos[staticObjectNode];
                var parameters       = renderMesh.Mesh.Parameters;
                if (parameters != skinningInfo.Parameters || parameters.PermutationCounter != skinningInfo.PermutationCounter)
                {
                    skinningInfo.Parameters         = parameters;
                    skinningInfo.PermutationCounter = parameters.PermutationCounter;

                    skinningInfo.HasSkinningPosition = parameters.Get(MaterialKeys.HasSkinningPosition);
                    skinningInfo.HasSkinningNormal   = parameters.Get(MaterialKeys.HasSkinningNormal);
                    skinningInfo.HasSkinningTangent  = parameters.Get(MaterialKeys.HasSkinningTangent);
                }

                for (int i = 0; i < effectSlotCount; ++i)
                {
                    var staticEffectObjectNode = staticObjectNode * effectSlotCount + i;
                    var renderEffect           = renderEffects[staticEffectObjectNode];

                    // Skip effects not used during this frame
                    if (renderEffect == null || !renderEffect.IsUsedDuringThisFrame(RenderSystem))
                    {
                        continue;
                    }

                    if (renderMesh.Mesh.Skinning != null)
                    {
                        renderEffect.EffectValidator.ValidateParameter(MaterialKeys.HasSkinningPosition, skinningInfo.HasSkinningPosition);
                        renderEffect.EffectValidator.ValidateParameter(MaterialKeys.HasSkinningNormal, skinningInfo.HasSkinningNormal);
                        renderEffect.EffectValidator.ValidateParameter(MaterialKeys.HasSkinningTangent, skinningInfo.HasSkinningTangent);

                        var skinningBones = Math.Max(MaxBones, renderMesh.Mesh.Skinning.Bones.Length);
                        renderEffect.EffectValidator.ValidateParameter(MaterialKeys.SkinningMaxBones, skinningBones);
                    }
                }
            });