formats

Monkey Dodge – Attempt at my own Flow Map

Published on March 19, 2012 by in Uncategorized

So this is how I attempted to create my own flowmap:

1) Took a screenshot of the scene from above:

2) Using GIMP, performed edge detection using Sobel size 3 filter

3) Performed Dilation 3 times.

4) Performed Brightness/Contrast adjustment, setting Brightness to 126, contrast to 127

5) I loaded the resulting image in MATLAB using:

im = imread(‘island.png’);

And treated it as a heightmap:

[xx,yy]=meshgrid(1:size(im,2),1:size(im,1));

to generate surface normals:

surfnorm(xx,yy,im);

6) I took the resulting normals:

[nxx, nyy, nzz] = surfnorm(xx, yy, im);

Created new rgb image:

nrgb = zeros(size(im,1),size(im,2),3);

And assigned x component of the normal to red channel, y component to green channel and ignored z component.

nrgb(:,:,1) = (nxx + 1) * 127;

nrgb(:,:,2) = (nyy + 1) * 127;

imwrite(uint8(nrgb), ‘island_nrgb.png’);

This resulted in the following image:

7) Back in GIMP, I removed the greenish/yellowish color filling most of the image and then using series of Dilations first without selection and later with inverted magic selection of the black background (magic wand on black background, then invert) obtained the following result:

8 ) I added the principal flow direction to normals by bumping red/green color curves appropriately:

9) Then filled what used to be black with pure yellow color (principal flow direction)

10) And finally applied some Gaussian blur (size 20)

11) The resulting renderings definitely show that something is going on around obstacles but I think it’s still not perfect.

If you have any ideas how this could be improved, feel free to leave a comment :) If you don’t have MATLAB, you can use a free alternative – Octave, it should also have the required functions! As usual, you’re more than welcome to play this fascinating monkey game ;)

DOWNLOAD: Monkey Dodge – Unity Game

 
 Share on Facebook Share on Twitter Share on Reddit Share on LinkedIn
No Comments  comments 
formats

Monkey Dodge – Adding bits of realism

Published on March 16, 2012 by in Uncategorized

I’m trying to add bits and pieces of modern rendering techniques which are supposed to make a game look more realistic. With moderate success so far… stuff used: Flow maps, Fur and Blur. Try to spot them in the picture ;)

 
 Share on Facebook Share on Twitter Share on Reddit Share on LinkedIn
No Comments  comments 
formats

Unity 3D Indie Realtime Water Reflection

Using the following two-pass shader I was able to get realtime water reflections in Indie/Free Edition of Unity 3D:

Shader "Custom/water_mirror" {
    Properties {
        _DiffuseTex ("Diffuse (RGB)", 2D) = "white" {}
        _NormalTex ("Normal (RGB)", 2D) = "bump" {}
        _SpecularTex ("Specular (R) Gloss (G)", 2D) = "gray" {}
        _WaterLevel ("Water Level", float) = 0
    }

    SubShader {

        Pass {
            Name "ContentBase"
            Tags {"LightMode" = "ForwardBase"}

            CGPROGRAM
                #pragma vertex vert
                #pragma fragment frag
                #pragma multi_compile_fwdbase
                #pragma fragmentoption ARB_precision_hint_fastest

                #include "UnityCG.cginc"
                #include "AutoLight.cginc"

                struct v2f
                {
                    float4  pos : SV_POSITION;
                    float2  uv : TEXCOORD0;
                    float3  lightDirT : TEXCOORD1;
                    float3  viewDirT : TEXCOORD2;
                    LIGHTING_COORDS(3,4)
                };

                v2f vert (appdata_tan v)
                {
                    v2f o;
                    o.pos = mul(UNITY_MATRIX_MVP, v.vertex);
                    o.uv = v.texcoord.xy;
                    TANGENT_SPACE_ROTATION;
                    o.lightDirT = mul(rotation, ObjSpaceLightDir(v.vertex));
                    o.viewDirT = mul(rotation, ObjSpaceViewDir(v.vertex));
                    TRANSFER_VERTEX_TO_FRAGMENT(o);
                    return o;
                }

                sampler2D _DiffuseTex;
                sampler2D _SpecularTex;
                sampler2D _NormalTex;

                float4 _LightColor0;

                float4 frag(v2f i) : COLOR
                {
                    float3 normal = normalize(tex2D(_NormalTex, i.uv).xyz * 2 - 1);
                    float NdotL = dot(normal, i.lightDirT);
                    float3 halfAngle = normalize(i.lightDirT + i.viewDirT);
                    float atten = LIGHT_ATTENUATION(i);
                    float3 specularity = (pow(saturate(dot(normal, halfAngle)), tex2D(_SpecularTex, i.uv).g * 200) * tex2D(_SpecularTex, i.uv).r)  * _LightColor0;

                    float4 result;
                    result.rgb = tex2D(_DiffuseTex, i.uv).rgb * NdotL * atten * _LightColor0 + specularity;
                    result.a = 0;
                    return result;
                }
            ENDCG
        }

        Pass {
            Name "ContentBase"
            Tags {"LightMode" = "ForwardBase"}
            Cull Front

            CGPROGRAM
                #pragma vertex vert
                #pragma fragment frag
                #pragma multi_compile_fwdbase
                #pragma fragmentoption ARB_precision_hint_fastest

                #include "UnityCG.cginc"
                #include "AutoLight.cginc"

                struct v2f
                {
                    float4  pos : SV_POSITION;
                    float2  uv : TEXCOORD0;
                    float3  lightDirT : TEXCOORD1;
                    float3  viewDirT : TEXCOORD2;
                    LIGHTING_COORDS(3,4)
                };

                float _WaterLevel;

                v2f vert (appdata_tan v)
                {
                    v2f o;
                    o.pos = mul(UNITY_MATRIX_MVP, v.vertex);
                    o.uv = v.texcoord.xy;
                    float4 p = mul(_Object2World, v.vertex);
                    p = float4(p[0], min(_WaterLevel, 2*_WaterLevel-p[1]), p[2], p[3]);
                    p = mul(_World2Object, p);
                    o.pos = mul(UNITY_MATRIX_MVP, p);
                    TANGENT_SPACE_ROTATION;
                    o.lightDirT = mul(rotation, ObjSpaceLightDir(v.vertex));
                    o.viewDirT = mul(rotation, ObjSpaceViewDir(v.vertex));
                    TRANSFER_VERTEX_TO_FRAGMENT(o);
                    return o;
                }

                sampler2D _DiffuseTex;
                sampler2D _SpecularTex;
                sampler2D _NormalTex;

                float4 _LightColor0;

                float4 frag(v2f i) : COLOR
                {
                    float3 normal = normalize(tex2D(_NormalTex, i.uv).xyz * 2 - 1);
                    float NdotL = dot(normal, i.lightDirT);
                    float3 halfAngle = normalize(i.lightDirT + i.viewDirT);
                    float atten = LIGHT_ATTENUATION(i);
                    float3 specularity = (pow(saturate(dot(normal, halfAngle)), tex2D(_SpecularTex, i.uv).g * 200) * tex2D(_SpecularTex, i.uv).r)  * _LightColor0;

                    float4 result;
                    result.rgb = tex2D(_DiffuseTex, i.uv).rgb * NdotL * atten * _LightColor0 + specularity;
                    result.a = 0;
                    return result;
                }
            ENDCG
        }
    }
}

The shader was based on some other shader demonstrating light computations in Unity3D. I added the second pass, made a mirror reflection of geometry against water and switched face culling to front. Hope somebody finds it useful ;)

 
 Share on Facebook Share on Twitter Share on Reddit Share on LinkedIn
1 Comment  comments 
formats

Monkey Dodge in Unity

Published on March 10, 2012 by in Uncategorized

After doing basics in Blender, my original plan was to teach my student how to port those games to GameKit and have them running on iOS and Android and earn some bucks, but in the end I’ve figured that it’s not reasonable to stick to open source tools. Unity3D is way better and supports lots of commercially interesting platforms like iOS, Android, Wii, PS3, XBOX360 and recently even… Flash, yes Adobe Flash (starting with Stage 3D/Molehill edition), you can put your 3D game on a web page just like that. Best of all, it’s free for PC and Mac. Linux is not supported ATM for game development but games can be played using Wine or Flash. For the kind of versatility and ease of use that Unity3D offers I think it’s worth to make a compromise. And so here comes Monkey Dodge in Unity. It looks a little bit different but the general idea is the same – don’t let the crates hit you. Stuff used: lightmaps, light flares, simple water, Blender import, animation, particle systems, skybox, blob shadows, JavaScript. So… a pretty decent introduction to Unity, I guess ;) Enjoy!

Download: Monkey Dodge in Unity

Download: Monkey Dodge in Unity, Flash version!

Try Flash version online here: http://monkey.staticloud.com/.

 
 Share on Facebook Share on Twitter Share on Reddit Share on LinkedIn
No Comments  comments 
formats

Monkey Dodge 2012.2

Here is how we’re progressing with my Blender teachings ;] As you can see, my student should now be able to create pleasingly looking scenes with some visually appealing details instead of just plain geometry. Some of the techniques involved: texture animation, normal textures, armature, IPO curves, skybox.

Download: monkey_dodge1.zip !!!

 
 Share on Facebook Share on Twitter Share on Reddit Share on LinkedIn
No Comments  comments 
formats

Monkey Dodge

I’ve been giving lessons in Blender recently. This is just a trivial little game I’ve created for my student to show him several concepts – dynamic shadows, object properties, texture coordinates animation, etc.

You can play it for a couple of minutes if you’d like: monkey_dodge.zip ;)

 
 Share on Facebook Share on Twitter Share on Reddit Share on LinkedIn
No Comments  comments 
formats

Partial replacement for MATLAB’s Image Processing Toolbox

I recently needed to replace the following functions from MATLAB’s Image Processing Toolbox: bwareaopen(), bwconncomp(), colfilt(), im2bw(), imclose(), imdilate(), imerode(), imfilter(), imopen() in order to remove it as a dependency of one of the new SPM toolboxes I’ve been working on. If you happen to be in a similar situation or just need this functions for other reasons, here they are (license: GPL). All of them behave exactly as their commercial counterparts, with the following exceptions:

  • Only 1-, 2- and 3-dimensional images are supported.
  • ls_imfilter(), ls_imdilate(), ls_imerode(), ls_imopen(), ls_imclose() use ls_improc.c as their core, ls_improc.c is multi-threaded and requires pthreads/pthreads-win32 to compile
  • ls_colfilt() takes function name instead of function handle as third argument. The function has to be on the MATLATB path. This can be easily fixed to use handles as well.
  • ls_imfilter() accepts only fixed numerical value or ‘symmetric’ modes of boundary processing. See ls_improc.c if you want to fix this.
  • ls_bwconncomp() requires spm_bwlabel() (part of SPM).

That’s it. Enjoy: ls_im.zip !

 
 Share on Facebook Share on Twitter Share on Reddit Share on LinkedIn
No Comments  comments 
formats

QSexyTooltip

Published on January 23, 2012 by in Qt

Here it goes (BSD Licensed)…

qsexytooltip.zip

You already know what it looks like:

Tested on Windows / Linux X11 (with/without compositing). Enjoy!

 
Tags: , , ,
 Share on Facebook Share on Twitter Share on Reddit Share on LinkedIn
No Comments  comments 
formats

VocaBreak 2012.1

Published on January 16, 2012 by in Qt, VocaBreak

Ok, here goes first version of VocaBreak in 2012. It features a new Qt Goodie I intend to publish soon – the QSexyToolTip class. Looks like this:

Pretty cool, huh? ;)

Enjoy: Vocabreak Setup!

 
Tags: , , ,
 Share on Facebook Share on Twitter Share on Reddit Share on LinkedIn
No Comments  comments 
formats

unionfs_by_intercept

Published on January 4, 2012 by in Uncategorized

Has it ever happened to you to be working on a system where you’re not completely in control (i.e. non-root)? Well, it happened to me more than once and quite recently I had to mount a UnionFS on such system – without any special privileges or cooperation from the system admin. Of course it turned out to be impossible using regular UnionFS/FUSE mechanism, so I had to prepare my own solution, based (as so many other cool hacks) on LD_PRELOAD trick and interception of file operations-related library calls. Obviously it’s not perfect because any piece of software that accesses files using other routines than the ones I’m trapping will circumvent this whole set-up. Nevertheless it turned out to be effective enough for my purposes, which in this case were to install TigerVNC, Fluxbox and Midnight Commander (+ their dependencies) from the official CentOS distribution packages into my home directory. For this particular bunch I had to override the following routines: open64, fopen64, access, stat, lstat, stat64, lstat64, __xstat, __lxstat, __xstat64, __lxstat64 and catopen. It was a bit surprising, especially the __* routines which I never even knew existed, but I managed to spot them using strace and objdump combo. That’s it for the introduction, now to the practical stuff…

To build, type:

gcc unionfs_by_intercept.c -shared -fPIC -ldl -o unionfs_by_intercept.so

Then, the usage is quite simple:

export UNIONFS=/path1:/path2:…:/pathN
export LD_PRELOAD=/path/to/unionfs_by_intercept.so

Optionally:

export UNIONFS_DEBUG=1

to get some debug messages printed to stderr.

The paths are unified at the root (/) level, e.g. specifying UNIONFS=/:/my/path would make the tricked applications see root as having the contents of original root plus whatever is in /my/path.

The code is published under revised BSD license: unionfs_by_intercept.c. In the rare event of actually finding it potentially useful, I hope it works for you ;)

 
Tags: , ,
 Share on Facebook Share on Twitter Share on Reddit Share on LinkedIn
No Comments  comments 
© 2010-2012 StanisÅ‚aw Adaszewski
credit