Vortex Visualization Development

From Official Kodi Wiki
Jump to: navigation, search
Home icon grey.png   ▶ Development ▶ Vortex Visualization Development

This page or section has not been updated in a long time, no longer applies, refers to features that have been replaced/removed, and/or may not be reliable.

This page is only kept for historical reasons, or in case someone wants to try updating it.

Vortex Visualization Development


1 Coding your own presets and transitions for Vortex

1.1 The filetypes

  • *.vtx - preset file, the actual visualization
  • *.tra - transition file, changes from current preset to the next preset

1.2 The template

<python>//filename - TheTransitionOrPresetFilename.Extension //author - your name void Init() {

 //TODO: put your initializationcode here


void Render() {

 //TODO: put your stunning graphics here


1.3 The coding

If you did some coding before, go on reading. If not, get your self some knowledge with coding c/c++ and return after that.

1.3.1 The datatypes

  • float
  • int
  • bool
  • Texture
  • Map
  • VoicePrint
  • Tunnel

1.3.2 The operators and math-functions

  • + - Addition
  • - - Subtraction
  • * - Multiplication
  • = - Equality (left side will be made same as right side)
  • += - same as left = left + right
  • -= - same as left = left - right
  • Cos(x) - Cosine of x in radians
  • Sin(x) - Sine of x in radians
  • Rand() - returns a random float between 0 and 1
  • Pow(a,x) - a to the power of x
  • Fabs(a) - makes float a an absolute value

Boolean operators

  • > - returns true if left is greater than right
  • < - returns true if right is greater than left
  • >= - returns true if left is greater or equal to right
  • <= - returns true if right is greater or equal to left
  • == - returns true if right is equal to left
  • != - returns true if right is not equal to left
  • && - returns left AND right
  • || - returns left OR right

1.3.3 The built-in VORTEX-variables

  • TREBLE - returns the treble level (float, values between -1 and 1)
  • MIDDLE - returns the middle level (float, values between -1 and 1)
  • BASS - returns the bass level (float, values between -1 and 1)
  • TIMEPASS - returns the time passed since the last Render()-Call (float, value in seconds)
  • FINISHED - set this to true if your tranisition has finished (boolean)

1.3.4 The built-in VORTEX-constants Blendmodes
  • const int BLEND_OFF = 0; - disables Blending
  • const int BLEND_ADD = 1; - adds color values
  • const int BLEND_MOD = 2; - modulated blend
  • const int BLEND_MAX = 3; - finalcolor is the brightest color PrimitiveTypes
  • const int PRIM_POINTLIST = 1; - vertices are rendered as individual points
  • const int PRIM_LINELIST = 2; - vrtices form lines (vertex 1&2, vertex 3&4 ...)
  • const int PRIM_LINELOOP = 3; - vertices form a loop (first and last vertex are connected)
  • const int PRIM_LINESTRIP = 4; - vertices form a continuous line (line from 1 to 2, 2 to 3 ...)
  • const int PRIM_TRIANGLELIST = 5; - vertices build triangles (1&2&3, 4&5&6 ...)
  • const int PRIM_TRIANGLESTRIP = 6; - vertices build continuous triangles (1&2&3, 2&3&4, 3&4&5...)
  • const int PRIM_TRIANGLEFAN = 7; - vertices build a fan of triangles (1&2&3, 1&3&4, 1&4&5...)
  • const int PRIM_QUADLIST = 8; - vertices build a quad: the vertices have to be ordered clockwise (1&2&3&4, 5&6&7&8...)
  • const int PRIM_QUADSTRIP = 9; - vertices build a continuous band of quads (1&2&3&4, 3&4&5&6...) Fillmodes
  • const int FILLMODE_SOLID = 0; - all trangles a rendered as filled triangles
  • const int FILLMODE_WIREFRAME = 1; - only the edges of the triangles are rendered StandardTextures
  • const int TEXTURE_FRAMEBUFFER = 1; - a texture showing the current framebuffer
  • const int TEXTURE_NEXTPRESET = 2; - a texture showing the next preset in action (used for transitions)
  • const int TEXTURE_CURRPRESET = 3; - a texture showing the current preset in action (used for transitions)
  • const int TEXTURE_ALBUMART = 4; - a texture showing the coverart of the currently playing song, if none available a default image will be used

1.3.5 The built-in VORTEX-functions

  • GetSpec(int a) - returns the spectrum value at the given position

1.3.6 The built-in VORTEX-functions for graphics

  • gfxSetTexture(Texture texture) - specifies the texture to be used for the next drawing calls
  • gfxSetRenderTarget(Texture texture) - specifies the texture as a rendertarget (output not to screen but to the texture)
    • gfxSetRenderTarget(Map map) - specifies the map as a rendertarget (output not to screen but to the map)
    • gfxSetRenderTarget(0) - specifies the screen as rendertarget (default)
  • gfxSetEnvTexture(Texture texture) - specifies the Texture as environment texture
  • gfxTranslate(float x, float y, float z) - adds a translation to the current view transformation (see CoordinateSystem)
  • gfxRotate(float angle, float axisX, float axisY, float axisZ) - adds a rotation to the current view transformation (float angle (degree), float axisX,axisY,axisZ form an axis from origin to the given coordinates (the rotation axis))
  • gfxColour(float r, float g, float b, float a) - set the color for the next drawing calls (RGB + Alpha)
  • gfxCube(a,b, c, d,e,[f]) (Using f coz I use f for something else)
  • gfxTexCoord(float tu, float tv) - set the texturecoordinates for the next vertex
  • gfxVertex(x,y,z) - adds a vertex to the renderingpipeline
  • gfxSetBlendMode(BLENDMODE) - set the blendmode (blending is used is a pixel already has a colorvalue, and an object needs to be rendered to this position)
  • gfxBegin(PRIMITIVETYPE) - sets the way the following vertices should be handled, reqires a closing gfxEnd()
  • gfxEnd() - tells the renderingpipeline that no more vertices should be rendered with to declared PRIMITIVETYPE
  • gfxPushMatrix() - pushes the current matrix on the stack
  • gfxPopMatrix() - pops the topmost matrix from the stack
  • gfxClear(0) -
  • gfxSetAspect(0) - sets the aspectratio of the screen
  • gfxTexRect(float left, float right, float top, float bottom) - draws a rectangle to the given coordinates, the texture is drawn completely on that rectangle
  • gfxLookAt(Cos(tn*1.23)*5,Sin(tn)*5,(tm*2)-1,Cos(tn*0.6734)*2,Sin(tn*0.2143)*2,(tm*2)+8,0,1,0 ) - calculates a viewmatrix to point to a desired point in space

1.3.7 The MAP-Datatype

Maps are some special kind of textures. If you use them like textures without any special handling, then all youll get is some black texture. But if you render something to them using the gfxSetRenderTarget-Method you can do some very cool and unique effects.

The map has always a dimension of 32x24!

Now the Step-By-Step-Guide to Maps:

  • create a new Map: <php>Map map;</php>
  • set the maps values:

<php> for (int y = 0; y < 24; y++) {

 for (int x = 0; x < 32; x++)
   map.SetValues(x, y, speedX, speedY, attR, attG, attB);

} </php> Here we used the SetValues-method of the map datatype. This function is where all the magic happens.

The x and y values only specify the position for the following values.

The speedX and speedY values move the pixel inside the map. if you set all speedX and speedY you'll get 24x32 little icons of what you rendered to the map. if you set them to 0 you see everything you rendered in the last frames on the texture too. So for example to move the last frames slowly to the top you have to set the speedX to 0 (you want no motion along the x axis) and the speed Y to some value other than 0.

The attR, attG, attB values specify how the color of the pixels change over time. For each basecolor you can specify how strong its filtering should be. If set to 0 the basecolor is filtered out, if 1 the basecolor will not be touched.

  • render the map

<php>map.Render();</php> Here the values you applied to the map will be used to transform the previous data in the map.

  • set the map as rendertarget


  • render something to the map


  • change the rendertarget to default


  • do something with the map

Now you can do something with the map. For example you can just put it on a rectangle and render it to screen.

2 The graphics basics

2.1 The coordinatesystem

The coordinate system used by vortex is a left handed coordinate system. This mean that the x-axis points in the same direction as your screens horizontal edges (from left to right), the y-axis points up and the z-axis point into the screen. The origin of this coordinate system is right in the center of your screen (if no transformation is added to the view matrix)

The texture coordinates have their origin in the top-left corner of the texture. tu points from left to right, tv from top to bottom.

2.2 The matrix transformations

Initially when you didnt apply any transformations the transformation matrix is the identity. This matrix leaves the vertices at their specified position. To get some cool motion into your preset you have to apply some transformation to the matrix. If you want to apply multiple transformations, you have to mind the order in which you apply the transformations: e.g: you want to rotate an object around itself and put further away into the screenspace. so you have to apply the rotation before the translation. in your code it looks like this:

<python> gfxTranslate(0,0,5); // this is the second transformation, it pushes the object into your screen gfxRotate(angle, 1,0,0); // this is the first transformation applied to the object, it rotates the object around the x-axis RenderSomeCoolObjectAtOrigin(); // the initial Object is rendered around the origin </python>

If you look at this code, then you notice, that the order of appliance to exactly the opposite of the appearance order in the code. So the later in the code, the earlier applied on the object.

To store some transformation for returning to it on a later renderingstep, you can use the gfxPushMatrix()-method. This methos pushes the matrix on a stack. I f you want to return to this matrix, then you can pop it off the stack. Remember that only the topmost matrix is popped off the stack. So if you push two matrices on the stack, and you want to return to the first pushed matrix, then you have to pop twice.

<python> gfxTranslate(0,0,5); // this is the second transformation, it pushes the object into your screen gfxPushMatrix(); // this stores the matrix on the stack gfxRotate(angle, 1,0,0); // this is the first transformation applied to the object, it rotates the object around the x-axis RenderSomeCoolObjectAtOrigin(); // the initial Object is rendered around the origin gfxPopMatrix(); // this gets the topmost matrix from the stack RenderSomeCoolObjectAtOrigin(); // the initial Object is rendered around the origin </python>

the result of this snippet are two objects: the first is rotated and translated, the second is only translated. |}

3 The examples

3.1 The preset

This is an example for a simple preset. it rotates some albumart-textured cube around itself (the rotation is defined by the music). The code for this example is written by MrC (I only put in the comments). <python> // AlbumArtCube.vtx // Author - MrC

float time = 0; float rx,rxamt,ry,ryamt;

void Render() {

 // time stores the the elapsed time since the preset started
 time += TIMEPASS;                                     
 // set the coverart of the current song as texture
 // push the object into the screen. the distance is calculated from the current TREBLE-value                    
 gfxTranslate(0, 0, 2.0f - (TREBLE * 0.5));            
 // change the rotation-direction for rotations around the x axis according to the BASS-value
 if (BASS>0.3) rxamt = 1;                              
 if (BASS<-0.3) rxamt = -1;
 // change the rotation-direction for rotations around the y axis according to the TREBLE-value
 if (TREBLE>0.3) ryamt = 1;                            
 if (TREBLE<-0.3) ryamt = -1;
 //calculate the current rotation angle from direction and elapsed time
 rx = rx + (rxamt*TIMEPASS);
 ry = ry + (ryamt*TIMEPASS);
 //add some continuous rotation to the preset
 // rotate around x-axis. Because of the previous rotation around y you have to put the z axis in here
 // this is the first transformation. it rotates around the y axis
 // set some color here
 gfxColour(1, 1, 1, 1);
 // render a cube textured with the previously definded texture, the albumart
 gfxCube(-0.25f, -0.25f, -0.25f, 0.25f, 0.25f, 0.25f);

} </python>

3.2 The transition

This transition slides in the new preset. (Code: MrC)

The only difference between presets and transitions is that you have to specify when the transition is over by using the FINISHED variable. <python> // Slide.tra // Author - MrC

int direction; float position;

// here we initialize some variables void Init() { position = 0;

// the direction is randomly chosen direction = Rand() * 4; }

void Render() {

 // calculate the new position from the elapsed time

position += TIMEPASS*0.75;

// end the transition if the position is greater or equal to 1

 if (position >= 1.0f)
 FINISHED = true;
 // set the current preset as texture
 // translate the rectangle (rendered below) to the magic position of 2.414. 
 // If you translate some rectangle with size -1,1,1,-1 by 2.414 into screen 
 // the result is exactly as big as the screen, so you will see no difference 
 // between the previously rendered preset and the transition, that renders the
 // preset on a rectangle.
 gfxTranslate(0, 0, 2.414);
 gfxColour(1, 1, 1, 1);
 gfxTexRect(-1, 1, 1, -1);
 // set the next preset as texture
 // choose direction

if (direction == 0) { // Top to bottom float i = -3 + position * 2;

// draws a rectangle initially out of screen and by time it slides down. gfxTexRect(-1, i+2, 1, i); }

// same as above but other direction else if (direction == 1) { // Bottom to top float i = 1 - (position * 2); gfxTexRect(-1, i+2, 1, i); } else if (direction == 2) { // Left to right float i = -3 + position * 2; gfxTexRect(i, 1, i+2, -1); } else { // Right to left float i = 1 - position * 2; gfxTexRect(i, 1, i+2, -1); }

} </python>

Personal tools

Wiki help