static AcceleratedImagingKernel()
        {
            var vsSource =
                @"struct VS_INPUT{
					float3 pos : POSITION;
					float2 tex : TEXCOORD;
				};
				struct PS_INPUT{
					float4 pos : SV_POSITION;
					float2 tex : TEXCOORD;
				};

				PS_INPUT main(VS_INPUT input)
				{
					PS_INPUT output=(PS_INPUT)0;

					output.pos = float4(input.pos,0.5);
					output.tex = float2(1 - input.tex.y, input.tex.x);

					return output;
				}
				"                ;

            mVertexShaderBytecode = ShaderBytecode.Compile(vsSource, "main", "vs_5_0", ShaderFlags.None, EffectFlags.None);
        }
Exemple #2
0
		public virtual void Dispose()
		{
			if (m_Bytecode != null && m_Bytecode.Disposed == false)
			{
				m_Bytecode.Dispose();
				m_Bytecode = null;
			}
		}
Exemple #3
0
 private void InitEffect()
 {
     using (D3DComp.ShaderBytecode shaderBytecode = D3DComp.ShaderBytecode.CompileFromFile(
                "MyEffect.fx", "fx_5_0",
                D3DComp.ShaderFlags.None,
                D3DComp.EffectFlags.None
                ))
     {
         effect = new Dx11.Effect(GraphicsDevice, shaderBytecode);
     }
 }
        /// <summary>
        /// Loads an Effect from the resource.
        /// </summary>
        /// <param name="resource">Resource that references the FX file</param>
        /// <param name="parameters">Loader parameters</param>
        /// <returns>Compiled effect</returns>
        public override Effect Load(IResource resource, LoaderParameters parameters)
        {
            EffectInclude include = new EffectInclude(ContentManager, Path.GetDirectoryName(resource.FullName));

            D3DC.ShaderBytecode byteCode = D3DC.ShaderBytecode.CompileFromFile(resource.FullName, "fx_4_0", D3DC.ShaderFlags.None, D3DC.EffectFlags.None, null, include);
            byte[]        bytes          = new byte[byteCode.Data.Length];
            System.IntPtr ptr            = Tesla.Util.MemoryHelper.PinObject(bytes);
            Tesla.Util.MemoryHelper.Copy(byteCode.Data.DataPointer, ptr, bytes.Length);
            Tesla.Util.MemoryHelper.UnpinObject(bytes);
            byteCode.Dispose();

            Effect e = new Effect(bytes);

            e.Name = resource.Name;

            return(e);
        }
Exemple #5
0
        // Zavedenie zdrojov
        public void LoadResources(DX11.Device device)
        {
            Vertex[] vertices;
            short[]  indices;
            if (telesoObjektu.Equals("Ihlan"))
            {
                //Ihlan - pyramid
                vertices = new Vertex[]
                {
                    new Vertex(new Vector3(-1, -1, 1), Color.Red.ToArgb()),
                    new Vertex(new Vector3(1, -1, 1), Color.LightBlue.ToArgb()),
                    new Vertex(new Vector3(-1, -1, -1), Color.LightCyan.ToArgb()),
                    new Vertex(new Vector3(1, -1, -1), Color.CadetBlue.ToArgb()),
                    new Vertex(new Vector3(0, 2, 0), Color.Yellow.ToArgb()),
                };

                indices = new short[]
                {
                    //Podstava
                    0, 2, 1,
                    1, 2, 3,
                    //Steny
                    0, 1, 4,
                    1, 3, 4,
                    3, 2, 4,
                    2, 0, 4
                };
            }
            else
            {
                //Kocka - box
                vertices = new Vertex[]   //Matica 8 vrcholov
                {
                    new Vertex(new Vector3(-1, -1, -1), Color.Red.ToArgb()),
                    new Vertex(new Vector3(1, -1, -1), Color.LightBlue.ToArgb()),
                    new Vertex(new Vector3(1, -1, 1), Color.LightCyan.ToArgb()),
                    new Vertex(new Vector3(-1, -1, 1), Color.CadetBlue.ToArgb()),
                    new Vertex(new Vector3(-1, 1, -1), Color.Red.ToArgb()),
                    new Vertex(new Vector3(1, 1, -1), Color.Orange.ToArgb()),
                    new Vertex(new Vector3(1, 1, 1), Color.Goldenrod.ToArgb()),
                    new Vertex(new Vector3(-1, 1, 1), Color.Yellow.ToArgb())
                };

                indices = new short[] //Matica 36 indexov
                {
                    4, 1, 0, 4, 5, 1, //Stena 1 ...
                    5, 2, 1, 5, 6, 2,
                    6, 3, 2, 6, 7, 3,
                    7, 0, 3, 7, 4, 0,
                    7, 5, 4, 7, 6, 5,
                    2, 3, 0, 2, 0, 1
                };
            }



            DataStream outStream      = new DataStream(8 * Marshal.SizeOf(typeof(Vertex)), true, true); //Inicializácia objektu typu DataStream pre vertex buffer
            DataStream outStreamIndex = new DataStream(36 * Marshal.SizeOf(typeof(short)), true, true); //Index buffer

            for (int loop = 0; loop < vertices.Length; loop++)                                          //Načítanie hodnôt
            {
                outStream.Write <Vertex>(vertices[loop]);
            }

            for (int loop = 0; loop < indices.Length; loop++)     //Načítanie hodnôt
            {
                outStreamIndex.Write <short>(indices[loop]);
            }

            outStream.Position      = 0;   //Nastavenie polohy
            outStreamIndex.Position = 0;

            DX11.BufferDescription bufferDescription = new DX11.BufferDescription();
            bufferDescription.BindFlags      = DX11.BindFlags.VertexBuffer;
            bufferDescription.CpuAccessFlags = DX11.CpuAccessFlags.None;
            bufferDescription.OptionFlags    = DX11.ResourceOptionFlags.None;
            bufferDescription.SizeInBytes    = 8 * Marshal.SizeOf(typeof(Vertex));
            bufferDescription.Usage          = DX11.ResourceUsage.Default;

            DX11.BufferDescription bufferDescriptionIndex = new DX11.BufferDescription();
            bufferDescriptionIndex.BindFlags      = DX11.BindFlags.IndexBuffer;
            bufferDescriptionIndex.CpuAccessFlags = DX11.CpuAccessFlags.None;
            bufferDescriptionIndex.OptionFlags    = DX11.ResourceOptionFlags.None;
            bufferDescriptionIndex.SizeInBytes    = 36 * Marshal.SizeOf(typeof(short));
            bufferDescriptionIndex.Usage          = DX11.ResourceUsage.Default;

            m_vertexBuffer = new DX11.Buffer(device, outStream, bufferDescription);           //Inicializácia pre vertex buffer
            m_indexBuffer  = new DX11.Buffer(device, outStreamIndex, bufferDescriptionIndex); //Index buffer
            outStream.Close();
            outStreamIndex.Close();

            //Preloženie efektového súboru (HLSL) a priradenie objektu m_ShaderByteCode
            D3DCompiler.ShaderBytecode m_shaderByteCode =
                D3DCompiler.ShaderBytecode.CompileFromFile("Shader1.fx",
                                                           "fx_5_0",
                                                           D3DCompiler.ShaderFlags.None,
                                                           D3DCompiler.EffectFlags.None);

            m_effect            = new DX11.Effect(device, m_shaderByteCode);              //Objekt pre správu množiny stavovývh objektov, zdrojov a šejdrov pre implementáciu D3D renderovacieho efektu
            m_effectTechnique   = m_effect.GetTechniqueByIndex(0);                        //Získať techniku cez index
            m_effectPass        = m_effectTechnique.GetPassByIndex(0);                    //Získať prechod cez index
            m_transformVariable = m_effect.GetVariableByName("WorldViewProj").AsMatrix(); //Získanie premennej cez meno

            DX11.InputElement[] m_inputElements = new DX11.InputElement[]                 //Parameter pre metódu InputLayout
            {
                new DX11.InputElement("POSITION", 0, SlimDX.DXGI.Format.R32G32B32_Float, 0, 0),
                new DX11.InputElement("COLOR", 0, SlimDX.DXGI.Format.R8G8B8A8_UNorm, 12, 0)
            };
            m_vertexLayout = new DX11.InputLayout(device, m_effectPass.Description.Signature, m_inputElements); //Vytvorenie objektu pre opis vstupu pre "Input assembler stage"
        }