当前位置: 首页>>代码示例>>C#>>正文


C# Effect.GetVariableByName方法代码示例

本文整理汇总了C#中Effect.GetVariableByName方法的典型用法代码示例。如果您正苦于以下问题:C# Effect.GetVariableByName方法的具体用法?C# Effect.GetVariableByName怎么用?C# Effect.GetVariableByName使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Effect的用法示例。


在下文中一共展示了Effect.GetVariableByName方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: RenderModel

        void RenderModel(Graphics.Content.Model10 model, SlimDX.Matrix entityWorld, Effect effect)
        {
            throw new NotImplementedException();
            //if (model == null || !model.Visible || model.Mesh == null) return;

            Matrix world = model.World * entityWorld;
            world.M41 = (float)((int)world.M41);
            world.M42 = (float)((int)world.M42);
            world *= Matrix.Scaling(2f / (float)view.Viewport.Width, 2f / (float)view.Viewport.Height, 1) * Matrix.Translation(-1, -1, 0) * Matrix.Scaling(1, -1, 1);
            world.M43 = 0.5f;

            effect.GetVariableByName("World").AsMatrix().SetMatrix(world);
            effect.GetVariableByName("Texture").AsResource().SetResource(model.TextureShaderView);

            effect.GetTechniqueByName("Render").GetPassByIndex(0).Apply();
            if (model.Mesh != null)
            {
                model.Mesh.Setup(view.Device10, view.Content.Acquire<InputLayout>(
                    new Content.VertexStreamLayoutFromEffect
                {
                    Signature10 = effect.GetTechniqueByIndex(0).GetPassByIndex(0).Description.Signature,
                    Layout = model.Mesh.VertexStreamLayout
                }));

                model.Mesh.Draw(device);
            }
        }
开发者ID:ChristianMarchiori,项目名称:DeadMeetsLead,代码行数:27,代码来源:InterfaceRenderer10.cs

示例2: LoadResources

		public override void LoadResources()
		{
			if (m_Disposed == true)
			{
				m_Effect = m_Effect = new Effect(GameEnvironment.Device, Bytecode); // Effect.FromFile(GameEnvironment.Device, Helper.ResolvePath(m_ShaderLocation), "fx_4_0", ShaderFlags.None, EffectFlags.None, null, null);
				m_Technique = m_Effect.GetTechniqueByName("Imposter");

				m_Pass_NoBlend = m_Technique.GetPassByName("NoBlend");
				m_Pass_OverlayAdd = m_Technique.GetPassByName("OverlayAdd");
				m_Pass_OverlaySubtract = m_Technique.GetPassByName("OverlaySubtract");
				m_Pass_OverlayInvert = m_Technique.GetPassByName("OverlayInvert");
				m_Pass_OverlayAlpha = m_Technique.GetPassByName("OverlayAlpha");

				m_Technique_BrightPass = m_Effect.GetTechniqueByName("Imposter_BrightPass");

				m_Pass_NoBlend_BrightPass = m_Technique_BrightPass.GetPassByName("NoBlend");
				m_Pass_OverlayAdd_BrightPass = m_Technique_BrightPass.GetPassByName("OverlayAdd");
				m_Pass_OverlaySubtract_BrightPass = m_Technique_BrightPass.GetPassByName("OverlaySubtract");
				m_Pass_OverlayAlpha_BrightPass = m_Technique_BrightPass.GetPassByName("OverlayAlpha");

				m_ImposterTextureResource = m_Effect.GetVariableByName("imposter").AsResource();

				m_BrightPassThreshold = m_Effect.GetVariableByName("brightPassThreshold").AsScalar();

				m_Layout = new InputLayout(GameEnvironment.Device, m_Pass_NoBlend.Description.Signature, new[] {
					new InputElement("POSITION", 0, Format.R32G32_Float, 0, 0),
					new InputElement("TEXCOORD", 0, Format.R32G32_Float, 8, 0)		
				});

				float minX = -1f, miny = -1f, maxX = 1f, maxY = 1f;

				using (DataStream stream = new DataStream(4 * Marshal.SizeOf(typeof(Vertex2D)), true, true))
				{
					stream.WriteRange(new Vertex2D[] {					
						new Vertex2D() { Position = new Vector2(maxX, miny), TextureCoords =  new Vector2(1.0f, 1.0f) }, 
						new Vertex2D() { Position = new Vector2(minX, miny), TextureCoords =  new Vector2(0.0f, 1.0f) }, 
						new Vertex2D() { Position = new Vector2(maxX, maxY), TextureCoords = new Vector2(1.0f, 0.0f) },  
						new Vertex2D() { Position = new Vector2(minX, maxY), TextureCoords =  new Vector2(0.0f, 0.0f) } 
					});
					stream.Position = 0;

					m_Vertices = new SlimDX.Direct3D11.Buffer(GameEnvironment.Device, stream, new BufferDescription()
					{
						BindFlags = BindFlags.VertexBuffer,
						CpuAccessFlags = CpuAccessFlags.None,
						OptionFlags = ResourceOptionFlags.None,
						SizeInBytes = 4 * Marshal.SizeOf(typeof(Vertex2D)),
						Usage = ResourceUsage.Default
					});
				}

				m_VerticesBindings = new VertexBufferBinding(m_Vertices, Marshal.SizeOf(typeof(Vertex2D)), 0);

				m_Disposed = false;
			}
		}
开发者ID:RugCode,项目名称:drg-pt,代码行数:56,代码来源:ImposterFloatEffect.cs

示例3: RenderContext

        public RenderContext(IRenderHost canvas, Effect effect)
        {
            this.Canvas = canvas;
            this.IsShadowPass = false;
            this.IsDeferredPass = false;

            this.mView = effect.GetVariableByName("mView").AsMatrix();
            this.mProjection = effect.GetVariableByName("mProjection").AsMatrix();
            this.vViewport = effect.GetVariableByName("vViewport").AsVector();
            this.vFrustum = effect.GetVariableByName("vFrustum").AsVector();
            this.vEyePos = effect.GetVariableByName("vEyePos").AsVector();                     
        }
开发者ID:dermeister0,项目名称:helix-toolkit,代码行数:12,代码来源:RenderContext.cs

示例4: LoadResources

		public override void LoadResources()
		{
			if (m_Disposed == true)
			{
				m_Effect = m_Effect = new Effect(GameEnvironment.Device, Bytecode); // Effect.FromFile(GameEnvironment.Device, Helper.ResolvePath(m_ShaderLocation), "fx_4_0", ShaderFlags.None, EffectFlags.None, null, null);
				m_Technique = m_Effect.GetTechniqueByName("RenderParticles");
				m_ParticlePass_Add = m_Technique.GetPassByName("Add");

				m_Layout = new InputLayout(GameEnvironment.Device, m_ParticlePass_Add.Description.Signature, new[] {
					new InputElement("POSITION", 0, Format.R32G32B32A32_Float, 0, 0),
					new InputElement("TEXCOORD", 0, Format.R32G32_Float, 16, 0),				
					new InputElement("INST_POSITION", 0, Format.R32G32B32_Float, 0, 1, InputClassification.PerInstanceData, 1),
					new InputElement("INST_COLOR", 0, Format.R32G32B32A32_Float, 12, 1, InputClassification.PerInstanceData, 1), 					
				});

				m_WorldViewProj = m_Effect.GetVariableByName("worldViewProj").AsMatrix();
				m_ParticleTexture = m_Effect.GetVariableByName("particle_texture").AsResource();
				m_AmpScale = m_Effect.GetVariableByName("ampScale").AsScalar();
				m_PartScaleX = m_Effect.GetVariableByName("partScaleX").AsScalar();
				m_PartScaleY = m_Effect.GetVariableByName("partScaleY").AsScalar(); 
				m_MaxDistance = m_Effect.GetVariableByName("maxDistance").AsScalar();
				m_MinDistance = m_Effect.GetVariableByName("minDistance").AsScalar();
				m_ScaleDistance = m_Effect.GetVariableByName("scaleDistance").AsScalar();

				m_Disposed = false;
			}
		}
开发者ID:RugCode,项目名称:drg-pt,代码行数:27,代码来源:ParticleEffect.cs

示例5: LoadResources

		public override void LoadResources()
		{
			if (m_Disposed == true)
			{
				m_Effect = new Effect(GameEnvironment.Device, Bytecode); // Helper.ResolvePath(m_ShaderLocation), "fx_4_0", ShaderFlags.None, EffectFlags.None, null, null);
				m_Technique = m_Effect.GetTechniqueByName("BlurBilinear");

				m_Pass_Gaussian = m_Technique.GetPassByName("Gaussian");

				m_SourceTex = m_Effect.GetVariableByName("g_SourceTex").AsResource();
				m_GWeights = m_Effect.GetVariableByName("g_GWeights").AsScalar();

				//m_ElementCount = 1 + GAUSSIAN_MAX_SAMPLES;
				m_DataStride = Marshal.SizeOf(typeof(Vector2)) * (1 + GAUSSIAN_MAX_SAMPLES);

				InputElement[] IADesc = new InputElement[1 + (GAUSSIAN_MAX_SAMPLES / 2)];

				IADesc[0] = new InputElement()
				{
					SemanticName = "POSITION",
					SemanticIndex = 0,
					AlignedByteOffset = 0,
					Slot = 0,
					Classification = InputClassification.PerVertexData,
					Format = Format.R32G32_Float
				};


				for (int i = 1; i < 1 + (GAUSSIAN_MAX_SAMPLES / 2); i++)
				{
					IADesc[i] = new InputElement()
					{
						SemanticName = "TEXCOORD",
						SemanticIndex = i - 1,
						AlignedByteOffset = 8 + (i - 1) * 16,
						Slot = 0,
						Classification = InputClassification.PerVertexData,
						Format = Format.R32G32B32A32_Float
					};
				}

				// Real number of "sematinc based" elements
				//m_ElementCount = 1 + GAUSSIAN_MAX_SAMPLES / 2;

				EffectPassDescription PassDesc = m_Pass_Gaussian.Description;
				m_Layout = new InputLayout(GameEnvironment.Device, PassDesc.Signature, IADesc);

				m_Disposed = false;
			}
		}
开发者ID:RugCode,项目名称:drg-pt,代码行数:50,代码来源:BloomEffect.cs

示例6: Draw

        internal override void Draw(SlimDX.Direct3D11.DeviceContext context)
        {
            Effect effect;
            using (ShaderBytecode byteCode = ShaderBytecode.CompileFromFile("Graphics/Effects/default.fx", "bidon", "fx_5_0", ShaderFlags.OptimizationLevel3, EffectFlags.None))
            {
                effect = new Effect(context.Device, byteCode);
            }
            var technique = effect.GetTechniqueByIndex(1);
            var pass = technique.GetPassByIndex(0);
            InputLayout inputLayout = new InputLayout(context.Device, pass.Description.Signature, new[] {
                new InputElement("POSITION", 0, SlimDX.DXGI.Format.R32G32B32_Float, 0),
                new InputElement("COLOR", 0, SlimDX.DXGI.Format.R8G8B8A8_UNorm, InputElement.AppendAligned, 0)
            });

            DataStream vertices = new DataStream((Vector3.SizeInBytes + 4) * 6, true, true);
            vertices.Write(new ColoredVertex(new Vector3(1.0f, 1.0f, 0.0f), new Color4(1.0f, 0.0f, 0.0f, 0.0f).ToArgb()));
            vertices.Write(new ColoredVertex(new Vector3(-1.0f, 1.0f, 0.0f), new Color4(1.0f, 0.0f, 0.0f, 0.0f).ToArgb()));
            vertices.Write(new ColoredVertex(new Vector3(-1.0f, -1.0f, 0.0f), new Color4(1.0f, 0.0f, 0.0f, 0.0f).ToArgb()));
            vertices.Write(new ColoredVertex(new Vector3(-1.0f, -1.0f, 0.0f), new Color4(1.0f, 0.0f, 0.0f, 0.0f).ToArgb()));
            vertices.Write(new ColoredVertex(new Vector3(1.0f, 1.0f, 0.0f), new Color4(1.0f, 0.0f, 0.0f, 0.0f).ToArgb()));
            vertices.Write(new ColoredVertex(new Vector3(1.0f, -1.0f, 0.0f), new Color4(1.0f, 0.0f, 0.0f, 0.0f).ToArgb()));

            vertices.Position = 0;
            BufferDescription bd = new BufferDescription()
            {
                Usage = ResourceUsage.Default,
                SizeInBytes = 16 * 6,
                BindFlags = BindFlags.VertexBuffer,
                CpuAccessFlags = CpuAccessFlags.None
            };

            var vertexBuffer = new SlimDX.Direct3D11.Buffer(context.Device, vertices, bd);

            context.InputAssembler.SetVertexBuffers(0, new VertexBufferBinding(vertexBuffer, 16, 0));
            //context.InputAssembler.SetIndexBuffer(indices, Format.R16_UInt, 0);

            /* scale * rotation * translation */
            Matrix worldMatrix = Matrix.Scaling(Scale) * Matrix.RotationYawPitchRoll(Rotation.Y, Rotation.X, Rotation.Z) * Matrix.Translation(Position);

            Matrix viewMatrix = Camera.ViewMatrix;

            Matrix projectionMatrix = Camera.ProjectionMatrix;

            effect.GetVariableByName("finalMatrix").AsMatrix().SetMatrix(worldMatrix * viewMatrix * projectionMatrix);

            context.InputAssembler.InputLayout = inputLayout;
            context.InputAssembler.PrimitiveTopology = PrimitiveTopology.TriangleStrip;

            pass.Apply(context);
            context.Draw(6, 0);
        }
开发者ID:eldernos,项目名称:SlimDXEngine,代码行数:51,代码来源:Rectangle.cs

示例7: LoadResources

		public override void LoadResources()
		{
			if (m_Disposed == true)
			{
				m_Effect = m_Effect = new Effect(GameEnvironment.Device, Bytecode); // Effect.FromFile(GameEnvironment.Device, Helper.ResolvePath(m_ShaderLocation), "fx_4_0", ShaderFlags.Debug | ShaderFlags.EnableStrictness, EffectFlags.None, null, null);
				m_Technique = m_Effect.GetTechniqueByName("Render");
				m_Pass0 = m_Technique.GetPassByName("P0");

				/*m_Layout = new InputLayout(GameEnvironment.Device, m_Pass0.Description.Signature, new[] {
					new InputElement( "POSITION", 0, Format.R32G32B32_Float, 0, 0, InputClassification.PerVertexData, 0),
					new InputElement( "NORMAL", 0, Format.R32G32B32_Float, 0, 12, InputClassification.PerVertexData, 0),
					new InputElement( "TEXCOORD", 0, Format.R32G32_Float, 0, 24, InputClassification.PerVertexData, 0),
				});*/

				m_Layout = new InputLayout(GameEnvironment.Device, m_Pass0.Description.Signature, new[] {
					new InputElement("POSITION", 0, Format.R32G32B32_Float, 0, 0),
					new InputElement("NORMAL", 0, Format.R32G32B32_Float, 12, 0),
					new InputElement("TEXCOORD", 0, Format.R32G32_Float, 24, 0)
				});

				//texColorMap
				//texNormalMap
				//texDiffuseMap
				//texSpecularMap

				//m_DiffuseVariable = m_Effect.GetVariableByName("g_txDiffuse").AsResource();
				m_DiffuseVariable = m_Effect.GetVariableByName("texColorMap").AsResource();
				m_NormalMapVariable = m_Effect.GetVariableByName("texNormalMap").AsResource();
				m_WorldVariable = m_Effect.GetVariableByName("World").AsMatrix();
				m_ViewVariable = m_Effect.GetVariableByName("View").AsMatrix();
				m_InvViewVariable = m_Effect.GetVariableByName("InvView").AsMatrix();
				m_ProjectionVariable = m_Effect.GetVariableByName("Projection").AsMatrix();
				//m_SpecularMapVariable = m_Effect.GetVariableByName("g_txEnvMap").AsResource();
				m_SpecularMapVariable = m_Effect.GetVariableByName("texSpecularMap").AsResource();
				m_DiffuseMapVariable = m_Effect.GetVariableByName("texDiffuseMap").AsResource();
				m_EyeVariable = m_Effect.GetVariableByName("Eye").AsVector();

				m_Disposed = false;
			}
		}
开发者ID:RugCode,项目名称:drg-pt,代码行数:40,代码来源:MaterialEffect.cs

示例8: TestEffect

        /// <summary>
        /// Create our test RenderEffect.
        /// </summary>
        /// <param name="Device"></param>
        public TestEffect(Device Device)
        {
            this.Device = Device;
            ImmediateContext = Device.ImmediateContext;

            // Compile our shader...
            string compileErrors;
            var compiledShader = SlimDX.D3DCompiler.ShaderBytecode.CompileFromFile
            (
                "../../Effects/TestEffect/TestEffect.fx",
                null,
                "fx_5_0",
                SlimDX.D3DCompiler.ShaderFlags.None,
                SlimDX.D3DCompiler.EffectFlags.None,
                null,
                null,
                out compileErrors
            );

            if (compileErrors != null && compileErrors != "")
            {
                throw new EffectBuildException(compileErrors);
            }

            Effect = new Effect(Device, compiledShader);
            EffectTechnique = Effect.GetTechniqueByName("TestTechnique");

            var vertexDesc = new[]
            {
                new InputElement("POSITION", 0, SlimDX.DXGI.Format.R32G32B32_Float, 0, 0, InputClassification.PerVertexData, 0),
                new InputElement("COLOR", 0, SlimDX.DXGI.Format.R32G32B32A32_Float, 12, 0, InputClassification.PerVertexData, 0)
            };

            WorldViewProj = SlimDX.Matrix.Identity;
            CPO_WorldViewProj = Effect.GetVariableByName("gWorldViewProj").AsMatrix();
            InputLayout = new InputLayout(Device, EffectTechnique.GetPassByIndex(0).Description.Signature, vertexDesc);

            Util.ReleaseCom(ref compiledShader);
        }
开发者ID:sessamekesh,项目名称:OutsideSimulator,代码行数:43,代码来源:TestEffect.cs

示例9: BindPassIterIndexSemantic

 private void BindPassIterIndexSemantic(Effect effect, int passiterindex)
 {
     foreach (EffectScalarVariable erv in this.varmanager.passiterindex)
     {
         effect.GetVariableByName(erv.Description.Name).AsScalar().Set(passiterindex);
     }
 }
开发者ID:antokhio,项目名称:dx11-vvvv,代码行数:7,代码来源:DX11ImageShaderNode.cs

示例10: Main

        private static void Main()
        {
            // Device creation
            var form = new RenderForm("Stereo test")
                           {
                               ClientSize = size,
                               //FormBorderStyle = System.Windows.Forms.FormBorderStyle.None,
                               //WindowState = FormWindowState.Maximized
                           };

            form.KeyDown += new KeyEventHandler(form_KeyDown);
               // form.Resize += new EventHandler(form_Resize);

            ModeDescription mDesc = new ModeDescription(form.ClientSize.Width, form.ClientSize.Height,
                                                        new Rational(120000, 1000), Format.R8G8B8A8_UNorm);
            mDesc.ScanlineOrdering = DisplayModeScanlineOrdering.Progressive;
            mDesc.Scaling = DisplayModeScaling.Unspecified;

            var desc = new SwapChainDescription()
                           {
                               BufferCount = 1,
                               ModeDescription = mDesc,
                                   Flags = SwapChainFlags.AllowModeSwitch,
                               IsWindowed = false,
                               OutputHandle = form.Handle,
                               SampleDescription = new SampleDescription(1, 0),
                               SwapEffect = SwapEffect.Discard,
                               Usage = Usage.RenderTargetOutput
                           };

            Device.CreateWithSwapChain(null, DriverType.Hardware, DeviceCreationFlags.Debug, desc, out device,
                                       out swapChain);

            //Stops Alt+enter from causing fullscreen skrewiness.
            factory = swapChain.GetParent<Factory>();
            factory.SetWindowAssociation(form.Handle, WindowAssociationFlags.IgnoreAll);

            backBuffer = Resource.FromSwapChain<Texture2D>(swapChain, 0);
            renderView = new RenderTargetView(device, backBuffer);

            ImageLoadInformation info = new ImageLoadInformation()
                                            {
                                                BindFlags = BindFlags.None,
                                                CpuAccessFlags = CpuAccessFlags.Read,
                                                FilterFlags = FilterFlags.None,
                                                Format = SlimDX.DXGI.Format.R8G8B8A8_UNorm,
                                                MipFilterFlags = FilterFlags.None,
                                                OptionFlags = ResourceOptionFlags.None,
                                                Usage = ResourceUsage.Staging,
                                                MipLevels = 1
                                            };

            // Make texture 3D
            sourceTexture = Texture2D.FromFile(device, "medusa.jpg", info);
            ImageLoadInformation info2 = new ImageLoadInformation()
                                            {
                                                BindFlags = BindFlags.ShaderResource,
                                                CpuAccessFlags = CpuAccessFlags.None,
                                                FilterFlags = FilterFlags.None,
                                                Format = SlimDX.DXGI.Format.R8G8B8A8_UNorm,
                                                MipFilterFlags = FilterFlags.None,
                                                OptionFlags = ResourceOptionFlags.None,
                                                Usage = ResourceUsage.Default,
                                                MipLevels = 1
                                            };
            Texture2D tShader = Texture2D.FromFile(device, "medusa.jpg", info2);
            srv = new ShaderResourceView(device, tShader);
            //ResizeDevice(new Size(1920, 1080), true);
            // Create a quad that fills the whole screen

            BuildQuad();
            // Create world view (ortho) projection matrices
            QuaternionCam qCam = new QuaternionCam();

            // Load effect from file. It is a basic effect that renders a full screen quad through
            // an ortho projectio=n matrix
            effect = Effect.FromFile(device, "Texture.fx", "fx_4_0", ShaderFlags.Debug, EffectFlags.None);
            EffectTechnique technique = effect.GetTechniqueByIndex(0);
            EffectPass pass = technique.GetPassByIndex(0);
            InputLayout layout = new InputLayout(device, pass.Description.Signature, new[]
                                                                                         {
                                                                                             new InputElement(
                                                                                                 "POSITION", 0,
                                                                                                 Format.
                                                                                                     R32G32B32A32_Float,
                                                                                                 0, 0),
                                                                                             new InputElement(
                                                                                                 "TEXCOORD", 0,
                                                                                                 Format.
                                                                                                     R32G32_Float,
                                                                                                 16, 0)
                                                                                         });
            effect.GetVariableByName("mWorld").AsMatrix().SetMatrix(
                Matrix.Translation(Layout.OrthographicTransform(Vector2.Zero, 99, size)));
            effect.GetVariableByName("mView").AsMatrix().SetMatrix(qCam.View);
            effect.GetVariableByName("mProjection").AsMatrix().SetMatrix(qCam.OrthoProjection);
            effect.GetVariableByName("tDiffuse").AsResource().SetResource(srv);

            // Set RT and Viewports
            device.OutputMerger.SetTargets(renderView);
//.........这里部分代码省略.........
开发者ID:yong-ja,项目名称:starodyssey,代码行数:101,代码来源:Program.cs

示例11: InitDevice

        /// <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;
        }
开发者ID:Prashant-Jonny,项目名称:phever,代码行数:43,代码来源:TutorialWindow.cs

示例12: CreateDeviceResources


//.........这里部分代码省略.........
            tex2DDescription.Height = 4096;
            tex2DDescription.Width = 512;
            tex2DDescription.MipLevels = 1;
            tex2DDescription.MiscFlags = 0;
            tex2DDescription.SampleDescription.Count = 1;
            tex2DDescription.SampleDescription.Quality = 0;
            tex2DDescription.Usage = Usage.Default;

            offscreenTexture = device.CreateTexture2D(tex2DDescription);

            using (Surface dxgiSurface = offscreenTexture.GetDXGISurface())
            {
                // Create a D2D render target which can draw into our offscreen D3D surface
                renderTarget = d2DFactory.CreateDxgiSurfaceRenderTarget(
                    dxgiSurface,
                    props);
            }

            PixelFormat alphaOnlyFormat = new PixelFormat(Format.A8_UNORM, AlphaMode.Premultiplied);

            opacityRenderTarget = renderTarget.CreateCompatibleRenderTarget(CompatibleRenderTargetOptions.None,
                                                                            alphaOnlyFormat);

            // Load pixel shader
            // Open precompiled vertex shader
            // This file was compiled using DirectX's SDK Shader compilation tool: 
            // fxc.exe /T fx_4_0 /Fo SciFiText.fxo SciFiText.fx
            shader = LoadResourceShader(device, "SciFiTextDemo.SciFiText.fxo");

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

            // Obtain the variables
            worldMatrixVariable = shader.GetVariableByName("World").AsMatrix();
            viewMatrixVariable = shader.GetVariableByName("View").AsMatrix();
            projectionMarixVariable = shader.GetVariableByName("Projection").AsMatrix();
            diffuseVariable = shader.GetVariableByName("txDiffuse").AsShaderResource();

            // Create the input layout
            PassDescription passDesc = new PassDescription();
            passDesc = technique.GetPassByIndex(0).Description;

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

            // Set the input layout
            device.IA.SetInputLayout(
                vertexLayout
                );

            IntPtr verticesDataPtr = Marshal.AllocHGlobal(Marshal.SizeOf(VertexArray.VerticesInstance));
            Marshal.StructureToPtr(VertexArray.VerticesInstance, verticesDataPtr, true);

            BufferDescription bd = new BufferDescription();
            bd.Usage = Usage.Default;
            bd.ByteWidth = (uint) Marshal.SizeOf(VertexArray.VerticesInstance);
            bd.BindFlags = BindFlag.VertexBuffer;
            bd.CpuAccessFlags = CpuAccessFlag.Unspecified;
            bd.MiscFlags = ResourceMiscFlag.Undefined;

            SubresourceData InitData = new SubresourceData()
                                           {
                                               SysMem = verticesDataPtr
开发者ID:Prashant-Jonny,项目名称:phever,代码行数:67,代码来源:Window1.xaml.cs

示例13: LoadResources

		public override void LoadResources()
		{
			if (m_Disposed == true)
			{
				m_TextFont.LoadResources();

				//SlimDX.D3DCompiler.ShaderBytecode blob = SlimDX.D3DCompiler.ShaderBytecode.CompileFromFile(Helper.ResolvePath(m_ShaderLocation), "fx_4_0", SlimDX.D3DCompiler.ShaderFlags.EnableStrictness, SlimDX.D3DCompiler.EffectFlags.None);

				m_Effect = new Effect(GameEnvironment.Device, Bytecode);

				m_Technique = m_Effect.GetTechniqueByName("LinesAndBoxes");
				m_Pass_BoxesAndText = m_Technique.GetPassByName("BoxesAndText");
				m_Pass_Lines = m_Technique.GetPassByName("Lines");
				
				m_Layout = new InputLayout(GameEnvironment.Device, m_Pass_Lines.Description.Signature, new[] {
					new InputElement("POSITION", 0, Format.R32G32B32_Float, 0, 0),
					new InputElement("TEXCOORD", 0, Format.R32G32_Float, 12, 0),
					new InputElement("COLOR", 0, Format.R32G32B32A32_Float, 20, 0),				
				});

				m_UiElementsTexture = m_Effect.GetVariableByName("UiElementsTexture").AsResource();
				m_UiElementsTexture.SetResource(m_TextFont.TexureView); 

				m_Disposed = false;
			}
		}
开发者ID:RugCode,项目名称:drg-pt,代码行数:26,代码来源:UiEffect.cs

示例14: EffectTransformVariables

 public EffectTransformVariables(Effect effect)
 {
     // openGL: uniform variables            
     mWorld = effect.GetVariableByName("mWorld").AsMatrix();
 }
开发者ID:BEEden,项目名称:Diplomarbeit,代码行数:5,代码来源:Model3D.cs

示例15: Run


//.........这里部分代码省略.........
            // ---------------------------------------------------------------------------------------------------
            // Acquire the mutexes. These are needed to assure the device in use has exclusive access to the surface
            // ---------------------------------------------------------------------------------------------------

            var device10Mutex = textureD3D10.QueryInterface<KeyedMutex>();
            var device11Mutex = textureD3D11.QueryInterface<KeyedMutex>();

            // ---------------------------------------------------------------------------------------------------
            // Main rendering loop
            // ---------------------------------------------------------------------------------------------------

            bool first = true;

            RenderLoop
                .Run(form,
                     () =>
                         {
                             if(first)
                             {
                                 form.Activate();
                                 first = false;
                             }

                             // clear the render target to black
                             context.ClearRenderTargetView(renderTargetView, Colors.DarkSlateGray);

                             // Draw the triangle
                             context.InputAssembler.InputLayout = layoutColor;
                             context.InputAssembler.PrimitiveTopology = PrimitiveTopology.TriangleList;
                             context.InputAssembler.SetVertexBuffers(0, new VertexBufferBinding(vertexBufferColor, VertexPositionColor.SizeInBytes, 0));
                             context.OutputMerger.BlendState = null;
                             var currentTechnique = effect.GetTechniqueByName("Color");
                             for (var pass = 0; pass < currentTechnique.Description.PassCount; ++pass)
                             {
                                 using (var effectPass = currentTechnique.GetPassByIndex(pass))
                                 {
                                     System.Diagnostics.Debug.Assert(effectPass.IsValid, "Invalid EffectPass");
                                     effectPass.Apply(context);
                                 }
                                 context.Draw(3, 0);
                             };

                             // Draw Ellipse on the shared Texture2D
                             device10Mutex.Acquire(0, 100);
                             renderTarget2D.BeginDraw();
                             renderTarget2D.Clear(Colors.Black);
                             renderTarget2D.DrawGeometry(tesselatedGeometry, solidColorBrush);
                             renderTarget2D.DrawEllipse(new Ellipse(center, 200, 200), solidColorBrush, 20, null);
                             renderTarget2D.EndDraw();
                             device10Mutex.Release(0);

                             // Draw the shared texture2D onto the screen, blending the 2d content in
                             device11Mutex.Acquire(0, 100);
                             var srv = new ShaderResourceView(device11, textureD3D11);
                             effect.GetVariableByName("g_Overlay").AsShaderResource().SetResource(srv);
                             context.InputAssembler.InputLayout = layoutOverlay;
                             context.InputAssembler.PrimitiveTopology = PrimitiveTopology.TriangleStrip;
                             context.InputAssembler.SetVertexBuffers(0, new VertexBufferBinding(vertexBufferOverlay, VertexPositionTexture.SizeInBytes, 0));
                             context.OutputMerger.BlendState = blendStateTransparent;
                             currentTechnique = effect.GetTechniqueByName("Overlay");

                             for (var pass = 0; pass < currentTechnique.Description.PassCount; ++pass)
                             {
                                 using (var effectPass = currentTechnique.GetPassByIndex(pass))
                                 {
                                     System.Diagnostics.Debug.Assert(effectPass.IsValid, "Invalid EffectPass");
                                     effectPass.Apply(context);
                                 }
                                 context.Draw(4, 0);
                             }
                             srv.Dispose();
                             device11Mutex.Release(0);

                             swapChain.Present(0, PresentFlags.None);
                         });

            // dispose everything
            vertexBufferColor.Dispose();
            vertexBufferOverlay.Dispose();
            layoutColor.Dispose();
            layoutOverlay.Dispose();
            effect.Dispose();
            shaderByteCode.Dispose();
            renderTarget2D.Dispose();
            swapChain.Dispose();
            device11.Dispose();
            device10.Dispose();
            textureD3D10.Dispose();
            textureD3D11.Dispose();
            factory1.Dispose();
            adapter1.Dispose();
            sharedResource.Dispose();
            factory2D.Dispose();
            surface.Dispose();
            solidColorBrush.Dispose();
            blendStateTransparent.Dispose();

            device10Mutex.Dispose();
            device11Mutex.Dispose();
        }
开发者ID:ernstnaezer,项目名称:SharpDXSharedResources,代码行数:101,代码来源:Program.cs


注:本文中的Effect.GetVariableByName方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。