V

Avatar



Kinect Cloth Simulation

During my christmas holidays i had time to spare and some ideas to develop, so with all the party-feeling and booze i started working on the one i wanted the most. This is a cloth simulation running on the CPU which you can interact with using the kinect. With the 3d information from the kinect i’m able to change the cloth in some cool ways. The most interesting is plain and simple, offset each connection point by the depth at that point. With that done i had to go with the visual side (fun fun!), so i started playing with per-pixel lighting and some cool patterns.

Then added self-shadowing to the mixture and some color control just for the fun and looks of it.

In the end i thought it would be nice to take my carpet out to clean. Happy holidays!





CLNUI 4 Java (Kinect)

Kinect is a new product from Microsoft for XBox360. With an RGB camera, a 3D depth sensor (structured IR light) and  a multi-array microphone , it is able to compute a depth map, something very interesting for the interactive world of creativity and gaming. Nothing new as technology, but still, interesting and cheap. Since its release people have been trying to work in order to hack it and get it to work with windows and mac OS. Quite a few people have been working on drivers and a way to hack the gadget to get access to the color/depth data. One of these people is called Alex from Code Laboratories, the man behind the PS3eye camera drivers for PC’s. Recently, he released a new package (C and C#) that includes drivers and SDK for Kinect. I took the SDK and with  JNA i wrote a library for java that wraps the original one and also tries to make its use easy for starters.

A very early release is available http://victamin.googlecode.com/files/CLNUI4J_01.zip. This might or might not work out-of-the-box and it sure needs improvement and more work, but as they say, release early, release often. This package includes the library and basic examples running on Eclipse IDE and processing IDE (untested). It is known that this library does not work directly with Processing.

EDIT! Version 0.2 is now available at: http://victamin.googlecode.com/files/CLNUI4J_02.zip.
You can now find a friendly wrapper and a couple of examples to get you started.

I would love to get some feedback, so if you’re a Kinect owner and you’re into java/processing, give it a  spin and let me know how it works out for you.

Have fun.





DroidTUIO

DroidTUIO is my first application made for Android OS. It was created for OS version 2.1+  with OpenGL ES renderer. This application is available to the public as i hope to get feedback, so please, spare a few minutes and let me know how it worked out for you. Now.. on with the application.  First thing you need to do is to run the application and then press MENU/Settings. Enter your network IP and press connect. Once connected, use your phone to send TUIO events (2dcursor only for the moment). Have fun.

Update! The link has been removed as the application was removed from online. I will get a new link ASAP.





MSAOpenCL for Java and Processing

Recently I have been doing some work with OpenCL and i found myself messing up with old code and re-writing most of it .  At first it was interesting and quite funny but no more, so,  I thought it was time to make things easier for myself and just make things reusable by creating a wrapper which would wrap most of the boring and time-consuming parts. This would be a wrapper on OpenCL for Java and/or Processing. Well, a well known guy named Mehmet “Memo” Akten has done such a wrapper in C++ for the OpenFrameworks and Cinder libraries. I have ported it  to Java.

There are some problems with reading/writing from/to GL textures. For some reason it crashes on me. I have been working with JavaCL‘s author, so hopefully it will be working soon.

:: Download

Download it, install it and try it.
If you find any problems or if you have suggestions, let me know.

Have fun.





Ping-pong technique on GPU

Hello there. Here is a new tutorial, this time about ping-pong on the gpu. I’ve been wanting to write about it for sometime, finally it’s off my todo list. Let’s get down to business. Ping-pong technique is normally used with a shader that needs it’s result as a source parameter for it’s next iteration. This is usually used in the gpu as for now it is not possible to write a program’s result to itself, so, we’ll need another equal buffer to save the current result for how next step/iteration. That was too hard?

So imagine we have 2 image buffers Image1, Image2. Usually to change data from Image1, you would simply access it and write directly back to the same positioion. Now, when we’re talking about a shader fragment program we can’t simply do that. You may ask now, what’s the solution? Ping-pong it!

Here is what i’m talking about:

//
// Initialization
//
int W = 100;
int H = 100;
ImageArray = new int[2][W*H];
int CurrActiveBuffer = 0; // Current active buffer index
 
 
//
// Mainloop
//
for( int j=0; j<H; j++ )
{
	for( int i=0; i<W; i++ )
	{
		// ERROR! Write to same buffer. Not possible in gpu shader
		//Image1[i+j*W] = Image1[i+j*W] * 2;  // Mul by 2
 
		// Ping-pong version
		int src = CurrActiveBuffer; // Current active buffer (Input)
		int dest = 1-CurrActiveBuffer;  // Back buffer (Output)
		ImageArray[dest][i+j*W] = ImageArray[src][i+j*W] * 2;  // Mul by 2
	}
}
 
// Swap back and front buffers (read becomes write and vice-versa)
CurrActiveBuffer = 1-CurrActiveBuffer;    // CurrActiveBuffer ? 0 : 1;

As you can see we start with buffer 0. That’s where we get out data from (read) and write it to Buffer 1. Once the operation is done, we swap buffers every frame. This way we’ll be able to use last iteration’s data as input for the next iteration.

Now let’s put this in OpenGL language. I will be using a FrameBufferObject (FBO) and 2 textures here. The framebuffer will be holding to both textures as 2 Color Attachments. So let’s get coding:

//
// Initialization
//
int W = 100;
int H = 100;
int FboID;
int TexID[2];
int CurrActiveBuffer = 0;  // Current active buffer index
 
// Create the frambuffer
glGenFramebuffersEXT( 1, &FboID );
glBindFramebufferEXT( GL_FRAMEBUFFER_EXT, FboID );
 
// Create 2 textures for input/output.
glGenTextures( 2, TexID );
 
for( int i=0; i<2; i++ )
{
	glBindTexture( GL_TEXTURE_2D, TexID[i] );
	glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
	glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
	glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE );
	glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE );
        // RGBA8 buffer
	glTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA, W, H, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL );
	if( _hasMipmapping )  glGenerateMipmapEXT( GL_TEXTURE_2D );
}
 
// Now attach textures to FBO
int src = CurrActiveBuffer;
int dest = 1-CurrActiveBuffer;
glFramebufferTexture2DEXT( GL_FRAMEBUFFER_EXT, 
                           GL_COLOR_ATTACHMENT0_EXT, 
                           GL_TEXTURE_2D, TexID[src], 0 );
glFramebufferTexture2DEXT( GL_FRAMEBUFFER_EXT, 
                           GL_COLOR_ATTACHMENT1_EXT, 
                           GL_TEXTURE_2D, TexID[dest], 0 );
);
 
 
 
//
// Mainloop
//
int src = CurrActiveBuffer;
int dest = 1-CurrActiveBuffer;
 
FBO.Bind();
 
glDrawBuffer( dest );
 
glBindTexture( GL_TEXTURE_2D, TexID[src] );
ShaderProgram.SetTextureUniform( 0 );
RenderScene();
 
FBO.Unbind();
 
 
// Swap back and front buffers (read becomes write and vice-versa)
CurrActiveBuffer = 1-CurrActiveBuffer;    // CurrActiveBuffer ? 0 : 1;

Why would you want to ping-pong? Well for instance imagine you are doing a water effect in the gpu. You’ll need to access data from your previous buffer right? Using the CPU that would be trivial as you have the last frame’s memory buffer allocated somewhere which you can read/write access directly. That doesn’t really work on the gpu side that way (but we’re getting closer with CL, CUDA, DC)

Have fun.


Flattr this