示例#1
0
 static Effect LoadResourceShader(D3DDevice device, string resourceName)
 {
     using (Stream stream = Application.ResourceAssembly.GetManifestResourceStream(resourceName))
     {
         return(device.CreateEffectFromCompiledBinary(stream));
     }
 }
        /// <summary>
        /// Creates the mesh manager
        /// </summary>
        /// <param name="device"></param>
        public XMeshManager(D3DDevice device)
        {
            this.device = device;

            // Create the effect
            //XMesh.fxo was compiled from XMesh.fx using:
            // "$(DXSDK_DIR)utilities\bin\x86\fxc" "$(ProjectDir)Mesh\MeshLoaders\XMesh.fx" /T fx_4_0 /Fo"$(ProjectDir)Mesh\MeshLoaders\XMesh.fxo"
            using (Stream effectStream = Assembly.GetExecutingAssembly().GetManifestResourceStream(
                       "Microsoft.WindowsAPICodePack.DirectX.DirectXUtilities.XMesh.fxo"))
            {
                effect = device.CreateEffectFromCompiledBinary(new BinaryReader(effectStream));
            }

            // Obtain the techniques
            techniqueRenderTexture       = effect.GetTechniqueByName("RenderTextured");
            techniqueRenderVertexColor   = effect.GetTechniqueByName("RenderVertexColor");
            techniqueRenderMaterialColor = effect.GetTechniqueByName("RenderMaterialColor");

            // Obtain the variables
            brightnessVariable    = effect.GetVariableByName("Brightness").AsScalar;
            materialColorVariable = effect.GetVariableByName("MaterialColor").AsVector;
            worldVariable         = effect.GetVariableByName("World").AsMatrix;
            viewVariable          = effect.GetVariableByName("View").AsMatrix;
            projectionVariable    = effect.GetVariableByName("Projection").AsMatrix;
            diffuseVariable       = effect.GetVariableByName("tex2D").AsShaderResource;
        }
        /// <summary>
        /// Create Direct3D device and swap chain
        /// </summary>
        protected void InitDevice()
        {
            device    = D3DDevice.CreateDeviceAndSwapChain(directControl.Handle);
            swapChain = device.SwapChain;

            SetViews();

            // Create the effect
            using (FileStream effectStream = File.OpenRead("Tutorial04.fxo"))
            {
                effect = device.CreateEffectFromCompiledBinary(new BinaryReader(effectStream));
            }

            // Obtain the technique
            technique = effect.GetTechniqueByName("Render");

            // Obtain the variables
            worldVariable      = effect.GetVariableByName("World").AsMatrix;
            viewVariable       = effect.GetVariableByName("View").AsMatrix;
            projectionVariable = effect.GetVariableByName("Projection").AsMatrix;

            InitVertexLayout();
            InitVertexBuffer();
            InitIndexBuffer();

            // Set primitive topology
            device.IA.PrimitiveTopology = PrimitiveTopology.TriangleList;

            InitMatrices();
            needsResizing = false;
        }
        /// <summary>
        /// Create Direct3D device and swap chain
        /// </summary>
        protected void InitDevice()
        {
            device    = D3DDevice1.CreateDeviceAndSwapChain1(host.Handle);
            swapChain = device.SwapChain;

            SetViews();

            // Create the effect
            using (FileStream effectStream = File.OpenRead("Tutorial07.fxo"))
            {
                effect = device.CreateEffectFromCompiledBinary(new BinaryReader(effectStream));
            }

            // Obtain the technique
            technique = effect.GetTechniqueByName("Render");

            // Obtain the variables
            worldVariable      = effect.GetVariableByName("World").AsMatrix;
            viewVariable       = effect.GetVariableByName("View").AsMatrix;
            projectionVariable = effect.GetVariableByName("Projection").AsMatrix;
            meshColorVariable  = effect.GetVariableByName("vMeshColor").AsVector;
            diffuseVariable    = effect.GetVariableByName("txDiffuse").AsShaderResource;

            InitVertexLayout();
            InitVertexBuffer();
            InitIndexBuffer();

            // Set primitive topology
            device.IA.PrimitiveTopology = PrimitiveTopology.TriangleList;

            // Load the Texture
            using (FileStream stream = File.OpenRead("seafloor.png"))
            {
                textureRV = TextureLoader.LoadTexture(device, stream);
            }

            InitMatrices();

            diffuseVariable.Resource = textureRV;
            needsResizing            = false;
        }
示例#5
0
        public Effects(D3DDevice device)
        {
            // File compiled using the following command:
            // "$(DXSDK_DIR)\utilities\bin\x86\fxc" "WindowsFlag.fx" /T fx_4_0 /Fo "WindowsFlag.fxo"
            using (Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream("WindowsFlag.WindowsFlag.fxo"))
            {
                effect = device.CreateEffectFromCompiledBinary(stream);
            }
            // Obtain the technique
            technique = effect.GetTechniqueByName("Render");

            // Obtain the variables
            worldVariable      = effect.GetVariableByName("World").AsMatrix;
            viewVariable       = effect.GetVariableByName("View").AsMatrix;
            projectionVariable = effect.GetVariableByName("Projection").AsMatrix;

            lightDirVariable   = effect.GetVariableByName("vLightDir").AsVector;
            lightColorVariable = effect.GetVariableByName("vLightColor").AsVector;
            baseColorVariable  = effect.GetVariableByName("vBaseColor").AsVector;

            // Set constants
            lightColorVariable.SetFloatVectorArray(vLightColors);
            lightDirVariable.SetFloatVectorArray(vLightDirs);
        }
示例#6
0
        /// <summary>
        /// Create Direct3D device and swap chain
        /// </summary>
        protected void InitDevice()
        {
            device = D3DDevice.CreateDeviceAndSwapChain(this.Handle, out swapChain);

            SetViews();

            // Create the effect
            using (FileStream effectStream = File.OpenRead("Tutorial07.fxo"))
            {
                effect = device.CreateEffectFromCompiledBinary(new BinaryReader(effectStream));
            }

            // Obtain the technique
            technique = effect.GetTechniqueByName( "Render" );

            // Obtain the variables
            worldVariable = effect.GetVariableByName( "World" ).AsMatrix();
            viewVariable = effect.GetVariableByName( "View" ).AsMatrix();
            projectionVariable = effect.GetVariableByName( "Projection" ).AsMatrix();
            meshColorVariable = effect.GetVariableByName( "vMeshColor" ).AsVector();
            diffuseVariable = effect.GetVariableByName( "txDiffuse" ).AsShaderResource();

            InitVertexLayout();
            InitVertexBuffer();
            InitIndexBuffer();

            // Set primitive topology
            device.IA.SetPrimitiveTopology(PrimitiveTopology.TriangleList);

            // Load the Texture
            using (FileStream stream = File.OpenRead("seafloor.png"))
            {
                textureRV = TextureLoader.LoadTexture(device, stream);
            }

            InitMatrices();

            diffuseVariable.SetResource(textureRV);
            active = true;
        }
示例#7
0
 static Effect LoadResourceShader(D3DDevice device, string resourceName)
 {
     using (Stream stream = Application.ResourceAssembly.GetManifestResourceStream(resourceName))
     {
         return device.CreateEffectFromCompiledBinary(stream);
     }
 }
示例#8
0
        /// <summary>
        /// Create Direct3D device and swap chain
        /// </summary>
        protected void InitDevice()
        {
            device = D3DDevice.CreateDeviceAndSwapChain(directControl.Handle, out swapChain);

            SetViews();

            // Create the effect
            using (FileStream effectStream = File.OpenRead("Tutorial02.fxo"))
            {
                effect = device.CreateEffectFromCompiledBinary(new BinaryReader(effectStream));
            }

            // Obtain the technique
            technique = effect.GetTechniqueByName("Render");

            // Define the input layout
            InputElementDescription[] layout = 
            {
                new InputElementDescription()
                {
                    SemanticName = "POSITION",
                    SemanticIndex = 0,
                    Format = Format.R32G32B32_FLOAT,
                    InputSlot = 0,
                    AlignedByteOffset = 0,
                    InputSlotClass = InputClassification.PerVertexData,
                    InstanceDataStepRate = 0
                }
            };

            PassDescription passDesc = technique.GetPassByIndex(0).Description;

            vertexLayout = device.CreateInputLayout(
                layout,
                passDesc.InputAssemblerInputSignature,
                passDesc.InputAssemblerInputSignatureSize);

            device.IA.SetInputLayout(vertexLayout);

            SimpleVertexArray vertex = new SimpleVertexArray();

            BufferDescription bd = new BufferDescription()
            {
                Usage = Usage.Default,
                ByteWidth = (uint)Marshal.SizeOf(vertex),
                BindFlags = BindFlag.VertexBuffer,
                CpuAccessFlags = 0,
                MiscFlags = 0
            };

            IntPtr vertexData = Marshal.AllocCoTaskMem(Marshal.SizeOf(vertex));
            Marshal.StructureToPtr(vertex, vertexData, false);

            SubresourceData InitData = new SubresourceData()
            {
                SysMem = vertexData,
                SysMemPitch = 0,
                SysMemSlicePitch = 0
            };

            //D3DBuffer buffer = null;
            vertexBuffer = device.CreateBuffer(bd, InitData);

            // Set vertex buffer
            uint stride = (uint)Marshal.SizeOf(typeof(Vector3F));
            uint offset = 0;
            device.IA.SetVertexBuffers(0, new Collection<D3DBuffer>()
                {
                    vertexBuffer
                },
                new uint[] { stride }, new uint[] { offset });

            // Set primitive topology
            device.IA.SetPrimitiveTopology(PrimitiveTopology.TriangleList);
            Marshal.FreeCoTaskMem(vertexData);
        }
示例#9
0
        public Effects(D3DDevice device)
        {
            // File compiled using the following command:
            // "$(DXSDK_DIR)\utilities\bin\x86\fxc" "WindowsFlag.fx" /T fx_4_0 /Fo "WindowsFlag.fxo"
            using (Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream("WindowsFlag.WindowsFlag.fxo"))
            {
                effect = device.CreateEffectFromCompiledBinary(stream);
            }
            // Obtain the technique
            technique = effect.GetTechniqueByName("Render");

            // Obtain the variables
            worldVariable = effect.GetVariableByName("World").AsMatrix();
            viewVariable = effect.GetVariableByName("View").AsMatrix();
            projectionVariable = effect.GetVariableByName("Projection").AsMatrix();

            lightDirVariable = effect.GetVariableByName("vLightDir").AsVector();
            lightColorVariable = effect.GetVariableByName("vLightColor").AsVector();
            baseColorVariable = effect.GetVariableByName("vBaseColor").AsVector();

            // Set constants
            lightColorVariable.SetFloatVectorArray(vLightColors);
            lightDirVariable.SetFloatVectorArray(vLightDirs);
        }
示例#10
0
        /// <summary>
        /// Create Direct3D device and swap chain
        /// </summary>
        protected void InitDevice()
        {
            device = D3DDevice.CreateDeviceAndSwapChain(directControl.Handle, out swapChain);

            SetViews();

            // Create the effect
            using (FileStream effectStream = File.OpenRead("Tutorial04.fxo"))
            {
                effect = device.CreateEffectFromCompiledBinary(new BinaryReader(effectStream));
            }

            // Obtain the technique
            technique = effect.GetTechniqueByName("Render");

            // Obtain the variables
            worldVariable = effect.GetVariableByName("World").AsMatrix();
            viewVariable = effect.GetVariableByName("View").AsMatrix();
            projectionVariable = effect.GetVariableByName("Projection").AsMatrix();

            InitVertexLayout();
            InitVertexBuffer();
            InitIndexBuffer();

            // Set primitive topology
            device.IA.SetPrimitiveTopology(PrimitiveTopology.TriangleList);

            InitMatrices();
            needsResizing = false;
        }
        /// <summary>
        /// Create Direct3D device and swap chain
        /// </summary>
        protected void InitDevice()
        {
            device = D3DDevice.CreateDeviceAndSwapChain(directControl.Handle);
            swapChain = device.SwapChain;

            SetViews();

            // Create the effect
            using (FileStream effectStream = File.OpenRead("Tutorial06.fxo"))
            {
                effect = device.CreateEffectFromCompiledBinary(new BinaryReader(effectStream));
            }

            // Obtain the technique
            technique = effect.GetTechniqueByName("Render");
            techniqueLight = effect.GetTechniqueByName("RenderLight");

            // Obtain the variables
            worldVariable = effect.GetVariableByName("World").AsMatrix;
            viewVariable = effect.GetVariableByName("View").AsMatrix;
            projectionVariable = effect.GetVariableByName("Projection").AsMatrix;

            lightDirVariable = effect.GetVariableByName("vLightDir").AsVector;
            lightColorVariable = effect.GetVariableByName("vLightColor").AsVector;
            outputColorVariable = effect.GetVariableByName("vOutputColor").AsVector;

            InitVertexLayout();
            InitVertexBuffer();
            InitIndexBuffer();

            // Set primitive topology
            device.IA.PrimitiveTopology = PrimitiveTopology.TriangleList;

            InitMatrices();
        }
示例#12
0
        /// <summary>
        /// Create Direct3D device and swap chain
        /// </summary>
        protected void InitDevice()
        {
            device    = D3DDevice.CreateDeviceAndSwapChain(directControl.Handle);
            swapChain = device.SwapChain;

            SetViews();

            // Create the effect
            using (FileStream effectStream = File.OpenRead("Tutorial02.fxo"))
            {
                effect = device.CreateEffectFromCompiledBinary(new BinaryReader(effectStream));
            }

            // Obtain the technique
            technique = effect.GetTechniqueByName("Render");

            // Define the input layout
            InputElementDescription[] layout =
            {
                new InputElementDescription()
                {
                    SemanticName         = "POSITION",
                    SemanticIndex        = 0,
                    Format               = Format.R32G32B32Float,
                    InputSlot            = 0,
                    AlignedByteOffset    = 0,
                    InputSlotClass       = InputClassification.PerVertexData,
                    InstanceDataStepRate = 0
                }
            };

            PassDescription passDesc = technique.GetPassByIndex(0).Description;

            vertexLayout = device.CreateInputLayout(
                layout,
                passDesc.InputAssemblerInputSignature,
                passDesc.InputAssemblerInputSignatureSize);

            device.IA.InputLayout = vertexLayout;

            SimpleVertexArray vertex = new SimpleVertexArray();

            BufferDescription bd = new BufferDescription()
            {
                Usage                        = Usage.Default,
                ByteWidth                    = (uint)Marshal.SizeOf(vertex),
                BindingOptions               = BindingOptions.VertexBuffer,
                CpuAccessOptions             = CpuAccessOptions.None,
                MiscellaneousResourceOptions = MiscellaneousResourceOptions.None
            };

            IntPtr vertexData = Marshal.AllocCoTaskMem(Marshal.SizeOf(vertex));

            Marshal.StructureToPtr(vertex, vertexData, false);

            SubresourceData InitData = new SubresourceData()
            {
                SystemMemory           = vertexData,
                SystemMemoryPitch      = 0,
                SystemMemorySlicePitch = 0
            };

            //D3DBuffer buffer = null;
            vertexBuffer = device.CreateBuffer(bd, InitData);

            // Set vertex buffer
            uint stride = (uint)Marshal.SizeOf(typeof(Vector3F));
            uint offset = 0;

            device.IA.SetVertexBuffers(0, new Collection <D3DBuffer>()
            {
                vertexBuffer
            },
                                       new uint[] { stride }, new uint[] { offset });

            // Set primitive topology
            device.IA.PrimitiveTopology = PrimitiveTopology.TriangleList;
            Marshal.FreeCoTaskMem(vertexData);
        }