public static void Cargar() { Device d3dDevice = GuiController.Instance.D3dDevice; // Cargo el shader que tiene los efectos de postprocesado Shader = Utiles.CargarShaderConTechnique("postprocesado.fx"); // Creo el quad que va a ocupar toda la pantalla CustomVertex.PositionTextured[] screenQuadVertices = 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) }; ScreenQuad = new VertexBuffer(typeof(CustomVertex.PositionTextured), 4, GuiController.Instance.D3dDevice, Usage.Dynamic | Usage.WriteOnly, CustomVertex.PositionTextured.Format, Pool.Default); ScreenQuad.SetData(screenQuadVertices, 0, LockFlags.None); // Creamos un render targer sobre el cual se va a dibujar la pantalla RenderTargetPostprocesado = new Texture(d3dDevice, d3dDevice.PresentationParameters.BackBufferWidth , d3dDevice.PresentationParameters.BackBufferHeight, 1, Usage.RenderTarget, Format.X8R8G8B8, Pool.Default); Trabajando = false; }
/// <summary> /// Crea el SkyDome. /// </summary> public static void Cargar() { Textura = TextureLoader.FromCubeFile(GuiController.Instance.D3dDevice, Utiles.TexturasDir("cubemap-evul.dds")); VerticesBuffer = new VertexBuffer(typeof(CustomVertex.PositionNormalTextured), NivelDeDetalle * NivelDeDetalle * CustomVertex.PositionNormalTextured.StrideSize, GuiController.Instance.D3dDevice, Usage.WriteOnly, CustomVertex.PositionNormalTextured.Format, Pool.Default); Vertices = new CustomVertex.PositionNormalTextured[NivelDeDetalle * NivelDeDetalle]; for (int v = 0; v < NivelDeDetalle; v++) { for (int u = 0; u < NivelDeDetalle; u++) { // Alpha es el desplazamiento horizontal float al = (float)(-2.0f * Math.PI * ((float)u / (NivelDeDetalle - 1.0f))); // Theta es el desplazamiento vertical float th = (float)(0.6f * Math.PI * ((float)v / (NivelDeDetalle - 1.0f))); // Armo los vertices para el domo Vertices[v * NivelDeDetalle + u].X = (float)(Math.Sin(th) * Math.Sin(al)); Vertices[v * NivelDeDetalle + u].Y = (float)Math.Cos(th); Vertices[v * NivelDeDetalle + u].Z = (float)(Math.Sin(th) * Math.Cos(al)); } } VerticesBuffer.SetData(Vertices, 0, LockFlags.None); IndicesBuffer = new IndexBuffer(typeof(int), sizeof(int) * 6 * (NivelDeDetalle - 1) * (NivelDeDetalle - 1), GuiController.Instance.D3dDevice, Usage.WriteOnly, Pool.Default); int[] Indices = new int[sizeof(int) * 6 * (NivelDeDetalle - 1) * (NivelDeDetalle - 1)]; int i = 0; for (int v = 0; v < NivelDeDetalle - 1; v++) { for (int u = 0; u < NivelDeDetalle - 1; u++) { // Triangulo 1 |/ Indices[i++] = v * NivelDeDetalle + u; Indices[i++] = v * NivelDeDetalle + u + 1; Indices[i++] = (v + 1) * NivelDeDetalle + u; // Triangulo 2 /| Indices[i++] = (v + 1) * NivelDeDetalle + u; Indices[i++] = v * NivelDeDetalle + u + 1; Indices[i++] = (v + 1) * NivelDeDetalle + u + 1; } } IndicesBuffer.SetData(Indices, 0, LockFlags.None); // Carga el Effect para el SkyDome. Shader = Utiles.CargarShaderConTechnique("skybox.fx"); }
/// <summary> /// Metodo que carga los valores necesarios para inicializar el Oceano. /// </summary> public static void Cargar() { Device d3dDevice = GuiController.Instance.D3dDevice; // Creo la textura de reflexion surf_reflection = new Texture(d3dDevice, GuiController.Instance.Panel3d.Width, GuiController.Instance.Panel3d.Height, 1, Usage.RenderTarget, Format.A32B32G32R32F, Pool.Default); // Creo la textura de refraccion surf_refraction = new Texture(d3dDevice, GuiController.Instance.Panel3d.Width, GuiController.Instance.Panel3d.Height, 1, Usage.RenderTarget, Format.A32B32G32R32F, Pool.Default); // Cargo la textura de fresnel (relación entre los campos eléctricos transmitido y reflejado) "fresnel_water_sRGB.bmp" surf_fresnel = TextureLoader.FromFile(d3dDevice, Utiles.TexturasDir("fresnel_water_sRGB.bmp")); // Carga el shader del movimiento del oceano PerlinShader = Utiles.CargarShaderConTechnique("perlin.fx"); // Cargar informacion de vertices: (X,Y,Z) + coord textura _vertices = new CustomVertex.PositionNormalTextured[CANTIDAD_DE_VERTICES]; int i = 0; for (int x = -RADIO; x <= RADIO; x++) { for (int z = -RADIO; z <= RADIO; z++) { _vertices[i++] = new CustomVertex.PositionNormalTextured( new Vector3(x * DISTANCIA_ENTRE_VERTICES, ParametrosDeConfiguracion.Agua.NivelDelMar, z * DISTANCIA_ENTRE_VERTICES), _normal, ((float)(x + RADIO) / ((float)LARGO - 1)), ((float)(z + RADIO) / ((float)LARGO - 1)) ); } } ; // Creamos el VertexBuffer _vertexBuffer = new VertexBuffer(typeof(CustomVertex.PositionNormalTextured), CANTIDAD_DE_VERTICES, d3dDevice, Usage.Dynamic | Usage.WriteOnly, CustomVertex.PositionNormalTextured.Format, Pool.Default); // Almacenar información en VertexBuffer _vertexBuffer.SetData(_vertices, 0, LockFlags.None); //Creo el quadTree para este terreno QuadTree.Cargar(_pos.X, _pos.Z, TAMAÑO, GuiController.Instance.D3dDevice); // creo los indices para el IndexBuffer usando un array de int // Son por 3 vertices por triangulo y son 2 triangulos for (int z = 0; z < LARGO - 1; z++) { for (int x = 0; x < LARGO - 1; x++) { var lista = new List <int>(); //Primer Triangulo lista.Add(x + z * LARGO); lista.Add(x + 1 + z * LARGO); lista.Add(x + LARGO + 1 + z * LARGO); //Segundo Triangulo lista.Add(x + LARGO + 1 + z * LARGO); lista.Add(x + LARGO + z * LARGO); lista.Add(x + z * LARGO); //Cargo los indices en los nodos del QuadTree QuadTree.AgregarIndices(lista); } } ; //LOD I for (int z = 0; z < LARGO - 1; z = z + 2) { for (int x = 0; x < LARGO - 1; x = x + 2) { var lista = new List <int>(); //Primer Triangulo lista.Add(x + z * LARGO); lista.Add(x + 2 + z * LARGO); lista.Add(x + 2 * LARGO + 2 + z * LARGO); //Segundo Triangulo lista.Add(x + 2 * LARGO + 2 + z * LARGO); lista.Add(x + 2 * LARGO + z * LARGO); lista.Add(x + z * LARGO); //Cargo los indices en los nodos del QuadTree QuadTree.AgregarLODI(lista); } } ; //LOD II for (int z = 0; z < LARGO - 1; z = z + 4) { for (int x = 0; x < LARGO - 1; x = x + 4) { var lista = new List <int>(); //Primer Triangulo lista.Add(x + z * LARGO); lista.Add(x + 4 + z * LARGO); lista.Add(x + 4 * LARGO + 4 + z * LARGO); //Segundo Triangulo lista.Add(x + 4 * LARGO + 4 + z * LARGO); lista.Add(x + 4 * LARGO + z * LARGO); lista.Add(x + z * LARGO); //Cargo los indices en los nodos del QuadTree QuadTree.AgregarLODII(lista); } } ; // Genera los heightmaps entre los que interpola la superficie, se generan para 2,4 y 8 octavas para poder usar // las diferentes configuraciones cambiando los Modifiers. // 2 ocatavas (ruido fuerte). // perlin 1 textPerlinNoise1_2Octavas = PerlinNoise.GetNuevoHeightmap(Oceano.LARGO, Oceano.LARGO, 2, out PerlinNoise1_2Octavas); textPerlinNoise2_2Octavas = PerlinNoise.GetNuevoHeightmap(Oceano.LARGO, Oceano.LARGO, 2, out PerlinNoise2_2Octavas); // 4 ocatavas (ruido normal). textPerlinNoise1_4Octavas = PerlinNoise.GetNuevoHeightmap(Oceano.LARGO, Oceano.LARGO, 4, out PerlinNoise1_4Octavas); textPerlinNoise2_4Octavas = PerlinNoise.GetNuevoHeightmap(Oceano.LARGO, Oceano.LARGO, 4, out PerlinNoise2_4Octavas); // 8 octavas (ruido suave). textPerlinNoise1_8Octavas = PerlinNoise.GetNuevoHeightmap(Oceano.LARGO, Oceano.LARGO, 8, out PerlinNoise1_8Octavas); textPerlinNoise2_8Octavas = PerlinNoise.GetNuevoHeightmap(Oceano.LARGO, Oceano.LARGO, 8, out PerlinNoise2_8Octavas); // Carga los valores iniciales de la Matriz de Perlin Noise. PerlinNoise1 = PerlinNoise1_8Octavas; PerlinNoise2 = PerlinNoise2_8Octavas; // Carga los valores iniciales de la textura que se usara como Heightmap y Normalmap para la superficie del oceano. textPerlinNoise1 = textPerlinNoise1_8Octavas; textPerlinNoise2 = textPerlinNoise2_8Octavas; // Peso (alpha) para interpolar, usa el InterpoladorVaiven para ir alterandolo. interpoladorPerlinNoiseHeightmaps = new InterpoladorVaiven(); interpoladorPerlinNoiseHeightmaps.Min = 0; interpoladorPerlinNoiseHeightmaps.Max = 1; interpoladorPerlinNoiseHeightmaps.Speed = 0.5f; //guardar el stencil inicial //g_depthstencil = d3dDevice.DepthStencilSurface; }