Exemplo n.º 1
0
        public void Evaluate(int SpreadMax)
        {
            this.FInvalidate = false;
            if (this.FOutput[0] == null)
            {
                this.FOutput[0] = new DX11Resource <DX11VertexGeometry>();
            }

            if (this.FInApply[0] || this.FFirst)
            {
                this.FFirst = false;

                this.FInput.Validate();
                this.FInLayout.Sync();
                this.FInTopology.Sync();
                this.FInVerticesCount.Sync();

                this.FInvalidate = true;
                DX11Resource <DX11VertexGeometry> instance = this.FOutput[0];
                this.FOutput[0] = instance;

                this.inputlayout = new InputElement[this.FInLayout.SliceCount];
                this.vertexsize  = 0;
                for (int i = 0; i < this.FInLayout.SliceCount; i++)
                {
                    if (this.FInLayout.IsConnected && this.FInLayout[i] != null)
                    {
                        this.inputlayout[i] = this.FInLayout[i];
                    }
                    else
                    {
                        //Set deault, can do better here
                        this.inputlayout[i] = new InputElement("POSITION", 0, Format.R32G32B32A32_Float, 0);
                    }
                    this.vertexsize += FormatHelper.Instance.GetSize(this.inputlayout[i].Format);
                }
                InputLayoutFactory.AutoIndex(this.inputlayout);


                if (this.FStream != null)
                {
                    this.FStream.Dispose();
                }
                this.FStream = new DataStream(this.FInVerticesCount[0] * this.vertexsize, true, true);

                double *ptr;
                int     ptrcnt;
                this.FInput.GetValuePointer(out ptrcnt, out ptr);

                for (int i = 0; i < this.FInVerticesCount[0] * (this.vertexsize / 4); i++)
                {
                    this.FStream.Write((float)ptr[i % ptrcnt]);
                }

                DX11Resource <DX11VertexGeometry> v = this.FOutput[0];
                this.FOutput[0] = v;
            }
        }
Exemplo n.º 2
0
 public void Evaluate(int SpreadMax)
 {
     if (this.FInLayoutType.IsChanged || this.FInFormat.IsChanged)
     {
         this.FOutput.SliceCount = SpreadMax;
         int offset = 0;
         for (int i = 0; i < SpreadMax; i++)
         {
             Format fmt = (Format)Enum.Parse(typeof(Format), this.FInFormat[i].Name);
             this.FOutput[i] = InputLayoutFactory.GetInputElement(this.FInLayoutType[i], fmt, 0, offset);
             offset         += FormatHelper.Instance.GetSize(fmt);
         }
     }
 }
Exemplo n.º 3
0
        private InputElement[] BindInputLayout(out int vertexsize)
        {
            InputElement[] inputlayout = new InputElement[this.FInLayout.SliceCount];
            vertexsize = 0;
            for (int i = 0; i < this.FInLayout.SliceCount; i++)
            {
                if (this.FInLayout.PluginIO.IsConnected && this.FInLayout[i] != null)
                {
                    inputlayout[i] = this.FInLayout[i];
                }
                else
                {
                    //Set deault, can do better here
                    inputlayout[i] = new InputElement("POSITION", 0, Format.R32G32B32A32_Float, 0);
                }
                vertexsize += FormatHelper.Instance.GetSize(inputlayout[i].Format);
            }
            InputLayoutFactory.AutoIndex(inputlayout);

            return(inputlayout);
        }
Exemplo n.º 4
0
        public void Evaluate(int SpreadMax)
        {
            if (this.FInLayoutType.IsChanged || this.FInFormat.IsChanged || this.FAutoIndex.IsChanged)
            {
                this.FOutput.SliceCount = SpreadMax;
                int offset = 0;

                InputElement[] elements = new InputElement[SpreadMax];

                for (int i = 0; i < SpreadMax; i++)
                {
                    Format fmt = (Format)Enum.Parse(typeof(Format), this.FInFormat[i].Name);
                    elements[i] = InputLayoutFactory.GetInputElement(this.FInLayoutType[i], fmt, 0, offset);
                    offset     += FormatHelper.Instance.GetSize(fmt);
                }

                if (this.FAutoIndex[0])
                {
                    InputLayoutFactory.AutoIndex(elements);
                }

                this.FOutput.AssignFrom(elements);
            }
        }
        public void Evaluate(int SpreadMax)
        {
            this.FInvalidate = false;
            if (this.FOutput[0] == null)
            {
                this.FOutput[0] = new DX11Resource <DX11IndexedGeometry>();
            }

            if (this.FInApply[0] || FFirst)
            {
                this.FFirst = false;
                this.FInput.Sync();
                this.FInVerticesCount.Sync();
                this.FInIndices.Sync();
                this.FIndicesCount.Sync();
                this.FInLayout.Sync();
                this.FInTopology.Sync();

                this.FInvalidate = true;
                DX11Resource <DX11IndexedGeometry> instance = this.FOutput[0];
                this.FOutput[0] = instance;

                //Get Input Layout
                this.inputlayout = new InputElement[this.FInLayout.SliceCount];
                this.vertexsize  = 0;
                for (int i = 0; i < this.FInLayout.SliceCount; i++)
                {
                    if (this.FInLayout.PluginIO.IsConnected && this.FInLayout[i] != null)
                    {
                        this.inputlayout[i] = this.FInLayout[i];
                    }
                    else
                    {
                        //Set deault, can do better here
                        this.inputlayout[i] = new InputElement("POSITION", 0, Format.R32G32B32A32_Float, 0);
                    }
                    this.vertexsize += FormatHelper.Instance.GetSize(this.inputlayout[i].Format);
                }
                InputLayoutFactory.AutoIndex(this.inputlayout);

                //Load Vertex Stream
                if (this.FVertexStream != null)
                {
                    this.FVertexStream.Dispose();
                }

                this.FVertexStream = new DataStream(this.FInVerticesCount[0] * this.vertexsize, true, true);

                for (int i = 0; i < this.FInVerticesCount[0] * (this.vertexsize / 4); i++)
                {
                    this.FVertexStream.Write(this.FInput[i]);
                }
                this.FVertexStream.Position = 0;

                //Load index stream
                if (this.FIndexStream != null)
                {
                    this.FIndexStream.Dispose();
                }

                this.FIndexStream = new DataStream(this.FIndicesCount[0] * 4, true, true);
                for (int i = 0; i < this.FIndicesCount[0]; i++)
                {
                    this.FIndexStream.Write(this.FInIndices[i]);
                }
                this.FIndexStream.Position = 0;
            }
        }
Exemplo n.º 6
0
        public D3DShader(Device device, IShaderEffect shaderEffect, ShaderName shader)
        {
            this.device = device;
            this.shader = shader;

            try
            {
                vertexShaderByteCode = ShaderBytecode.CompileFromFile(shaderEffect.EffectShaderFileName, shaderEffect.VsFunctionName, shaderEffect.VsVersion.ToString());
            }
            catch (Exception ex)
            {
                throw new Exception("vertexShaderByteCode: " + ex);
            }
            try
            {
                pixelShaderByteCode = ShaderBytecode.CompileFromFile(shaderEffect.EffectShaderFileName, shaderEffect.PsFunctionName, shaderEffect.PsVersion.ToString());
            }
            catch (Exception ex)
            {
                throw new Exception("vertexShaderByteCode: " + ex);
            }

            try
            {
                vertexShader = new VertexShader(device, vertexShaderByteCode);
            }
            catch (Exception ex)
            {
                throw new Exception("vertexShader: " + ex);
            }

            try
            {
                pixelShader = new PixelShader(device, pixelShaderByteCode);
            }
            catch (Exception ex)
            {
                throw new Exception("pixelShader: " + ex);
            }

            // Now setup the layout of the data that goes into the shader.
            // It needs to match the VertexType structure in the Model and in the shader.
            InputElement[] inputElementDesc = InputLayoutFactory.Create(shaderEffect.VertexType);

            CreateInputLayout(inputElementDesc);

            vertexShaderByteCode.Dispose();
            pixelShaderByteCode.Dispose();

            constantMatrixBuffer = GetConstantMatrixBuffer <BufferTypes.WorldViewProj>(device);

            //is there any differnece between loading one shader wih multiple effects
            //and more shaders with only one effect?
            if (shader != ShaderName.Color)
            {
                LoadTextureShader();
            }

            //shader.GetPerObjectBufferType<DiffuseLightBufferType>

            if (shader == ShaderName.ParallaxMapping || shader == ShaderName.Diffuse || shader == ShaderName.Bumpmaping || shader == ShaderName.LightingEffect)
            {
                constantLightBuffer = GetConstantMatrixBuffer <BufferTypes.DiffuseLightBufferType>(device);
            }
            if (shader == ShaderName.Ambient)
            {
                constantLightBuffer = GetConstantMatrixBuffer <BufferTypes.AmbientLightBufferType>(device);
            }
            if (shader == ShaderName.Specular || shader == ShaderName.DirectionalLightingParallaxMapping)
            {
                constantLightBuffer = GetConstantMatrixBuffer <BufferTypes.SpecularLightBufferType>(device);
            }

            if (shader == ShaderName.ParallaxMapping || shader == ShaderName.Bumpmaping || shader == ShaderName.Specular || shader == ShaderName.ParallaxMapping || shader == ShaderName.DirectionalLightingParallaxMapping)
            {
                constantCameraBuffer = GetConstantMatrixBuffer <BufferTypes.CameraBufferType>(device);
            }
        }