コード例 #1
0
        //public override void generateCommandsBegin(BaseRenderQueue q) { }

        public override void generateRenderCommand(RenderInfo r, BaseRenderQueue q)
        {
            StaticModelInfo smi = r as StaticModelInfo;

            q.addCommand(new SetRenderStateCommand(r.renderState));
            q.addCommand(new DrawIndexedCommand(PrimitiveType.Triangles, smi.indexCount, smi.indexOffset, DrawElementsType.UnsignedShort));
        }
コード例 #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)
        {
            StaticModelRenderable smr = r as StaticModelRenderable;

            StaticModelUniformData modelData = new StaticModelUniformData();

            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);
            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 <StaticModelInfo> rq = p.findRenderQueue(pipeline.id) as RenderQueue <StaticModelInfo>;
                if (rq == null)
                {
                    rq      = Renderer.device.createRenderQueue <StaticModelInfo>(pipeline);
                    rq.name = rq.myPipeline.shaderState.shaderProgram.name + "-" + (mesh.material.hasTransparency == true ? "transparent" : "opaque");
                    rq.myPipeline.vaoState.vao = new VertexArrayObject();
                    rq.myPipeline.vaoState.vao.bindVertexFormat <V3N3T2>(rq.myPipeline.shaderState.shaderProgram);
                    rq.visualizer = this;
                    p.registerQueue(rq);
                }

                StaticModelInfo info = rq.nextInfo();

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

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

                info.renderState.setUniform(new UniformData(0, Uniform.UniformType.Int, modelDataIndex));
                info.renderState.setStorageBuffer(myModelBuffer.id, 2);
                info.renderState.setVertexBuffer(smr.model.myVbo.id, 0, 0, V3N3T2.stride);
                info.renderState.setIndexBuffer(smr.model.myIbo.id);
                info.indexOffset = mesh.indexBase;
                info.indexCount  = mesh.indexCount;

                info.sortId = getSortId(info);
            }
        }
コード例 #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;
        }