Friday, April 15, 2011

PART 2 - Bigger resolution render, but same framing (safe area for 2D camera shakes) / PARTE 2 Renderear con margen para hacer camera shakes en 2D sin cambiar el encuadre


This could be used in any software (like Maya, Blender, 3Ds max, etc) but
 i'm a happy Softimage user since 1996, so i will use softimage as my base.
First of all, a little bit of background Math theory to make it easier ... i guess that you are familiar with trigonometry from secondary school... well i hope so, if not don't worry!, i'll guide you:  you always have to try to find a right triangle,  in our case, if we draw an imaginary line
 between the camera and an imaginary plane in Z space 
we could define a right triangle.
We know that: the tangent of an angle ß equals= the opposite side
 of the angle ß, divided by its adjacent side.  In the image below the opposite side being AB and the adjacent side being AC.  
So we know this, and we know the FOV which is the angle of the camera  (it doesn't  matter for this particular case if its horizontal or vertical because it works with both)
Let's suppose that the Z plane has a resolution 960 pixels, AB will be half of that, so it will have 480 pixels that is our length, and we know that we have a FOV which is the angle of the camera 
(we divide it by two because we are using half of it)
as i said before
 tan ß = AB / CA
we need to find CA... so, if we algebraicly change "CA" with "tan ß" we can assume that
CA = AB / tan ß
ok, so, the other plane (higher res) lies in the same position in Z, so we have the same CA, but we have more distance to render (AB') and a wider angle (FOV')
tan ß' = AB' / CA
now we know the new value of the tan of angle ß', we just need to go back from those strange values that tangent calculation results, and get a human readable angle, and for that 
we use the inverse function of the tangent, called the arctangent
atan (tan ß') = angle ß' degrees
since angle ß' is only half of FOV', we multiply it by 2 to get the full width.
FOV' = atan (tan ß') * 2
Hope that it was easy to understand.
in the next part i will show you how you put this into practice ...

Esto puede ser usado en cualquier software (Maya, Blender, 3Ds Max, etc) pero como soy un feliz usuario de Softimage desde 1996, lo voy a usar como mi base.
Antes que nada, un poco de teoria matematica de base para hacerlo mas facil...
supongo que te es familiar del secundario la trigonometría... eso espero, 
si no te es familiar, no desesperes!!,
yo voy a hacer de guia: siempre tienes que tratar de encontrar un triangulo rectangulo, 
en nuestro caso, si dibujasemos una linea imaginaria entre la camara y un plano
 imaginario en Z, podriamos definir un triangulo rectangulo.
 Sabemos que la tangente del angulo ß , es igual al lado opuesto del angulo ß, 
divido por su lado adyacente.
En la imagen el lado opuesto es AB y el lado adyacente es AC.  
Sabemos esto y sabemos el FOV que es el angulo de la camara (no importa
aqui para este caso en particular si es horizontal o vertical porque funciona igual)
Supongamos que el plano Z tiene una resolucion de 960 pixels, AB tendra la mitad,
nuestra longitud sera entonces 480 pixels, y sabemos nuestro FOV
que es el angulo de la camara (lo dividimos por dos porque solo usamos la mitad)
como dije antes
 tan ß = AB / CA
necesitamos encontrar el valor de CA ... entonces si reemplazo "CA" con "tan ß" podemos asumir que
CA = AB / tan ß
ok, entonces, el otro plano de mayor resolucion esta en la misma posicion en Z, tenemos
el mismo CA, pero mayor distancia a renderear (AB') y un angulo mayor (FOV')
tan ß' = AB' / CA
ahora sabemos el nuevo valor de la tangente del angulo ß', solo tenemos que
conseguir valores humanamente entendibles (en angulos) y para eso usamos
 la funcion inversa de la tangente, llamada arcotangente (atan en ingles)
atan (tan ß') = angulo ß' en grados
como el angulo ß' es la mitad del FOV', lo duplicamos para obtener todo el ancho.
FOV' = atan (tan ß') * 2
Espero que haya sido sencillo de entender.
en la proxima parte les mostrare como poner todo esto en practica

2 comments:

  1. Increible, muy claro.
    Voy a ver si lo hago add-on para Blender.
    Muy buena data.


    Gracias por compartir.

    pd: "feliz usuario"

    ReplyDelete
  2. A ver cuanto te duran las ganas de seguir escribiendo en los dos idiomas, jeje.

    Grax por compartir!! Te linkeo desde mi blog.

    ReplyDelete