Ejemplo n.º 1
0
        public void registerEffect(String technique, MaterialEffect effect)
        {
            Dictionary <UInt32, MaterialEffect> effectMap = null;

            if (myTechniqueEffects.TryGetValue(technique, out effectMap) == false)
            {
                myTechniqueEffects[technique] = new Dictionary <UInt32, MaterialEffect>();
            }

            myTechniqueEffects[technique][effect.effectType] = effect;
        }
Ejemplo n.º 2
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);
            }
        }
Ejemplo n.º 3
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)
        {
            SkydomeRenderable renderable = r as SkydomeRenderable;
            Model             model      = renderable.skydome;
            Mesh mesh = model.myMeshes[0];

            MaterialEffect effect   = getEffect(p.technique, (UInt32)Material.Feature.Skydome);
            PipelineState  pipeline = effect.createPipeline(mesh.material);

            RenderQueue <StaticModelInfo> rq = p.findRenderQueue(pipeline.id) as RenderQueue <StaticModelInfo>;

            if (rq == null)
            {
                rq      = Renderer.device.createRenderQueue <StaticModelInfo>(effect.createPipeline(mesh.material));
                rq.name = rq.myPipeline.shaderState.shaderProgram.name;
                rq.myPipeline.vaoState.vao = new VertexArrayObject();
                rq.myPipeline.vaoState.vao.bindVertexFormat(rq.myPipeline.shaderState.shaderProgram, V3.bindings());
                rq.visualizer = this;
                p.registerQueue(rq);
            }

            StaticModelInfo info = rq.nextInfo();

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

            info.renderState.setUniformBuffer(p.view.camera.uniformBufferId(), 0);
            info.renderState.setVertexBuffer(model.myVbos[0].id, 0, 0, V3N3T2.stride);
            info.renderState.setIndexBuffer(model.myIbo.id);
            info.renderState.setUniform(new UniformData(0, Uniform.UniformType.Vec3, renderable.sunPosition));
            Matrix4 rot = Matrix4.CreateRotationX(renderable.starRotation);

            info.renderState.setUniform(new UniformData(1, Uniform.UniformType.Mat4, rot));
            info.renderState.setUniform(new UniformData(26, Uniform.UniformType.Float, renderable.weatherIntensity));
            info.renderState.setUniform(new UniformData(27, Uniform.UniformType.Float, renderable.weatherSpeed));
            info.renderState.setUniform(new UniformData(28, Uniform.UniformType.Float, renderable.sunSize));
            info.renderState.setUniform(new UniformData(29, Uniform.UniformType.Float, renderable.moonSize));
            info.indexOffset = mesh.indexBase;
            info.indexCount  = mesh.indexCount;
        }
Ejemplo n.º 4
0
        public MaterialEffect getEffect(String technique, UInt32 effectType)
        {
            Dictionary <UInt32, MaterialEffect> effectMap = null;

            if (myTechniqueEffects.TryGetValue(technique, out effectMap) == false)
            {
                String err = String.Format("Cannot find effect map for technique {0} in visualizer {1}", technique, myType);
                Warn.print(err);
                throw new Exception(err);
            }

            MaterialEffect effect = null;

            if (effectMap.TryGetValue(effectType, out effect) == false)
            {
                //search for best match
                UInt32 bestType = 0;
                foreach (MaterialEffect e in effectMap.Values)
                {
                    UInt32 match = e.effectType & effectType;
                    if (match > bestType)
                    {
                        bestType = e.effectType;
                    }
                }

                if (effectMap.TryGetValue(bestType, out effect) == false)
                {
                    String err = String.Format("Cannot find effect type {0} in visualizer {1} for technique {2}", ((Material.Feature)effectType).ToString(), myType, technique);
                    Warn.print(err);
                    throw new Exception(err);
                }
            }

            return(effect);
        }
Ejemplo n.º 5
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)
        {
            SkyboxRenderable skyboxModel = r as SkyboxRenderable;
            MaterialEffect   effect      = getEffect(p.technique, (UInt32)Material.Feature.Skybox);
            PipelineState    pipeline    = effect.createPipeline(skyboxModel.model.mesh.material);

            RenderQueue <SkyboxRenderInfo> rq = p.findRenderQueue(pipeline.id) as RenderQueue <SkyboxRenderInfo>;

            if (rq == null)
            {
                rq      = Renderer.device.createRenderQueue <SkyboxRenderInfo>(effect.createPipeline(skyboxModel.model.mesh.material));
                rq.name = rq.myPipeline.shaderState.shaderProgram.name;
                rq.myPipeline.vaoState.vao = new VertexArrayObject();
                rq.myPipeline.vaoState.vao.bindVertexFormat(rq.myPipeline.shaderState.shaderProgram, V3.bindings());
                rq.visualizer = this;
                p.registerQueue(rq);
            }

            SkyboxRenderInfo info = rq.nextInfo();

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

            info.renderState.setUniformBuffer(p.view.camera.uniformBufferId(), 0);
        }