Saturday, March 22, 2014

Voxel Engine Project (GitHub Repository)

Some people want to contribute to the VoxelEngine demo and asked me to create a repository on GitHub. So here is the repository url:

https://github.com/charlesbarros/VoxelEngine

I also updated the project to Unity 4.3. ;)

Monday, October 7, 2013

Voxel Engine "Based" Projects

Recently I had a pleasant surprise to see that the Voxel Engine that I shared in this blog was able to help some guys to develop some amazing projects.

Inverto

"Inverto" is a first person shooter-puzzler with gravity manipulations. Game is ideological successor of such games as "Prey" and "Portal" with a pinch of parkour. Proceed all of the testing areas as a simple researcher with your trusty GraviGun. Prepare to explore Escher-esque spaces and solve navigational puzzles by changing gravity direction, employing body momentum and fighting nausea (only if you have weak vestibular system). "Inverto" is developed on Unity3D game engine and is planned on Windows, Mac, Linux and Web. Will be released later this summer. Current version of the game is in alpha state, and does not represent final product quality.


http://www.indiedb.com/games/gravitron
http://inverto.gravityboxstudio.net/



BitDrill

Although currently in it’s early stages, BitDrill is a game that is being developed by one man about online mining and combat. The basic idea of the game is that you and your friends get on a LAN game (currently, may add a server later) and mine. You sell off the resources gathered to obtain cash. With the cash you can then buy upgrades. With the upgrades you can mine deeper. Or you can fight your friends!

http://bitdrill.wordpress.com/


Optimizations

Other Unity forum users like RetromadeGames used the engine as well and shared some thoughts. Right now we are trying to optimize the chunk generation. I will post here if we are able to find some simple fixes to improve the engine performance. 
For now some things that you guys could try is avoid to recreate the mesh at every chunk refresh and use mesh double buffer and mesh markDynamic. But the biggest issues are:

  • Recreate the mesh collider (as Tito, a user of BitDrill pointed out, it's better to use aabb collision. This will fix most of the performance issues)
  • Soft Lightning. This could be and must be optimized ( this was just a proof of concept ).

Like I said before, this was just a prototype and it need a lot of work to get into a real project. So congrats for all those people who created some really nice things using the Voxel Engine. And please, let me know if someone else create something cool using this. :)

Thursday, September 26, 2013

How to identify iPhone5S and iPhone5C on Unity 3.5

Since Unity 3.5.7 is the last planned version of Unity 3, I created a simple plugin to help the developers that for some reason can't update their projects to Unity 4 atm. In fact this is something that I had to use in the past to identify the iPhone5... The ideia to post this came from this topic on Unity forum.


The following plugin is an alternative for users of Unity 3.5 that need to identify new Apple mobile devices like the iPhone5S and iPhone5C. Using the device model as a string is also a good ideia if your application can download config files from a server or if you are using AssetBundles. This way you do not need to upload a new binary to Apple only to set some settings based on the user device.

The plugin is avaliable at:
http://wiki.unity3d.com/index.php/IPhoneDeviceModel

Saturday, May 4, 2013

Voxelizer Part 2

It's time to add some colors to the voxelizer! :)



I've been busy finishing a project on my work, so unfortunately I'm not spending the time that I would like to finish the voxelizer. For now I just added colors to the voxels based on the mesh textures. The process is pretty straight forward:
1) Loop trough all vertices of the meshes and apply their texel color to the mesh vertex color.
2) When checking if the triangle collided with a voxel (SAT), calculate the average color of the triangle and store it into the voxel
3) And finally render the mesh voxels with a shader that supports vertex color.

The following images illustrate those steps:


There is many other ways to do that, but for my purposes that's good enough. The main problem with this technique is that it wont works so well for low-poly models, because you will end up with not enough color information for your voxels. But this is not the case in Sponza Pallace.

The project is not ready to share, but I believe that it will be done until the next weekend.

Thread:
Voxelizer Part 1
Voxelizer Part 2
Voxelizer Part 3
Voxelizer Part 4 (Final)

Saturday, April 27, 2013

Voxelizer Part 1

Here follows the first results of my voxelizer (the process to take a regular mesh and create a voxel representation). For the tests I'm using an old SpiderMan model that I created in 2005 (damn, I dunno how I found it on my HD) and Sponza Palace that Crytek donated to public domain (download link). I'm glad with the results, but I still have to take in account the model's texture to colorize the voxels. This is a small part of my Global Illumination studies. hehe

Just a few million of voxels. That's I call density. :D


In the next posts I will share the Unity webplayer demo and project source.
If you are interested to understand how it's made, I recomend you to start studing the "Separating Axis Theorem" (SAT). Here is some very usefull links about it:

Sunday, April 21, 2013

Unity Multi Pass Surface Shader

As you guys know, in Unity we can write shaders in some different ways. We can have Fixed Pipeline Shaders, Surface Shaders and CGPrograms (vertex and fragment shaders).
Surface Shaders are great to write lightning models, but I always believed that it limit the shader to just one pass. Well, yesterday I discovered that I was WRONG. I found a very interesting topic in Unity forum about this and I started to play around with it.

Here follows a very simple shader that illustrate how is possible to combine those languages and have a multi pass shader. Just uncomment the pass blocks to see the effect.


Shader "ZGreaterTest" 
{
 Properties 
 {
     _Color ("Main Color", Color) = (1,1,1,1)
     _MainTex ("Base (RGB)", 2D) = "white" {}
     _Indicator ("Indicator Color", Color) = (1,1,1,1)
     _Cutoff ("Alpha cutoff", Range (0,1)) = 0.0
 }
 
 SubShader 
 {
  Tags { "Queue" = "Geometry+1" "RenderType" = "Opaque" }
 
  CGPROGRAM
  #pragma surface surf BlinnPhong alphatest:_Cutoff
  uniform float4 _Color;
  uniform float4 _Indicator;
  uniform sampler2D _MainTex;
   
  struct Input 
  {
      float2 uv_MainTex;
      float3 viewDir;
  };
  
  void surf (Input IN, inout SurfaceOutput o) 
  {
      o.Albedo = tex2D ( _MainTex, IN.uv_MainTex).rgb * _Color;
  }
  ENDCG

// Pass: Surface SHADER
//     ZWrite Off
//     ZTest Greater
//     Blend DstColor Zero
//     
//  CGPROGRAM
//  #pragma surface surf BlinnPhong
//  uniform float4 _Color;
//  uniform float4 _Indicator;
//  uniform sampler2D _MainTex;
//
//  struct Input 
//  {
//      float2 uv_MainTex;
//      float3 viewDir;
//  };
//  
//  void surf (Input IN, inout SurfaceOutput o) 
//  {
//   //o.Albedo =_Indicator;
//      o.Albedo = tex2D ( _MainTex, IN.uv_MainTex).rgb * _Indicator;
//  }
//  ENDCG 

// Pass: CG SHADER
//  Pass
//        {
//         Tags { "LightMode" = "Always" }
//         AlphaTest Greater [_Cutoff]
//         ZWrite Off
//         ZTest Greater
//         
//            CGPROGRAM
//            #pragma vertex vert
//            #pragma fragment frag
//            #pragma fragmentoption ARB_precision_hint_fastest
//            #include "UnityCG.cginc"
//
//   sampler2D _MainTex;
//   float4 _MainTex_ST;
//   uniform float4 _Indicator;
//   
//            struct v2f 
//            {
//                float4 pos          : POSITION;
//                float2 uv           : TEXCOORD1;
//            };
//
//            v2f vert (appdata_full v)
//            {
//                v2f o;
//                o.pos = mul(UNITY_MATRIX_MVP, v.vertex);    
//                o.uv = TRANSFORM_TEX (v.texcoord, _MainTex);
//                return o;
//            }
//            
//            half4 frag( v2f i ) : COLOR
//            {
//             half4 texcol = tex2D (_MainTex, i.uv);
//               return texcol * _Indicator;
//            }
//          ENDCG           
//        }
        
// Pass: Fixed pipeline
//        Pass 
//  {          
//         Tags { "LightMode" = "Always" }
//         AlphaTest Greater [_Cutoff]
//         ZWrite Off
//         ZTest Greater
// 
//         SetTexture [_MainTex] 
//         {
//             constantColor [_Indicator]
//             //combine constant, texture
//             combine constant* texture
//         }
//  }
  
 }

 Fallback " Glossy", 0
}
 
I would like to thank Sycle and Farfarer to share this tip. :)

I think that the next post will be about a voxelizer that I'm writing. Stay tuned!

Saturday, March 9, 2013

Voxel Engine Part 3 (Final)

As promised, here is the Voxel Engine Unity Project:
Unity Package (1.36mb)
Alternative download link

The webplayer demo is available in my previous post.

There is a "Read-me" file inside the package pointing out some directions for those who are trying to understand the project.

I would like to thanks Paul of the BlockStory project that wrote some very useful articles that helped me a lot to get started in the Voxel World. Some classes are heavily based on his samples.

Thanks as well to the Unity community that have this great topic about voxels and to Jeff Standen that wrote the Simplex3D Noise that I'm using.

This demo works on iOS, Android, Mac, Windows and Webplayer. It was tested on my Android Galaxy S2 and Apple iPad4.

The main bottleneck is the CPU while the player is creating and destroying blocks. In the code I left some hints of things that I would have done differently now, or links to articles that offers a better solution for what I did. Remember, this is just a prototype that emerged from a study. There is a lot of stuff to change if you are planning to use this in a real project.

The textures and sounds came from Minecraft ( https://minecraft.net/ ), and the pickaxe is a model that I did trying to reproduce the Minecraft pickaxe. So those assets are not my property and should not be used in any commercial way.

Fell free to use all the other assets and scripts in the way you like.
If you did something cool using this project, please let me know. :)


Thread