Sunday, 27 January 2013

Sexy Unity Web Camera manipulator tutorial





Sexy Unity Web Camera Manipulator Tutorial ( Kinect OpenCV like )

DOWNLOAD PLUGIN:
http://dl.dropbox.com/u/106482752/KDManipulator.unitypackage

As all of us I’am very lazy guy. So I have created as simple way to use my manipulator as it possible. If you get my sources. You can get it by taking part in some simple contest.



http://forum.unity3d.com/threads/140213-Mage-Fight-a-game-based-on-mid-cost-Web-camera-motion-controller?p=1149084#post1149084

Anyway the package consist of 2 scripts:
KDManipulato.cs – do all dirty jobs for us
ManipulatorManager.cs – retrieve and setup manipulator

So we need to look deeper on ManipulatorManager:
using UnityEngine;
using System.Collections;

public class ManipulatorManager : MonoBehaviour {
               
                private WebCamTexture webcamTexture;
                private KDManipulator theManipulator;
               
                private float prevX;
                private float prevY;
                private float prevZ;
               
                // Use this for initialization
                void Start () {
               
                                webcamTexture = new WebCamTexture();       
                               
                                webcamTexture.requestedFPS = 30;
                                webcamTexture.requestedWidth = 320;
                                webcamTexture.requestedHeight = 240;
                               
                                webcamTexture.Play();
                               
                                theManipulator = new KDManipulator(webcamTexture.width, webcamTexture.height );                            
                               
                }
               
                // Update is called once per frame
                void FixedUpdate () {
               
                                theManipulator.ClearData();                     
                                theManipulator.ProcessImage( ref webcamTexture );
                               
                                // Now get coordinates
                                float x = ( theManipulator.GetMinX(theManipulator.BiggestAreaID) + theManipulator.GetMaxX(theManipulator.BiggestAreaID)) * 0.0015625f; //Normalized coeff
        float y = 1f - (( theManipulator.GetMinY(theManipulator.BiggestAreaID) + theManipulator.GetMaxY(theManipulator.BiggestAreaID)) * 0.00208333333333333333333333333333f); //Normalized coeff
        float z = theManipulator.GetArea(theManipulator.BiggestAreaID) * 1.3020833333333333333333333333333e-5f; // Normalize on 320x240 area
                               
                                x = ( x + prevX ) / 2f;
                                y = ( y + prevY ) / 2f;
                                z = ( z + prevZ ) / 2f;
                               
                                transform.position = new Vector3(x,y,z);                            
                               
                                prevX = x;
                                prevY = y;
                                prevZ = z;
                               
                }
}

theManipulator = new KDManipulator(webcamTexture.width, webcamTexture.height ); - Yes it is a dimension of a texture that manipulator will process. I have tooked 320x240, cuz larger textures produces lags and blabla. I also have overrode a constructor with minimum color filter and maximum color filter. By default it works with red markers.

So whats going on in FixedUpdate(). We process every fixed time a frame and retrieve coordinates. I just want to say that normalize coefficients will produce values [0..1] instead of 320x240 etc. Same on Z value. And previous coordinates is working like a some error correction of marker position.

You need to attach this script to an object. Or you can use it directly with small modificaiton. It works fine on Android, so should work on iPad/iPhone. Please don't ask me how it works on it, cuz i simply have no money for iPad, iPhone or Android.

If you have any questions how to use it. Please ask me.

And don't forget to achieve best result you should look like this:



konstantin dvornik

Monday, 14 January 2013

Unity 4 Cool & Sweet Terrain Tutorial with FREE assets




DOWNLOAD ASSETS LINK:
http://dl.dropbox.com/u/106482752/CoolTerrainTutorial.unitypackage

MIRROR ASSETS LINK:
https://drive.google.com/file/d/0BxgYUKP-c4dJM1hSWTZfQkFzZGM/edit?usp=sharing


WEB PLAYER LINK:
http://dl.dropbox.com/u/106482752/Terrain.html

ADDON ( Alpine Scene ):
http://dl.dropbox.com/u/106482752/Alpine.unitypackage

MIRROR:
https://drive.google.com/file/d/0BxgYUKP-c4dJd1BybU5wT2QtT2s/edit?usp=sharing
Part 2 Texturing
http://kostiantyn-dvornik.blogspot.com/2013/11/awesome-unity-texturing-terrain-tutorial.html





If you just started to learing Unity skip this tutorial. It is a sequence of tips and tricks not a click here, click there.








What do we need:
       1.       Unity
       2.       Geocontol 2

       3.       Image editor Like Photoshop or Gimp or Paint.Net but not MS Paint


1.      Set fractal scale to 8 in GeoControl
2.       Set heightmap resolution to 2048
3.       Export Terrain RAW 16 bit for Carra Heightmap from GeoControl
4.       Export Normal Map from Geocontol 

1.       Download assets that I provided
2.       You feel like a pro, delete terrain here and normal map.
3.       Import Heightmap from raw. Important: Size does matter. So set horizontal and vertical and height just nice. In picture above 5000x500x5000
4.       Set terrain Pixel Error to something like 10 or 20 if you don’t wanna kill your computer
5.       I have wrote a Terrain shader for you with a global normal map. Fuck yeahhh Unity 4 supports custom meterials on terrain! Drag your global normal map to that material.




 Lighting looks sucks! Everything messed up

Without normal map


With normal map






       1.       Open your image editor and flip normal map by Vertical axe.

       2.       Invert green and red channel too




1.       Texturize your terrain with terrain textures and normal maps
2.       I have fixed Terrain toolkit, now it’s support 2048 size terrains, but 4096 still not
3.       Add grass from package
4.       Fix grass tint and color to be just like on a terrain



TIPS AND TRICKS:
1.       I have used photo cubemaps from CGTextures.com
2.       I have set anisotropic filtering for global normal map to 8x
3.       Set FOG color as lowest color on a cubemap
4.       Use little tile on a Rock texture
5.       Not everything that look cool in GeoControl looks cool in Unity
6.       Set Directional light according to Sky light direction
7.       Set up nice view on camera.
8.       Amount of drawcalls should be playable.
Thanks! Have joy and fun!
Kostiantyn Dvornik
Konstantin








Thursday, 3 January 2013

Game Idea :: Whatta aqualung 2

konstantin dvornik

Title: Whatta aqualung 2

Huuuge city moving around the Earth on a monoroil in a 4D space. People with plugable legs in aqualungs fight againts monsters by coodrinate system of Fedoseev. Steve Jobs moved into space on a huge iPad (1/0). Now he replaces the sun with the sun app and ask people for pay for it in iTunes. Next parts Whatta aqualung 4 Whatta aqualung 8 Whatta aqualung 16.