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


C# Effect.SetValue方法代码示例

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


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

示例1: applyToEffect

 public virtual void applyToEffect(Effect effect)
 {
     effect.SetValue("lightColor", ColorValue.FromColor(this.color));
     effect.SetValue("lightPosition", TgcParserUtils.vector3ToFloat4Array(this.position));
     effect.SetValue("lightIntensity", this.intensity);
     effect.SetValue("lightAttenuation", this.attenuation);
 }
开发者ID:pablitar,项目名称:tgc-mirrorball,代码行数:7,代码来源:Lights.cs

示例2: configurarLinterna

        public void configurarLinterna(Effect shader)
        {
            Plane v = GuiController.Instance.Frustum.NearPlane;
            Vector3 lightPos = GuiController.Instance.FpsCamera.Position;
              //  Vector3 direccionLinterna = Vector3.Normalize(GuiController.Instance.FpsCamera.LookAt);
            Vector3 direccionLinterna = Vector3.Normalize(new Vector3(v.A, v.B, v.C));

            shader.SetValue("angleCosLinterna", FastMath.ToRad((float)GuiController.Instance.Modifiers["angleCosLinterna"]));
            shader.SetValue("exponentLinterna", (float)GuiController.Instance.Modifiers["exponentLinterna"]);
            shader.SetValue("intensidadLinterna", (float)GuiController.Instance.Modifiers["intensidadLinterna"]);
            shader.SetValue("atenuacionLinterna", (float)GuiController.Instance.Modifiers["atenuacionLinterna"]);
            shader.SetValue("colorLinterna", ColorValue.FromColor((Color)GuiController.Instance.Modifiers["colorLinterna"]));
            shader.SetValue("direccionLinterna", TgcParserUtils.vector3ToVector4(direccionLinterna));
            shader.SetValue("posicionLinterna", TgcParserUtils.vector3ToVector4(lightPos));
        }
开发者ID:pablitar,项目名称:tgc-mirrorball,代码行数:15,代码来源:EjemploEscenaNueva.cs

示例3: Water

        public Water()
        {
            Device d3dDevice = GuiController.Instance.D3dDevice;

            TgcSceneLoader loader = new TgcSceneLoader();
            loader.MeshFactory = new MeshShaderFactory();

            scene = loader.loadSceneFromFile(Path.WaterScene);
            mesh = (MeshShader)scene.Meshes[0];
            mesh.Scale = new Vector3(350f, 0.1f, 2200f);
            mesh.Position = new Vector3(0f, -20f, 0f);

            string compilationErrors;
            effect = Effect.FromFile(d3dDevice, Path.WaterShader, null, null, ShaderFlags.None, null, out compilationErrors);
            mesh.effect = effect;
            if (effect == null) GuiController.Instance.Logger.log(compilationErrors);

            effect.SetValue("textureOffset", 0.1f);
        }
开发者ID:faloi,项目名称:tegece,代码行数:19,代码来源:Water.cs

示例4: setShaderMatrixIdentity

        /// <summary>
        /// Cargar todas la matrices generales que necesita el shader, tomando
        /// como primicia que la matriz de world es la identidad.
        /// Simplica los calculos respecto a setShaderMatrix()
        /// </summary>
        public void setShaderMatrixIdentity(Effect effect)
        {
            Device device = GuiController.Instance.D3dDevice;

            Matrix matWorldView = device.Transform.View;
            Matrix matWorldViewProj = matWorldView * device.Transform.Projection;
            effect.SetValue("matWorld", Matrix.Identity);
            effect.SetValue("matWorldView", matWorldView);
            effect.SetValue("matWorldViewProj", matWorldViewProj);
            effect.SetValue("matInverseTransposeWorld", Matrix.Identity);
        }
开发者ID:aniPerezG,项目名称:barbalpha,代码行数:16,代码来源:TgcShaders.cs

示例5: cargarEscena

        public void cargarEscena(String zona1, String zona2, String zona3, String dirEscena, String nombreEscena)
        {
            this.zona1 = zona1;
            this.zona2 = zona2;
            this.zona3 = zona3;

            //Cargar escenario, pero inicialmente solo hacemos el parser, para separar los objetos que son solo luces y no meshes
            string scenePath = GuiController.Instance.AlumnoEjemplosDir + dirEscena + nombreEscena;
            string mediaPath = GuiController.Instance.AlumnoEjemplosDir + dirEscena;
            TgcSceneParser parser = new TgcSceneParser();
            TgcSceneData sceneData = parser.parseSceneFromString(File.ReadAllText(scenePath));

            //Separar modelos reales de las luces, y las luces según el layeral que pertenecen

            List<TgcMeshData> realMeshData = new List<TgcMeshData>();
            for (int i = 0; i < sceneData.meshesData.Length; i++)
            {
                TgcMeshData meshData = sceneData.meshesData[i];

                //Es una luz, no cargar mesh, solo importan sus datos
                if (meshData.layerName.Equals(zona1+constLuz))
                {
                    //Guardar datos de luz de zona 1
                    LightData light = new LightData(meshData);
                    lucesZona1.Add(light);
                }else if(meshData.layerName.Equals(zona2+constLuz)){
                    //Guardar datos de luz de zona 2
                    LightData light = new LightData(meshData);
                    lucesZona2.Add(light);
                }else if(meshData.layerName.Equals(zona3+constLuz)){
                    //Guardar datos de luz de zona 3
                    LightData light = new LightData(meshData);
                    lucesZona3.Add(light);
                } //Es un mesh real, agregar a array definitivo

                realMeshData.Add(meshData);

            }

            //Quedaron separados los meshes de las luces. Las luces están separadas por zona.

            //Reemplazar array original de meshData de sceneData por el definitivo
            sceneData.meshesData = realMeshData.ToArray();

            //Ahora si cargar meshes reales
            TgcSceneLoader loader = new TgcSceneLoader();
            scene = loader.loadScene(sceneData, mediaPath);
            GuiController.Instance.Logger.log("Empieza compilacion de shader", Color.Red);
            shader = TgcShaders.loadEffect(shaderUrl);
            GuiController.Instance.Logger.log("Fin compilacion de shader", Color.Red);
            shader.SetValue("mirrorBallTexture", TextureLoader.FromFile(GuiController.Instance.D3dDevice, GuiController.Instance.AlumnoEjemplosMediaDir + "\\mirrorBallLights.png"));

            //Pre-calculamos las 3 luces mas cercanas de cada mesh y cargamos el Shader

            foreach (TgcMesh mesh in scene.Meshes)
            {

                MeshLightData meshData = new MeshLightData();
                meshData.mesh = mesh;

                Vector3 meshCenter = mesh.BoundingBox.calculateBoxCenter();
                meshData.lights = lucesMasCercanas(meshCenter, 3, mesh.Layer);

                meshData.mesh.Effect = shader;

                //separados por zona, no se porqué, capaz para optimizar, no se
                if (mesh.Layer.Equals(this.zona1))
                {
                    meshesZona1.Add(meshData);
                }
                else if (mesh.Layer.Equals(this.zona2))
                {
                    meshesZona2.Add(meshData);
                }
                else if (mesh.Name.Equals("bola"))
                {
                    createMirrorBall(mesh);
                }else
                {
                    meshesZona3.Add(meshData);
                }
               if(mesh.Layer.Contains(constLuz)){
                   luzEnMovimiento(mesh, lucesMasCercanas(meshCenter, 1, mesh.Layer));
                   meshData.mesh.Position = meshCenter;
               }
            }
        }
开发者ID:pablitar,项目名称:tgc-mirrorball,代码行数:87,代码来源:ParseadorDeEscena.cs

示例6: init

        public override void init()
        {
            Device d3dDevice = GuiController.Instance.D3dDevice;
            GuiController.Instance.CustomRenderEnabled = true;

            MyMediaDir = GuiController.Instance.ExamplesDir + "Shaders\\WorkshopShaders\\Media\\";
            MyShaderDir = GuiController.Instance.ExamplesDir + "Shaders\\WorkshopShaders\\Shaders\\";

            //Cargar mesh
            TgcSceneLoader loader = new TgcSceneLoader();
            mesh = loader.loadSceneFromFile(GuiController.Instance.ExamplesMediaDir + "ModelosTgc\\Teapot\\Teapot-TgcScene.xml").Meshes[0];

            //Cargar Shader personalizado
            string compilationErrors;
            effect = Effect.FromFile(GuiController.Instance.D3dDevice,MyShaderDir + "MotionBlur.fx",
                null, null, ShaderFlags.PreferFlowControl, null, out compilationErrors);
            if (effect == null)
            {
                throw new Exception("Error al cargar shader. Errores: " + compilationErrors);
            }
            //Configurar Technique dentro del shader
            effect.Technique = "DefaultTechnique";
            mesh.Effect = effect;
            //Camara
            GuiController.Instance.RotCamera.Enable = true;
            GuiController.Instance.RotCamera.CameraCenter = new Vector3(0, 0, 0);
            GuiController.Instance.RotCamera.CameraDistance = 150;

            GuiController.Instance.BackgroundColor = Color.Black;


            // stencil
            g_pDepthStencil = d3dDevice.CreateDepthStencilSurface(d3dDevice.PresentationParameters.BackBufferWidth,
                                                                         d3dDevice.PresentationParameters.BackBufferHeight,
                                                                         DepthFormat.D24S8,
                                                                         MultiSampleType.None,
                                                                         0,
                                                                         true);

            // inicializo el render target
            g_pRenderTarget = new Texture(d3dDevice, d3dDevice.PresentationParameters.BackBufferWidth
                    , d3dDevice.PresentationParameters.BackBufferHeight, 1, Usage.RenderTarget,
                        Format.X8R8G8B8, Pool.Default);


            // velocidad del pixel
            g_pVel1 = new Texture(d3dDevice, d3dDevice.PresentationParameters.BackBufferWidth
                    , d3dDevice.PresentationParameters.BackBufferHeight, 1, Usage.RenderTarget,
                        Format.A16B16G16R16F, Pool.Default);
            g_pVel2 = new Texture(d3dDevice, d3dDevice.PresentationParameters.BackBufferWidth
                    , d3dDevice.PresentationParameters.BackBufferHeight, 1, Usage.RenderTarget,
                        Format.A16B16G16R16F, Pool.Default);

            // Resolucion de pantalla
            effect.SetValue("screen_dx", d3dDevice.PresentationParameters.BackBufferWidth);
            effect.SetValue("screen_dy", d3dDevice.PresentationParameters.BackBufferHeight);

            CustomVertex.PositionTextured[] vertices = new CustomVertex.PositionTextured[]
		    {
    			new CustomVertex.PositionTextured( -1, 1, 1, 0,0), 
			    new CustomVertex.PositionTextured(1,  1, 1, 1,0),
			    new CustomVertex.PositionTextured(-1, -1, 1, 0,1),
			    new CustomVertex.PositionTextured(1,-1, 1, 1,1)
    		};
            //vertex buffer de los triangulos
            g_pVBV3D = new VertexBuffer(typeof(CustomVertex.PositionTextured),
                    4, d3dDevice, Usage.Dynamic | Usage.WriteOnly,
                        CustomVertex.PositionTextured.Format, Pool.Default);
            g_pVBV3D.SetData(vertices, 0, LockFlags.None);

            antMatWorldView  = Matrix.Identity;



        }
开发者ID:aniPerezG,项目名称:barbalpha,代码行数:75,代码来源:MotionBlur.cs

示例7: RenderSkinnedMeshWithoutSkinning

        private void RenderSkinnedMeshWithoutSkinning(Common.Tuple<CustomFrame, CustomMeshContainer> SM, Effect effect, bool withShadows, Matrix viewProjection, Matrix[][] combinedTransforms)
        {
            if (withShadows)
            {
                effect.SetValue(EHShadowWorldViewProjection, combinedTransforms[0][0] * ShadowMapCamera);
                effect.CommitChanges();
                SM.Second.MeshData.Mesh.DrawSubset(0);
            }
            else
            {
                effect.SetValue(EHShadowWorldViewProjection, combinedTransforms[0][0] * ShadowMapCamera);
                effect.SetValue(EHWorldViewProjectionMatrix, combinedTransforms[0][0] * viewProjection);
                //effect.SetValue(EHWorldMatrix, SM.First.CombinedTransform);
                effect.SetValue(EHWorldMatrix, combinedTransforms[0][0]);
                //effect.SetValue(EHNormalMatrix, combinedTransforms[0].Second[0]);

                effect.CommitChanges();
                SM.Second.MeshData.Mesh.DrawSubset(0);
            }
        }
开发者ID:ChristianMarchiori,项目名称:DeadMeetsLead,代码行数:20,代码来源:SortedTestRenderer.cs

示例8: init

        public override void init()
        {
            GuiController.Instance.CustomRenderEnabled = true;

            Device d3dDevice = GuiController.Instance.D3dDevice;
            MyMediaDir = GuiController.Instance.ExamplesDir + "Shaders\\WorkshopShaders\\Media\\";
            MyShaderDir = GuiController.Instance.ExamplesDir + "Shaders\\WorkshopShaders\\Shaders\\";

            //Cargamos un escenario
            TgcSceneLoader loader = new TgcSceneLoader();
            TgcScene scene = loader.loadSceneFromFile(GuiController.Instance.ExamplesMediaDir + "MeshCreator\\Scenes\\Deposito\\Deposito-TgcScene.xml");
            meshes = scene.Meshes;

            //Cargar Shader personalizado
            string compilationErrors;
            effect = Effect.FromFile(GuiController.Instance.D3dDevice,
                GuiController.Instance.ExamplesDir + "Shaders\\WorkshopShaders\\Shaders\\GaussianBlur.fx",
                null, null, ShaderFlags.PreferFlowControl, null, out compilationErrors);
            if (effect == null)
            {
                throw new Exception("Error al cargar shader. Errores: " + compilationErrors);
            }
            //Configurar Technique dentro del shader
            effect.Technique = "DefaultTechnique";

            //Camara en primera personas
            GuiController.Instance.FpsCamera.Enable = true;
            GuiController.Instance.FpsCamera.setCamera(new Vector3(-182.3816f, 82.3252f, -811.9061f), new Vector3(-182.0957f, 82.3147f, -810.9479f));

            g_pDepthStencil = d3dDevice.CreateDepthStencilSurface(d3dDevice.PresentationParameters.BackBufferWidth,
                                                                         d3dDevice.PresentationParameters.BackBufferHeight,
                                                                         DepthFormat.D24S8,
                                                                         MultiSampleType.None,
                                                                         0,
                                                                         true);

            // inicializo el render target
            g_pRenderTarget = new Texture(d3dDevice, d3dDevice.PresentationParameters.BackBufferWidth
                    , d3dDevice.PresentationParameters.BackBufferHeight, 1, Usage.RenderTarget,
                        Format.X8R8G8B8, Pool.Default);

            g_pRenderTarget4 = new Texture(d3dDevice, d3dDevice.PresentationParameters.BackBufferWidth/4
                    , d3dDevice.PresentationParameters.BackBufferHeight/4, 1, Usage.RenderTarget,
                        Format.X8R8G8B8, Pool.Default);

            g_pRenderTarget4Aux = new Texture(d3dDevice, d3dDevice.PresentationParameters.BackBufferWidth / 4
                    , d3dDevice.PresentationParameters.BackBufferHeight / 4, 1, Usage.RenderTarget,
                        Format.X8R8G8B8, Pool.Default);

            effect.SetValue("g_RenderTarget", g_pRenderTarget);

            // Resolucion de pantalla
            effect.SetValue("screen_dx", d3dDevice.PresentationParameters.BackBufferWidth);
            effect.SetValue("screen_dy", d3dDevice.PresentationParameters.BackBufferHeight);

            CustomVertex.PositionTextured[] vertices = new CustomVertex.PositionTextured[]
            {
                new CustomVertex.PositionTextured( -1, 1, 1, 0,0),
                new CustomVertex.PositionTextured(1,  1, 1, 1,0),
                new CustomVertex.PositionTextured(-1, -1, 1, 0,1),
                new CustomVertex.PositionTextured(1,-1, 1, 1,1)
            };
            //vertex buffer de los triangulos
            g_pVBV3D = new VertexBuffer(typeof(CustomVertex.PositionTextured),
                    4, d3dDevice, Usage.Dynamic | Usage.WriteOnly,
                        CustomVertex.PositionTextured.Format, Pool.Default);
            g_pVBV3D.SetData(vertices, 0, LockFlags.None);

            GuiController.Instance.Modifiers.addBoolean("activar_efecto", "Activar efecto", true);
            GuiController.Instance.Modifiers.addBoolean("separable", "Separable Blur", true);
            GuiController.Instance.Modifiers.addInt("cant_pasadas", 1, 10, 1);
        }
开发者ID:JesusHerrera,项目名称:tgc-viewer,代码行数:72,代码来源:GaussianBlur.cs

示例9: Load

        /// <summary>
        /// Load the effect file & initialise everything
        /// </summary>
        public static void Load(Device device, ShaderFlags shaderFlags)
        {
            string err = "";										// shader compiler errors
            // Find and load the file
            try
            {
                string path = Utility.FindMediaFile("Simbiosis.fx");
                effect = ResourceCache.GetGlobalInstance().CreateEffectFromFile(device,
                                                                                path, null, null, shaderFlags, null, out err);
                if (effect == null) throw new Exception("effect = null");
            }
            catch (Exception e)
            {
                Debug.WriteLine("=========================================================================================");
                Debug.WriteLine("Unable to compile Effect file." + e.ToString());
                Debug.WriteLine(err);
                Debug.WriteLine("=========================================================================================");
                throw e;
            }

            // Set up handles for the globals
            matDiffuse = effect.GetParameter(null, "matDiffuse");
            matSpecular = effect.GetParameter(null, "matSpecular");
            matEmissive = effect.GetParameter(null, "matEmissive");
            matAmbient = effect.GetParameter(null, "matAmbient");
            baseTexture = effect.GetParameter(null, "baseTexture");
            bumpTexture = effect.GetParameter(null, "bumpTexture");
            world = effect.GetParameter(null, "world");
            worldViewProjection = effect.GetParameter(null, "worldViewProjection");
            eyePosition = effect.GetParameter(null, "eyePosition");
            isTextured = effect.GetParameter(null, "isTextured");
            isBump = effect.GetParameter(null, "isBump");
            isShadowed = effect.GetParameter(null, "isShadowed");
            isSpotlit = effect.GetParameter(null, "isSpotlit");
            spotVP = effect.GetParameter(null, "spotVP");
            spotTexture = effect.GetParameter(null, "spotTexture");
            spotPosition = effect.GetParameter(null, "spotPosition");
            causticTexture = effect.GetParameter(null, "causticTexture");
            envTexture = effect.GetParameter(null, "envTexture");
            shadowTexture = effect.GetParameter(null, "shadowTexture");
            shadowMatrix = effect.GetParameter(null, "shadowMatrix");

            // and the techniques
            mainTechnique = effect.GetTechnique("Main");
            sceneryTechnique = effect.GetTechnique("Scenery");
            waterTechnique = effect.GetTechnique("Water");
            skyboxTechnique = effect.GetTechnique("Skybox");
            shadowTechnique = effect.GetTechnique("Shadow");
            markerTechnique = effect.GetTechnique("Marker");

            // Set once-only shader constants
            effect.SetValue("sunPosition",new Vector4(512,1000,512,0));				// sun's position (.W is ignored - float3 in shader)
            effect.SetValue("ambient", new ColorValue(255, 255, 255));					// amount/colour of ambient skylight
            effect.SetValue("sunlight", new ColorValue(255, 255, 255));				// colour/brightness of sunlight

            // Set up the projection matrix for shadows, based on sun position
            sunProj = Matrix.OrthoLH(100, 100, 0, 1000);							// adjust width, height if necc
            effect.SetValue("sunProj", sunProj);
            SetCameraData();														// also set up the (variable) view matrix

            // Set up the projection matrix for caustics
            Matrix caustic =
                Matrix.Invert(														// "view" matrix
                Matrix.Translation(new Vector3(0, Water.WATERLEVEL, 0))				// caustics start at water level
                * Matrix.RotationYawPitchRoll(0, (float)Math.PI/2, 0)				// looking down
                )																	// Proj matrix (orthogonal)
                * Matrix.OrthoLH(80, 80, 0, 1000);									// adjust width, height
            effect.SetValue("causticMatrix", caustic);
        }
开发者ID:JamesTryand,项目名称:simergy,代码行数:72,代码来源:Fx.cs

示例10: init

        public override void init()
        {
            Device d3dDevice = GuiController.Instance.D3dDevice;
            GuiController.Instance.CustomRenderEnabled = true;

            MyMediaDir = GuiController.Instance.ExamplesDir + "Shaders\\WorkshopShaders\\Media\\";
            MyShaderDir = GuiController.Instance.ExamplesDir + "Shaders\\WorkshopShaders\\Shaders\\";

            circuito = new F1Circuit();

            //Cargar terreno: cargar heightmap y textura de color
            terrain = new TgcSimpleTerrain();
            terrain.loadHeightmap(GuiController.Instance.ExamplesMediaDir + "Heighmaps\\" + "TerrainTexture2.jpg",
                    20, 0.1f, new Vector3(0, -125, 0));
            terrain.loadTexture( GuiController.Instance.ExamplesMediaDir + "Heighmaps\\" + "TerrainTexture2.jpg");

            //Crear SkyBox
            skyBox = new TgcSkyBox();
            skyBox.Center = new Vector3(0, 500, 0);
            skyBox.Size = new Vector3(10000, 10000, 10000);
            string texturesPath = GuiController.Instance.ExamplesMediaDir + "Texturas\\Quake\\SkyBox LostAtSeaDay\\";
            skyBox.setFaceTexture(TgcSkyBox.SkyFaces.Up, texturesPath + "lostatseaday_up.jpg");
            skyBox.setFaceTexture(TgcSkyBox.SkyFaces.Down, texturesPath + "lostatseaday_dn.jpg");
            skyBox.setFaceTexture(TgcSkyBox.SkyFaces.Left, texturesPath + "lostatseaday_lf.jpg");
            skyBox.setFaceTexture(TgcSkyBox.SkyFaces.Right, texturesPath + "lostatseaday_rt.jpg");
            skyBox.setFaceTexture(TgcSkyBox.SkyFaces.Front, texturesPath + "lostatseaday_bk.jpg");
            skyBox.setFaceTexture(TgcSkyBox.SkyFaces.Back, texturesPath + "lostatseaday_ft.jpg");
            skyBox.updateValues();

            TgcSceneLoader loader = new TgcSceneLoader();
            TgcScene scene = loader.loadSceneFromFile(GuiController.Instance.ExamplesMediaDir + "MeshCreator\\Meshes\\Vehiculos\\Auto\\Auto-TgcScene.xml");
            car = scene.Meshes[0];
            car.AutoTransformEnable = false;

            //Cargar Shader personalizado
            string compilationErrors;
            effect = Effect.FromFile(GuiController.Instance.D3dDevice,MyShaderDir + "OutRun.fx",
                null, null, ShaderFlags.PreferFlowControl, null, out compilationErrors);
            if (effect == null)
            {
                throw new Exception("Error al cargar shader. Errores: " + compilationErrors);
            }
            //Configurar Technique dentro del shader
            effect.Technique = "DefaultTechnique";

            //Configurar FPS Camara
            GuiController.Instance.FpsCamera.Enable = true;
            GuiController.Instance.FpsCamera.MovementSpeed = 250f;
            GuiController.Instance.FpsCamera.JumpSpeed = 50f;
            //GuiController.Instance.FpsCamera.setCamera(new Vector3(315.451f, 40, -464.28490f), new Vector3(316.1626f, 40, -463.6029f));

            reset_pos();

            // para capturar el mouse
            Control focusWindows = GuiController.Instance.D3dDevice.CreationParameters.FocusWindow;
            mouseCenter = focusWindows.PointToScreen(new Point(focusWindows.Width / 2,focusWindows.Height / 2));
            mouseCaptured = true;
            Cursor.Hide();

            // stencil
            g_pDepthStencil = d3dDevice.CreateDepthStencilSurface(d3dDevice.PresentationParameters.BackBufferWidth,
                                                                         d3dDevice.PresentationParameters.BackBufferHeight,
                                                                         DepthFormat.D24S8,
                                                                         MultiSampleType.None,
                                                                         0,
                                                                         true);

            // inicializo el render target
            g_pRenderTarget = new Texture(d3dDevice, d3dDevice.PresentationParameters.BackBufferWidth
                    , d3dDevice.PresentationParameters.BackBufferHeight, 1, Usage.RenderTarget,
                        Format.X8R8G8B8, Pool.Default);
            g_pRenderTarget2 = new Texture(d3dDevice, d3dDevice.PresentationParameters.BackBufferWidth
                    , d3dDevice.PresentationParameters.BackBufferHeight, 1, Usage.RenderTarget,
                        Format.X8R8G8B8, Pool.Default);
            g_pRenderTarget3 = new Texture(d3dDevice, d3dDevice.PresentationParameters.BackBufferWidth
                    , d3dDevice.PresentationParameters.BackBufferHeight, 1, Usage.RenderTarget,
                        Format.X8R8G8B8, Pool.Default);
            g_pRenderTarget4 = new Texture(d3dDevice, d3dDevice.PresentationParameters.BackBufferWidth
                    , d3dDevice.PresentationParameters.BackBufferHeight, 1, Usage.RenderTarget,
                        Format.X8R8G8B8, Pool.Default);
            g_pRenderTarget5 = new Texture(d3dDevice, d3dDevice.PresentationParameters.BackBufferWidth
                    , d3dDevice.PresentationParameters.BackBufferHeight, 1, Usage.RenderTarget,
                        Format.X8R8G8B8, Pool.Default);

            // Resolucion de pantalla
            effect.SetValue("screen_dx", d3dDevice.PresentationParameters.BackBufferWidth);
            effect.SetValue("screen_dy", d3dDevice.PresentationParameters.BackBufferHeight);

            CustomVertex.PositionTextured[] vertices = new CustomVertex.PositionTextured[]
            {
                new CustomVertex.PositionTextured( -1, 1, 1, 0,0),
                new CustomVertex.PositionTextured(1,  1, 1, 1,0),
                new CustomVertex.PositionTextured(-1, -1, 1, 0,1),
                new CustomVertex.PositionTextured(1,-1, 1, 1,1)
            };
            //vertex buffer de los triangulos
            g_pVBV3D = new VertexBuffer(typeof(CustomVertex.PositionTextured),
                    4, d3dDevice, Usage.Dynamic | Usage.WriteOnly,
                        CustomVertex.PositionTextured.Format, Pool.Default);
            g_pVBV3D.SetData(vertices, 0, LockFlags.None);
//.........这里部分代码省略.........
开发者ID:JesusHerrera,项目名称:tgc-viewer,代码行数:101,代码来源:OutRun.cs

示例11: RenderSkinnedMeshWithSkinning

        private void RenderSkinnedMeshWithSkinning(Common.Tuple<CustomFrame, CustomMeshContainer> SM, Effect effect, bool withShadows, Matrix[][] combinedTransforms)
        {
            for (int i = 0; i < combinedTransforms.Length; i++)
            {
                if (combinedTransforms[i] != null)
                {
                    effect.SetValue(EHWorldMatrices, combinedTransforms[i]);
                    effect.SetValue(EHCurrentBoneCount, SM.Second.Influences - 1);

                    //if (!withShadows)
                        //effect.SetValue(EHNormalMatrices, combinedTransforms[i].Second);

                    effect.CommitChanges();

                    SM.Second.MeshData.Mesh.DrawSubset(i);
                }
            }
        }
开发者ID:ChristianMarchiori,项目名称:DeadMeetsLead,代码行数:18,代码来源:SortedTestRenderer.cs

示例12: LoadShaderTextures

        private static shader LoadShaderTextures(Effect effect) {
            try { effect.SetTexture("lastpass", lastPass); } catch { } //throws an exception if this parameter doesn't exist :(
            try { effect.SetTexture("lastshader", lastShader); } catch { }
            try { effect.SetTexture("depthframe", depthFrame); } catch { }
            try { effect.SetValue("rcpres", new Vector4(1f/frameWidth, 1f/frameHeight, 0, 1)); } catch { }
            try { effect.SetValue("fov", 85f); } catch { }
            try { effect.SetValue("fogstart", 819.2f); } catch { }
            try { effect.SetValue("fogrange", 65536.0f); } catch { }
            try { effect.SetValue("waterlevel", 0f); } catch { }
			try { effect.SetValue("HDR", new Vector4(0.25f, 0.25f, 0.25f, 02.5f)); } catch { }
			try { effect.SetValue("eyepos", new Vector3(0f, 0f, 128f)); } catch { }
			try { effect.SetValue("eyevec", new Vector3(1f, 0f, 0f)); } catch { }

            int count=1;
            while(true) {
                string texpath;
                try { texpath=effect.GetString("texname"+count.ToString()); } catch { break; }
                if(texpath!=null) {
                    try {
                        Texture tex=Texture.FromFile(DXMain.device, Statics.runDir + "\\data files\\textures\\"+texpath);
                        effect.SetTexture("tex"+count.ToString(), tex);
                    } catch { }
                } else break;
                count++;
            }

            shader s = new shader();
            try {
                s.ehTime = effect.GetParameter(null, "time");
            } catch {
                s.ehTime = null;
            }
            try {
                s.ehHDR = effect.GetParameter(null, "HDR");
            } catch {
                s.ehHDR = null;
            }
            s.effect=effect;

            return s;
        }
开发者ID:mdmallardi,项目名称:MGE-XE,代码行数:41,代码来源:Shaders.cs

示例13: render

        public void render(Effect effect)
        {
            Device device = GuiController.Instance.D3dDevice;
            GuiController.Instance.Shaders.setShaderMatrixIdentity(effect);
            device.VertexFormat = CustomVertex.PositionTextured.Format;
            device.SetStreamSource(0, vb, 0);

            // primero dibujo los objetos opacos:
            // piso de la ruta
            effect.SetValue("texDiffuseMap", textura_piso);
            device.RenderState.AlphaBlendEnable = false;
            int numPasses = effect.Begin(0);
            for (int n = 0; n < numPasses; n++)
            {
                effect.BeginPass(n);
                device.DrawPrimitives(PrimitiveType.TriangleStrip, 0, 2 * (cant_ptos_ruta - 1));
                effect.EndPass();
            }
            effect.End();

            // vegetacion
            if (pos_en_ruta != -1)
            {
                float[] K = new float[10];
                for (int i = 0; i < cant_arboles; ++i)
                {
                    K[i] = 1;
                    arbol[i].Effect = effect;
                    arbol[i].Technique = "DefaultTechnique";
                }

                int[] P = new int[10];
                P[0] = 11;
                P[1] = 7;
                P[2] = 13;
                P[3] = 5;

                float dr = ancho_ruta / 2;
                for (int i = 0; i < cant_ptos_ruta; ++i)
                {
                    Vector3 dir = pt_ruta[i + 1] - pt_ruta[i];
                    dir.Normalize();
                    Vector3 n = Vector3.Cross(dir, new Vector3(0, 1, 0));
                    Vector3 p0 = pt_ruta[i] - n * dr;
                    Vector3 p1 = pt_ruta[i] + n * dr;

                    for (int j = 0; j < cant_arboles; ++j)
                    {
                        if (i % P[j] == 0)
                        {
                            Vector3 pos = pt_ruta[i] - n * 300 * K[j];
                            pos.Y = 0;
                            arbol[j].Position = pos;
                            arbol[j].render();
                            K[j] *= -1;
                        }
                    }
                }
            }

            // Ahora los objetos transparentes (el guarda rail, y los carteles)
            // guarda rail
            device.RenderState.AlphaBlendEnable = true;
            GuiController.Instance.Shaders.setShaderMatrixIdentity(effect);
            device.VertexFormat = CustomVertex.PositionTextured.Format;
            device.SetStreamSource(0, vb, 0);
            effect.SetValue("texDiffuseMap", textura_guardrail);
            numPasses = effect.Begin(0);
            for (int n = 0; n < numPasses; n++)
            {
                effect.BeginPass(n);
                device.DrawPrimitives(PrimitiveType.TriangleStrip, 2 * cant_ptos_ruta, 2 * (cant_ptos_ruta - 1));
                device.DrawPrimitives(PrimitiveType.TriangleStrip, 4 * cant_ptos_ruta, 2 * (cant_ptos_ruta - 1));
                effect.EndPass();
            }
            effect.End();

            // carteles
            effect.SetValue("texDiffuseMap", textura_cartel);
            numPasses = effect.Begin(0);
            for (int n = 0; n < numPasses; n++)
            {
                effect.BeginPass(n);
                for (int i = 0; i < cant_carteles; ++i)
                    device.DrawPrimitives(PrimitiveType.TriangleStrip, pos_carteles + 4 * i, 2);
                effect.EndPass();
            }
            effect.End();
        }
开发者ID:JesusHerrera,项目名称:tgc-viewer,代码行数:89,代码来源:F1Circuit.cs

示例14: InitializeGraphics

		private void InitializeGraphics()
		{
			Cursor.Hide();
			PresentParameters presentParams = new PresentParameters();

			presentParams.Windowed = ! FullScreen;
			presentParams.SwapEffect = SwapEffect.Discard;
			presentParams.AutoDepthStencilFormat = DepthFormat.D24X8;
			presentParams.EnableAutoDepthStencil = true;
			// If we want a Fullscreen device we need to set up a backbuffer
			if ( FullScreen)
			{
				presentParams.BackBufferCount = 1;
				presentParams.BackBufferFormat = Format.X8R8G8B8; 
				presentParams.BackBufferWidth = 800;
				presentParams.BackBufferHeight = 600;
			}
			Caps hardware = Manager.GetDeviceCaps(0, DeviceType.Hardware);
			
			
			CreateFlags flags = CreateFlags.SoftwareVertexProcessing;

			if (hardware.DeviceCaps.SupportsHardwareTransformAndLight)
				flags = CreateFlags.HardwareVertexProcessing;

			if (hardware.DeviceCaps.SupportsPureDevice)
				flags |= CreateFlags.PureDevice;

			// Pixelshader 2.0 is required
			// If not available create a Reference device ( must have SDK installed )
			if (hardware.PixelShaderVersion >= new Version(2,0) && hardware.VertexShaderVersion >= new Version(1,1))				
				device = new Device(0, DeviceType.Hardware, this, flags, presentParams);
			else
				device = new Device(0, DeviceType.Reference, this, flags, presentParams);

			String s = null;
			
			effect = Effect.FromFile(device, @"shader.fx", null,null,ShaderFlags.None, null, out s);			
            //if ( s != null) 
            //{
            //    // There are Compilation errors show them and then close app
            //    Cursor.Show();
            //    device.Dispose();
            //    this.Visible = false;
            //    MessageBox.Show(s);
            //    return;
            //}

			effect.Technique = "TransformTexture";

			projMatrix = Matrix.PerspectiveFovLH((float)Math.PI/4f, 
				this.Width / this.Height, 1f, 250f);

			t1 = TextureLoader.FromFile(device,@"..\..\grass.bmp");
			t2 = TextureLoader.FromFile(device,@"..\..\rock.bmp");

			effect.SetValue("Texture1", t1);
			effect.SetValue("Texture2", t2);

			handle1 = effect.GetParameter(null,"ambient");
			handle2 = effect.GetParameter(null,"WorldViewProj");
			handle3 = effect.GetParameter(null,"light");

			t = new Terrain(device,0,28);

			font = new Microsoft.DirectX.Direct3D.Font(device,new System.Drawing.Font("Arial",18));
	}
开发者ID:xuchuansheng,项目名称:GenXSource,代码行数:67,代码来源:Form1.cs

示例15: MeasureLuminance

        public void MeasureLuminance(Effect effect, Device device)
        {
            Surface OriginalRenderTarget = device.GetRenderTarget(0);
            Vector2[] sampleOffsets = new Vector2[16];
            Texture dest = ToneMapTex[nToneMapTex - 1];

            SurfaceDescription destDescr = dest.GetLevelDescription(0);
            SurfaceDescription sourceDescr = Renderer.Instance.RenderSurface.Description;

            GetSampleOffsets_DownScale2x2_Lum(sourceDescr.Width, sourceDescr.Height, destDescr.Width, destDescr.Height, ref sampleOffsets);
            effect.SetValue<Vector2>(new EffectHandle("g_avSampleOffsets"), sampleOffsets);
            effect.Technique = "DownScale2x2_Lum_RGBE8";

            Surface destSurface = dest.GetSurfaceLevel(0);
            device.SetRenderTarget(0, destSurface);
            Surface OriginalDS = device.DepthStencilSurface;
            device.DepthStencilSurface = Renderer.Instance.RenderDepthSurface;
            device.SetSamplerState(0, SamplerState.MagFilter, (int)TextureFilter.Linear);
            device.SetSamplerState(0, SamplerState.MinFilter, (int)TextureFilter.Linear);
            device.SetTexture(0, Renderer.Instance.RenderTexture);

            Renderer.Instance.DrawFullScreenQuad();
            device.SetTexture(0, null);

            effect.Technique = "DownScale3x3_RGBE8";
            for (int i = nToneMapTex - 1; i > 0; i--)
            {
                Surface source = ToneMapTex[i].GetSurfaceLevel(0);
                dest = ToneMapTex[i - 1];
                destSurface = dest.GetSurfaceLevel(0);
                GetSampleOffsetsets_DownScale3x3(destSurface.Description.Width, destSurface.Description.Height, ref sampleOffsets);
                effect.SetValue<Vector2>(new EffectHandle("g_avSampleOffsets"), sampleOffsets);

                device.SetRenderTarget(0, destSurface);
                device.SetTexture(0, ToneMapTex[i]);
                //device.SetSamplerState(0, SamplerStageStates.MagFilter, (int)TextureFilter.Point);
                //device.SetSamplerState(0, SamplerStageStates.MinFilter, (int)TextureFilter.Point);

                Renderer.Instance.DrawFullScreenQuad();

                device.SetTexture(0, null);
            }

            // Add calculated luminance to average
            if (CurrentAvgToneMap == -1)
            {
                Rectangle avgrect = new Rectangle(new Point(), new Size(1, 1));
                device.StretchRectangle(ToneMapTex[0].GetSurfaceLevel(0), avgrect, avgToneMap[0].GetSurfaceLevel(0), avgrect, TextureFilter.Point);

                CurrentAvgToneMap = 0;
            }
            else
            {
                effect.Technique = "CalcAvgLum_RGBE8";
                device.SetTexture(0, avgToneMap[CurrentAvgToneMap]); // "main" average
                int other = (CurrentAvgToneMap == 0 ? 1 : 0);
                device.SetTexture(1, ToneMapTex[0]); // new average to be added
                Surface surf = avgToneMap[other].GetSurfaceLevel(0);
                device.SetRenderTarget(0, surf); // unused "main" average texture used as rendertarget

                Renderer.Instance.DrawFullScreenQuad();

                device.SetTexture(0, null);
                device.SetTexture(1, null);
                CurrentAvgToneMap = other; // swap avgTonemap usage next frame
            }

            device.SetRenderTarget(0, OriginalRenderTarget);
            device.DepthStencilSurface = OriginalDS;

            // Read result
            device.GetRenderTargetData(AverageLum.GetSurfaceLevel(0), LockableAverage.GetSurfaceLevel(0));
            DataRectangle rect = LockableAverage.LockRectangle(0, LockFlags.ReadOnly);
            Color4 color = new Color4(rect.Data.Read<int>());
            LockableAverage.UnlockRectangle(0);

            // Revert LogLum encoding
            float invLogLumRange = 1.0f / (MaxLogLum + MinLogLum);
            float logLumOffset = MinLogLum * invLogLumRange;
            double avgLum = Math.Exp((color.Alpha) / (invLogLumRange + logLumOffset));
            effect.SetValue("avgLogLum", avgLum);
            //System.Console.WriteLine(avgLum);
        }
开发者ID:maesse,项目名称:CubeHags,代码行数:83,代码来源:ToneMap.cs


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