예제 #1
0
        //public override void prepareFrameBegin() { }
        //public override void preparePerFrame(Renderable r) { }
        //public override void preparePerViewBegin(View v) { }
        //public override void preparePerView(Renderable r, View v) { }
        //public override void preparePerViewFinalize(View v) { }
        //public override void preparePerPassBegin(Pass p) { }
        //public override void preparePerPass(Renderable r, Pass p) { }

        public override void preparePerPass(Renderable r, Pass p)
        {
            SkinnedModelRenderable smr = r as SkinnedModelRenderable;

            SkinnedModelUniformData modelData = new SkinnedModelUniformData();

            modelData.modelMatrix  = smr.model.myInitialTransform * smr.modelMatrix;
            modelData.normalMatrix = (smr.model.myInitialTransform * smr.modelMatrix).ClearTranslation();
            //modelData.inverseNormalMatrix = modelData.normalMatrix.Inverted();
            modelData.activeLights  = new Vector4(0, 1, 2, 3);
            modelData.currentFrame  = (smr.findController("animation") as AnimationController).animation.currentFrame;
            modelData.nextFrame     = (smr.findController("animation") as AnimationController).animation.nextFrame;
            modelData.interpolation = (smr.findController("animation") as AnimationController).animation.interpolation;
            modelData.boneCount     = smr.model.boneCount;
            myModelData.Add(modelData);

            //save the index for this model
            int modelDataIndex = myModelData.Count - 1;

            foreach (Mesh mesh in smr.model.myMeshes)
            {
                MaterialEffect effect             = getEffect(p.technique, (UInt32)mesh.material.myFeatures);
                PipelineState  pipeline           = effect.createPipeline(mesh.material);
                RenderQueue <SkinnedModelInfo> rq = p.findRenderQueue(pipeline.id) as RenderQueue <SkinnedModelInfo>;
                if (rq == null)
                {
                    rq      = Renderer.device.createRenderQueue <SkinnedModelInfo>(effect.createPipeline(mesh.material));
                    rq.name = rq.myPipeline.shaderState.shaderProgram.name + "-" + (mesh.material.hasTransparency == true ? "transparent" : "opaque");
                    rq.myPipeline.vaoState.vao = new VertexArrayObject();
                    rq.myPipeline.vaoState.vao.bindVertexFormat <V3N3T2B4W4>(rq.myPipeline.shaderState.shaderProgram);
                    rq.visualizer = this;
                    p.registerQueue(rq);
                }

                SkinnedModelInfo info = rq.nextInfo();

                effect.updateRenderState(mesh.material, info.renderState);

                float dist = (p.view.camera.position - r.position).Length;
                info.distToCamera = dist;

                info.indexCount  = mesh.indexCount;
                info.indexOffset = mesh.indexBase;

                info.renderState.setUniform(new UniformData(0, Uniform.UniformType.Int, modelDataIndex));
                info.renderState.setStorageBuffer(myModelBuffer.id, 0);
                info.renderState.setStorageBuffer(smr.model.myFrames.id, 1);
                info.renderState.setVertexBuffer(smr.model.myVbo.id, 0, 0, V3N3T2B4W4.stride);
                info.renderState.setIndexBuffer(smr.model.myIbo.id);

                info.sortId = getSortId(info);
            }
        }
예제 #2
0
        //public override void prepareFrameBegin() { }
        public override void preparePerFrame(Renderable r)
        {
            SkinnedModelRenderable smr            = r as SkinnedModelRenderable;
            List <Matrix4>         skinningMatrix = (smr.findController("animation") as AnimationController).animation.skinningMatrix();

            smr.mySkinningBuffer.setData(skinningMatrix);

#if DEBUG
            Vector3    pos = smr.modelMatrix.ExtractTranslation();
            Quaternion ori = smr.modelMatrix.ExtractRotation();
            (smr.findController("animation") as AnimationController).animation.animation.debugDraw(skinningMatrix, pos, ori);
#endif
        }