Friday, January 22, 2016

CSG Unity plugin update 8

I guess I never posted this on my blog, oops!

Here's a video showing some WIP brush editing I've been working on.
It handles non-planar non-convex self-intersecting polygons.

Thursday, December 3, 2015

Half-Life Black Mesa in Unity / CSG Unity plugin update 7

Hi! It's been a while since the last update and this is mainly because I spend 2 months in Copenhagen for my Unity onboarding and I didn't really have much time to work on CSG then or after.

Since I can't work on it full time anymore the pace is a lot slower, it doesn't help that I need to spend a lot of time & energy on the eventual move to Copenhagen at the end of January.

But don't worry, I'm committed to finishing this plugin and it will get done!

In the meantime, here's some eye candy for you to enjoy :)

Yes your eyes are not deceiving you, this is a Half-Life Black mesa level running in Unity.
I wrote an importer that imports all the brushes from black mesa maps and turn them into the CSG brushes that my plugin uses. I also wrote an importer for the meshes (which was a huge time-sink, maybe I shouldn't have done that!)

After I got the importer working to a point where it was good enough (for my purposes at least), I did some performance testing .. and at first it was much slower than I suspected. It was interactive, but definitely not as fast as I thought it would be. It took me a while to figure out that I was actually, accidentally, updating all the >3000 brushes in the level every time I moved a single brush!

Monday, July 27, 2015

CSG Unity plugin progress update 6

Just came back from vacation from sunny Turkey and in half a day fixed a bug that I spend a couple of days trying to fix before I left. Funny how that works some time.

The bug had to do with several brushes having a surface that lie on the same plane and where sometimes the wrong surface would be categorized as being visible, such as a surface that should actually not exist anymore because it was removed by another brush.

Now I can finally focus on merging brushes on the edges where they intersect, this should fix all the problems I'm having with gaps between brushes. I already have a good idea on how to do this, so hopefully this shouldn't take too long.

Friday, July 10, 2015

CSG Unity plugin progress update 5

So the last few weeks I've been busy fixing lots of issues here and there, making sure things work like they should etc. I still need to implement a couple of important pieces but I'm making good progress.

Here's a video that shows some of the things that the plugin can already do (one of these days I'm going to show something more interesting than a couple of simple shapes)

Finally, I've been offered a job at Unity! So pretty soon now I'll start working there and do my best to help make Unity even better than it is :)

(and this is one of the reasons why I've had so many distractions lately)

Thursday, June 18, 2015

CSG Unity plugin progress update 4 - C++ / smoothing

The last couple of weeks where really busy, once again I had lots of distractions which made it hard for me to work on the plugin. I probably have something to announce soon!
I've done a couple of things however.

First of all I've moved the actual CSG code from Unity/C# to C++. The reason for this is because the more low level optimizations I did the more it felt like C# was actively resisting me trying to optimize everything.

The more you do low level optimizations, the more it starts to feel like C++ but without all the helpful syntax such as 'inline' and with pointer juggling without all the unsafe nonsense. I was actually already working with lots of big C# arrays + indices so I was effectively already doing memory management. Moving everything to C++ actually made it possible for me to clean up the code and make it MORE readable. Not something you usually hear when you compare C++ to C#!

The whole plugin was always intended as an editor only plugin anyway, so fortunately I won't condemn myself to supporting a gazillion platforms by moving everything to C++!
Other big benefits are that I have a clear separation between the Unity part and the CSG part, I can use good quality low level profilers to find bottlenecks and I have way more low level control over memory and performance now.

While I was moving everything to C++ it also gave me a chance to revisit some parts of the CSG process and fix some issues. One improvement I made, for instance, is normal smoothing, which at the moment can only be used on polygons that share the same texture coordinate surface.

Here you can see the normals in unity's 'normal' debug view.

Another, internal, improvement is that the CSG representation is now an n-tree internally instead of a binary tree. This matches the unity hierarchy better and allows me to have shallower hierarchies which should perform better.

My focus now is to get something out there, so I'm going to fix the remaining bugs and implement only what really needs to implemented for the first version.

Tuesday, June 2, 2015

Unity editor line rendering

I created a new github repository for rendering lines in the Unity editor. It allows you to render dotted lines with different dot sizes & render multiple lines at the same time.
It uses the Unity GL class for line rendering (which is what Unity uses itself when rendering lines in the Unity editor). The dots are created in a shader in screen space, so they'll look good no matter how you turn the camera.

Thursday, May 7, 2015

Subdivision surfaces

Just got back from the states, so I still have a bit of jetlag (man I hate that). But anyway, someone suggested I should take a look at Mesh Fusion, which is a really interesting tool that does approximate CSG with subdivision surfaces.

This made me want to try to see if I can get my CSG algorithm to work with subdivision surfaces, which I never tried out. So here's my first attempt at performing subdivision surfaces on a cube mesh, about half a days work.

Next on my list of things to do is fix some t-junction issues on the final mesh that pops out of the CSG process. I need to get the whole plugin in a shippable status, after that I'll continue my research on subdiv.