Texturas
description
Transcript of Texturas
![Page 1: Texturas](https://reader035.fdocumento.com/reader035/viewer/2022070404/56813bdb550346895da5058f/html5/thumbnails/1.jpg)
TexturasTexturasTexturasTexturasVisualización Computacional
II
![Page 2: Texturas](https://reader035.fdocumento.com/reader035/viewer/2022070404/56813bdb550346895da5058f/html5/thumbnails/2.jpg)
Horarios (again…)Horarios (again…)
LUNES 26/10: Aula 2 Facultad (19 hs.): Introducción
MARTES 27/10: Aula 2 Facultad (19 hs.): Texturas MIERCOLES 28/10: Aula 2 Facultad (19 hs.): Técnicas de iluminación avanzadas
JUEVES 29/10: Aula 3 Facultad (19 hs.): Sombras
VIERNES 30/10: Aula 2 Facultad (19 hs.): Animación - [Física]
LUNES 2/11: A determinar: [Física] - Optimización
![Page 3: Texturas](https://reader035.fdocumento.com/reader035/viewer/2022070404/56813bdb550346895da5058f/html5/thumbnails/3.jpg)
Crysis, Crytek - EA
![Page 4: Texturas](https://reader035.fdocumento.com/reader035/viewer/2022070404/56813bdb550346895da5058f/html5/thumbnails/4.jpg)
Texturas - Texturas - ResumenResumen
¿Por qué usar texturas?IntroducciónConceptos básicos
InterpolaciónMapeoTilingMipmapping
Usos adicionalesTexturas proceduralesLightmapsBump MappingEnvironment Mapping
![Page 5: Texturas](https://reader035.fdocumento.com/reader035/viewer/2022070404/56813bdb550346895da5058f/html5/thumbnails/5.jpg)
Texturas - Texturas - ¿Por qué usar texturas?¿Por qué usar texturas?
¿Podemos representar todo con geometría?
![Page 6: Texturas](https://reader035.fdocumento.com/reader035/viewer/2022070404/56813bdb550346895da5058f/html5/thumbnails/6.jpg)
Texturas - Texturas - ¿Por qué usar texturas?¿Por qué usar texturas?
Sería costoso y complicado representar TODO con geometría.
Ej. MUY Simple: ¿Qué pasaría con una etiqueta?.
![Page 7: Texturas](https://reader035.fdocumento.com/reader035/viewer/2022070404/56813bdb550346895da5058f/html5/thumbnails/7.jpg)
Texturas - Texturas - ¿Por qué usar texturas?¿Por qué usar texturas?
![Page 8: Texturas](https://reader035.fdocumento.com/reader035/viewer/2022070404/56813bdb550346895da5058f/html5/thumbnails/8.jpg)
Texturas - Texturas - ¿Por qué usar texturas?¿Por qué usar texturas?
The Guild II - 4Head Game StudiosUnreal 3 – Epic Studios
![Page 9: Texturas](https://reader035.fdocumento.com/reader035/viewer/2022070404/56813bdb550346895da5058f/html5/thumbnails/9.jpg)
Texturas - Texturas - IntroducciónIntroducción
Podemos utilizar la textura para modifcar alguna o todas las vars / ctes. de la ecuación de iluminación (color de pixel, color difuso, alterar normal, etc.)
Nluces
pp
nsdpaa KKIIKI
i
0
coscos
Textura usada como color cte.
Textura usada como color difuso.
Textura usada como normal map.
![Page 10: Texturas](https://reader035.fdocumento.com/reader035/viewer/2022070404/56813bdb550346895da5058f/html5/thumbnails/10.jpg)
Texturas - Texturas - IntroducciónIntroducción
Para cada polígono se establece una correspondencia con la textura.
![Page 11: Texturas](https://reader035.fdocumento.com/reader035/viewer/2022070404/56813bdb550346895da5058f/html5/thumbnails/11.jpg)
Texturas - Texturas - Mapeo eMapeo e InterpolaciónInterpolación
¿Podemos interpolar de manera directa linealmente los valores en el espacio de la pantalla?.
(0,0) (1,0)
(0,1)
![Page 12: Texturas](https://reader035.fdocumento.com/reader035/viewer/2022070404/56813bdb550346895da5058f/html5/thumbnails/12.jpg)
Texturas - Texturas - Mapeo eMapeo e InterpolaciónInterpolación
textura resultado esperado
Interpolación lineal en espacio de coord. de pantalla:
![Page 13: Texturas](https://reader035.fdocumento.com/reader035/viewer/2022070404/56813bdb550346895da5058f/html5/thumbnails/13.jpg)
Texturas - Texturas - Mapeo eMapeo e InterpolaciónInterpolación
Podemos reducir los errores subdividiendo el modelo en triangulos más pequeños.
Igualmente persisten los “errores”.
![Page 14: Texturas](https://reader035.fdocumento.com/reader035/viewer/2022070404/56813bdb550346895da5058f/html5/thumbnails/14.jpg)
Texturas -Texturas - Mapeo eMapeo e InterpolaciónInterpolación
Los pasos uniformes de la interpolación en el plano de la pantalla no se corresponden con los pasos uniformes de la interpolación a lo largo del triángulo.
Soluc.: Interpolación
en el espacio
[automática x OpenGL]
![Page 15: Texturas](https://reader035.fdocumento.com/reader035/viewer/2022070404/56813bdb550346895da5058f/html5/thumbnails/15.jpg)
Texturas – Texturas – MapeoMapeo
Se especifica una coordenada (u,v) para cada vértice.
Coordenadas canónicas (0,0) (1,0)
(0,0,0) (3,0,0)
(0,3,0)
(0,0)
(1,1)
glEnable(GL_TEXTURE);
glBindTexture(texID);
glbegin(GL_TRIANGLES);
glVertex3f(0.0, 0.0, 0);
glTexCoord2f(0,0);
glVertex3f(0.0, 3.0, 0);
glTexCoord2f(0,1);
glVertex3f(3.0, 0.0, 0);
glTexCoord2f(1,0);
glend;
![Page 16: Texturas](https://reader035.fdocumento.com/reader035/viewer/2022070404/56813bdb550346895da5058f/html5/thumbnails/16.jpg)
Texturas - Texturas - Tipos de mapeoTipos de mapeo
Generar automáticamente las
coordenadas de textura:
glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_SPHERE_MAP);
glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_SPHERE_MAP);
glEnable(GL_TEXTURE_GEN_S);
glEnable(GL_TEXTURE_GEN_T);
Tipos: GL_OBJECT_LINEAR, GL_EYE_LINEAR, GL_SPHERE_MAP, GL_REFLECTION_MAP
![Page 17: Texturas](https://reader035.fdocumento.com/reader035/viewer/2022070404/56813bdb550346895da5058f/html5/thumbnails/17.jpg)
Texturas - Texturas - MapeoMapeo
Truco:
Coordenadas de textura en una matriz adicional (Texture Matrix).
Aplicar transformaciones a esa matriz para modificar las coordenadas.
![Page 18: Texturas](https://reader035.fdocumento.com/reader035/viewer/2022070404/56813bdb550346895da5058f/html5/thumbnails/18.jpg)
Texturas - Texturas - TilingTiling
tiles sin bordestiles con bordes visibles(0,0) (3,0)
(0,3)
(0,0)
(1,1)
(0,0) (3,0)
(0,3)
(0,0)
(1,1)
![Page 19: Texturas](https://reader035.fdocumento.com/reader035/viewer/2022070404/56813bdb550346895da5058f/html5/thumbnails/19.jpg)
Texturas - Texturas - MipmappingMipmapping
Del Latín “Multum In Parvo” (muchos en un lugar pequeño).
gluBuild2DMipmaps(GL_TEXTURE_2D, GL_RGBA, 128, 128, GL_RGBA, GL_UNSIGNED_BYTE, image);gluBuild2DMipmaps(GL_TEXTURE_2D, GL_RGBA, 128, 128, GL_RGBA, GL_UNSIGNED_BYTE, image);
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
![Page 20: Texturas](https://reader035.fdocumento.com/reader035/viewer/2022070404/56813bdb550346895da5058f/html5/thumbnails/20.jpg)
Texturas - Texturas - MipmappingMipmapping
Se pueden almacenar de manera compacta.
Mínimo overhead para mantener un MIP map.
Mip map de 10 niveles.
Almac. en memoria
![Page 21: Texturas](https://reader035.fdocumento.com/reader035/viewer/2022070404/56813bdb550346895da5058f/html5/thumbnails/21.jpg)
Texturas - Texturas - VariablesVariables
![Page 22: Texturas](https://reader035.fdocumento.com/reader035/viewer/2022070404/56813bdb550346895da5058f/html5/thumbnails/22.jpg)
Texturas - MaskingTexturas - Masking
“Recortar” parte de un gráfico (según color o siguiendo un patrón)
Dar aspecto de transparencia a lo que se ha recortado
![Page 23: Texturas](https://reader035.fdocumento.com/reader035/viewer/2022070404/56813bdb550346895da5058f/html5/thumbnails/23.jpg)
Texturas - MaskingTexturas - Masking
Alpha Test:
Se hace sobre el valor de la componente alpha que se está evaluando.
Una función y un valor de referencia, según el resultado se acepta o se rechaza el fragmento.
glEnable(GL_ALPHA_TEST);glAlphaFunc (GL_GREATER, 0.1);
GL_NEVER: Nunca acepta el fragmento.
GL_ALWAYS: Siempre acepta el fragmento.
GL_LESS: Acepta el fragmento si Alpha origen < Alpha referencia
GL_LEQUAL: Acepta el fragmento si Alpha origen <= Alpha referencia
GL_EQUAL: Acepta el fragmento si Alpha origen = Alpha referencia
GL_GEQUAL: Acepta el fragmento si Alpha origen >= Alpha referencia
GL_GREATER: Acepta el fragmento si Alpha origen > Alpha referencia
GL_NOTEQUAL: Acepta el fragmento si Alpha origen <> Alpha referencia
![Page 24: Texturas](https://reader035.fdocumento.com/reader035/viewer/2022070404/56813bdb550346895da5058f/html5/thumbnails/24.jpg)
Texturas - MaskingTexturas - Masking
glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA)
glEnable(GL_BLEND)
Alpha Blending:
Se hace sobre el valor de la componente alpha que se está evaluando, combinando un fragmento con otro
Probar!! (uds.)
![Page 25: Texturas](https://reader035.fdocumento.com/reader035/viewer/2022070404/56813bdb550346895da5058f/html5/thumbnails/25.jpg)
Texturas - Texturas - Uso de lucesUso de luces
•¿Cuántas luces vemos en la escena?
•¿Cálculo?
•¿Ideas, opciones?
![Page 26: Texturas](https://reader035.fdocumento.com/reader035/viewer/2022070404/56813bdb550346895da5058f/html5/thumbnails/26.jpg)
Texturas - Texturas - LightmapsLightmaps
La utilización de luces brinda realismo a nuestras escenas, pero ¿cuál es el límite?.
Notar que la mayoría de luces en una escena son estáticas.
¿Se puede aprovechar de alguna manera esto para precalcular sombras e iluminaciones?.
+ =
![Page 27: Texturas](https://reader035.fdocumento.com/reader035/viewer/2022070404/56813bdb550346895da5058f/html5/thumbnails/27.jpg)
Texturas - Texturas - LightmapsLightmaps
Dibujar la geometría dos veces con distinta textura.
Costo memoria.
Costo GPU.
Lightmaps de poca resolución.
¿Coordenadas?.
![Page 28: Texturas](https://reader035.fdocumento.com/reader035/viewer/2022070404/56813bdb550346895da5058f/html5/thumbnails/28.jpg)
Texturas - Texturas - LightmapsLightmaps
Mejora: Utilización de multitextura
Diferentes texturas a un mismo objeto.
Coordenadas de texturas independientes.
¿Posibles usos?.
![Page 29: Texturas](https://reader035.fdocumento.com/reader035/viewer/2022070404/56813bdb550346895da5058f/html5/thumbnails/29.jpg)
Texturas - Texturas - Bump MappingBump Mapping
Usar la textura para alterar la normal del polígono.
Esfera con textura (difuso) Bump Map Esfera con textura (difuso y bump map)
Ganar detalle sin incrementar la geometría
![Page 30: Texturas](https://reader035.fdocumento.com/reader035/viewer/2022070404/56813bdb550346895da5058f/html5/thumbnails/30.jpg)
Texturas - Texturas - Bump MappingBump Mapping
Tomar la textura como una función de desplazamiento.
Calcular la normal a partir de esa función.
Diferentes opciones de implementación DESORDEN
![Page 31: Texturas](https://reader035.fdocumento.com/reader035/viewer/2022070404/56813bdb550346895da5058f/html5/thumbnails/31.jpg)
Texturas - Texturas - Bump Mapping (Fake)Bump Mapping (Fake)
Zonas negras Menor relieve
Zonas blancas Mayor relieve
Utilización de multitexturas.
Desplazamiento de la textura de Bump de acuerdo a la luz.
![Page 32: Texturas](https://reader035.fdocumento.com/reader035/viewer/2022070404/56813bdb550346895da5058f/html5/thumbnails/32.jpg)
Texturas - Texturas - Bump Mapping (Per Pixel)Bump Mapping (Per Pixel)
Utilización de un Normal Map.
Nuevas aproximaciones en tiempo real mediante shaders.
Idea de Per-pixel lighting.
Los componentes XYZ son reescalados del rango [-1, 1] a [0, 255]
Por ejemplo el vector [0, 0, 1] (Normal perpendicular entrante) sería convertido a [127, 127, 255], el azul violáceo q predominan en estas texturas.
![Page 33: Texturas](https://reader035.fdocumento.com/reader035/viewer/2022070404/56813bdb550346895da5058f/html5/thumbnails/33.jpg)
Texturas - Texturas - Bump MappingBump Mapping
norm = vec3(texture2D(sampler2d, vec2 (gl_TexCoord[0])));
norm = (norm - 0.5) * 2.0;
intensity = max(dot(lightDir, norm), 0.0) * diffuseFactor;
Norm: Valor de 0 a 1
Norm - 0.5: Valor de -0.5 a 0.5
(Norm - 0.5) * 2: Valor de -1 a 1
![Page 34: Texturas](https://reader035.fdocumento.com/reader035/viewer/2022070404/56813bdb550346895da5058f/html5/thumbnails/34.jpg)
Texturas - Texturas - Environment MappingEnvironment Mapping
Objetivo: Renderizar un objeto como si fuera perfectamente reflectivo.
Las reflexiones que vemos en el objeto dependen de:
Posición del espectador.
Forma del objeto.
Environment Map es una aproximación (se asume que los objetos del entorno están muy lejos del objeto reflectivo)
![Page 35: Texturas](https://reader035.fdocumento.com/reader035/viewer/2022070404/56813bdb550346895da5058f/html5/thumbnails/35.jpg)
Texturas - Texturas - Environment MappingEnvironment Mapping
Se utiliza la dirección del rayo reflectado para indexar una posición en una textura con coordenadas esféricas.
Se asume que todos los rayos comienzan en el mismo punto.
![Page 36: Texturas](https://reader035.fdocumento.com/reader035/viewer/2022070404/56813bdb550346895da5058f/html5/thumbnails/36.jpg)
Texturas - Texturas - Environment MappingEnvironment Mapping
![Page 37: Texturas](https://reader035.fdocumento.com/reader035/viewer/2022070404/56813bdb550346895da5058f/html5/thumbnails/37.jpg)
Texturas - Texturas - Texturas proceduralesTexturas procedurales
F(x,y,z) color
![Page 38: Texturas](https://reader035.fdocumento.com/reader035/viewer/2022070404/56813bdb550346895da5058f/html5/thumbnails/38.jpg)
Texturas - Texturas - Texturas proceduralesTexturas procedurales
Ventajas:Fácil de implementar en un raytracer/shaders.
Menos espacio.
Resolución infinita.
Desventajas:No intuitivo.
Sirven para situaciones puntuales.
![Page 39: Texturas](https://reader035.fdocumento.com/reader035/viewer/2022070404/56813bdb550346895da5058f/html5/thumbnails/39.jpg)
Texturas - Texturas - Texturas proceduralesTexturas procedurales